forked from iNextrix/ASTPP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
736 lines (690 loc) · 28.2 KB
/
install.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
#!/bin/bash
###############################################################################
# ASTPP - Open Source VoIP Billing Solution
#
# Copyright (C) 2016 iNextrix Technologies Pvt. Ltd.
# ASTPP Version 3.5
# License https://www.gnu.org/licenses/agpl-3.0.html
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
###############################################################################
#################################
########## variables ###########
#################################
TEMP_USER_ANSWER="no"
INSTALL_ASTPP="no"
CURRENT_DIR="${PWD}"
DOWNLOAD_DIR="/usr/src"
ASTPP_SOURCE_DIR=/usr/src/latest
ASTPP_HOST_DOMAIN_NAME="host.domain.tld"
#ASTPP Configuration
ASTPPDIR=/var/lib/astpp/
ASTPPEXECDIR=/usr/local/astpp/
ASTPPLOGDIR=/var/log/astpp/
LOCALE_DIR=/usr/local/share/locale
#Freeswich Configuration
FS_DIR=/usr/local/freeswitch
FS_SOUNDSDIR=${FS_DIR}/sounds/en/us/callie
FS_SCRIPTS=${FS_DIR}/scripts
WWWDIR=/var/www/html
ASTPP_USING_FREESWITCH="no"
ASTPP_USING_ASTERISK="no"
INSTALL_ASTPP_WEB_INTERFACE="no"
ASTPP_DATABASE_NAME="astpp"
ASTPP_DB_USER="astppuser"
MYSQL_ROOT_PASSWORD=""
ASTPPUSER_MYSQL_PASSWORD=""
#################################
#### general functions #########
#################################
# task of function: ask to user yes or no
# usage: ask_to_user_yes_or_no "your question"
# return TEMP_USER_ANSWER variable filled with "yes" or "no"
ask_to_user_yes_or_no ()
{
# default answer = no
TEMP_USER_ANSWER="no"
clear
echo ""
echo -e ${1}
read -n 1 -p "(y/n)? :"
if [ "${REPLY}" = "y" ]; then
TEMP_USER_ANSWER="yes"
else
TEMP_USER_ANSWER="no"
fi
}
# Determine the OS architecture
get_os_architecture ()
{
if [ ${HOSTTYPE} == "x86_64" ]; then
ARCH=x64
else
ARCH=x32
fi
}
get_os_architecture
# Linux Distribution CentOS or Debian
get_linux_distribution ()
{
V1=`cat /etc/*release | head -n1 | tail -n1 | cut -c 14- | cut -c1-18`
V2=`cat /etc/*release | head -n7 | tail -n1 | cut -c 14- | cut -c1-14`
PHPV=`php -v |sed -n 1p|awk '{ print $1 $2 }'|cut -c 1-4`
if [ "$PHPV" = "PHP7" ]; then
echo 'Opps!! Currently we are not supporting PHP 7 or greater, Please downgrade your PHP version to 5.6 OR below.'
exit 1
fi
if [ "$V1" = "Debian GNU/Linux 8" ]; then
DIST="DEBIAN"
else if [ "$V2" = "CentOS Linux 7" ]; then
DIST="CENTOS"
else
DIST="OTHER"
echo 'Opps!! Quick Installation does not support your distribution'
exit 1
fi
fi
}
get_linux_distribution
install_epel ()
{
yum install epel-release
}
remove_epel ()
{
# only on CentOS
yum remove epel-release
}
# Generate random password (for MySQL)
genpasswd()
{
length=$1
[ "$length" == "" ] && length=16
tr -dc A-Za-z0-9_ < /dev/urandom | head -c ${length} | xargs
}
MYSQL_ROOT_PASSWORD=$(genpasswd)
ASTPPUSER_MYSQL_PASSWORD=$(genpasswd)
#################################
######## ASK SCRIPTS ###########
#################################
# Ask to install astpp
ask_to_install_astpp ()
{
if [ ${DIST} = "CENTOS" ]; then
yum install -y wget
fi
# License acceptance
clear
echo "********************"
echo "License acceptance"
echo "********************"
if [ -f LICENSE ]; then
more LICENSE
else
wget --no-check-certificate -q -O GNU-AGPLv3.5.txt https://raw.githubusercontent.com/iNextrix/ASTPP/master/LICENSE
more GNU-AGPLv3.5.txt
fi
echo "***"
echo "*** I agree to be bound by the terms of the license - [YES/NO]"
echo "*** "
read ACCEPT
while [ "$ACCEPT" != "yes" ] && [ "$ACCEPT" != "Yes" ] && [ "$ACCEPT" != "YES" ] && [ "$ACCEPT" != "no" ] && [ "$ACCEPT" != "No" ] && [ "$ACCEPT" != "NO" ]; do
echo "I agree to be bound by the terms of the license - [YES/NO]"
read ACCEPT
done
if [ "$ACCEPT" != "yes" ] && [ "$ACCEPT" != "Yes" ] && [ "$ACCEPT" != "YES" ]; then
echo "License rejected!"
exit 0
else
echo "Licence accepted!"
echo "============checking your working directory=================="
git clone -b v3.5 https://github.com/iNextrix/ASTPP.git
cp -rf ASTPP latest
if [ ${CURRENT_DIR} == ${DOWNLOAD_DIR} ]; then
echo "dir is '$CURRENT_DIR' and it's matched!!!"
else
echo "dir is '$CURRENT_DIR' and not matched!!!"
mv -f ${CURRENT_DIR}/latest ${DOWNLOAD_DIR}/.
clear
echo "====================Starting installation again======================"
sleep 10
cd ${ASTPP_SOURCE_DIR} && chmod +x install.sh && ./install.sh
clear
fi
fi
ask_to_user_yes_or_no "Do you want to install ASTPP?"
if [ "${TEMP_USER_ANSWER}" = "yes" ]; then
INSTALL_ASTPP="yes"
echo ""
read -p "Enter FQDN example (i.e ${ASTPP_HOST_DOMAIN_NAME}): "
ASTPP_HOST_DOMAIN_NAME=${REPLY}
echo "Your entered FQDN is : ${ASTPP_HOST_DOMAIN_NAME} "
echo ""
read -p "Enter your email address: ${EMAIL}"
EMAIL=${REPLY}
read -n 1 -p "Press any key to continue ... "
ask_to_user_yes_or_no "Do you want use FreeSwitch on ASTPP?"
if [ ${TEMP_USER_ANSWER} = "yes" ]; then
ASTPP_USING_FREESWITCH="yes"
fi
ask_to_user_yes_or_no "Do you want to install ASTPP web interface?"
if [ ${TEMP_USER_ANSWER} = "yes" ]; then
INSTALL_ASTPP_WEB_INTERFACE="yes"
fi
fi
echo "Installation Done"
}
ask_to_install_astpp
#################################
#### INSTALL SCRIPTS ###########
#################################
clear
echo -e "Are you ready?"
read -n 1 -p "Press any key to continue ... "
clear
# install freeswitch for astpp
install_freeswitch_for_astpp ()
{
if [ ${DIST} = "DEBIAN" ]; then
apt-get -o Acquire::Check-Valid-Until=false update && apt-get install -y curl
curl https://files.freeswitch.org/repo/deb/debian/freeswitch_archive_g0.pub | apt-key add -
echo "deb http://files.freeswitch.org/repo/deb/freeswitch-1.6/ jessie main" > /etc/apt/sources.list.d/freeswitch.list
apt-get -o Acquire::Check-Valid-Until=false update && apt-get install -y --force-yes freeswitch-video-deps-most
# Install Freeswitch pre-requisite packages using apt-get
apt-get install -y autoconf automake devscripts gawk chkconfig dnsutils sendmail-bin sensible-mda ntpdate ntp g++ git-core curl libjpeg62-turbo-dev libncurses5-dev make python-dev pkg-config libgdbm-dev libyuv-dev libdb-dev libvpx2-dev gettext sudo lua5.1 php5 php5-dev php5-common php5-cli php5-gd php-pear php5-cli php-apc php5-curl libxml2 libxml2-dev openssl libcurl4-openssl-dev gettext gcc libldns-dev libpcre3-dev build-essential libssl-dev libspeex-dev libspeexdsp-dev libsqlite3-dev libedit-dev libldns-dev libpq-dev bc
#-------------------MySQL setup in for freeswitch Start ------------------------
clear
echo "======================Mysql installation start======================="
sleep 20
echo "MySQL root password is set to : ${MYSQL_ROOT_PASSWORD}"
echo "astppuser password is set to : ${ASTPPUSER_MYSQL_PASSWORD}"
echo mysql-server mysql-server/root_password password ${MYSQL_ROOT_PASSWORD} | debconf-set-selections
echo mysql-server mysql-server/root_password_again password ${MYSQL_ROOT_PASSWORD} | debconf-set-selections
apt-get install -y mysql-server php5-mysql
echo "======================Mysql installation end======================="
sleep 20
#-------------------MySQL setup in for freeswitch End ------------------------
elif [ ${DIST} = "CENTOS" ]; then
# Install Freeswitch pre-requisite packages using yum
yum groupinstall "Development tools" -y
install_epel
rpm -Uvh http://files.freeswitch.org/freeswitch-release-1-6.noarch.rpm
yum install epel-release
yum install -y wget git autoconf automake expat-devel yasm nasm gnutls-devel libtiff-devel libX11-devel unixODBC-devel python-devel zlib-devel alsa-lib-devel libogg-devel libvorbis-devel uuid-devel @development-tools gdbm-devel db4-devel libjpeg libjpeg-devel compat-libtermcap ncurses ncurses-devel ntp screen sendmail sendmail-cf gcc-c++ @development-tools bison bzip2 curl curl-devel dmidecode git make mysql-connector-odbc openssl-devel unixODBC zlib pcre-devel speex-devel sqlite-devel ldns-devel libedit-devel bc e2fsprogs-devel libcurl-devel libxml2-devel libyuv-devel opus-devel libvpx-devel libvpx2* libdb4* libidn-devel unbound-devel libuuid-devel lua-devel libsndfile-devel
fi
NAT1=$(dig +short myip.opendns.com @resolver1.opendns.com)
NAT2=$(curl http://ip-api.com/json/)
INTF=$(ifconfig $1|sed -n 2p|awk '{ print $2 }'|awk -F : '{ print $2 }')
if [ "${NAT1}" != "${INTF}" ]; then
echo "Server is behind NAT";
fi
curl --data "email=$EMAIL" --data "data=$NAT2" --data "type=Install" http://astppbilling.org/lib/
echo "Lets first make sure that time is correct before we continue ... "
# set right time
set_right_time ()
{
echo "Setting up correct time ..."
ntpdate pool.ntp.org
if [ ${DIST} = "DEBIAN" ]; then
systemctl restart ntp
chkconfig ntp on
else [ -f /etc/redhat-release ]
systemctl restart ntpd
chkconfig ntpd on
fi
}
set_right_time
#-----------------Freeswitch Installation Start------------------------------
# Download latest freeswitch version
cd /usr/local/src
git config --global pull.rebase true
git clone -b v1.6.19 https://freeswitch.org/stash/scm/fs/freeswitch.git
cd freeswitch
./bootstrap.sh -j
# Edit modules.conf
sed -i "s#\#xml_int/mod_xml_curl#xml_int/mod_xml_curl#g" /usr/local/src/freeswitch/modules.conf
sed -i "s#\#applications/mod_curl#applications/mod_curl#g" /usr/local/src/freeswitch/modules.conf
sed -i "s#\#event_handlers/mod_json_cdr#event_handlers/mod_json_cdr#g" /usr/local/src/freeswitch/modules.conf
sed -i "s#\#applications/mod_voicemail#applications/mod_voicemail#g" /usr/local/src/freeswitch/modules.conf
# Compile the Source
./configure -C
# Install Freeswitch with sound files
make all install cd-sounds-install cd-moh-install
make && make install
# Create symbolic links for Freeswitch executables
ln -s /usr/local/freeswitch/bin/freeswitch /usr/local/bin/freeswitch
ln -s /usr/local/freeswitch/bin/fs_cli /usr/local/bin/fs_cli
#-----------------Freeswitch Installation End------------------------------
systemctl stop apache2
systemctl disable apache2
}
#SUB Configure astpp Freeswitch Startup Script
astpp_freeswitch_startup_script ()
{
if [ ! -d ${ASTPP_SOURCE_DIR} ]; then
echo "ASTPP source doesn't exists, downloading it..."
cd /usr/src/
git clone -b v3.5 https://github.com/iNextrix/ASTPP.git
cp -rf ASTPP latest
fi
if [ ${DIST} = "DEBIAN" ]; then
adduser --disabled-password --quiet --system --home ${FS_DIR} --gecos "FreeSWITCH Voice Platform" --ingroup daemon freeswitch
chown -R freeswitch:daemon ${FS_DIR}/
chmod -R o-rwx ${FS_DIR}/
chmod -R u=rwx,g=rx ${FS_DIR}/bin/*
cp ${ASTPP_SOURCE_DIR}/freeswitch/init/freeswitch.debian.init /etc/init.d/freeswitch
elif [ ${DIST} = "CENTOS" ]; then
cp ${ASTPP_SOURCE_DIR}/freeswitch/init/freeswitch.centos.init /etc/init.d/freeswitch
fi
chmod 755 /etc/init.d/freeswitch
chmod +x /etc/init.d/freeswitch
update-rc.d freeswitch defaults
chkconfig --add freeswitch
chkconfig --level 345 freeswitch on
mkdir /var/run/freeswitch
chown -R freeswitch:daemon /var/run/freeswitch
}
startup_services()
{
# Startup Services
if [ ${DIST} = "DEBIAN" ]; then
chkconfig --add nginx
chkconfig --level 345 nginx on
chkconfig --add mysql
chkconfig --level 345 mysql on
systemctl restart mysql
systemctl restart nginx
systemctl restart freeswitch
elif [ ${DIST} = "CENTOS" ]; then
chkconfig --add nginx
chkconfig --levels 35 nginx on
chkconfig --add mysqld
chkconfig --levels 35 mysqld on
systemctl restart mariadb
systemctl restart nginx
systemctl restart freeswitch
fi
}
# Setup MySQL For ASTPP
mySQL_for_astpp ()
{
# Start MySQL server
if [ ${DIST} = "DEBIAN" ]; then
systemctl restart mysql
else [ -f /etc/redhat-release ]
# /etc/init.d/mysqld restart
systemctl restart mariadb
fi
# Configure MySQL server
sleep 5
# Save MySQL root password to a text file in /root
echo ""
echo "MySQL password set to '${MYSQL_ROOT_PASSWORD}'. Remember to delete ~/.mysql_passwd" | tee ~/.mysql_passwd
echo "" >> ~/.mysql_passwd
echo "MySQL astppuser password: ${ASTPPUSER_MYSQL_PASSWORD} " >> ~/.mysql_passwd
chmod 400 ~/.mysql_passwd
read -n 1 -p "*** Press any key to continue ..."
if [ ${DIST} = "CENTOS" ]; then
mysql -uroot -e "UPDATE mysql.user SET password=PASSWORD('${MYSQL_ROOT_PASSWORD}') WHERE user='root'; FLUSH PRIVILEGES;"
fi
# Create astpp database
mysql -uroot -p${MYSQL_ROOT_PASSWORD} -e "create database ${ASTPP_DATABASE_NAME};"
mysql -uroot -p${MYSQL_ROOT_PASSWORD} -e "CREATE USER 'astppuser'@'localhost' IDENTIFIED BY '${ASTPPUSER_MYSQL_PASSWORD}';"
mysql -uroot -p${MYSQL_ROOT_PASSWORD} -e "GRANT ALL PRIVILEGES ON \`${ASTPP_DATABASE_NAME}\` . * TO 'astppuser'@'localhost' WITH GRANT OPTION;FLUSH PRIVILEGES;"
mysql -uroot -p${MYSQL_ROOT_PASSWORD} astpp < ${ASTPP_SOURCE_DIR}/database/astpp-3.0.sql
mysql -uroot -p${MYSQL_ROOT_PASSWORD} astpp < ${ASTPP_SOURCE_DIR}/database/astpp-upgrade-3.5.sql
if [ ${DIST} = "DEBIAN" ]; then
apt-get install libmyodbc unixodbc-bin
cp ${ASTPP_SOURCE_DIR}/misc/odbc/deb_odbc.ini /etc/odbc.ini
cp ${ASTPP_SOURCE_DIR}/misc/odbc/deb_odbcinst.ini /etc/odbcinst.ini
fi
if [ ${DIST} = "CENTOS" ]; then
yum install unixODBC mysql-connector-odbc
cp ${ASTPP_SOURCE_DIR}/misc/odbc/cent_odbc.ini /etc/odbc.ini
cp ${ASTPP_SOURCE_DIR}/misc/odbc/cent_odbcinst.ini /etc/odbcinst.ini
fi
sed -i "s#PASSWORD = <PASSWORD>#PASSWORD = ${MYSQL_ROOT_PASSWORD}#g" /etc/odbc.ini
}
install_astpp ()
{
# Download ASTPP
if [ ! -d ${ASTPP_SOURCE_DIR} ]; then
echo "ASTPP source doesn't exists, downloading it..."
cd /usr/src/
git clone -b v3.5 https://github.com/iNextrix/ASTPP.git
cp -rf ASTPP latest
fi
if [ ${DIST} = "DEBIAN" ]; then
# Install ASTPP pre-requisite packages using apt-get
systemctl stop apache2
systemctl disable apache2
apt-get -o Acquire::Check-Valid-Until=false update
apt-get install -y curl libyuv-dev libvpx2-dev nginx php5-fpm php5 php5-mcrypt libmyodbc unixodbc-bin php5-dev php5-common php5-cli php5-gd php-pear php5-cli php-apc php5-curl libxml2 libxml2-dev openssl libcurl4-openssl-dev gettext gcc g++
elif [ ${DIST} = "CENTOS" ]; then
# Install ASTPP pre-requisite packages using YUM
yum install -y autoconf automake bzip2 cpio curl nginx php-fpm php-mcrypt* unixODBC mysql-connector-odbc curl-devel php php-devel php-common php-cli php-gd php-pear php-mysql php-pdo php-pecl-json mysql mariadb-server mysql-devel libxml2 libxml2-devel openssl openssl-devel gettext-devel fileutils gcc-c++ httpd httpd-devel
fi
# cd ${ASTPP_SOURCE_DIR}
if [ ${DIST} = "DEBIAN" ]; then
echo "Normalize ASTPP for Debian"
touch /var/log/nginx/astpp_access_log
touch /var/log/nginx/astpp_error_log
touch /var/log/nginx/fs_access_log
touch /var/log/nginx/fs_error_log
php5enmod mcrypt
systemctl restart php5-fpm
service nginx reload
fi
if [ ${DIST} = "CENTOS" ]; then
systemctl stop apache2
systemctl disable apache2
systemctl start php-fpm
fi
if [ ${ASTPP_USING_FREESWITCH} = "yes" ]; then
#Folder creation and permission
mkdir -p ${ASTPPDIR}
mkdir -p ${ASTPPLOGDIR}
mkdir -p ${ASTPPEXECDIR}
if [ ${DIST} = "DEBIAN" ]; then
chown -Rf root.root ${ASTPPDIR}
chown -Rf www-data.www-data ${ASTPPLOGDIR}
chown -Rf root.root ${ASTPPEXECDIR}
elif [ ${DIST} = "CENTOS" ]; then
chown -Rf root.root ${ASTPPDIR}
chown -Rf root.root ${ASTPPLOGDIR}
chown -Rf root.root ${ASTPPEXECDIR}
fi
#Setup FS-Scripts
/bin/cp -rf ${ASTPP_SOURCE_DIR}/freeswitch/scripts/* ${FS_SCRIPTS}/
/bin/cp -rf ${ASTPP_SOURCE_DIR}/freeswitch/fs /var/www/html/
/bin/cp -rf ${ASTPP_SOURCE_DIR}/freeswitch/sounds/*.wav ${FS_SOUNDSDIR}/
chmod -Rf 755 ${FS_SOUNDSDIR}
rm -rf /usr/local/freeswitch/conf/dialplan/*
touch /usr/local/freeswitch/conf/dialplan/astpp.xml
rm -rf /usr/local/freeswitch/conf/directory/*
touch /usr/local/freeswitch/conf/directory/astpp.xml
rm -rf /usr/local/freeswitch/conf/sip_profiles/*
touch /usr/local/freeswitch/conf/sip_profiles/astpp.xml
fi
if [ ${INSTALL_ASTPP_WEB_INTERFACE} = "yes" ]; then
echo "Installing ASTPP web interface"
mkdir -p ${ASTPPDIR}
#Copy configuration file
cp ${ASTPP_SOURCE_DIR}/config/astpp-config.conf ${ASTPPDIR}astpp-config.conf
cp ${ASTPP_SOURCE_DIR}/config/astpp.lua ${ASTPPDIR}astpp.lua
#Install GUI of ATSPP
mkdir -p ${WWWDIR}/astpp
echo "Directory created ${WWWDIR}/astpp"
cp -rf ${ASTPP_SOURCE_DIR}/web_interface/astpp/* ${WWWDIR}/astpp/
if [ ${DIST} = "DEBIAN" ]; then
chown -Rf root.root ${WWWDIR}/astpp
cp ${ASTPP_SOURCE_DIR}/web_interface/nginx/deb_astpp.conf /etc/nginx/sites-enabled/astpp.conf
cp ${ASTPP_SOURCE_DIR}/web_interface/nginx/deb_fs.conf /etc/nginx/sites-enabled/fs.conf
sed -i "s/;request_terminate_timeout = 0/request_terminate_timeout = 300/" /etc/php5/fpm/pool.d/www.conf
sed -i "s/client_max_body_size 8M/client_max_body_size 20M/" /etc/nginx/sites-enabled/astpp.conf
sed -i '35i fastcgi_read_timeout 300;' /etc/nginx/sites-enabled/astpp.conf
systemctl restart nginx
elif [ ${DIST} = "CENTOS" ]; then
chown -Rf root.root ${WWWDIR}/astpp
cp ${ASTPP_SOURCE_DIR}/web_interface/nginx/cent_astpp.conf /etc/nginx/conf.d/astpp.conf
cp ${ASTPP_SOURCE_DIR}/web_interface/nginx/cent_fs.conf /etc/nginx/conf.d/fs.conf
sed -i "s/SELINUX=enforcing/SELINUX=disabled/" /etc/sysconfig/selinux
sed -i "s/SELINUX=enforcing/SELINUX=disabled/" /etc/selinux/config
sed -i "s/;request_terminate_timeout = 0/request_terminate_timeout = 300/" /etc/php-fpm.d/www.conf
sed -i "s/client_max_body_size 8M/client_max_body_size 20M/" /etc/nginx/conf.d/astpp.conf
sed -i '35i fastcgi_read_timeout 300;' /etc/nginx/conf.d/astpp.conf
/etc/init.d/iptables stop
chkconfig iptables off
setenforce 0
fi
chmod -Rf 755 ${WWWDIR}/astpp
chmod -Rf 755 ${WWWDIR}/fs
if [ ${DIST} = "DEBIAN" ]; then
chown -Rf www-data.www-data ${WWWDIR}/astpp
chown -Rf www-data.www-data ${ASTPPLOGDIR}
chown -Rf root.root ${WWWDIR}/fs
elif [ ${DIST} = "CENTOS" ]; then
chown -Rf apache.apache ${WWWDIR}/astpp
chown -Rf apache.apache ${ASTPPLOGDIR}
chown -Rf root.root ${WWWDIR}/fs
fi
fi
touch /var/log/astpp/astpp.log
}
finalize_astpp_installation ()
{
# /etc/php.ini short_open_tag = On
# short_open_tag = Off to short_open_tag = On
echo "Make sure Short Open Tag is switched On"
if [ ${DIST} = "DEBIAN" ]; then
sed -i "s#short_open_tag = Off#short_open_tag = On#g" /etc/php5/fpm/php.ini
sed -i "s#;cgi.fix_pathinfo=1#cgi.fix_pathinfo=1#g" /etc/php5/fpm/php.ini
sed -i "s/max_execution_time = 30/max_execution_time = 3000/" /etc/php5/fpm/php.ini
sed -i "s/upload_max_filesize = 2M/upload_max_filesize = 20M/" /etc/php5/fpm/php.ini
sed -i "s/post_max_size = 8M/post_max_size = 20M/" /etc/php5/fpm/php.ini
sed -i "s/memory_limit = 128M/memory_limit = 512M/" /etc/php5/fpm/php.ini
systemctl restart php5-fpm
systemctl restart nginx
elif [ ${DIST} = "CENTOS" ]; then
sed -i "s#short_open_tag = Off#short_open_tag = On#g" /etc/php.ini
sed -i "s#;cgi.fix_pathinfo=1#cgi.fix_pathinfo=1#g" /etc/php.ini
sed -i "s/max_execution_time = 30/max_execution_time = 3000/" /etc/php.ini
sed -i "s/upload_max_filesize = 2M/upload_max_filesize = 20M/" /etc/php.ini
sed -i "s/post_max_size = 8M/post_max_size = 20M/" /etc/php.ini
sed -i "s/memory_limit = 128M/memory_limit = 512M/" /etc/php.ini
####### Some more steps for CentOS 7 #########
yum update
sed -i "s/SELINUX=enforcing/SELINUX=disabled/" /etc/sysconfig/selinux
sed -i "s/SELINUX=enforcing/SELINUX=disabled/" /etc/selinux/config
setenforce 0
systemctl disable httpd
systemctl enable nginx
systemctl enable php-fpm
systemctl start mariadb
systemctl start freeswitch
systemctl stop firewalld
chkconfig --levels 345 mariadb on
chkconfig --levels 345 freeswitch on
chkconfig --levels 123456 firewalld off
fi
/bin/cp -rf ${ASTPP_SOURCE_DIR}/freeswitch/conf/autoload_configs/* /usr/local/freeswitch/conf/autoload_configs/
# edit ASTPP Database Connection Information
# /var/lib/astpp/astpp-config.conf
sed -i "s#dbpass = <PASSSWORD>#dbpass = ${MYSQL_ROOT_PASSWORD}#g" ${ASTPPDIR}astpp-config.conf
sed -i "s#DB_PASSWD=\"<PASSSWORD>\"#DB_PASSWD = \"${MYSQL_ROOT_PASSWORD}\"#g" ${ASTPPDIR}astpp.lua
sed -i "s#base_url=http://localhost:8081/#base_url=http://${ASTPP_HOST_DOMAIN_NAME}:8089/#g" ${ASTPPDIR}/astpp-config.conf
}
setup_cron()
{
if [ ${DIST} = "DEBIAN" ]; then
CRONPATH='/var/spool/cron/crontabs/astpp'
elif [ ${DIST} = "CENTOS" ]; then
CRONPATH='/var/spool/cron/astpp'
fi
echo "# Generate Invoice
0 1 * * * cd /var/www/html/astpp/cron/ && php cron.php GenerateInvoice
# Low balance notification
0 1 * * * cd /var/www/html/astpp/cron/ && php cron.php UpdateBalance
# Low balance notification
0 0 * * * cd /var/www/html/astpp/cron/ && php cron.php LowBalance
# Update currency rate
0 0 * * * cd /var/www/html/astpp/cron/ && php cron.php CurrencyUpdate
# Email Broadcasting
* * * * * cd /var/www/html/astpp/cron/ && php cron.php BroadcastEmail
" > $CRONPATH
chmod 600 $CRONPATH
crontab $CRONPATH
}
install_fail2ban()
{
read -n 1 -p "Do you want to install and configure Fail2ban ? (y/n) "
if [ "$REPLY" = "y" ]; then
if [ -f /etc/debian_version ] ; then
DIST="DEBIAN"
apt-get -y install fail2ban
elif [ -f /etc/redhat-release ] ; then
DIST="CENTOS"
echo ""
echo "Downloading sources"
cd /usr/src
service iptables stop
wget -T 10 -t 1 http://sourceforge.net/projects/fail2ban/files/fail2ban-stable/fail2ban-0.8.4/fail2ban-0.8.4.tar.bz2
echo "/!\IF FILE COULD BE DOWNLOADED, MAKE SURE TO UPLOAD SOURCE ARCHIVE [fail2ban-0.8.4.tar.bz2] MANUALLY IN [/usr/src/] DIRECTORY/!\"
echo "/!\PRESS [CTRL-C] TO ABORT OR [ENTER] WHEN SOURCE ARCHIVE IS UPLOADED OR DOWNLOADED/!\"
read -e OK
if [ ! -f /usr/src/fail2ban-0.8.4.tar.bz2 ] ; #File that you are looking for isn't there
then
echo "/!\ STOP /!\ FILE fail2ban-0.8.4.tar.bz2 NOT AVAILABLE IN /USR/SRC/"
echo "Aborting Installation"
exit
fi
echo "################################################################"
echo "File OK, unarchiving in progress"
tar -jxf fail2ban-0.8.4.tar.bz2
cd fail2ban-0.8.4
echo "################################################################"
echo "Fail2Ban installation in progress"
python setup.py install
cp /usr/src/fail2ban-0.8.4/files/redhat-initd /etc/init.d/fail2ban
chmod 755 /etc/init.d/fail2ban
echo "Installation done"
echo "################################################################"
echo "################################################################"
echo "Auto Configuration in progress"
echo "-- Writing /etc/fail2ban/filter.d/freeswitch.conf file"
touch /etc/fail2ban/filter.d/freeswitch.conf
cp /etc/fail2ban/filter.d/freeswitch.conf /etc/fail2ban/filter.d/freeswitch.bak
else
echo "***"
echo "*** This Installer should be run only on CentOS 6.x or Debian based system"
echo "***"
exit 1
fi
echo "
# Fail2Ban configuration file
[Definition]
# Option: failregex
# Notes.: regex to match the password failures messages in the logfile. The
# host must be matched by a group named "host". The tag '<HOST>' can
# be used for standard IP/hostname matching and is only an alias for
# (?:::f{4,6}:)?(?P<host>[\w\-.^_]+)
# Values: TEXT
#
failregex = \[WARNING\] sofia_reg.c:\d+ SIP auth failure \(INVITE\) on sofia profile \'[^']+\' for \[.*\] from ip <HOST>
# Option: ignoreregex
# Notes.: regex to ignore. If this regex matches, the line is ignored.
# Values: TEXT
#
ignoreregex =" > /etc/fail2ban/filter.d/freeswitch.conf
echo "
# Fail2Ban configuration file
[Definition]
# Option: failregex
# Notes.: regex to match the password failures messages in the logfile. The
# host must be matched by a group named "host". The tag '<HOST>' can
# be used for standard IP/hostname matching and is only an alias for
# (?:::f{4,6}:)?(?P<host>[\w\-.^_]+)
# Values: TEXT
#
failregex = \[WARNING\] sofia_reg.c:\d+ SIP auth challenge \(REGISTER\) on sofia profile \'[^']+\' for \[.*\] from ip <HOST>
# Option: ignoreregex
# Notes.: regex to ignore. If this regex matches, the line is ignored.
# Values: TEXT
#
ignoreregex =" > /etc/fail2ban/filter.d/freeswitch-dos.conf
################################# FREESWITCH.CONF FILE READY ##################
echo "-- Modifying /etc/fail2ban/jail.conf file"
################################# JAIL.CONF FILE WRITING ####################
cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.bak
echo "
[freeswitch]
enabled = true
port = 5060,5061,5080,5081
filter = freeswitch
logpath = /usr/local/freeswitch/log/freeswitch.log
maxretry = 10
bantime = 10000000
findtime = 480
action = iptables-allports[name=freeswitch, protocol=all]
sendmail-whois[name=FreeSwitch, dest=$EMAIL, sender=fail2ban@${ASTPP_HOST_DOMAIN_NAME}]
" >> /etc/fail2ban/jail.local
################################# JAIL.CONF FILE READY ######################
echo "################################################################"
echo "Auto Configuration Completed"
if [ -f /etc/redhat-release ] ; then
echo "Restarting IPtables"
/etc/init.d/iptables start
fi
echo "Starting Fail2Ban Integration"
mkdir /var/run/fail2ban
/etc/init.d/fail2ban start
if [ -f /etc/redhat-release ] ; then
echo "Restarting IPtables"
/etc/init.d/iptables restart
fi
/etc/init.d/fail2ban restart
if [ -f /etc/redhat-release ] ; then
chkconfig iptables on
fi
chkconfig fail2ban on
echo "################################################################"
echo "Fail2Ban for FreeSwitch & IPtables Integration completed"
else
echo ""
echo "Fail2ban installation is aborted !"
fi
}
astpp_install ()
{
if [ ${ASTPP_USING_FREESWITCH} = "yes" ]; then
install_freeswitch_for_astpp
astpp_freeswitch_startup_script
echo ""
echo "FreeSWITCH is Installed"
fi
install_astpp
mySQL_for_astpp
finalize_astpp_installation
setup_cron
startup_services
install_fail2ban
clear
echo "******************************************************************************************"
echo "******************************************************************************************"
echo "******************************************************************************************"
echo "********** **********"
echo "********** Your ASTPP is installed successfully **********"
echo " Browse URL: http://${ASTPP_HOST_DOMAIN_NAME}:8089"
echo " Username: admin"
echo " Password: admin"
echo "********** IMPORTANT NOTE: Please reboot your server once. **********"
echo "********** **********"
echo "******************************************************************************************"
echo "******************************************************************************************"
echo "******************************************************************************************"
}
# Install astpp
start_install_astpp ()
{
if [ ${DIST} = "CENTOS" ]; then
astpp_install
elif [ ${DIST} = "DEBIAN" ]; then
astpp_install
else
echo "Can't install with this script on your OS"
fi
}
if [ ${INSTALL_ASTPP} = "yes" ]; then
start_install_astpp
fi