kamctl.sqlbase 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. #
  2. #
  3. # control tool for maintaining Kamailio
  4. #
  5. #===================================================================
  6. ##### ----------------------------------------------- #####
  7. ### common variables and functions for SQL engines
  8. if [ -z "$DBNAME" ] ; then
  9. DBNAME=kamailio
  10. fi
  11. if [ -z "$DBHOST" ] ; then
  12. DBHOST=localhost
  13. fi
  14. if [ -z "$DBRWUSER" ] ; then
  15. DBRWUSER=kamailio
  16. fi
  17. # the read-only user for whom password may be stored here
  18. if [ -z "$DBROUSER" ] ; then
  19. DBROUSER=kamailioro
  20. fi
  21. if [ -z "$DBROPW" ] ; then
  22. DBROPW=kamailioro
  23. fi
  24. # full privileges SQL user
  25. if [ -z "$DBROOTUSER" ]; then
  26. DBROOTUSER="root"
  27. fi
  28. DBFNOW="now()"
  29. #params: none
  30. # output: DBRWPW
  31. prompt_pw() {
  32. if [ -z "$DBRWPW" ] ; then
  33. savetty=`stty -g`
  34. if [ -z "$1" ] ; then
  35. printf "Password: " > /dev/stderr
  36. else
  37. printf "$1: " > /dev/stderr
  38. fi
  39. stty -echo
  40. read DBRWPW
  41. stty $savetty
  42. echo
  43. fi
  44. }
  45. # dbtext don't support db_ops
  46. usage_db_ops() {
  47. echo
  48. mecho " -- command 'db' - database operations"
  49. echo
  50. cat <<EOF
  51. db exec <query> ..................... execute SQL query
  52. db roexec <roquery> ................. execute read-only SQL query
  53. db run <id> ......................... execute SQL query from \$id variable
  54. db rorun <id> ....................... execute read-only SQL query from
  55. \$id variable
  56. db show <table> ..................... display table content
  57. db showg <table> .................... display formatted table content
  58. db smatch <table> <key> <value>...... display record from table that has
  59. ........................... column key equal to value as string
  60. db nmatch <table> <key> <value>...... display record from table that has
  61. ........................... column key equal to value as non-string
  62. db connect .......................... connect to db server via cli
  63. EOF
  64. }
  65. USAGE_FUNCTIONS="$USAGE_FUNCTIONS usage_db_ops"
  66. # speeddial not implemented for dbtext
  67. usage_speeddial() {
  68. echo
  69. mecho " -- command 'speeddial' - manage speed dials (short numbers)"
  70. echo
  71. cat <<EOF
  72. speeddial show <speeddial-id> ....... show speeddial details
  73. speeddial list <sip-id> ............. list speeddial for uri
  74. speeddial add <sip-id> <sd-id> <new-uri> [<desc>] ...
  75. ........................... add a speedial (*)
  76. speeddial rm <sip-id> <sd-id> ....... remove a speeddial (*)
  77. speeddial help ...................... help message
  78. - <speeddial-id>, <sd-id> must be an AoR (username@domain)
  79. - <sip-id> must be an AoR (username@domain)
  80. - <new-uri> must be a SIP AoR (sip:username@domain)
  81. - <desc> a description for speeddial
  82. EOF
  83. }
  84. USAGE_FUNCTIONS="$USAGE_FUNCTIONS usage_speeddial"
  85. # avp operations not implemented for dbtext
  86. usage_avp() {
  87. echo
  88. mecho " -- command 'avp' - manage AVPs"
  89. echo
  90. cat <<EOF
  91. avp list [-T table] [-u <sip-id|uuid>]
  92. [-a attribute] [-v value] [-t type] ... list AVPs
  93. avp add [-T table] <sip-id|uuid>
  94. <attribute> <type> <value> ............ add AVP (*)
  95. avp rm [-T table] [-u <sip-id|uuid>]
  96. [-a attribute] [-v value] [-t type] ... remove AVP (*)
  97. avp help .................................. help message
  98. - -T - table name
  99. - -u - SIP id or unique id
  100. - -a - AVP name
  101. - -v - AVP value
  102. - -t - AVP name and type (0 (str:str), 1 (str:int),
  103. 2 (int:str), 3 (int:int))
  104. - <sip-id> must be an AoR (username@domain)
  105. - <uuid> must be a string but not AoR
  106. EOF
  107. }
  108. USAGE_FUNCTIONS="$USAGE_FUNCTIONS usage_avp"
  109. # alias_db not implemented for dbtext
  110. usage_alias_db() {
  111. echo
  112. mecho " -- command 'alias_db' - manage database aliases"
  113. echo
  114. cat <<EOF
  115. alias_db show <alias> .............. show alias details
  116. alias_db list <sip-id> ............. list aliases for uri
  117. alias_db add <alias> <sip-id> ...... add an alias (*)
  118. alias_db rm <alias> ................ remove an alias (*)
  119. alias_db help ...................... help message
  120. - <alias> must be an AoR (username@domain)"
  121. - <sip-id> must be an AoR (username@domain)"
  122. EOF
  123. }
  124. USAGE_FUNCTIONS="$USAGE_FUNCTIONS usage_alias_db"
  125. usage_domain() {
  126. echo
  127. mecho " -- command 'domain' - manage local domains"
  128. echo
  129. cat <<EOF
  130. domain reload ....................... reload domains from disk
  131. domain show ......................... show current domains in memory
  132. domain showdb ....................... show domains in the database
  133. domain add <domain> ................. add the domain to the database
  134. domain rm <domain> .................. delete the domain from the database
  135. EOF
  136. }
  137. USAGE_FUNCTIONS="$USAGE_FUNCTIONS usage_domain"
  138. uid_usage_domain() {
  139. echo
  140. mecho " -- command 'uid_domain' - manage local domains"
  141. echo
  142. cat <<EOF
  143. uid_domain reload ....................... reload domains from disk
  144. uid_domain show ......................... show current domains in memory
  145. uid_domain showdb ....................... show domains in the database
  146. uid_domain add <domain> [did] [flags].... add the domain to the database
  147. uid_domain rm <domain> .................. delete the domain from the database
  148. EOF
  149. }
  150. USAGE_FUNCTIONS="$USAGE_FUNCTIONS uid_usage_domain"