kamdbctl.base 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. PATH=$PATH:/usr/local/sbin
  2. # config vars
  3. # name of the database to be used by Kamailio
  4. DBNAME=${DBNAME:-kamailio}
  5. # address of database server
  6. DBHOST=${DBHOST:-localhost}
  7. # user with full privileges over DBNAME database
  8. DBRWUSER=${DBRWUSER:-kamailio}
  9. # password user with full privileges over DBNAME database
  10. DBRWPW=${DBRWPW:-kamailiorw}
  11. # read-only user
  12. DBROUSER=${DBROUSER:-kamailioro}
  13. # password for read-only user
  14. DBROPW=${DBROPW:-kamailioro}
  15. # address of database server for root connections
  16. DBROOTHOST=${DBROOTHOST:-$DBHOST}
  17. # user name column
  18. USERCOL=${USERCOL:-username}
  19. # Describe what additional tables to install. Valid values for the variables
  20. # below are yes/no/ask. With ask it will interactively ask the user for the
  21. # answer, while yes/no allow for automated, unassisted installs.
  22. INSTALL_EXTRA_TABLES=${INSTALL_EXTRA_TABLES:-ask}
  23. INSTALL_PRESENCE_TABLES=${INSTALL_PRESENCE_TABLES:-ask}
  24. INSTALL_DBUID_TABLES=${INSTALL_DBUID_TABLES:-ask}
  25. # Used by dbtext and db_berkeley to define tables to be created, used by
  26. # postgres to do the grants
  27. STANDARD_TABLES=${STANDARD_TABLES:-'version acc dbaliases domain domain_attrs
  28. grp uri speed_dial lcr_gw lcr_rule lcr_rule_target pdt subscriber
  29. location location_attrs re_grp trusted address missed_calls
  30. usr_preferences aliases silo dialog dialog_vars dispatcher dialplan
  31. acc_cdrs topos_d topos_t'}
  32. EXTRA_TABLES=${EXTRA_TABLES:-'imc_members imc_rooms cpl sip_trace domainpolicy
  33. carrierroute carrier_name domain_name carrierfailureroute userblocklist
  34. globalblocklist htable purplemap uacreg pl_pipes mtree mtrees
  35. sca_subscriptions mohqcalls mohqueues rtpproxy rtpengine
  36. dr_gateways dr_rules dr_gw_lists dr_groups secfilter nds_trusted_domains s_cscf s_cscf_capabilities'}
  37. PRESENCE_TABLES=${PRESENCE_TABLES:-'presentity active_watchers watchers xcap
  38. pua rls_presentity rls_watchers'}
  39. DBUID_TABLES=${UID_TABLES:-'uid_credentials uid_domain uid_domain_attrs
  40. uid_global_attrs uid_uri uid_uri_attrs uid_user_attrs'}
  41. # SQL definitions
  42. # If you change this definitions here, then you must change them
  43. # in ../../lib/srdb1/schema/entities.xml too. They are used in this
  44. # script and needed to be the same as in the database definitions.
  45. # FIXME
  46. FOREVER=${FOREVER:-2030-05-28 21:32:15}
  47. # default location for config files
  48. DEFAULT_CFG_DIR=/usr/local/etc/kamailio
  49. # default location for data files
  50. DEFAULT_DATA_DIR=/usr/local/share/kamailio
  51. # Needed programs
  52. MD5=${MD5:-md5sum}
  53. AWK=${AWK:-awk}
  54. GREP=${GREP:-grep}
  55. SED=${SED:-sed}
  56. # define what modules should be installed
  57. STANDARD_MODULES=${STANDARD_MODULES:-'standard acc lcr domain group
  58. permissions registrar usrloc msilo alias_db uri_db speeddial
  59. avpops auth_db pdt dialog dispatcher dialplan topos'}
  60. PRESENCE_MODULES=${PRESENCE_MODULES:-'presence rls'}
  61. EXTRA_MODULES=${EXTRA_MODULES:-'imc cpl siptrace domainpolicy carrierroute
  62. drouting userblocklist htable purple uac pipelimit mtree sca mohqueue
  63. rtpproxy rtpengine secfilter ims_icscf'}
  64. DBUID_MODULES=${UID_MODULES:-'uid_auth_db uid_avp_db uid_domain uid_gflags
  65. uid_uri_db'}
  66. ############################################################
  67. # common functions
  68. usage() {
  69. COMMAND=`basename $0`
  70. cat <<EOF
  71. $0 $VERSION
  72. usage: $COMMAND create <db name or db_path, optional> ...(creates a new database)
  73. $COMMAND drop <db name or db_path, optional> .....(!entirely deletes tables!)
  74. $COMMAND reinit <db name or db_path, optional> ...(!entirely deletes and than re-creates tables!)
  75. $COMMAND backup <file> ...........................(dumps current database to file)
  76. $COMMAND restore <file> ..........................(restores tables from a file)
  77. $COMMAND copy <new_db> ...........................(creates a new db from an existing one)
  78. $COMMAND presence ................................(adds the presence related tables)
  79. $COMMAND extra ...................................(adds the extra tables)
  80. $COMMAND dbuid ...................................(adds the uid tables)
  81. $COMMAND dbonly ..................................(creates empty database)
  82. $COMMAND grant ...................................(grant privileges to database)
  83. $COMMAND revoke ..................................(revoke privileges to database)
  84. $COMMAND add-tables <gid> ........................(creates only tables groupped in gid)
  85. if you want to manipulate database as other database user than
  86. root, want to change database name from default value "$DBNAME",
  87. or want to use other values for users and password, edit the
  88. "config vars" section of the command $COMMAND.
  89. $COMMAND pframework create .......................(creates a sample provisioning framework file)
  90. EOF
  91. } #usage
  92. # read realm
  93. prompt_realm()
  94. {
  95. printf "Domain (realm) for the default user 'admin': "
  96. read SIP_DOMAIN
  97. echo
  98. }
  99. # calculate credentials for admin
  100. credentials()
  101. {
  102. HA1=`echo -n "admin:$SIP_DOMAIN:$DBRWPW" | $MD5 | $AWK '{ print $1 }'`
  103. if [ $? -ne 0 ] ; then
  104. merr "HA1 calculation failed"
  105. exit 1
  106. fi
  107. HA1B=`echo -n "admin@$SIP_DOMAIN:$SIP_DOMAIN:$DBRWPW" | $MD5 | $AWK '{ print $1 }'`
  108. if [ $? -ne 0 ] ; then
  109. merr "HA1B calculation failed"
  110. exit 1
  111. fi
  112. #PHPLIB_ID of users should be difficulty to guess for security reasons
  113. NOW=`date`;
  114. PHPLIB_ID=`echo -n "$RANDOM:$NOW:$SIP_DOMAIN" | $MD5 | $AWK '{ print $1 }'`
  115. if [ $? -ne 0 ] ; then
  116. merr "PHPLIB_ID calculation failed"
  117. exit 1
  118. fi
  119. }
  120. # FIXME use the definition from kamctl.base
  121. mdbg() {
  122. if [ "0$VERBOSE" -ne 0 ] ; then
  123. if [ -t 1 -a -z "$NOHLPRINT" ] ; then
  124. printf "\033[1m%s\033[0m\n" "$1"
  125. else
  126. echo "$1"
  127. fi
  128. fi
  129. }
  130. mwarn() {
  131. if [ -t 1 -a -z "$NOHLPRINT" ] ; then
  132. printf "\033[32;1mWARNING: %s\033[0m\n" "$1"
  133. else
  134. echo "** WARNING: $1"
  135. fi
  136. }
  137. minfo() {
  138. if [ -t 1 -a -z "$NOHLPRINT" ] ; then
  139. printf "\033[33;1mINFO: %s\033[0m\n" "$1"
  140. else
  141. echo "** INFO: $1"
  142. fi
  143. }
  144. mecho() {
  145. if [ -t 1 -a -z "$NOHLPRINT" ] ; then
  146. printf "\033[1m%s\033[0m\n" "$1"
  147. else
  148. echo "$1"
  149. fi
  150. }
  151. merr() {
  152. if [ -t 1 -a -z "$NOHLPRINT" ] ; then
  153. printf "\033[31;1mERROR: %s\033[0m\n" "$1"
  154. else
  155. echo "** ERROR: $1"
  156. fi
  157. }
  158. # Get a y/n value from a variable. If the variable contains the keyword
  159. # `ask', then interactively ask the user for an answer.
  160. #
  161. # Arguments:
  162. # $1 - variable holding yes/no/ask
  163. # $2 - question to print if value of variable is ask
  164. #
  165. # Return:
  166. # On return $ANSWER will be available with y/n
  167. #
  168. get_answer ()
  169. {
  170. value=$1
  171. question=$2
  172. if [ "${value}" = "ask" ]; then
  173. echo -n "$question"
  174. read value
  175. fi
  176. ANSWER=$(echo ${value} | grep -o -e '[YyNn]' | sed -e 's/Y/y/' -e 's/N/n/')
  177. }