-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdaShield
More file actions
589 lines (501 loc) · 27.2 KB
/
daShield
File metadata and controls
589 lines (501 loc) · 27.2 KB
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
#!/bin/bash
echo -e " \n\n"
echo " ____ _ ____ "
echo " / ___| _| |__ ___ _ __ / ___|_ __ "
echo "| | | | | | '_ \ / _ \ '__| | _\ \/ / "
echo "| |__| |_| | |_) | __/ | | |_| |> < "
echo " \____\__, |_.__/ \___|_| \____/_/\_\\"
echo " |___/ "
echo " Directadmin Shield - v1.0 "
echo " https://github.com/CyberGx/ "
FORE_RED_COLOR='\033[1;31m'
DEF_COLOR='\033[0m' # No Color
BACK_GREEN_COLOR='\033[42m'
FORE_WHITE_COLOR='\033[0;37m'
FORE_GREEN_COLOR='\033[1;32m'
directadmin_config_path=/usr/local/directadmin/conf/directadmin.conf
directadmin_options_path=/usr/local/directadmin/custombuild/options.conf
php_ini_path=$(/usr/local/bin/php --ini | sed -n "s/^Loaded Configuration File\s*:\s*\(\S*\).*$/\1/p")
ssh_config_path=/etc/ssh/sshd_config
mysql_config_path=/etc/my.cnf
csf_config_path=/etc/csf/csf.conf
webserver_config_path=/etc/httpd/conf/httpd.conf
webserver_mod_security_path=/etc/httpd/conf/extra/httpd-modsecurity.conf
ftp_config_path=/etc/proftpd.conf
dns_config_path=/etc/named.conf
mail_config_path=/etc/exim.conf
imap_config_path=/etc/exim.conf
pop3_config_path=/etc/exim.conf
# Functions
config_editor(){
sed -i 's/\(^'"$1"'\s*=\s*\).*/\1'"$2"'/' $3
}
set_directadmin_option(){
config_editor $1 $2 $directadmin_options_path
}
is_string_exist (){
grep -Fxq $1 $2
}
# $1:String, $2:Filepath
get_config_variable (){
sed -n "s/^$1\s*=\s*\(\S*\).*$/\1/p" $2
}
get_config_variable_space_based (){
sed -n "s/^$1\s* \(\S*\).*$/\1/p" $2
}
# $1:Variable, $2:Recomanded String, $3:Advisor
recommander(){
if [[ $1 == $2 ]]
then
echo $1
else
echo -e "${FORE_RED_COLOR}$1${DEF_COLOR}"
[ ! -z "$3" ] && echo -e " ${FORE_RED_COLOR}- " $3 "${DEF_COLOR}"
fi
}
recommanderReverse(){
if [[ $1 != $2 ]]
then
echo $1
else
echo -e "${FORE_RED_COLOR}$1${DEF_COLOR}"
[ ! -z "$3" ] && echo -e " ${FORE_RED_COLOR}- " $3 "${DEF_COLOR}"
fi
}
recommanderYesOrNo(){
if [ $1 == $2 ]
then
echo "Yes"
else
echo -e "${FORE_RED_COLOR}No${DEF_COLOR}"
[ ! -z "$3" ] && echo -e " ${FORE_RED_COLOR}- " $3 "${DEF_COLOR}"
fi
}
recommanderLower(){
NUMBER=$(echo "$1" | sed 's/[^0-9]*//g')
if [ "$NUMBER" -le "$2" ]
then
echo "Yes"
else
echo -e "${FORE_RED_COLOR}No${DEF_COLOR}"
[ ! -z "$3" ] && echo -e " ${FORE_RED_COLOR}- " $3 "${DEF_COLOR}"
fi
}
serviceStatusCheck(){
service_total_process=$(ps -ef | grep -v grep | grep $1 | wc -l)
if [ "$service_total_process" -gt "0" ]
then
echo -e "${FORE_GREEN_COLOR}⦿ Up${DEF_COLOR}"
else
echo -e "${FORE_RED_COLOR}⦾ Down${DEF_COLOR}"
fi
}
emptyMask(){
if [ ! -z "$1" ]
then
echo $1
else
echo $2
fi
}
qouteRemover(){
echo $(sed -e 's/^"//' -e 's/"$//' <<< $1)
}
sshStatus(){
echo -e "\n# SSH ($(serviceStatusCheck "sshd"))\n"
ssh_port=$(get_config_variable_space_based "Port" $ssh_config_path)
ssh_permit_root_login=$(get_config_variable_space_based "PermitRootLogin" $ssh_config_path)
ssh_protocol=$(get_config_variable_space_based "Protocol" $ssh_config_path)
ssh_password_authentication=$(get_config_variable_space_based "PasswordAuthentication" $ssh_config_path)
ssh_banner=$(get_config_variable_space_based "Banner" $ssh_config_path)
ssh_use_dns=$(get_config_variable_space_based "UseDNS" $ssh_config_path)
ssh_client_alive_interval=$(get_config_variable_space_based "ClientAliveInterval" $ssh_config_path)
ssh_client_count_max=$(get_config_variable_space_based "ClientAliveCountMax" $ssh_config_path)
echo " * SSH config path :" $ssh_config_path
echo " - Protocol :" $(recommander $(emptyMask $ssh_protocol "2") "2" "Set protocol to just 2.")
echo " - Port :" $(recommanderReverse $(emptyMask $ssh_port "22") "22" "Change default ssh port.")
echo " - PermitRootLogin :" $(recommander $(emptyMask $ssh_permit_root_login "yes") "no" "Disable login with username root.")
echo " - Use DNS :" $(recommander $(emptyMask $ssh_use_dns "yes") "no" "set to no becuse lfd will be unable to track SSHD login failures")
echo " - PasswordAuthentication :" $(recommander $(emptyMask $ssh_password_authentication "yes") "no" "Disable PasswordAuthentication and force to login with key.")
echo " - Banner :" $(recommanderReverse $(emptyMask $ssh_banner "N/A") "N/A" "Set banner to prevent attacker.")
echo " - ClientAliveInterval :" $(recommanderReverse $(emptyMask $ssh_client_alive_interval "N/A") "N/A" "Set it to 300 for disconnect after 5min.")
echo " - ClientAliveCountMax :" $(recommander $(emptyMask $ssh_client_count_max "N/A") "0" "Recomanded value is 0.")
}
directadminStatus(){
echo -e "\n# Directadmin ($(serviceStatusCheck "directadmin"))\n"
echo -e " * Service Information"
echo " - Total users :" $(ls -1 /usr/local/directadmin/data/users | grep -v admin | wc -l)
directadmin_config_port=$(get_config_variable "port" $directadmin_config_path)
directadmin_config_servername=$(get_config_variable "servername" $directadmin_config_path)
directadmin_config_ns1=$(get_config_variable "ns1" $directadmin_config_path)
directadmin_config_ns2=$(get_config_variable "ns2" $directadmin_config_path)
directadmin_config_ssl=$(get_config_variable "SSL" $directadmin_config_path)
directadmin_config_carootcert=$(get_config_variable "carootcert" $directadmin_config_path)
directadmin_config_letsencrypt=$(get_config_variable "letsencrypt" $directadmin_config_path)
directadmin_config_force_hostname=$(get_config_variable "force_hostname" $directadmin_config_path)
directadmin_config_ssl_redirect_host=$(get_config_variable "ssl_redirect_host" $directadmin_config_path)
echo -e "\n"
echo -e " * Directadmin Config path :" $directadmin_config_path
echo " - Directadmin Port :" $(recommanderReverse $directadmin_config_port "2222" "Change default Directadmin port.")
echo " - Directadmin Server Name :" $directadmin_config_servername
echo " - Directadmin Nameservers :" $directadmin_config_ns1"," $directadmin_config_ns2
echo " - Directadmin SSL :" $(recommanderYesOrNo $directadmin_config_ssl "1" "its better to enable SSL by set SSL=1")
echo " - Directadmin CA Root Cert :" $(recommanderReverse $(emptyMask $directadmin_config_carootcert "N/A") "N/A" "if ssl enabled you must set it.")
echo " - Is letsencrypt enable :" $(recommanderYesOrNo $(emptyMask $directadmin_config_letsencrypt "0") "1" "its better to enable letsencrypt by set letsencrypt=1")
echo " - Directadmin Force Hostname :" $(recommanderReverse $(emptyMask $directadmin_config_force_hostname "N/A") "N/A" "its better to set force_hostname=your.hostname.com")
echo " - Directadmin SSL Redirect Host :" $(recommanderReverse $(emptyMask $directadmin_config_ssl_redirect_host "N/A") "N/A" "its better to set ssl_redirect_host=your.hostname.com")
# Directadmin Options
directadmin_system_email=$(get_config_variable "email" $directadmin_options_path)
directadmin_autoupdate=$(get_config_variable "da_autoupdate" $directadmin_options_path)
directadmin_clean_old_webapps=$(get_config_variable "clean_old_webapps" $directadmin_options_path)
directadmin_webapps_updates=$(get_config_variable "webapps_updates" $directadmin_options_path)
directadmin_updates=$(get_config_variable "updates" $directadmin_options_path)
directadmin_php1_release=$(get_config_variable "php1_release" $directadmin_options_path)
directadmin_php2_release=$(get_config_variable "php2_release" $directadmin_options_path)
directadmin_php1_mode=$(get_config_variable "php1_mode" $directadmin_options_path)
directadmin_php2_mode=$(get_config_variable "php2_mode" $directadmin_options_path)
echo -e "\n"
echo " * Directadmin Options path :" $directadmin_options_path
echo " - Directadmin system email :" $directadmin_system_email
echo " - Directadmin automatic update :" $(recommander $directadmin_autoupdate "yes")
echo " - Clean old webapps :" $(recommander $directadmin_clean_old_webapps "yes")
echo " - Webapps updates :" $(recommander $directadmin_webapps_updates "yes")
echo " - Updates :" $(recommander $directadmin_updates "no" "its better to update manualy")
echo " - PHP1 Release :" $directadmin_php1_release
echo " - PHP1 Mode :" $directadmin_php1_mode
echo " - PHP2 Release :" $directadmin_php2_release
echo " - PHP2 Mode :" $directadmin_php2_mode
}
mysqlStatus(){
echo -e "\n# MYSQL ($(serviceStatusCheck "mysqld"))\n"
mysql_bind_address=$(get_config_variable "bind-address" $mysql_config_path)
mysql_local_infile=$(get_config_variable "local-infile" $mysql_config_path)
echo " * Mysql config path :" $mysql_config_path
echo " - Is mysql listen only on localhost :" $(recommanderYesOrNo $mysql_bind_address "127.0.0.1" "it better to disable remote access")
echo " - Is local-infile set to 0 :" $(recommanderYesOrNo $mysql_local_infile "0" "disable LOAD DATA LOCAL commands by set local-infile=0")
}
webserverStatus(){
echo -e "\n# Webserver ( Apache )\n"
echo " * Apache config path :" $webserver_config_path
echo " * mod_security config path :" $webserver_mod_security_path
}
phpStatus(){
echo -e "\n# PHP\n"
php_disable_functions=$(get_config_variable "disable_functions" $php_ini_path)
php_expose=$(get_config_variable "expose_php" $php_ini_path)
php_display_errors=$(get_config_variable "display_errors" $php_ini_path)
php_log_errors=$(get_config_variable "log_errors" $php_ini_path)
php_allow_url_include=$(get_config_variable "allow_url_include" $php_ini_path)
php_allow_url_fopen=$(get_config_variable "allow_url_fopen" $php_ini_path)
php_post_max_size=$(get_config_variable "post_max_size" $php_ini_path)
php_max_execution_time=$(get_config_variable "max_execution_time" $php_ini_path)
php_max_input_time=$(get_config_variable "max_input_time" $php_ini_path)
php_memory_limit=$(get_config_variable "memory_limit" $php_ini_path)
echo " * PHP.ini path :" $php_ini_path
echo " - PHP Version :" $(php -v | sed 's/(.*//' | head -1)
echo " - is Expose PHP OFF :" $(recommanderYesOrNo $php_expose "Off" "To restrict PHP information leakage set expose_php=Off")
echo " - is Display Errors OFF :" $(recommanderYesOrNo $php_display_errors "Off" "Set display_errors=Off, Do not expose PHP error messages to all site visitors.")
echo " - is Logging Enable :" $(recommanderYesOrNo $php_log_errors "On" "To enable logging system set log_errors=Off")
echo " - is allow_url_include Disable :" $(recommanderYesOrNo $php_allow_url_include "Off" "To prevent Remote Code Execution set allow_url_include=Off")
echo " - is allow_url_fopen Disable :" $(recommanderYesOrNo $php_allow_url_fopen "Off" "To prevent Remote Code Execution set allow_url_fopen=Off")
echo " - is post_max_size lower than 64M :" $(recommanderLower $php_post_max_size "64" "To prevent attacker to send oversized POST requests to eat your system resources, set post_max_size<64M")
echo " - is max_execution_time lower than 30 :" $(recommanderLower $php_max_execution_time "30" "To prevent attacker to DOS and eat your system resources, set php_max_execution_time<30")
echo " - is max_input_time lower than 60 :" $(recommanderLower $php_max_input_time "60" "To prevent attacker to DOS and eat your system resources, set max_input_time<60")
echo " - is memory_limit lower than 64M :" $(recommanderLower $php_memory_limit "128" "To prevent attacker to send oversized POST requests to eat your system resources, set php_memory_limit<128M")
echo " - Disable Functions :" $php_disable_functions
}
ftpStatus(){
echo -e "\n# FTP ($(serviceStatusCheck "pure-ftpd") - Pure-ftpd)\n"
ftp_port=$(get_config_variable_space_based "Port" $ftp_config_path)
echo " * FTP config path :" $ftp_config_path
echo " - Port :" $(recommanderReverse $(emptyMask $ftp_port "21") "21" "Change default ftp port.")
}
firewallStatus(){
echo -e "\n# Firewall ($(serviceStatusCheck "lfd") - LFD)\n"
csf_testing=$(get_config_variable "TESTING" $csf_config_path)
csf_tcp_in=$(get_config_variable "TCP_IN" $csf_config_path)
csf_tcp_out=$(get_config_variable "TCP_OUT" $csf_config_path)
csf_udp_in=$(get_config_variable "UDP_IN" $csf_config_path)
csf_udp_out=$(get_config_variable "UDP_OUT" $csf_config_path)
csf_icmp_in=$(get_config_variable "ICMP_IN" $csf_config_path)
csf_ipv6=$(get_config_variable "IPV6" $csf_config_path)
echo " * CSF config path :" $csf_config_path
echo " - is CSF enable :" $(recommanderYesOrNo $(qouteRemover $csf_testing) "0" "To enable firewall you must set TESTING=0")
echo " - Allowed TCP-IN Ports :" $(qouteRemover $csf_tcp_in)
echo " - Allowed TCP-OUT Ports :" $(qouteRemover $csf_tcp_out)
echo " - Allowed UDP-IN Ports :" $(qouteRemover $csf_udp_in)
echo " - Allowed UDP-OUT Ports :" $(qouteRemover $csf_udp_out)
echo " - is ICMP-IN Disable :" $(recommanderYesOrNo $(qouteRemover $csf_icmp_in) "0" "you must set ICMP_IN=0")
echo " - is IPV6 Disable :" $(recommanderYesOrNo $(qouteRemover $csf_ipv6) "0" "you must disable ipv6 by set IPV6=0")
}
dnsStatus(){
echo -e "\n# DNS ($(serviceStatusCheck "named") - Named)\n"
echo " * DNS config path :" $dns_config_path
}
mailStatus(){
# Mail Service
echo -e "\n# Mail ($(serviceStatusCheck "exim") - Exim)\n"
echo " * Mail config path :" $mail_config_path
# IMAP Service
echo -e "\n# IMAP ($(serviceStatusCheck "dovecot") - Dovecot)\n"
echo " * Exim config path :" $imap_config_path
# Pop3&SMTP Service
echo -e "\n# Pop3&SMTP ($(serviceStatusCheck "da-popb4smtp") - Da-popb4smtp)\n"
echo " * Pop3&Imap config path :" $pop3_config_path
}
showStatus(){
# Show Status
echo -e " \n\n ----- Server Status ----- \n"
echo "# OS :" $(cat /etc/redhat-release)
echo "# Hostname :" $(hostname)
echo "# Memory Usage :" $(free -m | awk 'NR==2{printf "%s/%sMB (%.2f%%)\n", $3,$2,$3*100/$2 }')
echo "# Disk Usage :" $(df -h | awk '$NF=="/"{printf "%d/%dGB (%s)\n", $3,$2,$5}')
echo "# CPU Load :" $(top -bn1 | grep load | awk '{printf "%.2f\n", $(NF-2)}' )
echo "# IP :" $(ifconfig | awk '/inet /{print substr($2,1)}' | grep -v 127.0.0.1 | xargs)
echo -e " \n\n ----- Services Status -----"
# SSH Status
sshStatus
# Directadmin Status
directadminStatus
# Mysql Status
mysqlStatus
# Webserver
webserverStatus
# PHP Status
phpStatus
# FTP Service
ftpStatus
# Firewall Service
firewallStatus
# DNS Service
dnsStatus
# Mail Service
mailStatus
}
phpRouter(){
if [[ ${BASH_ARGV[0]} == "--secure" ]]
then
cd /usr/local/directadmin/custombuild; ./build update; ./build secure_php
elif [ ${BASH_ARGV[0]} == "--double-php" ]
then
directadmin_php1_release=$(get_config_variable "php1_release" $directadmin_options_path)
directadmin_php2_release=$(get_config_variable "php2_release" $directadmin_options_path)
echo "* PHP1 Version :" $directadmin_php1_release
echo "* PHP2 Version :" $directadmin_php2_release
read -p '# PHP1 - What PHP version do you need (5.6) : ' first_php_version
read -p '# PHP2 - What PHP version do you need (7.2) : ' second_php_version
set_directadmin_option "php1_release" $first_php_version
set_directadmin_option "php2_release" $second_php_version
cd /usr/local/directadmin/custombuild; ./build update; ./build php d;
echo "* All websites currently running on your DirectAdmin server will use the value set for PHP 1. In order to alter the PHP version per website, navigate to the User Level, select the domain name, click ""Domain Setup"" under ""Your Account"", click the domain name and scroll down."
elif [ ${BASH_ARGV[0]} == "--set-timezone" ]
then
directadmin_php_timezone=$(get_config_variable "php_timezone" $directadmin_options_path)
php_ini_timezone=$(get_config_variable "date.timezone" $php_ini_path)
echo "* Current Timezone :" $directadmin_php_timezone "," $(qouteRemover $php_ini_timezone)
read -p '# Where are you (Ex: Europe\\/London | Asia\\/Tehran) : ' php_timezone
cd /usr/local/directadmin/custombuild; ./build set php_timezone $php_timezone
config_editor "date.timezone" "\"${php_timezone}\"" $php_ini_path
systemctl restart httpd
else
phpStatus
fi
}
webserverRouter(){
if [[ ${BASH_ARGV[0]} == "--install-mod-security" ]]
then
read -p '# Are you sure to install mod_security ? (if not CTRL+C) ' first_php_version
set_directadmin_option "modsecurity" "yes"
set_directadmin_option "modsecurity_ruleset" "comodo"
cd /usr/local/directadmin/custombuild; ./build modsecurity; ./build modsecurity_rules;
cd /usr/local/directadmin/custombuild; ./build cron;
else
webserverStatus
fi
}
mailRouter(){
if [[ ${BASH_ARGV[0]} == "--install-dkim" ]]
then
exim_supports=$(/usr/sbin/exim -bV | grep 'Support for' )
if [[ $exim_supports = *"DKIM"* ]]; then
echo "It's there!"
is_exim_already_support=$(cat /etc/exim.conf | grep exim.dkim.conf | wc -l)
if [ $is_exim_already_support -gt "0" ]
then
echo "exim is already supported."
else
cd /etc; wget -O exim.dkim.conf http://files.directadmin.com/services/exim.dkim.conf
sed -i 's/driver = smtp/driver = smtp\n.include_if_exists \/etc\/exim.dkim.conf/g' /etc/exim.conf
echo "* Restarting Exim ..."
service exim restart 2>&1 >/dev/null
echo "* Create directadmin.conf backup ..."
cd /usr/local/directadmin; cp -f conf/directadmin.conf conf/directadmin.conf.backup; echo 'dkim=1' >> conf/directadmin.conf;
echo "* Adding DKIM to directadmin.conf ..."
cd /usr/local/directadmin; echo 'dkim=1' >> conf/directadmin.conf;
echo "* Restarting Directadmin ..."
service directadmin restart 2>&1 >/dev/null
echo "* Adding DKIM to existing domain ..."
echo "action=rewrite&value=dkim" >> /usr/local/directadmin/data/task.queue
echo "+ DKIM added to exim successfully."
fi
#
else
echo "exim does not support DKIM, re-compile exim. https://help.directadmin.com/item.php?id=569"
fi
else
mailStatus
fi
}
directadminRouter(){
if [[ ${BASH_ARGV[0]} == "--change-port" ]]
then
directadmin_config_port=$(get_config_variable "port" $directadmin_config_path)
echo -e "\n"
echo "* Current Port :" $directadmin_config_port
read -p '* New Port : ' directadmin_new_port
is_new_port_inuse=$(lsof -i -P -n | grep LISTEN | grep "*:${directadmin_new_port}\ " | wc -l)
if [ $is_new_port_inuse -gt "0" ]
then
echo "- Port ${directadmin_new_port} is in use, choose another one."
else
# Change Directadmin Port
config_editor "port" "${directadmin_new_port}" $directadmin_config_path
# Change CSF Conf
#TCP-in
csf_tcp_in=$(get_config_variable "TCP_IN" $csf_config_path)
new_csf_tcp_in=$(sed "s/\,${directadmin_config_port}/\,${directadmin_new_port}/" <<< $csf_tcp_in)
config_editor "TCP_IN" "${new_csf_tcp_in}" $csf_config_path
#TCP-out
csf_tcp_out=$(get_config_variable "TCP_OUT" $csf_config_path)
new_csf_tcp_out=$(sed "s/\,${directadmin_config_port}/\,${directadmin_new_port}/" <<< $csf_tcp_out)
config_editor "TCP_OUT" "${new_csf_tcp_out}" $csf_config_path
# Restart CSF
echo -e "\n"
echo "* Restarting CSF ..."
csf -r >/dev/null
# Restart Directadmin
echo "* Restarting Directadmin ..."
service directadmin restart 2>&1 >/dev/null
echo "+ Port Changed."
echo -e "\n"
fi
elif [ ${BASH_ARGV[0]} == "--enable-letsencrypt" ]
then
directadmin_config_letsencrypt=$(get_config_variable "letsencrypt" $directadmin_config_path)
directadmin_config_ssl_sni=$(get_config_variable "enable_ssl_sni" $directadmin_config_path)
directadmin_config_ssl=$(get_config_variable "SSL" $directadmin_config_path)
# Edit Config File
echo "* Enable SSL SNI & Letsecnrypt ..."
config_editor "enable_ssl_sni" "1" $directadmin_config_path
config_editor "letsencrypt" "1" $directadmin_config_path
config_editor "SSL" "1" $directadmin_config_path
# Restart Directadmin
echo "* Restarting Directadmin ..."
echo "action=directadmin&value=restart" >> /usr/local/directadmin/data/task.queue; /usr/local/directadmin/dataskq d2000
# Add the /.well-known Alias:
echo "* Add the /.well-known Alias ..."
cd /usr/local/directadmin/custombuild; ./build rewrite_confs
# Run CustomBuild to install letsencrypt
echo "* Run CustomBuild to install letsencrypt"
cd /usr/local/directadmin/custombuild; ./build update; ./build letsencrypt
echo "+ Letsencrypt enabled succesfully."
echo -e "\n"
elif [ ${BASH_ARGV[0]} == "--enable-host-freessl" ]
then
echo -e "\n"
read -p '* Your Hostname : ' my_hostname
# get hostname from conf
echo "${$my_hostname}: admin" >> /etc/virtual/domainowners
cd /usr/local/directadmin/scripts; ./letsencrypt.sh request_single $my_hostname 4096
echo "carootcert=/usr/local/directadmin/conf/carootcert.pem" >> $directadmin_config_path
echo "force_hostname=${$my_hostname}" >> $directadmin_config_path
echo "ssl_redirect_host=${$my_hostname}" >> $directadmin_config_path
service directadmin restart
echo "+ SSL enabled succesfully please add A record for ${$my_hostname}."
else
directadminStatus
fi
}
mysqlRouter(){
if [[ ${BASH_ARGV[0]} == "--secure" ]]
then
echo "under construction..."
else
mysqlStatus
fi
}
showHelp(){
echo -e "\n"
echo "Usage: daShield [OPTION]"
echo "Example: daShield -s"
echo -e "\n"
echo "PHP Tools:"
echo " --php Show PHP status"
echo " --php --secure Secure PHP configuration"
echo " --php --double-php Add second php to directadmin"
echo " --php --set-timezone Set PHP timezone"
echo -e "\n"
echo "Directadmin Tools:"
echo "--directadmin Show Directadmin status"
echo "--directadmin --change-port Change directadmin port"
echo "--directadmin --enbale-letsencrypt Enable letsencrypt feature"
echo "--directadmin --enable-host-freessl Enable letsencrypt feature"
echo -e "\n"
echo "Webserver Tools:"
echo " --webserver Show Webserver status"
echo " --webserver --install-mod-security Install mod_security"
echo -e "\n"
echo "Mysql Tools : "
echo " --mysql Show mysql status"
echo " --mysql --secure Secure mysql configuration"
echo -e "\n"
echo "Mail Tools:"
echo " --mail Show Mailserver status"
echo " --mail --install-dkim Install Dkim"
echo -e "\n"
echo "Miscellaneous:"
echo " -s, --show-status Show server status"
echo " -h, --help Display this help text and exit"
echo -e "\n"
}
# Router
while [ "$1" != "exit" ]; do
case $1 in
-s | --show-status ) showStatus
;;
-h | --help ) showHelp
exit
;;
--php ) shift
phpRouter
exit
;;
--webserver ) shift
webserverRouter
exit
;;
--mysql ) shift
mysqlRouter
exit
;;
--directadmin ) shift
directadminRouter
exit
;;
--mail ) shift
mailRouter
exit
;;
* ) showHelp
exit 1
esac
shift
done
# Regular updates of system services, libraries and scripts.
# cd /usr/local/directadmin/custombuild; ./build update; ./build all d
# Change Directadmin Options
# set_directadmin_option "email" $email/
# set_directadmin_option "da_autoupdate" "yes"
# set_directadmin_option "clean_old_webapps" "yes"
# set_directadmin_option "updates" "no"
# set_directadmin_option "webapps_updates" "yes"