mirror of
https://github.com/usmannasir/cyberpanel.git
synced 2025-11-09 06:46:10 +01:00
Merge branch 'stable' into v2.0.3-dev
This commit is contained in:
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}"
|
||||||
@@ -1,9 +1,20 @@
|
|||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# Apache Regex portion original credits to: https://leancrew.com/all-this/2013/07/parsing-my-apache-logs/
|
# 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"
|
__author__ = "Michael Ramsey"
|
||||||
__version__ = "0.1.0"
|
__version__ = "0.1.2"
|
||||||
__license__ = "GPL-3.0"
|
__license__ = "GPL-3.0"
|
||||||
|
|
||||||
import os
|
import os
|
||||||
@@ -14,8 +25,12 @@ from collections import Counter
|
|||||||
from datetime import date, timedelta
|
from datetime import date, timedelta
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from os.path import join, isfile
|
from os.path import join, isfile
|
||||||
|
import getpass
|
||||||
|
import glob
|
||||||
|
|
||||||
|
|
||||||
|
# import pathlib
|
||||||
|
|
||||||
# print('version is', sys.version)
|
# print('version is', sys.version)
|
||||||
|
|
||||||
|
|
||||||
@@ -24,10 +39,11 @@ def main():
|
|||||||
# filename = sys.argv[2]
|
# filename = sys.argv[2]
|
||||||
# filenametest = "/home/example.com.access_log"
|
# filenametest = "/home/example.com.access_log"
|
||||||
# username = 'server'
|
# username = 'server'
|
||||||
username = str(sys.argv[1])
|
username = getpass.getuser()
|
||||||
|
# print(username)
|
||||||
# Define the day of interest in the Apache common log format. Default if not specified
|
# Define the day of interest in the Apache common log format. Default if not specified
|
||||||
try:
|
try:
|
||||||
daysago = int(sys.argv[2])
|
daysago = int(sys.argv[1])
|
||||||
# daysago = 0
|
# daysago = 0
|
||||||
except:
|
except:
|
||||||
daysago = 0
|
daysago = 0
|
||||||
@@ -46,7 +62,7 @@ def main():
|
|||||||
# Current Dcpumon file
|
# Current Dcpumon file
|
||||||
dcpumon_current_log = "/var/log/dcpumon/" + datetime_dcpumon # /var/log/dcpumon/2019/Feb/15
|
dcpumon_current_log = "/var/log/dcpumon/" + datetime_dcpumon # /var/log/dcpumon/2019/Feb/15
|
||||||
acesslog_sed = "-ssl_log"
|
acesslog_sed = "-ssl_log"
|
||||||
if username == 'server':
|
if username == 'root':
|
||||||
domlogs_path = '/usr/local/apache/domlogs/'
|
domlogs_path = '/usr/local/apache/domlogs/'
|
||||||
else:
|
else:
|
||||||
user_homedir = "/home/" + username
|
user_homedir = "/home/" + username
|
||||||
@@ -56,9 +72,9 @@ def main():
|
|||||||
elif os.path.isfile('/usr/bin/cyberpanel') | os.path.isfile(os.getcwd() + '/cyberpanel'):
|
elif os.path.isfile('/usr/bin/cyberpanel') | os.path.isfile(os.getcwd() + '/cyberpanel'):
|
||||||
controlpanel = 'CyberPanel'
|
controlpanel = 'CyberPanel'
|
||||||
acesslog_sed = ".access_log"
|
acesslog_sed = ".access_log"
|
||||||
if username == 'server':
|
if username == 'root':
|
||||||
# Needs updated to glob all /home/*/logs/
|
# Needs updated to glob all /home/*/logs/
|
||||||
domlogs_path = '/home/username/Desktop/domlogs'
|
domlogs_path2 = glob.glob('/home/*/logs/')
|
||||||
else:
|
else:
|
||||||
# Get users homedir path
|
# Get users homedir path
|
||||||
user_homedir = os.path.expanduser("~" + username)
|
user_homedir = os.path.expanduser("~" + username)
|
||||||
@@ -70,16 +86,24 @@ def main():
|
|||||||
# Define Output file
|
# Define Output file
|
||||||
stats_output = open(os.getcwd() + '/stats.txt', "w")
|
stats_output = open(os.getcwd() + '/stats.txt', "w")
|
||||||
|
|
||||||
# Define log path directory
|
if username == 'root' and controlpanel == 'CyberPanel':
|
||||||
path = domlogs_path
|
# 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)
|
||||||
|
|
||||||
# path = "/home/username/Desktop/domlogs"
|
# Get list of files only from this directory
|
||||||
|
logs = glob.glob("/home/*/logs/*.access_log")
|
||||||
|
|
||||||
# Get list of dir contents
|
else:
|
||||||
logs_path_contents = os.listdir(path)
|
# Define log path directory
|
||||||
|
path = domlogs_path
|
||||||
# Get list of files only from this directory
|
# Get list of dir contents
|
||||||
logs = filter(lambda f: isfile(join(path, f)), logs_path_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.
|
# Regex for the Apache common log format.
|
||||||
parts = [ # host %h :ip/hostname of the client 172.68.142.138
|
parts = [ # host %h :ip/hostname of the client 172.68.142.138
|
||||||
@@ -257,7 +281,12 @@ def main():
|
|||||||
if re.match("(.*)(/admin[a-zA-Z0-9_]*$)(.*)", line):
|
if re.match("(.*)(/admin[a-zA-Z0-9_]*$)(.*)", line):
|
||||||
prestashop_hit_count = prestashop_hit_count + 1
|
prestashop_hit_count = prestashop_hit_count + 1
|
||||||
m = pattern.match(line)
|
m = pattern.match(line)
|
||||||
hit = m.groupdict()
|
if m is not None:
|
||||||
|
hit = m.groupdict()
|
||||||
|
else:
|
||||||
|
# print("re.search() returned None")
|
||||||
|
continue
|
||||||
|
# hit = m.groupdict()
|
||||||
if ispage(hit):
|
if ispage(hit):
|
||||||
pages.append(pythonized(hit))
|
pages.append(pythonized(hit))
|
||||||
else:
|
else:
|
||||||
@@ -330,7 +359,7 @@ def main():
|
|||||||
|
|
||||||
print('Accesslog path used: ' + path)
|
print('Accesslog path used: ' + path)
|
||||||
# print(dcpumon_current_log)
|
# print(dcpumon_current_log)
|
||||||
|
print('============================================')
|
||||||
d = post_request_dict
|
d = post_request_dict
|
||||||
# Using dictionary comprehension to find list
|
# Using dictionary comprehension to find list
|
||||||
# keys having value in 0 will be removed from results
|
# keys having value in 0 will be removed from results
|
||||||
@@ -338,7 +367,7 @@ def main():
|
|||||||
|
|
||||||
# delete the key
|
# delete the key
|
||||||
for key in delete: del d[key]
|
for key in delete: del d[key]
|
||||||
|
print(' ')
|
||||||
print('''Top POST requests for %s''' % the_day.strftime('%b %d, %Y'))
|
print('''Top POST requests for %s''' % the_day.strftime('%b %d, %Y'))
|
||||||
print(' ')
|
print(' ')
|
||||||
# sort by dictionary by the values and print top 10 {key, value} pairs
|
# sort by dictionary by the values and print top 10 {key, value} pairs
|
||||||
|
|||||||
233
CPScripts/fixperms.sh
Normal file
233
CPScripts/fixperms.sh
Normal file
@@ -0,0 +1,233 @@
|
|||||||
|
#! /bin/bash
|
||||||
|
# Cyberpanel Fix Perms
|
||||||
|
# https://gitlab.com/cyberpaneltoolsnscripts/cyberpanel-fixperms
|
||||||
|
#
|
||||||
|
# Forked from https://github.com/PeachFlame/cPanel-fixperms
|
||||||
|
#
|
||||||
|
|
||||||
|
# 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 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
|
||||||
|
|
||||||
|
|
||||||
|
# fix mailperms
|
||||||
|
fixmailperms () {
|
||||||
|
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 () {
|
||||||
|
|
||||||
|
#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 the account's homedir
|
||||||
|
HOMEDIR=$(egrep "^${account}:" /etc/passwd | cut -d: -f6)
|
||||||
|
|
||||||
|
tput bold
|
||||||
|
tput setaf 4
|
||||||
|
echo "Fixing perms for $account:"
|
||||||
|
tput setaf 3
|
||||||
|
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 | xargs -d$'\n' -r chmod $verbose 644
|
||||||
|
find "$HOMEDIR"/public_html -name '*.cgi' -o -name '*.pl' | xargs -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":"$account" "$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 | 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
|
||||||
|
}
|
||||||
|
|
||||||
|
#Parses all users through Cyberpanel's users file
|
||||||
|
#all () {
|
||||||
|
# for user in $(cut -d: -f1 /etc/domainusers)
|
||||||
|
# do
|
||||||
|
# fixperms "$user"
|
||||||
|
# done
|
||||||
|
#}
|
||||||
|
|
||||||
|
|
||||||
|
all () {
|
||||||
|
|
||||||
|
if [[ $OS = 'CentOS Linux' ]] ; then
|
||||||
|
for user in $(getent passwd | awk -F: '5001<$3 && $3<6000 {print $1}' |grep -v spamd)
|
||||||
|
do
|
||||||
|
fixperms "$user"
|
||||||
|
done
|
||||||
|
fixmailperms
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ $OS = 'Ubuntu' ]] ; then
|
||||||
|
for user in $(getent passwd | awk -F: '1001<$3 && $3<2000 {print $1}')
|
||||||
|
do
|
||||||
|
fixperms "$user"
|
||||||
|
done
|
||||||
|
fixmailperms
|
||||||
|
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
|
||||||
@@ -219,6 +219,7 @@ sed -i 's/^SpamAssassin User State Dir =.*/& \/var\/spool\/MailScanner\/spamassa
|
|||||||
sed -i 's/^Always Looked Up Last =.*/Always Looked Up Last = \&MailWatchLogging/' /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/^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/^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
|
mkdir /usr/local/CyberCP/public/mailwatch
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user