| 1 |
# |
| 2 |
# |
| 3 |
# control tool for maintaining Kamailio |
| 4 |
# |
| 5 |
# This file is part of Kamailio, a free SIP server. |
| 6 |
# |
| 7 |
# SPDX-License-Identifier: GPL-2.0-or-later |
| 8 |
# |
| 9 |
# Kamailio is free software; you can redistribute it and/or modify |
| 10 |
# it under the terms of the GNU General Public License as published by |
| 11 |
# the Free Software Foundation; either version 2 of the License, or |
| 12 |
# (at your option) any later version |
| 13 |
# |
| 14 |
# Kamailio is distributed in the hope that it will be useful, |
| 15 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 |
# GNU General Public License for more details. |
| 18 |
# |
| 19 |
# You should have received a copy of the GNU General Public License |
| 20 |
# along with this program; if not, write to the Free Software |
| 21 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 22 |
# |
| 23 |
#=================================================================== |
| 24 |
|
| 25 |
##### ----------------------------------------------- ##### |
| 26 |
### common variables and functions for SQL engines |
| 27 |
|
| 28 |
if [ -z "$DBNAME" ] ; then |
| 29 |
DBNAME=kamailio |
| 30 |
fi |
| 31 |
if [ -z "$DBHOST" ] ; then |
| 32 |
DBHOST=localhost |
| 33 |
fi |
| 34 |
if [ -z "$DBRWUSER" ] ; then |
| 35 |
DBRWUSER=kamailio |
| 36 |
fi |
| 37 |
|
| 38 |
# the read-only user for whom password may be stored here |
| 39 |
if [ -z "$DBROUSER" ] ; then |
| 40 |
DBROUSER=kamailioro |
| 41 |
fi |
| 42 |
if [ -z "$DBROPW" ] ; then |
| 43 |
DBROPW=kamailioro |
| 44 |
fi |
| 45 |
|
| 46 |
# full privileges SQL user |
| 47 |
if [ -z "$DBROOTUSER" ]; then |
| 48 |
DBROOTUSER="root" |
| 49 |
fi |
| 50 |
|
| 51 |
DBFNOW="now()" |
| 52 |
|
| 53 |
#params: none |
| 54 |
# output: DBRWPW |
| 55 |
prompt_pw() { |
| 56 |
if [ -z "$DBRWPW" ] ; then |
| 57 |
savetty=`stty -g` |
| 58 |
if [ -z "$1" ] ; then |
| 59 |
printf "Password: " >&2 |
| 60 |
else |
| 61 |
printf "$1: " >&2 |
| 62 |
fi |
| 63 |
stty -echo |
| 64 |
read DBRWPW |
| 65 |
stty $savetty |
| 66 |
echo |
| 67 |
fi |
| 68 |
} |
| 69 |
|
| 70 |
# dbtext don't support db_ops |
| 71 |
usage_db_ops() { |
| 72 |
echo |
| 73 |
mecho " -- command 'db' - database operations" |
| 74 |
echo |
| 75 |
cat <<EOF |
| 76 |
db exec <query> ..................... execute SQL query |
| 77 |
db roexec <roquery> ................. execute read-only SQL query |
| 78 |
db run <id> ......................... execute SQL query from \$id variable |
| 79 |
db rorun <id> ....................... execute read-only SQL query from |
| 80 |
\$id variable |
| 81 |
db show <table> ..................... display table content |
| 82 |
db showg <table> .................... display formatted table content |
| 83 |
db smatch <table> <key> <value>...... display record from table that has |
| 84 |
........................... column key equal to value as string |
| 85 |
db nmatch <table> <key> <value>...... display record from table that has |
| 86 |
........................... column key equal to value as non-string |
| 87 |
db connect .......................... connect to db server via cli |
| 88 |
db version add <table> <value> ...... add new value in version table |
| 89 |
db version set <table> <value> ...... set value in version table |
| 90 |
db version update <table> <value> ... update value in version table |
| 91 |
EOF |
| 92 |
} |
| 93 |
USAGE_FUNCTIONS="$USAGE_FUNCTIONS usage_db_ops" |
| 94 |
|
| 95 |
# speeddial not implemented for dbtext |
| 96 |
usage_speeddial() { |
| 97 |
echo |
| 98 |
mecho " -- command 'speeddial' - manage speed dials (short numbers)" |
| 99 |
echo |
| 100 |
cat <<EOF |
| 101 |
speeddial show <speeddial-id> ....... show speeddial details |
| 102 |
speeddial list <sip-id> ............. list speeddial for uri |
| 103 |
speeddial add <sip-id> <sd-id> <new-uri> [<desc>] ... |
| 104 |
........................... add a speedial (*) |
| 105 |
speeddial rm <sip-id> <sd-id> ....... remove a speeddial (*) |
| 106 |
speeddial help ...................... help message |
| 107 |
- <speeddial-id>, <sd-id> must be an AoR (username@domain) |
| 108 |
- <sip-id> must be an AoR (username@domain) |
| 109 |
- <new-uri> must be a SIP AoR (sip:username@domain) |
| 110 |
- <desc> a description for speeddial |
| 111 |
EOF |
| 112 |
} |
| 113 |
USAGE_FUNCTIONS="$USAGE_FUNCTIONS usage_speeddial" |
| 114 |
|
| 115 |
# avp operations not implemented for dbtext |
| 116 |
usage_avp() { |
| 117 |
echo |
| 118 |
mecho " -- command 'avp' - manage AVPs" |
| 119 |
echo |
| 120 |
cat <<EOF |
| 121 |
avp list [-T table] [-u <sip-id|uuid>] |
| 122 |
[-a attribute] [-v value] [-t type] ... list AVPs |
| 123 |
avp add [-T table] <sip-id|uuid> |
| 124 |
<attribute> <type> <value> ............ add AVP (*) |
| 125 |
avp rm [-T table] [-u <sip-id|uuid>] |
| 126 |
[-a attribute] [-v value] [-t type] ... remove AVP (*) |
| 127 |
avp help .................................. help message |
| 128 |
- -T - table name |
| 129 |
- -u - SIP id or unique id |
| 130 |
- -a - AVP name |
| 131 |
- -v - AVP value |
| 132 |
- -t - AVP name and type (0 (str:str), 1 (str:int), |
| 133 |
2 (int:str), 3 (int:int)) |
| 134 |
- <sip-id> must be an AoR (username@domain) |
| 135 |
- <uuid> must be a string but not AoR |
| 136 |
EOF |
| 137 |
} |
| 138 |
USAGE_FUNCTIONS="$USAGE_FUNCTIONS usage_avp" |
| 139 |
|
| 140 |
# alias_db not implemented for dbtext |
| 141 |
usage_alias_db() { |
| 142 |
echo |
| 143 |
mecho " -- command 'alias_db' - manage database aliases" |
| 144 |
echo |
| 145 |
cat <<EOF |
| 146 |
alias_db show <alias> .............. show alias details |
| 147 |
alias_db list <sip-id> ............. list aliases for uri |
| 148 |
alias_db add <alias> <sip-id> ...... add an alias (*) |
| 149 |
alias_db rm <alias> ................ remove an alias (*) |
| 150 |
alias_db help ...................... help message |
| 151 |
- <alias> must be an AoR (username@domain)" |
| 152 |
- <sip-id> must be an AoR (username@domain)" |
| 153 |
EOF |
| 154 |
} |
| 155 |
USAGE_FUNCTIONS="$USAGE_FUNCTIONS usage_alias_db" |
| 156 |
|
| 157 |
usage_domain() { |
| 158 |
echo |
| 159 |
mecho " -- command 'domain' - manage local domains" |
| 160 |
echo |
| 161 |
cat <<EOF |
| 162 |
domain reload ....................... reload domains from disk |
| 163 |
domain show ......................... show current domains in memory |
| 164 |
domain showdb ....................... show domains in the database |
| 165 |
domain add <domain> ................. add the domain to the database |
| 166 |
domain rm <domain> .................. delete the domain from the database |
| 167 |
EOF |
| 168 |
} |
| 169 |
USAGE_FUNCTIONS="$USAGE_FUNCTIONS usage_domain" |
| 170 |
|
| 171 |
uid_usage_domain() { |
| 172 |
echo |
| 173 |
mecho " -- command 'uid_domain' - manage local domains" |
| 174 |
echo |
| 175 |
cat <<EOF |
| 176 |
uid_domain reload ....................... reload domains from disk |
| 177 |
uid_domain show ......................... show current domains in memory |
| 178 |
uid_domain showdb ....................... show domains in the database |
| 179 |
uid_domain add <domain> [did] [flags].... add the domain to the database |
| 180 |
uid_domain rm <domain> .................. delete the domain from the database |
| 181 |
EOF |
| 182 |
} |
| 183 |
USAGE_FUNCTIONS="$USAGE_FUNCTIONS uid_usage_domain" |