forked from Billionmail/BillionMail
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbm.sh
More file actions
1800 lines (1527 loc) · 67.9 KB
/
bm.sh
File metadata and controls
1800 lines (1527 loc) · 67.9 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
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
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
# Add domain name and email
CONTAINER_PROJECT_NAME=billionmail
PGSQL_CONTAINER_NAME="${CONTAINER_PROJECT_NAME}-pgsql-billionmail-1"
DOVECOT_CONTAINER_NAME="${CONTAINER_PROJECT_NAME}-dovecot-billionmail-1"
POSTFIX_CONTAINER_NAME="${CONTAINER_PROJECT_NAME}-postfix-billionmail-1"
RSPAMD_CONTAINER_NAME="${CONTAINER_PROJECT_NAME}-rspamd-billionmail-1"
create_time=$(date +%s)
time=$(date +%Y_%m_%d_%H_%M_%S)
if [ $(whoami) != "root" ];then
echo -e "Non-root install, please try the following solutions: \n 1.Please switch to root user install \n 2.Try executing the following install commands: \n sudo bash $0 $@"
exit 1
fi
PWD_d=`pwd`
SWITCH_TO_BILLIONMAIL_DIR(){
if [ -f "/opt/PWD-Billion-Mail.txt" ]; then
DIR=$(cat /opt/PWD-Billion-Mail.txt)
if [ -d "${DIR}" ]; then
cd "${DIR}"
echo "Enter the BillionMail project directory: ${DIR}"
fi
fi
}
if [ -s ".env" ]; then
CHECK_BILLIONMAIL=$(grep "BILLIONMAIL_HOSTNAME" .env)
if [ -z "${CHECK_BILLIONMAIL}" ]; then
SWITCH_TO_BILLIONMAIL_DIR
fi
else
SWITCH_TO_BILLIONMAIL_DIR
fi
if [ ! -s ".env" ]; then
ls -al
echo " The .env file does not exist. Cannot continue operation, please operate in the BillionMail project directory"
exit 1
fi
source .env
if [ -z "${DBUSER}" ] || [ -z "${DBNAME}" ] || [ -z "${DBPASS}" ]; then
echo "The obtained .env configuration exception is empty."
exit 1
fi
Red_Error(){
echo '=================================================';
printf '\033[1;31;40m%b\033[0m\n' "$@";
exit 1;
}
Command_Exists() {
command -v "$@" >/dev/null 2>&1
}
Docker_Compose_Check(){
if Command_Exists docker-compose ; then
DOCKER_COMPOSE="docker-compose"
else
if Command_Exists docker; then
Docker_compose="docker compose version"
if $Docker_compose >/dev/null 2>&1; then
DOCKER_COMPOSE="docker compose"
fi
else
Red_Error "ERROR: Docker Compose does not exist"
fi
fi
}
Docker_Compose_Check
GET_SERVICE_NAME() {
# ALL_SERVICE_NAME=$(${DOCKER_COMPOSE} config --services |grep "${SERVICE}")
# echo "${ALL_SERVICE_NAME}"
if [[ "${SERVICE}" == "core" ]] || [[ "${SERVICE}" == "manage" ]]; then
#echo "Getting the "${SERVICE}" service..."
SERVICE_NAME=$(${DOCKER_COMPOSE} ps -a --format " {{.Service}} {{.ID}} {{.Image}}" |grep "/core:" | awk '{print $1}' )
elif [[ "${SERVICE}" == "postfix" ]] || [[ "${SERVICE}" == "postfix-billionmail" ]]; then
SERVICE_NAME="postfix-billionmail"
elif [[ "${SERVICE}" == "dovecot" ]] || [[ "${SERVICE}" == "dovecot-billionmail" ]]; then
SERVICE_NAME="dovecot-billionmail"
elif [[ "${SERVICE}" == "rspamd" ]] || [[ "${SERVICE}" == "rspamd-billionmail" ]]; then
SERVICE_NAME="rspamd-billionmail"
elif [[ "${SERVICE}" == "pgsql" ]] || [[ "${SERVICE}" == "postgres" ]] || [[ "${SERVICE}" == "pgsql-billionmail" ]]; then
SERVICE_NAME="pgsql-billionmail"
elif [[ "${SERVICE}" == "redis" ]] || [[ "${SERVICE}" == "redis-billionmail" ]]; then
SERVICE_NAME="redis-billionmail"
elif [[ "${SERVICE}" == "webmail" ]] || [[ "${SERVICE}" == "roundcube" ]] || [[ "${SERVICE}" == "webmail-billionmail" ]]; then
SERVICE_NAME="webmail-billionmail"
else
echo "Please use: core|postfix|dovecot|rspamd|pgsql|redis|webmail"
Red_Error "ERROR: The "${SERVICE}" service does not exist"
fi
if [ -z "${SERVICE_NAME}" ]; then
Red_Error "ERROR: The "${SERVICE}" service does not exist"
fi
}
GET_CONTAINER_ID() {
if [ -z "${CONTAINER}" ]; then
CONTAINER="$1"
fi
if [[ "${CONTAINER}" == "core" ]] || [[ "${CONTAINER}" == "manage" ]]; then
CONTAINER_ID=$(${DOCKER_COMPOSE} ps -a --format "{{.ID}} {{.Image}}" |grep "/core:" | awk '{print $1}' )
elif [[ ""${CONTAINER}"" == "postfix" ]] || [[ ""${CONTAINER}"" == "postfix-billionmail" ]]; then
CONTAINER_ID=$(${DOCKER_COMPOSE} ps -a --format "{{.ID}} {{.Image}}" |grep "/postfix:" | awk '{print $1}' )
elif [[ ""${CONTAINER}"" == "dovecot" ]] || [[ ""${CONTAINER}"" == "dovecot-billionmail" ]]; then
CONTAINER_ID=$(${DOCKER_COMPOSE} ps -a --format "{{.ID}} {{.Image}}" |grep "/dovecot:" | awk '{print $1}' )
elif [[ ""${CONTAINER}"" == "rspamd" ]] || [[ ""${CONTAINER}"" == "rspamd-billionmail" ]]; then
CONTAINER_ID=$(${DOCKER_COMPOSE} ps -a --format "{{.ID}} {{.Image}}" |grep "/rspamd:" | awk '{print $1}' )
elif [[ ""${CONTAINER}"" == "pgsql" ]] || [[ ""${CONTAINER}"" == "postgres" ]] || [[ ""${CONTAINER}"" == "pgsql-billionmail" ]]; then
CONTAINER_ID=$(${DOCKER_COMPOSE} ps -a --format "{{.ID}} {{.Image}}" |grep "postgres:" | awk '{print $1}' )
elif [[ ""${CONTAINER}"" == "redis" ]] || [[ ""${CONTAINER}"" == "redis-billionmail" ]]; then
CONTAINER_ID=$(${DOCKER_COMPOSE} ps -a --format "{{.ID}} {{.Image}}" |grep "redis:" | awk '{print $1}' )
elif [[ ""${CONTAINER}"" == "webmail" ]] || [[ ""${CONTAINER}"" == "roundcube" ]] || [[ ""${CONTAINER}"" == "webmail-billionmail" ]]; then
CONTAINER_ID=$(${DOCKER_COMPOSE} ps -a --format "{{.ID}} {{.Image}}" |grep "roundcubemail:" | awk '{print $1}' )
else
echo "Please use: core|postfix|dovecot|rspamd|pgsql|redis|webmail"
Red_Error "ERROR: The ""${CONTAINER}"" container does not exist"
fi
}
Init_Email() {
input="$2"
# Regular expression verification email address format
if [[ "$input" =~ ^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$ ]]; then
mailbox=$(echo "$input" | cut -d '@' -f 1 | tr '[:upper:]' '[:lower:]')
BILLIONMAIL_HOSTNAME=$(echo "$input" | cut -d '@' -f 2 | tr '[:upper:]' '[:lower:]')
else
echo "Enter an email address that is not a legal one: $input"
echo "Example: user@example.com"
exit 1
fi
}
Init_Domain() {
BILLIONMAIL_HOSTNAME="$2"
# Regular expression check domain name format
# if [[ ! "${BILLIONMAIL_HOSTNAME}" =~ ^[a-zA-Z0-9][a-zA-Z0-9-]{0,61}[a-zA-Z0-9](\.[a-zA-Z0-9][a-zA-Z0-9-]{0,61}[a-zA-Z0-9])*$ ]]; then
if [[ ! "${BILLIONMAIL_HOSTNAME}" =~ ^([a-zA-Z0-9]([a-zA-Z0-9-]{0,62}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,}$ ]]; then
echo -e "\e[31m(${BILLIONMAIL_HOSTNAME}) is not a FQDN!\e[0m"
echo "Please change it to a FQDN"
exit 1
elif [[ "${BILLIONMAIL_HOSTNAME: -1}" == "." ]]; then
echo "(${BILLIONMAIL_HOSTNAME}) is ending with a dot. This is not a valid FQDN!"
exit 1
fi
# Convert to lowercase
BILLIONMAIL_HOSTNAME=$(echo "${BILLIONMAIL_HOSTNAME}" | tr '[:upper:]' '[:lower:]')
}
Domain_DKIM_record(){
if [ -z "${BILLIONMAIL_HOSTNAME}" ]; then
echo "Please enter the domain name"
exit 1
fi
Check_domain=$(docker exec -i -e PGPASSWORD=${DBPASS} ${PGSQL_CONTAINER_NAME} psql -U ${DBUSER} -d ${DBNAME} -c "SELECT * FROM domain WHERE domain = '${BILLIONMAIL_HOSTNAME}';" | grep -w "^ ${BILLIONMAIL_HOSTNAME}")
if [ -z "${Check_domain}" ]; then
echo "Error: ${BILLIONMAIL_HOSTNAME} Domain does not exist."
exit 1
fi
## DKIM key generation
docker exec -i -e BILLIONMAIL_HOSTNAME=${BILLIONMAIL_HOSTNAME} ${RSPAMD_CONTAINER_NAME} bash -c 'cat << "EOF" > /tmp/1.sh
#!/bin/bash
if [ ! -d "/var/lib/rspamd/dkim/${BILLIONMAIL_HOSTNAME}/" ]; then
mkdir -p "/var/lib/rspamd/dkim/${BILLIONMAIL_HOSTNAME}/"
fi
if [ -f "/var/lib/rspamd/dkim/${BILLIONMAIL_HOSTNAME}/default.private" ] && [ -f "/var/lib/rspamd/dkim/${BILLIONMAIL_HOSTNAME}/default.pub" ]; then
#echo "DKIM key already exists, skipping generation."
exit 0
fi
rspamadm dkim_keygen -s 'default' -b 1024 -d {domain} -k "/var/lib/rspamd/dkim/${BILLIONMAIL_HOSTNAME}/default.private" > "/var/lib/rspamd/dkim/${BILLIONMAIL_HOSTNAME}/default.pub"
if [ $? -eq 0 ]; then
# Define the root directory for private keys
DKIM_KEYS_DIR="/var/lib/rspamd/dkim"
# Configuration file path
CONFIG_FILE="/etc/rspamd/local.d/dkim_signing.conf"
# Check if the configuration file exists, if not, create it
if [ ! -f "${CONFIG_FILE}" ]; then
touch "${CONFIG_FILE}"
echo "${CONFIG_FILE}"
echo "domain {" > "${CONFIG_FILE}"
echo "#BT_DOMAIN_DKIM_BEGIN" >> "${CONFIG_FILE}"
echo "#BT_DOMAIN_DKIM_END" >> "${CONFIG_FILE}"
echo "}" >> "${CONFIG_FILE}"
fi
# Scan the DKIM_KEYS_DIR directory to get all domains
DOMAINS=()
for DOMAIN_DIR in "${DKIM_KEYS_DIR}"/*; do
if [ -d "${DOMAIN_DIR}" ]; then
DOMAIN_NAME=$(basename "${DOMAIN_DIR}")
PRIVATE_KEY_PATH="${DOMAIN_DIR}/default.private"
if [ -f "${PRIVATE_KEY_PATH}" ]; then
DOMAINS+=("${DOMAIN_NAME}:${PRIVATE_KEY_PATH}")
else
echo "Warning: Private key file ${PRIVATE_KEY_PATH} for domain ${DOMAIN_NAME} does not exist, skipping configuration."
fi
fi
done
# Add domain configurations
for DOMAIN in "${DOMAINS[@]}"; do
DOMAIN_NAME=$(echo "${DOMAIN}" | cut -d':' -f1)
PRIVATE_KEY_PATH=$(echo "${DOMAIN}" | cut -d':' -f2)
# Check if the domain already exists
if grep -wq "${DOMAIN_NAME}" "${CONFIG_FILE}"; then
# echo "Domain ${DOMAIN_NAME} already exists, skipping configuration."
continue
fi
# Insert domain configuration between #BT_DOMAIN_DKIM_BEGIN and #BT_DOMAIN_DKIM_END
sed -i "/^#BT_DOMAIN_DKIM_BEGIN$/a #${DOMAIN_NAME}_DKIM_BEGIN\n ${DOMAIN_NAME} {\n selectors [\n {\n path: \"${PRIVATE_KEY_PATH}\";\n selector: \"default\"\n }\n ]\n }\n#${DOMAIN_NAME}_DKIM_END" "${CONFIG_FILE}"
# echo "Domain ${DOMAIN_NAME} has been successfully added to the configuration file."
done
# echo "DKIM configuration update completed."
else
echo -e "DKIM key generation failed!"
exit 1
fi
chmod 755 -R "/var/lib/rspamd/dkim/${BILLIONMAIL_HOSTNAME}/"
EOF'
docker exec -i -e BILLIONMAIL_HOSTNAME=${BILLIONMAIL_HOSTNAME} ${RSPAMD_CONTAINER_NAME} bash /tmp/1.sh && rm -f /tmp/1.sh
DKIM_RECORD=$(docker exec ${RSPAMD_CONTAINER_NAME} cat "/var/lib/rspamd/dkim/${BILLIONMAIL_HOSTNAME}/default.pub")
# echo "DKIM RECORD: ${DKIM_RECORD}"
}
Domain_record() {
Check_domain=$(docker exec -i -e PGPASSWORD=${DBPASS} ${PGSQL_CONTAINER_NAME} psql -U ${DBUSER} -d ${DBNAME} -c "SELECT * FROM domain WHERE domain = '${BILLIONMAIL_HOSTNAME}';" | grep -w "^ ${BILLIONMAIL_HOSTNAME}")
if [ "${Check_domain}" ]; then
IPV4_ADDRESS=$(curl -sS -4 --connect-timeout 10 -m 20 https://ifconfig.me)
if [ -z "${IPV4_ADDRESS}" ]; then
IPV4_ADDRESS=$(curl -sSk --connect-timeout 10 -m 20 https://www.aapanel.com/api/common/getClientIP)
fi
ipv4_regex="^([0-9]{1,3}\.){3}[0-9]{1,3}$"
if [[ ${IPV4_ADDRESS} =~ ${ipv4_regex} ]]; then
echo "${IPV4_ADDRESS}" >/dev/null 2>&1
elif [ -z "${IPV4_ADDRESS}" ]; then
IPV4_ADDRESS="YOUR_SERVER_IPV4_ADDRESS"
fi
echo -e ""
echo -e "\e[31mPlease add the following record to your domain name\e[0m"
echo -e "==========================================================="
echo -e " Type | Host record | IPv4 address |"
echo -e " \e[1;33mA\e[0m | \e[1;33mmail.${BILLIONMAIL_HOSTNAME}\e[0m | \e[1;33m${IPV4_ADDRESS}\e[0m |"
echo -e "==========================================================="
echo -e " Type | Host record | MX priority | Record value "
echo -e " \e[1;33mMX\e[0m | \e[1;33m@\e[0m | \e[1;33m10\e[0m | \e[1;33mmail.${BILLIONMAIL_HOSTNAME}\e[0m "
echo -e "==========================================================="
if [ "${IPV4_ADDRESS}" ]; then
echo -e " Type | Host record | Record value |"
echo -e " \e[1;33mTXT\e[0m | \e[1;33m@\e[0m | \e[1;33mv=spf1 +a +mx +ip4:${IPV4_ADDRESS} -all\e[0m |"
else
echo -e " Type | Host record | Record value |"
echo -e " \e[1;33mTXT\e[0m | \e[1;33m@\e[0m | \e[1;33mv=spf1 +a +mx -all\e[0m |"
fi
echo -e "==========================================================="
echo -e " Type | Host record | Record value |"
echo -e " \e[1;33mTXT\e[0m | \e[1;33m_dmarc\e[0m | \e[1;33mv=DMARC1;p=quarantine;rua=mailto:admin@${BILLIONMAIL_HOSTNAME}\e[0m |"
echo -e "==========================================================="
Domain_DKIM_record
if [ "${DKIM_RECORD}" ]; then
DKIM_RECORD=$(echo "${DKIM_RECORD}" | awk -F'"' '{print $2 $4}' | tr -d '[:space:]')
#echo "DKIM RECORD: ${DKIM_RECORD}"
echo -e " Type | Host record | Record value |"
echo -e " \e[1;33mTXT\e[0m | \e[1;33mdefault._domainkey\e[0m | \e[1;33m${DKIM_RECORD}\e[0m |<-- Start from \"v=DKIM1\" end, A single line."
echo -e "==========================================================="
else
echo -e "${BILLIONMAIL_HOSTNAME} DKIM key generation failed!"
fi
else
echo -e "Domain ${BILLIONMAIL_HOSTNAME} does not exist."
fi
}
Select_Domain_data(){
# Check_domain=$(docker exec -i -e PGPASSWORD=${DBPASS} ${PGSQL_CONTAINER_NAME} psql -U ${DBUSER} -d ${DBNAME} -c "SELECT * FROM domain;")
# echo "${Check_domain}"
Check_domain=$(docker exec -i -e PGPASSWORD=${DBPASS} ${PGSQL_CONTAINER_NAME} psql -U ${DBUSER} -d ${DBNAME} -c "SELECT domain FROM domain;")
echo "${Check_domain}"
}
Select_Email_data(){
Check_mailbox=$(docker exec -i -e PGPASSWORD=${DBPASS} ${PGSQL_CONTAINER_NAME} psql -U ${DBUSER} -d ${DBNAME} -c "SELECT username FROM mailbox;")
echo "${Check_mailbox}"
}
Add_Domain() {
echo "Creating domain..."
Check_domain=$(docker exec -i -e PGPASSWORD=${DBPASS} ${PGSQL_CONTAINER_NAME} psql -U ${DBUSER} -d ${DBNAME} -c "SELECT * FROM domain WHERE domain = '${BILLIONMAIL_HOSTNAME}';" | grep -w "^ ${BILLIONMAIL_HOSTNAME}")
if [ -z "${Check_domain}" ]; then
# Create a domain
docker exec -i -e PGPASSWORD=${DBPASS} ${PGSQL_CONTAINER_NAME} psql -U ${DBUSER} -d ${DBNAME} -c "INSERT INTO domain (domain, a_record, mailboxes, mailbox_quota, quota, rate_limit, create_time, active)
VALUES ('${BILLIONMAIL_HOSTNAME}', 'mail.${BILLIONMAIL_HOSTNAME}', 500, 5368709120, 5368709120, 12, ${create_time}, 1);"
if [ $? -eq 0 ]; then
echo "${BILLIONMAIL_HOSTNAME} Domain creation was successful!"
Domain_record
else
Red_Error "Domain creation failed!"
fi
else
echo ""${Check_domain}" Domain already exists!"
fi
}
Del_Domain() {
echo "Deleting domain..."
Check_domain=$(docker exec -i -e PGPASSWORD=${DBPASS} ${PGSQL_CONTAINER_NAME} psql -U ${DBUSER} -d ${DBNAME} -c "SELECT * FROM domain WHERE domain = '${BILLIONMAIL_HOSTNAME}';" | grep -w "^ ${BILLIONMAIL_HOSTNAME}")
if [ -z "${Check_domain}" ]; then
echo "Domain '${BILLIONMAIL_HOSTNAME}' does not exist!"
else
# Delete the domain
docker exec -i -e PGPASSWORD=${DBPASS} ${PGSQL_CONTAINER_NAME} psql -U ${DBUSER} -d ${DBNAME} -c "DELETE FROM domain WHERE domain = '${BILLIONMAIL_HOSTNAME}';"
if [ $? -eq 0 ]; then
echo "Domain '${BILLIONMAIL_HOSTNAME}' deleted successfully!"
else
Red_Error "Failed to delete domain '${BILLIONMAIL_HOSTNAME}'!"
fi
fi
}
Add_Email() {
echo "Creating mailbox..."
Check_domain=$(docker exec -i -e PGPASSWORD=${DBPASS} ${PGSQL_CONTAINER_NAME} psql -U ${DBUSER} -d ${DBNAME} -c "SELECT * FROM domain WHERE domain = '${BILLIONMAIL_HOSTNAME}';" | grep -w "^ ${BILLIONMAIL_HOSTNAME}")
if [ -z "${Check_domain}" ]; then
Red_Error "Domain '${BILLIONMAIL_HOSTNAME}' does not exist, please create it first!"
fi
# Create a mailbox
if [ -z "${mailbox}" ]; then
mailbox=$(LC_ALL=C </dev/urandom tr -dc a-z0-9 2> /dev/null | head -c 6)
echo "Generate mailbox: ${mailbox}"
else
mailbox=$(echo "${mailbox}" | tr '[:upper:]' '[:lower:]')
fi
Generate_mailbox_password=$(LC_ALL=C </dev/urandom tr -dc A-Za-z0-9 2> /dev/null | head -c 16)
#echo "Generate_mailbox_password: ${Generate_mailbox_password}"
Encrypt_mailbox_password=$(docker exec -i ${DOVECOT_CONTAINER_NAME} doveadm pw -s MD5-CRYPT -p "${Generate_mailbox_password}" | sed 's/{MD5-CRYPT}//')
if [ $? -eq 0 ]; then
echo "Generate_mailbox_password: ${Generate_mailbox_password}"
echo "mailbox_password: ${Encrypt_mailbox_password}"
else
# Generate the default password after failure: BILLIONMAIL
Generate_mailbox_password="BILLIONMAIL"
Encrypt_mailbox_password='$1$ELBUCcYE$TbdGKBvLkFbjQguDbi3s01'
echo "Generate_mailbox_password--default: ${Generate_mailbox_password}"
Default_password=1
fi
if [ "${Default_password}" != 1 ]; then
# password_encode
# Base64 encoding of strings
b64_data=$(echo -n "${Generate_mailbox_password}" | base64)
# Convert characters to hexadecimal
password_encode=$(echo -n "${b64_data}" | while IFS= read -r -n1 char; do printf "%02x" "'$char"; done)
echo "password_encode: ${password_encode}"
if [ -z ${password_encode} ]; then
b64_data=$(echo -n "${Generate_mailbox_password}" | base64)
password_encode=$(echo -n "${b64_data}" | od -A n -t x1 | tr -d ' \n')
echo "password_encode: ${password_encode}"
fi
else
password_encode="516b6c4d54456c50546b31425355773d"
fi
Check_mailbox=$(docker exec -i -e PGPASSWORD=${DBPASS} ${PGSQL_CONTAINER_NAME} psql -U ${DBUSER} -d ${DBNAME} -c "SELECT * FROM mailbox WHERE username = '${mailbox}@${BILLIONMAIL_HOSTNAME}';" | grep -w "${mailbox}@${BILLIONMAIL_HOSTNAME}")
if [ -z "${Check_mailbox}" ]; then
INSERT_mailbox='INSERT INTO mailbox (username, password, password_encode, full_name, is_admin, maildir, quota, local_part, domain, create_time, update_time, active)
VALUES (
'\'${mailbox}@${BILLIONMAIL_HOSTNAME}\'',
'\'${Encrypt_mailbox_password}\'',
'\'${password_encode}\'',
'\'${mailbox}\'',
0,
'\'${mailbox}@${BILLIONMAIL_HOSTNAME}/\'',
5368709120,
'\'${mailbox}\'',
'\'${BILLIONMAIL_HOSTNAME}\'',
'${create_time}',
'${create_time}',
1
);'
echo "$INSERT_mailbox"
docker exec -i -e PGPASSWORD=${DBPASS} ${PGSQL_CONTAINER_NAME} psql -U ${DBUSER} -d ${DBNAME} -c "$INSERT_mailbox"
if [ $? -eq 0 ]; then
echo "Mailbox creation was successful!"
else
Red_Error "Mailbox creation failed!"
fi
#docker exec -i -e PGPASSWORD=${DBPASS} ${PGSQL_CONTAINER_NAME} psql -U ${DBUSER} -d ${DBNAME} -c "SELECT * FROM mailbox WHERE username = '${mailbox}@${BILLIONMAIL_HOSTNAME}';"
else
echo ""${Check_mailbox}" Mailbox already exists!"
fi
echo -e "\e[31mPlease save the following information:\e[0m"
echo -e "Mailbox (e-mail): \e[33m${mailbox}@${BILLIONMAIL_HOSTNAME}\e[0m \nPassword: \e[33m${Generate_mailbox_password}\e[0m"
}
Del_Email() {
echo "Deleting mailbox..."
Check_mailbox=$(docker exec -i -e PGPASSWORD=${DBPASS} ${PGSQL_CONTAINER_NAME} psql -U ${DBUSER} -d ${DBNAME} -c "SELECT * FROM mailbox WHERE username = '${mailbox}@${BILLIONMAIL_HOSTNAME}';" | grep -w "${mailbox}@${BILLIONMAIL_HOSTNAME}")
if [ -z "${Check_mailbox}" ]; then
echo "Mailbox '${mailbox}@${BILLIONMAIL_HOSTNAME}' does not exist!"
else
docker exec -i -e PGPASSWORD=${DBPASS} ${PGSQL_CONTAINER_NAME} psql -U ${DBUSER} -d ${DBNAME} -c "DELETE FROM mailbox WHERE username = '${mailbox}@${BILLIONMAIL_HOSTNAME}';"
if [ $? -eq 0 ]; then
echo "Mailbox '${mailbox}@${BILLIONMAIL_HOSTNAME}' deleted successfully!"
else
Red_Error "Failed to delete mailbox '${mailbox}@${BILLIONMAIL_HOSTNAME}'!"
fi
fi
}
Update_BillionMail() {
BRANCH="main"
if [ -f "update.sh" ]; then
echo -e "Checking for update.sh script..."
MD5_1="$(md5sum update.sh)"
git fetch origin
git checkout "origin/${BRANCH}" update.sh
MD5_2=$(md5sum update.sh)
if [[ "${MD5_1}" != "${MD5_2}" ]]; then
#echo -e "\033[33m update.sh is changed, please run update.sh script again.\033[0m"
chmod +x update.sh
echo y | ./update.sh
#exit 1
else
chmod +x update.sh
echo y | ./update.sh
fi
else
Red_Error "Error: update.sh script does not exist!"
fi
}
Default_info() {
ipv4_address=""
ipv6_address=""
if [ "$address" = "" ];then
ipv4_address=$(curl -4 -sSf --connect-timeout 10 -m 15 https://ifconfig.me 2>&1)
if [ -z "${ipv4_address}" ];then
ipv4_address=$(curl -4 -sSf --connect-timeout 10 -m 15 https://www.aapanel.com/api/common/getClientIP 2>&1)
if [ -z "${ipv4_address}" ];then
ipv4_address=$(curl -4 -sSf --connect-timeout 10 -m 15 https://www.bt.cn/Api/getIpAddress 2>&1)
fi
fi
IPV4_REGEX="^([0-9]{1,3}\.){3}[0-9]{1,3}$"
if ! [[ $ipv4_address =~ $IPV4_REGEX ]]; then
ipv4_address=""
fi
ipv6_address=$(curl -6 -sSf --connect-timeout 10 -m 15 https://ifconfig.me 2>&1)
IPV6_REGEX="^([0-9a-fA-F]{0,4}:){1,7}[0-9a-fA-F]{0,4}$"
if ! [[ $ipv6_address =~ $IPV6_REGEX ]]; then
ipv6_address=""
else
if [[ ! $ipv6_address =~ ^\[ ]]; then
ipv6_address="[$ipv6_address]"
fi
fi
if [ "$address" = "" ] && [ "$ipv4_address" = "" ] && [ "$ipv6_address" = "" ];then
address="SERVER_IP"
echo -e "\033[33mFailed to obtain Internet IP, please use the server Internet IP+PORT to access.\033[0m"
fi
fi
LOCAL_IP=$(ip addr | grep -E -o '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' | grep -E -v "^127\.|^255\.|^0\." | head -n 1)
echo -e "=================================================================="
echo -e "\033[32mBillionMail default info!\033[0m"
echo -e "=================================================================="
pool=https
if [ -f "core-data/billionmail_hostname.txt" ];then
BILLIONMAIL_Domain=$(cat core-data/billionmail_hostname.txt)
if [ "${HTTPS_PORT}" = "443" ];then
echo "BillionMail Domain Address: ${pool}://${BILLIONMAIL_Domain}/${SafePath}"
else
echo "BillionMail Domain Address: ${pool}://${BILLIONMAIL_Domain}:${HTTPS_PORT}/${SafePath}"
fi
fi
if [ "${ipv6_address}" ];then
if [ "${HTTPS_PORT}" = "443" ];then
echo "BillionMail Internet IPv6 Address: ${pool}://${ipv6_address}/${SafePath}"
else
echo "BillionMail Internet IPv6 Address: ${pool}://${ipv6_address}:${HTTPS_PORT}/${SafePath}"
fi
fi
if [ "${ipv4_address}" ];then
if [ "${HTTPS_PORT}" = "443" ];then
echo "BillionMail Internet IPv4 Address: ${pool}://${ipv4_address}/${SafePath}"
else
echo "BillionMail Internet IPv4 Address: ${pool}://${ipv4_address}:${HTTPS_PORT}/${SafePath}"
fi
fi
if [ "${address}" ];then
if [ "${HTTPS_PORT}" = "443" ];then
echo "BillionMail Internet Address: ${pool}://${address}/${SafePath}"
else
echo "BillionMail Internet Address: ${pool}://${address}:${HTTPS_PORT}/${SafePath}"
fi
fi
if [ "${HTTPS_PORT}" = "443" ];then
echo "BillionMail Internal Address: ${pool}://${LOCAL_IP}/${SafePath}"
else
echo "BillionMail Internal Address: ${pool}://${LOCAL_IP}:${HTTPS_PORT}/${SafePath}"
fi
echo -e "Username: ${ADMIN_USERNAME} \nPassword: ${ADMIN_PASSWORD}"
echo -e "\033[33mWarning:\033[0m"
echo -e "\033[33mIf you cannot access the BillionMail, \033[0m"
echo -e "\033[33mrelease the following port ${SMTP_PORT}|${SMTPS_PORT}|${SUBMISSION_PORT}|${POP_PORT}|${IMAP_PORT}|${IMAPS_PORT}|${POPS_PORT}|${HTTP_PORT}|${HTTPS_PORT} in the security group\033[0m"
echo -e "=================================================================="
}
# Modify the apply SSL interface access port
MODIFY_HTTP_SSL_PORT() {
NEW_PORT="$2"
if [ -z "${NEW_PORT}" ]; then
echo -e "\033[31m Let's Encrypt SSL certificate can only be applied using port 80, other ports cannot be applied.\033[0m"
read -p "Please enter the new apply SSL port: " NEW_PORT
fi
# Verify that the input is a number
if ! echo "${NEW_PORT}" | grep -qE '^[0-9]+$' || ((NEW_PORT < 1 || NEW_PORT > 65535)); then
echo -e "\033[31m Error: The port number must be a number between 1-65535 \033[0m"
exit 1
fi
Check_Port=$(ss -tlnp | grep -E ":(${NEW_PORT})\b")
if [ ! -z "${Check_Port}" ]; then
echo "${Check_Port}"
echo -e "\033[31m Error: The ${NEW_PORT} port is already in use. \033[0m"
exit 1
fi
# Perform modification
sed -i 's/^HTTP_PORT=.*/HTTP_PORT='"${NEW_PORT}"'/' .env
echo -e "The BillionMail apply SSL port has been modified to: ${NEW_PORT} \n Rebuild the container, please wait..."
sleep 3
# Find the container ID of the core image in the current project and rebuild the container
# CONTAINER_ID=$(${DOCKER_COMPOSE} ps -a --format "{{.ID}} {{.Image}}" |grep "/core:" | awk '{print $1}' )
CONTAINER="core"
GET_CONTAINER_ID ${CONTAINER}
if [ "${CONTAINER_ID}" ]; then
echo "Rebuilding Manage Container..."
docker stop ${CONTAINER_ID}
docker rm -f ${CONTAINER_ID}
${DOCKER_COMPOSE} up -d
else
echo "The "core" container does not exist"
echo "Starting BillionMail..."
${DOCKER_COMPOSE} up -d
fi
if [ -f "/usr/sbin/ufw" ]; then
/usr/sbin/ufw allow ${NEW_PORT}/tcp >/dev/null 2>&1
/usr/sbin/ufw reload
elif [ -f "/usr/sbin/firewall-cmd" ]; then
/usr/sbin/firewall-cmd --permanent --zone=public --add-port=${NEW_PORT}/tcp >/dev/null 2>&1
/usr/sbin/firewall-cmd --reload
elif [ -f "/etc/sysconfig/iptables" ]; then
iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport ${NEW_PORT} -j ACCEPT
service iptables save
fi
if [[ ${NEW_PORT} != "80" ]]; then
echo -e "\033[31m Let's Encrypt SSL certificate can only be applied using port 80, other ports cannot be applied.\033[0m"
fi
}
# Modify the management interface access port
MODIFY_HTTPS_PORT() {
NEW_PORT="$2"
if [ -z "${NEW_PORT}" ]; then
read -p "Please enter the new BillionMail management port: " NEW_PORT
fi
# Verify that the input is a number
if ! echo "${NEW_PORT}" | grep -qE '^[0-9]+$' || ((NEW_PORT < 1 || NEW_PORT > 65535)); then
echo -e "\033[31m Error: The port number must be a number between 1-65535 \033[0m"
exit 1
fi
Check_Port=$(ss -tlnp | grep -E ":(${NEW_PORT})\b")
if [ ! -z "${Check_Port}" ]; then
echo "${Check_Port}"
echo -e "\033[31m Error: The ${NEW_PORT} port is already in use. \033[0m"
exit 1
fi
# Perform modification
sed -i 's/^HTTPS_PORT=.*/HTTPS_PORT='"${NEW_PORT}"'/' .env
if [ $? -ne 0 ]; then
echo -e "\033[31m Error: The BillionMail management port modification failed! \033[0m"
exit 1
fi
echo -e "The BillionMail management port has been modified to: ${NEW_PORT} \n Rebuild the container, please wait..."
sleep 3
# Find the container ID of the core image in the current project and rebuild the container
# CONTAINER_ID=$(${DOCKER_COMPOSE} ps -a --format "{{.ID}} {{.Image}}" |grep "/core:" | awk '{print $1}' )
CONTAINER="core"
GET_CONTAINER_ID ${CONTAINER}
if [ "${CONTAINER_ID}" ]; then
echo "Rebuilding Manage Container..."
docker stop ${CONTAINER_ID}
docker rm -f ${CONTAINER_ID}
${DOCKER_COMPOSE} up -d
else
echo "The "core" container does not exist"
echo "Starting BillionMail..."
${DOCKER_COMPOSE} up -d
fi
if [ -f "/usr/sbin/ufw" ]; then
/usr/sbin/ufw allow ${NEW_PORT}/tcp >/dev/null 2>&1
/usr/sbin/ufw reload
elif [ -f "/usr/sbin/firewall-cmd" ]; then
/usr/sbin/firewall-cmd --permanent --zone=public --add-port=${NEW_PORT}/tcp >/dev/null 2>&1
/usr/sbin/firewall-cmd --reload
elif [ -f "/etc/sysconfig/iptables" ]; then
iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport ${NEW_PORT} -j ACCEPT
service iptables save
fi
# Display login information
bash bm.sh default
}
# Modify time zone
MODIFY_TZ() {
if [ -a /etc/timezone ]; then
SYSTEM_TIME_ZONE=$(cat /etc/timezone)
elif [ -a /etc/localtime ]; then
SYSTEM_TIME_ZONE=$(readlink /etc/localtime|sed -n 's|^.*zoneinfo/||p')
fi
NEW_TZ="$2"
echo -e ""
echo -e "See https://en.wikipedia.org/wiki/List_of_tz_database_time_zones for a list of timezones"
echo -e "Use a column named "TZ identifier" + note the column named "Notes""
echo -e "Please enter your time zone"
echo -e ""
if [ -z "${SYSTEM_TIME_ZONE}" ]; then
read -p "Timezone: " -e NEW_TZ
else
read -p "Timezone [${SYSTEM_TIME_ZONE}]: " -e NEW_TZ
[ -z "${NEW_TZ}" ] && NEW_TZ=${SYSTEM_TIME_ZONE}
fi
if [ -z "${NEW_TZ}" ]; then
echo -e "\033[31m Error: Please enter the time zone \033[0m"
exit 1
fi
# Perform modification
sed -i "s|^TZ=.*|TZ=${NEW_TZ}|" .env
if [ $? -ne 0 ]; then
echo -e "\033[31m Error: The BillionMail time zone modification failed! \033[0m"
exit 1
fi
if [ -f "postgresql-data/postgresql.conf" ]; then
cp -arpf postgresql-data/postgresql.conf postgresql-data/postgresql.conf_${time}
sed -i "s|^log_timezone = .*|log_timezone = \'${NEW_TZ}\'|" postgresql-data/postgresql.conf
sed -i "s|^timezone = .*|timezone = \'${NEW_TZ}\'|" postgresql-data/postgresql.conf
fi
echo -e "The BillionMail time zone has been modified to: ${NEW_TZ} \n Rebuild the container, please wait..."
sleep 3
${DOCKER_COMPOSE} down
${DOCKER_COMPOSE} up -d
}
# Modify Admin Username
MODIFY_ADMIN_USERNAME() {
NEW_ADMIN="$2"
if [ -z "${NEW_ADMIN}" ]; then
read -p "Please enter the new BillionMail administrator username (minimum 5 characters): " NEW_ADMIN
fi
if [ -z "${NEW_ADMIN}" ]; then
echo -e "\033[31mError: Administrator username is required!\033[0m"
exit 1
fi
if [ ${#NEW_ADMIN} -lt 5 ]; then
echo -e "\033[31mError: Username must be at least 5 characters long!\033[0m"
exit 1
fi
if ! [[ "${NEW_ADMIN}" =~ ^[a-zA-Z0-9@#_.!+-]+$ ]]; then
echo -e "\033[31mError: Username can only contain letters, numbers, symbols: @ # _ - + . !\033[0m"
exit 1
fi
# Perform modification
sed -i "s|^ADMIN_USERNAME=.*|ADMIN_USERNAME="${NEW_ADMIN}"|" .env
if [ $? -ne 0 ]; then
echo -e "\033[31mError: Failed to update BillionMail administrator username!\033[0m"
exit 1
fi
echo -e "BillionMail administrator username has been updated. Restarting container, please wait..."
sleep 3
# Find the container ID of the core image in the current project and rebuild the container
# CONTAINER_ID=$(${DOCKER_COMPOSE} ps -a --format "{{.ID}} {{.Image}}" |grep "/core:" | awk '{print $1}' )
CONTAINER="core"
GET_CONTAINER_ID ${CONTAINER}
if [ "${CONTAINER_ID}" ]; then
echo "Restarting Manage Container..."
docker restart ${CONTAINER_ID}
else
echo "The "core" container does not exist"
echo "Starting BillionMail..."
${DOCKER_COMPOSE} up -d
fi
# Display login information
bash bm.sh default
}
# Modify Admin Password
MODIFY_ADMIN_PASSWORD() {
NEW_PASSWORD="$2"
if [ -z "${NEW_PASSWORD}" ]; then
read -p "Please enter the new BillionMail administrator password (minimum 5 characters): " NEW_PASSWORD
fi
if [ -z "${NEW_PASSWORD}" ]; then
echo -e "\033[31mError: Administrator password is required!\033[0m"
exit 1
fi
if [ ${#NEW_PASSWORD} -lt 5 ]; then
echo -e "\033[31mError: Password must be at least 5 characters long!\033[0m"
exit 1
fi
if ! [[ "${NEW_PASSWORD}" =~ ^[a-zA-Z0-9@#_.!+-]+$ ]]; then
echo -e "\033[31mError: Password can only contain letters, numbers, symbols: @ # _ - + . !\033[0m"
exit 1
fi
# Perform modification
sed -i "s|^ADMIN_PASSWORD=.*|ADMIN_PASSWORD="${NEW_PASSWORD}"|" .env
if [ $? -ne 0 ]; then
echo -e "\033[31mError: Failed to update BillionMail administrator password!\033[0m"
exit 1
fi
echo -e "BillionMail administrator password has been updated. Restarting container, please wait..."
sleep 3
# Find the container ID of the core image in the current project and rebuild the container
#CONTAINER_ID=$(${DOCKER_COMPOSE} ps -a --format "{{.ID}} {{.Image}}" |grep "/core:" | awk '{print $1}' )
CONTAINER="core"
GET_CONTAINER_ID ${CONTAINER}
if [ "${CONTAINER_ID}" ]; then
echo "Restarting Manage Container..."
docker restart ${CONTAINER_ID}
else
echo "The "core" container does not exist"
echo "Starting BillionMail..."
${DOCKER_COMPOSE} up -d
fi
# Display login information
bash bm.sh default
}
# Modify Safe entrance
MODIFY_SAFE_ENTRANCE() {
NEW_ENTRANCE="$2"
if [ -z "${NEW_ENTRANCE}" ]; then
read -p "Please enter the new BillionMail security entrance path (minimum 5 characters): " NEW_ENTRANCE
fi
if [ -z "${NEW_ENTRANCE}" ]; then
echo -e "\033[31mError: Security entrance path is required!\033[0m"
exit 1
fi
if [ ${#NEW_ENTRANCE} -lt 5 ]; then
echo -e "\033[31mError: Security entrance path must be at least 5 characters long!\033[0m"
exit 1
fi
if ! [[ "${NEW_ENTRANCE}" =~ ^[a-zA-Z0-9]+$ ]]; then
echo -e "\033[31mError: Security entrance path can only contain letters and numbers!\033[0m"
exit 1
fi
# Perform modification
sed -i "s|^SafePath=.*|SafePath=${NEW_ENTRANCE}|" .env
if [ $? -ne 0 ]; then
echo -e "\033[31mError: Failed to update BillionMail security entrance path!\033[0m"
exit 1
fi
echo -e "BillionMail security entrance path has been updated. Restarting container, please wait..."
sleep 3
# Find the container ID of the core image in the current project and rebuild the container
# CONTAINER_ID=$(${DOCKER_COMPOSE} ps -a --format "{{.ID}} {{.Image}}" |grep "/core:" | awk '{print $1}' )
CONTAINER="core"
GET_CONTAINER_ID ${CONTAINER}
if [ "${CONTAINER_ID}" ]; then
echo "Restarting Manage Container..."
docker restart ${CONTAINER_ID}
else
echo "The "core" container does not exist"
echo "Starting BillionMail..."
${DOCKER_COMPOSE} up -d
fi
# Display login information
bash bm.sh default
}
# Rebuild the BillionMail project
REBUILD_PROJECT() {
echo "Rebuilding BillionMail..."
echo -e "\033[31mWarning: This operation will rebuild all containers, service will be unavailable during the rebuild process. \033[0m"
read -p "Are you sure you want to continue? (yes/no): " NEW_REBUILD
if [[ "$NEW_REBUILD" =~ ^(yes|y|Y)$ ]]; then
sleep 3
${DOCKER_COMPOSE} down
${DOCKER_COMPOSE} up -d
echo "Rebuild completed."
else
echo "Rebuild cancel."
fi
}
# Restart the BillionMail project
RESTART_PROJECT() {
echo "Restarting BillionMail..."
sleep 1
${DOCKER_COMPOSE} restart
}
# Stop the BillionMail project
STOP_PROJECT() {
echo "Stop BillionMail..."
sleep 1
${DOCKER_COMPOSE} stop
}
START_PROJECT() {
echo "Start BillionMail..."
sleep 1
${DOCKER_COMPOSE} up -d
}
DOWN_PROJECT() {
echo "Stop all BillionMail services and delete all BillionMail containers..."
sleep 3
${DOCKER_COMPOSE} down
}
# Restart the specified service
RESTART_SERVICE() {
SERVICE="$2"
if [ -z "${SERVICE}" ]; then
echo ""
echo "Support input: postfix|core|dovecot|rspamd|redis|webmail|pgsql"
read -p "Please enter service: " SERVICE
fi
GET_SERVICE_NAME ${SERVICE}
echo "Restarting ${SERVICE} service..."
sleep 3
${DOCKER_COMPOSE} restart ${SERVICE_NAME}
}
RESTART_SERVICE_ADMIN() {
SERVICE="core"
GET_SERVICE_NAME ${SERVICE}
echo "Restarting ${SERVICE} service..."
sleep 3
${DOCKER_COMPOSE} restart ${SERVICE_NAME}
}
# Get container log
GET_CONTAINER_LOG() {
CONTAINER="$2"
if [ -z "${CONTAINER}" ]; then
echo ""
echo "Support input: postfix|core|dovecot|rspamd|redis|webmail|pgsql"
read -p "Please enter container: " CONTAINER
fi
log_num="$3"
follow=""
if [ "$log_num" == "-f" ]; then
follow="-f"
log_num="$4"
elif [ "$4" == "-f" ]; then
follow="-f"
fi
if [[ "$log_num" =~ ^[0-9]+$ ]]; then
log_num="${log_num}"
else
log_num=25
fi
GET_CONTAINER_ID ${CONTAINER}
if [ -z "${CONTAINER_ID}" ]; then
Red_Error "ERROR: The "${CONTAINER}" container does not exist, Please execute '${DOCKER_COMPOSE} up -d' to start BillionMail"
fi
docker logs ${follow} --tail="${log_num}" ${CONTAINER_ID}
}
# Get file log
GET_FILE_LOG() {
NAME_FILE="$2"
if [ -z "${NAME_FILE}" ]; then
echo ""
echo "Support input: postfix|core|core-access|core-error|dovecot|rspamd|fail2ban"
read -p "Please enter name: " NAME_FILE
fi
log_num="$3"
follow=""
if [ "$log_num" == "-f" ]; then
follow="-f"
log_num="$4"
elif [ "$4" == "-f" ]; then
follow="-f"
fi
if [[ "$log_num" =~ ^[0-9]+$ ]]; then
log_num="${log_num}"
else
log_num=25
fi