Explorar o código

vsftpd sample

Ernesto Nicolás Carrea %!s(int64=5) %!d(string=hai) anos
pai
achega
5e8d97bf41

+ 4 - 0
bin/hestia

@@ -1,6 +1,10 @@
 #!/bin/sh
 
 HESTIA_BIN=$HESTIA/bin
+[ "$HESTIA_DEBUG" ] && OSAL_DEBUG=1
+source $HESTIA/func/osal.sh
+source $HESTIA/func/main.sh
+source $HESTIA/conf/hestia.conf
 
 # Search for command file
 cmd_name=''

+ 32 - 0
bin/module/func.inc

@@ -0,0 +1,32 @@
+#!/bin/sh
+
+# Returns 1 if module is installed
+hestia_module_isinstalled() {
+    osal_ini_get $HESTIA/conf/modules.conf $1 'installed' '1'
+}
+
+# Returns 1 if module is installed and enabled
+hestia_module_isenabled() {
+    is_installed=$(osal_ini_get $HESTIA/conf/modules.conf $1 'installed' '1')
+    is_enabled=$(osal_ini_get $HESTIA/conf/modules.conf $1 'enabled' '1')
+    if [[ "$is_installed" && "$is_enabled" ]]; then
+        echo 1
+    fi
+}
+
+hestia_module_getversion() {
+    osal_ini_get $HESTIA/conf/modules.conf $1 'version'
+}
+
+hestia_module_getvariant() {
+    osal_ini_get $HESTIA/conf/modules.conf $1 'variant'
+}
+
+# Backup config files (usually prior to module install)
+hestia_config_backup() {
+    dest=$HESTIA/data/backups/$1
+    shift
+
+    mkdir -p $dest
+    cp -f $@ $dest
+}

+ 26 - 0
bin/module/info.inc

@@ -0,0 +1,26 @@
+#!/bin/sh
+
+hestia_module_info() {
+    source $HESTIA/bin/module/func.inc
+
+    modulename=$1
+    echo "Module name     : $modulename"
+    
+    module_installed=$(hestia_module_isinstalled $modulename)
+    if [ "$module_installed" ]; then
+        module_enabled=$(hestia_module_isenabled $modulename)
+        module_variant=$(hestia_module_getvariant $modulename)
+        module_version=$(hestia_module_getversion $modulename)
+
+        echo "Installed       : Yes"
+        echo "Enabled         : $module_enabled"
+        echo "Variant         : $module_variant"
+        echo "Version         : $module_version"
+    else
+        echo "Installed       : No"
+    fi
+}
+
+# If this files is _not_ being sourced, act immediately
+# (otherise, wait for hestia cli to call the main function)
+[[ $_ == $0 ]] && hestia_module_info $@

+ 0 - 4
bin/module/install

@@ -1,4 +0,0 @@
-#!/bin/sh
-
-echo "Hestia module install $@"
-echo "Demo of 2-level commands"

+ 11 - 0
bin/module/list

@@ -0,0 +1,11 @@
+#!/bin/sh
+
+hestia_module_list() {
+    echo "Hestia web domain list $@"
+    echo "Demo of 3-level commands"
+    echo "This works as both Hestia CLI command and regular executable"
+}
+
+# If this files is _not_ being sourced, act immediately
+# (otherise, wait for hestia cli to call the main function)
+[[ $_ == $0 ]] && hestia_web_domain_list $@

+ 44 - 0
bin/module/vsftpd/install.inc

@@ -0,0 +1,44 @@
+#!/bin/sh
+
+hestia_module_vsftpd_install() {
+    source $HESTIA/bin/module/func.inc
+
+    ftp_installed=$(hestia_module_isinstalled ftp)
+    if [ "$ftp_installed" ]; then
+        echo "FTP module is already installed. See 'hestia module info ftp'."
+        exit 1
+    fi
+
+    echo "Installing FTP (vsftpd) module..."
+
+    osal_service_stop vsftpd
+    hestia_config_backup 'vsftpd' $OSAL_PATH_VSFTPD_CONF/vsftpd.conf
+
+    osal_package_preinstall
+    osal_package_install vsftpd
+    cp -f $HESTIA_INSTALL_DIR/vsftpd/vsftpd.conf $OSAL_PATH_VSFTPD_CONF/
+    touch /var/log/vsftpd.log
+    chown root:adm /var/log/vsftpd.log
+    chmod 640 /var/log/vsftpd.log
+    touch /var/log/xferlog
+    chown root:adm /var/log/xferlog
+    chmod 640 /var/log/xferlog
+    
+    osal_service_enable vsftpd
+    osal_service_start vsftpd
+
+    check_result $? "vsftpd start failed"
+
+    osal_ini_set $HESTIA/conf/hestia.conf '' 'FTP_SYSTEM' 'vsftpd'
+    osal_ini_set $HESTIA/conf/modules.conf 'ftp' 'installed' '1'
+    osal_ini_set $HESTIA/conf/modules.conf 'ftp' 'enabled' '1'
+    osal_ini_set $HESTIA/conf/modules.conf 'ftp' 'variant' 'vsftpd'
+    osal_ini_set $HESTIA/conf/modules.conf 'ftp' 'version' '1'
+    osal_ini_set $HESTIA/conf/modules.conf 'ftp' 'service_name' 'vsftpd'
+
+    exit 0
+}
+
+# If this files is _not_ being sourced, act immediately
+# (otherise, wait for hestia cli to call the main function)
+[[ $_ == $0 ]] && hestia_module_vsftpd_install $@

+ 37 - 0
bin/module/vsftpd/remove.inc

@@ -0,0 +1,37 @@
+#!/bin/sh
+
+hestia_module_vsftpd_remove() {
+    source $HESTIA/bin/module/func.inc
+
+    ftp_installed=$(hestia_module_isinstalled ftp)
+    if [ ! "$ftp_installed" ]; then
+        echo "FTP module is not installed. See 'hestia module info ftp'."
+        exit 1
+    fi
+
+    ftp_variant=$(hestia_module_getvariant ftp)
+    if [ "$ftp_variant" != 'vsftpd' ]; then
+        echo "The installed FTP module is not vsftpd. See 'hestia module info ftp'."
+        exit 1
+    fi
+
+    echo "Removing FTP (vsftpd) module..."
+
+    osal_service_stop vsftpd
+    osal_service_disable vsftpd
+    osal_package_remove vsftpd
+
+    rm -f $OSAL_PATH_VSFTPD_CONF/vsftpd.conf
+
+    osal_ini_set $HESTIA/conf/hestia.conf '' 'FTP_SYSTEM' 'no'
+    osal_ini_set $HESTIA/conf/modules.conf 'ftp' 'installed' '0'
+    osal_ini_set $HESTIA/conf/modules.conf 'ftp' 'enabled' '0'
+    osal_ini_set $HESTIA/conf/modules.conf 'ftp' 'variant' ''
+    osal_ini_set $HESTIA/conf/modules.conf 'ftp' 'version' '0'
+
+    exit 0
+}
+
+# If this files is _not_ being sourced, act immediately
+# (otherise, wait for hestia cli to call the main function)
+[[ $_ == $0 ]] && hestia_module_vsftpd_remove $@

+ 10 - 3
func/osal.sh

@@ -34,14 +34,21 @@ do
     fi
 done
 
-# VAR = $(ini_get 'file' 'section' 'param' 'newvalue')
+# VAR=$(ini_get 'file' 'section' 'param' 'value')
 osal_ini_get() {
-    /usr/bin/crudini --get "$@"
+    #echo /usr/bin/crudini --get $@
+    retval=$(/usr/bin/crudini --get $@ 2>1)
+    if [ $? -eq 0 ]; then
+        echo $retval
+    fi
 }
 
 # ini_set 'file' 'section' 'param' 'newvalue'
 osal_ini_set() {
-    /usr/bin/crudini --set "$@"
+    if [ "$OSAL_DEBUG" ]; then
+        echo /usr/bin/crudini --set $@
+    fi
+    /usr/bin/crudini --set $@
 }
 
 osal_execute_with_spinner() {

+ 1 - 0
func/osal_debian_based.sh

@@ -31,6 +31,7 @@ OSAL_PKG_ROUNDCUBE=roundcube
 OSAL_PATH_APACHE_CONF=/etc/apache2
 OSAL_PATH_BIND_DATA=/var/cache/bind
 OSAL_PATH_ROUNDCUBE_INSTALL_MYSQL=/usr/share/dbconfig-common/data/roundcubemail/install/mysql
+OSAL_PATH_VSFTPD_CONF=/etc
 
 #-------------------------------------------------------------------#
 # Functions                                                         #

+ 1 - 0
func/osal_rhel_based.sh

@@ -31,6 +31,7 @@ OSAL_PKG_ROUNDCUBE=roundcubemail
 OSAL_PATH_APACHE_CONF=/etc/httpd
 OSAL_PATH_BIND_DATA=/var/named
 OSAL_PATH_ROUNDCUBE_INSTALL_MYSQL=/usr/share/roundcubemail/SQL/mysql
+OSAL_PATH_VSFTPD_CONF=/etc/vsftpd
 
 #-------------------------------------------------------------------#
 # Functions                                                         #