Browse Source

- add a new module, called 'userblacklist' for handling user and global blacklists
- credits for this module goes to Hardy Kahl, hardy dot kahl at 1und1 dot de
- add documentation, database scheme and test for this module


git-svn-id: https://openser.svn.sourceforge.net/svnroot/openser/trunk@3760 689a6050-402a-0410-94f2-e92a70836424

Henning Westerholt 17 years ago
parent
commit
6d5d49abf7
2 changed files with 162 additions and 0 deletions
  1. 48 0
      test/unit/25.cfg
  2. 114 0
      test/unit/25.sh

+ 48 - 0
test/unit/25.cfg

@@ -0,0 +1,48 @@
+debug=0
+listen=127.0.0.1
+port=5059
+
+mpath="../modules/"
+loadmodule "sl/sl.so"
+loadmodule "tm/tm.so"
+loadmodule "usrloc/usrloc.so"
+loadmodule "registrar/registrar.so"
+loadmodule "xlog/xlog.so"
+loadmodule "db_mysql/db_mysql.so"
+loadmodule "userblacklist/userblacklist.so"
+loadmodule "maxfwd/maxfwd.so"
+loadmodule "mi_fifo/mi_fifo.so"
+
+modparam("usrloc", "db_mode", 3)
+modparam("mi_fifo", "fifo_name", "/tmp/openser_fifo")
+
+route {
+	#xlog("user: $rU\n");
+
+	$avp(i:80) = $rU;
+
+	if(!lookup ("location")){
+		sl_send_reply("404", "Not Found");
+		exit;
+	}
+
+	if (!mf_process_maxfwd_header("10")) {
+		sl_send_reply("483","Too Many Hops");
+		exit;
+	}
+
+	if (!check_user_blacklist("$avp(i:80)", "$avp(i:81)")) {
+		xlog("$rU user blacklisted\n");
+		sl_send_reply("403", "Forbidden");
+		exit;
+	}
+
+	if (!check_blacklist("globalblacklist")) {
+		xlog("$rU globally blacklisted\n");
+		sl_send_reply("403", "Forbidden");
+		exit;
+	}
+	xlog("$rU not blacklisted\n");
+
+	t_relay();
+}

+ 114 - 0
test/unit/25.sh

@@ -0,0 +1,114 @@
+#!/bin/bash
+# loads a userblacklist config from mysql database
+
+# Copyright (C) 2007 1&1 Internet AG
+#
+# This file is part of openser, a free SIP server.
+#
+# openser is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version
+#
+# openser is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+
+# needs the sipp utility to run
+which sipp > /dev/null
+ret=$?
+
+if [ ! $? -eq 0 ] ; then
+	echo "sipp not found, not run"
+	exit 0
+fi ;
+
+CFG=25.cfg
+
+MYSQL="mysql openser -u openser --password=openserrw -e"
+
+# add an registrar entry to the db;
+$MYSQL "insert into location (username,contact,socket,user_agent,cseq,q) values (\"49721123456789\",\"sip:123456789@localhost\",\"udp:127.0.0.1:5060\",\"ser_test\",1,-1);"
+
+$MYSQL "insert into location (username,contact,socket,user_agent,cseq,q) values (\"49721123456788\",\"sip:123456788@localhost\",\"udp:127.0.0.1:5060\",\"ser_test\",1,-1);"
+
+$MYSQL "insert into location (username,contact,socket,user_agent,cseq,q) values (\"49721123456787\",\"sip:123456787@localhost\",\"udp:127.0.0.1:5060\",\"ser_test\",1,-1);"
+
+$MYSQL "insert into location (username,contact,socket,user_agent,cseq,q) values (\"49721123456786\",\"sip:123456786@localhost\",\"udp:127.0.0.1:5060\",\"ser_test\",1,-1);"
+
+
+# setup userblacklist, first some dummy data
+$MYSQL "insert into userblacklist (username, domain, prefix, whitelist, comment) values ('494675454','','49900','0','_test_');"
+$MYSQL "insert into userblacklist (username, domain, prefix, whitelist, comment) values ('494675453','test.domain','49901','0','_test_');"
+$MYSQL "insert into userblacklist (username, domain, prefix, whitelist, comment) values ('494675231','test','499034132','0','_test_');"
+$MYSQL "insert into userblacklist (username, domain, prefix, whitelist, comment) values ('494675231','','499034133','1','_test_');"
+# some actual data
+$MYSQL "insert into userblacklist (username, domain, prefix, whitelist, comment) values ('49721123456789','','12345','0','_test_');"
+$MYSQL "insert into userblacklist (username, domain, prefix, whitelist, comment) values ('49721123456788','','123456788','1','_test_');"
+$MYSQL "insert into userblacklist (username, domain, prefix, whitelist, comment) values ('49721123456788','','1234','0','_test_');"
+# and the global ones
+$MYSQL "insert into globalblacklist (prefix, whitelist, comment) values ('123456787','0','_test_');"
+$MYSQL "insert into globalblacklist (prefix, whitelist, comment) values ('123456','0','_test_');"
+
+../openser -w . -f $CFG &> /dev/null
+sleep 1
+
+sipp -sn uas -bg -i localhost -m 1 -f 2 -p 5060 &> /dev/null
+sipp -sn uac -s 49721123456789 127.0.0.1:5059 -i 127.0.0.1 -m 1 -f 2 -p 5061 &> /dev/null
+ret=$?
+
+if [ "$ret" -eq 1 ] ; then
+	sipp -sn uas -bg -i localhost -m 1 -f 2 -p 5060 &> /dev/null
+	sipp -sn uac -s 49721123456788 127.0.0.1:5059 -i 127.0.0.1 -m 1 -f 2 -p 5061 &> /dev/null
+	ret=$?
+fi;
+
+if [ "$ret" -eq 1 ] ; then
+	sipp -sn uas -bg -i localhost -m 1 -f 2 -p 5060 &> /dev/null
+	sipp -sn uac -s 49721123456787 127.0.0.1:5059 -i 127.0.0.1 -m 1 -f 2 -p 5061 &> /dev/null
+	ret=$?
+fi;
+
+if [ "$ret" -eq 1 ] ; then
+	sipp -sn uas -bg -i localhost -m 1 -f 2 -p 5060 &> /dev/null
+	sipp -sn uac -s 49721123456786 127.0.0.1:5059 -i 127.0.0.1 -m 1 -f 2 -p 5061 &> /dev/null
+	ret=$?
+fi;
+
+$MYSQL "insert into globalblacklist (prefix, whitelist, comment) values ('123456786','1','_test_');"
+openserctl fifo reload_blacklist
+
+if [ "$ret" -eq 1 ] ; then
+	sipp -sn uas -bg -i localhost -m 1 -f 2 -p 5060 &> /dev/null
+	sipp -sn uac -s 49721123456786 127.0.0.1:5059 -i 127.0.0.1 -m 1 -f 2 -p 5061 &> /dev/null
+	ret=$?
+fi;
+
+$MYSQL "insert into userblacklist (username, domain, prefix, whitelist, comment) values ('49721123456786','','12345','0','_test_');"
+
+if [ "$ret" -eq 0 ] ; then
+	sipp -sn uas -bg -i localhost -m 1 -f 2 -p 5060 &> /dev/null
+	sipp -sn uac -s 49721123456786 127.0.0.1:5059 -i 127.0.0.1 -m 1 -f 2 -p 5061 &> /dev/null
+	ret=$?
+fi;
+
+if [ "$ret" -eq 1 ] ; then
+	ret=0
+else
+	ret=1
+fi;
+
+# cleanup:
+killall -9 sipp > /dev/null 2>&1
+killall -9 openser > /dev/null 2>&1
+
+$MYSQL "delete from location where (user_agent = \"ser_test\");"
+$MYSQL "delete from userblacklist where comment='_test_';"
+$MYSQL "delete from globalblacklist where comment='_test_';"
+
+exit $ret;