Просмотр исходного кода

- Added new v-script 'v-change-sys-ip-helo Ip Helo'
to be able to change HELO/SMTP Banner

- Added ability to change HELO/SMTP Banner
from add/edit ip screens

- Added preliminary support for RHEL.

cmstew 5 лет назад
Родитель
Сommit
bd75b5e9f7

+ 0 - 17
bin/v-add-mail-domain

@@ -104,23 +104,6 @@ if [[ "$MAIL_SYSTEM" =~ exim ]]; then
         echo "$local_ip" > $HOMEDIR/$user/conf/mail/$domain/ip
     fi
 
-    # Touch mailhelo.conf if it doesnt exist
-    if [ ! -f "/etc/exim4/mailhelo.conf" ]; then
-        touch /etc/exim4/mailhelo.conf
-    fi
-
-    # Setting HELO for mail domain
-    if [ ! -z "$local_ip" ]; then
-        IP_RDNS=$(is_ip_rdns_valid "$local_ip")
-        if [ ! -z "$IP_RDNS" ]; then
-            if [ $(grep -s "^${domain}:" /etc/exim4/mailhelo.conf) ]; then
-                sed -i "/^${domain}:/c\\${domain}:${IP_RDNS}" /etc/exim4/mailhelo.conf
-            else
-                echo ${domain}:${IP_RDNS} >> /etc/exim4/mailhelo.conf
-            fi
-        fi        
-    fi
-
     # Adding antispam protection
     if [ "$antispam" = 'yes' ]; then
         touch $HOMEDIR/$user/conf/mail/$domain/antispam

+ 10 - 3
bin/v-add-sys-ip

@@ -1,7 +1,7 @@
 #!/bin/bash
 # info: add system ip address
-# options: IP NETMASK [INTERFACE] [USER] [IP_STATUS] [IP_NAME] [NAT_IP]
-# labels: 
+# options: IP NETMASK [INTERFACE] [USER] [IP_STATUS] [IP_NAME] [NAT_IP] [HELO]
+# labels:
 #
 # example: v-add-sys-ip 216.239.32.21 255.255.255.0
 #
@@ -28,6 +28,7 @@ user="${4-admin}"
 ip_status="${5-shared}"
 ip_name=$6
 nat_ip=$7
+helo=$8
 
 # Includes
 source $HESTIA/func/main.sh
@@ -40,7 +41,7 @@ source $HESTIA/conf/hestia.conf
 #                    Verifications                         #
 #----------------------------------------------------------#
 
-check_args '2' "$#" 'IP NETMASK [INTERFACE] [USER] [STATUS] [NAME] [NATED_IP]'
+check_args '2' "$#" 'IP NETMASK [INTERFACE] [USER] [STATUS] [NAME] [NATED_IP] [HELO]'
 is_format_valid 'ip' 'netmask' 'interface' 'user' 'ip_status'
 is_ip_free
 is_object_valid 'user' 'USER' "$user"
@@ -112,6 +113,7 @@ U_WEB_DOMAINS='0'
 INTERFACE='$iface'
 NETMASK='$netmask'
 NAT='$nat_ip'
+HELO='$helo'
 TIME='$time'
 DATE='$date'" > $HESTIA/data/ips/$ip
 chmod 660 $HESTIA/data/ips/$ip
@@ -213,6 +215,11 @@ if [ ! -z "$FIREWALL_SYSTEM" ]; then
     $BIN/v-update-firewall
 fi
 
+# Update ip helo for exim
+if [ ! -z "$MAIL_SYSTEM" ] && [ ! -z "$helo"]; then
+    $BIN/v-change-sys-ip-helo $ip $helo
+fi
+
 # Logging
 log_history "added system ip address $ip" '' 'admin'
 log_event "$OK" "$ARGUMENTS"

+ 5 - 0
bin/v-change-sys-hostname

@@ -51,6 +51,11 @@ else
     echo "$domain" > /etc/hostname
 fi
 
+# Update ip helo for exim
+if [ ! -z "$MAIL_SYSTEM" ]; then
+    pub_ip=$(curl --ipv4 -s https://ip.hestiacp.com/)
+    $BIN/v-change-sys-ip-helo $pub_ip $domain
+fi
 
 #----------------------------------------------------------#
 #                       Hestia                             #

+ 54 - 0
bin/v-change-sys-ip-helo

@@ -0,0 +1,54 @@
+#!/bin/bash
+# info: change ip HELO/SMTP Banner
+# options: IP HELO
+#
+# The function for changing HELO/SMTP Banner associated with ip.
+
+
+#----------------------------------------------------------#
+#                    Variable&Function                     #
+#----------------------------------------------------------#
+
+# Argument definition
+ip=$1
+helo=$2
+
+# Includes
+source $HESTIA/func/main.sh
+source $HESTIA/func/ip.sh
+source $HESTIA/conf/hestia.conf
+
+# Check if mail system is installed
+if [ -z "$MAIL_SYSTEM" ]; then
+    check_result "$E_NOTEXIST" "Mail system not installed"
+fi
+
+#----------------------------------------------------------#
+#                    Verifications                         #
+#----------------------------------------------------------#
+
+check_args '2' "$#" 'IP HELO'
+is_format_valid 'ip'
+is_format_valid 'helo'
+is_ip_valid "$ip"
+
+# Perform verification if read-only mode is enabled
+check_hestia_demo_mode
+
+
+#----------------------------------------------------------#
+#                       Action                             #
+#----------------------------------------------------------#
+
+# Change ip HELO/SMTP Banner
+update_ip_helo_value $ip $helo
+
+#----------------------------------------------------------#
+#                       Hestia                             #
+#----------------------------------------------------------#
+
+# Logging
+log_history "changed associated HELO/SMTP Banner on $ip to $helo" '' 'admin'
+log_event "$OK" "$ARGUMENTS"
+
+exit

+ 0 - 3
bin/v-delete-mail-domain

@@ -86,9 +86,6 @@ rm -f $USER_DATA/mail/$domain.pem
 rm -f $USER_DATA/mail/$domain.pub
 rm -f $USER_DATA/mail/*@$domain.msg
 
-# Unsetting HELO for mail domain
-sed -i "/^${domain}:/d" /etc/exim4/mailhelo.conf
-
 # Decreasing domain value
 decrease_user_value "$user" '$U_MAIL_DOMAINS'
 if [ "$DKIM" = 'yes' ]; then

+ 5 - 3
bin/v-list-sys-ip

@@ -32,6 +32,7 @@ json_list() {
         "INTERFACE": "'$INTERFACE'",
         "NETMASK": "'$NETMASK'",
         "NAT": "'$NAT'",
+        "HELO": "'$HELO'",
         "TIME": "'$TIME'",
         "DATE": "'$DATE'"
         }'
@@ -49,6 +50,7 @@ shell_list() {
     echo "NAME:           $NAME"
     echo "USERS:          $U_SYS_USERS"
     echo "DOMAINS:        $U_WEB_DOMAINS"
+    echo "HELO:           $HELO"
     echo "TIME:           $TIME"
     echo "DATE:           $DATE"
 }
@@ -56,15 +58,15 @@ shell_list() {
 # PLAIN list function
 plain_list() {
     echo -ne "$IP\t$OWNER\t$STATUS\t$NAME\t$U_SYS_USERS\t$U_WEB_DOMAINS\t"
-    echo -e "$INTERFACE\t$NETMASK\t$NAT\t$TIME\t$DATE"
+    echo -e "$INTERFACE\t$NETMASK\t$NAT\t$HELO\t$TIME\t$DATE"
 }
 
 # CSV list function
 csv_list() {
     echo -n "IP,OWNER,STATUS,NAME,U_SYS_USERS,U_WEB_DOMAINS,INTERFACE"
-    echo "NETMASK,NAT,TIME,DATE"
+    echo "NETMASK,NAT,HELO,TIME,DATE"
     echo -n "$IP,$OWNER,$STATUS,$NAME,\"$U_SYS_USERS\",$U_WEB_DOMAINS,"
-    echo "$INTERFACE, $NETMASK,$NAT,$TIME,$DATE"
+    echo "$INTERFACE, $NETMASK,$NAT,$HELO,$TIME,$DATE"
 }
 
 

+ 7 - 6
bin/v-list-sys-ips

@@ -34,6 +34,7 @@ json_list() {
         "INTERFACE": "'$INTERFACE'",
         "NETMASK": "'$NETMASK'",
         "NAT": "'$NAT'",
+        "HELO": "'$HELO'",
         "TIME": "'$TIME'",
         "DATE": "'$DATE'"
         }'
@@ -49,14 +50,14 @@ json_list() {
 
 # SHELL list function
 shell_list() {
-    echo "IP   MASK   NAT   STATUS   WEB  DATE"
-    echo "--   ----   ---   ------   ---  ----"
+    echo "IP   MASK   NAT    HELO    STATUS   WEB  DATE"
+    echo "--   ----   ---    ----    ------   ---  ----"
     while read IP; do
         source $HESTIA/data/ips/$IP
         if [ -z "$NAT" ]; then
             NAT='no'
         fi
-        echo "$IP $NETMASK $NAT $STATUS $U_WEB_DOMAINS $DATE"
+        echo "$IP $NETMASK $NAT $HELO $STATUS $U_WEB_DOMAINS $DATE"
     done < <(ls $HESTIA/data/ips/)
 }
 
@@ -65,18 +66,18 @@ plain_list() {
     while read IP; do
         source $HESTIA/data/ips/$IP
         echo -ne "$IP\t$OWNER\t$STATUS\t$NAME\t$U_SYS_USERS\t$U_WEB_DOMAINS\t"
-        echo -e "$INTERFACE\t$NETMASK\t$NAT\t$TIME\t$DATE"
+        echo -e "$INTERFACE\t$NETMASK\t$NAT\t$HELO\t$TIME\t$DATE"
     done < <(ls $HESTIA/data/ips/)
 }
 
 # CSV list function
 csv_list() {
     echo -n "IP,OWNER,STATUS,NAME,U_SYS_USERS,U_WEB_DOMAINS,INTERFACE"
-    echo "NETMASK,NAT,TIME,DATE"
+    echo "NETMASK,NAT,HELO,TIME,DATE"
     while read IP; do
         source $HESTIA/data/ips/$IP
         echo -n "$IP,$OWNER,$STATUS,$NAME,\"$U_SYS_USERS\",$U_WEB_DOMAINS,"
-        echo "$INTERFACE, $NETMASK,$NAT,$TIME,$DATE"
+        echo "$INTERFACE, $NETMASK,$NAT,$HELO,$TIME,$DATE"
     done < <(ls $HESTIA/data/ips/)
 }
 

+ 8 - 0
bin/v-update-sys-ip

@@ -125,6 +125,14 @@ if [ ! -e "$HESTIA/data/ips/$pub_ip" ]; then
     fi
 fi
 
+# Update ip helo for exim
+if [ ! -z "$MAIL_SYSTEM" ]; then
+    helo=$(is_ip_rdns_valid $pub_ip)
+
+    if [ ! -z "$helo" ]; then
+        $BIN/v-change-sys-ip-helo $ip $helo
+    fi
+fi
 
 #----------------------------------------------------------#
 #                       Hestia                             #

+ 29 - 0
func/ip.sh

@@ -43,6 +43,35 @@ is_ip_rdns_valid() {
     return 1 # False
 }
 
+# Update ip helo for exim
+update_ip_helo_value() {
+    ip="$1"
+    helo="$2"
+
+    # Create or update ip value
+    if [ ! $(get_ip_value '$HELO') ]; then
+        echo "HELO='$helo'" >> $HESTIA/data/ips/$ip
+    else
+        update_ip_value '$HELO' "$helo"
+    fi
+
+    # Create mailhelo.conf file if doesn't exist
+    if [ ! -e "/etc/${MAIL_SYSTEM}/mailhelo.conf" ]; then
+        touch /etc/${MAIL_SYSTEM}/mailhelo.conf
+    fi
+
+    #Create or update ip:helo pair in mailhelo.conf file
+    if [ ! -z "$helo" ]; then
+        if [ $(cat /etc/${MAIL_SYSTEM}/mailhelo.conf | grep "$ip") ]; then
+            sed -i "/^$ip:/c $ip:$helo" /etc/${MAIL_SYSTEM}/mailhelo.conf
+        else
+            echo $ip:$helo >> /etc/${MAIL_SYSTEM}/mailhelo.conf
+        fi
+    else
+        sed -i "/^$ip:/d" /etc/${MAIL_SYSTEM}/mailhelo.conf
+    fi
+}
+
 # Update ip address value
 update_ip_value() {
     key="$1"

+ 0 - 10
func/rebuild.sh

@@ -531,16 +531,6 @@ rebuild_mail_domain_conf() {
             echo "$local_ip" > $HOMEDIR/$user/conf/mail/$domain/ip
         fi
 
-        
-        # Setting HELO for mail domain
-        if [ ! -z "$local_ip" ]; then
-            IP_RDNS=$(is_ip_rdns_valid "$local_ip")
-            sed -i "/^${domain}:/d" /etc/exim4/mailhelo.conf >/dev/null 2>&1
-            if [ ! -z "$IP_RDNS" ]; then
-                echo ${domain}:${IP_RDNS} >> /etc/exim4/mailhelo.conf
-            fi
-        fi
-
         # Adding antispam protection
         if [ "$ANTISPAM" = 'yes' ]; then
             touch $HOMEDIR/$user/conf/mail/$domain/antispam

+ 2 - 1
install/deb/exim/exim4.conf.template

@@ -9,6 +9,7 @@
 #CLAMD = yes
 
 smtp_banner = $smtp_active_hostname
+smtp_active_hostname = ${if exists {/etc/exim4/mailhelo.conf}{${lookup{$interface_address}lsearch{/etc/exim4/mailhelo.conf}{$value}{$primary_hostname}}}{$primary_hostname}}
 add_environment = <; PATH=/bin:/usr/bin
 keep_environment =
 disable_ipv6 = true
@@ -325,7 +326,7 @@ begin transports
 
 remote_smtp:
   driver = smtp
-  helo_data = ${if exists {/etc/exim4/mailhelo.conf}{${lookup{$sender_address_domain}lsearch*{/etc/exim4/mailhelo.conf}{$value}{$primary_hostname}}}{$primary_hostname}}
+  helo_data = ${if exists {/etc/exim4/mailhelo.conf}{${lookup{$sending_ip_address}lsearch{/etc/exim4/mailhelo.conf}{$value}{$primary_hostname}}}{$primary_hostname}}
   dkim_domain = DKIM_DOMAIN
   dkim_selector = mail
   dkim_private_key = DKIM_PRIVATE_KEY

+ 0 - 22
install/upgrade/versions/1.3.1.sh

@@ -1,22 +0,0 @@
-#!/bin/sh
-
-# Hestia Control Panel upgrade script for target version 1.3.1
-
-#######################################################################################
-#######                      Place additional commands below.                   #######
-#######################################################################################
-
-# Remove duplicate values in U_SYS_USERS variable for ips
-for ip in $(ls $HESTIA/data/ips/); do
-    current_usr=$(grep "U_SYS_USERS=" $HESTIA/data/ips/$ip |cut -f 2 -d \')
-    
-    new_usr=$(echo "$current_usr" |\
-        sed "s/,/\n/g"|\
-        sort -u |\
-        sed ':a;N;$!ba;s/\n/,/g')
-
-    if [ ! -z "$new_usr" ]; then
-        sed -i "s/U_SYS_USERS='$current_usr'/U_SYS_USERS='$new_usr'/g" $HESTIA/data/ips/$ip
-    fi
-done
-

+ 29 - 1
install/upgrade/versions/1.3.3.sh

@@ -16,4 +16,32 @@ if [ -e "/etc/nginx/nginx.conf" ]; then
 fi
 
 echo '[*] Set Role "Admin" to Administrator'
-$HESTIA/bin/v-change-user-role admin admin
+$HESTIA/bin/v-change-user-role admin admin
+
+if [ "$MAIL_SYSTEM" == "exim4" ]; then
+    source $HESTIA/func/ip.sh
+
+    # Populating HELO/SMTP Banner for existing ip's
+    echo "[ * ] Populating HELO/SMTP Banner param for existing ip's..."
+    > /etc/exim4/mailhelo.conf
+
+    for ip in $(v-list-sys-ips plain | cut -f1); do
+        helo=$(is_ip_rdns_valid $ip)
+
+        if [ ! -z "$helo" ]; then
+            v-change-sys-ip-helo $ip $helo
+        fi
+    done
+
+
+    # Update exim configuration
+    echo "[ * ] Updating exim4 configuration..."
+
+    # Check if smtp_active_hostname exists before adding it
+    if [ ! 'grep -q ^smtp_active_hostname  /etc/exim4/exim4.conf.template' ]; then
+        sed -i '/^smtp_banner = \$smtp_active_hostname$/a smtp_active_hostname = ${if exists {\/etc\/exim4\/mailhelo.conf}{${lookup{$interface_address}lsearch{\/etc\/exim4\/mailhelo.conf}{$value}{$primary_hostname}}}{$primary_hostname}}"' /etc/exim4/exim4.conf.template
+    fi
+
+    sed -i 's/helo_data = \${if exists {\/etc\/exim4\/mailhelo.conf}{${lookup{\$sender_address_domain}lsearch\*{\/etc\/exim4\/mailhelo.conf}{\$value}{\$primary_hostname}}}{\$primary_hostname}}/helo_data = ${if exists {\/etc\/exim4\/mailhelo.conf}{${lookup{$sending_ip_address}lsearch{\/etc\/exim4\/mailhelo.conf}{$value}{$primary_hostname}}}{$primary_hostname}}/' /etc/exim4/exim4.conf.template
+
+fi

+ 3 - 1
web/add/ip/index.php

@@ -42,6 +42,7 @@ if (!empty($_POST['ok'])) {
     $v_netmask = escapeshellarg($_POST['v_netmask']);
     $v_name = escapeshellarg($_POST['v_name']);
     $v_nat = escapeshellarg($_POST['v_nat']);
+    $v_helo = escapeshellarg($_POST['v_helo']);
     $v_interface = escapeshellarg($_POST['v_interface']);
     $v_owner = escapeshellarg($_POST['v_owner']);
     $v_shared = $_POST['v_shared'];
@@ -57,7 +58,7 @@ if (!empty($_POST['ok'])) {
 
     // Add IP
     if (empty($_SESSION['error_msg'])) {
-        exec (HESTIA_CMD."v-add-sys-ip ".$v_ip." ".$v_netmask." ".$v_interface."  ".$v_owner." ".escapeshellarg($ip_status)." ".$v_name." ".$v_nat, $output, $return_var);
+        exec (HESTIA_CMD."v-add-sys-ip ".$v_ip." ".$v_netmask." ".$v_interface."  ".$v_owner." ".escapeshellarg($ip_status)." ".$v_name." ".$v_nat." ".$v_helo, $output, $return_var);
         check_return_code($return_var,$output);
         unset($output);
         $v_owner = $_POST['v_owner'];
@@ -71,6 +72,7 @@ if (!empty($_POST['ok'])) {
         unset($v_netmask);
         unset($v_name);
         unset($v_nat);
+        unset($v_helo);
     }
 }
 

+ 9 - 0
web/edit/ip/index.php

@@ -32,6 +32,7 @@ $v_netmask = $data[$v_ip]['NETMASK'];
 $v_interace = $data[$v_ip]['INTERFACE'];
 $v_name = $data[$v_ip]['NAME'];
 $v_nat = $data[$v_ip]['NAT'];
+$v_helo = $data[$v_ip]['HELO'];
 $v_ipstatus = $data[$v_ip]['STATUS'];
 if ($v_ipstatus == 'dedicated') $v_dedicated = 'yes';
 $v_owner = $data[$v_ip]['OWNER'];
@@ -99,6 +100,14 @@ if (!empty($_POST['save'])) {
         unset($output);
     }
 
+    // Change HELO/SMTP Banner address
+    if (($v_helo != $_POST['v_helo']) && (empty($_SESSION['error_msg']))) {
+        $v_helo = escapeshellarg($_POST['v_helo']);
+        exec (HESTIA_CMD."v-change-sys-ip-helo ".$v_ip." ".$v_helo, $output, $return_var);
+        check_return_code($return_var,$output);
+        unset($output);
+    }
+
     // Set success message
     if (empty($_SESSION['error_msg'])) {
         $_SESSION['ok_msg'] = _('Changes has been saved.');

+ 11 - 1
web/templates/admin/add_ip.html

@@ -138,10 +138,20 @@
                                     <input type="text" size="20" class="vst-input" name="v_nat" value="<?=htmlentities(trim($v_nat, "'"))?>">
                                 </td>
                             </tr>
+                            <tr style="<?php if ($_SESSION['MAIL_SYSTEM'] != 'exim4') { echo 'display: none;';}?>">
+                                <td class="vst-text input-label">
+                                    <?php print _('HELO/SMTP Banner');?> <span class="optional">(<?php print _('optional');?>)</span>
+                                </td>
+                            </tr>
+                            <tr style="<?php if ($_SESSION['MAIL_SYSTEM'] != 'exim4') { echo 'display: none;';}?>">
+                                <td>
+                                    <input type="text" size="20" class="vst-input" name="v_helo" value="<?=htmlentities(trim($v_helo, "'"))?>">
+                                </td>
+                            </tr>
                         </table>
                         <table class="data-col2"></table>
                     </td>
                 </tr>
             </table>
         </form>
-      </div>
+      </div>

+ 10 - 0
web/templates/admin/edit_ip.html

@@ -134,6 +134,16 @@
                                     <input type="text" size="20" class="vst-input" name="v_nat" value="<?=htmlentities(trim($v_nat, "'"))?>">
                                 </td>
                             </tr>
+                            <tr style="<?php if ($_SESSION['MAIL_SYSTEM'] != 'exim4') { echo 'display: none;';}?>">
+                                <td class="vst-text input-label">
+                                    <?php print _('HELO/SMTP Banner');?> <span class="optional">(<?php print _('optional');?>)</span>
+                                </td>
+                            </tr>
+                            <tr style="<?php if ($_SESSION['MAIL_SYSTEM'] != 'exim4') { echo 'display: none;';}?>">
+                                <td>
+                                    <input type="text" size="20" class="vst-input" name="v_helo" value="<?=htmlentities(trim($v_helo, "'"))?>">
+                                </td>
+                            </tr>
                         </table>
                         <table class="data-col2"></table>
                     </td>