forked from engintron/engintron
-
Notifications
You must be signed in to change notification settings - Fork 0
/
engintron.sh
1098 lines (915 loc) · 33.7 KB
/
engintron.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
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
# /**
# * @version 1.8.8
# * @package Engintron for cPanel/WHM
# * @author Fotis Evangelou
# * @url https://engintron.com
# * @copyright Copyright (c) 2010 - 2018 Nuevvo Webware P.C. All rights reserved.
# * @license GNU/GPL license: https://www.gnu.org/copyleft/gpl.html
# */
# Constants
APP_PATH="/usr/local/src/engintron"
APP_VERSION="1.8.8"
CPANEL_PLG_PATH="/usr/local/cpanel/whostmgr/docroot/cgi"
REPO_CDN_URL="https://cdn.rawgit.com/engintron/engintron/master"
GET_HTTPD_VERSION=$(httpd -v | grep "Server version")
GET_CENTOS_VERSION=$(rpm -q --qf "%{VERSION}" $(rpm -q --whatprovides redhat-release))
GET_CPANEL_VERSION=$(/usr/local/cpanel/cpanel -V)
############################# HELPER FUCTIONS [start] #############################
function install_basics {
echo "=== Let's upgrade our system first & install a few required packages ==="
yum -y update
yum -y upgrade
yum -y install atop bash-completion bc cronie curl htop ifstat iftop iotop make nano openssl-devel pcre pcre-devel sudo tree unzip zip zlib-devel
yum clean all
echo ""
echo ""
}
function install_mod_remoteip {
# Get system IPs
SYSTEM_IPS=$(ip addr show | grep -o "inet [0-9]*\.[0-9]*\.[0-9]*\.[0-9]*" | grep -o "[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*" | sed ':a;N;$!ba;s/\n/ /g');
if [[ ! $(echo $SYSTEM_IPS | grep "127.0.0.1") ]]; then
SYSTEM_IPS="127.0.0.1 $SYSTEM_IPS"
fi
echo "=== Installing mod_remoteip for Apache ==="
if [ -f /etc/apache2/conf/httpd.conf ]; then
yum -y install ea-apache24-mod_remoteip
if [ -f /etc/apache2/modules/mod_remoteip.so ]; then
REMOTEIP_CONF=$(find /etc/apache2/conf.modules.d/ -iname "*_mod_remoteip.conf")
if [ -f $REMOTEIP_CONF ]; then
cat > $REMOTEIP_CONF <<EOF
# mod_remoteip (https://httpd.apache.org/docs/current/mod/mod_remoteip.html)
LoadModule remoteip_module modules/mod_remoteip.so
RemoteIPHeader X-Forwarded-For
RemoteIPInternalProxy $SYSTEM_IPS
EOF
sed -i "s:LogFormat \"%h %a %l:LogFormat \"%a %l:" /etc/apache2/conf/httpd.conf
sed -i "s:LogFormat \"%h %l:LogFormat \"%a %l:" /etc/apache2/conf/httpd.conf
fi
fi
else
cd /usr/local/src
/bin/rm -f mod_remoteip.c
#wget --no-check-certificate https://svn.apache.org/repos/asf/httpd/httpd/trunk/modules/metadata/mod_remoteip.c
wget --no-check-certificate $REPO_CDN_URL/apache/mod_remoteip.c
wget --no-check-certificate $REPO_CDN_URL/apache/apxs.sh
chmod +x apxs.sh
./apxs.sh -i -c -n mod_remoteip.so mod_remoteip.c
/bin/rm -f mod_remoteip.c
/bin/rm -f apxs.sh
if [ -f /usr/local/apache/modules/mod_remoteip.so ]; then
if [ ! -f /usr/local/apache/conf/includes/remoteip.conf ]; then
touch /usr/local/apache/conf/includes/remoteip.conf
fi
cat > "/usr/local/apache/conf/includes/remoteip.conf" <<EOF
# mod_remoteip (https://httpd.apache.org/docs/current/mod/mod_remoteip.html)
LoadModule remoteip_module modules/mod_remoteip.so
RemoteIPHeader X-Forwarded-For
RemoteIPInternalProxy $SYSTEM_IPS
EOF
/bin/cp -f /usr/local/apache/conf/httpd.conf /usr/local/apache/conf/httpd.conf.bak
sed -i 's:Include "/usr/local/apache/conf/includes/remoteip.conf"::' /usr/local/apache/conf/httpd.conf
sed -i 's:Include "/usr/local/apache/conf/includes/errordocument.conf":Include "/usr/local/apache/conf/includes/errordocument.conf"\nInclude "/usr/local/apache/conf/includes/remoteip.conf":' /usr/local/apache/conf/httpd.conf
sed -i "s:LogFormat \"%h %a %l:LogFormat \"%a %l:" /usr/local/apache/conf/httpd.conf
sed -i "s:LogFormat \"%h %l:LogFormat \"%a %l:" /usr/local/apache/conf/httpd.conf
fi
fi
echo ""
echo ""
}
function remove_mod_remoteip {
if [ -f /etc/apache2/conf/httpd.conf ]; then
yum -y remove ea-apache24-mod_remoteip
sed -i "s:LogFormat \"%h %a %l:LogFormat \"%h %l:" /etc/apache2/conf/httpd.conf
sed -i "s:LogFormat \"%a %l:LogFormat \"%h %l:" /etc/apache2/conf/httpd.conf
else
if [ -f /usr/local/apache/conf/includes/remoteip.conf ]; then
echo "=== Removing mod_remoteip for Apache ==="
rm -f /usr/local/apache/conf/includes/remoteip.conf
sed -i 's:Include "/usr/local/apache/conf/includes/remoteip.conf"::' /usr/local/apache/conf/httpd.conf
sed -i "s:LogFormat \"%h %a %l:LogFormat \"%h %l:" /usr/local/apache/conf/httpd.conf
sed -i "s:LogFormat \"%a %l:LogFormat \"%h %l:" /usr/local/apache/conf/httpd.conf
fi
fi
echo ""
echo ""
}
function install_mod_rpaf {
echo "=== Installing mod_rpaf (v0.8.4) for Apache ==="
cd /usr/local/src
/bin/rm -f mod_rpaf-0.8.4.zip
wget --no-check-certificate $REPO_CDN_URL/apache/mod_rpaf-0.8.4.zip
unzip -o mod_rpaf-0.8.4.zip
/bin/rm -f mod_rpaf-0.8.4.zip
cd mod_rpaf-0.8.4
chmod +x apxs.sh
./apxs.sh -i -c -n mod_rpaf.so mod_rpaf.c
/bin/rm -rf /usr/local/src/mod_rpaf-0.8.4/
if [ -f /usr/local/apache/modules/mod_rpaf.so ]; then
# Get system IPs
SYSTEM_IPS=$(ip addr show | grep -o "inet [0-9]*\.[0-9]*\.[0-9]*\.[0-9]*" | grep -o "[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*" | sed ':a;N;$!ba;s/\n/ /g');
if [[ ! $(echo $SYSTEM_IPS | grep "127.0.0.1") ]]; then
SYSTEM_IPS="127.0.0.1 $SYSTEM_IPS"
fi
if [ ! -f /usr/local/apache/conf/includes/rpaf.conf ]; then
touch /usr/local/apache/conf/includes/rpaf.conf
fi
cat > "/usr/local/apache/conf/includes/rpaf.conf" <<EOF
# mod_rpaf (https://github.com/gnif/mod_rpaf)
LoadModule rpaf_module modules/mod_rpaf.so
RPAF_Enable On
RPAF_ForbidIfNotProxy Off
RPAF_Header X-Forwarded-For
RPAF_ProxyIPs $SYSTEM_IPS
RPAF_SetHostName On
RPAF_SetHTTPS On
RPAF_SetPort On
EOF
/bin/cp -f /usr/local/apache/conf/httpd.conf /usr/local/apache/conf/httpd.conf.bak
sed -i 's:Include "/usr/local/apache/conf/includes/rpaf.conf"::' /usr/local/apache/conf/httpd.conf
sed -i 's:Include "/usr/local/apache/conf/includes/errordocument.conf":Include "/usr/local/apache/conf/includes/errordocument.conf"\nInclude "/usr/local/apache/conf/includes/rpaf.conf":' /usr/local/apache/conf/httpd.conf
sed -i "s:LogFormat \"%h %a %l:LogFormat \"%a %l:" /usr/local/apache/conf/httpd.conf
sed -i "s:LogFormat \"%h %l:LogFormat \"%a %l:" /usr/local/apache/conf/httpd.conf
echo ""
echo ""
fi
}
function remove_mod_rpaf {
if [ -f /usr/local/apache/conf/includes/rpaf.conf ]; then
echo "=== Removing mod_rpaf (v0.8.4) for Apache ==="
rm -f /usr/local/apache/conf/includes/rpaf.conf
sed -i 's:Include "/usr/local/apache/conf/includes/rpaf.conf"::' /usr/local/apache/conf/httpd.conf
sed -i "s:LogFormat \"%h %a %l:LogFormat \"%h %l:" /usr/local/apache/conf/httpd.conf
sed -i "s:LogFormat \"%a %l:LogFormat \"%h %l:" /usr/local/apache/conf/httpd.conf
echo ""
echo ""
fi
}
function apache_change_port {
echo "=== Switch Apache to ports 8080 & 8443, distill changes & restart Apache ==="
if [ -f /usr/local/cpanel/bin/whmapi1 ]; then
/usr/local/cpanel/bin/whmapi1 set_tweaksetting key=apache_port value=0.0.0.0:8080
/usr/local/cpanel/bin/whmapi1 set_tweaksetting key=apache_ssl_port value=0.0.0.0:8443
else
if grep -Fxq "^apache_" /var/cpanel/cpanel.config
then
sed -i 's/^apache_port=.*/apache_port=0.0.0.0:8080/' /var/cpanel/cpanel.config
sed -i 's/^apache_ssl_port=.*/apache_ssl_port=0.0.0.0:8443/' /var/cpanel/cpanel.config
else
echo "apache_port=0.0.0.0:8080" >> /var/cpanel/cpanel.config
echo "apache_ssl_port=0.0.0.0:8443" >> /var/cpanel/cpanel.config
fi
/usr/local/cpanel/whostmgr/bin/whostmgr2 --updatetweaksettings
fi
echo ""
echo ""
echo "=== Distill changes in Apache's configuration and restart Apache ==="
/usr/local/cpanel/bin/apache_conf_distiller --update
/scripts/rebuildhttpdconf
/scripts/restartsrv_httpd
echo ""
echo ""
}
function apache_revert_port {
echo "=== Switch Apache back to ports 80 & 443 ==="
if [ -f /usr/local/cpanel/bin/whmapi1 ]; then
/usr/local/cpanel/bin/whmapi1 set_tweaksetting key=apache_port value=0.0.0.0:80
/usr/local/cpanel/bin/whmapi1 set_tweaksetting key=apache_ssl_port value=0.0.0.0:443
else
if grep -Fxq "^apache_" /var/cpanel/cpanel.config
then
sed -i 's/^apache_port=.*/apache_port=0.0.0.0:80/' /var/cpanel/cpanel.config
sed -i 's/^apache_ssl_port=.*/apache_ssl_port=0.0.0.0:443/' /var/cpanel/cpanel.config
else
echo "apache_port=0.0.0.0:80" >> /var/cpanel/cpanel.config
echo "apache_ssl_port=0.0.0.0:443" >> /var/cpanel/cpanel.config
fi
/usr/local/cpanel/whostmgr/bin/whostmgr2 --updatetweaksettings
fi
echo ""
echo ""
echo "=== Distill changes in Apache's configuration and restart Apache ==="
/usr/local/cpanel/bin/apache_conf_distiller --update
/scripts/rebuildhttpdconf
/scripts/restartsrv_httpd
echo ""
echo ""
}
function install_nginx {
if [ ! -f /etc/yum.repos.d/nginx.repo ]; then
touch /etc/yum.repos.d/nginx.repo
fi
# Allow switching from mainline to stable release
if [[ ! $1 ]]; then
if grep -iq "mainline" /etc/yum.repos.d/nginx.repo; then
yum -y remove nginx
fi
fi
# Setup Nginx repo
if [[ $1 == 'mainline' ]]; then
echo "=== Install Nginx (mainline) from nginx.org ==="
cat > "/etc/yum.repos.d/nginx.repo" <<EOFM
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/mainline/centos/\$releasever/\$basearch/
gpgcheck=0
enabled=1
EOFM
else
echo "=== Install Nginx (stable) from nginx.org ==="
cat > "/etc/yum.repos.d/nginx.repo" <<EOFS
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/\$releasever/\$basearch/
gpgcheck=0
enabled=1
EOFS
fi
# Install Nginx
yum -y install nginx
# Copy Nginx config files
if [ -f /etc/nginx/custom_rules ]; then
/bin/cp -f $APP_PATH/nginx/custom_rules /etc/nginx/custom_rules.dist
else
/bin/cp -f $APP_PATH/nginx/custom_rules /etc/nginx/
fi
if [ -f /etc/nginx/proxy_params_common ]; then
/bin/cp -f /etc/nginx/proxy_params_common /etc/nginx/proxy_params_common.bak
fi
/bin/cp -f $APP_PATH/nginx/proxy_params_common /etc/nginx/
if [ -f /etc/nginx/proxy_params_dynamic ]; then
/bin/cp -f /etc/nginx/proxy_params_dynamic /etc/nginx/proxy_params_dynamic.bak
fi
/bin/cp -f $APP_PATH/nginx/proxy_params_dynamic /etc/nginx/
if [ -f /etc/nginx/proxy_params_static ]; then
/bin/cp -f /etc/nginx/proxy_params_static /etc/nginx/proxy_params_static.bak
fi
/bin/cp -f $APP_PATH/nginx/proxy_params_static /etc/nginx/
if [ -f /etc/nginx/mime.types ]; then
/bin/cp -f /etc/nginx/mime.types /etc/nginx/mime.types.bak
fi
/bin/cp -f $APP_PATH/nginx/mime.types /etc/nginx/
if [ -f /etc/nginx/nginx.conf ]; then
/bin/cp -f /etc/nginx/nginx.conf /etc/nginx/nginx.conf.bak
fi
/bin/cp -f $APP_PATH/nginx/nginx.conf /etc/nginx/
if [ -f /etc/nginx/conf.d/default.conf ]; then
/bin/cp -f /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf.bak
fi
/bin/rm -f /etc/nginx/conf.d/*.conf
/bin/cp -f $APP_PATH/nginx/conf.d/default.conf /etc/nginx/conf.d/
/bin/cp -f $APP_PATH/nginx/common_https.conf /etc/nginx/
if [ ! -d /etc/nginx/utilities ]; then
mkdir -p /etc/nginx/utilities
fi
/bin/cp -f $APP_PATH/nginx/utilities/https_vhosts.php /etc/nginx/utilities/
/bin/cp -f $APP_PATH/nginx/utilities/https_vhosts.sh /etc/nginx/utilities/
chmod +x /etc/nginx/utilities/*
if [ ! -d /etc/ssl/engintron ]; then
mkdir -p /etc/ssl/engintron
fi
if [ -f /sbin/chkconfig ]; then
/sbin/chkconfig nginx on
else
systemctl enable nginx
fi
if [ -f /usr/lib/systemd/system/nginx.service ]; then
sed -i 's/PrivateTmp=true/PrivateTmp=false/' /usr/lib/systemd/system/nginx.service
systemctl daemon-reload
fi
if [ "$(pstree | grep 'nginx')" ]; then
service nginx stop
fi
# Adjust log rotation to 7 days
if [ -f /etc/logrotate.d/nginx ]; then
sed -i 's:rotate .*:rotate 7:' /etc/logrotate.d/nginx
fi
echo ""
echo ""
}
function remove_nginx {
echo "=== Removing Nginx... ==="
if [ -f /sbin/chkconfig ]; then
/sbin/chkconfig nginx off
else
systemctl disable nginx
fi
service nginx stop
yum -y remove nginx
/bin/rm -rf /etc/nginx/*
/bin/rm -f /etc/yum.repos.d/nginx.repo
/bin/rm -rf /etc/ssl/engintron/*
echo ""
echo ""
}
function install_engintron_ui {
echo "=== Installing Engintron WHM plugin files... ==="
# Cleanup older installations from the obsolete addon_engintron.cgi file
if [ -f $CPANEL_PLG_PATH/addon_engintron.cgi ]; then
/bin/rm -f $CPANEL_PLG_PATH/addon_engintron.cgi
fi
/bin/cp -f $APP_PATH/app/engintron.php $CPANEL_PLG_PATH/
chmod +x $CPANEL_PLG_PATH/engintron.php
echo ""
echo "=== Register Engintron as a cPanel app ==="
/usr/local/cpanel/bin/register_appconfig $APP_PATH/app/engintron.conf
echo ""
echo ""
}
function remove_engintron_ui {
echo "=== Removing Engintron WHM plugin files... ==="
/bin/rm -f $CPANEL_PLG_PATH/engintron.php
echo ""
echo "=== Unregister Engintron as a cPanel app ==="
/usr/local/cpanel/bin/unregister_appconfig engintron
echo ""
echo ""
}
function install_munin_patch {
if [ -f /etc/munin/plugin-conf.d/cpanel.conf ]; then
echo "=== Updating Munin's configuration for Apache ==="
if grep -q "\[apache_status\]" /etc/munin/plugin-conf.d/cpanel.conf
then
echo "Munin configuration already updated, nothing to do here"
else
cat >> "/etc/munin/plugin-conf.d/cpanel.conf" <<EOF
[apache_status]
env.ports 8080
env.label 8080
EOF
fi
ln -s /usr/local/cpanel/3rdparty/share/munin/plugins/nginx_* /etc/munin/plugins/
service munin-node restart
echo ""
echo ""
fi
}
function remove_munin_patch {
if [ -f /etc/munin/plugin-conf.d/cpanel.conf ]; then
echo ""
echo "=== Updating Munin's configuration for Apache ==="
if grep -q "\[apache_status\]" /etc/munin/plugin-conf.d/cpanel.conf
then
sed -i 's:\[apache_status\]::' /etc/munin/plugin-conf.d/cpanel.conf
sed -i 's:env\.ports 8080::' /etc/munin/plugin-conf.d/cpanel.conf
sed -i 's:env\.label 8080::' /etc/munin/plugin-conf.d/cpanel.conf
else
echo "Munin was not found, nothing to do here"
fi
/bin/rm -f /etc/munin/plugins/nginx_*
service munin-node restart
echo ""
echo ""
fi
}
function csf_pignore_add {
if [ -f /etc/csf/csf.pignore ]; then
echo ""
echo "=== Adding Nginx to CSF's process ignore list ==="
if grep -q "exe\:\/usr\/sbin\/nginx" /etc/csf/csf.pignore
then
echo "Nginx seems to be already configured with CSF..."
else
echo "exe:/usr/sbin/nginx" >> /etc/csf/csf.pignore
csf -r
service lfd restart
fi
echo ""
echo ""
fi
}
function csf_pignore_remove {
if [ -f /etc/csf/csf.pignore ]; then
echo ""
echo "=== Removing Nginx from CSF's process ignore list ==="
if grep -q "exe\:\/usr\/sbin\/nginx" /etc/csf/csf.pignore
then
sed -i 's:^exe\:\/usr\/sbin\/nginx::' /etc/csf/csf.pignore
csf -r
service lfd restart
fi
echo ""
echo ""
fi
}
function cron_for_https_vhosts_add {
if [ -f /etc/crontab ]; then
if grep -q "https_vhosts\.sh" /etc/crontab
then
echo "=== Skip adding cron job to generate Nginx's HTTPS vhosts ==="
else
echo ""
echo "=== Adding cron job to generate Nginx's HTTPS vhosts ==="
cat >> "/etc/crontab" <<EOF
* * * * * root /etc/nginx/utilities/https_vhosts.sh >> /dev/null 2>&1
EOF
fi
echo ""
echo ""
fi
}
function cron_for_https_vhosts_remove {
if [ -f /etc/crontab ]; then
echo ""
echo "=== Removing cron job used for generating Nginx's HTTPS vhosts ==="
sed -i 's:* * * * * root /etc/nginx/utilities/https_vhosts.sh >> /dev/null 2>&1::' /etc/crontab
echo ""
echo ""
fi
}
function chkserv_nginx_on {
if [ -f /etc/chkserv.d/httpd ]; then
echo ""
echo "=== Enable TailWatch chkservd driver for Nginx ==="
sed -i 's:service\[httpd\]=80,:service[httpd]=8080,:' /etc/chkserv.d/httpd
echo "nginx:1" >> /etc/chkserv.d/chkservd.conf
if [ ! -f /etc/chkserv.d/nginx ]; then
touch /etc/chkserv.d/nginx
fi
echo "service[nginx]=80,GET / HTTP/1.0,HTTP/1..,killall -TERM nginx;sleep 2;killall -9 nginx;service nginx stop;service nginx start" > /etc/chkserv.d/nginx
/scripts/restartsrv_chkservd
echo ""
echo ""
fi
}
function chkserv_nginx_off {
if [ -f /etc/chkserv.d/httpd ]; then
echo ""
echo "=== Disable TailWatch chkservd driver for Nginx ==="
sed -i 's:service\[httpd\]=8080,:service[httpd]=80,:' /etc/chkserv.d/httpd
sed -i 's:^nginx\:1::' /etc/chkserv.d/chkservd.conf
if [ -f /etc/chkserv.d/nginx ]; then
/bin/rm -f /etc/chkserv.d/nginx
fi
/scripts/restartsrv_chkservd
echo ""
echo ""
fi
}
############################# HELPER FUCTIONS [end] #############################
### Define actions ###
case $1 in
install)
clear
if [ ! -f /engintron.sh ]; then
echo ""
echo ""
echo "***********************************************"
echo ""
echo " ENGINTRON NOTICE:"
echo " You must place & execute engintron.sh"
echo " from the root directory (/) of your server!"
echo ""
echo " --- Exiting ---"
echo ""
echo "***********************************************"
echo ""
echo ""
exit 0
fi
echo "**************************************"
echo "* Installing Engintron *"
echo "**************************************"
echo ""
echo ""
chmod +x /engintron.sh
if [[ $2 == 'local' ]]; then
echo -e "\033[36m=== Performing local installation from $APP_PATH... ===\033[0m"
cd /
else
# Set Engintron src file path
if [[ ! -d $APP_PATH ]]; then
mkdir -p $APP_PATH
fi
# Get the files
cd $APP_PATH
wget --no-check-certificate -O engintron.zip https://github.com/engintron/engintron/archive/master.zip
unzip engintron.zip
/bin/cp -rf $APP_PATH/engintron-master/* $APP_PATH/
/bin/rm -rvf $APP_PATH/engintron-master/*
/bin/rm -f $APP_PATH/engintron.zip
cd /
fi
echo ""
echo ""
install_basics
install_nginx $2
if [[ $GET_HTTPD_VERSION =~ "Apache/2.2." ]]; then
install_mod_rpaf
else
install_mod_remoteip
fi
apache_change_port
install_munin_patch
install_engintron_ui
if [ ! -f /etc/ssl/certs/dhparam.pem ]; then
echo ""
echo "=== Generating DHE ciphersuites (2048 bits)... ==="
openssl dhparam -out /etc/ssl/certs/dhparam.pem 2048
fi
echo ""
echo "=== Restarting Apache & Nginx... ==="
/scripts/restartsrv_httpd
fuser -k 80/tcp
fuser -k 8080/tcp
fuser -k 443/tcp
fuser -k 8443/tcp
service nginx start
csf_pignore_add
cron_for_https_vhosts_add
chkserv_nginx_on
service nginx restart
if [ ! -f $APP_PATH/state.conf ]; then
touch $APP_PATH/state.conf
fi
echo "on" > $APP_PATH/state.conf
if [ -f $APP_PATH/engintron.sh ]; then
chmod +x $APP_PATH/engintron.sh
$APP_PATH/engintron.sh purgecache
fi
/scripts/restartsrv_httpd
sleep 5
service httpd restart
service nginx restart
echo ""
echo "**************************************"
echo "* Installation Complete *"
echo "**************************************"
echo ""
echo ""
;;
remove)
clear
echo "**************************************"
echo "* Removing Engintron *"
echo "**************************************"
if [[ $GET_HTTPD_VERSION =~ "Apache/2.2." ]]; then
remove_mod_rpaf
else
remove_mod_remoteip
fi
apache_revert_port
remove_nginx
remove_munin_patch
remove_engintron_ui
csf_pignore_remove
cron_for_https_vhosts_remove
chkserv_nginx_off
echo ""
echo "=== Removing Engintron files... ==="
/bin/rm -rvf $APP_PATH
echo ""
echo "=== Restarting Apache... ==="
/scripts/restartsrv_httpd
echo ""
echo "**************************************"
echo "* Removal Complete *"
echo "**************************************"
echo ""
echo ""
;;
enable)
clear
echo "**************************************"
echo "* Enabling Engintron *"
echo "**************************************"
if [ ! -f $APP_PATH/state.conf ]; then
touch $APP_PATH/state.conf
fi
echo "on" > $APP_PATH/state.conf
install_munin_patch
service nginx stop
sed -i 's:listen 8080 default_server:listen 80 default_server:' /etc/nginx/conf.d/default.conf
sed -i 's:listen [\:\:]\:8080 default_server:listen [\:\:]\:80 default_server:' /etc/nginx/conf.d/default.conf
sed -i 's:deny all; #:# deny all; #:' /etc/nginx/conf.d/default.conf
sed -i 's:\:80; # Apache Status Page:\:8080; # Apache Status Page:' /etc/nginx/conf.d/default.conf
if [ -f /etc/nginx/conf.d/default_https.conf ]; then
sed -i 's:listen 8443 ssl:listen 443 ssl:g' /etc/nginx/conf.d/default_https.conf
sed -i 's:listen [\:\:]\:8443 ssl:listen [\:\:]\:443 ssl:g' /etc/nginx/conf.d/default_https.conf
sed -i 's:deny all; #:# deny all; #:g' /etc/nginx/conf.d/default_https.conf
fi
sed -i 's:deny all; #:# deny all; #:g' /etc/nginx/utilities/https_vhosts.php
sed -i 's:'HTTPD_HTTPS_PORT', '443':'HTTPD_HTTPS_PORT', '8443':' /etc/nginx/utilities/https_vhosts.php
sed -i 's:'NGINX_HTTPS_PORT', '8443':'NGINX_HTTPS_PORT', '443':' /etc/nginx/utilities/https_vhosts.php
sed -i 's:PROXY_TO_PORT 443:PROXY_TO_PORT 8443:' /etc/nginx/common_https.conf
sed -i 's:PROXY_DOMAIN_OR_IP\:80:PROXY_DOMAIN_OR_IP\:8080:' /etc/nginx/proxy_params_common
apache_change_port
service nginx start
/scripts/restartsrv_httpd
service nginx restart
chkserv_nginx_on
echo ""
echo "**************************************"
echo "* Engintron Enabled *"
echo "**************************************"
echo ""
echo ""
;;
disable)
clear
echo "**************************************"
echo "* Disabling Engintron *"
echo "**************************************"
if [ ! -f $APP_PATH/state.conf ]; then
touch $APP_PATH/state.conf
fi
echo "off" > $APP_PATH/state.conf
remove_munin_patch
service nginx stop
sed -i 's:listen 80 default_server:listen 8080 default_server:' /etc/nginx/conf.d/default.conf
sed -i 's:listen [\:\:]\:80 default_server:listen [\:\:]\:8080 default_server:' /etc/nginx/conf.d/default.conf
sed -i 's:# deny all; #:deny all; #:' /etc/nginx/conf.d/default.conf
sed -i 's:\:8080; # Apache Status Page:\:80; # Apache Status Page:' /etc/nginx/conf.d/default.conf
if [ -f /etc/nginx/conf.d/default_https.conf ]; then
sed -i 's:listen 443 ssl:listen 8443 ssl:g' /etc/nginx/conf.d/default_https.conf
sed -i 's:listen [\:\:]\:443 ssl:listen [\:\:]\:8443 ssl:g' /etc/nginx/conf.d/default_https.conf
sed -i 's:# deny all; #:deny all; #:g' /etc/nginx/conf.d/default_https.conf
fi
sed -i 's:# deny all; #:deny all; #:g' /etc/nginx/utilities/https_vhosts.php
sed -i 's:'HTTPD_HTTPS_PORT', '8443':'HTTPD_HTTPS_PORT', '443':' /etc/nginx/utilities/https_vhosts.php
sed -i 's:'NGINX_HTTPS_PORT', '443':'NGINX_HTTPS_PORT', '8443':' /etc/nginx/utilities/https_vhosts.php
sed -i 's:PROXY_TO_PORT 8443:PROXY_TO_PORT 443:' /etc/nginx/common_https.conf
sed -i 's:PROXY_DOMAIN_OR_IP\:8080:PROXY_DOMAIN_OR_IP\:80:' /etc/nginx/proxy_params_common
apache_revert_port
service nginx start
/scripts/restartsrv_httpd
service nginx restart
chkserv_nginx_off
echo ""
echo "**************************************"
echo "* Engintron Disabled *"
echo "**************************************"
echo ""
echo ""
;;
resall)
echo "========================================="
echo "=== Restarting All Important Services ==="
echo "========================================="
echo ""
#if [ -f "/usr/local/cpanel/cpanel" ]; then
# service cpanel restart
# echo ""
#fi
if [ "$(pstree | grep 'crond')" ]; then
service crond restart
echo ""
fi
if [[ -f /etc/csf/csf.conf && "$(cat /etc/csf/csf.conf | grep 'TESTING = \"0\"')" ]]; then
csf -r
echo ""
fi
if [ "$(pstree | grep 'lfd')" ]; then
service lfd restart
echo ""
fi
if [ "$(pstree | grep 'munin-node')" ]; then
service munin-node restart
echo ""
fi
if [ "$(pstree | grep 'mysql')" ]; then
/scripts/restartsrv_mysql
echo ""
fi
if [ "$(pstree | grep 'httpd')" ]; then
echo "Restarting Apache..."
/scripts/restartsrv_httpd
echo ""
fi
if [ "$(pstree | grep 'nginx')" ]; then
echo "Restarting Nginx..."
service nginx restart
echo ""
fi
echo ""
;;
res)
echo "====================================="
echo "=== Restarting All Basic Services ==="
echo "====================================="
echo ""
if [ "$(pstree | grep 'httpd')" ]; then
echo "Restarting Apache..."
/scripts/restartsrv_httpd
echo ""
fi
if [ "$(pstree | grep 'nginx')" ]; then
echo "Restarting Nginx..."
service nginx restart
echo ""
fi
echo ""
;;
purgecache)
NOW=$(date +'%Y.%m.%d at %H:%M:%S')
echo "==================================================================="
echo "=== Clean Nginx cache & temp folders and restart Apache & Nginx ==="
echo "==================================================================="
echo ""
echo "--- Process started at $NOW ---"
echo ""
find /tmp/engintron_dynamic/ -type f | xargs rm -rvf
find /tmp/engintron_static/ -type f | xargs rm -rvf
find /tmp/engintron_temp/ -type f | xargs rm -rvf
if [ "$(pstree | grep 'httpd')" ]; then
echo "Restarting Apache..."
/scripts/restartsrv_httpd
echo ""
fi
if [ "$(pstree | grep 'nginx')" ]; then
echo "Restarting Nginx..."
service nginx restart
echo ""
fi
echo ""
;;
purgelogs)
echo "================================================================"
echo "=== Clean Nginx access/error logs and restart Apache & Nginx ==="
echo "================================================================"
echo ""
if [ -f /var/log/nginx/access.log ]; then
echo "" > /var/log/nginx/access.log
fi
if [ -f /var/log/nginx/error.log ]; then
echo "" > /var/log/nginx/error.log
fi
if [ "$(pstree | grep 'httpd')" ]; then
echo "Restarting Apache..."
/scripts/restartsrv_httpd
echo ""
fi
if [ "$(pstree | grep 'nginx')" ]; then
echo "Restarting Nginx..."
service nginx restart
echo ""
fi
echo ""
;;
fixaccessperms)
echo "===================================================="
echo "=== Fix user file & directory access permissions ==="
echo "===================================================="
echo ""
echo "Changing directory permissions to 755..."
find /home/*/public_html/ -type d -exec chmod 755 {} \;
echo ""
echo "Changing file permissions to 644..."
find /home/*/public_html/ -type f -exec chmod 644 {} \;
echo ""
echo "Operation completed."
echo ""
echo ""
;;
fixownerperms)
echo "==================================================="
echo "=== Fix user file & directory owner permissions ==="
echo "==================================================="
echo ""
cd /home
for user in $( ls -d * )
do
if [ -d /home/$user/public_html ]; then
echo "=== Fixing permissions for user $user ==="
chown -R $user:$user /home/$user/public_html
chown $user:nobody /home/$user/public_html
fi
done
echo "Operation completed."
echo ""
echo ""
;;
restoreipfwd)
echo "======================================="
echo "=== Restore IP Forwarding in Apache ==="
echo "======================================="
echo ""
if [[ $GET_HTTPD_VERSION =~ "Apache/2.2." ]]; then
install_mod_rpaf
else
install_mod_remoteip
fi
/scripts/restartsrv_httpd
service nginx reload
echo "Operation completed."
echo ""
echo ""
;;
cleanup)
echo "========================================================================="
echo "=== Cleanup Mac or Windows specific metadata & Apache error_log files ==="
echo "========================================================================="
echo ""
find /home/*/public_html/ -iname 'error_log' | xargs rm -rvf
find /home/*/public_html/ -iname '.DS_Store' | xargs rm -rvf
find /home/*/public_html/ -iname 'thumbs.db' | xargs rm -rvf
find /home/*/public_html/ -iname '__MACOSX' | xargs rm -rvf
find /home/*/public_html/ -iname '._*' | xargs rm -rvf
echo ""
echo "Operation completed."
echo ""
echo ""
;;
info)
echo "=================="
echo "=== OS Version ==="
echo "=================="
echo ""
cat /etc/redhat-release
echo ""
echo "cPanel version: $GET_CPANEL_VERSION"
echo ""
echo ""
echo "=================="
echo "=== Disk Usage ==="
echo "=================="
echo ""
df -hT