Browse Source

Sync with upstream development branch

Kristan Kenney 6 years ago
parent
commit
065bf9b67f
5 changed files with 67 additions and 79 deletions
  1. 5 25
      bin/v-add-sys-sftp-jail
  2. 18 18
      bin/v-add-user-sftp-jail
  3. 5 9
      bin/v-delete-sys-sftp-jail
  4. 22 17
      bin/v-delete-user-sftp-jail
  5. 17 10
      src/hst_autocompile.sh

+ 5 - 25
bin/v-add-sys-sftp-jail

@@ -27,7 +27,7 @@ source $HESTIA/conf/hestia.conf
 # Checking sshd directives
 config='/etc/ssh/sshd_config'
 sftp_n=$(grep -n "Subsystem.*sftp" $config |grep -v internal |grep -v ":#")
-sftp_i=$(grep -n "Subsystem.*sftp" $config |grep internal |grep -v ":#")
+sftp_i=$(grep -n "^# Hestia SFTP Chroot" $config)
 
 # Disabling normal sftp
 if [ ! -z "$sftp_n" ]; then
@@ -39,11 +39,11 @@ fi
 # Enabling jailed sftp
 if [ -z "$sftp_i" ]; then
     echo " " >> $config
-    echo "Subsystem sftp internal-sftp" >> $config
-    echo "Match Group sftp-only" >> $config
-    echo "ChrootDirectory /chroot/%u" >> $config
-    echo "    AllowTCPForwarding no" >> $config
+    echo "# Hestia SFTP Chroot" >> $config
+    echo "Match User sftp_dummy99" >> $config
+    echo "ChrootDirectory %h" >> $config
     echo "    X11Forwarding no" >> $config
+    echo "    AllowTCPForwarding no" >> $config
     echo "    ForceCommand internal-sftp" >> $config
     restart='yes'
 fi
@@ -63,32 +63,12 @@ if [ "$restart" = 'yes' ]; then
     fi
 fi
 
-# Adding sftp group
-groupadd sftp-only 2>/dev/null
-
 # Checking users
 shells="rssh|nologin"
 for user in $(grep "$HOMEDIR" /etc/passwd |egrep "$shells" |cut -f 1 -d:); do
     $BIN/v-add-user-sftp-jail $user
 done
 
-# Adding v-add-sys-sftp-jail to startup
-if [ -e "/etc/rc.local" ]; then
-    check_sftp=$(grep $0 /etc/rc.local)
-    check_exit=$(grep ^exit /etc/rc.local)
-    if [ -z "$check_sftp" ]; then
-        if [ -z "$check_exit" ]; then
-            echo "$BIN/v-add-sys-sftp-jail" >> /etc/rc.local
-        else
-            sed -i "s|^exit|$BIN/v-add-sys-sftp-jail\nexit|" /etc/rc.local
-        fi
-    fi
-    chmod +x /etc/rc.local
-else
-    echo "$BIN/v-add-sys-sftp-jail" > /etc/rc.local
-    chmod +x /etc/rc.local
-fi
-
 #----------------------------------------------------------#
 #                       Hestia                             #
 #----------------------------------------------------------#

+ 18 - 18
bin/v-add-user-sftp-jail

@@ -33,36 +33,36 @@ if [ $user = "syslog" ]; then
     exit
 fi
 
+# Get current users and split into array
+ssh_users=$(grep -A1 "^# Hestia SFTP Chroot" /etc/ssh/sshd_config | sed -n 2p | sed 's/Match User //')
+IFS=',' read -r -a users <<< "$ssh_users"
+
+# Check if jail is already enabled
+if [[ ! " ${users[@]} " =~ " ${user} " ]]; then
+    exit
+fi
+
 
 #----------------------------------------------------------#
 #                       Action                             #
 #----------------------------------------------------------#
 
-# Defining user homedir
-home="$(echo $user_str |cut -f 6 -d :)"
+# Add user to array
+users+=($user)
 
-# Adding chroot directory
-if [ ! -d "/chroot/$user/$home" ]; then
-    mkdir -p /chroot/$user/$home
-    chmod 750 /chroot/$user
-    chmod 775 /chroot/$user/$home
-    chown root:sftp-only /chroot/$user
-    chown $user:sftp-only /chroot/$user/$home
-fi
-
-# Adding user to sftp group
-usermod -a -G sftp-only $user
-
-# Mouting home directory
-if [ -z "$(mount |grep /chroot/$user/$home)" ]; then
-    mount -o bind $home /chroot/$user/$home/
-fi
+# Write new user list to config
+users=$(IFS=',';echo "${users[*]// /|}";IFS=$' \t\n')
+sed -i "s/$ssh_users/$users/g" /etc/ssh/sshd_config
 
 
 #----------------------------------------------------------#
 #                       Hestia                             #
 #----------------------------------------------------------#
 
+# Restart ssh service
+service ssh restart > /dev/null 2>&1
+service sshd restart > /dev/null 2>&1
+
 # Logging
 log_event "$OK" "$ARGUMENTS"
 

+ 5 - 9
bin/v-delete-sys-sftp-jail

@@ -27,15 +27,10 @@ source $HESTIA/conf/hestia.conf
 #                       Action                             #
 #----------------------------------------------------------#
 
-# Checking users
-for user in $(grep "$HOMEDIR" /etc/passwd |cut -f 1 -d:); do
-    $BIN/v-delete-user-sftp-jail $user
-done
-
 # Checking sshd directives
 config='/etc/ssh/sshd_config'
 sftp_n=$(grep -n "Subsystem.*sftp" $config |grep -v internal |grep ":#")
-sftp_i=$(grep -n "Subsystem.*sftp" $config |grep internal |grep -v ":#")
+sftp_i=$(grep -n "^# Hestia SFTP Chroot" $config)
 
 # Backing up config
 cp $config $config.bak-$(date +%s)
@@ -70,14 +65,15 @@ if [ "$restart" = 'yes' ]; then
     fi
 fi
 
-# Deleting v-add-sys-sftp-jail from startup
-sed -i "/v-add-sys-sftp-jail/d" /etc/rc.local 2>/dev/null
-
 
 #----------------------------------------------------------#
 #                       Hestia                             #
 #----------------------------------------------------------#
 
+# Restart ssh service
+service ssh restart > /dev/null 2>&1
+service sshd restart > /dev/null 2>&1
+
 # Logging
 log_event "$OK" "$ARGUMENTS"
 

+ 22 - 17
bin/v-delete-user-sftp-jail

@@ -28,35 +28,40 @@ if [ -z "$user_str" ]; then
     exit
 fi
 
+# Get current users and split into array
+ssh_users=$(grep -A1 "^# Hestia SFTP Chroot" /etc/ssh/sshd_config | sed -n 2p | sed 's/Match User //')
+IFS=',' read -r -a users <<< "$ssh_users"
+
+# Check if jail exist
+if [[ ! " ${users[@]} " =~ " ${user} " ]]; then
+    exit
+fi
+
+
 #----------------------------------------------------------#
 #                       Action                             #
 #----------------------------------------------------------#
 
-# Defining user homedir
-home="$(echo $user_str |cut -f 6 -d :)"
-
-# Unmounting home directory
-mount_dir=$(mount |grep /chroot/$user/ |awk '{print $3}')
-if [ ! -z "$mount_dir" ]; then
-    umount -f $mount_dir 2>/dev/null
-    if [ $? -ne 0 ]; then
-        gpasswd -d $user sftp-only >/dev/null 2>&1
-        exit 1
+# Remove user from array
+for sftp_user in "${users[@]}"; do
+    if [ "$sftp_user" != "$user" ]; then
+        new_users+=($sftp_user)
     fi
-fi
+done
 
-# Deleting chroot dir
-rmdir $mount_dir 2>/dev/null
-rm -rf /chroot/$user
-
-# Deleting user from sftp group
-gpasswd -d $user sftp-only >/dev/null 2>&1
+# Write new user list to config
+users=$(IFS=',';echo "${new_users[*]// /|}";IFS=$' \t\n')
+sed -i "s/$ssh_users/$users/g" /etc/ssh/sshd_config
 
 
 #----------------------------------------------------------#
 #                       Hestia                             #
 #----------------------------------------------------------#
 
+# Restart ssh service
+service ssh restart > /dev/null 2>&1
+service sshd restart > /dev/null 2>&1
+
 # Logging
 #log_event "$OK" "$ARGUMENTS"
 

+ 17 - 10
src/hst_autocompile.sh

@@ -54,6 +54,9 @@ if [ ! -e /usr/local/include/curl ]; then
     ln -s /usr/include/x86_64-linux-gnu/curl /usr/local/include/curl
 fi
 
+# Get system cpu cores
+NUM_CPUS=$(grep "^cpu cores" /proc/cpuinfo | uniq |  awk '{print $4}')
+
 # Set packages to compile
 for arg; do
     case "$1" in
@@ -113,6 +116,8 @@ PHP='http://de2.php.net/distributions/php-'$PHP_V'.tar.gz'
 #################################################################################
 
 if [ "$NGINX_B" = true ] ; then
+
+    echo "Building hestia-nginx package..."
     # Change to build directory
     cd $BUILD_DIR
 
@@ -146,14 +151,13 @@ if [ "$NGINX_B" = true ] ; then
                   --with-pcre-jit \
                   --with-zlib=../zlib-$ZLIB_V
 
-    # Check install directory and move if exists
-    if [ -d $INSTALL_DIR ]; then
-          #mv $INSTALL_DIR $INSTALL_DIR$(timestamp)
-          rm -r $INSTALL_DIR
+    # Check install directory and remove if exists
+    if [ -d "$BUILD_DIR$INSTALL_DIR" ]; then
+          rm -r "$BUILD_DIR$INSTALL_DIR"
     fi
 
     # Create the files and install them
-    make && make install
+    make -j $NUM_CPUS && make DESTDIR=$BUILD_DIR install
 
     # Cleare up unused files
     cd $BUILD_DIR
@@ -175,7 +179,7 @@ if [ "$NGINX_B" = true ] ; then
 
     # Move nginx directory
     cd ..
-    mv /usr/local/hestia/nginx usr/local/hestia/
+    mv $BUILD_DIR/usr/local/hestia/nginx usr/local/hestia/
 
     # Get Service File
     cd etc/init.d
@@ -208,6 +212,7 @@ fi
 #################################################################################
 
 if [ "$PHP_B" = true ] ; then
+    echo "Building hestia-php package..."
     # Change to build directory
     cd $BUILD_DIR
 
@@ -218,7 +223,7 @@ if [ "$PHP_B" = true ] ; then
     fi
 
     # Create directory
-    mkdir $BUILD_DIR/hestia-php_$PHP_V
+    mkdir ${BUILD_DIR}/hestia-php_$PHP_V
 
     # Download and unpack source files
     wget -qO- $PHP | tar xz
@@ -237,7 +242,7 @@ if [ "$PHP_B" = true ] ; then
                 --enable-mbstring
 
     # Create the files and install them
-    make && make install
+    make -j $NUM_CPUS && make INSTALL_ROOT=$BUILD_DIR install
 
     # Cleare up unused files
     cd $BUILD_DIR
@@ -254,7 +259,7 @@ if [ "$PHP_B" = true ] ; then
 
     # Move php directory
     cd ..
-    mv /usr/local/hestia/php usr/local/hestia/
+    mv ${BUILD_DIR}/usr/local/hestia/php usr/local/hestia/
 
     # Get php-fpm.conf
     wget $GIT_REP/php/php-fpm.conf -O usr/local/hestia/php/etc/php-fpm.conf
@@ -283,6 +288,7 @@ fi
 #################################################################################
 
 if [ "$HESTIA_B" = true ] ; then
+    echo "Building Hestia Control Panel package..."
     # Change to build directory
     cd $BUILD_DIR
 
@@ -339,7 +345,8 @@ fi
 #
 #################################################################################
 
-if [ "$install" = 'yes' ] || [ "$install" = 'YES' ] || [ "$install" = 'y' ] || [ "$install" = 'Y' ]; then
+if [ "$install" = 'yes' ] || [ "$install" = 'y' ]; then
+    echo "Installing packages..."
     for i in $DEB_DIR/*.deb; do
       # Install all available packages
       dpkg -i $i