deploy_fusionpbx_fedora_server22 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496
  1. #!/bin/bash
  2. ###############################################
  3. #
  4. # Installation Script to Install FreeSWITCH, FusionPBX, PostgreSQL, PHP, Apache and required
  5. # Supporting software on Centos 6.
  6. # Copyright (C) 2011, Ken Rice <[email protected]>
  7. #
  8. # Version: MPL 1.1
  9. #
  10. # The contents of this file are subject to the Mozilla Public License Version
  11. # 1.1 (the "License"); you may not use this file except in compliance with
  12. # the License. You may obtain a copy of the License at
  13. # http://www.mozilla.org/MPL/
  14. #
  15. # Software distributed under the License is distributed on an "AS IS" basis,
  16. # WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  17. # for the specific language governing rights and limitations under the
  18. # License.
  19. #
  20. # The Initial Developer of the Original Code is
  21. # Ken Rice <[email protected]>
  22. # Portions created by the Initial Developer are Copyright (C)
  23. # the Initial Developer. All Rights Reserved.
  24. #
  25. # Contributor(s):
  26. #
  27. # Slava Bendersky [email protected]
  28. # Also thanks to:
  29. # The FreeSWITCH, FusionPBX and PostgreSQL Crews without them, none of this would be possible
  30. #
  31. ###############################################
  32. VERSION="1.2"
  33. ###########################################
  34. ## Set Defaults for Variables
  35. defSUPPORTNAME='Company Name'
  36. defSUPPORTEMAIL='[email protected]'
  37. defPUBLICHOSTNAME='voice.example.com'
  38. defDOMAINNAME='example.com'
  39. defUSERNAME_FUSIONPBX='fusionpbx'
  40. defDB_HOST='127.0.0.1'
  41. defDBNAME_FUSIONPBX='fusionpbx'
  42. defDBNAME_FREESWITCH='freeswitch'
  43. ###########################################
  44. if [[ "$EUID" -ne 0 ]]; then
  45. echo "Please run as root ..."
  46. exit 1
  47. fi
  48. # Install functions.
  49. . ./install-functions_fedora_server22
  50. #get the machine type x86_64
  51. MACHINE_TYPE=$(uname -m)
  52. cat <<EOT
  53. This Script will install basic configuration required to run FusionPBX on Fedora22 server
  54. As with anything you will want to review the configs after the installer to make sure they are what you want.
  55. This is Version $VERSION of this script.
  56. EOT
  57. read -p "SNMP Support Name [$defSUPPORTNAME]: " -e t1
  58. if [ -n "$t1" ]
  59. then
  60. SUPPORTNAME="$t1"
  61. else
  62. SUPPORTNAME="$defSUPPORTNAME"
  63. fi
  64. read -p "Support Email [$defSUPPORTEMAIL]: " -e t1
  65. if [ -n "$t1" ]
  66. then
  67. SUPPORTEMAIL="$t1"
  68. else
  69. SUPPORTEMAIL="$defSUPPORTEMAIL"
  70. fi
  71. read -p "Domain Name [$defDOMAINNAME]: " -e t1
  72. if [ -n "$t1" ]
  73. then
  74. DOMAINNAME="$t1"
  75. else
  76. DOMAINNAME="$defDOMAINNAME"
  77. fi
  78. defPUBLICHOSTNAME="sip.${DOMAINNAME}"
  79. read -p "Public Hostname [$defPUBLICHOSTNAME]: " -e t1
  80. if [ -n "$t1" ]
  81. then
  82. PUBLICHOSTNAME="$t1"
  83. else
  84. PUBLICHOSTNAME="$defPUBLICHOSTNAME"
  85. fi
  86. read -r -p "Do you want deploy database on same server ? [Y/n] " answer
  87. if [[ $answer =~ ^([yY][eE][sS]|[yY])$ ]]; then
  88. DB_HOST="$defDB_HOST"
  89. read -p "User name for fusionpbx database [$defUSERNAME_FUSIONPBX]: " -e t1
  90. if [ -n "$t1" ]
  91. then
  92. USERNAME_FUSIONPBX="$t1"
  93. else
  94. USERNAME_FUSIONPBX="$defUSERNAME_FUSIONPBX"
  95. fi
  96. read -p "Database name for freeswitch database [$defDBNAME_FREESWITCH]: " -e t1
  97. if [ -n "$t1" ]
  98. then
  99. DBNAME_FREESWITCH="$t1"
  100. else
  101. DBNAME_FREESWITCH="$defDBNAME_FREESWITCH"
  102. fi
  103. read -p "Database name for fusionpbx database [$defDBNAME_FUSIONPBX]: " -e t1
  104. if [ -n "$t1" ]
  105. then
  106. DBNAME_FUSIONPBX="$t1"
  107. else
  108. DBNAME_FUSIONPBX="$defDBNAME_FUSIONPBX"
  109. fi
  110. read -s -p "Enter database user password: " psql_passwd
  111. DBNAME_FREESWITCH_PASSWD="$psql_passwd"
  112. DBNAME_USER_PASSWD="$psql_passwd"
  113. if [[ ${DB_HOST%%.*} -eq 127 ]]; then
  114. read -r -p "Do you want deploy database with BDR (PgSQL Multi Master Replication) ? [Y/n] " bdr_answer
  115. if [[ $bdr_answer =~ ^([yY][eE][sS]|[yY])$ ]]; then
  116. DB_TYPE="bdr"
  117. fi
  118. fi
  119. read -r -p "Are you sure? [Y/n] " response
  120. if [[ $response =~ ^([yY][eE][sS]|[yY])$ ]]; then
  121. echo -n "Here we go..."
  122. else
  123. echo "Aborting:"
  124. exit
  125. fi
  126. if [[ "$DB_TYPE" != bdr ]]; then
  127. dnf -y install postgresql-server postgresql-contrib
  128. else
  129. rc=$(rpm -q postgresql-bdr94-2ndquadrant-fedora >/dev/null 2>&1; echo $?)
  130. if [[ $rc -ne 0 ]]; then
  131. dnf install -y http://packages.2ndquadrant.com/postgresql-bdr94-2ndquadrant/yum-repo-rpms/postgresql-bdr94-2ndquadrant-fedora-1.0-2.noarch.rpm
  132. dnf install -y postgresql-bdr94-bdr postgresql-bdr94-contrib
  133. else
  134. dnf install -y postgresql-bdr94-bdr postgresql-bdr94-contrib
  135. fi
  136. fi
  137. else
  138. echo -ne "\e[31mIf deployed pgpool2 with watchdog enter VIP (Virtual IP/Hostname).\e[0m\n"
  139. read -r -p "Please enter IP/Hostname of database server: " ip_address
  140. DB_HOST="$ip_address"
  141. fi
  142. ###############
  143. #install dependencies
  144. echo "Installing required repository ..."
  145. dnf -y install http://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-22.noarch.rpm
  146. dnf -y install http://download1.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-22.noarch.rpm
  147. cmd_yum_repo_fusionpbx > /etc/yum.repos.d/networklab.repo
  148. dnf -y install pgtune freeswitch freeswitch-config-vanilla freeswitch-application-valet_parking freeswitch-sounds-* freeswitch-codec-* freeswitch-application-memcache freeswitch-lang-* freeswitch-lua freeswitch-application-voicemail-ivr freeswitch-application-directory freeswitch-application-voicemail freeswitch-application-db freeswitch-application-callcenter freeswitch-application-limit freeswitch-application-curl freeswitch-xml-cdr freeswitch-format-mod-shout freeswitch-v8 freeswitch-application-enum incron chrony ipset git memcached fail2ban fail2ban-firewalld ulogd sudo ghostscript libtiff vim wget net-snmp net-snmp-utils postgresql-odbc nginx php-common php-pdo php-process php-pgsql php-soap php-odbc php-xml php-xmlrpc php-pgsql php-fpm php-cli php-pear php-pdo php-gd php-mbstring php-mcrypt
  149. if [[ $? -eq 0 ]]; then
  150. echo "Setting up configuration file ..."
  151. mv /etc/ulogd.conf /etc/ulogd.conf.orig
  152. mv /etc/snmp/snmpd.conf /etc/snmp/snmpd.conf.orig
  153. cmd_ulogd_fusionpbx > /etc/ulogd.conf
  154. cmd_nginx_fusionpbx > /etc/nginx/conf.d/fusionpbx.conf
  155. cmd_snmp_fusionpbx > /etc/snmp/snmpd.conf
  156. cmd_fail2ban_fusionpbx > /etc/fail2ban/jail.conf
  157. cmd_service_sip-ext > /etc/firewalld/services/sip-ext.xml
  158. cmd_service_sip-int > /etc/firewalld/services/sip-int.xml
  159. cmd_service_chronyd > /etc/firewalld/services/chronyd.xml
  160. cmd_service_snmp > /etc/firewalld/services/snmp.xml
  161. cmd_service_www > /etc/firewalld/services/www.xml
  162. cmd_service_rtp > /etc/firewalld/services/rtp.xml
  163. cmd_service_xml_rpc > /etc/firewalld/services/xml-rpc.xml
  164. cmd_sysconfig_freeswitch > /etc/sysconfig/freeswitch
  165. else
  166. echo "Something happened, please review it .."
  167. pause
  168. fi
  169. # Find pgsql staff
  170. find_psql_lib=$(find /usr -name psqlodbcw.so)
  171. find_psql_data_dir=$(find /var/lib/pgsql -type d -name data)
  172. if [[ "$DB_TYPE" != bdr ]]; then
  173. find_psql_service_file=$(find /usr/lib/systemd/system -type f -name postgresql.service)
  174. else
  175. find_psql_service_file=$(find /usr/lib/systemd/system -type f -name postgresql*.service)
  176. fi
  177. find_psql_db94_setup=$(find / -type f -name postgresql94-setup)
  178. my_ip=$(ip -o route get 8.8.8.8 | awk '{print $7}')
  179. my_name=(hostname -s)
  180. echo "Adjusting firewalld logs ..."
  181. mkdir -p /var/log/firewalld_log
  182. echo "Adjusting Selinux ..."
  183. if [[ -x /usr/sbin/setenforce ]]; then
  184. /usr/sbin/setenforce 0
  185. /bin/sed -i -e s,'SELINUX=enforcing','SELINUX=disabled', /etc/sysconfig/selinux
  186. /bin/sed -i -e s,'SELINUX=enforcing','SELINUX=disabled', /etc/selinux/config
  187. fi
  188. echo "Setting up FusionPBX web app ..."
  189. deploy_fusion_pbx /usr/share/nginx/fusionpbx
  190. echo "Setting up Database PgSQL ..."
  191. if [[ ${DB_HOST%%.*} -eq 127 ]] && [[ "$DB_TYPE" != bdr ]]; then
  192. updatedb
  193. postgresql-setup --initdb
  194. if [[ -d "$find_psql_data_dir" ]]; then
  195. echo "PgSQL already initialized continue ..."
  196. systemctl restart ${find_psql_service_file##*/}
  197. rc_pgsql=$(systemctl is-active ${find_psql_service_file##*/})
  198. if [[ "$rc_pgsql" == "failed" ]]; then
  199. echo "Postgresql failed to start, please review the logs and start manually, before proceed with database setup."
  200. pause
  201. fi
  202. mv ${find_psql_data_dir}/pg_hba.conf ${find_psql_data_dir}/pg_hba.conf.orig
  203. mv ${find_psql_data_dir}/postgresql.conf ${find_psql_data_dir}/postgresql.conf.orig
  204. cmd_odbc_fusionpbx > /etc/odbc.ini
  205. cmd_odbc_fusionpbx_p2 >> /etc/odbcinst.ini
  206. cmd_postgres_hba_fusionpbx > ${find_psql_data_dir}/pg_hba.conf
  207. cmd_postgres_conf_fusionpbx > ${find_psql_data_dir}/postgresql.conf
  208. pgtune -c 600 -i ${find_psql_data_dir}/postgresql.conf >/tmp/pgtune.conf
  209. mv ${find_psql_data_dir}/postgresql.conf{,.bak}
  210. cp /tmp/pgtune.conf ${find_psql_data_dir}/postgresql.conf
  211. chown -R postgres:postgres ${find_psql_data_dir}
  212. systemctl restart ${find_psql_service_file##*/}
  213. su - postgres -c "echo \"*:*:*:${USERNAME_FUSIONPBX}:${DBNAME_USER_PASSWD}\" > ~/.pgpass; chmod 600 ~/.pgpass"
  214. cmd_create_db
  215. su - postgres -c 'rm -f ~/.pgpass'
  216. else
  217. echo "Unknown error is happed ..."
  218. exit
  219. fi
  220. elif [[ "$DB_TYPE" = bdr ]]; then
  221. updatedb
  222. ${find_psql_db94_setup} initdb
  223. mv ${find_psql_data_dir}/pg_hba.conf ${find_psql_data_dir}/pg_hba.conf.orig
  224. mv ${find_psql_data_dir}/postgresql.conf ${find_psql_data_dir}/postgresql.conf.orig
  225. echo "Setting up SSL certificate for BDR ..."
  226. curl --silent -o /usr/sbin/CertMng http://ftpsrv01.networklab.ca/scripts/CertMng
  227. chmod +x /usr/sbin/CertMng
  228. CertMng --CASetup /etc/pki/pg_bdr
  229. find_cert_cnf=$(find /etc/pki/pg_bdr -maxdepth 1 -type f -name '*.cnf')
  230. CertMng --GenCert ${find_cert_cnf##*/}
  231. rm -f /usr/sbin/CertMng
  232. private_key="/etc/pki/pg_bdr/${my_name}/${my_name}-key-nopasswd.pem"
  233. chmod 600 "$private_key"
  234. cmd_postgres_bdr_conf_fusionpbx > ${find_psql_data_dir}/postgresql.conf
  235. cmd_postgres_conf_fusionpbx >> ${find_psql_data_dir}/postgresql.conf
  236. cmd_postgres_bdr_hba_fusionpbx > ${find_psql_data_dir}/pg_hba.conf
  237. pgtune -c 600 -i ${find_psql_data_dir}/postgresql.conf >/tmp/pgtune.conf
  238. mv ${find_psql_data_dir}/postgresql.conf{,.bak}
  239. cp /tmp/pgtune.conf ${find_psql_data_dir}/postgresql.conf
  240. chown -R postgres:postgres ${find_psql_data_dir} /etc/pki/pg_bdr
  241. systemctl restart postgresql-9.4.service
  242. su - postgres -c "echo \"*:*:*:${USERNAME_FUSIONPBX}:${DBNAME_USER_PASSWD}\" > ~/.pgpass; chmod 600 ~/.pgpass"
  243. cmd_create_db
  244. curl --silent -u fusionpbx_Admin:dron12345 --silent -o /tmp/freeswitch-pgsql-bdr-1.6.5.sql http://ftpsrv01.networklab.ca/misc/freeswitch-pgsql-bdr-1.6.5.sql
  245. su - postgres -c "psql --command 'CREATE EXTENSION pgcrypto' -d ${DBNAME_FREESWITCH} -w --no-password"
  246. chown postgres:postgres /tmp/freeswitch-pgsql-bdr-1.6.5.sql
  247. sed -i "s/freeswitch/${USERNAME_FUSIONPBX}/" /tmp/freeswitch-pgsql-bdr-1.6.5.sql
  248. su - postgres -c "psql -d ${DBNAME_FREESWITCH} -w --no-password -f /tmp/freeswitch-pgsql-bdr-1.6.5.sql -L /tmp/sql.log"
  249. su - postgres -c 'rm -f ~/.pgpass'
  250. rm -f /tmp/freeswitch-pgsql-bdr-1.6.5.sql
  251. echo -ne "\e[31mI added to pg_hba.conf file only myself please add rest replication members.\e[0m\n"
  252. sleep 4
  253. else
  254. read -r -p "Do you want me deploy PgSQL on remote host? [Y/n] " answer
  255. if [[ $answer =~ ^([yY][eE][sS]|[yY])$ ]]; then
  256. echo -ne "\e[31mPlease make sure ssh key installed and tested with root access.\e[0m\n"
  257. pause
  258. echo -ne "\e[31mIf entered PgPool2 VIP ip then answer here are 'No' and enter actual database server ip.\e[0m\n"
  259. read -r -p "Is IP/Hostname [$DB_HOST] correct ? [Y/n] " answer
  260. if [[ $answer =~ ^([yY][eE][sS]|[yY])$ ]]; then
  261. deploy_remote_pgsql
  262. ssh "$DB_HOST" -l root -o 'LogLevel ERROR' -o 'StrictHostKeyChecking=no' -t -t "$(</tmp/deploy_remote_pgsql)"
  263. else
  264. read -r -p "Please enter IP/Hostname of PgSQL server: " new_ip_address
  265. deploy_remote_pgsql
  266. ssh "$new_ip_address" -l root -o 'LogLevel ERROR' -o 'StrictHostKeyChecking=no' -t -t "$(</tmp/deploy_remote_pgsql)"
  267. fi
  268. else
  269. echo "Continue on set FusionPbx setup ..."
  270. fi
  271. fi
  272. echo "Setting up firewalld ..."
  273. default_interface=$(ip -o route get 8.8.8.8 | awk '{print $5}')
  274. get_zone=$(firewall-cmd --get-zone-of-interface=$default_interface)
  275. pre_array_list=(
  276. "PRE -i $default_interface+ -m recent --update --name MYSIP -j ACCEPT"
  277. "PRE -i $default_interface+ -p tcp --dport 5060:5082 -m string --string sip:${PUBLICHOSTNAME} --algo bm --icase -j NEWSIP"
  278. "PRE -i $default_interface+ -p udp --dport 5060:5082 -m string --string sip:${PUBLICHOSTNAME} --algo bm --to 1500 --icase -j NEWSIP"
  279. "PRE -i $default_interface+ -m recent --update --name BADSIP -j DROP"
  280. "PRE -i $default_interface+ -p tcp --dport 5060:5082 -j TCPSIP"
  281. "PRE -i $default_interface+ -p udp --dport 5060:5082 -j UDPSIP"
  282. "LOG01 -m limit --limit 4/min --limit-burst 10 -m comment --comment SIP-TRAFFIC-CHECK-LOG -j NFLOG --nflog-prefix Firewalld:raw-sip2FW:ACCEPT: --nflog-group 2 --nflog-threshold 10"
  283. "LOG01 -m comment --comment SIP-TRAFFIC-CHECK-LOG -j ACCEPT"
  284. "LOG02 -m limit --limit 4/min --limit-burst 10 -m comment --comment BAD-SIP-SCANNER-LOG -j NFLOG --nflog-prefix Firewalld:bad-sip2FW:DROP: --nflog-group 3 --nflog-threshold 10"
  285. "LOG02 -m comment --comment BAD-SIP-SCANNER-LOG -j DROP"
  286. "TCPSIP -m string --string sundayddr --algo bm -j BADSIP"
  287. "TCPSIP -m string --string sipsak --algo bm -j BADSIP"
  288. "TCPSIP -m string --string sipvicious --algo bm --icase -j BADSIP"
  289. "TCPSIP -m string --string friendly-scanner --algo bm -j BADSIP"
  290. "TCPSIP -m string --string iWar --algo bm -j BADSIP"
  291. "TCPSIP -m string --string sip-scan --algo bm -j BADSIP"
  292. "TCPSIP -m string --string sipcli --algo bm -j BADSIP"
  293. "TCPSIP -m string --string eyeBeam --algo bm -j BADSIP"
  294. "TCPSIP -m string --string VaxSIPUserAgent --algo bm -j BADSIP"
  295. "TCPSIP -m string --string sip:nm@nm --algo bm -j BADSIP"
  296. "TCPSIP -m string --string sip:[email protected] --algo bm -j BADSIP"
  297. "UDPSIP -m string --string sundayddr --algo bm --to 1500 -j BADSIP"
  298. "UDPSIP -m string --string sipsak --algo bm --to 1500 -j BADSIP"
  299. "UDPSIP -m string --string sipvicious --algo bm --icase --to 1500 -j BADSIP"
  300. "UDPSIP -m string --string friendly-scanner --algo bm --to 1500 -j BADSIP"
  301. "UDPSIP -m string --string iWar --algo bm --to 1500 -j BADSIP"
  302. "UDPSIP -m string --string sip-scan --algo bm --to 1500 -j BADSIP"
  303. "UDPSIP -m string --string sipcli --algo bm --to 1500 -j BADSIP"
  304. "UDPSIP -m string --string eyeBeam --algo bm --to 1500 -j BADSIP"
  305. "UDPSIP -m string --string VaxSIPUserAgent --algo bm --to 1500 -j BADSIP"
  306. "UDPSIP -m string --string sip:nm@nm --algo bm --to 1500 -j BADSIP"
  307. "UDPSIP -m string --string sip:[email protected] --algo bm --to 1500 -j BADSIP"
  308. "BADSIP -m recent --set --name BADSIP -g LOG02"
  309. "NEWSIP -m recent --set --name MYSIP -g LOG01"
  310. )
  311. for chain in {BADSIP,TCPSIP,UDPSIP,NEWSIP,LOG01,LOG02}; do
  312. firewall-cmd --permanent --direct --add-chain ipv4 raw "$chain"
  313. done
  314. echo "Starting update firewalld rules ..."
  315. num=0
  316. for pre_rule in "${pre_array_list[@]}"; do
  317. i=$((num++))
  318. echo "Adding rule number: $i"
  319. if [[ "$pre_rule" = PRE* ]]; then
  320. firewall-cmd --permanent --direct --add-rule ipv4 raw PREROUTING ${i} ${pre_rule#PRE }
  321. elif [[ "$pre_rule" = LOG01* ]]; then
  322. firewall-cmd --permanent --direct --add-rule ipv4 raw LOG01 ${i} ${pre_rule#LOG01 }
  323. elif [[ "$pre_rule" = LOG02* ]]; then
  324. firewall-cmd --permanent --direct --add-rule ipv4 raw LOG02 ${i} ${pre_rule#LOG02 }
  325. elif [[ "$pre_rule" = TCPSIP* ]]; then
  326. firewall-cmd --permanent --direct --add-rule ipv4 raw TCPSIP ${i} ${pre_rule#TCPSIP }
  327. elif [[ "$pre_rule" = UDPSIP* ]]; then
  328. firewall-cmd --permanent --direct --add-rule ipv4 raw UDPSIP ${i} ${pre_rule#UDPSIP }
  329. elif [[ "$pre_rule" = BADSIP* ]]; then
  330. firewall-cmd --permanent --direct --add-rule ipv4 raw BADSIP ${i} ${pre_rule#BADSIP }
  331. elif [[ "$pre_rule" = NEWSIP* ]]; then
  332. firewall-cmd --permanent --direct --add-rule ipv4 raw NEWSIP ${i} ${pre_rule#NEWSIP }
  333. else
  334. echo "Didn't found any firewalld rule .."
  335. fi
  336. done
  337. service_file_array=( $(find /etc/firewalld/services -maxdepth 1 -type f -name '*.xml') )
  338. for file in "${service_file_array[@]##*/}"; do
  339. firewall-cmd --permanent --zone "$get_zone" --add-service "${file%.xml}"
  340. done
  341. firewall-cmd --reload
  342. echo "Setting up certificate for freeswitch ..."
  343. if [ ! -d /etc/freeswitch/ssl ]; then
  344. mkdir -p /etc/freeswitch/ssl/CA
  345. fi
  346. if (shopt -s nullglob dotglob; f=(/etc/freeswitch/ssl/CA/*); ((! ${#f[@]}))); then
  347. sed -i '/^CONFDIR=*/d' /usr/bin/gentls_cert
  348. sed -i '/^DAYS=*/a \CONFDIR=\/etc\/freeswitch/ssl' /usr/bin/gentls_cert
  349. /usr/bin/gentls_cert setup -cn ${PUBLICHOSTNAME} -alt DNS:${PUBLICHOSTNAME} -org ${DOMAINNAME}
  350. fi
  351. shopt -u nullglob dotglob
  352. cat <<EOT
  353. ******************************
  354. Almost done! Now certificates for encryption of TLS and SRTP will be created. Answer yes when asked to create the certificates.
  355. ******************************
  356. EOT
  357. /usr/bin/gentls_cert create_server -cn ${PUBLICHOSTNAME} -alt DNS:${PUBLICHOSTNAME} -org ${DOMAINNAME}
  358. chmod 640 /etc/freeswitch/ssl/agent.pem
  359. chmod 640 /etc/freeswitch/ssl/CA/cacert.pem
  360. chmod 640 /etc/freeswitch/ssl/cafile.pem
  361. /usr/bin/gentls_cert create_client -cn client.${DOMAINNAME} -out phone
  362. echo "Correcting all permissions ..."
  363. usermod -G daemon nginx
  364. mkdir -p /etc/fusionpbx
  365. cp -rp /usr/share/nginx/fusionpbx/resources/install/scripts/* /usr/share/freeswitch/scripts
  366. chown -R freeswitch:daemon /etc/freeswitch
  367. chown -R freeswitch:daemon /usr/share/freeswitch
  368. chown -R nginx:nginx /usr/share/nginx/fusionpbx
  369. chown -R nginx:nginx /var/lib/php/session
  370. chown -R nginx:nginx /etc/fusionpbx
  371. rm -f /etc/freeswitch/sip_profiles/{external-ipv6.xml,external.xml,internal-ipv6.xml,internal.xml}
  372. # Inside directory
  373. cd /etc/freeswitch
  374. find . -type f -exec chmod 0660 {} \;
  375. find . -type d -exec chmod 0760 {} \;
  376. # XML Edtior
  377. fix_perm
  378. cd /var/lib/freeswitch
  379. find . -type f -exec chmod 0660 {} \;
  380. find . -type d -exec chmod 0760 {} \;
  381. fix_perm
  382. cd /usr/share/freeswitch/scripts
  383. find . -type f -exec chmod 0660 {} \;
  384. find . -type d -exec chmod 0760 {} \;
  385. fix_perm
  386. # Actual directory
  387. for dir in {'/etc/freeswitch','/var/lib/freeswitch','/usr/share/freeswitch/scripts'}; do
  388. perm=$(stat -c '%a %n' $dir | awk {'print $1'})
  389. if [[ "$perm" != 760 ]]; then
  390. chmod 0760 "$dir"
  391. fi
  392. setfacl -m user:nginx:rwx,group:nginx:rwx "$dir"
  393. done
  394. echo "Correcting freeswitch configuration file ..."
  395. line1="<X-PRE-PROCESS cmd=\"set\" data=\"dsn=pgsql://hostaddr=${DB_HOST} dbname=${DBNAME_FREESWITCH} user=${USERNAME_FUSIONPBX} password=${DBNAME_USER_PASSWD}\"/>"
  396. if [[ "$DB_TYPE" = bdr ]]; then
  397. line2='<param name="auto-create-schemas" value="false"/>'
  398. else
  399. line2='<param name="auto-create-schemas" value="true"/>'
  400. fi
  401. line3="<param name=\"odbc-dsn\" value=\"$${dsn}\"/>"
  402. line4="<param name=\"core-db-dsn\" value=\"$${dsn}\"/>"
  403. line5='security.limit_extensions = .php .html .js .gif .png'
  404. line6='user = nginx'
  405. line7='group = nginx'
  406. line8='listen = 9000'
  407. line9='<param name="xml-handler-script" value="app.lua xml_handler"/>'
  408. line10='<param name="xml-handler-bindings" value="configuration,dialplan,directory"/>'
  409. line11='<param name="script-directory" value="/usr/share/freeswitch/scripts/?.lua"/>'
  410. line12='<X-PRE-PROCESS cmd="set" data="json_db_handle=$${dsn}"/>'
  411. file_add2="/etc/freeswitch/autoload_configs/switch.conf.xml"
  412. file_add5="/etc/freeswitch/autoload_configs/db.conf.xml"
  413. file_add6="/etc/freeswitch/autoload_configs/lcr.conf.xml"
  414. file_add7="/etc/php-fpm.d/www.conf"
  415. file_add8="/etc/freeswitch/autoload_configs/lua.conf.xml"
  416. file_add9="/etc/freeswitch/vars.xml"
  417. sed -i -e '/^user=*/d' -e '/^group=*/d' -e '/^listen=*/d' "$file_add7"
  418. sed -i "154 i \ \ $line4" "$file_add2"
  419. sed -i "155 i \ \ $line2" "$file_add2"
  420. sed -i "3 i \ \ $line3" "$file_add5"
  421. sed -i "3 i \ \ $line3" "$file_add6"
  422. sed -i "373 i \ \ $line5" "$file_add7"
  423. sed -i "23 i \ \ $line6" "$file_add7"
  424. sed -i "25 i \ \ $line7" "$file_add7"
  425. sed -i "40 i \ \ $line8" "$file_add7"
  426. sed -i "3 i \ \ $line9" "$file_add8"
  427. sed -i "4 i \ \ $line10" "$file_add8"
  428. sed -i "6 i \ \ $line11" "$file_add8"
  429. sed -i "261 i \ \ $line1" "$file_add9"
  430. echo "Correcting start up services ..."
  431. if [[ ${DB_HOST%%.*} -eq 127 ]]; then
  432. systemctl enable ${find_psql_service_file##*/}
  433. systemctl restart ${find_psql_service_file##*/}
  434. fi
  435. for service in {php-fpm,freeswitch,nginx,memcached,fail2ban,firewalld,ulogd}; do
  436. systemctl enable "${service/%/.service}"
  437. systemctl restart "${service/%/.service}"
  438. done
  439. echo "Installing crontab jobs for xml cdr..."
  440. cmd_crontab_fusionpbx > /etc/cron.d/xml_cdr_fusionpbx
  441. web_interface=${my_ip}
  442. echo -n "
  443. As long as you didnt see errors by this point Firewalls, PostgreSQL, FreeSWITCH, FusionPBX, Fail2Ban, Monit should be installed.
  444. Point your browser to http://$web_interface:82/ and let the FusionPBX installer take it from there.
  445. Please use user name and password previously set in \"Database setup section\" to complete database setup in FusionPBX Setup Wizard.
  446. For post installation task visit wiki page https://networklab.freshdesk.com/solution/articles/6000030050-post-installation-task.
  447. "