mirror of
https://github.com/usmannasir/cyberpanel.git
synced 2026-01-06 15:42:06 +01:00
Initial commit for v2.4.3
This commit is contained in:
126
CPScripts/CyberpanelSnapshotByCyberpanelUser.sh
Normal file
126
CPScripts/CyberpanelSnapshotByCyberpanelUser.sh
Normal file
@@ -0,0 +1,126 @@
|
||||
#!/bin/bash
|
||||
## Author: Michael Ramsey
|
||||
## Objective Find A Cyberpanel Users Domlogs Stats for last 5 days for all of their domains. v2
|
||||
## https://gitlab.com/cyberpaneltoolsnscripts/snapshotbycyberpaneluser
|
||||
## How to use.
|
||||
# ./CyberpanelSnapshotByCyberpanelUser.sh username
|
||||
#./CyberpanelSnapshotCyberpanelUser.sh exampleuserbob
|
||||
#
|
||||
##bash <(curl -s https://gitlab.com/cyberpaneltoolsnscripts/snapshotbycyberpaneluser/-/raw/master/CyberpanelSnapshotByCyberpanelUser.sh || wget -qO - https://gitlab.com/cyberpaneltoolsnscripts/snapshotbycyberpaneluser/-/raw/master/CyberpanelSnapshotByCyberpanelUser.sh) exampleuserbob;
|
||||
##
|
||||
Username=$1
|
||||
|
||||
#CURRENTDATE=$(date +"%Y-%m-%d %T") # 2019-02-09 06:47:56
|
||||
#PreviousDay1=$(date --date='1 day ago' +"%Y-%m-%d") # 2019-02-08
|
||||
#PreviousDay2=$(date --date='2 days ago' +"%Y-%m-%d") # 2019-02-07
|
||||
#PreviousDay3=$(date --date='3 days ago' +"%Y-%m-%d") # 2019-02-06
|
||||
#PreviousDay4=$(date --date='4 days ago' +"%Y-%m-%d") # 2019-02-05
|
||||
|
||||
#datetimeDom=$(date +"%d/%b/%Y") # 09/Feb/2019
|
||||
#datetimeDom1DaysAgo=$(date --date='1 day ago' +"%d/%b/%Y") # 08/Feb/2019
|
||||
#datetimeDom2DaysAgo=$(date --date='2 days ago' +"%d/%b/%Y") # 07/Feb/2019
|
||||
#datetimeDom3DaysAgo=$(date --date='3 days ago' +"%d/%b/%Y") # 06/Feb/2019
|
||||
#datetimeDom4DaysAgo=$(date --date='4 days ago' +"%d/%b/%Y") # 05/Feb/2019
|
||||
|
||||
#Domlog Date array for past 5 days
|
||||
declare -a datetimeDomLast5_array=($(date +"%d/%b/%Y") $(date --date='1 day ago' +"%d/%b/%Y") $(date --date='2 days ago' +"%d/%b/%Y") $(date --date='3 days ago' +"%d/%b/%Y") $(date --date='4 days ago' +"%d/%b/%Y")); #for DATE in "${datetimeDomLast5_array[@]}"; do echo $DATE; done;
|
||||
|
||||
#Get users homedir path
|
||||
user_homedir=$(sudo egrep "^${Username}:" /etc/passwd | cut -d: -f6)
|
||||
|
||||
#setup Domlogs/Accesslog path based off user_homedir/logs
|
||||
domlogs_path="${user_homedir}/logs/"
|
||||
|
||||
Now=$(date +"%Y-%m-%d_%T")
|
||||
|
||||
user_CyberpanelSnapshot="${Username}-CyberpanelSnapshot_${Now}.txt";
|
||||
|
||||
#create logfile in user's homedirectory.
|
||||
#sudo touch "$user_CyberpanelSnapshot"
|
||||
|
||||
#chown logfile to user
|
||||
#sudo chown ${Username}:${Username} "$user_CyberpanelSnapshot";
|
||||
|
||||
|
||||
main_function() {
|
||||
|
||||
|
||||
echo ""
|
||||
echo "Web Traffic Stats Check";
|
||||
|
||||
echo "";
|
||||
for DATE in "${datetimeDomLast5_array[@]}"; do
|
||||
echo "=============================================================";
|
||||
echo "Apache Dom Logs POST Requests for ${DATE} for $Username";
|
||||
|
||||
sudo grep -r "$DATE" ${domlogs_path} | grep POST | awk '{print $1}' | cut -d: -f1|sed -e "s|$domlogs_path||g" -e 's|"||g' -e 's/.access_log//g'| sort | uniq -c | sort -rn | head
|
||||
echo ""
|
||||
echo "HTTP Dom Logs GET Requests for ${DATE} for $Username"
|
||||
sudo grep -r "$DATE" ${domlogs_path} | grep GET | awk '{print $1}' | cut -d: -f1 |sed -e "s|$domlogs_path||g" -e 's|"||g' -e 's/.access_log//g'| sort | uniq -c | sort -rn | head
|
||||
echo ""
|
||||
echo "HTTP Dom Logs Top 10 bot/crawler requests per domain name for ${DATE}"
|
||||
sudo grep -r "$DATE" ${domlogs_path} | grep -Ei 'crawl|bot|spider|yahoo|bing|google'| awk '{print $1}' | cut -d: -f1|sed -e "s|$domlogs_path||g" -e 's|"||g' -e 's/.access_log//g'| sort | uniq -c | sort -rn | head
|
||||
echo ""
|
||||
echo "HTTP Dom Logs top ten IPs for ${DATE} for $Username"
|
||||
|
||||
command=$(sudo grep -r "$DATE" ${domlogs_path} | grep POST | awk '{print $1}'|sed -e 's/^[^=:]*[=:]//' -e 's|"||g' | sort | uniq -c | sort -rn | head| column -t);readarray -t iparray < <( echo "${command}" | tr '/' '\n'); echo ""; for IP in "${iparray[@]}"; do echo "$IP"; done; echo ""; echo "Show unique IP's with whois IP, Country,and ISP"; echo ""; for IP in "${iparray[@]}"; do IP=$(echo "$IP" |grep -Eo '([0-9]{1,3}[.]){3}[0-9]{1,3}|(*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])(\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])(\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])(\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])(\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])(\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])(\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])(\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])){3}))|:)))(%.+)?\s*)'); whois -h whois.cymru.com " -c -p $IP"|cut -d"|" -f 2,4,5|grep -Ev 'IP|whois.cymru.com'; done
|
||||
|
||||
echo ""
|
||||
echo "Checking the IPs that Have Hit the Server Most and What Site they were hitting:"
|
||||
sudo grep -rs "$DATE" ${domlogs_path} | awk {'print $1'} |sed -e "s|$domlogs_path||g" -e 's|"||g' -e 's/.access_log:/ /g'| sort | uniq -c | sort -n | tail -10| sort -rn| column -t
|
||||
echo ""
|
||||
echo "Checking the Top Hits Per Site Per IP:"
|
||||
sudo grep -rs "$DATE" ${domlogs_path} | awk {'print $1,$6,$7'} |sed -e "s|$domlogs_path||g" -e 's|"||g' -e 's/.access_log:/ /g'| sort | uniq -c | sort -n | tail -15| sort -rn| column -t
|
||||
echo ""
|
||||
echo "Apache Dom Logs find the top number of uri's being requested for ${DATE}"
|
||||
sudo grep -r "$DATE" ${domlogs_path} | grep POST | awk '{print $7}' | cut -d: -f2 |sed "s|$domlogs_path||g"| sort | uniq -c | sort -rn | head| column -t
|
||||
echo ""
|
||||
echo "";
|
||||
echo "View Apache requests per hour for $Username";
|
||||
sudo grep -r "$DATE" ${domlogs_path} | cut -d[ -f2 | cut -d] -f1 | awk -F: '{print $2":00"}' | sort -n | uniq -c| column -t
|
||||
echo ""
|
||||
echo "CMS Checks"
|
||||
echo ""
|
||||
echo "Wordpress Checks"
|
||||
echo "Wordpress Login Bruteforcing checks for wp-login.php for ${DATE} for $Username"
|
||||
sudo grep -r "$DATE" ${domlogs_path} | grep -E "wp-login.php|wp-admin.php" | cut -f 1 -d ":" |sed -e "s|$domlogs_path||g" -e 's|"||g' -e 's/.access_log//g'|awk {'print $1,$6,$7'} | sort | uniq -c | sort -n|tail| sort -rn
|
||||
echo ""
|
||||
echo "Wordpress Cron wp-cron.php(virtual cron) checks for ${DATE} for $Username"
|
||||
sudo grep -r "$DATE" ${domlogs_path} | grep wp-cron.php| cut -f 1 -d ":" |sed -e "s|$domlogs_path||g" -e 's|"||g' -e 's/.access_log//g'|awk {'print $1,$6,$7'} | sort | uniq -c | sort -n|tail| sort -rn
|
||||
echo ""
|
||||
echo "Wordpress XMLRPC Attacks checks for xmlrpc.php for ${DATE} for $Username"
|
||||
sudo grep -r "$DATE" ${domlogs_path} | grep xmlrpc.php| cut -f 1 -d ":" |sed -e "s|$domlogs_path||g" -e 's|"||g' -e 's/.access_log//g'|awk {'print $1,$6,$7'} | sort | uniq -c | sort -n|tail| sort -rn
|
||||
echo ""
|
||||
echo "Wordpress Heartbeat API checks for admin-ajax.php for ${DATE} for $Username"
|
||||
sudo grep -r "$DATE" ${domlogs_path} | grep admin-ajax.php| cut -f 1 -d ":" |sed -e "s|$domlogs_path||g" -e 's|"||g' -e 's/.access_log//g'|awk {'print $1,$6,$7'} | sort | uniq -c | sort -n|tail| sort -rn;
|
||||
echo ""
|
||||
echo "CMS Bruteforce Checks"
|
||||
echo "Drupal Login Bruteforcing checks for user/login/ for ${DATE} for $Username"
|
||||
sudo grep -r "$DATE" ${domlogs_path} | grep -E "user/login/" | cut -f 1 -d ":" |sed -e "s|$domlogs_path||g" -e 's|"||g' -e 's/.access_log//g'|awk {'print $1,$6,$7'} | sort | uniq -c | sort -n|tail| sort -rn
|
||||
echo ""
|
||||
echo "Magento Login Bruteforcing checks for admin pages /admin_xxxxx/admin/index/index for ${DATE} for $Username"
|
||||
sudo grep -r "$DATE" ${domlogs_path} | grep -E "admin_[a-zA-Z0-9_]*[/admin/index/index]" | cut -f 1 -d ":" |sed -e "s|$domlogs_path||g" -e 's|"||g' -e 's/.access_log//g'|awk {'print $1,$6,$7'} | sort | uniq -c | sort -n|tail| sort -rn
|
||||
echo ""
|
||||
echo "Joomla Login Bruteforcing checks for admin pages /administrator/index.php for ${DATE} for $Username"
|
||||
sudo grep -r "$DATE" ${domlogs_path} | grep -E "admin_[a-zA-Z0-9_]*[/admin/index/index]" | cut -f 1 -d ":" |sed -e "s|$domlogs_path||g" -e 's|"||g' -e 's/.access_log//g'|awk {'print $1,$6,$7'} | sort | uniq -c | sort -n|tail| sort -rn
|
||||
echo ""
|
||||
echo "vBulletin Login Bruteforcing checks for admin pages admincp for ${DATE} for $Username"
|
||||
sudo grep -r "$DATE" ${domlogs_path} | grep -E "admincp" | cut -f 1 -d ":" |sed -e "s|$domlogs_path||g" -e 's|"||g' -e 's/.access_log//g'|awk {'print $1,$6,$7'} | sort | uniq -c | sort -n|tail| sort -rn
|
||||
echo ""
|
||||
echo "Opencart Login Bruteforcing checks for admin pages /admin/index.php for ${DATE} for $Username"
|
||||
sudo grep -r "$DATE" ${domlogs_path} | grep -E "/admin/index.php" | cut -f 1 -d ":" |sed -e "s|$domlogs_path||g" -e 's|"||g' -e 's/.access_log//g'|awk {'print $1,$6,$7'} | sort | uniq -c | sort -n|tail| sort -rn
|
||||
echo ""
|
||||
echo "Prestashop Login Bruteforcing checks for admin pages /adminxxxx for ${DATE} for $Username"
|
||||
sudo grep -r "$DATE" ${domlogs_path} | grep -E "/admin[a-zA-Z0-9_]*$" | cut -f 1 -d ":" |sed -e "s|$domlogs_path||g" -e 's|"||g' -e 's/.access_log//g'|awk {'print $1,$6,$7'} | sort | uniq -c | sort -n|tail| sort -rn
|
||||
echo ""
|
||||
|
||||
|
||||
done;
|
||||
echo "============================================================="
|
||||
|
||||
|
||||
echo "Contents have been saved to ${user_CyberpanelSnapshot}"
|
||||
}
|
||||
|
||||
# log everything, but also output to stdout
|
||||
main_function 2>&1 | tee -a "${user_CyberpanelSnapshot}"
|
||||
491
CPScripts/EasyEngine/EasyEngine-migration.sh
Normal file
491
CPScripts/EasyEngine/EasyEngine-migration.sh
Normal file
@@ -0,0 +1,491 @@
|
||||
#!/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.
|
||||
|
||||
<IfModule mod_rewrite.c>
|
||||
RewriteEngine On
|
||||
RewriteBase /
|
||||
RewriteRule ^index\.php$ - [L]
|
||||
RewriteCond %{REQUEST_FILENAME} !-f
|
||||
RewriteCond %{REQUEST_FILENAME} !-d
|
||||
RewriteRule . /index.php [L]
|
||||
</IfModule>
|
||||
#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 "ls -l /usr/bin/wp"
|
||||
if [[ $? != "0" ]] ; then
|
||||
$ssh_v "$sudoer wget -O /usr/bin/wp https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar"
|
||||
$ssh_v "$sudoer chmod +x /usr/bin/wp"
|
||||
fi
|
||||
#install WP CLI if not yet installed.
|
||||
$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..."
|
||||
}
|
||||
|
||||
db_length_check() {
|
||||
ssh_v="ssh -o StrictHostKeyChecking=no root@$server_ip -p$server_port -i /root/.ssh/cyberpanel_migration_key"
|
||||
output=$($ssh_v "$sudoer cat /usr/local/CyberCP/plogical/mysqlUtilities.py")
|
||||
if echo $output | grep -q "should be 16 at max" ; then
|
||||
echo -e "\nPlease upgrade your CyberPanel to latest first..."
|
||||
clean_up
|
||||
exit
|
||||
fi
|
||||
}
|
||||
|
||||
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.
|
||||
|
||||
db_length_check
|
||||
|
||||
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
|
||||
97
CPScripts/EasyEngine/ext.sh
Normal file
97
CPScripts/EasyEngine/ext.sh
Normal file
@@ -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
|
||||
89
CPScripts/EasyEngine/header.sh
Normal file
89
CPScripts/EasyEngine/header.sh
Normal file
@@ -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 <<<END_extraHeaders
|
||||
unset Cache-control
|
||||
set Cache-control public, max-age=15552000
|
||||
set Access-Control-Allow-Origin: *
|
||||
END_extraHeaders
|
||||
|
||||
|
||||
rewrite {
|
||||
|
||||
}
|
||||
addDefaultCharset off
|
||||
|
||||
phpIniOverride {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
context /wp-content/cache/js/ {
|
||||
location $DOC_ROOT/wp-content/cache/js/
|
||||
allowBrowse 1
|
||||
enableExpires 1
|
||||
expiresByType application/x-javascript=A15552000, text/javascript=A15552000, application/javascript=A15552000
|
||||
extraHeaders <<<END_extraHeaders
|
||||
unset Cache-control
|
||||
set Cache-control public, max-age=15552000
|
||||
set Access-Control-Allow-Origin: *
|
||||
END_extraHeaders
|
||||
|
||||
|
||||
rewrite {
|
||||
|
||||
}
|
||||
addDefaultCharset off
|
||||
|
||||
phpIniOverride {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
context exp:^.*(css|gif|ico|jpeg|jpg|js|png|webp|woff|woff2|fon|fot|ttf)$ {
|
||||
location $DOC_ROOT/$0
|
||||
allowBrowse 1
|
||||
enableExpires 1
|
||||
expiresByType text/css=A15552000, image/gif=A15552000, image/x-icon=A15552000, image/jpeg=A15552000, application/x-javascript=A15552000, text/javascript=A15552000, application/javascript=A15552000, image/png=A15552000, image/webp=A15552000, font/ttf=A15552000, font/woff=A15552000, font/woff2=A15552000, application/x-font-ttf=A15552000, application/x-font-woff=A15552000, application/font-woff=A15552000, application/font-woff2=A15552000
|
||||
extraHeaders <<<END_extraHeaders
|
||||
unset Cache-control
|
||||
set Cache-control public, max-age=15552000
|
||||
set Access-Control-Allow-Origin: *
|
||||
END_extraHeaders
|
||||
|
||||
|
||||
rewrite {
|
||||
|
||||
}
|
||||
addDefaultCharset off
|
||||
|
||||
phpIniOverride {
|
||||
|
||||
}
|
||||
}
|
||||
EOF
|
||||
|
||||
cat header.txt >> /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..."
|
||||
78
CPScripts/EasyEngine/key.sh
Normal file
78
CPScripts/EasyEngine/key.sh
Normal file
@@ -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
|
||||
144
CPScripts/access-logparser-user.sh
Normal file
144
CPScripts/access-logparser-user.sh
Normal file
@@ -0,0 +1,144 @@
|
||||
#!/bin/bash
|
||||
## Author: Michael Ramsey
|
||||
## Objective Find A Cyberpanel/cPanel Users Dom/Access logs Stats for last 5 days for all of their domains from inside the account. Great for end users without Sudo/Root access in a shared setup to check their own logs.
|
||||
## https://gitlab.com/mikeramsey/access-log-parser
|
||||
## How to use.
|
||||
# Run the script from your account via manual or curl method.
|
||||
#
|
||||
# ./access-logparser-user.sh
|
||||
#
|
||||
#
|
||||
##bash <(curl -s https://gitlab.com/mikeramsey/access-log-parser/-/raw/master/access-logparser-user.sh || wget -qO - https://gitlab.com/mikeramsey/access-log-parser/-/raw/master/access-logparser-user.sh) ;
|
||||
##
|
||||
Username=${USER}
|
||||
|
||||
#Detect Control panel
|
||||
if [ -f /usr/local/cpanel/cpanel ]; then
|
||||
# Cpanel check for /usr/local/cpanel/cpanel -V
|
||||
ControlPanel="cpanel"
|
||||
datetimeDcpumon=$(date +"%Y/%b/%d") # 2019/Feb/15
|
||||
#Current Dcpumon file
|
||||
# DcpumonCurrentLOG="/var/log/dcpumon/${datetimeDcpumon}" # /var/log/dcpumon/2019/Feb/15
|
||||
#Setup datetimeDcpumonLast5_array
|
||||
# declare -a datetimeDcpumonLast5_array=($(date +"%Y/%b/%d") $(date --date='1 day ago' +"%Y/%b/%d") $(date --date='2 days ago' +"%Y/%b/%d") $(date --date='3 days ago' +"%Y/%b/%d") $(date --date='4 days ago' +"%Y/%b/%d")); #for DATE in "${datetimeDcpumonLast5_array[@]}"; do echo $DATE; done;
|
||||
|
||||
user_homedir=${HOME}
|
||||
user_accesslogs="${HOME}/logs/"
|
||||
domlogs_path="/usr/local/apache/domlogs/${Username}/"
|
||||
acesslog_sed="-ssl_log"
|
||||
|
||||
elif [ -f /usr/bin/cyberpanel ]; then
|
||||
# CyberPanel check /usr/bin/cyberpanel
|
||||
ControlPanel="cyberpanel"
|
||||
|
||||
#Get users homedir path
|
||||
user_homedir=${HOME}
|
||||
domlogs_path="${user_homedir}/logs/"
|
||||
acesslog_sed=".access_log"
|
||||
|
||||
else
|
||||
echo "Not able to detect Control panel. Unsupported Control Panel exiting now"
|
||||
exit 1;
|
||||
fi
|
||||
echo "=============================================================";
|
||||
echo "$ControlPanel Control Panel Detected"
|
||||
echo "User Homedirectory: ${user_homedir}"
|
||||
echo "User Domlogs Path: ${domlogs_path}"
|
||||
echo "=============================================================";
|
||||
echo "";
|
||||
#Domlog Date array for past 5 days
|
||||
declare -a datetimeDomLast5_array=($(date +"%d/%b/%Y") $(date --date='1 day ago' +"%d/%b/%Y") $(date --date='2 days ago' +"%d/%b/%Y") $(date --date='3 days ago' +"%d/%b/%Y") $(date --date='4 days ago' +"%d/%b/%Y")); #for DATE in "${datetimeDomLast5_array[@]}"; do echo $DATE; done;
|
||||
|
||||
|
||||
Now=$(date +"%Y-%m-%d_%T")
|
||||
|
||||
user_Snapshot="${Username}-Snapshot_${Now}.txt";
|
||||
|
||||
#create logfile in user's homedirectory.
|
||||
touch ${user_Snapshot}
|
||||
|
||||
#chown logfile to user
|
||||
#sudo chown ${Username}:${Username} "$user_CyberpanelSnapshot";
|
||||
|
||||
|
||||
main_function() {
|
||||
|
||||
echo ""
|
||||
echo "Web Traffic Stats Check";
|
||||
|
||||
echo "";
|
||||
for DATE in "${datetimeDomLast5_array[@]}"; do
|
||||
echo "=============================================================";
|
||||
echo "HTTP Dom Logs POST Requests for ${DATE} for $Username";
|
||||
|
||||
grep -r "$DATE" ${domlogs_path} | grep POST | awk '{print $1}' | cut -d: -f1|sed -e "s|$domlogs_path||g" -e 's|"||g' -e "s|$acesslog_sed||g" -e "s|$Username/||g"| sort | uniq -c | sort -rn | head
|
||||
echo ""
|
||||
echo "HTTP Dom Logs GET Requests for ${DATE} for $Username"
|
||||
grep -r "$DATE" ${domlogs_path} | grep GET | awk '{print $1}' | cut -d: -f1 |sed -e "s|$domlogs_path||g" -e 's|"||g' -e "s|$acesslog_sed||g" -e "s|$Username/||g"| sort | uniq -c | sort -rn | head
|
||||
echo ""
|
||||
echo "HTTP Dom Logs Top 10 bot/crawler requests per domain name for ${DATE}"
|
||||
grep -r "$DATE" ${domlogs_path} | grep -Ei 'crawl|bot|spider|yahoo|bing|google'| awk '{print $1}' | cut -d: -f1|sed -e "s|$domlogs_path||g" -e 's|"||g' -e "s|$acesslog_sed||g" -e "s|$Username/||g"| sort | uniq -c | sort -rn | head
|
||||
echo ""
|
||||
echo "HTTP Dom Logs top ten IPs for ${DATE} for $Username"
|
||||
|
||||
command=$(grep -r "$DATE" ${domlogs_path} | grep POST | awk '{print $1}'|sed -e 's/^[^=:]*[=:]//' -e 's|"||g' | sort | uniq -c | sort -rn | head| column -t);readarray -t iparray < <( echo "${command}" | tr '/' '\n'); echo ""; for IP in "${iparray[@]}"; do echo "$IP"; done; echo ""; echo "Show unique IP's with whois IP, Country,and ISP"; echo ""; for IP in "${iparray[@]}"; do IP=$(echo "$IP" |grep -Eo '([0-9]{1,3}[.]){3}[0-9]{1,3}|(*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])(\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])(\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])(\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])(\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])(\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])(\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])(\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])){3}))|:)))(%.+)?\s*)'); whois -h whois.cymru.com " -c -p $IP"|cut -d"|" -f 2,4,5|grep -Ev 'IP|whois.cymru.com'; done
|
||||
|
||||
echo ""
|
||||
echo "Checking the IPs that Have Hit the Server Most and What Site they were hitting:"
|
||||
grep -rs "$DATE" ${domlogs_path} | awk {'print $1'} |sed -e "s|$domlogs_path||g" -e 's|"||g' -e "s|$acesslog_sed:| |g"| sort | uniq -c | sort -n | tail -10| sort -rn| column -t
|
||||
echo ""
|
||||
echo "Checking the Top Hits Per Site Per IP:"
|
||||
grep -rs "$DATE" ${domlogs_path} | awk {'print $1,$6,$7'} |sed -e "s|$domlogs_path||g" -e 's|"||g' -e "s|$acesslog_sed:| |g"| sort | uniq -c | sort -n | tail -10| sort -rn| column -t
|
||||
echo ""
|
||||
echo "HTTP Dom Logs find the top number of uri's being requested for ${DATE}"
|
||||
grep -r "$DATE" ${domlogs_path} | grep POST | awk '{print $7}' | cut -d: -f2 |sed "s|$domlogs_path||g"| sort | uniq -c | sort -rn | head| column -t
|
||||
echo ""
|
||||
echo "";
|
||||
echo "View HTTP requests per hour for $Username";
|
||||
grep -r "$DATE" ${domlogs_path} | cut -d[ -f2 | cut -d] -f1 | awk -F: '{print $2":00"}' | sort -n | uniq -c| column -t
|
||||
echo ""
|
||||
echo "CMS Checks"
|
||||
echo ""
|
||||
echo "Wordpress Checks"
|
||||
echo "Wordpress Login Bruteforcing checks for wp-login.php for ${DATE} for $Username"
|
||||
grep -r "$DATE" ${domlogs_path} | grep wp-login.php | cut -f 1 -d ":" |sed -e "s|$domlogs_path||g" -e 's|"||g' -e "s|$acesslog_sed||g" -e "s|$Username/||g"|awk {'print $1,$6,$7'} | sort | uniq -c | sort -n|tail| sort -rn
|
||||
echo ""
|
||||
echo "Wordpress Cron wp-cron.php(virtual cron) checks for ${DATE} for $Username"
|
||||
grep -r "$DATE" ${domlogs_path} | grep wp-cron.php| cut -f 1 -d ":" |sed -e "s|$domlogs_path||g" -e 's|"||g' -e "s|$acesslog_sed||g" -e "s|$Username/||g"|awk {'print $1,$6,$7'} | sort | uniq -c | sort -n|tail| sort -rn
|
||||
echo ""
|
||||
echo "Wordpress XMLRPC Attacks checks for xmlrpc.php for ${DATE} for $Username"
|
||||
grep -r "$DATE" ${domlogs_path} | grep xmlrpc.php| cut -f 1 -d ":" |sed -e "s|$domlogs_path||g" -e 's|"||g' -e "s|$acesslog_sed||g" -e "s|$Username/||g"|awk {'print $1,$6,$7'} | sort | uniq -c | sort -n|tail| sort -rn
|
||||
echo ""
|
||||
echo "Wordpress Heartbeat API checks for admin-ajax.php for ${DATE} for $Username"
|
||||
grep -r "$DATE" ${domlogs_path} | grep admin-ajax.php| cut -f 1 -d ":" |sed -e "s|$domlogs_path||g" -e 's|"||g' -e "s|$acesslog_sed||g" -e "s|$Username/||g"|awk {'print $1,$6,$7'} | sort | uniq -c | sort -n|tail| sort -rn;
|
||||
echo ""
|
||||
echo "CMS Bruteforce Checks"
|
||||
echo "Drupal Login Bruteforcing checks for user/login/ for ${DATE} for $Username"
|
||||
grep -r "$DATE" ${domlogs_path} | grep -E "user/login/" | cut -f 1 -d ":" |sed -e "s|$domlogs_path||g" -e 's|"||g' -e "s|$acesslog_sed||g" -e "s|$Username/||g"|awk {'print $1,$6,$7'} | sort | uniq -c | sort -n|tail| sort -rn
|
||||
echo ""
|
||||
echo "Magento Login Bruteforcing checks for admin pages /admin_xxxxx/admin/index/index for ${DATE} for $Username"
|
||||
grep -r "$DATE" ${domlogs_path} | grep -E "admin_[a-zA-Z0-9_]*[/admin/index/index]" | cut -f 1 -d ":" |sed -e "s|$domlogs_path||g" -e 's|"||g' -e "s|$acesslog_sed||g" -e "s|$Username/||g"|awk {'print $1,$6,$7'} | sort | uniq -c | sort -n|tail| sort -rn
|
||||
echo ""
|
||||
echo "Joomla Login Bruteforcing checks for admin pages /administrator/index.php for ${DATE} for $Username"
|
||||
grep -r "$DATE" ${domlogs_path} | grep -E "/administrator/index.php" | cut -f 1 -d ":" |sed -e "s|$domlogs_path||g" -e 's|"||g' -e "s|$acesslog_sed||g" -e "s|$Username/||g"|awk {'print $1,$6,$7'} | sort | uniq -c | sort -n|tail| sort -rn
|
||||
echo ""
|
||||
echo "vBulletin Login Bruteforcing checks for admin pages admincp for ${DATE} for $Username"
|
||||
grep -r "$DATE" ${domlogs_path} | grep -E "admincp" | cut -f 1 -d ":" |sed -e "s|$domlogs_path||g" -e 's|"||g' -e "s|$acesslog_sed||g" -e "s|$Username/||g"|awk {'print $1,$6,$7'} | sort | uniq -c | sort -n|tail| sort -rn
|
||||
echo ""
|
||||
echo "Opencart Login Bruteforcing checks for admin pages /admin/index.php for ${DATE} for $Username"
|
||||
grep -r "$DATE" ${domlogs_path} | grep -E "/admin/index.php" | cut -f 1 -d ":" |sed -e "s|$domlogs_path||g" -e 's|"||g' -e "s|$acesslog_sed||g" -e "s|$Username/||g"|awk {'print $1,$6,$7'} | sort | uniq -c | sort -n|tail| sort -rn
|
||||
echo ""
|
||||
echo "Prestashop Login Bruteforcing checks for admin pages /adminxxxx for ${DATE} for $Username"
|
||||
grep -r "$DATE" ${domlogs_path} | grep -E "/admin[a-zA-Z0-9_]*$" | cut -f 1 -d ":" |sed -e "s|$domlogs_path||g" -e 's|"||g' -e "s|$acesslog_sed||g" -e "s|$Username/||g"|awk {'print $1,$6,$7'} | sort | uniq -c | sort -n|tail| sort -rn
|
||||
echo ""
|
||||
|
||||
|
||||
done;
|
||||
echo "============================================================="
|
||||
|
||||
|
||||
echo "Contents have been saved to ${user_Snapshot}"
|
||||
}
|
||||
|
||||
# log everything, but also output to stdout
|
||||
main_function 2>&1 | tee -a "${user_Snapshot}"
|
||||
601
CPScripts/access-logparser.py
Normal file
601
CPScripts/access-logparser.py
Normal file
@@ -0,0 +1,601 @@
|
||||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
# Apache Regex portion original credits to: https://leancrew.com/all-this/2013/07/parsing-my-apache-logs/
|
||||
## https://gitlab.com/mikeramsey/access-log-parser
|
||||
## How to use.
|
||||
# Run the script from your account via manual or curl method. It autodetects the current user and defaults to the todays date if not argument for how many days ago it provided.
|
||||
# For todays hits
|
||||
# ./access-logparser.py
|
||||
#
|
||||
# For yesterdays aka 1 Days ago
|
||||
# ./access-logparser.py 1
|
||||
#
|
||||
##python <(curl -s https://gitlab.com/mikeramsey/access-log-parser/-/raw/master/access-logparser.py || wget -qO - https://gitlab.com/mikeramsey/access-log-parser/-/raw/master/access-logparser.py) 1;
|
||||
|
||||
|
||||
__author__ = "Michael Ramsey"
|
||||
__version__ = "0.1.2"
|
||||
__license__ = "GPL-3.0"
|
||||
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
import time
|
||||
from collections import Counter
|
||||
from datetime import date, timedelta
|
||||
from datetime import datetime
|
||||
from os.path import join, isfile
|
||||
import getpass
|
||||
import glob
|
||||
|
||||
|
||||
# import pathlib
|
||||
|
||||
# print('version is', sys.version)
|
||||
|
||||
|
||||
def main():
|
||||
script = sys.argv[0]
|
||||
# filename = sys.argv[2]
|
||||
# filenametest = "/home/example.com.access_log"
|
||||
# username = 'server'
|
||||
username = getpass.getuser()
|
||||
# print(username)
|
||||
# Define the day of interest in the Apache common log format. Default if not specified
|
||||
try:
|
||||
daysago = int(sys.argv[1])
|
||||
# daysago = 0
|
||||
except:
|
||||
daysago = 0
|
||||
the_day = date.today() - timedelta(daysago)
|
||||
apache_day = the_day.strftime('[%d/%b/%Y:')
|
||||
dcpumon_day = the_day.strftime('%Y/%b/%d')
|
||||
|
||||
# Set variables to empty
|
||||
controlpanel = ''
|
||||
domlogs_path = ''
|
||||
|
||||
try:
|
||||
if os.path.isfile('/usr/local/cpanel/cpanel') | os.path.isfile(os.getcwd() + '/cpanel'):
|
||||
controlpanel = 'Cpanel'
|
||||
datetime_dcpumon = date.today().strftime('%Y/%b/%d') # 2020/Feb/10
|
||||
# Current Dcpumon file
|
||||
dcpumon_current_log = "/var/log/dcpumon/" + datetime_dcpumon # /var/log/dcpumon/2019/Feb/15
|
||||
acesslog_sed = "-ssl_log"
|
||||
if username == 'root':
|
||||
domlogs_path = '/usr/local/apache/domlogs/'
|
||||
else:
|
||||
user_homedir = "/home/" + username
|
||||
user_accesslogs = "/home/" + username + "/logs/"
|
||||
domlogs_path = "/usr/local/apache/domlogs/" + username
|
||||
|
||||
elif os.path.isfile('/usr/bin/cyberpanel') | os.path.isfile(os.getcwd() + '/cyberpanel'):
|
||||
controlpanel = 'CyberPanel'
|
||||
acesslog_sed = ".access_log"
|
||||
if username == 'root':
|
||||
# Needs updated to glob all /home/*/logs/
|
||||
domlogs_path2 = glob.glob('/home/*/logs/')
|
||||
else:
|
||||
# Get users homedir path
|
||||
user_homedir = os.path.expanduser("~" + username)
|
||||
domlogs_path = user_homedir + "/logs/"
|
||||
|
||||
except:
|
||||
controlpanel = 'Control Panel not found'
|
||||
|
||||
# Define Output file
|
||||
stats_output = open(os.getcwd() + '/stats.txt', "w")
|
||||
|
||||
if username == 'root' and controlpanel == 'CyberPanel':
|
||||
# Needs updated to glob all /home/*/logs/
|
||||
path = '/home/*/logs/*'
|
||||
domlogs_path = glob.glob("/home/*/logs/")
|
||||
print('Root CyberPanel Detected')
|
||||
# Get list of dir contents
|
||||
# logs_path_contents = glob.glob("/home/*/logs/*.access_log", recursive=True)
|
||||
|
||||
# Get list of files only from this directory
|
||||
logs = glob.glob("/home/*/logs/*.access_log")
|
||||
|
||||
else:
|
||||
# Define log path directory
|
||||
path = domlogs_path
|
||||
# Get list of dir contents
|
||||
logs_path_contents = os.listdir(path)
|
||||
# Get list of files only from this directory
|
||||
logs = filter(lambda f: isfile(join(path, f)), logs_path_contents)
|
||||
|
||||
# Regex for the Apache common log format.
|
||||
parts = [ # host %h :ip/hostname of the client 172.68.142.138
|
||||
# indent %l (unused) :client identity via client's identd configuration -
|
||||
# user %u :HTTP authenticated user ID -
|
||||
# time %t :timestamp [09/Mar/2019:00:38:03 -0600]
|
||||
# request "%r" :request method of request, resource requested, & protocol "POST /wp-login.php HTTP/1.1"
|
||||
# status %>s :Apache status code 404
|
||||
# size %b (careful,can be'-'):size of request in bytes, excluding headers 3767
|
||||
# referrer "%{Referer}i" :Referer "https://www.google.com/"
|
||||
# user agent "%{User-agent}i":User-Agent "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36 SE 2.X MetaSr 1.0"
|
||||
r'(?P<host>\S+)',
|
||||
r'\S+',
|
||||
r'(?P<user>\S+)',
|
||||
r'\[(?P<time>.+)\]',
|
||||
r'"(?P<request>.*)"',
|
||||
r'(?P<status>[0-9]+)',
|
||||
r'(?P<size>\S+)',
|
||||
r'"(?P<referrer>.*)"',
|
||||
r'"(?P<agent>.*)"',
|
||||
]
|
||||
pattern = re.compile(r'\s+'.join(parts) + r'\s*\Z')
|
||||
|
||||
# Regex for a feed request.
|
||||
feed = re.compile(r'/all-this/(\d\d\d\d/\d\d/[^/]+/)?feed/(atom/)?')
|
||||
|
||||
# Regexes for internal and Google search referrers.
|
||||
|
||||
internal = re.compile(r'https?://(www\.)?example\.com.*')
|
||||
google = re.compile(r'https?://(www\.)?google\..*')
|
||||
|
||||
# Regexes for Uptime Monitoring Robots
|
||||
uptimeroboturl = re.compile(r'https?://(www\.)?uptimerobot\..*')
|
||||
uptimerobot = re.compile(r'UptimeRobot')
|
||||
|
||||
# Change Apache log items into Python types.
|
||||
|
||||
def pythonized(d):
|
||||
# Clean up the request.
|
||||
|
||||
d['request'] = d['request'].split()[1]
|
||||
|
||||
# Some dashes become None.
|
||||
|
||||
for k in ('user', 'referrer', 'agent'):
|
||||
if d[k] == '-':
|
||||
d[k] = None
|
||||
|
||||
# The size dash becomes 0.
|
||||
|
||||
if d['size'] == '-':
|
||||
d['size'] = 0
|
||||
else:
|
||||
d['size'] = int(d['size'])
|
||||
|
||||
# Convert the timestamp into a datetime object. Accept the server's time zone.
|
||||
|
||||
(time, zone) = d['time'].split()
|
||||
d['time'] = datetime.strptime(time, '%d/%b/%Y:%H:%M:%S')
|
||||
|
||||
return d
|
||||
|
||||
# Is this hit a page?
|
||||
|
||||
def ispage(hit):
|
||||
# Failures and redirects.
|
||||
|
||||
hit['status'] = int(hit['status'])
|
||||
if hit['status'] < 200 or hit['status'] >= 300:
|
||||
return False
|
||||
|
||||
# Feed requests.
|
||||
|
||||
if feed.search(hit['request']):
|
||||
return False
|
||||
|
||||
# Requests that aren't GET.
|
||||
|
||||
# if (hit['request'])[0:3] != 'GET':
|
||||
# return False
|
||||
|
||||
# Images, sounds, etc.
|
||||
|
||||
if hit['request'].split()[1][-1] != '/':
|
||||
return False
|
||||
|
||||
# Requests that aren't Head type. AKA uptime monitoring
|
||||
|
||||
if (hit['request'])[0:3] == 'HEAD':
|
||||
return False
|
||||
|
||||
# Must be a page.
|
||||
|
||||
return True
|
||||
|
||||
# Is the referrer interesting? Internal and Google referrers are not.
|
||||
def goodref(hit):
|
||||
if hit['referrer']:
|
||||
return not (google.search(hit['referrer'])
|
||||
or internal.search(hit['referrer']))
|
||||
else:
|
||||
return False
|
||||
|
||||
# Is the user agent interesting? An uptime monitoring robot is not.
|
||||
def goodagent(hit):
|
||||
if hit['agent']:
|
||||
return not (uptimerobot.search(hit['agent'])
|
||||
or uptimeroboturl.search(hit['agent']))
|
||||
else:
|
||||
return False
|
||||
|
||||
# create a function which returns the value of a dictionary
|
||||
def keyfunction(k):
|
||||
return d[k]
|
||||
|
||||
# Initialize pages for top IP's
|
||||
|
||||
pages = []
|
||||
|
||||
# Initialize dictionaries for hit counters
|
||||
post_request_dict = {}
|
||||
get_request_dict = {}
|
||||
wp_login_dict = {}
|
||||
wp_cron_dict = {}
|
||||
wp_xmlrpc_dict = {}
|
||||
wp_admin_ajax_dict = {}
|
||||
drupal_login_dict = {}
|
||||
magento_login_dict = {}
|
||||
joomla_login_dict = {}
|
||||
vbulletin_login_dict = {}
|
||||
opencart_login_dict = {}
|
||||
prestashop_login_dict = {}
|
||||
|
||||
# Parse all the lines associated with the day of interest.
|
||||
|
||||
for log in logs:
|
||||
file = os.path.join(path, log)
|
||||
text = open(file, "r")
|
||||
post_request_hit_count = 0
|
||||
get_request_hit_count = 0
|
||||
wp_login_hit_count = 0
|
||||
wp_cron_hit_count = 0
|
||||
wp_xmlrpc_hit_count = 0
|
||||
wp_admin_ajax_hit_count = 0
|
||||
drupal_hit_count = 0
|
||||
magento_hit_count = 0
|
||||
joomla_hit_count = 0
|
||||
vbulletin_hit_count = 0
|
||||
opencart_hit_count = 0
|
||||
prestashop_hit_count = 0
|
||||
for line in text:
|
||||
if apache_day in line:
|
||||
if re.match("(.*)(POST)(.*)", line):
|
||||
post_request_hit_count = post_request_hit_count + 1
|
||||
if re.match("(.*)(GET)(.*)", line):
|
||||
get_request_hit_count = get_request_hit_count + 1
|
||||
if re.match("(.*)(wp-login.php)(.*)", line):
|
||||
wp_login_hit_count = wp_login_hit_count + 1
|
||||
if re.match("(.*)(wp-cron.php)(.*)", line):
|
||||
wp_cron_hit_count = wp_cron_hit_count + 1
|
||||
if re.match("(.*)(xmlrpc.php)(.*)", line):
|
||||
wp_xmlrpc_hit_count = wp_xmlrpc_hit_count + 1
|
||||
if re.match("(.*)(admin-ajax.php)(.*)", line):
|
||||
wp_admin_ajax_hit_count = wp_admin_ajax_hit_count + 1
|
||||
if re.match("(.*)(user/login/)(.*)", line):
|
||||
drupal_hit_count = drupal_hit_count + 1
|
||||
if re.match("(.*)(admin_[a-zA-Z0-9_]*[/admin/index/index])(.*)", line):
|
||||
magento_hit_count = magento_hit_count + 1
|
||||
if re.match("(.*)(/administrator/index.php)(.*)", line):
|
||||
joomla_hit_count = joomla_hit_count + 1
|
||||
if re.match("(.*)(admincp)(.*)", line):
|
||||
vbulletin_hit_count = vbulletin_hit_count + 1
|
||||
if re.match("(.*)(/admin/index.php)(.*)", line):
|
||||
opencart_hit_count = opencart_hit_count + 1
|
||||
if re.match("(.*)(/admin[a-zA-Z0-9_]*$)(.*)", line):
|
||||
prestashop_hit_count = prestashop_hit_count + 1
|
||||
m = pattern.match(line)
|
||||
if m is not None:
|
||||
hit = m.groupdict()
|
||||
else:
|
||||
# print("re.search() returned None")
|
||||
continue
|
||||
# hit = m.groupdict()
|
||||
if ispage(hit):
|
||||
pages.append(pythonized(hit))
|
||||
else:
|
||||
continue
|
||||
# print >> stats_output, log + "|" + line,
|
||||
# print(log + "|" + line, end="", file=stats_output)
|
||||
# print(wp_login_hit_count)
|
||||
log = log.replace('-ssl_log', '', 1)
|
||||
log = log.replace('.access_log', '', 1)
|
||||
|
||||
# wp_login_dict[log] = int(wp_login_hit_count)
|
||||
# wp_cron_dict[log] = int(wp_cron_hit_count)
|
||||
# wp_xmlrpc_dict[log] = int(wp_xmlrpc_hit_count)
|
||||
# wp_admin_ajax_dict[log] = int(wp_admin_ajax_hit_count)
|
||||
|
||||
# Only add hit count to dictionary if not equal to '0'
|
||||
if post_request_hit_count != '0':
|
||||
post_request_dict[log] = int(post_request_hit_count)
|
||||
|
||||
if get_request_hit_count != '0':
|
||||
get_request_dict[log] = int(get_request_hit_count)
|
||||
|
||||
if wp_login_hit_count != '0':
|
||||
wp_login_dict[log] = int(wp_login_hit_count)
|
||||
|
||||
if wp_cron_hit_count != '0':
|
||||
wp_cron_dict[log] = int(wp_cron_hit_count)
|
||||
|
||||
if wp_xmlrpc_hit_count != '0':
|
||||
wp_xmlrpc_dict[log] = int(wp_xmlrpc_hit_count)
|
||||
|
||||
if wp_admin_ajax_hit_count != '0':
|
||||
wp_admin_ajax_dict[log] = int(wp_admin_ajax_hit_count)
|
||||
|
||||
if drupal_hit_count != '0':
|
||||
drupal_login_dict[log] = int(drupal_hit_count)
|
||||
|
||||
if magento_hit_count != '0':
|
||||
magento_login_dict[log] = int(magento_hit_count)
|
||||
|
||||
if joomla_hit_count != '0':
|
||||
joomla_login_dict[log] = int(joomla_hit_count)
|
||||
|
||||
if vbulletin_hit_count != '0':
|
||||
vbulletin_login_dict[log] = int(vbulletin_hit_count)
|
||||
|
||||
if opencart_hit_count != '0':
|
||||
opencart_login_dict[log] = int(opencart_hit_count)
|
||||
|
||||
if prestashop_hit_count != '0':
|
||||
prestashop_login_dict[log] = int(prestashop_hit_count)
|
||||
|
||||
# print(log)
|
||||
# print("Wordpress Logins => " + str(wp_login_hit_count))
|
||||
# print("Wordpress wp-cron => " + str(wp_cron_hit_count))
|
||||
# print("Wordpress xmlrpc => " + str(wp_xmlrpc_hit_count))
|
||||
# print("Wordpress admin-ajax => " + str(wp_admin_ajax_hit_count))
|
||||
# print("===============================================================")
|
||||
text.close()
|
||||
# print(pages, file=stats_output)
|
||||
|
||||
print(' ')
|
||||
print('============================================')
|
||||
print('Snapshot for ' + username)
|
||||
print(time.strftime('%H:%M%p %Z on %b %d, %Y'))
|
||||
if controlpanel == 'Cpanel' or controlpanel == 'CyberPanel':
|
||||
print(controlpanel + " detected")
|
||||
else:
|
||||
print('No control Panel detected')
|
||||
|
||||
print('Accesslog path used: ' + path)
|
||||
# print(dcpumon_current_log)
|
||||
print('============================================')
|
||||
d = post_request_dict
|
||||
# Using dictionary comprehension to find list
|
||||
# keys having value in 0 will be removed from results
|
||||
delete = [key for key in d if d[key] == 0]
|
||||
|
||||
# delete the key
|
||||
for key in delete: del d[key]
|
||||
print(' ')
|
||||
print('''Top POST requests for %s''' % the_day.strftime('%b %d, %Y'))
|
||||
print(' ')
|
||||
# sort by dictionary by the values and print top 10 {key, value} pairs
|
||||
for key in sorted(d, key=keyfunction, reverse=True)[:10]:
|
||||
print(' %5d %s' % (d[key], key))
|
||||
print(' %5d total hits' % sum(dict.values(d)))
|
||||
print('============================================')
|
||||
|
||||
d = get_request_dict
|
||||
# Using dictionary comprehension to find list
|
||||
# keys having value in 0 will be removed from results
|
||||
delete = [key for key in d if d[key] == 0]
|
||||
|
||||
# delete the key
|
||||
for key in delete: del d[key]
|
||||
|
||||
print('''Top GET requests for %s''' % the_day.strftime('%b %d, %Y'))
|
||||
print(' ')
|
||||
# sort by dictionary by the values and print top 10 {key, value} pairs
|
||||
for key in sorted(d, key=keyfunction, reverse=True)[:10]:
|
||||
print(' %5d %s' % (d[key], key))
|
||||
print(' %5d total hits' % sum(dict.values(d)))
|
||||
print('============================================')
|
||||
|
||||
# Show the top 10 pages and the total.
|
||||
print('''
|
||||
Show top 10 pages %s''' % the_day.strftime('%b %d, %Y'))
|
||||
pageviews = Counter(x['request'] for x in pages if goodagent(x))
|
||||
pagestop10 = pageviews.most_common(10)
|
||||
for p in pagestop10:
|
||||
print(' %5d %s' % p[::-1])
|
||||
print(' %5d total' % len(pages))
|
||||
print('============================================')
|
||||
|
||||
# Show the top five referrers.
|
||||
print('''
|
||||
Show top 10 referrers %s''' % the_day.strftime('%b %d, %Y'))
|
||||
referrers = Counter(x['referrer'] for x in pages if goodref(x))
|
||||
referrerstop10 = referrers.most_common(10)
|
||||
for r in referrerstop10:
|
||||
print(' %5d %s' % r[::-1])
|
||||
print(' %5d total' % sum(referrers.values()))
|
||||
print('============================================')
|
||||
# Show the top 10 IPs.
|
||||
print('''
|
||||
Show Top 10 IPs %s''' % the_day.strftime('%b %d, %Y'))
|
||||
iphits = Counter(x['host'] for x in pages if goodagent(x))
|
||||
iptop10 = iphits.most_common(10)
|
||||
for p in iptop10:
|
||||
print(' %5d %s' % p[::-1])
|
||||
print(' %5d total hits' % sum(iphits.values()))
|
||||
print('============================================')
|
||||
|
||||
# CMS Checks
|
||||
|
||||
print(' ')
|
||||
print('CMS Checks')
|
||||
print(' ')
|
||||
|
||||
print('Wordpress Checks')
|
||||
print('============================================')
|
||||
|
||||
d = wp_login_dict
|
||||
# Using dictionary comprehension to find list
|
||||
# keys having value in 0 will be removed from results
|
||||
delete = [key for key in d if d[key] == 0]
|
||||
|
||||
# delete the key
|
||||
for key in delete: del d[key]
|
||||
|
||||
# print(d)
|
||||
|
||||
print('''Wordpress Bruteforce Logins for wp-login.php %s''' % the_day.strftime('%b %d, %Y'))
|
||||
print(' ')
|
||||
# sort by dictionary by the values and print top 10 {key, value} pairs
|
||||
for key in sorted(d, key=keyfunction, reverse=True)[:10]:
|
||||
print(' %5d %s' % (d[key], key))
|
||||
print(' %5d total hits' % sum(dict.values(d)))
|
||||
print(' ')
|
||||
|
||||
d = wp_cron_dict
|
||||
# Using dictionary comprehension to find list
|
||||
# keys having value in 0 will be removed from results
|
||||
delete = [key for key in d if d[key] == 0]
|
||||
|
||||
# delete the key
|
||||
for key in delete: del d[key]
|
||||
|
||||
print('''Wordpress Cron wp-cron.php(virtual cron) checks for %s''' % the_day.strftime('%b %d, %Y'))
|
||||
print(' ')
|
||||
# sort by dictionary by the values and print top 10 {key, value} pairs
|
||||
for key in sorted(d, key=keyfunction, reverse=True)[:10]:
|
||||
print(' %5d %s' % (d[key], key))
|
||||
print(' %5d total hits' % sum(dict.values(d)))
|
||||
print(' ')
|
||||
|
||||
d = wp_xmlrpc_dict
|
||||
# Using dictionary comprehension to find list
|
||||
# keys having value in 0 will be removed from results
|
||||
delete = [key for key in d if d[key] == 0]
|
||||
|
||||
# delete the key
|
||||
for key in delete: del d[key]
|
||||
|
||||
print('''Wordpress XMLRPC Attacks checks for xmlrpc.php for %s''' % the_day.strftime('%b %d, %Y'))
|
||||
print(' ')
|
||||
# sort by dictionary by the values and print top 10 {key, value} pairs
|
||||
for key in sorted(d, key=keyfunction, reverse=True)[:10]:
|
||||
print(' %5d %s' % (d[key], key))
|
||||
print(' %5d total hits' % sum(dict.values(d)))
|
||||
print(' ')
|
||||
|
||||
d = wp_admin_ajax_dict
|
||||
# Using dictionary comprehension to find list
|
||||
# keys having value in 0 will be removed from results
|
||||
delete = [key for key in d if d[key] == 0]
|
||||
|
||||
# delete the key
|
||||
for key in delete: del d[key]
|
||||
|
||||
print('''Wordpress Heartbeat API checks for admin-ajax.php for %s''' % the_day.strftime('%b %d, %Y'))
|
||||
print(' ')
|
||||
# sort by dictionary by the values and print top 10 {key, value} pairs
|
||||
for key in sorted(d, key=keyfunction, reverse=True)[:10]:
|
||||
print(' %5d %s' % (d[key], key))
|
||||
print(' %5d total hits' % sum(dict.values(d)))
|
||||
print('============================================')
|
||||
|
||||
d = drupal_login_dict
|
||||
# Using dictionary comprehension to find list
|
||||
# keys having value in 0 will be removed from results
|
||||
delete = [key for key in d if d[key] == 0]
|
||||
|
||||
# delete the key
|
||||
for key in delete: del d[key]
|
||||
|
||||
print('''Drupal Login Bruteforcing checks for user/login/ for %s''' % the_day.strftime('%b %d, %Y'))
|
||||
print(' ')
|
||||
# sort by dictionary by the values and print top 10 {key, value} pairs
|
||||
for key in sorted(d, key=keyfunction, reverse=True)[:10]:
|
||||
print(' %5d %s' % (d[key], key))
|
||||
print(' %5d total hits' % sum(dict.values(d)))
|
||||
print('============================================')
|
||||
|
||||
d = magento_login_dict
|
||||
# Using dictionary comprehension to find list
|
||||
# keys having value in 0 will be removed from results
|
||||
delete = [key for key in d if d[key] == 0]
|
||||
|
||||
# delete the key
|
||||
for key in delete: del d[key]
|
||||
|
||||
print(
|
||||
'''Magento Login Bruteforcing checks for admin pages /admin_xxxxx/admin/index/index for %s''' % the_day.strftime(
|
||||
'%b %d, %Y'))
|
||||
print(' ')
|
||||
# sort by dictionary by the values and print top 10 {key, value} pairs
|
||||
for key in sorted(d, key=keyfunction, reverse=True)[:10]:
|
||||
print(' %5d %s' % (d[key], key))
|
||||
print(' %5d total hits' % sum(dict.values(d)))
|
||||
print('============================================')
|
||||
|
||||
d = joomla_login_dict
|
||||
# Using dictionary comprehension to find list
|
||||
# keys having value in 0 will be removed from results
|
||||
delete = [key for key in d if d[key] == 0]
|
||||
|
||||
# delete the key
|
||||
for key in delete: del d[key]
|
||||
|
||||
print('''Joomla Login Bruteforcing checks for admin pages /administrator/index.php for %s''' % the_day.strftime(
|
||||
'%b %d, %Y'))
|
||||
print(' ')
|
||||
# sort by dictionary by the values and print top 10 {key, value} pairs
|
||||
for key in sorted(d, key=keyfunction, reverse=True)[:10]:
|
||||
print(' %5d %s' % (d[key], key))
|
||||
print(' %5d total hits' % sum(dict.values(d)))
|
||||
print('============================================')
|
||||
|
||||
d = vbulletin_login_dict
|
||||
# Using dictionary comprehension to find list
|
||||
# keys having value in 0 will be removed from results
|
||||
delete = [key for key in d if d[key] == 0]
|
||||
|
||||
# delete the key
|
||||
for key in delete: del d[key]
|
||||
|
||||
print('''vBulletin Login Bruteforcing checks for admin pages admincp for %s''' % the_day.strftime('%b %d, %Y'))
|
||||
print(' ')
|
||||
# sort by dictionary by the values and print top 10 {key, value} pairs
|
||||
for key in sorted(d, key=keyfunction, reverse=True)[:10]:
|
||||
print(' %5d %s' % (d[key], key))
|
||||
print(' %5d total hits' % sum(dict.values(d)))
|
||||
print('============================================')
|
||||
|
||||
d = opencart_login_dict
|
||||
# Using dictionary comprehension to find list
|
||||
# keys having value in 0 will be removed from results
|
||||
delete = [key for key in d if d[key] == 0]
|
||||
|
||||
# delete the key
|
||||
for key in delete: del d[key]
|
||||
|
||||
print('''Opencart Login Bruteforcing checks for admin pages /admin/index.php for %s''' % the_day.strftime(
|
||||
'%b %d, %Y'))
|
||||
print(' ')
|
||||
# sort by dictionary by the values and print top 10 {key, value} pairs
|
||||
for key in sorted(d, key=keyfunction, reverse=True)[:10]:
|
||||
print(' %5d %s' % (d[key], key))
|
||||
print(' %5d total hits' % sum(dict.values(d)))
|
||||
print('============================================')
|
||||
|
||||
d = prestashop_login_dict
|
||||
# Using dictionary comprehension to find list
|
||||
# keys having value in 0 will be removed from results
|
||||
delete = [key for key in d if d[key] == 0]
|
||||
|
||||
# delete the key
|
||||
for key in delete: del d[key]
|
||||
|
||||
print('''Prestashop Login Bruteforcing checks for admin pages /adminxxxx for %s''' % the_day.strftime('%b %d, %Y'))
|
||||
print(' ')
|
||||
# sort by dictionary by the values and print top 10 {key, value} pairs
|
||||
for key in sorted(d, key=keyfunction, reverse=True)[:10]:
|
||||
print(' %5d %s' % (d[key], key))
|
||||
print(' %5d total hits' % sum(dict.values(d)))
|
||||
print('============================================')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
158
CPScripts/access-logparser.sh
Normal file
158
CPScripts/access-logparser.sh
Normal file
@@ -0,0 +1,158 @@
|
||||
#!/bin/bash
|
||||
## Author: Michael Ramsey
|
||||
## Objective Find A Cyberpanel/cPanel Users Dom/Access logs Stats for last 5 days for all of their domains. v2
|
||||
## https://gitlab.com/mikeramsey/access-log-parser
|
||||
## How to use.
|
||||
# ./access-logparser.sh username
|
||||
#./access-logparser.sh exampleuserbob
|
||||
#
|
||||
##bash <(curl -s https://gitlab.com/mikeramsey/access-log-parser/-/raw/master/access-logparser.sh || wget -qO - https://gitlab.com/mikeramsey/access-log-parser/-/raw/master/access-logparser.sh) exampleuserbob;
|
||||
##
|
||||
Username=$1
|
||||
|
||||
#Detect Control panel
|
||||
if [ -f /usr/local/cpanel/cpanel ]; then
|
||||
# Cpanel check for /usr/local/cpanel/cpanel -V
|
||||
ControlPanel="cpanel"
|
||||
datetimeDcpumon=$(date +"%Y/%b/%d") # 2019/Feb/15
|
||||
#Current Dcpumon file
|
||||
DcpumonCurrentLOG="/var/log/dcpumon/${datetimeDcpumon}" # /var/log/dcpumon/2019/Feb/15
|
||||
#Setup datetimeDcpumonLast5_array
|
||||
declare -a datetimeDcpumonLast5_array=($(date +"%Y/%b/%d") $(date --date='1 day ago' +"%Y/%b/%d") $(date --date='2 days ago' +"%Y/%b/%d") $(date --date='3 days ago' +"%Y/%b/%d") $(date --date='4 days ago' +"%Y/%b/%d")); #for DATE in "${datetimeDcpumonLast5_array[@]}"; do echo $DATE; done;
|
||||
|
||||
user_homedir="/home/${Username}"
|
||||
user_accesslogs="/home/${Username}/logs/"
|
||||
domlogs_path="/usr/local/apache/domlogs/${Username}/"
|
||||
acesslog_sed="-ssl_log"
|
||||
|
||||
elif [ -f /usr/bin/cyberpanel ]; then
|
||||
# CyberPanel check /usr/bin/cyberpanel
|
||||
ControlPanel="cyberpanel"
|
||||
|
||||
#Get users homedir path
|
||||
user_homedir=$(sudo egrep "^${Username}:" /etc/passwd | cut -d: -f6)
|
||||
domlogs_path="${user_homedir}/logs/"
|
||||
acesslog_sed=".access_log"
|
||||
|
||||
else
|
||||
echo "Not able to detect Control panel. Unsupported Control Panel exiting now"
|
||||
exit 1;
|
||||
fi
|
||||
echo "=============================================================";
|
||||
echo "$ControlPanel Control Panel Detected"
|
||||
echo "User Homedirectory: ${user_homedir}"
|
||||
echo "User Domlogs Path: ${domlogs_path}"
|
||||
echo "=============================================================";
|
||||
echo "";
|
||||
#Domlog Date array for past 5 days
|
||||
declare -a datetimeDomLast5_array=($(date +"%d/%b/%Y") $(date --date='1 day ago' +"%d/%b/%Y") $(date --date='2 days ago' +"%d/%b/%Y") $(date --date='3 days ago' +"%d/%b/%Y") $(date --date='4 days ago' +"%d/%b/%Y")); #for DATE in "${datetimeDomLast5_array[@]}"; do echo $DATE; done;
|
||||
|
||||
|
||||
Now=$(date +"%Y-%m-%d_%T")
|
||||
|
||||
user_Snapshot="${Username}-Snapshot_${Now}.txt";
|
||||
|
||||
#create logfile in user's homedirectory.
|
||||
#sudo touch "$user_CyberpanelSnapshot"
|
||||
|
||||
#chown logfile to user
|
||||
#sudo chown ${Username}:${Username} "$user_CyberpanelSnapshot";
|
||||
|
||||
|
||||
main_function() {
|
||||
|
||||
if [ "${ControlPanel}" == "cpanel" ] ;
|
||||
|
||||
then
|
||||
for DATE in "${datetimeDcpumonLast5_array[@]}"; do
|
||||
echo "=============================================================";
|
||||
echo "Find $Username user's highest CPU use processes via Dcpumon Logs for $DATE";
|
||||
sudo grep "$Username" /var/log/dcpumon/"${DATE}";
|
||||
done; echo "";
|
||||
echo "For more information about Dcpumon(Daily Process Logs) see https://docs.cpanel.net/whm/server-status/daily-process-log/82/"
|
||||
echo "============================================================="
|
||||
echo "";
|
||||
else
|
||||
#echo "The DcpumonCurrentLOG '$DcpumonCurrentLOG' was not found. Not running Dcpumon stats"
|
||||
echo "";
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "Web Traffic Stats Check";
|
||||
|
||||
echo "";
|
||||
for DATE in "${datetimeDomLast5_array[@]}"; do
|
||||
echo "=============================================================";
|
||||
echo "HTTP Dom Logs POST Requests for ${DATE} for $Username";
|
||||
|
||||
sudo grep -r "$DATE" ${domlogs_path} | grep POST | awk '{print $1}' | cut -d: -f1|sed -e "s|$domlogs_path||g" -e 's|"||g' -e "s|$acesslog_sed||g" -e "s|$Username/||g"| sort | uniq -c | sort -rn | head
|
||||
echo ""
|
||||
echo "HTTP Dom Logs GET Requests for ${DATE} for $Username"
|
||||
sudo grep -r "$DATE" ${domlogs_path} | grep GET | awk '{print $1}' | cut -d: -f1 |sed -e "s|$domlogs_path||g" -e 's|"||g' -e "s|$acesslog_sed||g" -e "s|$Username/||g"| sort | uniq -c | sort -rn | head
|
||||
echo ""
|
||||
echo "HTTP Dom Logs Top 10 bot/crawler requests per domain name for ${DATE}"
|
||||
sudo grep -r "$DATE" ${domlogs_path} | grep -Ei 'crawl|bot|spider|yahoo|bing|google'| awk '{print $1}' | cut -d: -f1|sed -e "s|$domlogs_path||g" -e 's|"||g' -e "s|$acesslog_sed||g" -e "s|$Username/||g"| sort | uniq -c | sort -rn | head
|
||||
echo ""
|
||||
echo "HTTP Dom Logs top ten IPs for ${DATE} for $Username"
|
||||
|
||||
command=$(sudo grep -r "$DATE" ${domlogs_path} | grep POST | awk '{print $1}'|sed -e 's/^[^=:]*[=:]//' -e 's|"||g' | sort | uniq -c | sort -rn | head| column -t);readarray -t iparray < <( echo "${command}" | tr '/' '\n'); echo ""; for IP in "${iparray[@]}"; do echo "$IP"; done; echo ""; echo "Show unique IP's with whois IP, Country,and ISP"; echo ""; for IP in "${iparray[@]}"; do IP=$(echo "$IP" |grep -Eo '([0-9]{1,3}[.]){3}[0-9]{1,3}|(*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])(\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])(\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])(\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])(\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])(\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])(\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])(\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])){3}))|:)))(%.+)?\s*)'); whois -h whois.cymru.com " -c -p $IP"|cut -d"|" -f 2,4,5|grep -Ev 'IP|whois.cymru.com'; done
|
||||
|
||||
echo ""
|
||||
echo "Checking the IPs that Have Hit the Server Most and What Site they were hitting:"
|
||||
sudo grep -rs "$DATE" ${domlogs_path} | awk {'print $1'} |sed -e "s|$domlogs_path||g" -e 's|"||g' -e "s|$acesslog_sed:| |g"| sort | uniq -c | sort -n | tail -10| sort -rn| column -t
|
||||
echo ""
|
||||
echo "Checking the Top Hits Per Site Per IP:"
|
||||
sudo grep -rs "$DATE" ${domlogs_path} | awk {'print $1,$6,$7'} |sed -e "s|$domlogs_path||g" -e 's|"||g' -e "s|$acesslog_sed:| |g"| sort | uniq -c | sort -n | tail -10| sort -rn| column -t
|
||||
echo ""
|
||||
echo "HTTP Dom Logs find the top number of uri's being requested for ${DATE}"
|
||||
sudo grep -r "$DATE" ${domlogs_path} | grep POST | awk '{print $7}' | cut -d: -f2 |sed "s|$domlogs_path||g"| sort | uniq -c | sort -rn | head| column -t
|
||||
echo ""
|
||||
echo "";
|
||||
echo "View HTTP requests per hour for $Username";
|
||||
sudo grep -r "$DATE" ${domlogs_path} | cut -d[ -f2 | cut -d] -f1 | awk -F: '{print $2":00"}' | sort -n | uniq -c| column -t
|
||||
echo ""
|
||||
echo "CMS Checks"
|
||||
echo ""
|
||||
echo "Wordpress Checks"
|
||||
echo "Wordpress Login Bruteforcing checks for wp-login.php for ${DATE} for $Username"
|
||||
sudo grep -r "$DATE" ${domlogs_path} | grep wp-login.php | cut -f 1 -d ":" |sed -e "s|$domlogs_path||g" -e 's|"||g' -e "s|$acesslog_sed||g" -e "s|$Username/||g"|awk {'print $1,$6,$7'} | sort | uniq -c | sort -n|tail| sort -rn
|
||||
echo ""
|
||||
echo "Wordpress Cron wp-cron.php(virtual cron) checks for ${DATE} for $Username"
|
||||
sudo grep -r "$DATE" ${domlogs_path} | grep wp-cron.php| cut -f 1 -d ":" |sed -e "s|$domlogs_path||g" -e 's|"||g' -e "s|$acesslog_sed||g" -e "s|$Username/||g"|awk {'print $1,$6,$7'} | sort | uniq -c | sort -n|tail| sort -rn
|
||||
echo ""
|
||||
echo "Wordpress XMLRPC Attacks checks for xmlrpc.php for ${DATE} for $Username"
|
||||
sudo grep -r "$DATE" ${domlogs_path} | grep xmlrpc.php| cut -f 1 -d ":" |sed -e "s|$domlogs_path||g" -e 's|"||g' -e "s|$acesslog_sed||g" -e "s|$Username/||g"|awk {'print $1,$6,$7'} | sort | uniq -c | sort -n|tail| sort -rn
|
||||
echo ""
|
||||
echo "Wordpress Heartbeat API checks for admin-ajax.php for ${DATE} for $Username"
|
||||
sudo grep -r "$DATE" ${domlogs_path} | grep admin-ajax.php| cut -f 1 -d ":" |sed -e "s|$domlogs_path||g" -e 's|"||g' -e "s|$acesslog_sed||g" -e "s|$Username/||g"|awk {'print $1,$6,$7'} | sort | uniq -c | sort -n|tail| sort -rn;
|
||||
echo ""
|
||||
echo "CMS Bruteforce Checks"
|
||||
echo "Drupal Login Bruteforcing checks for user/login/ for ${DATE} for $Username"
|
||||
sudo grep -r "$DATE" ${domlogs_path} | grep -E "user/login/" | cut -f 1 -d ":" |sed -e "s|$domlogs_path||g" -e 's|"||g' -e "s|$acesslog_sed||g" -e "s|$Username/||g"|awk {'print $1,$6,$7'} | sort | uniq -c | sort -n|tail| sort -rn
|
||||
echo ""
|
||||
echo "Magento Login Bruteforcing checks for admin pages /admin_xxxxx/admin/index/index for ${DATE} for $Username"
|
||||
sudo grep -r "$DATE" ${domlogs_path} | grep -E "admin_[a-zA-Z0-9_]*[/admin/index/index]" | cut -f 1 -d ":" |sed -e "s|$domlogs_path||g" -e 's|"||g' -e "s|$acesslog_sed||g" -e "s|$Username/||g"|awk {'print $1,$6,$7'} | sort | uniq -c | sort -n|tail| sort -rn
|
||||
echo ""
|
||||
echo "Joomla Login Bruteforcing checks for admin pages /administrator/index.php for ${DATE} for $Username"
|
||||
sudo grep -r "$DATE" ${domlogs_path} | grep -E "/administrator/index.php" | cut -f 1 -d ":" |sed -e "s|$domlogs_path||g" -e 's|"||g' -e "s|$acesslog_sed||g" -e "s|$Username/||g"|awk {'print $1,$6,$7'} | sort | uniq -c | sort -n|tail| sort -rn
|
||||
echo ""
|
||||
echo "vBulletin Login Bruteforcing checks for admin pages admincp for ${DATE} for $Username"
|
||||
sudo grep -r "$DATE" ${domlogs_path} | grep -E "admincp" | cut -f 1 -d ":" |sed -e "s|$domlogs_path||g" -e 's|"||g' -e "s|$acesslog_sed||g" -e "s|$Username/||g"|awk {'print $1,$6,$7'} | sort | uniq -c | sort -n|tail| sort -rn
|
||||
echo ""
|
||||
echo "Opencart Login Bruteforcing checks for admin pages /admin/index.php for ${DATE} for $Username"
|
||||
sudo grep -r "$DATE" ${domlogs_path} | grep -E "/admin/index.php" | cut -f 1 -d ":" |sed -e "s|$domlogs_path||g" -e 's|"||g' -e "s|$acesslog_sed||g" -e "s|$Username/||g"|awk {'print $1,$6,$7'} | sort | uniq -c | sort -n|tail| sort -rn
|
||||
echo ""
|
||||
echo "Prestashop Login Bruteforcing checks for admin pages /adminxxxx for ${DATE} for $Username"
|
||||
sudo grep -r "$DATE" ${domlogs_path} | grep -E "/admin[a-zA-Z0-9_]*$" | cut -f 1 -d ":" |sed -e "s|$domlogs_path||g" -e 's|"||g' -e "s|$acesslog_sed||g" -e "s|$Username/||g"|awk {'print $1,$6,$7'} | sort | uniq -c | sort -n|tail| sort -rn
|
||||
echo ""
|
||||
|
||||
|
||||
done;
|
||||
echo "============================================================="
|
||||
|
||||
|
||||
echo "Contents have been saved to ${user_Snapshot}"
|
||||
}
|
||||
|
||||
# log everything, but also output to stdout
|
||||
main_function 2>&1 | tee -a "${user_Snapshot}"
|
||||
455
CPScripts/fixperms.sh
Normal file
455
CPScripts/fixperms.sh
Normal file
@@ -0,0 +1,455 @@
|
||||
#!/usr/bin/env bash
|
||||
## Author: Michael Ramsey
|
||||
## Objective Fix permissions issues on CyberPanel/cPanel/Plesk for a linux user or users
|
||||
# https://gitlab.com/wizardassistantscripts/fixperms
|
||||
#
|
||||
# Forked from https://github.com/PeachFlame/cPanel-fixperms
|
||||
#
|
||||
# Plesk portion credits too
|
||||
# https://www.orware.com/blog/tips-and-how-tos/plesk/correct-httpdocs-permissions
|
||||
# https://support.plesk.com/hc/en-us/articles/115001969889--BUG-plesk-repair-fs-doesn-t-set-correct-owner-inside-httpdocs
|
||||
|
||||
## How to use.
|
||||
# wget https://gitlab.com/wizardassistantscripts/fixperms/-/raw/master/fixperms.sh ; bash fixperms.sh username
|
||||
#
|
||||
# wget https://gitlab.com/wizardassistantscripts/fixperms/-/raw/master/fixperms.sh ; bash fixperms.sh exampleuserbob
|
||||
#
|
||||
# Or once of
|
||||
## bash <(curl -s https://gitlab.com/wizardassistantscripts/fixperms/-/raw/master/fixperms.sh || wget -qO - https://gitlab.com/wizardassistantscripts/fixperms/-/raw/master/fixperms.sh) exampleuserbob;
|
||||
#
|
||||
# Permanent Install for reuse via the below
|
||||
# wget -O /usr/bin/fixperms https://gitlab.com/wizardassistantscripts/fixperms/-/raw/master/fixperms.sh; chmod +x /usr/bin/fixperms;
|
||||
#
|
||||
# Then
|
||||
# fixperms -v -a Username
|
||||
# fixperms -v -all
|
||||
# Username=$1
|
||||
|
||||
|
||||
#Detect Control panel
|
||||
if [ -f /usr/local/cpanel/cpanel ]; then
|
||||
# Cpanel check for /usr/local/cpanel/cpanel -V
|
||||
ControlPanel="cpanel"
|
||||
#user_homedir="/home/${Username}"
|
||||
|
||||
|
||||
elif [ -f /usr/bin/cyberpanel ]; then
|
||||
# CyberPanel check /usr/bin/cyberpanel
|
||||
ControlPanel="cyberpanel"
|
||||
#Get users homedir path
|
||||
#user_homedir=$(grep -E "^${Username}:" /etc/passwd | cut -d: -f6)
|
||||
|
||||
elif [ -f /usr/local/psa/core.version ]; then
|
||||
# Plesk check /usr/local/psa/core.version
|
||||
ControlPanel="plesk"
|
||||
|
||||
#Get users homedir path
|
||||
#user_homedir=$(grep -E "^${Username}:" /etc/passwd | cut -d: -f6)
|
||||
|
||||
|
||||
else
|
||||
echo "Not able to detect Control panel. Unsupported Control Panel exiting now"
|
||||
exit 1;
|
||||
fi
|
||||
echo "=============================================================";
|
||||
echo "$ControlPanel Control Panel Detected"
|
||||
echo "=============================================================";
|
||||
echo "";
|
||||
|
||||
|
||||
|
||||
# Set verbose to null
|
||||
verbose=""
|
||||
|
||||
|
||||
#Print the help text
|
||||
helptext () {
|
||||
tput bold
|
||||
tput setaf 2
|
||||
echo "Fix perms script help:"
|
||||
echo "Sets file/directory permissions to match suPHP and FastCGI schemes"
|
||||
echo "USAGE: fixperms [options] -a account_name"
|
||||
echo "-------"
|
||||
echo "Options:"
|
||||
echo "-h or --help: print this screen and exit"
|
||||
echo "-v: verbose output"
|
||||
echo "-all: run on all Cyberpanel accounts"
|
||||
echo "--account or -a: specify a Cyberpanel/cPanel/Plesk account"
|
||||
# echo "--domain or -d: specify a Cyberpanel domain"
|
||||
tput sgr0
|
||||
exit 0
|
||||
}
|
||||
|
||||
#Detect OS
|
||||
if [ -f /etc/os-release ]; then
|
||||
# freedesktop.org and systemd
|
||||
. /etc/os-release
|
||||
OS=$NAME
|
||||
VER=$VERSION_ID
|
||||
elif type lsb_release >/dev/null 2>&1; then
|
||||
# linuxbase.org
|
||||
OS=$(lsb_release -si)
|
||||
VER=$(lsb_release -sr)
|
||||
elif [ -f /etc/lsb-release ]; then
|
||||
# For some versions of Debian/Ubuntu without lsb_release command
|
||||
. /etc/lsb-release
|
||||
OS=$DISTRIB_ID
|
||||
VER=$DISTRIB_RELEASE
|
||||
elif [ -f /etc/debian_version ]; then
|
||||
# Older Debian/Ubuntu/etc.
|
||||
OS=Debian
|
||||
VER=$(cat /etc/debian_version)
|
||||
elif [ -f /etc/SuSe-release ]; then
|
||||
# Older SuSE/etc.
|
||||
...
|
||||
elif [ -f /etc/redhat-release ]; then
|
||||
# Older Red Hat, CentOS, etc.
|
||||
...
|
||||
else
|
||||
# Fall back to uname, e.g. "Linux <version>", also works for BSD, etc.
|
||||
OS=$(uname -s)
|
||||
VER=$(uname -r)
|
||||
fi
|
||||
|
||||
|
||||
|
||||
#### Cyberpanel Section
|
||||
|
||||
# fix mailperms
|
||||
fixmailperms_cyberpanel () {
|
||||
tput bold
|
||||
tput setaf 4
|
||||
echo "Fixing mailperms...."
|
||||
tput sgr0
|
||||
#Fix perms of /home/vmail
|
||||
chown -R vmail:vmail /home/vmail
|
||||
chmod 755 /home/vmail
|
||||
find /home/vmail -type d -exec chmod 0755 {} \;
|
||||
find /home/vmail -type f -exec chmod 0640 {} \;
|
||||
echo "Finished fixing mailperms...."
|
||||
|
||||
}
|
||||
|
||||
# Main workhorse, fix perms per account passed to it
|
||||
fixperms_cyberpanel () {
|
||||
|
||||
#Get account from what is passed to the function
|
||||
account=$1
|
||||
|
||||
#Make sure account isn't blank
|
||||
if [ -z "$account" ]
|
||||
then
|
||||
tput bold
|
||||
tput setaf 1
|
||||
echo "Need an account name!"
|
||||
tput sgr0
|
||||
helptext
|
||||
#Else, start doing work
|
||||
else
|
||||
|
||||
# Get linux user from Domain
|
||||
domain_username=$(grep -E "/${1}:" /etc/passwd | cut -d: -f1)
|
||||
if id "$1" >/dev/null 2>&1; then
|
||||
echo "$1 exists"
|
||||
elif id "$domain_username" >/dev/null 2>&1; then
|
||||
echo "Found user: $domain_username from domain: $1"
|
||||
echo "$domain_username exists"
|
||||
account=$domain_username
|
||||
else
|
||||
echo "user does not exist"
|
||||
fi
|
||||
|
||||
|
||||
#Get the account's homedir
|
||||
HOMEDIR=$(grep -E "^${account}:" /etc/passwd | cut -d: -f6)
|
||||
echo "User Homedirectory: ${HOMEDIR}"
|
||||
tput bold
|
||||
tput setaf 4
|
||||
echo "Fixing perms for $account:"
|
||||
tput setaf 3
|
||||
if [ -d "$HOMEDIR/.cagefs" ]; then
|
||||
chmod 775 "$HOMEDIR"/.cagefs
|
||||
chmod 700 "$HOMEDIR"/.cagefs/tmp
|
||||
chmod 700 "$HOMEDIR"/.cagefs/var
|
||||
chmod 777 "$HOMEDIR"/.cagefs/cache
|
||||
chmod 777 "$HOMEDIR"/.cagefs/run
|
||||
fi
|
||||
echo "------------------------"
|
||||
tput setaf 4
|
||||
echo "Fixing website files...."
|
||||
tput sgr0
|
||||
|
||||
|
||||
#Fix individual files in public_html
|
||||
find "$HOMEDIR"/public_html -type d -exec chmod "$verbose" 755 {} \;
|
||||
find "$HOMEDIR"/public_html -type f -print0 | xargs -d$'\n' -r chmod "$verbose" 644
|
||||
find "$HOMEDIR"/public_html -name '*.cgi' -print0 -o -name '*.pl' | xargs -0 -r chmod "$verbose" 755
|
||||
chown $verbose -R "$account":"$account" "$HOMEDIR"/public_html/*
|
||||
# Hidden files test support: https://serverfault.com/a/156481
|
||||
chown "$verbose" -R "$account":"$account" "$HOMEDIR"/public_html/.[^.]*
|
||||
find "$HOMEDIR"/* -name .htaccess -exec chown "$verbose" "$account"."$account" {} \;
|
||||
|
||||
tput bold
|
||||
tput setaf 4
|
||||
echo "Fixing public_html...."
|
||||
tput sgr0
|
||||
#Fix perms of public_html itself
|
||||
chown "$verbose" "$account":nobody "$HOMEDIR"/public_html
|
||||
chmod "$verbose" 755 "$HOMEDIR"/public_html
|
||||
|
||||
tput bold
|
||||
tput setaf 4
|
||||
echo "Fixing logs...."
|
||||
tput sgr0
|
||||
#Fix perms of $HOMEDIR/logs
|
||||
chown "$verbose" nobody:"$account" "$HOMEDIR"/logs
|
||||
chmod "$verbose" 750 "$HOMEDIR"/logs
|
||||
find "$HOMEDIR"/logs/* -name '*.access_log' -exec chown "$verbose" nobody."$account" {} \;
|
||||
|
||||
|
||||
|
||||
#Fix subdomains that lie outside of public_html
|
||||
#tput setaf 3
|
||||
#tput bold
|
||||
#echo "------------------------"
|
||||
#tput setaf 4
|
||||
#echo "Fixing any domains with a document root outside of public_html...."
|
||||
#for SUBDOMAIN in $(grep -i documentroot /var/cpanel/userdata/$account/* | grep -v '.cache\|_SSL' | awk '{print $2}' | grep -v public_html)
|
||||
#do
|
||||
#tput bold
|
||||
#tput setaf 4
|
||||
#echo "Fixing sub/addon domain document root $SUBDOMAIN...."
|
||||
#tput sgr0
|
||||
#find $SUBDOMAIN -type d -exec chmod $verbose 755 {} \;
|
||||
#find $SUBDOMAIN -type f -print0 | xargs -d$'\n' -r chmod $verbose 644
|
||||
#find $SUBDOMAIN -name '*.cgi' -o -name '*.pl' | xargs -r chmod $verbose 755
|
||||
#chown $verbose -R $account:$account $SUBDOMAIN
|
||||
#find $SUBDOMAIN -name .htaccess -exec chown $verbose $account.$account {} \;
|
||||
#done
|
||||
|
||||
#Finished
|
||||
tput bold
|
||||
tput setaf 3
|
||||
echo "Finished!"
|
||||
echo "------------------------"
|
||||
printf "\n\n"
|
||||
tput sgr0
|
||||
fi
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
|
||||
#########cPanel
|
||||
# Main workhorse, fix perms per account passed to it
|
||||
fixperms_cpanel () {
|
||||
|
||||
#Get account from what is passed to the function
|
||||
account=$1
|
||||
|
||||
#Check account against cPanel users file
|
||||
if ! grep "$account" /var/cpanel/users/*
|
||||
then
|
||||
tput bold
|
||||
tput setaf 1
|
||||
echo "Invalid cPanel account"
|
||||
tput sgr0
|
||||
exit 0
|
||||
fi
|
||||
|
||||
#Make sure account isn't blank
|
||||
if [ -z "$account" ]
|
||||
then
|
||||
tput bold
|
||||
tput setaf 1
|
||||
echo "Need an account name!"
|
||||
tput sgr0
|
||||
helptext
|
||||
#Else, start doing work
|
||||
else
|
||||
|
||||
#Get the account's homedir
|
||||
HOMEDIR=$(grep -E "^${account}:" /etc/passwd | cut -d: -f6)
|
||||
echo "User Homedirectory: ${HOMEDIR}"
|
||||
tput bold
|
||||
tput setaf 4
|
||||
echo "Fixing perms for $account:"
|
||||
tput setaf 3
|
||||
if [ -d "$HOMEDIR/.cagefs" ]; then
|
||||
chmod 775 "$HOMEDIR"/.cagefs
|
||||
chmod 700 "$HOMEDIR"/.cagefs/tmp
|
||||
chmod 700 "$HOMEDIR"/.cagefs/var
|
||||
chmod 777 "$HOMEDIR"/.cagefs/cache
|
||||
chmod 777 "$HOMEDIR"/.cagefs/run
|
||||
fi
|
||||
echo "------------------------"
|
||||
tput setaf 4
|
||||
echo "Fixing website files...."
|
||||
tput sgr0
|
||||
|
||||
|
||||
|
||||
#Fix individual files in public_html
|
||||
find "$HOMEDIR"/public_html -type d -exec chmod "$verbose" 755 {} \;
|
||||
find "$HOMEDIR"/public_html -type f -print0 | xargs -0 -d$'\n' -r chmod "$verbose" 644
|
||||
find "$HOMEDIR"/public_html -name '*.cgi' -print0 -o -name '*.pl' | xargs -0 -r chmod "$verbose" 755
|
||||
chown $verbose -R "$account":"$account" "$HOMEDIR"/public_html/*
|
||||
# fix hidden files and folders like .well-known/ with root or other user perms
|
||||
chown "$verbose" -R "$account":"$account" "$HOMEDIR"/public_html/.[^.]*
|
||||
find "$HOMEDIR"/* -name .htaccess -exec chown "$verbose" "$account"."$account" {} \;
|
||||
|
||||
tput bold
|
||||
tput setaf 4
|
||||
echo "Fixing public_html...."
|
||||
tput sgr0
|
||||
#Fix perms of public_html itself
|
||||
chown "$verbose" "$account":nobody "$HOMEDIR"/public_html
|
||||
chmod "$verbose" 750 "$HOMEDIR"/public_html
|
||||
|
||||
#Fix subdomains that lie outside of public_html
|
||||
tput setaf 3
|
||||
tput bold
|
||||
echo "------------------------"
|
||||
tput setaf 4
|
||||
echo "Fixing any domains with a document root outside of public_html...."
|
||||
for SUBDOMAIN in $(grep -i documentroot /var/cpanel/userdata/"$account"/* | grep -v '.cache\|_SSL' | awk '{print $2}' | grep -v public_html)
|
||||
do
|
||||
tput bold
|
||||
tput setaf 4
|
||||
echo "Fixing sub/addon domain document root $SUBDOMAIN...."
|
||||
tput sgr0
|
||||
find "$SUBDOMAIN" -type d -exec chmod "$verbose" 755 {} \;
|
||||
find "$SUBDOMAIN" -type f -print0 | xargs -0 -d$'\n' -r chmod "$verbose" 644
|
||||
find "$SUBDOMAIN" -name '*.cgi' -print0 -o -name '*.pl' | xargs -0 -r chmod "$verbose" 755
|
||||
chown "$verbose" -R "$account":"$account" "$SUBDOMAIN"
|
||||
chmod "$verbose" 755 "$SUBDOMAIN"
|
||||
find "$SUBDOMAIN" -name .htaccess -exec chown "$verbose" "$account"."$account" {} \;
|
||||
done
|
||||
|
||||
#Finished
|
||||
tput bold
|
||||
tput setaf 3
|
||||
echo "Finished!"
|
||||
echo "------------------------"
|
||||
printf "\n\n"
|
||||
tput sgr0
|
||||
fi
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
###################################
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
##################################
|
||||
|
||||
fixperms () {
|
||||
Username=$1
|
||||
if [ "${ControlPanel}" == "cpanel" ] ; then
|
||||
|
||||
fixperms_cpanel "${Username}"
|
||||
# Fix users mailperms
|
||||
tput bold
|
||||
tput setaf 4
|
||||
echo "Fixing Mailperms...."
|
||||
tput sgr0
|
||||
/scripts/mailperm --verbose "${Username}"
|
||||
#Finished
|
||||
tput bold
|
||||
tput setaf 3
|
||||
echo "Finished!"
|
||||
echo "------------------------"
|
||||
printf "\n\n"
|
||||
tput sgr0
|
||||
|
||||
elif [ "${ControlPanel}" == "cyberpanel" ] ; then
|
||||
|
||||
fixperms_cyberpanel "${Username}"
|
||||
fixmailperms_cyberpanel
|
||||
|
||||
|
||||
elif [ "${ControlPanel}" == "plesk" ] ; then
|
||||
#Get users homedir path
|
||||
user_homedir=$(grep -E "^${Username}:" /etc/passwd | cut -d: -f6)
|
||||
echo "User Homedirectory: ${user_homedir}"
|
||||
echo "Resetting perms/ownership for ${user_homedir}/httpdocs"
|
||||
sudo chown -R "${Username}":psacln "${user_homedir}"/httpdocs
|
||||
sudo chown "${Username}":psaserv "${user_homedir}"/httpdocs
|
||||
|
||||
fi
|
||||
}
|
||||
|
||||
all () {
|
||||
|
||||
if [ "${ControlPanel}" == "cpanel" ] ; then
|
||||
|
||||
for user in $(cut -d: -f1 /etc/domainusers)
|
||||
do
|
||||
fixperms_cpanel "$user"
|
||||
done
|
||||
# Fix all users mailperms
|
||||
/scripts/mailperm --verbose
|
||||
|
||||
elif [ "${ControlPanel}" == "cyberpanel" ] ; then
|
||||
|
||||
if [[ $OS = 'CentOS Linux' ]] ; then
|
||||
for user in $(getent passwd | awk -F: '5001<$3 && $3<6000 {print $1}' |grep -v spamd)
|
||||
do
|
||||
fixperms_cyberpanel "$user"
|
||||
done
|
||||
fixmailperms_cyberpanel
|
||||
fi
|
||||
|
||||
if [[ $OS = 'Ubuntu' ]] ; then
|
||||
for user in $(getent passwd | awk -F: '1001<$3 && $3<2000 {print $1}')
|
||||
do
|
||||
fixperms_cyberpanel "$user"
|
||||
done
|
||||
fixmailperms_cyberpanel
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
|
||||
#Main function, switches options passed to it
|
||||
case "$1" in
|
||||
|
||||
-h) helptext
|
||||
;;
|
||||
--help) helptext
|
||||
;;
|
||||
-v) verbose="-v"
|
||||
|
||||
case "$2" in
|
||||
|
||||
-all) all
|
||||
;;
|
||||
--account) fixperms "$3"
|
||||
;;
|
||||
-a) fixperms "$3"
|
||||
;;
|
||||
*) tput bold
|
||||
tput setaf 1
|
||||
echo "Invalid Option!"
|
||||
helptext
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
|
||||
-all) all
|
||||
;;
|
||||
--account) fixperms "$2"
|
||||
;;
|
||||
-a) fixperms "$2"
|
||||
;;
|
||||
*)
|
||||
tput bold
|
||||
tput setaf 1
|
||||
echo "Invalid Option!"
|
||||
helptext
|
||||
;;
|
||||
esac
|
||||
390
CPScripts/mailscannerinstaller.sh
Normal file
390
CPScripts/mailscannerinstaller.sh
Normal file
@@ -0,0 +1,390 @@
|
||||
#!/bin/bash
|
||||
#systemctl stop firewalld
|
||||
|
||||
check_return() {
|
||||
#check previous command result , 0 = ok , non-0 = something wrong.
|
||||
if [[ $? -eq "0" ]]; then
|
||||
:
|
||||
else
|
||||
echo -e "\ncommand failed, exiting..."
|
||||
exit
|
||||
fi
|
||||
}
|
||||
|
||||
echo 'backup configs'
|
||||
cp /etc/dovecot/dovecot.conf /etc/dovecot/dovecot.conf-bak_$(date '+%Y-%m-%d_%H_%M:%S')
|
||||
cp /etc/postfix/master.cf /etc/postfix/master.cf-bak_$(date '+%Y-%m-%d_%H_%M:%S')
|
||||
cp /etc/postfix/main.cf /etc/postfix/main.cf-bak_$(date '+%Y-%m-%d_%H_%M:%S')
|
||||
cp /etc/dovecot/dovecot-sql.conf.ext /etc/dovecot/dovecot-sql.conf.ext-bak_$(date '+%Y-%m-%d_%H_%M:%S')
|
||||
|
||||
ZONE=$(firewall-cmd --get-default-zone)
|
||||
firewall-cmd --zone=$ZONE --add-port=4190/tcp --permanent
|
||||
systemctl stop firewalld
|
||||
|
||||
echo 'Stop CSF'
|
||||
csf -x
|
||||
|
||||
MAILSCANNER=/etc/MailScanner
|
||||
|
||||
if [ -d $MAILSCANNER ]; then
|
||||
echo "MailScanner found. If you wish to reinstall then remove the package and revert"
|
||||
echo "Postfix back to its original config at /etc/postfix/main.cf and remove"
|
||||
echo "/etc/MailScanner and /usr/share/MailScanner directories"
|
||||
exit
|
||||
fi
|
||||
|
||||
### Check SpamAssasin before moving forward
|
||||
|
||||
DIR=/etc/mail/spamassassin
|
||||
|
||||
if [ -d "$DIR" ]; then
|
||||
sa-update
|
||||
else
|
||||
echo "Please install SpamAssasin through the CyberPanel interface before proceeding"
|
||||
exit
|
||||
fi
|
||||
|
||||
### OS Detection
|
||||
Server_OS=""
|
||||
Server_OS_Version=""
|
||||
if grep -q -E "CentOS Linux 7|CentOS Linux 8" /etc/os-release ; then
|
||||
Server_OS="CentOS"
|
||||
elif grep -q "AlmaLinux-8" /etc/os-release ; then
|
||||
Server_OS="AlmaLinux"
|
||||
elif grep -q -E "CloudLinux 7|CloudLinux 8" /etc/os-release ; then
|
||||
Server_OS="CloudLinux"
|
||||
elif grep -q -E "Rocky Linux" /etc/os-release ; then
|
||||
Server_OS="RockyLinux"
|
||||
elif grep -q -E "Ubuntu 18.04|Ubuntu 20.04|Ubuntu 20.10|Ubuntu 22.04" /etc/os-release ; then
|
||||
Server_OS="Ubuntu"
|
||||
elif grep -q -E "openEuler 20.03|openEuler 22.03" /etc/os-release ; then
|
||||
Server_OS="openEuler"
|
||||
else
|
||||
echo -e "Unable to detect your system..."
|
||||
echo -e "\nCyberPanel is supported on x86_64 based Ubuntu 18.04, Ubuntu 20.04, Ubuntu 20.10, Ubuntu 22.04, CentOS 7, CentOS 8, AlmaLinux 8, RockyLinux 8, CloudLinux 7, CloudLinux 8, openEuler 20.03, openEuler 22.03...\n"
|
||||
exit
|
||||
fi
|
||||
|
||||
Server_OS_Version=$(grep VERSION_ID /etc/os-release | awk -F[=,] '{print $2}' | tr -d \" | head -c2 | tr -d . )
|
||||
|
||||
echo -e "System: $Server_OS $Server_OS_Version detected...\n"
|
||||
|
||||
if [[ $Server_OS = "CloudLinux" ]] || [[ "$Server_OS" = "AlmaLinux" ]] || [[ "$Server_OS" = "RockyLinux" ]] ; then
|
||||
Server_OS="CentOS"
|
||||
#CloudLinux gives version id like 7.8, 7.9, so cut it to show first number only
|
||||
#treat CloudLinux, Rocky and Alma as CentOS
|
||||
fi
|
||||
|
||||
if [[ $Server_OS = "CentOS" ]] && [[ "$Server_OS_Version" = "7" ]] ; then
|
||||
|
||||
setenforce 0
|
||||
yum install -y perl yum-utils perl-CPAN
|
||||
yum install -y gcc cpp perl bzip2 zip make patch automake rpm-build perl-Archive-Zip perl-Filesys-Df perl-OLE-Storage_Lite perl-Sys-Hostname-Long perl-Sys-SigAction perl-Net-CIDR perl-DBI perl-MIME-tools perl-DBD-SQLite binutils glibc-devel perl-Filesys-Df zlib unzip zlib-devel wget mlocate clamav "perl(DBD::mysql)"
|
||||
|
||||
rpm -Uvh https://forensics.cert.org/centos/cert/7/x86_64/unrar-5.4.0-1.el7.x86_64.rpm
|
||||
export PERL_MM_USE_DEFAULT=1
|
||||
curl -L https://cpanmin.us | perl - App::cpanminus
|
||||
perl -MCPAN -e 'install Encoding::FixLatin'
|
||||
perl -MCPAN -e 'install Digest::SHA1'
|
||||
perl -MCPAN -e 'install Geo::IP'
|
||||
perl -MCPAN -e 'install Razor2::Client::Agent'
|
||||
perl -MCPAN -e 'install Net::Patricia'
|
||||
|
||||
freshclam -v
|
||||
|
||||
elif [[ $Server_OS = "CentOS" ]] && [[ "$Server_OS_Version" = "8" ]] ; then
|
||||
|
||||
setenforce 0
|
||||
yum install -y perl yum-utils perl-CPAN
|
||||
dnf --enablerepo=powertools install -y perl-IO-stringy
|
||||
dnf --enablerepo=PowerTools install -y perl-IO-stringy
|
||||
yum install -y gcc cpp perl bzip2 zip make patch automake rpm-build perl-Archive-Zip perl-Filesys-Df perl-OLE-Storage_Lite perl-Net-CIDR perl-DBI perl-MIME-tools perl-DBD-SQLite binutils glibc-devel perl-Filesys-Df zlib unzip zlib-devel wget mlocate clamav clamav-update "perl(DBD::mysql)"
|
||||
|
||||
rpm -Uvh https://forensics.cert.org/centos/cert/8/x86_64/unrar-5.4.0-1.el8.x86_64.rpm
|
||||
|
||||
export PERL_MM_USE_DEFAULT=1
|
||||
curl -L https://cpanmin.us | perl - App::cpanminus
|
||||
|
||||
perl -MCPAN -e 'install Encoding::FixLatin'
|
||||
perl -MCPAN -e 'install Digest::SHA1'
|
||||
perl -MCPAN -e 'install Geo::IP'
|
||||
perl -MCPAN -e 'install Razor2::Client::Agent'
|
||||
perl -MCPAN -e 'install Sys::Hostname::Long'
|
||||
perl -MCPAN -e 'install Sys::SigAction'
|
||||
|
||||
freshclam -v
|
||||
|
||||
elif [ "$CLNVERSION" = "ID=\"cloudlinux\"" ]; then
|
||||
|
||||
setenforce 0
|
||||
yum install -y perl yum-utils perl-CPAN
|
||||
yum install -y gcc cpp perl bzip2 zip make patch automake rpm-build perl-Archive-Zip perl-Filesys-Df perl-OLE-Storage_Lite perl-Sys-Hostname-Long perl-Sys-SigAction perl-Net-CIDR perl-DBI perl-MIME-tools perl-DBD-SQLite binutils glibc-devel perl-Filesys-Df zlib unzip zlib-devel wget mlocate clamav "perl(DBD::mysql)"
|
||||
|
||||
rpm -Uvh https://forensics.cert.org/centos/cert/7/x86_64/unrar-5.4.0-1.el7.x86_64.rpm
|
||||
export PERL_MM_USE_DEFAULT=1
|
||||
curl -L https://cpanmin.us | perl - App::cpanminus
|
||||
perl -MCPAN -e 'install Encoding::FixLatin'
|
||||
perl -MCPAN -e 'install Digest::SHA1'
|
||||
perl -MCPAN -e 'install Geo::IP'
|
||||
perl -MCPAN -e 'install Razor2::Client::Agent'
|
||||
perl -MCPAN -e 'install Net::Patricia'
|
||||
|
||||
freshclam -v
|
||||
|
||||
elif [[ $Server_OS = "Ubuntu" ]]; then
|
||||
|
||||
apt-get install -y libmysqlclient-dev
|
||||
|
||||
apt-get install -y cpanminus gcc perl bzip2 zip make patch automake rpm libarchive-zip-perl libfilesys-df-perl libole-storage-lite-perl libsys-hostname-long-perl libsys-sigaction-perl libregexp-common-net-cidr-perl libmime-tools-perl libdbd-sqlite3-perl binutils build-essential libfilesys-df-perl zlib1g unzip mlocate clamav libdbd-mysql-perl unrar libclamav-dev libclamav-client-perl libclamunrar9
|
||||
|
||||
cpanm Encoding::FixLatin
|
||||
cpanm Digest::SHA1
|
||||
cpanm Geo::IP
|
||||
cpanm Razor2::Client::Agent
|
||||
cpanm Net::Patricia
|
||||
cpanm Net::CIDR
|
||||
|
||||
sudo systemctl stop clamav-freshclam.service
|
||||
|
||||
freshclam
|
||||
|
||||
sudo systemctl start clamav-freshclam.service
|
||||
|
||||
fi
|
||||
|
||||
echo "header_checks = regexp:/etc/postfix/header_checks" >>/etc/postfix/main.cf
|
||||
echo "/^Received:/ HOLD" >>/etc/postfix/header_checks
|
||||
|
||||
systemctl restart postfix
|
||||
|
||||
if [[ $Server_OS = "Ubuntu" ]]; then
|
||||
wget https://github.com/MailScanner/v5/releases/download/5.4.4-1/MailScanner-5.4.4-1.noarch.deb
|
||||
dpkg -i *.noarch.deb
|
||||
|
||||
mkdir /var/run/MailScanner
|
||||
mkdir /var/lock/subsys
|
||||
mkdir /var/lock/subsys/MailScanner
|
||||
chown -R postfix:postfix /var/run/MailScanner
|
||||
chown -R postfix:postfix /var/lock/subsys/MailScanner
|
||||
chown -R postfix:postfix /var/spool/MailScanner
|
||||
|
||||
elif [[ $Server_OS = "CentOS" ]]; then
|
||||
wget https://github.com/MailScanner/v5/releases/download/5.4.4-1/MailScanner-5.4.4-1.rhel.noarch.rpm
|
||||
rpm -Uvh *.rhel.noarch.rpm
|
||||
elif [ "$OS" = "NAME=\"CloudLinux\"" ]; then
|
||||
wget https://github.com/MailScanner/v5/releases/download/5.3.3-1/MailScanner-5.3.3-1.rhel.noarch.rpm
|
||||
rpm -Uvh *.rhel.noarch.rpm
|
||||
fi
|
||||
|
||||
mkdir /var/spool/MailScanner/spamassassin
|
||||
|
||||
chown postfix.mtagroup /var/spool/MailScanner/spamassassin
|
||||
chown root.mtagroup /var/spool/MailScanner/incoming/
|
||||
chown postfix.mtagroup /var/spool/MailScanner/milterin
|
||||
chown postfix.mtagroup /var/spool/MailScanner/milterout
|
||||
chown postfix.mtagroup /var/spool/postfix/hold
|
||||
chown postfix.mtagroup /var/spool/postfix/incoming
|
||||
usermod -a -G mtagroup nobody
|
||||
|
||||
chmod g+rx /var/spool/postfix/incoming
|
||||
chmod g+rx /var/spool/postfix/hold
|
||||
chmod -R 0775 /var/spool/postfix/incoming
|
||||
chmod -R 0775 /var/spool/postfix/hold
|
||||
|
||||
sed -i 's/^Run As User =.*/& postfix/' /etc/MailScanner/MailScanner.conf
|
||||
sed -i 's/^Run As Group =.*/& postfix/' /etc/MailScanner/MailScanner.conf
|
||||
sed -i 's/^Incoming Queue Dir =.*/Incoming Queue Dir = \/var\/spool\/postfix\/hold/' /etc/MailScanner/MailScanner.conf
|
||||
sed -i 's/^Outgoing Queue Dir =.*/Outgoing Queue Dir = \/var\/spool\/postfix\/incoming/' /etc/MailScanner/MailScanner.conf
|
||||
sed -i 's/^MTA =.*/MTA = postfix/' /etc/MailScanner/MailScanner.conf
|
||||
sed -i 's/^Quarantine User =.*/& postfix/' /etc/MailScanner/MailScanner.conf
|
||||
sed -i 's/^Quarantine Group =.*/& mtagroup/' /etc/MailScanner/MailScanner.conf
|
||||
sed -i 's/^Quarantine Permissions =.*/Quarantine Permissions = 640/' /etc/MailScanner/MailScanner.conf
|
||||
sed -i 's/^Virus Scanners =.*/Virus Scanners = clamav/' /etc/MailScanner/MailScanner.conf
|
||||
sed -i 's/^Is Definitely Not Spam =.*/Is Definitely Not Spam = \&SQLWhitelist/' /etc/MailScanner/MailScanner.conf
|
||||
sed -i 's/^Is Definitely Spam =.*/Is Definitely Spam = \&SQLBlacklist/' /etc/MailScanner/MailScanner.conf
|
||||
sed -i 's/^SpamAssassin User State Dir =.*/& \/var\/spool\/MailScanner\/spamassassin/' /etc/MailScanner/MailScanner.conf
|
||||
sed -i 's/^Always Looked Up Last =.*/Always Looked Up Last = \&MailWatchLogging/' /etc/MailScanner/MailScanner.conf
|
||||
sed -i 's/^Quarantine Whole Message =.*/Quarantine Whole Message = yes/' /etc/MailScanner/MailScanner.conf
|
||||
sed -i 's/^Spam List =.*/Spam List = SBL + XBL/' /etc/MailScanner/MailScanner.conf
|
||||
sed -i 's/^Sign Clean Messages =.*/Sign Clean Messages = no/' /etc/MailScanner/MailScanner.conf
|
||||
|
||||
mkdir /usr/local/CyberCP/public/mailwatch
|
||||
|
||||
cd /usr/local/CyberCP/public/mailwatch
|
||||
|
||||
git clone --depth=1 https://github.com/mailwatch/MailWatch.git --branch 1.2 --single-branch
|
||||
|
||||
mv /usr/local/CyberCP/public/mailwatch/MailWatch/* /usr/local/CyberCP/public/mailwatch/
|
||||
|
||||
PASSWORD=$(cat /etc/cyberpanel/mysqlPassword)
|
||||
USER=root
|
||||
DATABASE=mailscanner
|
||||
ADMINPASS=$(cat /etc/cyberpanel/adminPass)
|
||||
|
||||
### Fix a bug in MailWatch SQL File
|
||||
|
||||
sed -i 's/char(512)/char(255)/g' /usr/local/CyberCP/public/mailwatch/create.sql
|
||||
|
||||
##
|
||||
|
||||
mysql -u${USER} -p${PASSWORD} <"/usr/local/CyberCP/public/mailwatch/create.sql"
|
||||
mysql -u${USER} -p${PASSWORD} -e "use mailscanner"
|
||||
mysql -u${USER} -D${DATABASE} -p${PASSWORD} -e "GRANT ALL ON mailscanner.* TO root@localhost IDENTIFIED BY '${PASSWORD}';"
|
||||
mysql -u${USER} -D${DATABASE} -p${PASSWORD} -e "FLUSH PRIVILEGES;"
|
||||
mysql -u${USER} -D${DATABASE} -p${PASSWORD} -e "INSERT INTO mailscanner.users SET username = 'admin', password = MD5('${ADMINPASS}'), fullname = 'admin', type = 'A';"
|
||||
|
||||
cp /usr/local/CyberCP/public/mailwatch/mailscanner/conf.php.example /usr/local/CyberCP/public/mailwatch/mailscanner/conf.php
|
||||
|
||||
sed -i "s/^define('DB_USER',.*/define('DB_USER','root');/" /usr/local/CyberCP/public/mailwatch/mailscanner/conf.php
|
||||
sed -i "s/^define('DB_PASS',.*/define('DB_PASS','${PASSWORD}');/" /usr/local/CyberCP/public/mailwatch/mailscanner/conf.php
|
||||
sed -i "s/^define('MAILWATCH_HOME',.*/define(\'MAILWATCH_HOME\', \'\/usr\/local\/CyberCP\/public\/mailwatch\/mailscanner');/" /usr/local/CyberCP/public/mailwatch/mailscanner/conf.php
|
||||
|
||||
MSDEFAULT=/etc/MailScanner/defaults
|
||||
if [ -f "$MSDEFAULT" ]; then
|
||||
sed -i 's/^run_mailscanner=.*/run_mailscanner=1/' /etc/MailScanner/defaults
|
||||
elif [ ! -f "$MSDEFAULT" ]; then
|
||||
touch /etc/MailScanner/defaults
|
||||
echo "run_mailscanner=1" >>/etc/MailScanner/defaults
|
||||
fi
|
||||
|
||||
cp /usr/local/CyberCP/public/mailwatch/MailScanner_perl_scripts/MailWatchConf.pm /usr/share/MailScanner/perl/custom/
|
||||
sed -i 's/^my (\$db_user) = .*/my (\$db_user) = \x27'${USER}'\x27;/' /usr/share/MailScanner/perl/custom/MailWatchConf.pm
|
||||
sed -i 's/^my (\$db_pass) = .*/my (\$db_pass) = \x27'${PASSWORD}'\x27;/' /usr/share/MailScanner/perl/custom/MailWatchConf.pm
|
||||
ln -s /usr/local/CyberCP/public/mailwatch/MailScanner_perl_scripts/MailWatch.pm /usr/share/MailScanner/perl/custom
|
||||
ln -s /usr/local/CyberCP/public/mailwatch/MailScanner_perl_scripts/SQLBlackWhiteList.pm /usr/share/MailScanner/perl/custom
|
||||
ln -s /usr/local/CyberCP/public/mailwatch/MailScanner_perl_scripts/SQLSpamSettings.pm /usr/share/MailScanner/perl/custom
|
||||
sed -i "s/^\$pathToFunctions =.*/\$pathToFunctions = '\/usr\/local\/CyberCP\/public\/mailwatch\/mailscanner\/functions.php';/" /usr/local/CyberCP/public/mailwatch/upgrade.php
|
||||
|
||||
/usr/local/lsws/lsphp72/bin/php /usr/local/CyberCP/public/mailwatch/upgrade.php
|
||||
systemctl enable mailscanner
|
||||
systemctl restart mailscanner
|
||||
|
||||
IPADDRESS=$(cat /etc/cyberpanel/machineIP)
|
||||
|
||||
### Furhter onwards is sieve configurations
|
||||
|
||||
#echo 'Setting up spamassassin and sieve to deliver spam to Junk folder by default'
|
||||
##echo "If you wish mailscanner/spamassassin to send spam email to a spam folder please follow the tutorial on the Cyberpanel Website"
|
||||
#echo 'Fix protocols'
|
||||
#sed -i 's/^protocols =.*/protocols = imap pop3 lmtp sieve/g' /etc/dovecot/dovecot.conf
|
||||
#
|
||||
#sed -i "s|^user_query.*|user_query = SELECT '5000' as uid, '5000' as gid, '/home/vmail/%d/%n' as home,mail FROM e_users WHERE email='%u';|g" /etc/dovecot/dovecot-sql.conf.ext
|
||||
#
|
||||
#if [ "$OS" = "NAME=\"Ubuntu\"" ]; then
|
||||
# if [ "$UBUNTUVERSION" = "VERSION_ID=\"18.04\"" ]; then
|
||||
# apt-get install -y dovecot-managesieved dovecot-sieve dovecot-lmtpd net-tools pflogsumm
|
||||
# elif [ "$UBUNTUVERSION" = "VERSION_ID=\"20.04\"" ]; then
|
||||
# apt-get install -y libmysqlclient-dev
|
||||
# sed -e '/deb/ s/^#*/#/' -i /etc/apt/sources.list.d/dovecot.list
|
||||
# apt install -y dovecot-lmtpd dovecot-managesieved dovecot-sieve net-tools pflogsumm
|
||||
# fi
|
||||
#
|
||||
#elif [ "$CENTOSVERSION" = "VERSION_ID=\"7\"" ]; then
|
||||
#
|
||||
# yum install -y nano net-tools dovecot-pigeonhole postfix-perl-scripts
|
||||
#
|
||||
#elif [ "$CENTOSVERSION" = "VERSION_ID=\"8\"" ]; then
|
||||
#
|
||||
# rpm -Uvh http://mirror.ghettoforge.org/distributions/gf/el/8/gf/x86_64/gf-release-8-11.gf.el8.noarch.rpm
|
||||
# dnf --enablerepo=gf-plus upgrade -y dovecot23*
|
||||
# dnf --enablerepo=gf-plus install -y dovecot23-pigeonhole
|
||||
# dnf install -y net-tools postfix-perl-scripts
|
||||
#
|
||||
#elif [ "$CLNVERSION" = "ID=\"cloudlinux\"" ]; then
|
||||
# yum install -y nano net-tools dovecot-pigeonhole postfix-perl-scripts
|
||||
#fi
|
||||
#
|
||||
## Create Sieve files
|
||||
#mkdir -p /etc/dovecot/sieve/global
|
||||
#touch /var/log/{dovecot-lda-errors.log,dovecot-lda.log}
|
||||
#touch /var/log/{dovecot-sieve-errors.log,dovecot-sieve.log}
|
||||
#touch /var/log/{dovecot-lmtp-errors.log,dovecot-lmtp.log}
|
||||
#touch /etc/dovecot/sieve/default.sieve
|
||||
#chown vmail: -R /etc/dovecot/sieve
|
||||
#chown vmail:mail /var/log/dovecot-*
|
||||
#
|
||||
#echo 'Create Sieve Default spam to Junk rule'
|
||||
#cat >>/etc/dovecot/sieve/default.sieve <<EOL
|
||||
#require "fileinto";
|
||||
#if header :contains "X-Spam-Flag" "YES" {
|
||||
# fileinto "INBOX.Junk E-mail";
|
||||
#}
|
||||
#EOL
|
||||
#
|
||||
#echo "Adding Sieve to /etc/dovecot/dovecot.conf"
|
||||
#cat >>/etc/dovecot/dovecot.conf <<EOL
|
||||
#
|
||||
#service managesieve-login {
|
||||
# inet_listener sieve {
|
||||
# port = 4190
|
||||
# }
|
||||
#}
|
||||
#service managesieve {
|
||||
#}
|
||||
#protocol sieve {
|
||||
# managesieve_max_line_length = 65536
|
||||
# managesieve_implementation_string = dovecot
|
||||
# log_path = /var/log/dovecot-sieve-errors.log
|
||||
# info_log_path = /var/log/dovecot-sieve.log
|
||||
#}
|
||||
#plugin {
|
||||
#sieve = /home/vmail/%d/%n/dovecot.sieve
|
||||
#sieve_global_path = /etc/dovecot/sieve/default.sieve
|
||||
#sieve_dir = /home/vmail/%d/%n/sieve
|
||||
#sieve_global_dir = /etc/dovecot/sieve/global/
|
||||
#}
|
||||
#protocol lda {
|
||||
# mail_plugins = $mail_plugins sieve quota
|
||||
# postmaster_address = postmaster@example.com
|
||||
# hostname = server.example.com
|
||||
# auth_socket_path = /var/run/dovecot/auth-master
|
||||
# log_path = /var/log/dovecot-lda-errors.log
|
||||
# info_log_path = /var/log/dovecot-lda.log
|
||||
#}
|
||||
#protocol lmtp {
|
||||
# mail_plugins = $mail_plugins sieve quota
|
||||
# log_path = /var/log/dovecot-lmtp-errors.log
|
||||
# info_log_path = /var/log/dovecot-lmtp.log
|
||||
#}
|
||||
#EOL
|
||||
#
|
||||
#hostname=$(hostname)
|
||||
#
|
||||
#echo 'Fix postmaster email in sieve'
|
||||
#postmaster_address=$(grep postmaster_address /etc/dovecot/dovecot.conf | sed 's/.*=//' | sed -e 's/^[ \t]*//' | sort -u)
|
||||
#
|
||||
#sed -i "s|postmaster@example.com|$postmaster_address|g" /etc/dovecot/dovecot.conf
|
||||
#sed -i "s|server.example.com|$hostname|g" /etc/dovecot/dovecot.conf
|
||||
#sed -i "s|postmaster@example.com|$postmaster_address|g" /etc/dovecot/dovecot.conf
|
||||
#
|
||||
##Sieve the global spam filter
|
||||
#sievec /etc/dovecot/sieve/default.sieve
|
||||
#
|
||||
##Sieve the global spam filter
|
||||
#sievec /etc/dovecot/sieve/default.sieve
|
||||
#
|
||||
#if [ "$OS" = "NAME=\"Ubuntu\"" ]; then
|
||||
# sed -i 's|^spamassassin.*|spamassassin unix - n n - - pipe flags=DROhu user=vmail:vmail argv=/usr/bin/spamc -f -e /usr/lib/dovecot/deliver -f ${sender} -d ${user}@${nexthop}|g' /etc/postfix/master.cf
|
||||
#
|
||||
#elif [ "$OS" = "NAME=\"CentOS Linux\"" ]; then
|
||||
# sed -i 's|^spamassassin.*|spamassassin unix - n n - - pipe flags=DROhu user=vmail:vmail argv=/usr/bin/spamc -f -e /usr/libexec/dovecot/deliver -f ${sender} -d ${user}@${nexthop}|g' /etc/postfix/master.cf
|
||||
#
|
||||
#elif [ "$OS" = "NAME=\"CloudLinux\"" ]; then
|
||||
# sed -i 's|^spamassassin.*|spamassassin unix - n n - - pipe flags=DROhu user=vmail:vmail argv=/usr/bin/spamc -f -e /usr/libexec/dovecot/deliver -f ${sender} -d ${user}@${nexthop}|g' /etc/postfix/master.cf
|
||||
#
|
||||
#fi
|
||||
|
||||
echo 'Restart and check services are up'
|
||||
systemctl restart dovecot && systemctl restart postfix && systemctl restart spamassassin && systemctl restart mailscanner
|
||||
|
||||
csf -e
|
||||
|
||||
echo "MailScanner successfully installed. MailWatch successfully installed."
|
||||
echo "Visit https://${IPADDRESS}:8090/mailwatch/mailscanner"
|
||||
echo "Username: admin"
|
||||
echo "Password: ${ADMINPASS}"
|
||||
#echo "If you wish mailscanner/spamassassin to send spam email to a spam folder please follow the tutorial on the Cyberpanel Website"
|
||||
echo "Firewalld is stopped. Either enable, install CSF or use an alternative!"
|
||||
echo "Optional cpan/cpanm modules are available for MailScanner. Cronjobs and further postfix tools are available for MailWatch"
|
||||
echo "See https://www.mailwatch.org and https://docs.mailwatch.org/install/optional-setup.html"
|
||||
exit
|
||||
57
CPScripts/mailscanneruninstaller.sh
Normal file
57
CPScripts/mailscanneruninstaller.sh
Normal file
@@ -0,0 +1,57 @@
|
||||
#!/bin/bash
|
||||
## Uninstall Mailscanner CyberPanel
|
||||
|
||||
### OS Detection
|
||||
Server_OS=""
|
||||
Server_OS_Version=""
|
||||
if grep -q -E "CentOS Linux 7|CentOS Linux 8" /etc/os-release ; then
|
||||
Server_OS="CentOS"
|
||||
elif grep -q "AlmaLinux-8" /etc/os-release ; then
|
||||
Server_OS="AlmaLinux"
|
||||
elif grep -q -E "CloudLinux 7|CloudLinux 8" /etc/os-release ; then
|
||||
Server_OS="CloudLinux"
|
||||
elif grep -q -E "Rocky Linux" /etc/os-release ; then
|
||||
Server_OS="RockyLinux"
|
||||
elif grep -q -E "Ubuntu 18.04|Ubuntu 20.04|Ubuntu 20.10|Ubuntu 22.04" /etc/os-release ; then
|
||||
Server_OS="Ubuntu"
|
||||
elif grep -q -E "openEuler 20.03|openEuler 22.03" /etc/os-release ; then
|
||||
Server_OS="openEuler"
|
||||
else
|
||||
echo -e "Unable to detect your system..."
|
||||
echo -e "\nCyberPanel is supported on x86_64 based Ubuntu 18.04, Ubuntu 20.04, Ubuntu 20.10, Ubuntu 22.04, CentOS 7, CentOS 8, AlmaLinux 8, RockyLinux 8, CloudLinux 7, CloudLinux 8, openEuler 20.03, openEuler 22.03...\n"
|
||||
exit
|
||||
fi
|
||||
|
||||
Server_OS_Version=$(grep VERSION_ID /etc/os-release | awk -F[=,] '{print $2}' | tr -d \" | head -c2 | tr -d . )
|
||||
|
||||
echo -e "System: $Server_OS $Server_OS_Version detected...\n"
|
||||
|
||||
if [[ $Server_OS = "CloudLinux" ]] || [[ "$Server_OS" = "AlmaLinux" ]] || [[ "$Server_OS" = "RockyLinux" ]] ; then
|
||||
Server_OS="CentOS"
|
||||
#CloudLinux gives version id like 7.8, 7.9, so cut it to show first number only
|
||||
#treat CloudLinux, Rocky and Alma as CentOS
|
||||
fi
|
||||
|
||||
systemctl stop mailscanner
|
||||
|
||||
|
||||
if [[ $Server_OS = "CentOS" ]] && [[ "$Server_OS_Version" = "7" ]] ; then
|
||||
|
||||
yum remove -y MailScanner
|
||||
|
||||
elif [[ $Server_OS = "CentOS" ]] && [[ "$Server_OS_Version" = "8" ]] ; then
|
||||
|
||||
yum remove -y MailScanner
|
||||
|
||||
elif [[ $Server_OS = "Ubuntu" ]]; then
|
||||
|
||||
apt purge -y mailscanner
|
||||
|
||||
fi
|
||||
|
||||
sed -i 's/\/^Received:\/ HOLD/\/^Received:\/ IGNORE/g' /etc/postfix/header_checks
|
||||
rm -rf /etc/MailScanner
|
||||
rm -rf /usr/share/MailScanner
|
||||
rm -rf /usr/local/CyberCP/public/mailwatch
|
||||
|
||||
systemctl restart postfix dovecot
|
||||
59
CPScripts/setup_php_sessions.sh
Normal file
59
CPScripts/setup_php_sessions.sh
Normal file
@@ -0,0 +1,59 @@
|
||||
#!/usr/bin/env bash
|
||||
## Author: Michael Ramsey
|
||||
## Objective Fix session issues on CyberPanel and standardized session paths.
|
||||
# Fixes #430
|
||||
# https://github.com/usmannasir/cyberpanel/issues/430
|
||||
|
||||
|
||||
# Create the session path directories and chmod it for security to 1733 like the existing one is.
|
||||
|
||||
for version in $(ls /usr/local/lsws|grep lsphp);
|
||||
do
|
||||
mkdir -p "/var/lib/lsphp/session/$version"
|
||||
chmod -R 1733 "/var/lib/lsphp/session/$version"
|
||||
done
|
||||
|
||||
|
||||
YUM_CMD=$(which yum 2> /dev/null)
|
||||
APT_GET_CMD=$(which apt-get 2> /dev/null)
|
||||
|
||||
if [[ -n $YUM_CMD ]]; then
|
||||
# Centos
|
||||
for version in $(ls /usr/local/lsws|grep lsphp); do echo ""; echo "PHP $version"; sed -i -e "s|^;session.save_path.*|session.save_path = '/var/lib/lsphp/session/${version}'|g" -e "s|^session.save_path.*|session.save_path = '/var/lib/lsphp/session/${version}'|g" /usr/local/lsws/${version}/etc/php.ini; /usr/local/lsws/${version}/bin/php -i |grep -Ei 'session.save_path' && echo "" ; done; service lsws restart; killall lsphp;
|
||||
|
||||
|
||||
|
||||
elif [[ -n $APT_GET_CMD ]]; then
|
||||
# Ubuntu
|
||||
for phpver in $(ls -1 /usr/local/lsws/ |grep lsphp | sed 's/lsphp//g') ; do echo ""; echo "LSPHP $phpver" ; lsphpver=$(echo $phpver | sed 's/^\(.\{1\}\)/\1./'); sed -i -e "s|^;session.save_path.*|session.save_path = '/var/lib/lsphp/session/lsphp${phpver}'|g" -e "s|^session.save_path.*|session.save_path = '/var/lib/lsphp/session/lsphp${phpver}'|g" /usr/local/lsws/lsphp${phpver}/etc/php/${lsphpver}/litespeed/php.ini ; /usr/local/lsws/lsphp${phpver}/bin/php -i |grep -Ei 'session.save_path' && echo "" ; done; service lsws restart; killall lsphp;
|
||||
|
||||
else
|
||||
echo "error can't install required packages. Unsupported OS"
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
|
||||
# Setup a cron to clear stuff older then session.gc_maxlifetime currently set in the php.ini for each version
|
||||
|
||||
# Create cron file if missing.
|
||||
if [[ ! -e /usr/local/CyberCP/bin/cleansessions ]]; then
|
||||
touch /usr/local/CyberCP/bin/cleansessions
|
||||
chmod +x /usr/local/CyberCP/bin/cleansessions
|
||||
cat >> /usr/local/CyberCP/bin/cleansessions <<"EOL"
|
||||
#!/bin/bash
|
||||
for version in $(ls /usr/local/lsws|grep lsphp); do echo ""; echo "PHP $version"; session_time=$(/usr/local/lsws/${version}/bin/php -i |grep -Ei 'session.gc_maxlifetime'| grep -Eo "[[:digit:]]+"|sort -u); find -O3 "/var/lib/lsphp/session/${version}" -ignore_readdir_race -depth -mindepth 1 -name 'sess_*' -type f -cmin 120 -delete; done
|
||||
EOL
|
||||
|
||||
fi
|
||||
|
||||
# Create crontab only if not exist
|
||||
echo "Installing PHP Session cleaning cron"
|
||||
command="/usr/local/CyberCP/bin/cleansessions >/dev/null 2>&1"
|
||||
job="09,39 * * * * $command"
|
||||
cat <(grep -i -v "$command" <(crontab -l)) <(echo "$job") | crontab -
|
||||
|
||||
echo "Checking cleansessions file"
|
||||
cat /usr/local/CyberCP/bin/cleansessions
|
||||
|
||||
# Set to a 4 hour default as the 24 min default is kinda low and logs people out too often and as a global default in shared scenario its hard for clients to know how to override this while working in their admin area backends etc.
|
||||
grep -Eilr '^memory_limit' --include=\*php.ini /usr/local/lsws/lsphp* | xargs sed -i -e "s/^session.gc_maxlifetime.*/session.gc_maxlifetime = '14400'/g"
|
||||
126
CPScripts/spamassassin_tojunk_installer.sh
Normal file
126
CPScripts/spamassassin_tojunk_installer.sh
Normal file
@@ -0,0 +1,126 @@
|
||||
#!/bin/bash
|
||||
# SpamAssassin Setup Spam to Junk folder. Should be called after the main SpamAssassin install part completes or mapped to an optional button to install. Personally think this should be a default part of the SpamAssassin installation.
|
||||
|
||||
echo 'backup configs';
|
||||
cp /etc/dovecot/dovecot.conf /etc/dovecot/dovecot.conf-bak_$(date '+%Y-%m-%d_%H_%M:%S');
|
||||
cp /etc/postfix/master.cf /etc/postfix/master.cf-bak_$(date '+%Y-%m-%d_%H_%M:%S');
|
||||
cp /etc/postfix/main.cf /etc/postfix/main.cf-bak_$(date '+%Y-%m-%d_%H_%M:%S');
|
||||
cp /etc/dovecot/dovecot-sql.conf.ext /etc/dovecot/dovecot-sql.conf.ext-bak_$(date '+%Y-%m-%d_%H_%M:%S')
|
||||
|
||||
|
||||
echo 'Setting up spamassassin and sieve to deliver spam to Junk folder by default'
|
||||
echo 'Fix protocols'
|
||||
sed -i 's/^protocols =.*/protocols = imap pop3 lmtp sieve/g' /etc/dovecot/dovecot.conf
|
||||
|
||||
|
||||
sed -i "s|^user_query.*|user_query = SELECT '5000' as uid, '5000' as gid, '/home/vmail/%d/%n' as home,mail FROM e_users WHERE email='%u';|g" /etc/dovecot/dovecot-sql.conf.ext
|
||||
|
||||
if [ "$OS" = "NAME=\"Ubuntu\"" ];then
|
||||
if [ "$UBUNTUVERSION" = "VERSION_ID=\"18.04\"" ];then
|
||||
apt-get install -y dovecot-managesieved dovecot-sieve dovecot-lmtpd net-tools pflogsumm
|
||||
elif [ "$UBUNTUVERSION" = "VERSION_ID=\"20.04\"" ];then
|
||||
apt-get install -y libmysqlclient-dev
|
||||
sed -e '/deb/ s/^#*/#/' -i /etc/apt/sources.list.d/dovecot.list
|
||||
apt install -y dovecot-lmtpd dovecot-managesieved dovecot-sieve net-tools pflogsumm
|
||||
fi
|
||||
|
||||
elif [ "$CENTOSVERSION" = "VERSION_ID=\"7\"" ];then
|
||||
|
||||
yum install -y nano net-tools dovecot-pigeonhole postfix-perl-scripts
|
||||
|
||||
elif [ "$CENTOSVERSION" = "VERSION_ID=\"8\"" ];then
|
||||
|
||||
rpm -Uvh http://mirror.ghettoforge.org/distributions/gf/el/8/gf/x86_64/gf-release-8-11.gf.el8.noarch.rpm
|
||||
dnf --enablerepo=gf-plus upgrade -y dovecot23*
|
||||
dnf --enablerepo=gf-plus install -y dovecot23-pigeonhole
|
||||
dnf install -y net-tools postfix-perl-scripts
|
||||
|
||||
elif [ "$CLNVERSION" = "ID=\"cloudlinux\"" ];then
|
||||
|
||||
yum install -y nano net-tools dovecot-pigeonhole postfix-perl-scripts
|
||||
fi
|
||||
|
||||
|
||||
# Create Sieve files
|
||||
mkdir -p /etc/dovecot/sieve/global
|
||||
touch /var/log/{dovecot-lda-errors.log,dovecot-lda.log}
|
||||
touch /var/log/{dovecot-sieve-errors.log,dovecot-sieve.log}
|
||||
touch /var/log/{dovecot-lmtp-errors.log,dovecot-lmtp.log}
|
||||
touch /etc/dovecot/sieve/default.sieve
|
||||
chown vmail: -R /etc/dovecot/sieve
|
||||
chown vmail:mail /var/log/dovecot-*
|
||||
|
||||
echo 'Create Sieve Default spam to Junk rule'
|
||||
cat >> /etc/dovecot/sieve/default.sieve <<EOL
|
||||
require "fileinto";
|
||||
if header :contains "X-Spam-Flag" "YES" {
|
||||
fileinto "INBOX.Junk E-mail";
|
||||
}
|
||||
EOL
|
||||
|
||||
|
||||
echo "Adding Sieve to /etc/dovecot/dovecot.conf"
|
||||
cat >> /etc/dovecot/dovecot.conf <<EOL
|
||||
service managesieve-login {
|
||||
inet_listener sieve {
|
||||
port = 4190
|
||||
}
|
||||
}
|
||||
service managesieve {
|
||||
}
|
||||
protocol sieve {
|
||||
managesieve_max_line_length = 65536
|
||||
managesieve_implementation_string = dovecot
|
||||
log_path = /var/log/dovecot-sieve-errors.log
|
||||
info_log_path = /var/log/dovecot-sieve.log
|
||||
}
|
||||
plugin {
|
||||
sieve = /home/vmail/%d/%n/dovecot.sieve
|
||||
sieve_global_path = /etc/dovecot/sieve/default.sieve
|
||||
sieve_dir = /home/vmail/%d/%n/sieve
|
||||
sieve_global_dir = /etc/dovecot/sieve/global/
|
||||
}
|
||||
protocol lda {
|
||||
mail_plugins = $mail_plugins sieve quota
|
||||
postmaster_address = postmaster@example.com
|
||||
hostname = server.example.com
|
||||
auth_socket_path = /var/run/dovecot/auth-master
|
||||
log_path = /var/log/dovecot-lda-errors.log
|
||||
info_log_path = /var/log/dovecot-lda.log
|
||||
}
|
||||
protocol lmtp {
|
||||
mail_plugins = $mail_plugins sieve quota
|
||||
log_path = /var/log/dovecot-lmtp-errors.log
|
||||
info_log_path = /var/log/dovecot-lmtp.log
|
||||
}
|
||||
EOL
|
||||
|
||||
hostname=$(hostname);
|
||||
|
||||
echo 'Fix postmaster email in sieve'
|
||||
postmaster_address=$(grep postmaster_address /etc/dovecot/dovecot.conf | sed 's/.*=//' |sed -e 's/^[ \t]*//'| sort -u)
|
||||
|
||||
sed -i "s|postmaster@example.com|$postmaster_address|g" /etc/dovecot/dovecot.conf
|
||||
sed -i "s|server.example.com|$hostname|g" /etc/dovecot/dovecot.conf
|
||||
sed -i "s|postmaster@example.com|$postmaster_address|g" /etc/dovecot/dovecot.conf
|
||||
|
||||
#Sieve the global spam filter
|
||||
sievec /etc/dovecot/sieve/default.sieve
|
||||
|
||||
#Sieve the global spam filter
|
||||
sievec /etc/dovecot/sieve/default.sieve
|
||||
|
||||
if [ "$OS" = "NAME=\"Ubuntu\"" ];then
|
||||
sed -i 's|^spamassassin.*|spamassassin unix - n n - - pipe flags=DROhu user=vmail:vmail argv=/usr/bin/spamc -f -e /usr/lib/dovecot/deliver -f ${sender} -d ${user}@${nexthop}|g' /etc/postfix/master.cf
|
||||
|
||||
elif [ "$OS" = "NAME=\"CentOS Linux\"" ];then
|
||||
sed -i 's|^spamassassin.*|spamassassin unix - n n - - pipe flags=DROhu user=vmail:vmail argv=/usr/bin/spamc -f -e /usr/libexec/dovecot/deliver -f ${sender} -d ${user}@${nexthop}|g' /etc/postfix/master.cf
|
||||
|
||||
elif [ "$OS" = "NAME=\"CloudLinux\"" ];then
|
||||
sed -i 's|^spamassassin.*|spamassassin unix - n n - - pipe flags=DROhu user=vmail:vmail argv=/usr/bin/spamc -f -e /usr/libexec/dovecot/deliver -f ${sender} -d ${user}@${nexthop}|g' /etc/postfix/master.cf
|
||||
|
||||
fi
|
||||
|
||||
|
||||
echo 'Restart and check services are up'
|
||||
systemctl restart dovecot && systemctl restart postfix && systemctl restart spamassassin
|
||||
175
CPScripts/watchdog.sh
Normal file
175
CPScripts/watchdog.sh
Normal file
@@ -0,0 +1,175 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Add any services to be watched by the watchdog to the SERVICE_LIST
|
||||
# Format of the service list: "Display Name" "Service Name" "semicolon delimited list of watchdog arguments"
|
||||
SERVICE_LIST=(
|
||||
"LiteSpeed" "lsws" "lsws;web;litespeed;openlitespeed"
|
||||
"MariaDB" "mariadb" "mariadb;database;mysql"
|
||||
"PowerDNS" "pdns" "powerdns;dns"
|
||||
"Dovecot" "dovecot" "dovecot;imap;pop3"
|
||||
"PostFix" "postfix" "postfix;smtp"
|
||||
"Pure-FTPd" "pure-ftpd" "pureftpd;pure-ftpd;ftp"
|
||||
)
|
||||
|
||||
SERVICE_COUNT=$((${#SERVICE_LIST[@]}/3))
|
||||
|
||||
show_help() {
|
||||
echo -e "\nrun command: \e[31mnohup bash /etc/cyberpanel/watchdog.sh SERVICE_NAME >/dev/null 2>&1 &\e[39m"
|
||||
echo -e "\nreplace \e[31mSERVICE_NAME\e[39m to the service name, acceptable word:"
|
||||
|
||||
for ((x=0; x<SERVICE_COUNT; x++)) ; do
|
||||
IFS=';' read -ra SERVICE_ARGS <<< "${SERVICE_LIST[(x*3)+2]}"
|
||||
echo -e " \e[31m${SERVICE_ARGS[0]}\e[39m"
|
||||
done
|
||||
|
||||
echo -e "\nWatchdog will check service status every 60 seconds and tries to restart if it is not running and also send an email to designated address"
|
||||
echo -e "\nto exit watchdog , run command \e[31mbash /etc/cyberpanel/watchdog.sh kill\e[39m"
|
||||
echo -e "\n\nplease also create \e[31m/etc/cyberpanel/watchdog.flag\e[39m file with following format:"
|
||||
echo -e "TO=address@email.com"
|
||||
echo -e "SENDER=sender name"
|
||||
echo -e "FROM=sender@email.com"
|
||||
echo -e "You may proceed without flag file , but that will make email sending failed."
|
||||
}
|
||||
|
||||
watchdog_check() {
|
||||
for ((x=0; x<SERVICE_COUNT; x++)) ; do
|
||||
DISPLAY_NAME=${SERVICE_LIST[x*3]}
|
||||
SERVICE_NAME=${SERVICE_LIST[(x*3)+1]}
|
||||
IFS=';' read -ra SERVICE_ARGS <<< "${SERVICE_LIST[(x*3)+2]}"
|
||||
SERVICE_ARG=${SERVICE_ARGS[0]}
|
||||
|
||||
echo -e "\nChecking ${DISPLAY_NAME}..."
|
||||
pid=$(ps aux | grep "watchdog ${SERVICE_ARG}" | grep -v grep | awk '{print $2}')
|
||||
if [[ "$pid" == "" ]] ; then
|
||||
echo -e "\nWatchDog for ${DISPLAY_NAME} is gone , restarting..."
|
||||
nohup watchdog ${SERVICE_ARG} > /dev/null 2>&1 &
|
||||
echo -e "\nWatchDog for ${DISPLAY_NAME} has been started..."
|
||||
else
|
||||
echo -e "\nWatchDog for ${DISPLAY_NAME} is running...\n"
|
||||
echo $(ps aux | grep "watchdog ${SERVICE_ARG}" | grep -v grep)
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
check_service() {
|
||||
systemctl status $NAME 2>&1>/dev/null
|
||||
if [[ $? == "0" ]] ; then
|
||||
if [[ $NAME == "mariadb" ]] ; then
|
||||
pid=$(ps aux | grep "/usr/sbin/mysqld" | grep -v grep | awk '{print $2}')
|
||||
if [[ $pid != "" ]] ; then
|
||||
echo "-1000" > /proc/$pid/oom_score_adj
|
||||
fi
|
||||
pid=$(ps aux | grep "/usr/sbin/mysqld" | grep -v grep | awk '{print $2}')
|
||||
if [[ $pid != "" ]] ; then
|
||||
echo "-1000" > /proc/$pid/oom_score_adj
|
||||
fi
|
||||
fi
|
||||
echo "$NAME service is running..."
|
||||
else
|
||||
echo "$NAME is down , try to restart it..."
|
||||
if [[ $NAME == "lsws" ]] ; then
|
||||
pkill lsphp
|
||||
fi
|
||||
if [[ $NAME == "mariadb" ]] ; then
|
||||
pid=$(ps aux | grep "/usr/sbin/mysqld" | grep -v grep | awk '{print $2}')
|
||||
if [[ $pid != "" ]] ; then
|
||||
echo "-1000" > /proc/$pid/oom_score_adj
|
||||
fi
|
||||
pid=$(ps aux | grep "/usr/sbin/mysqld" | grep -v grep | awk '{print $2}')
|
||||
if [[ $pid != "" ]] ; then
|
||||
echo "-1000" > /proc/$pid/oom_score_adj
|
||||
fi
|
||||
fi
|
||||
systemctl stop $NAME
|
||||
systemctl start $NAME
|
||||
if [ -f /etc/cyberpanel/watchdog.flag ] ; then
|
||||
flag="/etc/cyberpanel/watchdog.flag"
|
||||
LINE3=$(awk 'NR==3' $flag)
|
||||
LINE2=$(awk 'NR==2' $flag)
|
||||
LINE1=$(awk 'NR==1' $flag)
|
||||
|
||||
FROM=${LINE3#*=}
|
||||
SENDER=${LINE2#*=}
|
||||
TO=${LINE1#*=}
|
||||
sendmail -F $SENDER -f $FROM -i $TO <<MAIL_END
|
||||
Subject: $NAME is down...
|
||||
To: $TO
|
||||
$NAME is down , watchdog attempted to restarting it...
|
||||
|
||||
MAIL_END
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
if [[ $1 == "help" ]] || [[ $1 == "-h" ]] || [[ $1 == "--help" ]] || [[ $1 == "" ]] ; then
|
||||
show_help
|
||||
exit
|
||||
elif [[ $1 == "check" ]] || [[ $1 == "status" ]] ; then
|
||||
watchdog_check
|
||||
exit
|
||||
elif [[ $1 == "kill" ]] ; then
|
||||
for ((x=0; x<SERVICE_COUNT; x++)); do
|
||||
IFS=';' read -ra SERVICE_ARGS <<< "${SERVICE_LIST[(x*3)+2]}"
|
||||
SERVICE_ARG=${SERVICE_ARGS[0]}
|
||||
|
||||
pid=$(ps aux | grep "watchdog ${SERVICE_ARG}" | grep -v grep | awk '{print $2}')
|
||||
if [[ "$pid" != "" ]] ; then
|
||||
kill -15 $pid
|
||||
fi
|
||||
done
|
||||
echo "watchdog has been killed..."
|
||||
exit
|
||||
fi
|
||||
|
||||
# Check if $1 matches any service argument names
|
||||
SERVICE_FOUND=0
|
||||
for ((x=0; x<SERVICE_COUNT; x++)) ; do
|
||||
DISPLAY_NAME=${SERVICE_LIST[x*3]}
|
||||
SERVICE_NAME=${SERVICE_LIST[(x*3)+1]}
|
||||
IFS=';' read -ra SERVICE_ARGS <<< "${SERVICE_LIST[(x*3)+2]}"
|
||||
SERVICE_ARG=${SERVICE_ARGS[0]}
|
||||
|
||||
for arg in "${SERVICE_ARGS[@]}" ; do
|
||||
if [[ $1 == "$arg" ]] ; then
|
||||
SERVICE_FOUND=1
|
||||
NAME=$SERVICE_NAME
|
||||
echo "Watchdog on ${DISPLAY_NAME} is starting up ..."
|
||||
fi
|
||||
done
|
||||
done
|
||||
|
||||
if [[ $SERVICE_FOUND == 0 ]] ; then
|
||||
echo -e "unknown service name \e[31m$1\e[39m..."
|
||||
|
||||
show_help
|
||||
exit
|
||||
fi
|
||||
|
||||
|
||||
|
||||
while [ true = true ]
|
||||
do
|
||||
if [[ $NAME == "pdns" ]] ; then
|
||||
if [ -f /home/cyberpanel/powerdns ] ; then
|
||||
check_service
|
||||
fi
|
||||
elif [[ $NAME == "postfix" ]] ; then
|
||||
if [ -f /home/cyberpanel/postfix ] ; then
|
||||
check_service
|
||||
fi
|
||||
elif [[ $name == "pure-ftpd" ]] || [[ $name == "pure-ftpd-mysql" ]] ; then
|
||||
if [ -f /home/cyberpanel/pureftpd ] ; then
|
||||
if [ -f /etc/lsb-release ] ; then
|
||||
NAME="pure-ftpd-mysql"
|
||||
else
|
||||
NAME="pure-ftpd"
|
||||
fi
|
||||
|
||||
check_service
|
||||
fi
|
||||
else
|
||||
check_service
|
||||
fi
|
||||
sleep 60
|
||||
done
|
||||
Reference in New Issue
Block a user