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

Merge branch 'bugfix/2020-07_file-manager-installer' into staging/fixes

Kristan Kenney 5 лет назад
Родитель
Сommit
7387a4bbf1

+ 119 - 0
bin/v-add-sys-filemanager

@@ -0,0 +1,119 @@
+#!/bin/bash
+# info: add file manager functionality to Hestia Control Panel
+# options: none
+#
+# The function installs the File Manager on the server
+# for access through the Web interface.
+
+#----------------------------------------------------------#
+#                    Variable&Function                     #
+#----------------------------------------------------------#
+
+# Includes
+source $HESTIA/func/main.sh
+source $HESTIA/conf/hestia.conf
+
+MODE=$1
+user="admin"
+
+FM_INSTALL_DIR="$HESTIA/web/fm"
+FM_V="7.4.1"
+FM_FILE="filegator_v${FM_V}.zip"
+FM_URL="https://github.com/filegator/filegator/releases/download/v${FM_V}/${FM_FILE}"
+COMPOSER_BIN="$HOMEDIR/$user/.composer/composer"
+
+
+#----------------------------------------------------------#
+#                    Verifications                         #
+#----------------------------------------------------------#
+
+# Checking root permissions
+if [ "x$(id -u)" != 'x0' ]; then
+    echo "ERROR: v-add-sys-filemanager can be run executed only by root user"
+    exit 10
+fi
+
+# Ensure that $HESTIA (/usr/local/hestia/) and other variables are valid.
+if [ -z "$HESTIA" ]; then
+    HESTIA="/usr/local/hestia"
+fi
+
+if [ -z "$HOMEDIR" ] || [ -z "$HESTIA_INSTALL_DIR" ]; then
+    echo "ERROR: Environment variables not present, installation aborted."
+    exit 2
+fi
+
+# Ensure that Composer is installed for the user before continuing as it is a dependency of the File Manager.
+if [ ! -f "$COMPOSER_BIN" ]; then
+    $BIN/v-add-user-composer "$user"
+    if [ $? -ne 0 ]; then
+        $BIN/v-add-user-notification admin 'Composer installation failed!' '<b>The File Manager will not work without Composer.</b><br><br>Please try running the installer manually from a shell session:<br>v-add-sys-filemanager<br><br>If this continues, open an issue report on <a href="https://github.com/hestiacp/hestiacp/issues" target="_new"><i class="fab fa-github"></i> GitHub</a>.'
+        exit 1
+    fi
+fi
+
+# Ensure PHP 7.3 is installed before continuing
+if [ ! -f "/usr/bin/php7.3" ]; then
+    $BIN/v-add-user-notification admin 'File Manager installation failed!' '<b>Unable to proceed with installation of File Manager.</b><br><br>Package <b>php7.3-cli</b> is missing from your system. Please check your PHP installation and environment settings.'
+    echo "ERROR: PHP 7.3 not installed on your system, aborting."
+    exit 1
+fi
+
+# Perform verification if read-only mode is enabled
+check_hestia_demo_mode
+
+#----------------------------------------------------------#
+#                       Action                             #
+#----------------------------------------------------------#
+
+rm --recursive --force "$FM_INSTALL_DIR"
+mkdir -p "$FM_INSTALL_DIR"
+cd "$FM_INSTALL_DIR"
+
+[ ! -f "${FM_INSTALL_DIR}/${FM_FILE}" ] && wget "$FM_URL" --quiet -O "${FM_INSTALL_DIR}/${FM_FILE}"
+
+unzip -qq "${FM_INSTALL_DIR}/${FM_FILE}"
+mv --force ${FM_INSTALL_DIR}/filegator/* "${FM_INSTALL_DIR}"
+rm --recursive --force ${FM_INSTALL_DIR}/filegator
+[[ -f "${FM_INSTALL_DIR}/${FM_FILE}" ]] && rm "${FM_INSTALL_DIR}/${FM_FILE}"
+
+cp --recursive --force ${HESTIA_INSTALL_DIR}/filemanager/filegator/* "${FM_INSTALL_DIR}"
+
+chown $user: -R "${FM_INSTALL_DIR}"
+
+COMPOSER_HOME="$HOMEDIR/$user/.config/composer" user_exec /usr/bin/php7.3 $COMPOSER_BIN --quiet --no-dev install
+
+# Check if installation was successful, if not abort script and throw error message notification and clean-up
+if [ $? -ne 0 ]; then
+    echo "ERROR: File Manager installation failed!"
+    echo "Please report this to our development team:"
+    echo "https://github.com/hestiacp/hestiacp/issues"
+    $BIN/v-add-user-notification admin 'File Manager installation failed!' 'Please report this to our development team on <a href="https://github.com/hestiacp/hestiacp/issues" target="_new"><i class="fab fa-github"></i> GitHub</a>.'
+    # Installation failed, clean up files
+    rm --recursive --force ${FM_INSTALL_DIR}
+    $BIN/v-change-sys-config-value 'FILE_MANAGER' 'false'
+    exit 1
+fi
+
+# Add configuration file
+cp -f $HESTIA_INSTALL_DIR/filemanager/filegator/configuration.php $HESTIA/web/fm/configuration.php
+
+
+# Set permissions
+chown root: -R "${FM_INSTALL_DIR}"
+chown $user: "${FM_INSTALL_DIR}/private"
+chown $user: "${FM_INSTALL_DIR}/private/logs"
+chown $user: "${FM_INSTALL_DIR}/repository"
+
+$BIN/v-change-sys-config-value 'FILE_MANAGER' 'true'
+
+if [ "$MODE" != "quiet" ]; then
+    echo "File Manager is now installed and ready for use."  
+fi
+
+#----------------------------------------------------------#
+#                       Logging                            #
+#----------------------------------------------------------#
+
+log_history "file manager installed" '' 'admin'
+log_event "$OK" "$ARGUMENTS"

+ 72 - 0
bin/v-delete-sys-filemanager

@@ -0,0 +1,72 @@
+#!/bin/bash
+# info: remove file manager functionality from Hestia Control Panel
+# options: [FULL]
+#
+# The function removes the File Manager and its entry points
+
+#----------------------------------------------------------#
+#                    Variable&Function                     #
+#----------------------------------------------------------#
+
+MODE=$1
+
+# Includes
+source $HESTIA/func/main.sh
+source $HESTIA/conf/hestia.conf
+
+user='admin'
+FM_INSTALL_DIR="$HESTIA/web/fm"
+FM_V="7.4.1"
+COMPOSER_BIN="$HOMEDIR/$user/.composer/composer"
+
+#----------------------------------------------------------#
+#                    Verifications                         #
+#----------------------------------------------------------#
+
+# Checking root permissions
+if [ "x$(id -u)" != 'x0' ]; then
+    echo "Error: Script can be run executed only by root"
+    exit 10
+fi
+
+# Ensure that $HESTIA (/usr/local/hestia/) and other variables are valid.
+if [ -z "$HESTIA" ]; then
+    HESTIA="/usr/local/hestia"
+fi
+
+if [ -z "$HOMEDIR" ] || [ -z "$HESTIA_INSTALL_DIR" ]; then
+    echo "Error: Hestia environment vars not present"
+    exit 2
+fi
+
+# Perform verification if read-only mode is enabled
+check_hestia_demo_mode
+
+# Check if File Manager components are installed
+if [ "$MODE" != "force" ] && [ ! -e "$FM_INSTALL_DIR" ]; then
+    echo "ERROR: File Manager components are not installed."
+    exit 1
+fi
+
+if [ "$MODE" != "force" ] && [ "$FILE_MANGER" = "false" ]; then
+    echo "ERROR: File Manager is not enabled."
+    exit 1
+fi
+
+#----------------------------------------------------------#
+#                       Action                             #
+#----------------------------------------------------------#
+
+rm --recursive --force "$FM_INSTALL_DIR"
+$BIN/v-change-sys-config-value 'FILE_MANAGER' 'false'
+
+if [ "$MODE" != "quiet" ]; then
+    echo "File Manager has been removed from the system."
+fi
+
+#----------------------------------------------------------#
+#                       Logging                            #
+#----------------------------------------------------------#
+
+log_history "file manager uninstalled" '' 'admin'
+log_event "$OK" "$ARGUMENTS"

+ 10 - 6
bin/v-list-sys-config

@@ -41,6 +41,7 @@ json_list() {
         "DISK_QUOTA": "'$DISK_QUOTA'",
         "FIREWALL_SYSTEM": "'$FIREWALL_SYSTEM'",
         "FIREWALL_EXTENSION": "'$FIREWALL_EXTENSION'",
+        "FILE_MANAGER": "'$FILE_MANAGER'",
         "REPOSITORY": "'$REPOSITORY'",
         "VERSION": "'$VERSION'",
         "RELEASE_BRANCH": "'$RELEASE_BRANCH'",
@@ -134,6 +135,9 @@ shell_list() {
     if [ ! -z "$DEMO_MODE" ]; then
         echo "Demo Mode:        $DEMO_MODE"
     fi
+    if [ ! -z "$FILE_MANAGER" ]; then
+        echo "File Manager:        $FILE_MANAGER"
+    fi
     echo "Release Branch:   $RELEASE_BRANCH"
     echo "Theme:            $THEME"
 }
@@ -146,8 +150,8 @@ plain_list() {
     echo -ne "$ANTIVIRUS_SYSTEM\t$ANTISPAM_SYSTEM\t$DB_SYSTEM\t"
     echo -ne "$DNS_SYSTEM\t$DNS_CLUSTER\t$STATS_SYSTEM\t$BACKUP_SYSTEM\t"
     echo -ne "$CRON_SYSTEM\t$DISK_QUOTA\t$FIREWALL_SYSTEM\t$FIREWALL_EXTENSION\t"
-    echo -ne "$REPOSITORY\t$VERSION\t$DEMO_MODE\t$RELEASE_BRANCH\t$THEME\t$LANGUAGE\t"
-    echo -e "$BACKUP_GZIP\t$BACKUP\t$WEBMAIL_ALIAS\t$DB_PMA_ALIAS\t$DB_PGA_ALIAS"
+    echo -ne "$FILE_MANAGER\t$REPOSITORY\t$VERSION\t$DEMO_MODE\t$RELEASE_BRANCH\t$THEME\t"
+    echo -e "$LANGUAGE\t$BACKUP_GZIP\t$BACKUP\t$WEBMAIL_ALIAS\t$DB_PMA_URL\t$DB_PGA_URL"
 }
 
 
@@ -159,7 +163,7 @@ csv_list() {
     echo -n "'ANTIVIRUS_SYSTEM','ANTISPAM_SYSTEM','DB_SYSTEM',"
     echo -n "'DNS_SYSTEM','DNS_CLUSTER','STATS_SYSTEM','BACKUP_SYSTEM',"
     echo -n "'CRON_SYSTEM','DISK_QUOTA','FIREWALL_SYSTEM',"
-    echo -n "'FIREWALL_EXTENSION','REPOSITORY',"
+    echo -n "'FIREWALL_EXTENSION','FILE_MANAGER','REPOSITORY',"
     echo -n "'VERSION','LANGUAGE','BACKUP_GZIP','BACKUP','WEBMAIL_ALIAS',"
     echo -n "'DB_PMA_ALIAS','DB_PGA_ALIAS'"
     echo
@@ -168,9 +172,9 @@ csv_list() {
     echo -n "'$PROXY_SSL_PORT','$FTP_SYSTEM','$MAIL_SYSTEM','$IMAP_SYSTEM',"
     echo -n "'$ANTIVIRUS_SYSTEM','$ANTISPAM_SYSTEM','$DB_SYSTEM','$DNS_SYSTEM',"
     echo -n "'$DNS_CLUSTER','$STATS_SYSTEM','$BACKUP_SYSTEM','$CRON_SYSTEM',"
-    echo -n "'$DISK_QUOTA','$FIREWALL_SYSTEM','$REPOSITORY','$FIREWALL_EXTENSION',"
-    echo -n "'$VERSION','$DEMO_MODE','$RELEASE_BRANCH','$THEME','$LANGUAGE',"
-    echo -n "'$BACKUP_GZIP','$BACKUP','$WEBMAIL_ALIAS','$DB_PMA_ALIAS','$DB_PGA_ALIAS'"
+    echo -n "'$DISK_QUOTA','$FIREWALL_SYSTEM','$FIREWALL_EXTENSION','$FILE_MANAGER',"
+    echo -n "'$REPOSITORY', '$VERSION','$DEMO_MODE','$RELEASE_BRANCH','$THEME','$LANGUAGE',"
+    echo -n "'$BACKUP_GZIP','$BACKUP','$WEBMAIL_ALIAS','$DB_PMA_URL','$DB_PGA_URL'"
     echo
 }
 

+ 15 - 10
install/upgrade/versions/latest.sh

@@ -134,15 +134,21 @@ if [ "$WEB_SYSTEM" = "apache2" ]; then
     rm --force /etc/apache2/mods-enabled/status.conf # a2dismod will not remove the file if it isn't a symlink
 fi
 
-# Install Filegator FileManager during upgrade
-if [ ! -e "$HESTIA/web/fm/configuration.php" ]; then
-    echo "(*) Configuring File Manager..."
-    # Install the FileManager
-    source $HESTIA_INSTALL_DIR/filemanager/install-fm.sh > /dev/null 2>&1
-else 
-    echo "(*) Updating File Manager configuration..."
-    # Update configuration.php
-    cp -f $HESTIA_INSTALL_DIR/filemanager/filegator/configuration.php $HESTIA/web/fm/configuration.php
+# Install File Manager during upgrade if environment variable oesn't already exist and isn't set to false
+# so that we don't override preference
+FILE_MANAGER_CHECK=$(cat $HESTIA/conf/hestia.conf | grep "FILE_MANAGER='false'")
+if [ -z "$FILE_MANAGER_CHECK" ]; then
+    if [ ! -e "$HESTIA/web/fm/configuration.php" ]; then
+        echo "(*) Installing File Manager..."
+        # Install the File Manager
+        $HESTIA/bin/v-add-sys-filemanager quiet
+    else 
+        echo "(*) Updating File Manager configuration..."
+        # Update configuration.php
+        cp -f $HESTIA_INSTALL_DIR/filemanager/filegator/configuration.php $HESTIA/web/fm/configuration.php
+        # Set environment variable for interface
+        $HESTIA/bin/v-change-sys-config-value 'FILE_MANAGER' 'true'
+    fi
 fi
 
 # Enable nginx module loading
@@ -191,4 +197,3 @@ PGA_ALIAS_CHECK=$(cat $HESTIA/conf/hestia.conf | grep DB_PGA_ALIAS)
         $HESTIA/bin/v-change-sys-db-alias "pga" "phppgadmin"
     fi
 fi
-

+ 3 - 1
web/templates/admin/panel.html

@@ -11,7 +11,9 @@
 		<a href="/list/user/" class="l-logo"></a>
 		<div class="l-menu clearfix noselect">
 			<div class="l-menu__item <?php if($TAB == 'WEB' ) echo 'l-menu__item--active' ?> <?php if($TAB == 'DNS' ) echo 'l-menu__item--active' ?> <?php if($TAB == 'MAIL' ) echo 'l-menu__item--active' ?> <?php if($TAB == 'DB' ) echo 'l-menu__item--active' ?> <?php if($TAB == 'BACKUP' ) echo 'l-menu__item--active' ?> <?php if($TAB == 'CRON' ) echo 'l-menu__item--active' ?><?php if($TAB == 'PACKAGE' ) echo 'l-menu__item--active' ?> <?php if($TAB == 'USER' ) echo 'l-menu__item--active' ?>"><a href="/list/user/"><i class="fas fa-tasks panel-icon"></i>&nbsp;&nbsp;&nbsp;<?=__('Records')?></a></div>
-			<div class="l-menu__item <?php if($TAB == 'FM' ) echo 'l-menu__item--active' ?>"><a href="/fm/"><i class="fas fa-folder-open panel-icon"></i>&nbsp;&nbsp;&nbsp;<?=__('Fm')?></a></div>
+			<?php if ((isset($_SESSION['FILE_MANAGER'])) && (!empty($_SESSION['FILE_MANAGER'])) && ($_SESSION['FILE_MANAGER'] == "true")) {?>
+				<div class="l-menu__item <?php if($TAB == 'FM' ) echo 'l-menu__item--active' ?>"><a href="/fm/"><i class="fas fa-folder-open panel-icon"></i>&nbsp;&nbsp;&nbsp;<?=__('Fm')?></a></div>
+			<?php } ?>
 			<div class="l-menu__item <?php if($TAB == 'LOG' ) echo 'l-menu__item--active' ?>"><a href="/list/log/"><i class="fas fa-history panel-icon"></i>&nbsp;&nbsp;&nbsp;<?=__('Log')?></a></div>
 			<div class="l-menu__item <?php if($TAB == 'STATS' ) echo 'l-menu__item--active' ?>"><a href="/list/stats/"><i class="fas fa-chart-line panel-icon"></i>&nbsp;&nbsp;&nbsp;<?=__('Statistics')?></a></div>
 		</div>

+ 4 - 2
web/templates/user/panel.html

@@ -11,8 +11,10 @@
 		<a href="/list/web/" class="l-logo"></a>
 		<div class="l-menu clearfix noselect">
 			<div class="l-menu__item <?php if($TAB == 'WEB' ) echo 'l-menu__item--active' ?> <?php if($TAB == 'DNS' ) echo 'l-menu__item--active' ?> <?php if($TAB == 'MAIL' ) echo 'l-menu__item--active' ?> <?php if($TAB == 'DB' ) echo 'l-menu__item--active' ?> <?php if($TAB == 'BACKUP' ) echo 'l-menu__item--active' ?> <?php if($TAB == 'CRON' ) echo 'l-menu__item--active' ?>"><a href="/list/web/"><i class="fas fa-tasks panel-icon"></i>&nbsp;&nbsp;&nbsp;<?=__('Records')?></a></div>
-			<div class="l-menu__item <?php if($TAB == 'FM' ) echo 'l-menu__item--active' ?>"><a href="/fm/"><i class="fas fa-folder-open panel-icon"></i>&nbsp;&nbsp;&nbsp;<?=__('Fm')?></a></div>
-			<div class="l-menu__item <?php if($TAB == 'LOG' ) echo 'l-menu__item--active' ?>"><a href="/list/log/"><i class="fas fa-history panel-icon"></i>&nbsp;&nbsp;&nbsp;<?=__('Log')?></a></div>
+			<?php if ((isset($_SESSION['FILE_MANAGER'])) && (!empty($_SESSION['FILE_MANAGER'])) && ($_SESSION['FILE_MANAGER'] == "true")) {?>
+				<div class="l-menu__item <?php if($TAB == 'FM' ) echo 'l-menu__item--active' ?>"><a href="/fm/"><i class="fas fa-folder-open panel-icon"></i>&nbsp;&nbsp;&nbsp;<?=__('Fm')?></a></div>
+			<?php } ?>
+				<div class="l-menu__item <?php if($TAB == 'LOG' ) echo 'l-menu__item--active' ?>"><a href="/list/log/"><i class="fas fa-history panel-icon"></i>&nbsp;&nbsp;&nbsp;<?=__('Log')?></a></div>
 			<div class="l-menu__item <?php if($TAB == 'STATS' ) echo 'l-menu__item--active' ?>"><a href="/list/stats/"><i class="fas fa-chart-line panel-icon"></i>&nbsp;&nbsp;&nbsp;<?=__('Statistics')?></a></div>
 		</div>
 		<div class="l-profile noselect">