Skip to content

Commit 7387a4b

Browse files
author
Kristan Kenney
committed
Merge branch 'bugfix/2020-07_file-manager-installer' into staging/fixes
2 parents 2f59eeb + 158e41e commit 7387a4b

File tree

6 files changed

+223
-19
lines changed

6 files changed

+223
-19
lines changed

bin/v-add-sys-filemanager

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
#!/bin/bash
2+
# info: add file manager functionality to Hestia Control Panel
3+
# options: none
4+
#
5+
# The function installs the File Manager on the server
6+
# for access through the Web interface.
7+
8+
#----------------------------------------------------------#
9+
# Variable&Function #
10+
#----------------------------------------------------------#
11+
12+
# Includes
13+
source $HESTIA/func/main.sh
14+
source $HESTIA/conf/hestia.conf
15+
16+
MODE=$1
17+
user="admin"
18+
19+
FM_INSTALL_DIR="$HESTIA/web/fm"
20+
FM_V="7.4.1"
21+
FM_FILE="filegator_v${FM_V}.zip"
22+
FM_URL="https://github.com/filegator/filegator/releases/download/v${FM_V}/${FM_FILE}"
23+
COMPOSER_BIN="$HOMEDIR/$user/.composer/composer"
24+
25+
26+
#----------------------------------------------------------#
27+
# Verifications #
28+
#----------------------------------------------------------#
29+
30+
# Checking root permissions
31+
if [ "x$(id -u)" != 'x0' ]; then
32+
echo "ERROR: v-add-sys-filemanager can be run executed only by root user"
33+
exit 10
34+
fi
35+
36+
# Ensure that $HESTIA (/usr/local/hestia/) and other variables are valid.
37+
if [ -z "$HESTIA" ]; then
38+
HESTIA="/usr/local/hestia"
39+
fi
40+
41+
if [ -z "$HOMEDIR" ] || [ -z "$HESTIA_INSTALL_DIR" ]; then
42+
echo "ERROR: Environment variables not present, installation aborted."
43+
exit 2
44+
fi
45+
46+
# Ensure that Composer is installed for the user before continuing as it is a dependency of the File Manager.
47+
if [ ! -f "$COMPOSER_BIN" ]; then
48+
$BIN/v-add-user-composer "$user"
49+
if [ $? -ne 0 ]; then
50+
$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>.'
51+
exit 1
52+
fi
53+
fi
54+
55+
# Ensure PHP 7.3 is installed before continuing
56+
if [ ! -f "/usr/bin/php7.3" ]; then
57+
$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.'
58+
echo "ERROR: PHP 7.3 not installed on your system, aborting."
59+
exit 1
60+
fi
61+
62+
# Perform verification if read-only mode is enabled
63+
check_hestia_demo_mode
64+
65+
#----------------------------------------------------------#
66+
# Action #
67+
#----------------------------------------------------------#
68+
69+
rm --recursive --force "$FM_INSTALL_DIR"
70+
mkdir -p "$FM_INSTALL_DIR"
71+
cd "$FM_INSTALL_DIR"
72+
73+
[ ! -f "${FM_INSTALL_DIR}/${FM_FILE}" ] && wget "$FM_URL" --quiet -O "${FM_INSTALL_DIR}/${FM_FILE}"
74+
75+
unzip -qq "${FM_INSTALL_DIR}/${FM_FILE}"
76+
mv --force ${FM_INSTALL_DIR}/filegator/* "${FM_INSTALL_DIR}"
77+
rm --recursive --force ${FM_INSTALL_DIR}/filegator
78+
[[ -f "${FM_INSTALL_DIR}/${FM_FILE}" ]] && rm "${FM_INSTALL_DIR}/${FM_FILE}"
79+
80+
cp --recursive --force ${HESTIA_INSTALL_DIR}/filemanager/filegator/* "${FM_INSTALL_DIR}"
81+
82+
chown $user: -R "${FM_INSTALL_DIR}"
83+
84+
COMPOSER_HOME="$HOMEDIR/$user/.config/composer" user_exec /usr/bin/php7.3 $COMPOSER_BIN --quiet --no-dev install
85+
86+
# Check if installation was successful, if not abort script and throw error message notification and clean-up
87+
if [ $? -ne 0 ]; then
88+
echo "ERROR: File Manager installation failed!"
89+
echo "Please report this to our development team:"
90+
echo "https://github.com/hestiacp/hestiacp/issues"
91+
$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>.'
92+
# Installation failed, clean up files
93+
rm --recursive --force ${FM_INSTALL_DIR}
94+
$BIN/v-change-sys-config-value 'FILE_MANAGER' 'false'
95+
exit 1
96+
fi
97+
98+
# Add configuration file
99+
cp -f $HESTIA_INSTALL_DIR/filemanager/filegator/configuration.php $HESTIA/web/fm/configuration.php
100+
101+
102+
# Set permissions
103+
chown root: -R "${FM_INSTALL_DIR}"
104+
chown $user: "${FM_INSTALL_DIR}/private"
105+
chown $user: "${FM_INSTALL_DIR}/private/logs"
106+
chown $user: "${FM_INSTALL_DIR}/repository"
107+
108+
$BIN/v-change-sys-config-value 'FILE_MANAGER' 'true'
109+
110+
if [ "$MODE" != "quiet" ]; then
111+
echo "File Manager is now installed and ready for use."
112+
fi
113+
114+
#----------------------------------------------------------#
115+
# Logging #
116+
#----------------------------------------------------------#
117+
118+
log_history "file manager installed" '' 'admin'
119+
log_event "$OK" "$ARGUMENTS"

bin/v-delete-sys-filemanager

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#!/bin/bash
2+
# info: remove file manager functionality from Hestia Control Panel
3+
# options: [FULL]
4+
#
5+
# The function removes the File Manager and its entry points
6+
7+
#----------------------------------------------------------#
8+
# Variable&Function #
9+
#----------------------------------------------------------#
10+
11+
MODE=$1
12+
13+
# Includes
14+
source $HESTIA/func/main.sh
15+
source $HESTIA/conf/hestia.conf
16+
17+
user='admin'
18+
FM_INSTALL_DIR="$HESTIA/web/fm"
19+
FM_V="7.4.1"
20+
COMPOSER_BIN="$HOMEDIR/$user/.composer/composer"
21+
22+
#----------------------------------------------------------#
23+
# Verifications #
24+
#----------------------------------------------------------#
25+
26+
# Checking root permissions
27+
if [ "x$(id -u)" != 'x0' ]; then
28+
echo "Error: Script can be run executed only by root"
29+
exit 10
30+
fi
31+
32+
# Ensure that $HESTIA (/usr/local/hestia/) and other variables are valid.
33+
if [ -z "$HESTIA" ]; then
34+
HESTIA="/usr/local/hestia"
35+
fi
36+
37+
if [ -z "$HOMEDIR" ] || [ -z "$HESTIA_INSTALL_DIR" ]; then
38+
echo "Error: Hestia environment vars not present"
39+
exit 2
40+
fi
41+
42+
# Perform verification if read-only mode is enabled
43+
check_hestia_demo_mode
44+
45+
# Check if File Manager components are installed
46+
if [ "$MODE" != "force" ] && [ ! -e "$FM_INSTALL_DIR" ]; then
47+
echo "ERROR: File Manager components are not installed."
48+
exit 1
49+
fi
50+
51+
if [ "$MODE" != "force" ] && [ "$FILE_MANGER" = "false" ]; then
52+
echo "ERROR: File Manager is not enabled."
53+
exit 1
54+
fi
55+
56+
#----------------------------------------------------------#
57+
# Action #
58+
#----------------------------------------------------------#
59+
60+
rm --recursive --force "$FM_INSTALL_DIR"
61+
$BIN/v-change-sys-config-value 'FILE_MANAGER' 'false'
62+
63+
if [ "$MODE" != "quiet" ]; then
64+
echo "File Manager has been removed from the system."
65+
fi
66+
67+
#----------------------------------------------------------#
68+
# Logging #
69+
#----------------------------------------------------------#
70+
71+
log_history "file manager uninstalled" '' 'admin'
72+
log_event "$OK" "$ARGUMENTS"

bin/v-list-sys-config

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ json_list() {
4141
"DISK_QUOTA": "'$DISK_QUOTA'",
4242
"FIREWALL_SYSTEM": "'$FIREWALL_SYSTEM'",
4343
"FIREWALL_EXTENSION": "'$FIREWALL_EXTENSION'",
44+
"FILE_MANAGER": "'$FILE_MANAGER'",
4445
"REPOSITORY": "'$REPOSITORY'",
4546
"VERSION": "'$VERSION'",
4647
"RELEASE_BRANCH": "'$RELEASE_BRANCH'",
@@ -134,6 +135,9 @@ shell_list() {
134135
if [ ! -z "$DEMO_MODE" ]; then
135136
echo "Demo Mode: $DEMO_MODE"
136137
fi
138+
if [ ! -z "$FILE_MANAGER" ]; then
139+
echo "File Manager: $FILE_MANAGER"
140+
fi
137141
echo "Release Branch: $RELEASE_BRANCH"
138142
echo "Theme: $THEME"
139143
}
@@ -146,8 +150,8 @@ plain_list() {
146150
echo -ne "$ANTIVIRUS_SYSTEM\t$ANTISPAM_SYSTEM\t$DB_SYSTEM\t"
147151
echo -ne "$DNS_SYSTEM\t$DNS_CLUSTER\t$STATS_SYSTEM\t$BACKUP_SYSTEM\t"
148152
echo -ne "$CRON_SYSTEM\t$DISK_QUOTA\t$FIREWALL_SYSTEM\t$FIREWALL_EXTENSION\t"
149-
echo -ne "$REPOSITORY\t$VERSION\t$DEMO_MODE\t$RELEASE_BRANCH\t$THEME\t$LANGUAGE\t"
150-
echo -e "$BACKUP_GZIP\t$BACKUP\t$WEBMAIL_ALIAS\t$DB_PMA_ALIAS\t$DB_PGA_ALIAS"
153+
echo -ne "$FILE_MANAGER\t$REPOSITORY\t$VERSION\t$DEMO_MODE\t$RELEASE_BRANCH\t$THEME\t"
154+
echo -e "$LANGUAGE\t$BACKUP_GZIP\t$BACKUP\t$WEBMAIL_ALIAS\t$DB_PMA_URL\t$DB_PGA_URL"
151155
}
152156

153157

@@ -159,7 +163,7 @@ csv_list() {
159163
echo -n "'ANTIVIRUS_SYSTEM','ANTISPAM_SYSTEM','DB_SYSTEM',"
160164
echo -n "'DNS_SYSTEM','DNS_CLUSTER','STATS_SYSTEM','BACKUP_SYSTEM',"
161165
echo -n "'CRON_SYSTEM','DISK_QUOTA','FIREWALL_SYSTEM',"
162-
echo -n "'FIREWALL_EXTENSION','REPOSITORY',"
166+
echo -n "'FIREWALL_EXTENSION','FILE_MANAGER','REPOSITORY',"
163167
echo -n "'VERSION','LANGUAGE','BACKUP_GZIP','BACKUP','WEBMAIL_ALIAS',"
164168
echo -n "'DB_PMA_ALIAS','DB_PGA_ALIAS'"
165169
echo
@@ -168,9 +172,9 @@ csv_list() {
168172
echo -n "'$PROXY_SSL_PORT','$FTP_SYSTEM','$MAIL_SYSTEM','$IMAP_SYSTEM',"
169173
echo -n "'$ANTIVIRUS_SYSTEM','$ANTISPAM_SYSTEM','$DB_SYSTEM','$DNS_SYSTEM',"
170174
echo -n "'$DNS_CLUSTER','$STATS_SYSTEM','$BACKUP_SYSTEM','$CRON_SYSTEM',"
171-
echo -n "'$DISK_QUOTA','$FIREWALL_SYSTEM','$REPOSITORY','$FIREWALL_EXTENSION',"
172-
echo -n "'$VERSION','$DEMO_MODE','$RELEASE_BRANCH','$THEME','$LANGUAGE',"
173-
echo -n "'$BACKUP_GZIP','$BACKUP','$WEBMAIL_ALIAS','$DB_PMA_ALIAS','$DB_PGA_ALIAS'"
175+
echo -n "'$DISK_QUOTA','$FIREWALL_SYSTEM','$FIREWALL_EXTENSION','$FILE_MANAGER',"
176+
echo -n "'$REPOSITORY', '$VERSION','$DEMO_MODE','$RELEASE_BRANCH','$THEME','$LANGUAGE',"
177+
echo -n "'$BACKUP_GZIP','$BACKUP','$WEBMAIL_ALIAS','$DB_PMA_URL','$DB_PGA_URL'"
174178
echo
175179
}
176180

install/upgrade/versions/latest.sh

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -134,15 +134,21 @@ if [ "$WEB_SYSTEM" = "apache2" ]; then
134134
rm --force /etc/apache2/mods-enabled/status.conf # a2dismod will not remove the file if it isn't a symlink
135135
fi
136136

137-
# Install Filegator FileManager during upgrade
138-
if [ ! -e "$HESTIA/web/fm/configuration.php" ]; then
139-
echo "(*) Configuring File Manager..."
140-
# Install the FileManager
141-
source $HESTIA_INSTALL_DIR/filemanager/install-fm.sh > /dev/null 2>&1
142-
else
143-
echo "(*) Updating File Manager configuration..."
144-
# Update configuration.php
145-
cp -f $HESTIA_INSTALL_DIR/filemanager/filegator/configuration.php $HESTIA/web/fm/configuration.php
137+
# Install File Manager during upgrade if environment variable oesn't already exist and isn't set to false
138+
# so that we don't override preference
139+
FILE_MANAGER_CHECK=$(cat $HESTIA/conf/hestia.conf | grep "FILE_MANAGER='false'")
140+
if [ -z "$FILE_MANAGER_CHECK" ]; then
141+
if [ ! -e "$HESTIA/web/fm/configuration.php" ]; then
142+
echo "(*) Installing File Manager..."
143+
# Install the File Manager
144+
$HESTIA/bin/v-add-sys-filemanager quiet
145+
else
146+
echo "(*) Updating File Manager configuration..."
147+
# Update configuration.php
148+
cp -f $HESTIA_INSTALL_DIR/filemanager/filegator/configuration.php $HESTIA/web/fm/configuration.php
149+
# Set environment variable for interface
150+
$HESTIA/bin/v-change-sys-config-value 'FILE_MANAGER' 'true'
151+
fi
146152
fi
147153

148154
# Enable nginx module loading
@@ -191,4 +197,3 @@ PGA_ALIAS_CHECK=$(cat $HESTIA/conf/hestia.conf | grep DB_PGA_ALIAS)
191197
$HESTIA/bin/v-change-sys-db-alias "pga" "phppgadmin"
192198
fi
193199
fi
194-

web/templates/admin/panel.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
<a href="/list/user/" class="l-logo"></a>
1212
<div class="l-menu clearfix noselect">
1313
<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>
14-
<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>
14+
<?php if ((isset($_SESSION['FILE_MANAGER'])) && (!empty($_SESSION['FILE_MANAGER'])) && ($_SESSION['FILE_MANAGER'] == "true")) {?>
15+
<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>
16+
<?php } ?>
1517
<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>
1618
<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>
1719
</div>

web/templates/user/panel.html

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@
1111
<a href="/list/web/" class="l-logo"></a>
1212
<div class="l-menu clearfix noselect">
1313
<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>
14-
<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>
15-
<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>
14+
<?php if ((isset($_SESSION['FILE_MANAGER'])) && (!empty($_SESSION['FILE_MANAGER'])) && ($_SESSION['FILE_MANAGER'] == "true")) {?>
15+
<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>
16+
<?php } ?>
17+
<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>
1618
<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>
1719
</div>
1820
<div class="l-profile noselect">

0 commit comments

Comments
 (0)