diff --git a/.DS_Store b/.DS_Store index 4bed96c06..db680f6a4 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/CPScripts/EasyEngine/EasyEngine-migration.sh b/CPScripts/EasyEngine/EasyEngine-migration.sh new file mode 100644 index 000000000..c029e5e8b --- /dev/null +++ b/CPScripts/EasyEngine/EasyEngine-migration.sh @@ -0,0 +1,472 @@ +#!/bin/bash + +#EasyEngine to CyberPanel migration script + +sudoer="" +server_port="22" +user_name="root" +RED='\033[0;31m' +NC='\033[0m' +DIR="/opt/easyengine" +DIR_SSL="/opt/easyengine/services/nginx-proxy/certs" +DIR_TMP="/opt/easyengine/tmp" +SSL="0" +owner_user="" +owner_group="" + +set_header() { +if [[ -d /opt/easyengine/sites/${domains[$i]}/app/htdocs/wp-content ]] ; then +ssh -o StrictHostKeyChecking=no root@$server_ip -p$server_port -i /root/.ssh/cyberpanel_migration_key "$sudoer wget -q -O /root/header.sh https://raw.githubusercontent.com/usmannasir/cyberpanel/stable/CPScripts/EasyEngine/header.sh ; $sudoer bash /root/header.sh ${domains[$i]}" +fi +} + +fix_permission() { +ssh_v="ssh -o StrictHostKeyChecking=no root@$server_ip -p$server_port -i /root/.ssh/cyberpanel_migration_key" +echo -e "\nget the user and group on remote CyberPanel server...." +owner_user=$(${ssh_v} stat -c '%U' /home/${domains[$i]}) +owner_group=$(${ssh_v} stat -c '%G' /home/${domains[$i]}) +#get user and group on remote server. +} + + +set_ssl_cyberpanel() { +if [[ $SSL == "1" ]] ; then + echo -e "\nstarting certificate and private key transfer..." +ssh_v="ssh -o StrictHostKeyChecking=no root@$server_ip -p$server_port -i /root/.ssh/cyberpanel_migration_key" +${ssh_v} "rm -f /etc/letsencrypt/live/${domains[$i]}/fullchain.pem" +${ssh_v} "rm -f /etc/letsencrypt/live/${domains[$i]}/privkey.pem" +#remove current self-signed cert + +rsync --stats -av -e "ssh -o StrictHostKeyChecking=no -p $server_port -i /root/.ssh/cyberpanel_migration_key" $cert_file root@$server_ip:/etc/letsencrypt/live/${domains[$i]}/fullchain.pem + if [[ $? == "0" ]] ; then + echo -e "\ncert file transferred...\n" + else + echo -e "\ncert file trasnfer failed..." + clean_up + exit + fi + +rsync --stats -av -e "ssh -o StrictHostKeyChecking=no -p $server_port -i /root/.ssh/cyberpanel_migration_key" $key_file root@$server_ip:/etc/letsencrypt/live/${domains[$i]}/privkey.pem + if [[ $? == "0" ]] ; then + echo -e "\nkey file has been succesfully transferred to CyberPanel server...\n" + else + echo -e "\nkey file trasnfer failed..." + clean_up + exit + fi +#rsync cert and key + +echo -e "checking LiteSpeed status on remote Cyebrpanel server..." +${ssh_v} "/usr/local/lsws/bin/lswsctrl stop" +${ssh_v} "pkill lsphp" +${ssh_v} "systemctl stop lsws" +${ssh_v} "systemctl start lsws" +check_string=$(${ssh_v} "ps -aux | grep litespeed | grep -v grep") + if echo $check_string | grep -q litespeed ; then + echo -e "\nrestart LiteSpeed successful..." + else + echo -e "LiteSpeed start failed..." + fi +fi +#restart LSWS to apply new cert + +} + +show_cyberpanel_site() { + echo -e "\nchecking current websites on remote CyberPanel server..." + ssh_v="ssh -o StrictHostKeyChecking=no root@$server_ip -p$server_port -i /root/.ssh/cyberpanel_migration_key" + $ssh_v "cyberpanel listWebsitesPretty" +} + +create_database() { + echo -e "\nstarting database creation on remote CyberPanel server..." + ssh_v="ssh -o StrictHostKeyChecking=no root@$server_ip -p$server_port -i /root/.ssh/cyberpanel_migration_key" + + check_string=$(${ssh_v} "cyberpanel createDatabase --databaseWebsite ${domains[$i]} --dbName $WPDBNAME --dbUsername $WPDBUSER --dbPassword $WPDBPASS") + if echo $check_string | grep -q "None" ; then + echo -e "\ndatabase successfully created..." + else + echo -e "\ndatabase failed to create..." + clean_up + exit + fi + + check_string=$(${ssh_v} "mysql -u $WPDBUSER -p$WPDBPASS $WPDBNAME < /home/${domains[$i]}/$database_name ; if [ $? = 0 ] ; then echo "OK" ; fi") + if echo $check_string | grep -q "OK" ; then + echo -e "\nstarting database import on remote CyberPanel..." + echo -e "\ndatabase successfully imported..." + ${ssh_v} rm -f /home/${domains[$i]}/$database_name + else + echo -e "\ndatabase import failed..." + ${ssh_v} rm -f /home/${domains[$i]}/$database_name + clean_up + exit + fi + +# ${ssh_v} sed -i 's|global-db:3306|localhost:3306|g' /home/${domains[$i]}/public_html/wp-config.php + + ${ssh_v} "sed -i 's|global-db:3306|/var/lib/mysql/mysql.sock|g' /home/${domains[$i]}/public_html/wp-config.php" + #set DB HOST to local unix socket for better performance. + +} + +clean_up() { +#remove all the files created during operation +echo -e "\nstarting clean up process..." +ssh -o StrictHostKeyChecking=no root@$server_ip -p$server_port -i /root/.ssh/cyberpanel_migration_key "$sudoer wget -q -O /root/key.sh https://raw.githubusercontent.com/usmannasir/cyberpanel/stable/CPScripts/EasyEngine/key.sh ; $sudoer bash /root/key.sh disable" +rm -f /root/.ssh/cyberpanel_migration_key +rm -rf /opt/easyengine/tmp +echo -e "\nclean up successful..." +} + +create_site_cyberpanel() { +ssh_v="ssh -o StrictHostKeyChecking=no root@$server_ip -p$server_port -i /root/.ssh/cyberpanel_migration_key" +echo -e "\nstarting to create ${domains[$i]} on remote CyberPanel server..." +echo -e "\nyou may see error message on acme.sh but this is normal as actual DNS is not pointed to remote server.\n\n\n" +check_string=$(${ssh_v} "cyberpanel createWebsite --package Default --owner admin --domainName ${domains[$i]} --email admin@${domains[$i]} --php 7.4 --ssl 1") + if echo $check_string | grep -q "None" ; then + echo -e "\nwebsite successfully created..." + ${ssh_v} "rm -f /home/${domains[$i]}/public_html/index.html" + ${ssh_v} "cat << EOF > /home/${domains[$i]}/public_html/.htaccess +RewriteCond %{REQUEST_URI} (wp-config|readme|license|example)\.(txt|html) [NC,OR] +RewriteCond %{REQUEST_URI} wp-content\/uploads\/.*php [NC,OR] +RewriteCond %{REQUEST_URI} (^\.|/\.) [NC] +RewriteRule .* - [F,L] +#EasyEnine converted equivalent rule. + + +RewriteEngine On +RewriteBase / +RewriteRule ^index\.php$ - [L] +RewriteCond %{REQUEST_FILENAME} !-f +RewriteCond %{REQUEST_FILENAME} !-d +RewriteRule . /index.php [L] + +#WordPress default rule. +EOF" +#rewrite rule for similar effect on easyengine configuration. + + else + echo -e "\nfailed to create website..." + echo -e "\nplease check if ${domains[$i]} is already created on remote server, and delete it" + clean_up + exit + fi +} + +trasnfer_file() { +ssh_v="ssh -o StrictHostKeyChecking=no root@$server_ip -p$server_port -i /root/.ssh/cyberpanel_migration_key" +if [[ -f /opt/easyengine/sites/${domains[$i]}/app/wp-config.php ]] ; then + echo -e "\nstarting to transfer files..." + echo -e "\ndepends on your files , this may take a while..." + rsync --stats -av --chown=${owner_user}:${owner_group} -e "ssh -o StrictHostKeyChecking=no -p $server_port -i /root/.ssh/cyberpanel_migration_key" /opt/easyengine/sites/${domains[$i]}/app/wp-config.php root@$server_ip:/home/${domains[$i]}/public_html/wp-config.php + if [[ $? == "0" ]] ; then + echo -e "\nwp-config.php successfully transferred..." + else + echo -e "\nwp-config.php trasnfer failed..." + clean_up + exit + fi + +rsync --stats -av --chown=${owner_user}:${owner_group} -e "ssh -o StrictHostKeyChecking=no -p $server_port -i /root/.ssh/cyberpanel_migration_key" /opt/easyengine/sites/${domains[$i]}/app/htdocs/ root@$server_ip:/home/${domains[$i]}/public_html/ + if [[ $? == "0" ]] ; then + echo -e "\nsite files succesfully transferred..." + else + echo -e "\nsite files trasnfer failed..." + clean_up + exit + fi + +rsync --stats -av -e "ssh -o StrictHostKeyChecking=no -p $server_port -i /root/.ssh/cyberpanel_migration_key" $OUTPUT/$database_name root@$server_ip:/home/${domains[$i]}/$database_name + if [[ $? == "0" ]] ; then + echo -e "\ndatabase dump successfully transferred..." + else + echo -e "\ndatabase dump trasnfer failed..." + clean_up + exit + fi + +else + echo -e "\nthe script currently only works with Wordpress site..." + clean_up + exit +fi +} + +export_cert() { +echo -e "\nstarting to search certificates and private keys..." +if [[ -f $DIR_SSL/${domains[$i]}.crt ]] && [[ -f $DIR_SSL/${domains[$i]}.key ]] ; then + echo -e "\n${domains[$i]} cert detected..." + echo -e "\n${domains[$i]} key detected..." + SSL="1" + cert_file="$DIR_SSL/${domains[$i]}.crt" + key_file="$DIR_SSL/${domains[$i]}.key" +else + SSL="0" + echo -e "\n${domains[$i]} cert not found..." + echo -e "\n${domains[$i]} key not found..." +fi +} + + +fetch_cyberpanel_key() { +if [[ ! -d /root/.ssh ]] ; then + mkdir /root/.ssh + chmod 700 /root/.ssh +fi +echo -e "\nPlease input your CyberPanel server address" +printf "%s" "Server Address: " +read server_ip + if [[ $server_ip == "" ]] ; then + echo -e "\nPlease enter a valid address" + exit + fi +echo -e "\nremote server is set to $server_ip..." +echo -e "\nPlease input your CyberPanel server SSH port" +echo -e "Press Enter key to use port 22 as default." +printf "%s" "SSH port: " +read server_port + re='^[0-9]+$' + if [[ $server_port == "" ]] ; then + server_port="22" + elif [[ ! $server_port =~ $re ]] ; then + echo -e "\nPlease input a valid port number." + fi +echo -e "\nSSH port is set to $server_port..." +echo -e "\nPlease input the user name , this must be root user or sudo user." +echo -e "Press Enter key to use root user as default." +printf "%s" "Username: " +read user_name + if [[ $user_name == "" ]] ; then + echo -e "\nset username to root..." + user_name="root" + sudoer="" + elif [[ $user_name == "root" ]] ; then + sudoer="" + else + sudoer="sudo -S" + fi +#ask user to input server IP , port and user name + +echo -e "\nlogin username is set to $user_name" +if grep -q "PRIVATE KEY" /root/.ssh/cyberpanel_migration_key 2>/dev/null ; then + status=$(ssh -o BatchMode=yes -o ConnectTimeout=5 -o StrictHostKeyChecking=no root@$server_ip -p$server_port -i /root/.ssh/cyberpanel_migration_key echo ok 2>&1) + if [[ $status == ok ]] ; then + echo -e "\nvalid key detected..." + return + else + echo -e "\nunable to connect to remote server..." + clean_up + exit + fi +fi + +echo -e "\nPlease input the password , if you are using public key authentication,please press Enter key." +printf "%s" "Password: " +stty -echo +read password +stty echo +echo "" + +if [[ $password == "" ]] ; then +echo -e "\nPlease input the private key file with absolute path" +echo -e "\ne.g. /root/.ssh/id_rsa" +printf "%s" "key path: " +read password +fi + +if [[ $password == "" ]] ; then +echo -e "Please enter a valid path." +exit +fi + +if [[ -f $password ]] ; then +#check the input , if it's a file , consider it as key. + ssh -o StrictHostKeyChecking=no $user_name@$server_ip -p$server_port -i $password "$sudoer wget -q -O /root/key.sh https://raw.githubusercontent.com/usmannasir/cyberpanel/stable/CPScripts/EasyEngine/key.sh ; $sudoer bash /root/key.sh enable" + if [[ $? == "0" ]] ; then + ssh -o StrictHostKeyChecking=no $user_name@$server_ip -p$server_port -i $password "$sudoer cat /root/.ssh/cyberpanel_migration_key" > /root/.ssh/cyberpanel_migration_key + if [[ $? == "0" ]] ; then + chmod 400 /root/.ssh/cyberpanel_migration_key + status=$(ssh -o BatchMode=yes -o ConnectTimeout=5 -o StrictHostKeyChecking=no root@$server_ip -p$server_port -i /root/.ssh/cyberpanel_migration_key echo ok 2>&1) + if [[ $status == ok ]] ; then + echo -e "\nvalid key detected..." + else + echo -e "\nunabel to connect remote server..." + clean_up + exit + fi + else + clean_up + echo -e "\nunable to set remote key..." + exit + fi + else + echo -e "\nunable to set up the key, please manually set it up..." + clean_up + exit + fi +else +#if it's not file , consider it as password + sshpass -p "${password}" ssh -o StrictHostKeyChecking=no $user_name@$server_ip -p$server_port "$sudoer wget -q -O /root/key.sh https://raw.githubusercontent.com/usmannasir/cyberpanel/stable/CPScripts/EasyEngine/key.sh ; $sudoer bash /root/key.sh enable" + if [[ $? == "0" ]] ; then + sshpass -p "${password}" ssh -o StrictHostKeyChecking=no $user_name@$server_ip -p$server_port "$sudoer cat /root/.ssh/cyberpanel_migration_key" > /root/.ssh/cyberpanel_migration_key + chmod 400 /root/.ssh/cyberpanel_migration_key + status=$(ssh -o BatchMode=yes -o ConnectTimeout=5 -o StrictHostKeyChecking=no root@$server_ip -p$server_port -i /root/.ssh/cyberpanel_migration_key echo ok 2>&1) + if [[ $status == ok ]] ; then + echo -e "\nvalid key detected..." + else + echo -e "\nunabel to connect remote server..." + clean_up + exit + fi + else + echo -e "\nunable to set up the key, please manually set it up..." + clean_up + exit + fi +fi +} + +install_lscwp() { +ssh_v="ssh -o StrictHostKeyChecking=no root@$server_ip -p$server_port -i /root/.ssh/cyberpanel_migration_key" +$ssh_v "sudo -u $owner_user -i -- wp --path=/home/${domains[$i]}/public_html plugin install litespeed-cache" +echo -e "\nInstalling LiteSpeed Cache for WordPress..." +} + +export_database() { +WPDBNAME=`cat /opt/easyengine/sites/${domains[$i]}/app/wp-config.php | grep DB_NAME | cut -d \' -f 4` +WPDBUSER=`cat /opt/easyengine/sites/${domains[$i]}/app/wp-config.php | grep DB_USER | cut -d \' -f 4` +WPDBPASS=`cat /opt/easyengine/sites/${domains[$i]}/app/wp-config.php | grep DB_PASSWORD | cut -d \' -f 4` +#get database name , user and password for mysqldump + +echo -e "\nstarting to export database..." +USER="root" +PASSWORD=`cat /opt/easyengine/services/docker-compose.yml | grep MYSQL_ROOT_PASSWORD | awk -F'=' '{print $2}'` +OUTPUT="$DIR_TMP/database" +DOCKERDatabaseID=`docker ps | grep -e 'services_global-db' | cut -c1-12;` + +databases=`docker exec $DOCKERDatabaseID bash -c "mysql -h localhost --user=$USER --password=$PASSWORD -e 'show databases;'" | tr -d "| " | grep -v Database` + +for db in $databases; do + if [[ $db == "$WPDBNAME" ]] ; then + echo -e "\ndumping database for ${domains[$i]}..." + sudo docker exec $DOCKERDatabaseID bash -c "/usr/bin/mysqldump -u $USER -p$PASSWORD --databases $db" > $OUTPUT/$db.sql + database_name="$db.sql" + if [[ $? == "0" ]] ; then + echo -e "\ndatabase successfully exported..." + else + echo -e "\nfailed to export database..." + clean_up + exit + fi + fi +done +#credit to https://community.easyengine.io/t/cant-create-mysqldump/12306 + +} + + +check_dir () { +if [[ ! -d /opt/easyengine/sites ]] ; then + echo -e "\ncan not detect sites directory..." + exit +fi + +if [[ -d $DIR_TMP ]] ; then + rm -rf $DIR_TMP +fi + mkdir $DIR_TMP + mkdir $DIR_TMP/database +} + +show_help() { +echo -e "\nEasyEngine to CyberPanel Migration Script" +echo -e "\nThis script will do:" +echo -e "\n1. Generate public key and private key for root user on remote CyberPanel server." +echo -e "2. Find the Wordpress sites hosting on this EasyEngine server" +echo -e "3. Export the site's database and its SSL cert/key if available and trasnfer to remote CyberPanel server." +echo -e "4. Create website with same domain on remote CyberPanel server and its related database." +echo -e "5. Import database dump and set up SSL cert/key if available" +echo -e "6. Download LiteSpeed Cache plugin for Wordpress, but it will not be enabled until you activate it." +echo -e "7. Install PHP extension sodium imagick redis and memcached." +echo -e "8. Once the migration process is completed, previously generated key will be removed on remote CyberPanel server." +echo -e "9. All the temporary generated files on this server will also be cleaned up." +echo -e "\nOnce migration is completed, you can use local host file to override the DNS record to test site on remote CyberPanel server" +echo -e "without effecting your live site" +echo -e "\nNo file on this server will be touched.\n" +read -rsn1 -p "Please press any key to continue..." +} + +check_dir +#check if this is an easyengine server and create a temp dir for storing files during the process. + +show_help + +declare -a domains + +for i in $(ls /opt/easyengine/sites); + do + domains=("${domains[@]}" "$i") + done + +echo -e "\n\nsearching websites..." +echo -e "\ntotal number of domains: ${#domains[@]}" +echo -e "\ndomain list: ${domains[@]}" + +dpkg -l sshpass > /dev/null +echo -e "\n\nchecking necessary package..." + if [[ $? == "0" ]] ; then + echo -e "\nsshpass package already installed...\n" + else + apt update + DEBIAN_FRONTEND=noninteractive apt install -y sshpass + if [[ $? == "0" ]] ; then + echo -e "\nsshpass successfully installed...\n" + else + echo -e "\nunable to install sshpass...\n" + exit + fi + fi + +fetch_cyberpanel_key + +#function to get cyberpanel server key so future SSH command won't require password input. + +tLen=${#domains[@]} +#get the domain list and number of domains. + +for (( i=0; i<${tLen}; i++ )); + do + # ${domains[$i]} , domain name variable + #create a file to save variable to source in cyberpanel server to read it. + + export_database + #dump all sites' database + + export_cert + #find the cert for this domain + + create_site_cyberpanel + + fix_permission + + trasnfer_file + + create_database + + set_header + + install_lscwp + + set_ssl_cyberpanel + done +#for loop to run each function for each domain. + +ssh -o StrictHostKeyChecking=no root@$server_ip -p$server_port -i /root/.ssh/cyberpanel_migration_key "$sudoer wget -q -O /root/ext.sh https://raw.githubusercontent.com/usmannasir/cyberpanel/stable/CPScripts/EasyEngine/ext.sh ; $sudoer bash /root/ext.sh" +#install some php ext + +show_cyberpanel_site + +clean_up +#remove all the files in tmp dir after script is done. +exit diff --git a/CPScripts/EasyEngine/ext.sh b/CPScripts/EasyEngine/ext.sh new file mode 100644 index 000000000..db01fbb1e --- /dev/null +++ b/CPScripts/EasyEngine/ext.sh @@ -0,0 +1,97 @@ +#!/bin/bash + +#script to install some lsphp74 extension + +SERVER_OS="" + + +hash yum 2>/dev/null + if [[ $? == "0" ]] ; then + echo -e "\nyum detected..." + SERVER_OS="CentOS" + fi + +hash apt 2>/dev/null + if [[ $? == "0" ]] ; then + echo -e "\napt detected..." + SERVER_OS="Ubuntu" + fi + +if [[ $SERVER_OS == "" ]] ; then + echo -e "\nunable to detect the system..." + exit +fi + + +if [[ ! -f /usr/local/lsws/lsphp74/lib64/php/modules/zip.so ]] && [[ $SERVER_OS == "CentOS" ]] ; then + yum list installed libzip-devel + if [[ $? == "0" ]] ; then + yum remove -y libzip-devel + fi + + yum install -y http://packages.psychotic.ninja/7/plus/x86_64/RPMS/libzip-0.11.2-6.el7.psychotic.x86_64.rpm + yum install -y http://packages.psychotic.ninja/7/plus/x86_64/RPMS/libzip-devel-0.11.2-6.el7.psychotic.x86_64.rpm + yum install -y lsphp74-devel + + if [[ ! -d /usr/local/lsws/lsphp74/tmp ]] ; then + mkdir /usr/local/lsws/lsphp74/tmp + fi + + /usr/local/lsws/lsphp74/bin/pecl channel-update pecl.php.net + /usr/local/lsws/lsphp74/bin/pear config-set temp_dir /usr/local/lsws/lsphp74/tmp + /usr/local/lsws/lsphp74/bin/pecl install zip + if [[ $? == 0 ]] ; then + echo "extension=zip.so" > /usr/local/lsws/lsphp74/etc/php.d/20-zip.ini + chmod 755 /usr/local/lsws/lsphp74/lib64/php/modules/zip.so + echo -e "\nInstalling lsphp74-zip" + else + echo -e "\nlsphp74-zip compilation failed..." + fi +fi + + +if [[ $SERVER_OS == "CentOS" ]] ; then + yum install -y lsphp74-redis + echo -e "\nInstalling lsphp74-redis" +else + DEBIAN_FRONTEND=noninteractive apt install -y lsphp74-redis + echo -e "\nInstalling lsphp74-redis" +fi + +if [[ $SERVER_OS == "CentOS" ]] ; then + yum install -y lsphp74-memcached + echo -e "\nInstalling lsphp74-memcached" +else + DEBIAN_FRONTEND=noninteractive apt install -y lsphp74-memcached + echo -e "\nInstalling lsphp74-memcached" +fi + +if [[ $SERVER_OS == "CentOS" ]] ; then + yum install -y lsphp74-imagick + echo -e "\nInstalling lsphp74-imagick" +else + DEBIAN_FRONTEND=noninteractive apt install -y lsphp74-imagick + echo -e "\nInstalling lsphp74-imagick" +fi + + + + +if [[ $SERVER_OS == "CentOS" ]] ; then + yum install -y lsphp74-sodium + echo -e "\nInstalling lsphp74-sodium" +else + mkdir /usr/local/lsws/cyberpanel-tmp + cd /usr/local/lsws/cyberpanel-tmp + DEBIAN_FRONTEND=noninteractive apt install -y libsodium-dev + wget -O libsodium.tgz http://pecl.php.net/get/libsodium + tar xzvf libsodium.tgz + cd libsodium-* + /usr/local/lsws/lsphp74/bin/phpize + ./configure --with-php-config=/usr/local/lsws/lsphp74/bin/php-config7.4 + make + make install + echo "extension=sodium.so" > /usr/local/lsws/lsphp74/etc/php/7.4/mods-available/20-sodium.ini + pkill lsphp74 + echo -e "\nInstalling lsphp74-sodium" +fi diff --git a/CPScripts/EasyEngine/header.sh b/CPScripts/EasyEngine/header.sh new file mode 100644 index 000000000..98f0ac5f0 --- /dev/null +++ b/CPScripts/EasyEngine/header.sh @@ -0,0 +1,89 @@ +#!/bin/bash + +set_header() { +if [[ -f /usr/local/lsws/conf/vhosts/$1/vhost.conf ]] ; then +cat << EOF > header.txt + +context /wp-content/cache/css/ { + location $DOC_ROOT/wp-content/cache/css/ + allowBrowse 1 + enableExpires 1 + expiresByType text/css=A15552000 + extraHeaders <<> /usr/local/lsws/conf/vhosts/$1/vhost.conf +fi +} + +if /usr/local/lsws/bin/lshttpd -v | grep -iF open ; then + echo -e "\nOpenLiteSpeed detected..." + set_header +else + echo -e "\nLiteSpeed Enterprise detected..." + exit + #LiteSpeed Enterprise can read htaccess for expire header, no need to set it up. +fi + +rm -f header.txt +rm -f $0 +echo -e "\nexpire , cache-control and CORS header set..." diff --git a/CPScripts/EasyEngine/key.sh b/CPScripts/EasyEngine/key.sh new file mode 100644 index 000000000..44846bab5 --- /dev/null +++ b/CPScripts/EasyEngine/key.sh @@ -0,0 +1,78 @@ +#!/bin/bash + +# script to set up access key for non-interactive SSH login + +check_root() { + if [[ $(id -u) != 0 ]] > /dev/null; then + echo -e "\nYou must use root permission...\n" + exit + fi +} + +key_generation() { +rm -f /root/.ssh/cyberpanel_migration_key +rm -f /root/.ssh/cyberpanel_migration_key.pub +ssh-keygen -t rsa -N "" -f /root/.ssh/cyberpanel_migration_key +if [[ -f /root/.ssh/authorized_keys ]] ; then + cp /root/.ssh/authorized_keys /root/.ssh/authorized_keys_migration + string=$(head -c 3 /root/.ssh/authorized_keys) + if [[ $string != "ssh" ]] ; then + #check if it's like AWS that prohibits direct root login. + rm -f /root/.ssh/authorized_keys + cat /root/.ssh/cyberpanel_migration_key.pub > /root/.ssh/authorized_keys + else + cat /root/.ssh/cyberpanel_migration_key.pub >> /root/.ssh/authorized_keys + fi +else + cat /root/.ssh/cyberpanel_migration_key.pub > /root/.ssh/authorized_keys + chmod 600 /root/.ssh/authorized_keys +fi + +echo -e "\nsuccessfully set up public key and private key for migration..." +# this function creates public key and private key +} + +ssh_config() { +rm -f /etc/ssh/sshd_config_migration +cp /etc/ssh/sshd_config /etc/ssh/sshd_config_migration +if grep -q "#PubkeyAuthentication yes" /etc/ssh/sshd_config ; then + sed -i 's|#PubkeyAuthentication yes|PubkeyAuthentication yes|g' /etc/ssh/sshd_config +fi +systemctl restart sshd +#this function will modify ssh configuration to allow public key login and root login +} + + +revert_change() { + if [[ ! -f /etc/ssh/sshd_config_migration ]] ; then + echo -e "You didn't enable it..." + exit + else + rm -f /root/.ssh/authorized_keys + rm -f /etc/ssh/sshd_config + rm -f /root/.ssh/cyberpanel_migration_key + rm -f /root/.ssh/cyberpanel_migration_key.pub + cp /etc/ssh/sshd_config_migration /etc/ssh/sshd_config + if [[ -f /root/.ssh/authorized_keys_migration ]] ; then + cp /root/.ssh/authorized_keys_migration /root/.ssh/authorized_keys + rm -f /root/.ssh/authorized_keys_migration + fi + systemctl restart sshd + fi +echo -e "\nsuccessfully removed public key and private key for migration..." + +#this function will revert the changes and restore backed up files. +} + +check_root + + +if [[ $1 == "enable" ]] ; then + ssh_config + key_generation +elif [[ $1 == "disable" ]] ; then + revert_change +else + echo -e "\nPlease use argument enable or disable" + echo -e "\ne.g. ./key.sh enable\n" +fi diff --git a/cyberpanel.sh b/cyberpanel.sh index 374ea596a..f34aa98f1 100644 --- a/cyberpanel.sh +++ b/cyberpanel.sh @@ -1597,4 +1597,4 @@ pip_virtualenv system_tweak -main_install +main_install \ No newline at end of file