Skip to content

Commit 03c1d88

Browse files
Add web terminal (hestiacp#3859)
* Add frontend for web-terminal * Fix Terminal export * Remove some messages * Make terminal accessible to regular users * Add message on terminal exit * Use writeln for connection messages * Order sys-config json and add BACKEND_PORT * Fix json syntax * Add variable to syshealth * Add nodejs on install and maybe do a deb? * Better uid and gid detection * Whoops, removed something by accident * Fix dependency and upgrade script * Check on activation * Create build directory * And the other directory * Make sure node is installed * Don't run husky in CI * Fix terminal ids * Create folders and fix permissions * Add separate service for web terminal * Use the user shell * Use systemd service instead of init.d * Enable service postinst * Use class instead of ID, move to xterm deps * Restart service on upgrade * Add some logging * Keep clients in a Set just in case we need them * Fix service starting, probably * okay no var in path * Better logs * Again, a bit more accurate logs * Add remote IP to nginx conf * Add reasons for websockets closing * Fix websockets error code * Change service name for consistency * Return to user list * Add flag to installer and WEB_TERMINAL_PORT option * Run service under the hestia-users group * Add padding to terminal * Add terminal configs * Add some debug logs and reorder compile commands * Add web terminal to service list * Correctly show service status * change service name in control panel, redirect settings * Add command to change the web terminal port * Render using WebGL or Canvas2D * Open the terminal after loading the addon * Build JS/CSS in deb * Make sure service is disabled/enabled * Check for node in compile script * Don't show terminal button for `nologin` users * Unset temp vars * Make it work when impersonating * Use 2 classes for consistency --------- Co-authored-by: Jaap Marcus <9754650+jaapmarcus@users.noreply.github.com>
1 parent 6ac8a27 commit 03c1d88

38 files changed

+1007
-122
lines changed

.drone.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ steps:
2525
- git submodule update --init --recursive
2626
- name: Build Hestia package and install
2727
commands:
28-
- npm ci
28+
- npm ci --ignore-scripts
2929
- npm run build
3030
- ./src/hst_autocompile.sh --hestia --install '~localsrc'
3131
- name: Reset Web templates
@@ -83,7 +83,7 @@ steps:
8383
- git submodule update --init --recursive
8484
- name: Build Hestia package install
8585
commands:
86-
- npm ci
86+
- npm ci --ignore-scripts
8787
- npm run build
8888
- ./src/hst_autocompile.sh --hestia --install '~localsrc'
8989
- name: Reset Web templates
@@ -131,7 +131,7 @@ steps:
131131
- name: Build JS/CSS
132132
image: node:current-slim
133133
commands:
134-
- npm ci
134+
- npm ci --ignore-scripts
135135
- npm run build
136136
- name: Build
137137
image: debian:bullseye

.github/workflows/lint.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ jobs:
4646
node-version: 16
4747

4848
- name: Install Node packages
49-
run: npm ci
49+
run: npm ci --ignore-scripts
5050

5151
- name: Run Prettier
5252
run: npx prettier --check .
@@ -64,7 +64,7 @@ jobs:
6464
node-version: 16
6565

6666
- name: Install Node packages
67-
run: npm ci
67+
run: npm ci --ignore-scripts
6868

6969
- name: Run ESLint
7070
run: npx eslint .
@@ -82,7 +82,7 @@ jobs:
8282
node-version: 16
8383

8484
- name: Install Node packages
85-
run: npm ci
85+
run: npm ci --ignore-scripts
8686

8787
- name: Run Stylelint
8888
run: npx stylelint web/css/src/**/*.css

bin/v-add-sys-sftp-jail

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,14 @@ fi
4545

4646
# Enabling jailed sftp
4747
if [ -z "$sftp_i" ]; then
48-
echo " " >> $config
49-
echo "# Hestia SFTP Chroot" >> $config
50-
echo "Match User sftp_dummy99" >> $config
51-
echo " ChrootDirectory /srv/jail/%u" >> $config
52-
echo " X11Forwarding no" >> $config
53-
echo " AllowTCPForwarding no" >> $config
54-
echo " ForceCommand internal-sftp -d /home" >> $config
55-
restart='yes'
48+
echo " " >> $config
49+
echo "# Hestia SFTP Chroot" >> $config
50+
echo "Match User sftp_dummy99" >> $config
51+
echo " ChrootDirectory /srv/jail/%u" >> $config
52+
echo " X11Forwarding no" >> $config
53+
echo " AllowTCPForwarding no" >> $config
54+
echo " ForceCommand internal-sftp -d /home" >> $config
55+
restart='yes'
5656
fi
5757

5858
# Validating opensshd config
@@ -63,10 +63,10 @@ if [ "$restart" = 'yes' ]; then
6363
if [ "$?" -ne 0 ]; then
6464
mail_text="OpenSSH can not be restarted. Please check config:
6565
\n\n$(/usr/sbin/sshd -t)"
66-
echo -e "$mail_text" |$SENDMAIL -s "$subj" $email
67-
else
68-
service sshd restart >/dev/null 2>&1
69-
fi
66+
echo -e "$mail_text" | $SENDMAIL -s "$subj" $email
67+
else
68+
service sshd restart > /dev/null 2>&1
69+
fi
7070
fi
7171

7272
# Checking users

bin/v-add-sys-web-terminal

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/bin/bash
2+
# info: add system web terminal
3+
# options: NONE
4+
#
5+
# example: v-add-sys-web-terminal
6+
#
7+
# This function enables the web terminal.
8+
9+
#----------------------------------------------------------#
10+
# Variables & Functions #
11+
#----------------------------------------------------------#
12+
13+
# Includes
14+
# shellcheck source=/etc/hestiacp/hestia.conf
15+
source /etc/hestiacp/hestia.conf
16+
# shellcheck source=/usr/local/hestia/func/main.sh
17+
source $HESTIA/func/main.sh
18+
# load config file
19+
source_conf "$HESTIA/conf/hestia.conf"
20+
21+
#----------------------------------------------------------#
22+
# Verifications #
23+
#----------------------------------------------------------#
24+
25+
if [ "$WEB_TERMINAL" = 'true' ]; then
26+
exit
27+
fi
28+
29+
# Perform verification if read-only mode is enabled
30+
check_hestia_demo_mode
31+
32+
#----------------------------------------------------------#
33+
# Action #
34+
#----------------------------------------------------------#
35+
36+
# Updating WEB_TERMINAL value
37+
$BIN/v-change-sys-config-value "WEB_TERMINAL" "true"
38+
39+
# Check if nodejs and hestia-web-terminal are installed
40+
if [ ! -f "/usr/bin/node" ] || [ ! -f "$HESTIA/web-terminal/server.js" ]; then
41+
apt-get -qq update
42+
apt-get -qq install nodejs hestia-web-terminal -y
43+
else
44+
# Starting web terminal websocket server
45+
$BIN/v-start-service "hestia-web-terminal"
46+
systemctl enable hestia-web-terminal
47+
fi
48+
49+
#----------------------------------------------------------#
50+
# Hestia #
51+
#----------------------------------------------------------#
52+
53+
# Logging
54+
$BIN/v-log-action "system" "Info" "Web Terminal" "Web terminal enabled."
55+
log_event "$OK" "$ARGUMENTS"
56+
57+
exit

bin/v-change-sys-web-terminal-port

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
#!/bin/bash
2+
# info: change system web terminal backend port
3+
# options: PORT
4+
#
5+
# example: v-change-sys-web-terminal-port 5678
6+
#
7+
# This function for changing the system's web terminal backend port in NGINX configuration.
8+
9+
#----------------------------------------------------------#
10+
# Variables & Functions #
11+
#----------------------------------------------------------#
12+
13+
# Argument definition
14+
PORT=$1
15+
NGINX_CONFIG="$HESTIA/nginx/conf/nginx.conf"
16+
17+
# Includes
18+
# shellcheck source=/etc/hestiacp/hestia.conf
19+
source /etc/hestiacp/hestia.conf
20+
# shellcheck source=/usr/local/hestia/func/main.sh
21+
source $HESTIA/func/main.sh
22+
# load config file
23+
source_conf "$HESTIA/conf/hestia.conf"
24+
25+
# Functions
26+
is_port_valid() {
27+
# Check if PORT is numeric
28+
if [[ ! "$PORT" =~ ^[0-9]+$ ]]; then
29+
echo "Port should contains a numeric value only!"
30+
log_event "$E_INVALID" "$ARGUMENTS"
31+
exit "$E_INVALID"
32+
fi
33+
34+
# Check if PORT is already used
35+
BUSY_PORT=$(lsof -i:"$PORT")
36+
if [ -n "$BUSY_PORT" ] && [ "$PORT" != "$BACKEND_PORT" ]; then
37+
echo "Port is already used by Hestia, please set another one!"
38+
log_event "$E_INUSE" "$ARGUMENTS"
39+
exit "$E_INUSE"
40+
fi
41+
}
42+
43+
#----------------------------------------------------------#
44+
# Verifications #
45+
#----------------------------------------------------------#
46+
47+
check_args '1' "$#" 'PORT'
48+
is_port_valid
49+
50+
# Perform verification if read-only mode is enabled
51+
check_hestia_demo_mode
52+
53+
#----------------------------------------------------------#
54+
# Action #
55+
#----------------------------------------------------------#
56+
57+
# Get original port
58+
ORIGINAL_PORT=$(cat ${NGINX_CONFIG} | grep -m1 "proxy_pass http://localhost:" | sed 's/[^0-9]*//g')
59+
60+
# Check if port is different to nginx.conf
61+
if [ "$ORIGINAL_PORT" = "$PORT" ]; then
62+
# Nothing to do, exit
63+
exit
64+
else
65+
# Set new port in config via v-change-sys-config-value
66+
$BIN/v-change-sys-config-value "WEB_TERMINAL_PORT" "$PORT"
67+
# Replace port in config files.
68+
sed -i "s/\(proxy_pass http:\/\/localhost:\)[0-9][0-9]*\([^0-9]*\;$\)/\1$PORT\2/" ${NGINX_CONFIG}
69+
70+
# Check if the web terminal backend is running
71+
if [[ $(ps -eaf | grep -i hestia/web-terminal | sed '/^$/d' | wc -l) -gt 1 ]]; then
72+
$BIN/v-restart-service hestia-web-terminal
73+
fi
74+
75+
# Check if Hestia is running
76+
if [[ $(ps -eaf | grep -i hestia | sed '/^$/d' | wc -l) -gt 1 ]]; then
77+
$BIN/v-restart-service hestia
78+
fi
79+
fi
80+
81+
#----------------------------------------------------------#
82+
# Hestia #
83+
#----------------------------------------------------------#
84+
85+
# Logging
86+
$BIN/v-log-action "system" "Warning" "System" "Hestia Control Panel web terminal port changed (New Value: $PORT, Old Value: $ORIGINAL_PORT)."
87+
log_event "$OK" "$ARGUMENTS"
88+
89+
exit

bin/v-delete-sys-web-terminal

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/bin/bash
2+
# info: delete web terminal
3+
# options: NONE
4+
#
5+
# example: v-delete-sys-web-terminal
6+
#
7+
# This function disables the web terminal.
8+
9+
#----------------------------------------------------------#
10+
# Variables & Functions #
11+
#----------------------------------------------------------#
12+
13+
# Includes
14+
# shellcheck source=/etc/hestiacp/hestia.conf
15+
source /etc/hestiacp/hestia.conf
16+
# shellcheck source=/usr/local/hestia/func/main.sh
17+
source $HESTIA/func/main.sh
18+
# load config file
19+
source_conf "$HESTIA/conf/hestia.conf"
20+
21+
#----------------------------------------------------------#
22+
# Verifications #
23+
#----------------------------------------------------------#
24+
25+
if [ -z "$WEB_TERMINAL" ]; then
26+
exit
27+
fi
28+
29+
# Perform verification if read-only mode is enabled
30+
check_hestia_demo_mode
31+
32+
#----------------------------------------------------------#
33+
# Action #
34+
#----------------------------------------------------------#
35+
36+
# Updating WEB_TERMINAL value
37+
$BIN/v-change-sys-config-value "WEB_TERMINAL" "false"
38+
39+
# Stopping web terminal websocket server
40+
$BIN/v-stop-service "hestia-web-terminal"
41+
systemctl disable hestia-web-terminal
42+
43+
#----------------------------------------------------------#
44+
# Hestia #
45+
#----------------------------------------------------------#
46+
47+
# Logging
48+
$BIN/v-log-action "system" "Warning" "Web Terminal" "Web terminal disabled."
49+
log_event "$OK" "$ARGUMENTS"
50+
51+
exit

0 commit comments

Comments
 (0)