D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
opt
/
psa
/
admin
/
sbin
/
modules
/
ssh-terminal
/
Filename :
installer
back
Copy
#!/bin/bash -e ### Copyright 1999-2024. WebPros International GmbH. All rights reserved. cd "`dirname "$0"`" sshd_systemd_name() { if [ "`plesk sbin osdetect --pkg`" = "deb" ]; then echo "ssh" else echo "sshd" fi } systemd_unit_dir() { if [ "`plesk sbin osdetect --pkg`" = "deb" ]; then echo "/lib/systemd/system" else echo "/usr/lib/systemd/system" fi } get_arch_for_systemd() { local arch="`plesk sbin osdetect --arch`" case "$arch" in aarch64) echo "arm64" ;; x86_64) echo "x86-64" ;; *) echo "$arch" ;; esac } user_name="plesk-ssh-terminal" group_name="$user_name" home="/usr/local/psa/var/modules/ssh-terminal" service_name="plesk-ssh-terminal" unit_template="/usr/local/psa/admin/plib/modules/ssh-terminal/resources/config/plesk-ssh-terminal.service" unit_file="`systemd_unit_dir`/$service_name.service" unit_drop_in="/etc/systemd/system/$service_name.service.d/options.conf" sshd_name="`sshd_systemd_name`" case "$1" in --create-user) if ! id "$user_name" >/dev/null 2>&1; then echo "Adding user and group $user_name" useradd --system --user-group --shell /usr/sbin/nologin --home "$home" \ --comment "Plesk SSH Terminal" \ "$user_name" # SSH tries to create .ssh on client side and emits warning if unable, avoid this install -d -m 0700 -o "$user_name" -g "$group_name" "$home/.ssh" fi if ! id -nG "sw-cp-server" | grep -q "$group_name"; then gpasswd -a "sw-cp-server" "$group_name" plesk sbin pleskrc sw-cp-server reload fi if ! id -nG "psaadm" | grep -q "$group_name"; then gpasswd -a "psaadm" "$group_name" plesk sbin pleskrc sw-engine reload fi ;; --delete-user) if id -nG "psaadm" | grep -q "$group_name"; then gpasswd -d "psaadm" "$group_name" # Removal from UI is synchronous, so no reload here to avoid breaking the request fi if id -nG "sw-cp-server" | grep -q "$group_name"; then gpasswd -d "sw-cp-server" "$group_name" plesk sbin pleskrc sw-cp-server reload fi if id "$user_name" >/dev/null 2>&1; then echo "Removing user and group $user_name" userdel --force "$user_name" # Home directory contents will be removed by Plesk as part of extension uninstall fi ;; --is-sshd-active) if systemctl is-active -q "$sshd_name.socket"; then true else plesk sbin pleskrc "$sshd_name" status fi ;; --update-configuration) if systemctl is-active -q "$sshd_name.socket"; then SSHD_LISTENS_ON="$(systemctl show "$sshd_name.socket" -p Listen \ | cut -d= -f2 | cut -d' ' -f1 | head -n1)" else SSHD_LISTENS_ON="$(lsof -nP -a -i TCP -s TCP:LISTEN \ -p "`systemctl show "$sshd_name.service" -p MainPID | cut -d= -f2`" \ | awk '(NR > 1) {print $9; exit}')" fi if [ -n "$SSHD_LISTENS_ON" ]; then echo "Configuring to connect to $SSHD_LISTENS_ON" mkdir -p "`dirname "$unit_drop_in"`" cat > "$unit_drop_in" <<-EOT # Created by $0 $* [Service] Environment="OPTIONS=--connect-to $SSHD_LISTENS_ON" EOT /bin/systemctl daemon-reload else echo "Skipping configuration update: cannot detect address:port sshd listens on" fi ;; --remove-configuration) rm -f "$unit_drop_in" || : rmdir --ignore-fail-on-non-empty "`dirname "$unit_drop_in"`" || : ;; --enable-service) ARCH="`get_arch_for_systemd`" SERVICE_ACTION="try-restart" [ -f "$unit_file" ] || SERVICE_ACTION="start" sed -e "s/@ARCH@/$ARCH/g" "$unit_template" | cmp -s "$unit_file" - || { sed -e "s/@ARCH@/$ARCH/g" "$unit_template" > "$unit_file" # This also implicitly does 'systemctl daemon-reload', required on unit update plesk sbin register_service --enable "$service_name" } plesk sbin pleskrc "$service_name" "$SERVICE_ACTION" ;; --disable-service) plesk sbin pleskrc "$service_name" "stop" || : plesk sbin register_service --disable "$service_name" || : rm -f "$unit_file" || : ;; -h|--help|*) cat <<-EOT Usage: `basename "$0"` [OPTIONS] Options: --create-user Create the user and group for SSH terminal --delete-user Delete the user and group for SSH terminal --update-configuration Update daemon configuration according to current system settings, including address:port of sshd daemon to connect to --remove-configuration Remove daemon configuration --enable-service Install, enable, and start the daemon unit --disable-service Stop, disable, and remove the daemon unit --is-sshd-active Check if SSH daemon is ready to accept connections -h, --help Show this help EOT exit 1 ;; esac