forked from engintron/engintron
-
Notifications
You must be signed in to change notification settings - Fork 0
/
engintron.sh
915 lines (755 loc) · 24.2 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
#!/bin/bash
# /**
# * @version 1.7.2
# * @package Engintron for cPanel/WHM
# * @author Fotis Evangelou
# * @url https://engintron.com
# * @copyright Copyright (c) 2010 - 2016 Nuevvo Webware P.C. All rights reserved.
# * @license GNU/GPL license: http://www.gnu.org/copyleft/gpl.html
# */
# Constants
APP_PATH="/usr/local/src/engintron"
APP_VERSION="1.7.2"
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_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
#systemips=$(ip addr show | grep 'inet ' | grep ' brd ' | cut -d/ -f1 | cut -c10- | tr '\n' ' ');
systemips=$(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 [ ! -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
# RPAF
LoadModule rpaf_module modules/mod_rpaf.so
RPAF_Enable On
RPAF_ProxyIPs 127.0.0.1 $systemips
RPAF_SetHostName On
RPAF_SetHTTPS On
RPAF_SetPort On
RPAF_ForbidIfNotProxy Off
RPAF_Header X-Real-IP
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 %l:LogFormat \"%h %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
echo ""
echo ""
fi
}
function install_mod_remoteip {
# Get system IPs
#systemips=$(ip addr show | grep 'inet ' | grep ' brd ' | cut -d/ -f1 | cut -c10- | tr '\n' ' ');
systemips=$(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');
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
# Enable mod_remoteip
LoadModule remoteip_module modules/mod_remoteip.so
RemoteIPInternalProxy 127.0.0.1 $systemips
RemoteIPHeader X-Real-IP
EOF
sed -i "s:LogFormat \"%h %l:LogFormat \"%h %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
# RemoteIP
LoadModule remoteip_module modules/mod_remoteip.so
RemoteIPInternalProxy 127.0.0.1 $systemips
RemoteIPHeader X-Real-IP
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 %l:LogFormat \"%h %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
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
fi
fi
echo ""
echo ""
}
function apache_change_port {
echo "=== Switch Apache to port 8080, 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
else
if grep -Fxq "apache_port=" /var/cpanel/cpanel.config
then
sed -i 's/^apache_port=.*/apache_port=0.0.0.0:8080/' /var/cpanel/cpanel.config
/usr/local/cpanel/whostmgr/bin/whostmgr2 --updatetweaksettings
else
echo "apache_port=0.0.0.0:8080" >> /var/cpanel/cpanel.config
fi
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 port 80 ==="
if [ -f /usr/local/cpanel/bin/whmapi1 ]; then
/usr/local/cpanel/bin/whmapi1 set_tweaksetting key=apache_port value=0.0.0.0:80
else
if grep -Fxq "apache_port=" /var/cpanel/cpanel.config
then
sed -i 's/^apache_port=.*/apache_port=0.0.0.0:80/' /var/cpanel/cpanel.config
/usr/local/cpanel/whostmgr/bin/whostmgr2 --updatetweaksettings
else
echo "apache_port=0.0.0.0:80" >> /var/cpanel/cpanel.config
fi
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/
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
echo ""
echo ""
}
function install_engintron_ui {
echo "=== Installing Engintron WHM plugin files... ==="
/bin/cp -f $APP_PATH/app/addon_engintron.cgi $CPANEL_PLG_PATH/
/bin/cp -f $APP_PATH/app/engintron.php $CPANEL_PLG_PATH/
chmod +x $CPANEL_PLG_PATH/addon_engintron.cgi
chmod +x $CPANEL_PLG_PATH/engintron.php
echo ""
echo "=== Fix ACL requirements in newer cPanel releases ==="
if [ -f /usr/local/cpanel/bin/whmapi1 ]; then
/usr/local/cpanel/bin/whmapi1 set_tweaksetting key=permit_unregistered_apps_as_root value=1
else
if grep -Fxq "permit_unregistered_apps_as_root=" /var/cpanel/cpanel.config
then
sed -i 's/^permit_unregistered_apps_as_root=.*/permit_unregistered_apps_as_root=1/' /var/cpanel/cpanel.config
else
echo "permit_unregistered_apps_as_root=1" >> /var/cpanel/cpanel.config
fi
/usr/local/cpanel/whostmgr/bin/whostmgr2 --updatetweaksettings
fi
/usr/local/cpanel/etc/init/startcpsrvd
echo ""
echo ""
}
function remove_engintron_ui {
echo "=== Removing Engintron WHM plugin files... ==="
/bin/rm -f $CPANEL_PLG_PATH/addon_engintron.*
/bin/rm -f $CPANEL_PLG_PATH/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
}
############################# 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 "**************************************"
chmod +x /engintron.sh
cd /
# 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 /
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
echo ""
echo "=== Restarting Apache & Nginx... ==="
service httpd restart
fuser -k 80/tcp
service nginx start
csf_pignore_add
if [ ! -f $APP_PATH/state.conf ]; then
touch $APP_PATH/state.conf
fi
echo "on" > $APP_PATH/state.conf
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
echo ""
echo "=== Removing Engintron files... ==="
/bin/rm -rvf $APP_PATH
echo ""
echo "=== Restarting Apache... ==="
service httpd restart
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: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
sed -i 's:PROXY_DOMAIN_OR_IP\:80:PROXY_DOMAIN_OR_IP\:8080:' /etc/nginx/proxy_params_common
apache_change_port
service nginx start
service httpd restart
service nginx restart
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:# 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
sed -i 's:PROXY_DOMAIN_OR_IP\:8080:PROXY_DOMAIN_OR_IP\:80:' /etc/nginx/proxy_params_common
apache_revert_port
service nginx start
service httpd restart
service nginx restart
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..."
service httpd restart
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..."
service httpd restart
echo ""
fi
if [ "$(pstree | grep 'nginx')" ]; then
echo "Restarting Nginx..."
service nginx restart
echo ""
fi
echo ""
;;
purgecache)
echo "==================================================================="
echo "=== Clean Nginx cache & temp folders and restart Apache & Nginx ==="
echo "==================================================================="
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 "Apache restarting..."
service httpd restart
echo ""
fi
if [ "$(pstree | grep 'nginx')" ]; then
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 "Apache restarting..."
service httpd restart
echo ""
fi
if [ "$(pstree | grep 'nginx')" ]; then
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/*
fi
done
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
echo ""
echo ""
echo "=============="
echo "=== Uptime ==="
echo "=============="
echo ""
uptime
echo ""
echo ""
echo "==================="
echo "=== System Date ==="
echo "==================="
echo ""
date
echo ""
echo ""
echo "======================="
echo "=== Users Logged In ==="
echo "======================="
echo ""
who
echo ""
echo ""
;;
80)
echo "=== Connections on port 80 sorted by connection count & IP ==="
echo ""
netstat -anp | grep :80 | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -n
echo ""
echo ""
echo "=== Concurrent connections on port 80 ==="
echo ""
netstat -an | grep :80 | wc -l
echo ""
echo ""
;;
-h|--help|*)
echo " _______ _____________ ____________ ____ _ __"
echo " / ____/ | / / ____/ _/ | / /_ __/ __ \/ __ \/ | / /"
echo " / __/ / |/ / / __ / // |/ / / / / /_/ / / / / |/ / "
echo " / /___/ /| / /_/ // // /| / / / / _, _/ /_/ / /| / "
echo "/_____/_/ |_/\____/___/_/ |_/ /_/ /_/ |_|\____/_/ |_/ "
echo " "
echo " https://engintron.com "
cat <<EOF
Engintron for cPanel/WHM is the easiest way to integrate Nginx on your cPanel/WHM server.
Usage: /engintron.sh [command] [flag]
Main commands:
install Install, re-install or update Engintron (enables Nginx by default).
Add optional flag "mainline" to install Nginx mainline release.
remove Remove Engintron completely.
enable Set Nginx to port 80 & Apache to port 8080
disable Set Nginx to port 8080 & switch Apache to port 80
purgecache Purge Nginx's "cache" & "temp" folders,
then restart both Apache & Nginx
purgelogs Purge Nginx's access & error log files
Utility commands:
res Restart web servers only (Apache & Nginx)
resall Restart Cron, CSF & LFD (if installed), Munin (if installed),
MySQL, Apache, Nginx
80 Show active connections on port 80 sorted by connection count & IP,
including total concurrent connections count
fixaccessperms Change file & directory access permissions to 644 & 755 respectively
in all user /public_html directories
fixownerperms Fix owner permissions in all user /public_html directories
cleanup Cleanup Mac or Windows specific metadata & Apache error_log files
in all user /public_html directories
info Show basic system info
~~ Enjoy Engintron! ~~
EOF
;;
esac
# END