Module: sip-router
Branch: master
Commit: 9a1d64bddbf3ec931d39a0e47370e8d46ec2aeb9
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=9a1d64b…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: Wed Jan 23 12:49:16 2013 +0100
kamctl: added option to grant sql access from a remote host
- set DBACCESSHOST in kamctlrc
---
utils/kamctl/kamctlrc | 9 ++++++---
utils/kamctl/kamdbctl.mysql | 18 ++++++++++++++++++
2 files changed, 24 insertions(+), 3 deletions(-)
diff --git a/utils/kamctl/kamctlrc b/utils/kamctl/kamctlrc
index 99b9562..e5d8311 100644
--- a/utils/kamctl/kamctlrc
+++ b/utils/kamctl/kamctlrc
@@ -29,16 +29,19 @@
# DB_PATH="/usr/local/etc/kamailio/dbtext"
## database read/write user
-# DBRWUSER=kamailio
+# DBRWUSER="kamailio"
## password for database read/write user
# DBRWPW="kamailiorw"
## database read only user
-# DBROUSER=kamailioro
+# DBROUSER="kamailioro"
## password for database read only user
-# DBROPW=kamailioro
+# DBROPW="kamailioro"
+
+## database access host (from where is kamctl used)
+# DBACCESSHOST=192.168.0.1
## database super user (for ORACLE this is 'scheme-creator' user)
# DBROOTUSER="root"
diff --git a/utils/kamctl/kamdbctl.mysql b/utils/kamctl/kamdbctl.mysql
index eabc8ea..e4825ab 100644
--- a/utils/kamctl/kamdbctl.mysql
+++ b/utils/kamctl/kamdbctl.mysql
@@ -170,6 +170,15 @@ kamailio_db_grant () # pars: <database name>
exit 1
fi
fi
+
+ if [ ! -z "$DBACCESSHOST" ] ; then
+ sql_query "" "GRANT ALL PRIVILEGES ON $1.* TO
'$DBRWUSER'@'$DBACCESSHOST' IDENTIFIED BY '$DBRWPW';
+ GRANT SELECT ON $1.* TO '$DBROUSER'@'$DBACCESSHOST' IDENTIFIED BY
'$DBROPW';"
+ if [ $? -ne 0 ] ; then
+ merr "granting access host privileges to database $1 failed!"
+ exit 1
+ fi
+ fi
}
kamailio_db_revoke () # pars: <database name>
@@ -198,6 +207,15 @@ kamailio_db_revoke () # pars: <database name>
exit 1
fi
fi
+
+ if [ ! -z "$DBACCESSHOST" ] ; then
+ sql_query "" "REVOKE ALL PRIVILEGES ON $1.* FROM
'$DBRWUSER'@'$DBACCESSHOST';
+ REVOKE SELECT ON $1.* FROM '$DBROUSER'@'$DBACCESSHOST';"
+ if [ $? -ne 0 ] ; then
+ merr "granting access host privileges to database $1 failed!"
+ exit 1
+ fi
+ fi
}