forked from a4business/MPBX
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathINSTALL-Centos8.sh
728 lines (610 loc) · 25.3 KB
/
INSTALL-Centos8.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
#!/bin/bash
########
##### Multitenant PBX: installation steps
##### Centos 8
########
### Refresh outdated Repo Locations:
sed -i 's/^mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-*
sed -i 's|^#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-*
[ -f ./.domain ] && . .domain
[ -f ./.ip ] && . .ip
# External IP:
IP_=$(ip route get 8.8.8.8 | awk -F"src " 'NR==1{split($2,a," ");print a[1]}')
IP=${IP:-$IP_}
read -p " Server External IP[${IP}]" IP_
IP=${IP_:-$IP}
echo "IP=$IP" > ./.ip
#Domain:
read -p " FQDN Domain name:[${DOMAIN_}]" DOMAIN
DOMAIN=${DOMAIN:-$DOMAIN_}
echo "DOMAIN_=$DOMAIN" > ./.domain
# Disable Security #
setenforce 0
if [ ! -f /usr/bin/perl ];then
echo ' Perl install...'
yum install perl -y
fi
## Disable SeLinux : ## This will ask confirmation to delete selinux: ##
perl -pi -e "s/=enforcing/=disabled/g" /etc/selinux/config
[ $(rpm -qa |grep selinux-policy-targeted | wc -l) -gt 0 ] && yum remove selinux-policy-targeted -y
firewall-cmd --zone public --add-port 80/tcp --permanent
firewall-cmd --zone public --add-port 443/tcp --permanent
firewall-cmd --zone public --add-source 127.0.0.1 --permanent
firewall-cmd --zone public --add-port 5060/udp --permanent
firewall-cmd --zone public --add-port 8081/udp --permanent
firewall-cmd --zone public --add-port 8443/udp --permanent
firewall-cmd --zone public --add-port 19302/udp --permanent
firewall-cmd --zone public --add-port 19303/udp --permanent
firewall-cmd --zone public --add-port 8081/tcp --permanent
firewall-cmd --zone public --add-port 8443/tcp --permanent
firewall-cmd --zone public --add-port 19302/tcp --permanent
firewall-cmd --reload
yum groupinstall core base 'Development Tools' -y
if [ $(rpm -qa|grep remi-release|wc -l) -eq 0 ]; then
read -p " ### Install epel-release and remi-release [ next ]" next
rpm -Uvh http://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
if [ $(cat /etc/redhat-release|grep "8.5.2"|wc -l) -eq 1 ];then
rpm -Uvh https://rpms.remirepo.net/enterprise/8/remi/x86_64/remi-release-8.5-2.el8.remi.noarch.rpm
else
rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-8.rpm
fi
fi
### Tool repo, install DNF plugins package:
dnf -y install dnf-plugins-core
dnf config-manager --set-enabled powertools
###
[ $(rpm -qa |grep selinux-policy-targeted | wc -l) -gt 0 ] && yum remove selinux-policy-targeted -y
## xmlstarlet?
yum install -y gcc gcc-c++ unixODBC-devel libiodbc-devel yum-utils bison mysql-devel mysql-server tftp-server httpd make ncurses-devel libtermcap-devel sendmail sendmail-cf caching-nameserver newt-devel libxml2-devel libtiff-devel audiofile-devel gtk2-devel subversion kernel-devel git subversion kernel-devel crontabs cronie cronie-anacron wget vim certbot libtool sqlite-devel sqlite-devel unixODBC uuid-devel libuuid-devel binutils-devel opus opus-devel libedit-devel openssl-devel libevent libevent-devel libedit-devel libxml2-devel sqlite-devel curl-devel unixODBC-devel certbot certbot-apache mod_ssl iptables iptables-services tcpdump ngrep fail2ban net-tools libsrtp libsrtp-devel sox sox-devel
## Captagent Dependeces + Zabbix agent
yum install -y json-c-devel expat-devel libpcap-devel flex-devel automake libtool bison libuv-devel flex pcre-devel zabbix-agent
## Install Statically linked ffmpeg:
if [ ! -f /usr/bin/ffmpeg ]; then
read -p " ### Install ffmpeg static [enter]" next
FILE="ffmpeg-release-amd64-static.tar.xz"
LINK="https://johnvansickle.com/ffmpeg/releases/ffmpeg-release-amd64-static.tar.xz"
[ ! -f /usr/bin/ffmpeg ] && wget ${LINK} && tar -xJf ${FILE} && cp ./ffmpeg-*-amd64-static/ffmpeg /usr/bin/ffmpeg
fi
## SOX
if [ -f /usr/bin/sox ];then
read -p " SOX Already installed, Re-Install it??? [n]" P
[ "${P:-n}" == "y" ] && rm -rf /usr/bin/sox
fi
if [ ! -f /usr/bin/sox ]; then
read -p " ### Install SOx from Sources: [enter]" next
GETSOX=https://ftp.icm.edu.pl/packages/sox/14.4.2/sox-14.4.2.tar.gz
wget ${GETSOX} && tar -xvzf sox-14.4.2.tar.gz && cd sox-14.4.2 && ./configure --prefix=/usr && make && make install
if [ ! -f /usr/bin/sox ]; then
read -p " [WARNING]: SOX is not installed form sources, Re-try install from packages y/n? [y]" P
P=${P:-y}
if [ "$P" = "y" ]; then
yum install sox sox-devel -y
fi
fi
fi
if [ -f /usr/local/captagent/sbin/captagent ];then
read -p " CAPTAGENT for HOMER7 Already installed, Re-Install it??? [n]" P
[ "${P:-n}" == "y" ] && rm -rf /usr/local/captagent/sbin/captagent
fi
if [ ! -f /usr/local/captagent/sbin/captagent ]; then
PWD=$(pwd)
echo " [ Installing CAPTAGENT for HOMER7 ] " ### https://github.com/sipcapture/captagent/wiki/Installation
cd /usr/src
rm -rf captagent
git clone https://github.com/sipcapture/captagent.git captagent
cd captagent
./build.sh
./configure
make && make install
cp init/el/captagent.sysconfig /etc/sysconfig/captagent
cp init/el/captagent.service /usr/lib/systemd/system
systemctl enable captagent
systemctl status captagent
cd $PWD
else
echo " [ CAPTAGENT INSTALLED ALREADY! ] "
fi
if [ ! -f /usr/bin/php ]; then
echo -n " ### Install f@ck!ng old PHP ( 5.x ) ? " && read -p ' [enter]' next
yum install -y php56 php56-php-curl php56-php-ldap php56-php-fileinfo php56-php-zip php56-php-fileinfo php56-php-xml php56-php-mbstring php56-php-process php56-php-http php56-php-devel php56-php-mysql php56-mod_php
php56-pear channel-update pear.php.net && php56-pear install db-1.7.14
update-alternatives --install /usr/bin/php php /opt/remi/php56/root/bin/php 1
php -v
fi
[ -f /etc/opt/remi/php56/php.ini ] && perl -pi -e "s/post_max_size = 8M/post_max_size = 32M/" /etc/opt/remi/php56/php.ini
[ -f /etc/opt/remi/php56/php.ini ] && perl -pi -e "s/upload_max_filesize = 2M/upload_max_filesize = 20M/" /etc/opt/remi/php56/php.ini
[ -f /usr/lib/systemd/system/php56-php-fpm.service ] && perl -pi -e "s/PrivateTmp=true/PrivateTmp=false/" /usr/lib/systemd/system/php56-php-fpm.service && systemctl daemon-reload && systemctl restart php56-php-fpm
if [ -f /usr/sbin/mysqld ] ; then
echo -n " ### Install mysql-server:" && read -p ' [enter]' next
yum install mysql-server mysql-devel -y
yum install php56-php-mysqlnd perl-DBD-MySQL cyrus-sasl-sql postfix -y
service mysqld start
/usr/bin/mysql_secure_installation
wget https://repo.mysql.com//mysql80-community-release-el8-1.noarch.rpm
rpm -Uvh mysql80-community-release-el8-1.noarch.rpm
perl -pi -e "s/gpgcheck=1/gpgcheck=0/g" /etc/yum.repos.d/mysql-community*
yum install -y mysql-connector-odbc
fi
#VER=16
VER=18
## ASTERISK
if [ -f /usr/sbin/asterisk ];then
read -p " ASTERISK Pbx Already installed, Re-Install it??? [n]" P
[ "${P:-n}" == "y" ] && rm -rf /usr/sbin/asterisk && AST_PREFIX="RE-"
fi
if [ ! -f /usr/sbin/asterisk ] ; then
read -p " ### ${AST_PREFIX}Install Asterisk v${VER} From Sources ? [ enter ]" next
rm -rf asterisk-${VER}.*
[ ! -f asterisk-${VER}-current.tar.gz ] && wget http://downloads.asterisk.org/pub/telephony/asterisk/asterisk-${VER}-current.tar.gz
tar -xzf asterisk-${VER}-current.tar.gz && cd asterisk-${VER}.*
contrib/scripts/install_prereq install
make clean
./configure --with-pjproject-bundled --with-jansson-bundled
make menuselect.makeopts
menuselect/menuselect --enable res_config_mysql menuselect.makeopts
menuselect/menuselect --enable format_mp3 menuselect.makeopts
menuselect/menuselect --enable codec_opus menuselect.makeopts
menuselect/menuselect --enable codec_silk menuselect.makeopts
menuselect/menuselect --enable codec_siren7 menuselect.makeopts
menuselect/menuselect --enable codec_siren14 menuselect.makeopts
contrib/scripts/get_mp3_source.sh
make && make install && make samples && make config
[ $VER == 18 ] && perl -pi -e "s/noload = chan_sip.so/;noload = chan_sip.so/" /etc/asterisk/modules.conf
fi
## SNGREP Install
if [ -f /usr/local/bin/sngrep ];then
read -p " SNGREP tool Already installed, Re-Install it??? [n]" P
[ "${P:-n}" == "y" ] && rm -rf /usr/local/bin/sngrep && SNGREP_PREFIX="RE-"
fi
if [ ! -f /usr/local/bin/sngrep ]; then
read -p " ### ${SNGREP_PREFIX}Install SNGREP ? [ enter ]" next
cd /usr/src
git clone https://github.com/irontec/sngrep.git
cd sngrep
./bootstrap.sh
./configure
make && make install
fi
####### Install WEB files form this Remote:#######################################
read -p " Install WEB GUI from repo [ enter ] " next
cd /var/www/html
git clone https://git.a4business.com/george/mpbx.git ./pbx
git clone https://git.a4business.com/george/crm.git ./crm
curl -sS https://getcomposer.org/installer | php
mv composer.phar /usr/local/bin/composer
cp /usr/local/bin/composer /usr/bin/composer
cd /var/www/html/pbx && composer install
cd /var/www/html/pbx/core && composer install
cd /var/www/html/crm && composer install
## Make forlder for Text2Speech cache:
mkdir -p /tts && chmod 777 /tts
read -p " Next - Configure Asterisk PBX server? [ enter ] " next
## Link Asterisk config files
for CONF in func_odbc.conf macros.include conferences.include; do ln -sf /var/www/html/pbx/core/${CONF} /etc/asterisk/${CONF}; done
cd /etc/asterisk && for CONF in extensions.tenants inbound.include internal.include ivrmenus.include outbound.include queues.include res_parking.include ringgroups.include sip-register.tenants sip.tenants tenants.include; do touch $CONF; chown apache.apache $CONF; done
echo "#include res_parking.include" >> /etc/asterisk/res_parking.conf
rm -rf /var/lib/asterisk/agi-bin && ln -sf /var/www/html/pbx/agi-bin /var/lib/asterisk/agi-bin
read -p " Next - Configure MySQL Server ? [ enter ] " next
### Create Databas ###
## To get tmeporary pass: grep 'temporary password' /var/log/mysqld.log
## or reset root:
## sudo mysqld_safe --skip-grant-tables &
## alter user 'root'@'localhost' IDENTIFIED BY 'p@ssw0rd';
## /etc/init.d/mysqld restart
[ -f ~/.mysql ] && . ~/.mysql
read -p " Provide Mysql root password to setup DB(type help for reset info):[${mysql_pass}]" P
[ "${P}" = "help" ] && echo -e "To get myslq root after mysqld install: grep 'temporary password' /var/log/mysqld.log\n\t To reset mysql root: \n\t\tsudo mysqld_safe --skip-grant-tables\n\t\techo alter user 'root'@'localhost' IDENTIFIED BY 'p@ssw0rd'; | mysql\n\t\t/etc/init.d/mysqld restart\n" && exit
P=${P:-$mysql_pass}
export MYSQL_PWD=${P}
echo "mysql_pass=$MYSQL_PWD" > ~/.mysql
## Create Local User:
echo 'create database mpbx ;'| mysql -p${P}
echo 'create user mpbx_web@`localhost` identified by "P@ssw0rd123" ;'| mysql -p${P}
echo 'grant all privileges on mpbx.* to mpbx_web@`localhost` '| mysql -p${P}
## Create database structure
cat /var/www/html/pbx/core/proc/mpbx.sql | mysql -u root -p${P} mpbx
cat /var/www/html/pbx/core/proc/mpbx-initial-data.sql | mysql -u root -p${P} mpbx
cd /var/www/html/pbx/core/proc && ./install ${P}
read -p " Next - Configure Apache WEB server ? [ enter ] " next
cat <<EOF > /etc/httpd/conf.d/${DOMAIN}.conf
<VirtualHost *:80>
ServerName ${DOMAIN}
DocumentRoot /var/www/html/crm
ServerAlias www.${DOMAIN}
RewriteEngine on
RewriteCond %{SERVER_NAME} =${DOMAIN} [OR]
RewriteCond %{SERVER_NAME} =www.${DOMAIN}
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
EOF
read -p " Generate TLS certificates for Domain: ${DOMAIN} [ enter ]" next
################ Create ssl certificates ( required for webrtc (wss/dtls) and for SIP/tls )
service httpd restart
if [ "${DOMAIN:-no}" != "no" ]; then
[ ! -d /etc/letsencrypt/live/${DOMAIN} ] && certbot -d ${DOMAIN} certonly --apache
if [ -d /etc/letsencrypt/live/${DOMAIN} ]; then
[ ! -L /etc/asterisk/keys ] && ln -sf /etc/letsencrypt/live/${DOMAIN} /etc/asterisk/keys
[ ! -f /etc/asterisk/keys/TLS.pem ] && cd /etc/asterisk/keys && cat privkey.pem fullchain.pem > TLS.pem
else
echo 'Warning: SSL certs not created!'
fi
else
echo "WARNING: no domain name - SKIPPED SSL generation!"
fi
## Commercial SSL convert into PEM:
# openssl rsa -in domain.com.key -out domain.com.key.pem
# openssl x509 -inform PEM -in domain.com.crt -out domain.com.crt.pem
# cat domain.com.key.pem domain.com.crt.pem domain.com-bundle > TLS.pem
read -p " Configure WEB server Apache2 with domain[$DOMAIN] [ enter ] " next
## Configure WEB Server :
[ ! -f /etc/httpd/conf.d/ssl.conf.old ] && mv /etc/httpd/conf.d/ssl.conf /etc/httpd/conf.d/ssl.conf.old
if [ ! -f /etc/httpd/conf.d/${DOMAIN}.conf ]; then
cat <<EOF > /etc/httpd/conf.d/${DOMAIN}.conf
<VirtualHost *:80>
ServerName ${DOMAIN}
DocumentRoot /var/www/html/crm
ServerAlias www.${DOMAIN}
RewriteEngine on
RewriteCond %{SERVER_NAME} =${DOMAIN} [OR]
RewriteCond %{SERVER_NAME} =www.${DOMAIN}
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
<VirtualHost localhost:8081>
SSLProxyEngine on
Timeout 1200
ProxyTimeout 1200
ServerName ${DOMAIN}
DocumentRoot /var/www/html/pbx
ServerAlias www.${DOMAIN}
<Directory /var/www/html/pbx >
AllowOverride All
Options Indexes MultiViews FollowSymLinks
</Directory>
</VirtualHost>
EOF
fi
if [ ! -f /etc/httpd/conf.d/${DOMAIN}-le-ssl.conf ]; then
cat <<EOF > /etc/httpd/conf.d/${DOMAIN}-le-ssl.conf
<IfModule mod_ssl.c>
Listen 443 https
Listen 8081 https
<VirtualHost _default_:443>
SSLProxyEngine on
Timeout 1200
ProxyTimeout 1200
ServerName ${DOMAIN}
DocumentRoot /var/www/html/crm
ServerAlias www.${DOMAIN}
<Directory /var/www/html/crm >
AllowOverride All
Options Indexes MultiViews FollowSymLinks
</Directory>
SSLCertificateFile /etc/letsencrypt/live/${DOMAIN}/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/${DOMAIN}/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
<VirtualHost *:8081>
ServerName ${DOMAIN}
DocumentRoot /var/www/html/pbx
ServerAlias www.${DOMAIN}
<Directory /var/www/html/pbx >
AllowOverride All
Options Indexes MultiViews FollowSymLinks
</Directory>
SSLCertificateFile /etc/letsencrypt/live/${DOMAIN}/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/${DOMAIN}/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
</IfModule>
EOF
fi
[ ! -f /etc/httpd/options-ssl-apache.conf ] && cp /etc/letsencrypt/options-ssl-apache.conf /etc/httpd/
service httpd restart
read -p " Configure MYSQL Server [ enter ]" next
## Configure Database##
if [ $(cat /etc/my.cnf|grep utf8_unicode|wc -l) -eq 0 ] ; then
cat <<EOF > /etc/my.cnf
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8
[mysqld]
collation-server = utf8_unicode_ci
character-set-server = utf8
default_authentication_plugin = mysql_native_password
EOF
service mysqld restart
fi
### COnfigure ODBC connection
## First: make sure the Mysql Driver name used is mentioned in : /etc/odbcinst.ini and Librarry is in place
## For example: perl -pi -e "s/libmyodbc5.so/libmyodbc8a.so/g" /etc/odbcinst.ini
[ $(cat /etc/odbc.ini|grep PBX|wc -l) -eq 0 ] && cat <<EOF >> /etc/odbc.ini
[mpbx]
Description = PBX MySQL ODBC
Driver = MySQL ODBC 8.0 Unicode Driver
Socket = /var/lib/mysql/mysql.sock
User = mpbx_web
Password = P@ssw0rd123
Database = mpbx
Option = 3
EOF
## NOTE: after setting up odbc.ini, Make sure you can connect by running: isql mpbx
read -p " Configure CoTURN with IP[${IP_}]/Domain: $DOMAIN [ enter ]" next
## Coturn install
yum install coturn -y
if [ ! -f /usr/bin/turnserver ]; then
wget http://turnserver.open-sys.org/downloads/v4.5.1.1/turnserver-4.5.1.1.tar.gz
tar -xvzf turnserver-4.5.1.1.tar.gz
cd turnserver-4.5.1.1
./configure --prefix=/usr
make && make install
fi
cat <<EOF > /etc/turnserver.conf
listening-ip=$IP
relay-ip=$IP
listening-port=19302
tls-listening-port=19303
cert=/etc/asterisk/keys/TLS.pem
pkey=/etc/asterisk/keys/privkey.pem
fingerprint
realm=${DOMAIN}
server-name=${DOMAIN}
lt-cred-mech
user=turn:secured
user=stun:secured
log-file=/var/log/coturn.log
no-stdout-log
EOF
#### Install Initd file: to /etc/init.d/turnserverd
cat <<EOF > /etc/init.d/turnserverd
#! /bin/sh
# /etc/init.d/turnserver
#
# chkconfig: 2345 90 60
# description: Stun/ Turnserver for telephony
# processname: turnserver
# Some things that run always
touch /var/lock/
# Carry out specific functions when asked to by the system
case "\$1" in
start)
echo "Starting turnserver"
cat /etc/turnserver.conf 2>/dev/null |grep '^listen'
/usr/bin/turnserver -c /etc/turnserver.conf >/var/log/turnserver.log 2>&1 &
;;
stop)
echo "Stopping script turnserver"
killall -9 turnserver || echo "Failed to stop turnserver "
;;
*)
echo "Usage: /etc/init.d/turnserver {start|stop}"
exit 1
;;
esac
exit 0
EOF
chmod +x /etc/init.d/turnserverd
chkconfig --add turnserverd
chkconfig turnserverd on
service turnserverd start
####################### Confiure Asterisk: ###############################
read -p " configure Asterisk server[enter]" next
perl -pi -e "s/^;verbose =/verbose=/" /etc/asterisk/asterisk.conf
perl -pi -e "s/^;debug =/debug=/" /etc/asterisk/asterisk.conf
perl -pi -e "s/^;full =/full =/" /etc/asterisk/logger.conf
rasterisk -rx 'logger reload'
## Make sure cert files exists!!
cat <<EOF > /etc/asterisk/sip_tls.conf
tlsenable=yes
tlsbindaddr=0.0.0.0:5061
tlscertfile=/etc/asterisk/keys/TLS.pem
tlsprivatekey=/etc/asterisk/keys/privkey.pem
tlscafile=/etc/asterisk/keys/fullchain.pem
tlsclientmethod=ALL
tlscipher=ALL
tlsclientmethod=tlsv1
tlsdontverifyserver=yes
EOF
perl -pi -e "s/^;tlscertfile/#include sip_tls.conf\n;;;tlscertfile/" /etc/asterisk/sip.conf
perl -pi -e "s/^;rtcachefriends=yes/rtcachefriends=yes/" /etc/asterisk/sip.conf
perl -pi -e "s/enabled = no/enabled = yes/" /etc/asterisk/manager.conf
perl -pi -e "s/bindaddr = 0.0.0.0/bindaddr = 127.0.0.1/" /etc/asterisk/manager.conf
perl -pi -e "s/; retry rules\./; retry rules\.\n#include sip-register.tenants\n"/ /etc/asterisk/sip.conf
touch /etc/asterisk/sip.tenants && echo "#include sip.tenants" >> /etc/asterisk/sip.conf
cat <<EOF > /etc/cron.d/mpbx
## Generate additional SIP settings every minute #
* * * * * root [ $(ps ax|grep gen_sip_settings|grep -v grep) -eq 0 ] && ( cd /var/www/html/pbx && php core/gen_sip_settings.php > /etc/asterisk/sip.include 2>&1)
## Every Night clean CDRs/CEL
0 3 * * * root curl -k https://localhost:8081/jaxer.php?cleanCDRS=1 >> /var/log/pbx.log 2>&1 &
EOF
service crond restart
### Fail2ban:
read -p ' Configure Fail2ban? [ enter ]' next
[ -f /etc/fail2ban/jail.d/00-firewalld.conf ] && perl -pi -e "s/banaction/#banaction/g" /etc/fail2ban/jail.d/00-firewalld.conf
echo -e "[DEFAULT]\nignoreip = 127.0.0.1/8 ::1\n" > /etc/fail2ban/jail.d/local.conf
sed -i "45i\ \t curl -k 'https://localhost:8081/jaxer.php?blockIP=<ip>&block_reason=by-Fail2Ban-<name>-REJECT&bantime=<bantime>'" /etc/fail2ban/action.d/iptables-allports.conf
sed -i "42i\ \t curl -k 'https://localhost:8081/jaxer.php?blockIP=<ip>&block_reason=by-Fail2Ban-<name>-REJECT&bantime=<bantime>'" /etc/fail2ban/action.d/iptables-multiport.conf
cat <<EOF > /etc/fail2ban/jail.local
[asterisk]
enabled = true
port = 0:65535
action_ = %(default/action_)s[name=%(__name__)s-tcp, protocol="tcp"]
%(default/action_)s[name=%(__name__)s-udp, protocol="udp"]
logpath = /var/log/asterisk/full
actionban = <iptables> -I f2b-<name> 1 -s <ip> -j <blocktype>
curl -k "https://localhost:8081/jaxer.php?blockIP=<ip>&block_reason=by-Fail2Ban-<name>-REJECT&bantime=<bantime>" 2>/dev/null
maxretry = 3
bantime = 3600
findtime = 300
EOF
CONF=cel_odbc.conf
[ $(cat /etc/asterisk/$CONF|grep 'pbxdb'|wc -l) -eq 0 ] && cat <<EOF > /etc/asterisk/$CONF
[general]
[cel]
connection=pbxdb
username = mpbx_web
password = P@ssw0rd123
loguniqueid=yes
table=t_cel ;"cdr" is default table name
usegmtime=no ; set to "yes" to log in GMT
alias userfield => tenant_id
EOF
CONF=cel.conf
[ $(cat /etc/asterisk/$CONF|grep 'events=ALL'|wc -l) -eq 0 ] && cat <<EOF > /etc/asterisk/$CONF
[general]
enable=yes
apps=all
events=ALL
dateformat = %d-%m-%Y %T
EOF
CONF=cdr_adaptive_odbc.conf
[ $(cat /etc/asterisk/$CONF|grep pbxdb|wc -l) -eq 0 ] && cat <<EOF >> /etc/asterisk/$CONF
[global]
connection=pbxdb
username = mpbx_web
password = P@ssw0rd123
loguniqueid=yes
dispositionstring=yes
table=t_cdrs ;"cdr" is default table name
usegmtime=no ; set to "yes" to log in GMT
alias start => calldate
EOF
CONF=res_odbc.conf
[ $(cat /etc/asterisk/$CONF|grep pbxdb|wc -l) -eq 0 ] && cat <<EOF >> /etc/asterisk/$CONF
[pbxdb]
enabled => yes
dsn => mpbx
username => mpbx_web
password => P@ssw0rd123
pre-connect => yes
EOF
CONF=res_config_mysql.conf
[ $(cat /etc/asterisk/$CONF|grep pbxdb|wc -l) -eq 0 ] && cat <<EOF >> /etc/asterisk/$CONF
[pbxdb]
dbhost=localhost
dbname=mpbx
dbuser=mpbx_web
dbpass=P@ssw0rd123
dbport=3306
dbsock=/var/lib/mysql/mysql.sock
requirements=warn
EOF
CONF=extensions.conf
[ $(cat /etc/asterisk/$CONF|grep tenants|wc -l) -eq 0 ] && cat <<EOF > /etc/asterisk/$CONF
[general]
static=yes
writeprotect=yes
priorityjumping=no
autofallthrough=no
clearglobalvars=yes
[globals]
RECORDING_FORMAT=WAV
#include extensions.tenants
[from-pstn]
include => did-inbound
exten => i,1,NooP( INVALID INBOUND EXTEN:${EXTEN} FROM \${CHANNEL(peerip)} )
same => n,Playback(invalid)
same => n,Hangup()
EOF
CONF=extconfig.conf
[ $(cat /etc/asterisk/$CONF|grep pbxdb|wc -l) -eq 0 ] && cat <<EOF >> /etc/asterisk/$CONF
musiconhold => mysql,pbxdb,t_moh
sippeers => mysql,pbxdb,t_sip_users
voicemail => mysql,pbxdb,t_vmusers
queues => mysql,pbxdb,t_queues
queue_members => mysql,pbxdb,t_queue_members
extensions => mysql,pbxdb,t_extensions
followme => mysql,pbxdb,t_user_options
followme_numbers => mysql,pbxdb,t_user_followme
EOF
# Enable WEB clients to receive calls :
perl -pi -e "s/;rtcachefriends=yes/rtcachefriends=yes/" /etc/asterisk/sip.conf
# Disable skinny public access :
perl -pi -e "s/0.0.0.0/127.0.0.1/g" /etc/asterisk/skinny.conf
CONF=manager.conf
perl -pi -e "s/bindaddr = 127.0.0.1/bindaddr = 0.0.0.0/" /etc/asterisk/$CONF
[ $(cat /etc/asterisk/$CONF|grep pbx-manager-dev|wc -l) -eq 0 ] && cat <<EOF >> /etc/asterisk/$CONF
[pbx-manager-dev]
writetimeout=200
displayconnects=no
secret=92jdf3hfdf
deny=0.0.0.0/0.0.0.0
permit=127.0.0.1/255.255.255.0
permit=192.168.0.0/255.255.0.0 ; RFC 1918 addresses
permit=10.0.0.0/255.0.0.0 ; Also RFC1918
permit=172.16.0.0/12 ; Another RFC1918 with CIDR notation
permit=169.254.0.0/255.255.0.0 ; Zero conf local network
read = system,call,log,verbose,agent,user,dtmf,reporting,cdr,dialplan
write = system,call,agent,user,command,reporting,originate
EOF
CONF=http.conf
[ $(cat /etc/asterisk/$CONF|grep TLS.pem|wc -l) -eq 0 ] && cat <<EOF > /etc/asterisk/$CONF
[general]
servername=Asterisk
enabled=no
bindaddr=127.0.0.1
bindport=8081
tlsenable=yes
tlsbindaddr=0.0.0.0:8443
tlscertfile=/etc/asterisk/keys/TLS.pem
tlsprivatekey=/etc/asterisk/keys/privkey.pem
EOF
## Create INI files from samples
read -p " Generate dynamic configuration [ enter ]" next
for PRJ in pbx crm; do
[ ! -f /var/www/html/${PRJ}/include/config.ini ] && cp /var/www/html/${PRJ}/include/config.ini.sample /var/www/html/${PRJ}/include/config.ini 2>/dev/null
[ "$DOMAIN" != "" ] && perl -pi -e "s/app.a4business.com/$DOMAIN/g" /var/www/html/${PRJ}/include/config.ini
done
## Test run :
cd /var/www/html/pbx && php core/gen_sip_settings.php
## Do not load some depricated modules (chan_sip is next)
[ $(cat /etc/asterisk/modules.conf|grep cdr_musql|wc -l) -eq 0 ] && echo -e "noload = app_image\nnoload = chan_oss\nnoload = chan_skinny\nnoload = cdr_mysql" >> /etc/asterisk/modules.conf
### Logrotate:
cat <<EOF > /etc/logrotate.d/asterisk
/var/log/asterisk/full
/var/log/asterisk/debug
/var/log/asterisk/messages
/var/log/pbx.log
/var/log/reports.log
{
rotate 6
missingok
maxsize 50M
delaycompress
daily
postrotate
/usr/sbin/asterisk -rx 'logger reload' 2>/dev/null || true
endscript
}
EOF
chmod +s /usr/sbin/asterisk
service firewalld stop
chkconfig firewalld off
touch /var/log/pbx.log && chown apache.apache /var/log/pbx.log
chown -R apache.apache /var/lib/asterisk/sounds /var/lib/asterisk/moh /var/lib/asterisk /tts /var/spool/asterisk/monitor
chmod a+s /var/spool/asterisk
chmod a+x /var/spool/asterisk/monitor
service turnd stop
service turnd start
for SERVICE in sendmail fail2ban mysqld httpd asterisk php56-php-fpm
do
chkconfig --level 345 ${SERVICE} on
service ${SERVICE} start
done
cat <<EOF
============================================================
MPBX INSTALLATION COMPLETED !
============================================================
Access your server with default login:
Admin panel: https://${DOMAIN}:8081 admin : CHANGEME1
Agent panel: https://${DOMAIN} admin : CHANGEME1
To create more agents, follow this plan:
1. Create more extensions in tenant
2. Create a user, and link it with extension
3. Login to WEBrtc Dialer:
https://${DOMAIN} with created user credentials , call to *600 ( echo test app )
=============================================================
Check MySQL collation(check migration script)
sip.conf for sip.include script,
ODBC Driver version /etc/odbc.ini [isql mpbx]
EOF