浏览代码

Change exim relay when changing network

Bob Mottram 8 年前
父节点
当前提交
84adebc17b
共有 2 个文件被更改,包括 20 次插入4 次删除
  1. 17
    4
      src/freedombone-base-email
  2. 3
    0
      src/freedombone-controlpanel

+ 17
- 4
src/freedombone-base-email 查看文件

804
     echo "dc_readhost=''" >> /etc/exim4/update-exim4.conf.conf
804
     echo "dc_readhost=''" >> /etc/exim4/update-exim4.conf.conf
805
     echo "dc_relay_domains=''" >> /etc/exim4/update-exim4.conf.conf
805
     echo "dc_relay_domains=''" >> /etc/exim4/update-exim4.conf.conf
806
     echo "dc_minimaldns='false'" >> /etc/exim4/update-exim4.conf.conf
806
     echo "dc_minimaldns='false'" >> /etc/exim4/update-exim4.conf.conf
807
-    RELAY_NETS='192.168.1.0/24'
807
+    IPv4_address=$(get_ipv4_address)
808
+    IPv4_address_base=$(echo "$IPv4_address" | awk -F '.' '{print $1"."$2"."$3}')
809
+    RELAY_NETS="${IPv4_address_base}.0/24"
808
     if [ $LOCAL_NETWORK_STATIC_IP_ADDRESS ]; then
810
     if [ $LOCAL_NETWORK_STATIC_IP_ADDRESS ]; then
809
         RELAY_NETS=$(echo $LOCAL_NETWORK_STATIC_IP_ADDRESS | awk -F '.' '{print $1 "." $2 "." $3 ".0/24"}')
811
         RELAY_NETS=$(echo $LOCAL_NETWORK_STATIC_IP_ADDRESS | awk -F '.' '{print $1 "." $2 "." $3 ".0/24"}')
810
     fi
812
     fi
832
 
834
 
833
     sed -i '/login_saslauthd_server/,/.endif/ s/# *//' /etc/exim4/exim4.conf.template
835
     sed -i '/login_saslauthd_server/,/.endif/ s/# *//' /etc/exim4/exim4.conf.template
834
     if ! grep -q "MAIN_TLS_ENABLE = true" /etc/exim4/exim4.conf.template; then
836
     if ! grep -q "MAIN_TLS_ENABLE = true" /etc/exim4/exim4.conf.template; then
835
-        sed -i "/.ifdef MAIN_HARDCODE_PRIMARY_HOSTNAME/i\MAIN_HARDCODE_PRIMARY_HOSTNAME = $DEFAULT_DOMAIN_NAME\nMAIN_TLS_ENABLE = true" /etc/exim4/exim4.conf.template
837
+        sed -i "/.ifdef MAIN_HARDCODE_PRIMARY_HOSTNAME/i\MAIN_HARDCODE_PRIMARY_HOSTNAME =\nMAIN_TLS_ENABLE = true" /etc/exim4/exim4.conf.template
836
     else
838
     else
837
-        sed -i "s|MAIN_HARDCODE_PRIMARY_HOSTNAME =.*|MAIN_HARDCODE_PRIMARY_HOSTNAME = $DEFAULT_DOMAIN_NAME|g" /etc/exim4/exim4.conf.template
839
+        sed -i "s|MAIN_HARDCODE_PRIMARY_HOSTNAME =.*|MAIN_HARDCODE_PRIMARY_HOSTNAME =|g" /etc/exim4/exim4.conf.template
838
     fi
840
     fi
839
     sed -i "s|SMTPLISTENEROPTIONS=''|SMTPLISTENEROPTIONS='-oX 465:25:587 -oP /var/run/exim4/exim.pid'|g" /etc/default/exim4
841
     sed -i "s|SMTPLISTENEROPTIONS=''|SMTPLISTENEROPTIONS='-oX 465:25:587 -oP /var/run/exim4/exim.pid'|g" /etc/default/exim4
840
     if ! grep -q "tls_on_connect_ports=465" /etc/exim4/exim4.conf.template; then
842
     if ! grep -q "tls_on_connect_ports=465" /etc/exim4/exim4.conf.template; then
847
     adduser $MY_USERNAME sasl
849
     adduser $MY_USERNAME sasl
848
     addgroup Debian-exim sasl
850
     addgroup Debian-exim sasl
849
     systemctl restart exim4
851
     systemctl restart exim4
852
+    if [ ! -d /etc/skel/log ]; then
853
+        mkdir -m 700 /etc/skel/log
854
+    fi
850
     if [ ! -d /etc/skel/Maildir ]; then
855
     if [ ! -d /etc/skel/Maildir ]; then
851
         mkdir -m 700 /etc/skel/.mutt
856
         mkdir -m 700 /etc/skel/.mutt
852
         mkdir -m 700 /etc/skel/Maildir
857
         mkdir -m 700 /etc/skel/Maildir
897
     mark_completed $FUNCNAME
902
     mark_completed $FUNCNAME
898
 }
903
 }
899
 
904
 
905
+function email_change_relay {
906
+    curr_ip_address="$1"
907
+    email_relay_base=$(echo "$curr_ip_address" | awk -F '.' '{print $1"."$2"."$3}')
908
+    RELAY_NETS="${email_relay_base}.0/24"
909
+    sed -i "s|dc_relay_nets=.*|dc_relay_nets='$RELAY_NETS'|g" /etc/exim4/update-exim4.conf.conf
910
+    dpkg-reconfigure --frontend noninteractive exim4-config
911
+}
912
+
900
 function create_procmail {
913
 function create_procmail {
901
     if [ ! -d /etc/exim4 ]; then
914
     if [ ! -d /etc/exim4 ]; then
902
         return
915
         return
1094
     # this must be accessible by root
1107
     # this must be accessible by root
1095
     chown -R $MY_USERNAME:root /home/$MY_USERNAME/.spamassassin
1108
     chown -R $MY_USERNAME:root /home/$MY_USERNAME/.spamassassin
1096
 
1109
 
1097
-    systemctl restart spamassassin
1110
+    systemctl start spamassassin
1098
     systemctl restart exim4
1111
     systemctl restart exim4
1099
     systemctl restart cron
1112
     systemctl restart cron
1100
 
1113
 

+ 3
- 0
src/freedombone-controlpanel 查看文件

1344
             write_config_param "NETWORK_IS_STATIC" "1"
1344
             write_config_param "NETWORK_IS_STATIC" "1"
1345
             write_config_param "STATIC_IP_ADDRESS" "$NEW_STATIC_IP"
1345
             write_config_param "STATIC_IP_ADDRESS" "$NEW_STATIC_IP"
1346
             write_config_param "ROUTER_IP_ADDRESS" "$NEW_STATIC_GATEWAY"
1346
             write_config_param "ROUTER_IP_ADDRESS" "$NEW_STATIC_GATEWAY"
1347
+
1348
+            email_change_relay "$NEW_STATIC_IP"
1349
+
1347
             if [[ $(config_param_exists "WIFI_INTERFACE") == "0" ]]; then
1350
             if [[ $(config_param_exists "WIFI_INTERFACE") == "0" ]]; then
1348
                 # wired network
1351
                 # wired network
1349
                 echo '# This file describes the network interfaces available on your system' > /etc/network/interfaces
1352
                 echo '# This file describes the network interfaces available on your system' > /etc/network/interfaces