deploy_fusionpbx_fedora_server22 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489
  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 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. if [[ ${DB_HOST%%.*} -eq 127 ]] && [[ "$DB_TYPE" != bdr ]]; then
  191. updatedb
  192. postgresql-setup --initdb
  193. if [[ -d "$find_psql_data_dir" ]]; then
  194. echo "PgSQL already initialized continue ..."
  195. systemctl restart ${find_psql_service_file##*/}
  196. rc_pgsql=$(systemctl is-active ${find_psql_service_file##*/})
  197. if [[ "$rc_pgsql" == "failed" ]]; then
  198. echo "Postgresql failed to start, please review the logs and start manually, before proceed with database setup."
  199. pause
  200. fi
  201. mv ${find_psql_data_dir}/pg_hba.conf ${find_psql_data_dir}/pg_hba.conf.orig
  202. mv ${find_psql_data_dir}/postgresql.conf ${find_psql_data_dir}/postgresql.conf.orig
  203. cmd_odbc_fusionpbx > /etc/odbc.ini
  204. cmd_odbc_fusionpbx_p2 >> /etc/odbcinst.ini
  205. cmd_postgres_hba_fusionpbx > ${find_psql_data_dir}/pg_hba.conf
  206. cmd_postgres_conf_fusionpbx > ${find_psql_data_dir}/postgresql.conf
  207. chown -R postgres:postgres ${find_psql_data_dir}
  208. systemctl restart ${find_psql_service_file##*/}
  209. su - postgres -c "echo \"*:*:*:${USERNAME_FUSIONPBX}:${DBNAME_USER_PASSWD}\" > ~/.pgpass; chmod 600 ~/.pgpass"
  210. cmd_create_db
  211. su - postgres -c 'rm -f ~/.pgpass'
  212. else
  213. echo "Unknown error is happed ..."
  214. exit
  215. fi
  216. elif [[ "$DB_TYPE" = bdr ]]; then
  217. updatedb
  218. ${find_psql_db94_setup} initdb
  219. mv ${find_psql_data_dir}/pg_hba.conf ${find_psql_data_dir}/pg_hba.conf.orig
  220. mv ${find_psql_data_dir}/postgresql.conf ${find_psql_data_dir}/postgresql.conf.orig
  221. echo "Setting up SSL certificate for BDR ..."
  222. curl --silent -o /usr/sbin/CertMng http://ftpsrv01.networklab.ca/scripts/CertMng
  223. chmod +x /usr/sbin/CertMng
  224. CertMng --CASetup /etc/pki/pg_bdr
  225. find_cert_cnf=$(find /etc/pki/pg_bdr -maxdepth 1 -type f -name '*.cnf')
  226. CertMng --GenCert ${find_cert_cnf##*/}
  227. rm -f /usr/sbin/CertMng
  228. private_key="/etc/pki/pg_bdr/${my_name}/${my_name}-key-nopasswd.pem"
  229. chmod 600 "$private_key"
  230. cmd_postgres_bdr_conf_fusionpbx > ${find_psql_data_dir}/postgresql.conf
  231. cmd_postgres_conf_fusionpbx >> ${find_psql_data_dir}/postgresql.conf
  232. cmd_postgres_bdr_hba_fusionpbx > ${find_psql_data_dir}/pg_hba.conf
  233. chown -R postgres:postgres ${find_psql_data_dir} /etc/pki/pg_bdr
  234. systemctl restart postgresql-9.4.service
  235. su - postgres -c "echo \"*:*:*:${USERNAME_FUSIONPBX}:${DBNAME_USER_PASSWD}\" > ~/.pgpass; chmod 600 ~/.pgpass"
  236. cmd_create_db
  237. 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
  238. su - postgres -c "psql --command 'CREATE EXTENSION pgcrypto' -d ${DBNAME_FREESWITCH} -w --no-password"
  239. chown postgres:postgres /tmp/freeswitch-pgsql-bdr-1.6.5.sql
  240. sed -i "s/freeswitch/${USERNAME_FUSIONPBX}/" /tmp/freeswitch-pgsql-bdr-1.6.5.sql
  241. su - postgres -c "psql -d ${DBNAME_FREESWITCH} -w --no-password -f /tmp/freeswitch-pgsql-bdr-1.6.5.sql -L /tmp/sql.log"
  242. su - postgres -c 'rm -f ~/.pgpass'
  243. rm -f /tmp/freeswitch-pgsql-bdr-1.6.5.sql
  244. echo -ne "\e[31mI added to pg_hba.conf file only myself please add rest replication members.\e[0m\n"
  245. sleep 4
  246. else
  247. read -r -p "Do you want me deploy PgSQL on remote host? [Y/n] " answer
  248. if [[ $answer =~ ^([yY][eE][sS]|[yY])$ ]]; then
  249. echo -ne "\e[31mPlease make sure ssh key installed and tested with root access.\e[0m\n"
  250. pause
  251. echo -ne "\e[31mIf entered PgPool2 VIP ip then answer here are 'No' and enter actual database server ip.\e[0m\n"
  252. read -r -p "Is IP/Hostname [$DB_HOST] correct ? [Y/n] " answer
  253. if [[ $answer =~ ^([yY][eE][sS]|[yY])$ ]]; then
  254. deploy_remote_pgsql
  255. ssh "$DB_HOST" -l root -o 'LogLevel ERROR' -o 'StrictHostKeyChecking=no' -t -t "$(</tmp/deploy_remote_pgsql)"
  256. else
  257. read -r -p "Please enter IP/Hostname of PgSQL server: " new_ip_address
  258. deploy_remote_pgsql
  259. ssh "$new_ip_address" -l root -o 'LogLevel ERROR' -o 'StrictHostKeyChecking=no' -t -t "$(</tmp/deploy_remote_pgsql)"
  260. fi
  261. else
  262. echo "Continue on set FusionPbx setup ..."
  263. fi
  264. fi
  265. echo "Setting up firewalld ..."
  266. default_interface=$(ip -o route get 8.8.8.8 | awk '{print $5}')
  267. get_zone=$(firewall-cmd --get-zone-of-interface=$default_interface)
  268. pre_array_list=(
  269. "PRE -i $default_interface+ -m recent --update --name MYSIP -j ACCEPT"
  270. "PRE -i $default_interface+ -p tcp --dport 5060:5082 -m string --string sip:${PUBLICHOSTNAME} --algo bm --icase -j NEWSIP"
  271. "PRE -i $default_interface+ -p udp --dport 5060:5082 -m string --string sip:${PUBLICHOSTNAME} --algo bm --to 1500 --icase -j NEWSIP"
  272. "PRE -i $default_interface+ -m recent --update --name BADSIP -j DROP"
  273. "PRE -i $default_interface+ -p tcp --dport 5060:5082 -j TCPSIP"
  274. "PRE -i $default_interface+ -p udp --dport 5060:5082 -j UDPSIP"
  275. "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"
  276. "LOG01 -m comment --comment SIP-TRAFFIC-CHECK-LOG -j ACCEPT"
  277. "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"
  278. "LOG02 -m comment --comment BAD-SIP-SCANNER-LOG -j DROP"
  279. "TCPSIP -m string --string sundayddr --algo bm -j BADSIP"
  280. "TCPSIP -m string --string sipsak --algo bm -j BADSIP"
  281. "TCPSIP -m string --string sipvicious --algo bm --icase -j BADSIP"
  282. "TCPSIP -m string --string friendly-scanner --algo bm -j BADSIP"
  283. "TCPSIP -m string --string iWar --algo bm -j BADSIP"
  284. "TCPSIP -m string --string sip-scan --algo bm -j BADSIP"
  285. "TCPSIP -m string --string sipcli --algo bm -j BADSIP"
  286. "TCPSIP -m string --string eyeBeam --algo bm -j BADSIP"
  287. "TCPSIP -m string --string VaxSIPUserAgent --algo bm -j BADSIP"
  288. "TCPSIP -m string --string sip:nm@nm --algo bm -j BADSIP"
  289. "TCPSIP -m string --string sip:[email protected] --algo bm -j BADSIP"
  290. "UDPSIP -m string --string sundayddr --algo bm --to 1500 -j BADSIP"
  291. "UDPSIP -m string --string sipsak --algo bm --to 1500 -j BADSIP"
  292. "UDPSIP -m string --string sipvicious --algo bm --icase --to 1500 -j BADSIP"
  293. "UDPSIP -m string --string friendly-scanner --algo bm --to 1500 -j BADSIP"
  294. "UDPSIP -m string --string iWar --algo bm --to 1500 -j BADSIP"
  295. "UDPSIP -m string --string sip-scan --algo bm --to 1500 -j BADSIP"
  296. "UDPSIP -m string --string sipcli --algo bm --to 1500 -j BADSIP"
  297. "UDPSIP -m string --string eyeBeam --algo bm --to 1500 -j BADSIP"
  298. "UDPSIP -m string --string VaxSIPUserAgent --algo bm --to 1500 -j BADSIP"
  299. "UDPSIP -m string --string sip:nm@nm --algo bm --to 1500 -j BADSIP"
  300. "UDPSIP -m string --string sip:[email protected] --algo bm --to 1500 -j BADSIP"
  301. "BADSIP -m recent --set --name BADSIP -g LOG02"
  302. "NEWSIP -m recent --set --name MYSIP -g LOG01"
  303. )
  304. for chain in {BADSIP,TCPSIP,UDPSIP,NEWSIP,LOG01,LOG02}; do
  305. firewall-cmd --permanent --direct --add-chain ipv4 raw "$chain"
  306. done
  307. echo "Starting update firewalld rules ..."
  308. num=0
  309. for pre_rule in "${pre_array_list[@]}"; do
  310. i=$((num++))
  311. echo "Adding rule number: $i"
  312. if [[ "$pre_rule" = PRE* ]]; then
  313. firewall-cmd --permanent --direct --add-rule ipv4 raw PREROUTING ${i} ${pre_rule#PRE }
  314. elif [[ "$pre_rule" = LOG01* ]]; then
  315. firewall-cmd --permanent --direct --add-rule ipv4 raw LOG01 ${i} ${pre_rule#LOG01 }
  316. elif [[ "$pre_rule" = LOG02* ]]; then
  317. firewall-cmd --permanent --direct --add-rule ipv4 raw LOG02 ${i} ${pre_rule#LOG02 }
  318. elif [[ "$pre_rule" = TCPSIP* ]]; then
  319. firewall-cmd --permanent --direct --add-rule ipv4 raw TCPSIP ${i} ${pre_rule#TCPSIP }
  320. elif [[ "$pre_rule" = UDPSIP* ]]; then
  321. firewall-cmd --permanent --direct --add-rule ipv4 raw UDPSIP ${i} ${pre_rule#UDPSIP }
  322. elif [[ "$pre_rule" = BADSIP* ]]; then
  323. firewall-cmd --permanent --direct --add-rule ipv4 raw BADSIP ${i} ${pre_rule#BADSIP }
  324. elif [[ "$pre_rule" = NEWSIP* ]]; then
  325. firewall-cmd --permanent --direct --add-rule ipv4 raw NEWSIP ${i} ${pre_rule#NEWSIP }
  326. else
  327. echo "Didn't found any firewalld rule .."
  328. fi
  329. done
  330. service_file_array=( $(find /etc/firewalld/services -maxdepth 1 -type f -name '*.xml') )
  331. for file in "${service_file_array[@]##*/}"; do
  332. firewall-cmd --permanent --zone "$get_zone" --add-service "${file%.xml}"
  333. done
  334. firewall-cmd --reload
  335. echo "Setting up certificate for freeswitch ..."
  336. if [ ! -d /etc/freeswitch/ssl ]; then
  337. mkdir -p /etc/freeswitch/ssl/CA
  338. fi
  339. if (shopt -s nullglob dotglob; f=(/etc/freeswitch/ssl/CA/*); ((! ${#f[@]}))); then
  340. sed -i '/^CONFDIR=*/d' /usr/bin/gentls_cert
  341. sed -i '/^DAYS=*/a \CONFDIR=\/etc\/freeswitch/ssl' /usr/bin/gentls_cert
  342. /usr/bin/gentls_cert setup -cn ${PUBLICHOSTNAME} -alt DNS:${PUBLICHOSTNAME} -org ${DOMAINNAME}
  343. fi
  344. shopt -u nullglob dotglob
  345. cat <<EOT
  346. ******************************
  347. Almost done! Now certificates for encryption of TLS and SRTP will be created. Answer yes when asked to create the certificates.
  348. ******************************
  349. EOT
  350. /usr/bin/gentls_cert create_server -cn ${PUBLICHOSTNAME} -alt DNS:${PUBLICHOSTNAME} -org ${DOMAINNAME}
  351. chmod 640 /etc/freeswitch/ssl/agent.pem
  352. chmod 640 /etc/freeswitch/ssl/CA/cacert.pem
  353. chmod 640 /etc/freeswitch/ssl/cafile.pem
  354. /usr/bin/gentls_cert create_client -cn client.${DOMAINNAME} -out phone
  355. echo "Correcting all permissions ..."
  356. usermod -G daemon nginx
  357. mkdir -p /etc/fusionpbx
  358. cp -rp /usr/share/nginx/fusionpbx/resources/install/scripts/* /usr/share/freeswitch/scripts
  359. chown -R freeswitch:daemon /etc/freeswitch
  360. chown -R freeswitch:daemon /usr/share/freeswitch
  361. chown -R nginx:nginx /usr/share/nginx/fusionpbx
  362. chown -R nginx:nginx /var/lib/php/session
  363. chown -R nginx:nginx /etc/fusionpbx
  364. rm -f /etc/freeswitch/sip_profiles/{external-ipv6.xml,external.xml,internal-ipv6.xml,internal.xml}
  365. # Inside directory
  366. cd /etc/freeswitch
  367. find . -type f -exec chmod 0660 {} \;
  368. find . -type d -exec chmod 0760 {} \;
  369. # XML Edtior
  370. fix_perm
  371. cd /var/lib/freeswitch
  372. find . -type f -exec chmod 0660 {} \;
  373. find . -type d -exec chmod 0760 {} \;
  374. fix_perm
  375. cd /usr/share/freeswitch/scripts
  376. find . -type f -exec chmod 0660 {} \;
  377. find . -type d -exec chmod 0760 {} \;
  378. fix_perm
  379. # Actual directory
  380. for dir in {'/etc/freeswitch','/var/lib/freeswitch','/usr/share/freeswitch/scripts'}; do
  381. perm=$(stat -c '%a %n' $dir | awk {'print $1'})
  382. if [[ "$perm" != 760 ]]; then
  383. chmod 0760 "$dir"
  384. fi
  385. setfacl -m user:nginx:rwx,group:nginx:rwx "$dir"
  386. done
  387. echo "Correcting freeswitch configuration file ..."
  388. line1="<X-PRE-PROCESS cmd=\"set\" data=\"dsn=pgsql://hostaddr=${DB_HOST} dbname=${DBNAME_FREESWITCH} user=${USERNAME_FUSIONPBX} password=${DBNAME_USER_PASSWD}\"/>"
  389. if [[ "$DB_TYPE" = bdr ]]; then
  390. line2='<param name="auto-create-schemas" value="false"/>'
  391. else
  392. line2='<param name="auto-create-schemas" value="true"/>'
  393. fi
  394. line3="<param name=\"odbc-dsn\" value=\"$${dsn}\"/>"
  395. line4="<param name=\"core-db-dsn\" value=\"$${dsn}\"/>"
  396. line5='security.limit_extensions = .php .html .js .gif .png'
  397. line6='user = nginx'
  398. line7='group = nginx'
  399. line8='listen = 9000'
  400. line9='<param name="xml-handler-script" value="app.lua xml_handler"/>'
  401. line10='<param name="xml-handler-bindings" value="configuration,dialplan,directory"/>'
  402. line11='<param name="script-directory" value="/usr/share/freeswitch/scripts/?.lua"/>'
  403. line12='<X-PRE-PROCESS cmd="set" data="json_db_handle=$${dsn}"/>'
  404. file_add2="/etc/freeswitch/autoload_configs/switch.conf.xml"
  405. file_add5="/etc/freeswitch/autoload_configs/db.conf.xml"
  406. file_add6="/etc/freeswitch/autoload_configs/lcr.conf.xml"
  407. file_add7="/etc/php-fpm.d/www.conf"
  408. file_add8="/etc/freeswitch/autoload_configs/lua.conf.xml"
  409. file_add9="/etc/freeswitch/vars.xml"
  410. sed -i -e '/^user=*/d' -e '/^group=*/d' -e '/^listen=*/d' "$file_add7"
  411. sed -i "154 i \ \ $line4" "$file_add2"
  412. sed -i "155 i \ \ $line2" "$file_add2"
  413. sed -i "3 i \ \ $line3" "$file_add5"
  414. sed -i "3 i \ \ $line3" "$file_add6"
  415. sed -i "373 i \ \ $line5" "$file_add7"
  416. sed -i "23 i \ \ $line6" "$file_add7"
  417. sed -i "25 i \ \ $line7" "$file_add7"
  418. sed -i "40 i \ \ $line8" "$file_add7"
  419. sed -i "3 i \ \ $line9" "$file_add8"
  420. sed -i "4 i \ \ $line10" "$file_add8"
  421. sed -i "6 i \ \ $line11" "$file_add8"
  422. sed -i "261 i \ \ $line1" "$file_add9"
  423. echo "Correcting start up services ..."
  424. if [[ ${DB_HOST%%.*} -eq 127 ]]; then
  425. systemctl enable ${find_psql_service_file##*/}
  426. systemctl restart ${find_psql_service_file##*/}
  427. fi
  428. for service in {php-fpm,freeswitch,nginx,memcached,fail2ban,firewalld,ulogd}; do
  429. systemctl enable "${service/%/.service}"
  430. systemctl restart "${service/%/.service}"
  431. done
  432. echo "Installing crontab jobs for xml cdr..."
  433. cmd_crontab_fusionpbx > /etc/cron.d/xml_cdr_fusionpbx
  434. web_interface=${my_ip}
  435. echo -n "
  436. As long as you didnt see errors by this point Firewalls, PostgreSQL, FreeSWITCH, FusionPBX, Fail2Ban, Monit should be installed.
  437. Point your browser to http://$web_interface:82/ and let the FusionPBX installer take it from there.
  438. Please use user name and password previously set in \"Database setup section\" to complete database setup in FusionPBX Setup Wizard.
  439. For post installation task visit wiki page https://networklab.freshdesk.com/solution/articles/6000030050-post-installation-task.
  440. "