Module: sip-router
Branch: master
Commit: 7b976204796a2260775dfd094cc388bde0a63ea9
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=7b97620…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: Tue May 8 19:35:29 2012 +0200
kamctl: added 'address' command
- handle records for address table of permissions module
---
utils/kamctl/kamctl | 88 +++++++++++++++++++++++++++++++++++++++++----
utils/kamctl/kamctl.base | 28 +++++++++++---
2 files changed, 102 insertions(+), 14 deletions(-)
diff --git a/utils/kamctl/kamctl b/utils/kamctl/kamctl
index 5e0d7a7..2cfb951 100755
--- a/utils/kamctl/kamctl
+++ b/utils/kamctl/kamctl
@@ -1051,9 +1051,9 @@ domain() {
#
##### ------------------------------------------------ #####
-### trusted management
+### permissions trusted management
#
-trusted() {
+permissions_trusted() {
case $1 in
reload)
require_ctlengine
@@ -1123,6 +1123,78 @@ trusted() {
esac
}
+
+#
+##### ------------------------------------------------ #####
+### permissions address management
+#
+permissions_address() {
+ case $1 in
+ reload)
+ require_ctlengine
+ $CTLCMD address_reload
+ ;;
+ dump)
+ require_ctlengine
+ $CTLCMD address_dump
+ ;;
+ show)
+ require_dbengine
+ QUERY="select * FROM $ADDRESS_TABLE ; "
+ $DBROCMD "$QUERY"
+ ;;
+ add)
+ require_dbengine
+ shift
+ if [ $# -lt 2 ] ; then
+ usage_address
+ exit 1
+ fi
+ AMASK=32
+ if [ ! -z "$3" ]; then
+ AMASK="$3"
+ fi
+ APORT=0
+ if [ ! -z "$4" ]; then
+ APORT="$4"
+ fi
+ ATAG=""
+ if [ ! -z "$5" ]; then
+ ATAG="$5"
+ fi
+
+ QUERY="insert into $ADDRESS_TABLE \
+ (grp, ip_addr, mask, port, tag) \
+ VALUES ($1, '$2', $AMASK, $APORT, '$ATAG');"
+ $DBCMD "$QUERY"
+ if [ $? -ne 0 ] ; then
+ merr "permissions address - SQL Error"
+ exit 1
+ fi
+ minfo "execute '$0 address reload' to synchronize cache and
database"
+ ;;
+ rm)
+ require_dbengine
+ shift
+ if [ $# -ne 2 ] ; then
+ usage_address
+ exit 1
+ fi
+ QUERY="delete from $ADDRESS_TABLE where grp=$1 and ip_addr='$2';"
+ $DBCMD "$QUERY"
+ if [ $? -ne 0 ] ; then
+ merr "permissions address - SQL Error"
+ exit 1
+ fi
+ minfo "execute '$0 address reload' to synchronize cache and
database"
+ ;;
+ *)
+ usage_address
+ exit 1
+ esac
+}
+
+
#
##### ------------------------------------------------ #####
### LCR management
@@ -2402,7 +2474,12 @@ case $1 in
trusted)
shift
- trusted "$@"
+ permissions_trusted "$@"
+ ;;
+
+ address)
+ shift
+ permissions_address "$@"
;;
fifo|mi|unixsock|ser_mi|sercmd_mi|sercmdmi)
@@ -2427,11 +2504,6 @@ case $1 in
cr "$@"
;;
- trusted)
- shift
- trusted "$@"
- ;;
-
dispatcher)
shift
dispatcher "$@"
diff --git a/utils/kamctl/kamctl.base b/utils/kamctl/kamctl.base
index 11c398d..dd4635f 100644
--- a/utils/kamctl/kamctl.base
+++ b/utils/kamctl/kamctl.base
@@ -180,11 +180,6 @@ fi
DO_DOMAIN_COLUMN=domain
DO_LAST_MODIFIED_COLUMN=last_modified
-# trusted table
-if [ -z "$TRUSTED_TABLE" ] ; then
- TRUSTED_TABLE=trusted
-fi
-
# lcr tables
if [ -z "$LCR_TABLE" ] ; then
LCR_TABLE=lcr
@@ -279,6 +274,11 @@ TRUSTED_PROTO_COLUMN=proto
TRUSTED_FROM_PATTERN_COLUMN=from_pattern
TRUSTED_TAG_COLUMN=tag
+# address table
+if [ -z "$ADDRESS_TABLE" ] ; then
+ ADDRESS_TABLE=address
+fi
+
# dispatcher tables
if [ -z "$DISPATCHER_TABLE" ] ; then
DISPATCHER_TABLE=dispatcher
@@ -416,7 +416,23 @@ cat <<EOF
trusted add <src_ip> <proto> <from_pattern> <tag>
....................... add a new entry
....................... (from_pattern and tag are optional arguments)
- trusted rm <src_ip> ............... remove all entres for the given src_ip
+ trusted rm <src_ip> ............... remove all entries for the given src_ip
+EOF
+}
+USAGE_FUNCTIONS="$USAGE_FUNCTIONS usage_trusted"
+
+usage_address() {
+ echo
+ mecho " -- command 'add|dump|reload|rm|show' - manage address"
+ echo
+cat <<EOF
+ address show ...................... show db content
+ address dump ...................... show cache content
+ address reload .................... reload db table into cache
+ address add <grp> <ipaddr> <mask> <port> <tag>
+ ....................... add a new entry
+ ....................... (mask, port and tag are optional arguments)
+ address rm <grp> <ipaddr> ......... remove entries for given grp and ipaddr
EOF
}
USAGE_FUNCTIONS="$USAGE_FUNCTIONS usage_trusted"