kamctl.sqlbase 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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: " >&2
  36. else
  37. printf "$1: " >&2
  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. db version add <table> <value> ...... add new value in version table
  64. db version set <table> <value> ...... set value in version table
  65. db version update <table> <value> ... update value in version table
  66. EOF
  67. }
  68. USAGE_FUNCTIONS="$USAGE_FUNCTIONS usage_db_ops"
  69. # speeddial not implemented for dbtext
  70. usage_speeddial() {
  71. echo
  72. mecho " -- command 'speeddial' - manage speed dials (short numbers)"
  73. echo
  74. cat <<EOF
  75. speeddial show <speeddial-id> ....... show speeddial details
  76. speeddial list <sip-id> ............. list speeddial for uri
  77. speeddial add <sip-id> <sd-id> <new-uri> [<desc>] ...
  78. ........................... add a speedial (*)
  79. speeddial rm <sip-id> <sd-id> ....... remove a speeddial (*)
  80. speeddial help ...................... help message
  81. - <speeddial-id>, <sd-id> must be an AoR (username@domain)
  82. - <sip-id> must be an AoR (username@domain)
  83. - <new-uri> must be a SIP AoR (sip:username@domain)
  84. - <desc> a description for speeddial
  85. EOF
  86. }
  87. USAGE_FUNCTIONS="$USAGE_FUNCTIONS usage_speeddial"
  88. # avp operations not implemented for dbtext
  89. usage_avp() {
  90. echo
  91. mecho " -- command 'avp' - manage AVPs"
  92. echo
  93. cat <<EOF
  94. avp list [-T table] [-u <sip-id|uuid>]
  95. [-a attribute] [-v value] [-t type] ... list AVPs
  96. avp add [-T table] <sip-id|uuid>
  97. <attribute> <type> <value> ............ add AVP (*)
  98. avp rm [-T table] [-u <sip-id|uuid>]
  99. [-a attribute] [-v value] [-t type] ... remove AVP (*)
  100. avp help .................................. help message
  101. - -T - table name
  102. - -u - SIP id or unique id
  103. - -a - AVP name
  104. - -v - AVP value
  105. - -t - AVP name and type (0 (str:str), 1 (str:int),
  106. 2 (int:str), 3 (int:int))
  107. - <sip-id> must be an AoR (username@domain)
  108. - <uuid> must be a string but not AoR
  109. EOF
  110. }
  111. USAGE_FUNCTIONS="$USAGE_FUNCTIONS usage_avp"
  112. # alias_db not implemented for dbtext
  113. usage_alias_db() {
  114. echo
  115. mecho " -- command 'alias_db' - manage database aliases"
  116. echo
  117. cat <<EOF
  118. alias_db show <alias> .............. show alias details
  119. alias_db list <sip-id> ............. list aliases for uri
  120. alias_db add <alias> <sip-id> ...... add an alias (*)
  121. alias_db rm <alias> ................ remove an alias (*)
  122. alias_db help ...................... help message
  123. - <alias> must be an AoR (username@domain)"
  124. - <sip-id> must be an AoR (username@domain)"
  125. EOF
  126. }
  127. USAGE_FUNCTIONS="$USAGE_FUNCTIONS usage_alias_db"
  128. usage_domain() {
  129. echo
  130. mecho " -- command 'domain' - manage local domains"
  131. echo
  132. cat <<EOF
  133. domain reload ....................... reload domains from disk
  134. domain show ......................... show current domains in memory
  135. domain showdb ....................... show domains in the database
  136. domain add <domain> ................. add the domain to the database
  137. domain rm <domain> .................. delete the domain from the database
  138. EOF
  139. }
  140. USAGE_FUNCTIONS="$USAGE_FUNCTIONS usage_domain"
  141. uid_usage_domain() {
  142. echo
  143. mecho " -- command 'uid_domain' - manage local domains"
  144. echo
  145. cat <<EOF
  146. uid_domain reload ....................... reload domains from disk
  147. uid_domain show ......................... show current domains in memory
  148. uid_domain showdb ....................... show domains in the database
  149. uid_domain add <domain> [did] [flags].... add the domain to the database
  150. uid_domain rm <domain> .................. delete the domain from the database
  151. EOF
  152. }
  153. USAGE_FUNCTIONS="$USAGE_FUNCTIONS uid_usage_domain"