2
0

kamdbctl.base 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  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. EXTRA_TABLES=${EXTRA_TABLES:-imc_members imc_rooms cpl sip_trace domainpolicy
  30. carrierroute carrier_name domain_name carrierfailureroute userblacklist
  31. globalblacklist htable purplemap uacreg pl_pipes mtree mtrees
  32. sca_subscriptions}
  33. PRESENCE_TABLES=${PRESENCE_TABLES:-presentity active_watchers watchers xcap
  34. pua rls_presentity rls_watchers}
  35. DBUID_TABLES=${UID_TABLES:-uid_credentials uid_domain uid_domain_attrs
  36. uid_global_attrs uid_uri uid_uri_attrs uid_user_attrs}
  37. # SQL definitions
  38. # If you change this definitions here, then you must change them
  39. # in ../../lib/srdb1/schema/entities.xml too. They are used in this
  40. # script and needed to be the same as in the database definitions.
  41. # FIXME
  42. FOREVER=${FOREVER:-2030-05-28 21:32:15}
  43. DEFAULT_ALIASES_EXPIRES=${DEFAULT_ALIASES_EXPIRES:-${FOREVER}}
  44. DEFAULT_Q=${DEFAULT_Q:-1.0}
  45. DEFAULT_CALLID=${DEFAULT_CALLID:-Default-Call-ID}
  46. DEFAULT_CSEQ=${DEFAULT_CSEQ:-13}
  47. DEFAULT_LOCATION_EXPIRES=${DEFAULT_LOCATION_EXPIRES:-${FOREVER}}
  48. # default location for config files
  49. DEFAULT_CFG_DIR=/usr/local/etc/kamailio
  50. # default location for data files
  51. DEFAULT_DATA_DIR=/usr/local/share/kamailio
  52. # Needed programs
  53. MD5=${MD5:-md5sum}
  54. AWK=${AWK:-awk}
  55. GREP=${GREP:-grep}
  56. SED=${SED:-sed}
  57. # define what modules should be installed
  58. STANDARD_MODULES=${STANDARD_MODULES:-standard acc lcr domain group
  59. permissions registrar usrloc msilo alias_db uri_db speeddial
  60. avpops auth_db pdt dialog dispatcher dialplan}
  61. PRESENCE_MODULES=${PRESENCE_MODULES:-presence rls}
  62. EXTRA_MODULES=${EXTRA_MODULES:-imc cpl siptrace domainpolicy carrierroute
  63. userblacklist htable purple uac pipelimit mtree sca}
  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 migrate <old_db> <new_db> ...............(migrates DB from 1.2 to 1.3, not implemented yet!)
  79. $COMMAND presence ................................(adds the presence related tables)
  80. $COMMAND extra ...................................(adds the extra tables)
  81. $COMMAND dbuid ...................................(adds the uid tables)
  82. $COMMAND dbonly ..................................(creates empty database)
  83. $COMMAND grant ...................................(grant privileges to database)
  84. $COMMAND revoke ..................................(revoke privileges to database)
  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. echo -e "\033[1m$1\033[0m"
  125. else
  126. echo "$1"
  127. fi
  128. fi
  129. }
  130. mwarn() {
  131. if [ -t 1 -a -z "$NOHLPRINT" ] ; then
  132. echo -e '\E[37;32m'"\033[1mWARNING: $1\033[0m"
  133. else
  134. echo "** WARNING: $1"
  135. fi
  136. }
  137. minfo() {
  138. if [ -t 1 -a -z "$NOHLPRINT" ] ; then
  139. echo -e '\E[37;33m'"\033[1mINFO: $1\033[0m"
  140. else
  141. echo "** INFO: $1"
  142. fi
  143. }
  144. mecho() {
  145. if [ -t 1 -a -z "$NOHLPRINT" ] ; then
  146. echo -e "\033[1m$1\033[0m"
  147. else
  148. echo "$1"
  149. fi
  150. }
  151. merr() {
  152. if [ -t 1 -a -z "$NOHLPRINT" ] ; then
  153. echo -e '\E[37;31m'"\033[1mERROR: $1\033[0m"
  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 ANSWER
  175. else
  176. ANSWER=${value}
  177. fi
  178. ANSWER=${ANSWER:0:1}
  179. ANSWER=${ANSWER/Y/y}
  180. ANSWER=${ANSWER/N/n}
  181. }