Ernesto Nicolás Carrea 5 tahun lalu
induk
melakukan
9ed985bcb1

+ 23 - 0
bin/module/clamav/exim-integration/disable.inc

@@ -0,0 +1,23 @@
+#!/bin/sh
+
+hestia_module_clamav_setup-exim() {
+    source $HESTIA/bin/module/func.inc
+
+    module_installed=$(hestia_module_isinstalled mta)
+    if [ ! "$module_installed" ] && [ ! "$param_force" ]; then
+        echo "MTA module is not installed. See 'hestia module info mta'."
+        exit 1
+    fi
+
+    module_variant=$(hestia_module_getvariant mta)
+    if [ "$module_variant" != 'exim' ] && [ ! "$param_force" ]; then
+        echo "The installed MTA module is not Exim. See 'hestia module info mta'."
+        exit 1
+    fi
+
+    echo "Disabling Exim-ClamAV integration..."
+
+    /usr/bin/sed -i "/CLAMD/ s/^/#/" $OSAL_PATH_EXIM_CONF/exim4.conf.template
+
+    # FIXME: how do we rebuild exim.conf? 
+}

+ 26 - 0
bin/module/clamav/exim-integration/enable.inc

@@ -0,0 +1,26 @@
+#!/bin/sh
+
+hestia_module_clamav_setup-exim() {
+    source $HESTIA/bin/module/func.inc
+
+    module_installed=$(hestia_module_isinstalled mta)
+    if [ ! "$module_installed" ] && [ ! "$param_force" ]; then
+        echo "MTA module is not installed. See 'hestia module info mta'."
+        exit 1
+    fi
+
+    module_variant=$(hestia_module_getvariant mta)
+    if [ "$module_variant" != 'exim' ] && [ ! "$param_force" ]; then
+        echo "The installed MTA module is not Exim. See 'hestia module info mta'."
+        exit 1
+    fi
+
+    echo "Enabling Exim-ClamAV integration..."
+
+    /usr/bin/sed -i "/CLAMD/ s/#*//" $OSAL_PATH_EXIM_CONF/exim4.conf.template
+
+    gpasswd -a clamav mail > /dev/null 2>&1
+    gpasswd -a clamav $OSAL_USER_EXIM > /dev/null 2>&1
+
+    # FIXME: how do we rebuild exim.conf? 
+}

+ 59 - 0
bin/module/clamav/install.inc

@@ -0,0 +1,59 @@
+#!/bin/sh
+
+hestia_module_clamav_install() {
+    source $HESTIA/bin/module/func.inc
+
+    module_installed=$(hestia_module_isinstalled antivirus)
+    if [ "$module_installed" ] && [ ! "$param_force" ]; then
+        echo "Antivirus module is already installed. See 'hestia module info antivirus'."
+        exit 1
+    fi
+
+    echo "Installing Antivirus (ClamAV) module..."
+
+    osal_service_stop $OSAL_SERVICE_CLAMAV
+    hestia_config_backup 'clamav-install' $OSAL_PATH_CLAMAV_CONF
+
+    osal_package_preinstall
+    osal_package_install $OSAL_PKG_CLAMAV
+
+    cp -f $HESTIA_INSTALL_DIR/clamav/clamd.conf $OSAL_PATH_CLAMAV_CONF
+
+    mkdir -p /var/log/clamav /var/run/clamav
+    chown -R clamav:clamav /var/log/clamav /var/run/clamav
+
+    if [ $OS_BASE = 'debian' ]; then
+        if [ -e "/lib/systemd/system/clamav-daemon.service" ]; then
+            exec_pre1='ExecStartPre=-/bin/mkdir -p /var/run/clamav'
+            exec_pre2='ExecStartPre=-/bin/chown -R clamav:clamav /var/run/clamav'
+            sed -i "s|\[Service\]/|[Service]\n$exec_pre1\n$exec_pre2|g" \
+                /lib/systemd/system/clamav-daemon.service
+            systemctl daemon-reload
+        fi
+    elif [ $OS_BASE = 'rhel' ]; then
+        useradd clamav -g clamupdate -s /sbin/nologin -d /var/lib/clamav 2>/dev/null
+        cp -f $HESTIA_INSTALL_DIR/clamav/freshclam.conf /etc/
+        chown clamav:clamupdate /var/log/clamav /var/run/clamav
+        chown -R clamav:clamupdate /var/lib/clamav
+        chmod 0775 /var/lib/clamav /var/log/clamav
+    fi
+
+    osal_execute_with_spinner /usr/bin/freshclam
+
+    exim_installed=$(hestia_module_variant_installed 'mta' 'exim')
+    if [ "$exim_installed" ]; then
+        hestia module clamav exim-integration enable
+    fi
+
+    osal_service_enable $OSAL_SERVICE_CLAMAV
+    osal_service_start $OSAL_SERVICE_CLAMAV
+    check_result $? "ClamAV start failed"
+
+    osal_kv_write $HESTIA/conf/hestia.conf 'ANTIVIRUS_SYSTEM' 'clamav-daemon'
+    osal_kv_write $HESTIA_CONF_MODULES/antivirus.conf 'installed' '1'
+    osal_kv_write $HESTIA_CONF_MODULES/antivirus.conf 'description' 'Hestia Antivirus (ClamAV) module'
+    osal_kv_write $HESTIA_CONF_MODULES/antivirus.conf 'enabled' '1'
+    osal_kv_write $HESTIA_CONF_MODULES/antivirus.conf 'variant' 'clamav'
+    osal_kv_write $HESTIA_CONF_MODULES/antivirus.conf 'version' '1'
+    osal_kv_write $HESTIA_CONF_MODULES/antivirus.conf 'service_name' $OSAL_SERVICE_CLAMAV
+}

+ 40 - 0
bin/module/clamav/remove.inc

@@ -0,0 +1,40 @@
+#!/bin/sh
+
+hestia_module_clamav_remove() {
+    source $HESTIA/bin/module/func.inc
+
+    module_installed=$(hestia_module_isinstalled mta)
+    if [ ! "$module_installed" ] && [ ! "$param_force" ]; then
+        echo "MTA module is not installed. See 'hestia module info mta'."
+        exit 1
+    fi
+
+    module_variant=$(hestia_module_getvariant mta)
+    if [ "$module_variant" != 'clamav' ] && [ ! "$param_force" ]; then
+        echo "The installed MTA module is not ClamAV. See 'hestia module info mta'."
+        exit 1
+    fi
+
+    echo "Removing MTA (ClamAV) module..."
+
+    osal_service_stop $OSAL_PKG_EXIM
+    osal_service_disable $OSAL_PKG_EXIM
+
+    hestia_config_backup 'clamav-remove' $OSAL_PATH_CLAMAV_CONF
+
+    exim_installed=$(hestia_module_variant_installed 'mta' 'exim')
+    if [ "$exim_installed" ]; then
+        hestia module clamav exim-integration disable
+    fi
+
+    osal_package_remove $OSAL_PKG_EXIM $OSAL_PKG_EXIM_DAEMON
+
+    osal_kv_write $HESTIA/conf/hestia.conf 'MAIL_SYSTEM' 'no'
+    osal_kv_write $HESTIA_CONF_MODULES/mta.conf 'installed' '0'
+    osal_kv_write $HESTIA_CONF_MODULES/mta.conf 'description' ''
+    osal_kv_write $HESTIA_CONF_MODULES/mta.conf 'enabled' '0'
+    osal_kv_write $HESTIA_CONF_MODULES/mta.conf 'variant' ''
+    osal_kv_write $HESTIA_CONF_MODULES/mta.conf 'version' '0'
+
+    exit 0
+}

+ 6 - 1
bin/module/exim/install.inc

@@ -15,7 +15,7 @@ hestia_module_exim_install() {
     hestia_config_backup 'exim-install' $OSAL_PATH_EXIM_CONF
     hestia_config_backup 'exim-install' $OSAL_PATH_EXIM_CONF
 
 
     osal_package_preinstall
     osal_package_preinstall
-    osal_package_install $OSAL_PKG_EXIM $OSAL_PKG_EXIM_DAEMON
+    osal_package_install $OSAL_PKG_EXIM
 
 
     gpasswd -a $OSAL_USER_EXIM mail > /dev/null 2>&1
     gpasswd -a $OSAL_USER_EXIM mail > /dev/null 2>&1
     cp -f $HESTIA_INSTALL_DIR/exim/${OSAL_PKG_EXIM}.conf.template $OSAL_PATH_EXIM_CONF/
     cp -f $HESTIA_INSTALL_DIR/exim/${OSAL_PKG_EXIM}.conf.template $OSAL_PATH_EXIM_CONF/
@@ -47,6 +47,11 @@ hestia_module_exim_install() {
     osal_service_start $OSAL_PKG_EXIM
     osal_service_start $OSAL_PKG_EXIM
     check_result $? "Exim start failed"
     check_result $? "Exim start failed"
 
 
+    clamav_installed=$(hestia_module_variant_installed 'antivirus' 'clamav')
+    if [ "$clamav_installed" ]; then
+        hestia module clamav exim-integration enable
+    fi
+
     osal_kv_write $HESTIA/conf/hestia.conf 'MAIL_SYSTEM' 'exim'
     osal_kv_write $HESTIA/conf/hestia.conf 'MAIL_SYSTEM' 'exim'
     osal_kv_write $HESTIA_CONF_MODULES/mta.conf 'installed' '1'
     osal_kv_write $HESTIA_CONF_MODULES/mta.conf 'installed' '1'
     osal_kv_write $HESTIA_CONF_MODULES/mta.conf 'description' 'Hestia MTA (Exim) module'
     osal_kv_write $HESTIA_CONF_MODULES/mta.conf 'description' 'Hestia MTA (Exim) module'

+ 1 - 1
bin/module/exim/remove.inc

@@ -22,7 +22,7 @@ hestia_module_exim_remove() {
 
 
     hestia_config_backup 'exim-remove' $OSAL_PATH_EXIM_CONF
     hestia_config_backup 'exim-remove' $OSAL_PATH_EXIM_CONF
 
 
-    osal_package_remove $OSAL_PKG_EXIM $OSAL_PKG_EXIM_DAEMON
+    osal_package_remove $OSAL_PKG_EXIM
 
 
     osal_kv_write $HESTIA/conf/hestia.conf 'MAIL_SYSTEM' 'no'
     osal_kv_write $HESTIA/conf/hestia.conf 'MAIL_SYSTEM' 'no'
     osal_kv_write $HESTIA_CONF_MODULES/mta.conf 'installed' '0'
     osal_kv_write $HESTIA_CONF_MODULES/mta.conf 'installed' '0'

+ 5 - 3
func/osal_debian_based.sh

@@ -8,6 +8,7 @@
 # Services
 # Services
 OSAL_SERVICE_APACHE=apache2
 OSAL_SERVICE_APACHE=apache2
 OSAL_SERVICE_BIND=bind9
 OSAL_SERVICE_BIND=bind9
+OSAL_SERVICE_CLAMAV=clamav-daemon
 OSAL_SERVICE_CRON=cron
 OSAL_SERVICE_CRON=cron
 
 
 # Users
 # Users
@@ -24,17 +25,18 @@ OSAL_CMD_PACKAGE_MANAGER=/usr/bin/apt-get
 OSAL_PKG_APACHE=apache2
 OSAL_PKG_APACHE=apache2
 OSAL_PKG_APACHE_MOD_RUID2=libapache2-mod-ruid2
 OSAL_PKG_APACHE_MOD_RUID2=libapache2-mod-ruid2
 OSAL_PKG_BIND=bind9
 OSAL_PKG_BIND=bind9
-OSAL_PKG_EXIM=exim4
-OSAL_PKG_EXIM_DAEMON=exim4-daemon-heavy
+OSAL_PKG_CLAMAV=clamav-daemon
+OSAL_PKG_EXIM=exim4 exim4-daemon-heavy
 OSAL_PKG_PHPMYADMIN=phpmyadmin
 OSAL_PKG_PHPMYADMIN=phpmyadmin
 OSAL_PKG_ROUNDCUBE=roundcube
 OSAL_PKG_ROUNDCUBE=roundcube
 
 
 # Paths
 # Paths
 OSAL_PATH_APACHE_CONF=/etc/apache2
 OSAL_PATH_APACHE_CONF=/etc/apache2
 OSAL_PATH_BIND_DATA=/var/cache/bind
 OSAL_PATH_BIND_DATA=/var/cache/bind
+OSAL_PATH_CLAMAV_CONF=/etc/clamav
 OSAL_PATH_EXIM_CONF=/etc/exim4
 OSAL_PATH_EXIM_CONF=/etc/exim4
 OSAL_PATH_ROUNDCUBE_INSTALL_MYSQL=/usr/share/dbconfig-common/data/roundcubemail/install/mysql
 OSAL_PATH_ROUNDCUBE_INSTALL_MYSQL=/usr/share/dbconfig-common/data/roundcubemail/install/mysql
-OSAL_PATH_VSFTPD_CONF=/etc
+OSAL_PATH_VSFTPD_CONF=/etc/vsftpd.conf
 
 
 #-------------------------------------------------------------------#
 #-------------------------------------------------------------------#
 # Functions                                                         #
 # Functions                                                         #

+ 4 - 2
func/osal_rhel_based.sh

@@ -8,6 +8,7 @@
 # Services
 # Services
 OSAL_SERVICE_APACHE=httpd
 OSAL_SERVICE_APACHE=httpd
 OSAL_SERVICE_BIND=named
 OSAL_SERVICE_BIND=named
+OSAL_SERVICE_CLAMAV=clamd
 OSAL_SERVICE_CRON=crond
 OSAL_SERVICE_CRON=crond
 
 
 # Users
 # Users
@@ -24,15 +25,16 @@ OSAL_CMD_PACKAGE_MANAGER=/usr/bin/dnf
 OSAL_PKG_APACHE=httpd
 OSAL_PKG_APACHE=httpd
 OSAL_PKG_APACHE_MOD_RUID2=mod_ruid2
 OSAL_PKG_APACHE_MOD_RUID2=mod_ruid2
 OSAL_PKG_BIND=bind
 OSAL_PKG_BIND=bind
+OSAL_PKG_CLAMAV=clamav clamav-update
 OSAL_PKG_EXIM=exim
 OSAL_PKG_EXIM=exim
-OSAL_PKG_EXIM_DAEMON=
 OSAL_PKG_PHPMYADMIN=phpMyAdmin
 OSAL_PKG_PHPMYADMIN=phpMyAdmin
 OSAL_PKG_ROUNDCUBE=roundcubemail
 OSAL_PKG_ROUNDCUBE=roundcubemail
 
 
 # Paths
 # Paths
 OSAL_PATH_APACHE_CONF=/etc/httpd
 OSAL_PATH_APACHE_CONF=/etc/httpd
 OSAL_PATH_BIND_DATA=/var/named
 OSAL_PATH_BIND_DATA=/var/named
-OSAL_PATH_EXIM_CONF=/etc/exim4
+OSAL_PATH_CLAMAV_CONF=/etc/clamd.conf /etc/clamd.d
+OSAL_PATH_EXIM_CONF=/etc/exim
 OSAL_PATH_ROUNDCUBE_INSTALL_MYSQL=/usr/share/roundcubemail/SQL/mysql
 OSAL_PATH_ROUNDCUBE_INSTALL_MYSQL=/usr/share/roundcubemail/SQL/mysql
 OSAL_PATH_VSFTPD_CONF=/etc/vsftpd
 OSAL_PATH_VSFTPD_CONF=/etc/vsftpd