kamdbctl.base 6.4 KB

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