install_fusionpbx_postgres_9.2.sh 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649
  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. # Ken Rice <[email protected]>
  28. # Dar Zuch <[email protected]>
  29. # Mark J Crane <[email protected]>
  30. # Also thanks to:
  31. # The FreeSWITCH, FusionPBX and PostgreSQL Crews without them, none of this would be possible
  32. #
  33. ###############################################
  34. VERSION="0.9"
  35. ###########################################
  36. ## Set Defaults for Variables
  37. defSUPPORTNAME='Company Name'
  38. defSUPPORTEMAIL='[email protected]'
  39. defPUBLICHOSTNAME='voice.example.com'
  40. defDOMAINNAME='example.com'
  41. ###########################################
  42. #get the machine type x86_64
  43. MACHINE_TYPE=`uname -m`
  44. cat <<EOT
  45. This Script will install and create base line configs for FreeSWITCH, FusionPBX, Fail2Ban, Monit and PostgreSQL, TLS.
  46. It is designed to run on a Centos6.2 I386/x86_64 "Basic Server" Install. EPEL will also be temporarily Enabled to get a few packages
  47. not in the main Centos Repositories.
  48. As with anything you will want to review the configs after the installer to make sure they are what you want.
  49. This is Version $VERSION of this script.
  50. EOT
  51. read -p "SNMP Support Name [$defSUPPORTNAME]: " -e t1
  52. if [ -n "$t1" ]
  53. then
  54. SUPPORTNAME="$t1"
  55. else
  56. SUPPORTNAME="$defSUPPORTNAME"
  57. fi
  58. read -p "Support Email [$defSUPPORTEMAIL]: " -e t1
  59. if [ -n "$t1" ]
  60. then
  61. SUPPORTEMAIL="$t1"
  62. else
  63. SUPPORTEMAIL="$defSUPPORTEMAIL"
  64. fi
  65. read -p "Domain Name [$defDOMAINNAME]: " -e t1
  66. if [ -n "$t1" ]
  67. then
  68. DOMAINNAME="$t1"
  69. else
  70. DOMAINNAME="$defDOMAINNAME"
  71. fi
  72. defPUBLICHOSTNAME="voice.${DOMAINNAME}"
  73. read -p "Public Hostname [$defPUBLICHOSTNAME]: " -e t1
  74. if [ -n "$t1" ]
  75. then
  76. PUBLICHOSTNAME="$t1"
  77. else
  78. PUBLICHOSTNAME="$defPUBLICHOSTNAME"
  79. fi
  80. read -r -p "Are you sure? [Y/n] " response
  81. if [[ $response =~ ^([yY][eE][sS]|[yY])$ ]]
  82. then
  83. echo "Here we go..."
  84. else
  85. echo "Aborting"
  86. exit
  87. fi
  88. ###############
  89. #install dependencies
  90. yum -y install sudo ghostscript libtiff
  91. ###########################################3
  92. #dz Install OpenSSL for TLS and SRTP support
  93. yum -y install openssl-devel
  94. ###############
  95. #dz Install SNMP to support mod_snmp
  96. #dz net-snmp-devel necessary to install net-snmp-config script
  97. yum -y install net-snmp net-snmp-utils net-snmp-devel
  98. mv /etc/snmp/snmpd.conf /etc/snmp/snmpd.conf.org
  99. #Create a new config file.
  100. #Add Settings to freeswitch sysconfig filed
  101. cat >> /etc/snmp/snmpd.conf <<EOT
  102. rocommunity public
  103. syslocation ${SUPPORTNAME}
  104. syscontact ${SUPPORTEMAIL}
  105. EOT
  106. #Start the snmpd service
  107. /etc/init.d/snmpd start
  108. # snmpwalk -v 1 -c public -O e 127.0.0.1
  109. chkconfig snmpd on
  110. #################
  111. # dz move to directory that is more open so that when we su, its not restricted.
  112. cd /usr/local/src
  113. mkdir fusionpbxinstall
  114. cd fusionpbxinstall
  115. # Do a Yum Update to update the system
  116. yum update -y
  117. yum -y install wget
  118. # dz add the postgresql 9.2 repository so it can be installed via yum
  119. if [ ${MACHINE_TYPE} == 'x86_64' ]; then
  120. wget http://yum.postgresql.org/9.2/redhat/rhel-6-x86_64/pgdg-centos92-9.2-6.noarch.rpm
  121. else
  122. wget http://yum.postgresql.org/9.2/redhat/rhel-6-i386/pgdg-centos92-9.2-6.noarch.rpm
  123. fi
  124. rpm -ivh pgdg-centos92-9.2-6.noarch.rpm
  125. #install other required packages
  126. yum -y install autoconf automake gcc-c++ git-core libjpeg-devel libtool make ncurses-devel pkgconfig unixODBC-devel openssl-devel gnutls-devel libogg-devel libvorbis-devel curl-devel libtiff-devel libjpeg-devel python-devel expat-devel zlib zlib-devel bzip2 which postgresql92-devel postgresql92-odbc postgresql92-server subversion screen vim php* ntp
  127. # dz Install unixodbc so we can switch from the default sqllite db to postgresql for Freeswitch
  128. yum -y install unixODBC-devel postgresql-odbc
  129. # dz this has not been tested.
  130. cat >> /etc/odbc.ini << EOT
  131. [freeswitch]
  132. ; WARNING: The old psql odbc driver psqlodbc.so is now renamed psqlodbcw.so
  133. ; in version 08.x. Note that the library can also be installed under an other
  134. ; path than /usr/local/lib/ following your installation.
  135. Driver = /usr/lib/psqlodbcw.so
  136. Description=Connection to LDAP/POSTGRESQL
  137. Servername=127.0.0.1
  138. Port=5432
  139. ;Protocol=6.4 #dz does this need to be 9.1 for postgresql 9.1?
  140. FetchBufferSize=99
  141. Username=freeswitch
  142. ;Password=password
  143. Database=freeswitch
  144. ReadOnly=no
  145. Debug=1
  146. CommLog=1
  147. [fusionpbx]
  148. Driver = /usr/lib/psqlodbcw.so
  149. Description=Connection to FusionPBX used for mod_CDR
  150. Servername=127.0.0.1
  151. Port=5432
  152. ;Protocol=6.4 #dz does this need to be 9.1 for postgresql 9.1?
  153. FetchBufferSize=99
  154. Username=fusionpbx
  155. ;Password=password
  156. Database=fusionpbx
  157. ReadOnly=no
  158. Debug=1
  159. CommLog=1
  160. EOT
  161. #users for Postgres are added after Postgres is started
  162. #lets get the Time Right
  163. ntpdate pool.ntp.org
  164. service ntpd start
  165. chkconfig ntpd on
  166. #Disable SELinux
  167. if [ -x /usr/sbin/setenforce ]; then
  168. /usr/sbin/setenforce 0
  169. /bin/sed -i -e s,'SELINUX=enforcing','SELINUX=disabled', /etc/sysconfig/selinux
  170. #dz it seems both these files exist on Centos 6.2 but this next on actually controls selinux
  171. /bin/sed -i -e s,'SELINUX=enforcing','SELINUX=disabled', /etc/selinux/config
  172. fi
  173. # Lets go Get the FreeSWITCH Source and install it
  174. cd /usr/src
  175. git clone https://stash.freeswitch.org/scm/fs/freeswitch.git
  176. cd freeswitch
  177. git checkout v1.2.stable
  178. ./bootstrap.sh -j
  179. #dz modify the /usr/src/freeswitch/modules.conf file here dz120308
  180. /bin/sed -i -e s,'#applications/mod_callcenter','applications/mod_callcenter', /usr/src/freeswitch/modules.conf
  181. /bin/sed -i -e s,'#endpoints/mod_rtmp','endpoints/mod_rtmp', /usr/src/freeswitch/modules.conf
  182. /bin/sed -i -e s,'#endpoints/mod_dingaling','endpoints/mod_dingaling', /usr/src/freeswitch/modules.conf
  183. /bin/sed -i -e s,'#applications/mod_lcr','applications/mod_lcr', /usr/src/freeswitch/modules.conf
  184. /bin/sed -i -e s,'#applications/mod_blacklist','applications/mod_blacklist', /usr/src/freeswitch/modules.conf
  185. #mod_cidlookup requires additional configuration which is not yet in this script
  186. /bin/sed -i -e s,'#applications/mod_cidlookup','applications/mod_cidlookup', /usr/src/freeswitch/modules.conf
  187. #/bin/sed -i -e s,'#asr_tts/mod_pocketsphinx','asr_tts/mod_pocketsphinx', /usr/src/freeswitch/modules.conf
  188. /bin/sed -i -e s,'#applications/mod_voicemail_ivr','applications/mod_voicemail_ivr', /usr/src/freeswitch/modules.conf
  189. /bin/sed -i -e s,'#event_handlers/mod_snmp','event_handlers/mod_snmp', /usr/src/freeswitch/modules.conf
  190. /bin/sed -i -e s,'#formats/mod_shout','formats/mod_shout', /usr/src/freeswitch/modules.conf
  191. /bin/sed -i -e s,'#asr_tts/mod_tts_commandline','asr_tts/mod_tts_commandline', /usr/src/freeswitch/modules.conf
  192. /bin/sed -i -e s,'#asr_tts/mod_flite','asr_tts/mod_flite', /usr/src/freeswitch/modules.conf
  193. ./configure --without-libcurl -C
  194. make -j `cat /proc/cpuinfo |grep processor |wc -l`
  195. make install
  196. make cd-moh-install && make cd-sounds-install
  197. #add a user for freeswitch
  198. useradd freeswitch
  199. #set ownership, perms, and install init scripts
  200. cd /usr/local/
  201. chown -R freeswitch:freeswitch freeswitch
  202. chmod -R g+w freeswitch
  203. cd /usr/src/freeswitch/build
  204. cp freeswitch.init.redhat /etc/init.d/freeswitch
  205. chmod +x /etc/init.d/freeswitch
  206. cp freeswitch.sysconfig /etc/sysconfig/freeswitch
  207. #Add Settings to freeswitch sysconfig filed
  208. cat >> /etc/sysconfig/freeswitch <<EOT
  209. PID_FILE=/var/run/freeswitch/freeswitch.pid
  210. FS_USER=freeswitch
  211. FS_FILE=/usr/local/freeswitch/bin/freeswitch
  212. FS_HOME=/usr/local/freeswitch
  213. EOT
  214. configure mod_cidlookup
  215. #dz need to install UnixODBC first
  216. # see http://wiki.freeswitch.org/wiki/Using_ODBC_in_the_core
  217. mv /usr/local/freeswitch/conf/autoload_configs/cidlookup.conf.xml /usr/local/freeswitch/conf/autoload_configs/cidlookup.conf.xml.bak
  218. cat >> /usr/local/freeswitch/conf/autoload_configs/cidlookup.conf.xml <<EOT
  219. <configuration name="cidlookup.conf" description="cidlookup Configuration">
  220. <settings>
  221. <param name="cache" value="true"/>
  222. <param name="cache-expire" value="86400"/>
  223. <param name="odbc-dsn" value="fusionpbx:fusionpbx:"/>
  224. <param name="sql" value="
  225. SELECT p.contact_name_family ||', '|| p.contact_name_given as name
  226. FROM v_contact_phones n INNER JOIN v_contacts p ON n.contact_uuid = p.contact_uuid
  227. WHERE n.phone_number = '${caller_id_number}'
  228. LIMIT 1
  229. "/>
  230. </settings>
  231. </configuration>
  232. EOT
  233. /bin/sed -i -e s,'<!-- <param name="core-db-dsn" value="dsn:username:password" /> -->','<param name="core-db-dsn" value="freeswitch:freeswitch:" />', /usr/local/freeswitch/conf/autoload_configs/switch.conf.xml
  234. chown apache:apache /usr/local/freeswitch/conf/autoload_configs/cidlookup.conf.xml
  235. #dz Change Sofia to use Postgres
  236. /bin/sed -i -e s,'</settings>','<param name="odbc-dsn" value="freeswitch:freeswitch:"/></settings>', /usr/local/freeswitch/conf/sip_profiles/internal.xml
  237. /bin/sed -i -e s,'</settings>','<param name="odbc-dsn" value="freeswitch:freeswitch:"/></settings>', /usr/local/freeswitch/conf/sip_profiles/external.xml
  238. #dz Use Postgres for voicemail
  239. /bin/sed -i -e s,'<!--<param name="odbc-dsn" value="dsn:user:pass"/>-->','<param name="odbc-dsn" value="freeswitch:freeswitch:"/>', /usr/local/freeswitch/conf/autoload_configs/voicemail.conf.xml
  240. # sym link fs_cli into /usr/local/bin so we don't have to adjust paths
  241. cd /usr/local/bin/
  242. ln -s /usr/local/freeswitch/bin/fs_cli fs_cli
  243. #start installing FusionPBX From Subversion
  244. #cd /var/www
  245. #svn co http://fusionpbx.googlecode.com/svn/trunk/fusionpbx html
  246. cd /var/www/html
  247. mkdir fusionpbx
  248. svn co http://fusionpbx.googlecode.com/svn/trunk/fusionpbx fusionpbx
  249. #Add a redirect so the default doc at the web root goes to the fusionpbx login.
  250. cat > /var/www/html/index.php <<EOT
  251. <?php header( 'Location: /fusionpbx/index.php' ) ;?>
  252. EOT
  253. #fix FusionPBX Ownership and Perms
  254. #chown -R apache:apache html
  255. chown -R apache:apache fusionpbx
  256. cd /usr/local/freeswitch/conf/
  257. chmod 770 `find . -type d`
  258. chmod 660 `find . -type f`
  259. # add apache to the freeswitch Group
  260. usermod -a -G freeswitch apache
  261. # dz20120614 Freeswitch should be in the apache group. Freeswitch is a
  262. # more critical service and apache is more public. Therefore we should
  263. # not allow apache access to the freeswitch files. Conf files that
  264. # are modified by the web interface should be owned by the apache group
  265. # and freeswitch should have access to it.
  266. # add freeswitch to the apache group
  267. usermod -a -G apache freeswitch
  268. ## Install EPEL so we can get monit and ngrep
  269. if [ ${MACHINE_TYPE} == 'x86_64' ]; then
  270. rpm -Uvh http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
  271. else
  272. rpm -Uvh http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
  273. fi
  274. #Install Monit, Fail2Ban, and ngrep
  275. yum install -y monit ngrep fail2ban
  276. #Drop monit configs in the right spot
  277. cat > /etc/monit.d/freeswitch <<EOT
  278. check process freeswitch with pidfile /usr/local/freeswitch/run/freeswitch.pid
  279. group voice
  280. start program = "/etc/init.d/freeswitch start"
  281. stop program = "/etc/init.d/freeswitch stop"
  282. if failed port 5060 type UDP then restart
  283. if 5 restarts within 5 cycles then timeout
  284. depends on freeswitch_bin
  285. depends on freeswitch_rc
  286. check file freeswitch_bin with path /usr/local/freeswitch/bin/freeswitch
  287. group voice
  288. if failed checksum then unmonitor
  289. if failed permission 755 then unmonitor
  290. if failed uid freeswitch then unmonitor
  291. check file freeswitch_rc with path /etc/init.d/freeswitch
  292. group voice
  293. if failed checksum then unmonitor
  294. if failed permission 755 then unmonitor
  295. if failed uid root then unmonitor
  296. if failed gid root then unmonitor
  297. EOT
  298. #Add Fail2Ban configs for
  299. echo > /etc/fail2ban/filter.d/freeswitch.conf << EOT
  300. # Fail2Ban configuration file
  301. #
  302. # Author: Rupa SChomaker
  303. #
  304. [Definition]
  305. # Option: failregex
  306. # Notes.: regex to match the password failures messages in the logfile. The
  307. # host must be matched by a group named "host". The tag "<HOST>" can
  308. # be used for standard IP/hostname matching and is only an alias for
  309. # (?:::f{4,6}:)?(?P<host>[\w\-.^_]+)
  310. # Values: TEXT
  311. #
  312. failregex = \[WARNING\] sofia_reg.c:\d+ SIP auth failure \(REGISTER\) on sofia profile \'\S+\' for \[.*\] from ip <HOST>
  313. \[WARNING\] sofia_reg.c:\d+ SIP auth failure \(INVITE\) on sofia profile \'\S+\' for \[.*\] from ip <HOST>
  314. # Option: ignoreregex
  315. # Notes.: regex to ignore. If this regex matches, the line is ignored.
  316. # Values: TEXT
  317. #
  318. ignoreregex =
  319. EOT
  320. echo >> /etc/fail2ban/jail.conf << EOT
  321. [freeswitch-tcp]
  322. enabled = true
  323. port = 5060,5061,5080,5081
  324. protocol = tcp
  325. filter = freeswitch
  326. logpath = /usr/local/freeswitch/log/freeswitch.log
  327. action = iptables-allports[name=freeswitch-tcp, protocol=all]
  328. sendmail-whois[name=FreeSwitch, dest=root, [email protected]]
  329. [freeswitch-udp]
  330. enabled = true
  331. port = 5060,5061,5080,5081
  332. protocol = udp
  333. filter = freeswitch
  334. logpath = /usr/local/freeswitch/log/freeswitch.log
  335. action = iptables-allports[name=freeswitch-udp, protocol=all]
  336. sendmail-whois[name=FreeSwitch, dest=root, [email protected]]
  337. EOT
  338. echo > /etc/fail2ban/filter.d/fusionpbx.conf << EOT
  339. # Fail2Ban configuration file
  340. #
  341. # Author: soapee01
  342. #
  343. [Definition]
  344. # Option: failregex
  345. # Notes.: regex to match the password failures messages in the logfile. The
  346. # host must be matched by a group named "host". The tag "<HOST>" can
  347. # be used for standard IP/hostname matching and is only an alias for
  348. # (?:::f{4,6}:)?(?P<host>[\w\-.^_]+)
  349. # Values: TEXT
  350. #
  351. #failregex = [hostname] FusionPBX: \[<HOST>\] authentication failed
  352. #[hostname] variable doesn't seem to work in every case. Do this instead:
  353. failregex = .* FusionPBX: \[<HOST>\] authentication failed for
  354. = .* FusionPBX: \[<HOST>\] provision attempt bad password for
  355. # Option: ignoreregex
  356. # Notes.: regex to ignore. If this regex matches, the line is ignored.
  357. # Values: TEXT
  358. #
  359. ignoreregex =
  360. EOT
  361. echo >> /etc/fail2ban/jail.conf << EOT
  362. [fusionpbx]
  363. enabled = true
  364. port = 80,443
  365. protocol = tcp
  366. filter = fusionpbx
  367. logpath = /var/log/messages
  368. action = iptables-allports[name=fusionpbx, protocol=all]
  369. sendmail-whois[name=FusionPBX, dest=root, [email protected]]
  370. EOT
  371. # INIT Postgresql, and set it for easyness
  372. #quick hack to postgresql init script to init the DB with trust access **** YOU MAY NOT WANT THIS FOR PRODUCTION ****
  373. /bin/sed -i -e s,'ident','trust', /etc/init.d/postgresql-9.2
  374. cd /etc/init.d/
  375. ./postgresql-9.2 initdb
  376. chkconfig postgresql-9.2 on
  377. service postgresql-9.2 start
  378. #set this back to normal
  379. /bin/sed -i -e s,'trust','ident', /etc/init.d/postgresql-9.2
  380. service postgresql-9.2 restart
  381. #create users for core Freeswitch
  382. cd /var/tmp
  383. sudo -u postgres /usr/pgsql-9.2/bin/createuser -s -e freeswitch
  384. sudo -u postgres /usr/pgsql-9.2/bin/createdb -E UTF8 -O freeswitch freeswitch
  385. # dz create a fusionpbx user and a fusionpbx database.
  386. cd /var/tmp
  387. sudo -u postgres /usr/pgsql-9.2/bin/createuser -s -e fusionpbx
  388. sudo -u postgres /usr/pgsql-9.2/bin/createdb -E UTF8 -O fusionpbx fusionpbx
  389. # dz create a script to do a backup of the postgre databases (to disk). Assuming you have another
  390. # script that backs the freeswitch and fusionpbx folder up
  391. wget -P /usr/local/freeswitch/scripts/ http://helia.ca/a/fusionpbx/pb_backup_rotated.sh
  392. chmod 755 /usr/local/freeswitch/scripts/pb_backup_rotated.sh
  393. # dz Create a cron job to backup the postgres dbs to disk every day at 5 minutes past midnight
  394. cat >> /var/spool/cron/root << EOT
  395. 5 0 * * * /usr/local/freeswitch/scripts/pb_backup_rotated.sh
  396. EOT
  397. #disable epel repo for normal use. Leaving it enabled can have unintended consequences
  398. /bin/sed -i -e s,'enabled=1','enabled=0', /etc/yum.repos.d/epel.repo
  399. #Make the Prompt Pretty and add a few aliases that come in handy
  400. cat >>~/.bashrc <<EOT
  401. export LESSCHARSET="latin1"
  402. export LESS="-R"
  403. export CHARSET="ISO-8859-1"
  404. export PS1='\n\[\033[01;31m\]\u@\h\[\033[01;36m\] [\d \@] \[\033[01;33m\] \w\n\[\033[00m\]<\#>:'
  405. export PS2="\[\033[1m\]> \[\033[0m\]"
  406. export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
  407. export VISUAL=vim
  408. umask 022
  409. alias vi='vim'
  410. alias fstop='top -p \`cat /usr/local/freeswitch/run/freeswitch.pid\`'
  411. alias fsgdb='gdb /usr/local/freeswitch/bin/freeswitch \`cat /usr/local/freeswitch/run/freeswitch.pid\`'
  412. alias fscore='gdb /usr/local/freeswitch/bin/freeswitch \`ls -rt core.* | tail -n1\`'
  413. EOT
  414. #Add a screenrc with a status line, a big scroll back and ^\ as the metakey as to not screw with emacs users
  415. cat >> ~/.screenrc <<EOT
  416. hardstatus alwaysignore
  417. startup_message off
  418. escape ^\b
  419. defscrollback 8000
  420. # status line at the bottom
  421. hardstatus on
  422. hardstatus alwayslastline
  423. hardstatus string "%{.bW}%-w%{.rW}%f%n %t%{-}%+w %=%{..G}[%H %l] %{..Y} %m/%d %c "
  424. termcapinfo xterm \'is=\E[r\E[m\E[2J\E[H\E[?7h\E[?1;4;6l\'
  425. EOT
  426. # and finally lets fix up IPTables so things works correctly
  427. # SSH port
  428. iptables -I INPUT -p tcp -m tcp --dport 22 -j ACCEPT
  429. # Block 'friendly-scanner' AKA sipvicious
  430. iptables -I INPUT -p udp --dport 5060 -m string --string "friendly-scanner" --algo bm -j DROP
  431. iptables -I INPUT -p udp --dport 5080 -m string --string "friendly-scanner" --algo bm -j DROP
  432. # rate limit registrations to keep us from getting hammered on
  433. iptables -I INPUT -m string --string "REGISTER sip:" --algo bm --to 65 -m hashlimit --hashlimit 4/minute --hashlimit-burst 1 --hashlimit-mode srcip,dstport --hashlimit-name sip_r_limit -j ACCEPT
  434. # FreeSwitch ports internal SIP profile
  435. iptables -I INPUT -p udp -m udp --dport 5060 -j ACCEPT
  436. iptables -I INPUT -p tcp -m tcp --dport 5060 -j ACCEPT
  437. # FreeSwitch Ports external SIP profile
  438. iptables -I INPUT -p udp -m udp --dport 5080 -j ACCEPT
  439. iptables -I INPUT -p tcp -m tcp --dport 5080 -j ACCEPT
  440. # NTP time port for phones
  441. iptables -I INPUT -p udp -m udp --dport 123 -j ACCEPT
  442. # FreeSwitch ports internal SIPS profile
  443. iptables -I INPUT -p tcp -m tcp --dport 5061 -j ACCEPT
  444. # FreeSwitch ports external SIPS profile
  445. iptables -I INPUT -p tcp -m tcp --dport 5081 -j ACCEPT
  446. # RTP Traffic 16384-32768
  447. iptables -I INPUT -p udp -m udp --dport 16384:32768 -j ACCEPT
  448. # Ports for the Web GUI
  449. iptables -I INPUT -p tcp -m tcp --dport 80 -j ACCEPT
  450. iptables -I INPUT -p tcp -m tcp --dport 443 -j ACCEPT
  451. # Ports for SNMP
  452. iptables -I INPUT -p udp -m udp --dport 161 -j ACCEPT
  453. iptables -I INPUT -p udp -m udp --dport 162 -j ACCEPT
  454. #save the IPTables rules for later
  455. service iptables save
  456. #################################
  457. #generate cert for TLS
  458. #NOTE: the domain name here
  459. /usr/local/freeswitch/bin/gentls_cert setup -cn ${PUBLICHOSTNAME} -alt DNS:${PUBLICHOSTNAME} -org ${DOMAINNAME}
  460. # Creates file cafile.pem and CA/cacert.pem, CA/cakey.pem, CA/config.tpl
  461. cat <<EOT
  462. ******************************
  463. Almost done! Now certificates for encryption of TLS and SRTP will be created. Answer yes when asked to create the certificates.
  464. ******************************
  465. EOT
  466. /usr/local/freeswitch/bin/gentls_cert create_server -cn ${PUBLICHOSTNAME} -alt DNS:${PUBLICHOSTNAME} -org ${DOMAINNAME}
  467. # Creates file agent.pem CA/cacert.srl
  468. #review the cert
  469. #openssl x509 -noout -inform pem -text -in /usr/local/freeswitch/conf/ssl/agent.pem
  470. chown freeswitch:freeswitch /usr/local/freeswitch/conf/ssl/agent.pem
  471. #chown freeswitch:freeswitch /usr/local/freeswitch/conf/ssl/cacert.pem # This file is the orig but doesn't exist
  472. chown freeswitch:freeswitch /usr/local/freeswitch/conf/ssl/CA/cacert.pem # right file name in a CA folder
  473. chown freeswitch:freeswitch /usr/local/freeswitch/conf/ssl/cafile.pem # file name is wrong
  474. chmod 640 /usr/local/freeswitch/conf/ssl/agent.pem
  475. #chmod 640 /usr/local/freeswitch/conf/ssl/cacert.pem # This file is the orig but doesn't exist
  476. chmod 640 /usr/local/freeswitch/conf/ssl/CA/cacert.pem # right filename in the CA folder
  477. # file name is wrong
  478. chmod 640 /usr/local/freeswitch/conf/ssl/cafile.pem
  479. /bin/sed -i -e s,'<X-PRE-PROCESS cmd="set" data="external_ssl_enable=false"/>','<X-PRE-PROCESS cmd="set" data="external_ssl_enable=true"/>', /usr/local/freeswitch/conf/vars.xml
  480. /bin/sed -i -e s,'<X-PRE-PROCESS cmd="set" data="internal_ssl_enable=false"/>','<X-PRE-PROCESS cmd="set" data="internal_ssl_enable=true"/>', /usr/local/freeswitch/conf/vars.xml
  481. # Generate client certificate
  482. /usr/local/freeswitch/bin/gentls_cert create_client -cn client.${DOMAINNAME} -out phone
  483. #######################################################
  484. # start up some services and set them to run at boot
  485. service freeswitch start
  486. service httpd restart
  487. chkconfig freeswitch on
  488. chkconfig httpd on
  489. service monit start
  490. chkconfig monit on
  491. LOCAL_IP=`ifconfig eth0 | head -n2 | tail -n1 | cut -d' ' -f12 | cut -c 6-`
  492. cat <<EOT
  493. As long as you didnt see errors by this point, PostgreSQL, FreeSWITCH, FusionPBX, Fail2Ban, and Monit should be installed.
  494. Point your browser to http://$LOCAL_IP/ and let the FusionPBX installer take it from there.
  495. EOT
  496. #######################################################
  497. ##Additional Notes
  498. #from iliah.i.borg
  499. #If using postgresql92 you may want to create a symlink from /usr/pgsql-9.2/lib/psqlodbcw.so to /usr/lib/psqlodbcw.so or edit lines 169 and 183 to read:
  500. #Driver = /usr/pgsql-9.2/lib/psqlodbcw.so
  501. #On a side note, to avoid problems, at a very early stage of system tuning, I usually disable postgresql from normal repo, like:
  502. #vi /etc/yum.repos.d/CentOS-Base.repo
  503. #[base]
  504. #exclude=postgresql*
  505. #[updates]
  506. #exclude=postgresql*
  507. #and install postgresql92-contrib too