Cleanup unused scripts

This commit is contained in:
Matthew McKinnon 2024-06-21 21:50:10 +10:00
parent 735d661aa2
commit bcb0f6990c
11 changed files with 11 additions and 429 deletions

View File

@ -6,9 +6,9 @@
# This script will email a logwatch report
MAILTO="support@comprofix.com"
MAILFROM="support@comprofix.com"
THISSERVER=$(hostname -f)
SMTP="mail.comprofix.com"
MAILFROM="$THISSERVER@comprofix.com"
SMTP="comprofix-com.mail.protection.outlook.com"
#Check if removed-but-not-purged
test -x /usr/share/logwatch/scripts/logwatch.pl || exit 0
@ -17,3 +17,5 @@ test -x /usr/share/logwatch/scripts/logwatch.pl || exit 0
/usr/sbin/logwatch > /tmp/logwatch
sendemail -o tls=no -s $SMTP -t $MAILTO -f "$THISSERVER <$MAILFROM>" -u "[$THISSERVER] Logwatch" -m "$(cat /tmp/logwatch)" -q
rm /tmp/logwatch

View File

@ -16,9 +16,9 @@
#
MAILTO="support@comprofix.com"
MAILFROM="support@comprofix.com"
THISSERVER=$(hostname -f)
SMTP="webserver.home.comprofix.com"
MAILFROM="$THISSERVER@comprofix.com"
SMTP="comprofix-com.mail.protection.outlook.com"
AUTOUPDATE="no"
LOGFILE="/var/log/server_maint.log"

View File

@ -1,141 +0,0 @@
#!/bin/bash
# Script Name: check_updates_rpm
# Author Name: Matt McKinnon
# Date: 7th June 2016
# Description: For use on rpm based distros ie CentOS, Red Hat, Fedora
# This script will:
# Clean up the local rpm repository of retrieved packages (yum clean)
# Resync the package index (yum makecache)
# If called with AUTOUPDATE set to yes then SECURITY updates will be downloaded and applied. (The package yum-plugin-security is required Install using
# yum install yum-plugin-security)
#
# Make user configuration changes in this section
#
MAILTO="support@comprofix.com"
AUTOUPDATE="no"
LOGFILE="/var/log/server_maint.log"
THISSERVER=$(hostname -f)
#
# End of user configuration section
#
DASHES="---------------------------------------------------------------------------------"
DASHES2="================================================================================="
# Check if the script is being run as root exit if it is not.
if [ $(id -u) -ne 0 ]
then
echo "ur not root bro"
exit 1
fi
startlogging() {
echo $DASHES2 >> $LOGFILE
echo "$0 started running at `date`" >> $LOGFILE
echo $DASHES2 >> $LOGFILE
}
stoplogging() {
echo "`date` [MESSAGE] $0 finished runnning" >> $LOGFILE
echo $DASHES >> $LOGFILE
}
check_return() {
if [ "$?" -ne "0" ]
then
echo "$(date) [ERROR] $1 failed to run" >> $LOGFILE
send_error_email $1
stoplogging
exit 1
fi
echo "$(date) [SUCCESS] $1 ran without error" >> $LOGFILE
}
send_error_email() {
echo "Hello,
Whilst running the update script ($0) on $THISSERVER there was a problem.
[ERROR] "$1" failed to run
The server has the following network interfaces configured ${SERVERADDS[@]}.
Please log in via ssh (e.g. ssh root@${IPADDR[0]}) and check the log file:
vim $LOGFILE
Regards." | /bin/mail -s "[$THISSERVER] There was an error whilst running $0" $MAILTO
}
# IP Address stuff
declare -a IPADDR
declare -a NICINTERFACE
declare -a SERVERADDS
index=0
for i in $( ifconfig | grep 'inet addr' | awk '{print $2}'| sed 's#addr:##g' );
do
IPADDR[$index]=$i
let "index += 1"
done
index=0
for i in $( ifconfig | grep 'eth' | awk '{print $1}' );
do
SERVERADDS[$index]="$i ${IPADDR[$index]}"
let "index += 1"
done
# End IP Address stuff
startlogging
yum clean all > /dev/null
check_return "yum clean all"
yum makecache > /dev/null
check_return "yum makecache"
if [[ "$AUTOUPDATE" == "yes" ]]
then
yum -y update --security > /dev/null
check_return "yum -y update --security"
else
PACKAGES_TO_BE_UPGRADED=`yum list updates -q`
check_return "yum list updates -q"
fi
if [[ -z $PACKAGES_TO_BE_UPGRADED ]]
then
echo "$(date) [MESSAGE] No packages need updating." >> $LOGFILE
else
echo "
Hello,
Packages requiring updates onto $THISSERVER.
$PACKAGES_TO_BE_UPGRADED
The server has the following network interfaces configured ${SERVERADDS[@]}.
To update the server log in via ssh (e.g. ssh root@${IPADDR[0]}) and run the following command:
yum upgrade
See the logfile for more info: vim $LOGFILE
Regards. " | /bin/mail -s "[$THISSERVER] server may need some updates applied" $MAILTO
echo "`date` [MESSAGE] Packages need updating email sent to $MAILTO" >> $LOGFILE
fi
stoplogging
exit 0

View File

@ -16,10 +16,12 @@
MAILTO="support@comprofix.com"
MAILFROM="support@comprofix.com"
SQLSERVER="mysql.comprofix.xyz"
THISSERVER=$(hostname -f)
MAILFROM="$THISSERVER@comprofix.com"
SMTP="comprofix-com.mail.protection.outlook.com"
SQLSERVER="mysql.comprofix.xyz"
BAKDATE=$(date +%Y%m%d)
SUBJECT="$SQLSERVER Database Backup Completed - $BAKDATE"
DBUSER='dbbackup'

View File

@ -6,8 +6,8 @@
# This script will email when diskspace is high.
MAILTO="support@comprofix.com"
MAILFROM="support@comprofix.com"
THISSERVER=$(hostname -f)
MAILFROM="$THISSERVER@comprofix.com"
SMTP="comprofix-com.mail.protection.outlook.com"
LOGFILE="/var/log/diskalert.log"

View File

@ -1,21 +0,0 @@
#!/bin/bash
# Script Name: mailQWatch
# Author: Matt McKinnon
# Date: 7th June 2016
# Description:
# This script will email a report mailq on postfix is high.
QUEUELIMIT=75
SUBJECT="Mail Queue on $HOST is currently $QUEUECOUNT"
MAILTO="support@comprofix.com"
HOST=$(/bin/hostname)
POSTQUEUE=$(which postqueue)
QUEUELENGTH=$($POSTQUEUE -p | tail -n1 | awk '{print $5}')
QUEUECOUNT=$(echo $QUEUELENGTH | grep "[0-9]")
if [ "$QUEUECOUNT" == "" ]; then
exit;
elif [ "$QUEUECOUNT" -gt "$QUEUELIMIT" ]; then
$POSTQUEUE -p | /bin/mail -s "$SUBJECT" "$MAILTO"
fi

View File

@ -1,51 +0,0 @@
#!/bin/bash
MAILTO="support@comprofix.com"
MAILFROM="support@comprofix.com"
THISSERVER=$(hostname -f)
SMTP="mail.comprofix.com"
SUBJECT="Backup Log `date +%d-%m-%Y`"
LOGFOLDER=/var/log/nasbackup
LOGFILE=$LOGFOLDER/backuplog-`date +%d-%m-%Y.log`
THISSERVER=`hostname --fqdn`
N_DAYS=7
startlogging() {
echo $DASHES2 >> $LOGFILE
echo "$0 started running at $(date)" >> $LOGFILE
echo $DASHES2 >> $LOGFILE
}
stoplogging() {
echo "$(date) [MESSAGE] $0 finished runnning" >> $LOGFILE
echo $DASHES >> $LOGFILE
}
DASHES="---------------------------------------------------------------------------------"
DASHES2="================================================================================="
startlogging
mkdir -p $LOGFOLDER
rsync -urtlOv --partial --delete --exclude 'kvm' /data/ /media/nas/ >> $LOGFILE
FILES=$(find $LOGFOLDER -type f -mtime +$N_DAYS -name '*.log' | wc -l)
if [ $FILES -eq 0 ];
then
echo "$(date) [MESSAGE] No Old Log Files Found" >> $LOGFILE
else
echo "$(date) [MESSAGE] Older than $N_DAYS days will be deleted" >> $LOGFILE
find $LOGFOLDER/* -mtime +$N_DAYS -exec rm {} \;
fi
echo "$(date) [MESSAGE] Backup completed $LOGFILE has been emailed." >> $LOGFILE
stoplogging
sendemail -o tls=no -s $SMTP -t $MAILTO -f "$THISSERVER <$MAILFROM>" -u "$SUBJECT" -a "$LOGFILE" -m "$SUBJECT" -q

View File

@ -1,29 +0,0 @@
#Map Network Drive
New-PSDrive -Persist -Name "Z" -PSProvider "FileSystem" -Root "\\NAS\backup" -Confirm:$false
# set variables
$date = get-Date -UFormat "%d-%m-%Y"
$SourceFolder = "D:\"
$DestinationFolder = "Z:\DATA"
$Logfile = "backup-$date.log"
$EmailParams = @{
From = "support@comprofix.com"
To = "support@comprofix.com"
Subject = "Backup Log $date"
SMTPServer = "mail.comprofix.local"
Port = "25"
}
# copy
ROBOCOPY.EXE $SourceFolder $DestinationFolder /E /J /PURGE /MIR /X /FP /NS /NDL /ETA /TEE /np /LOG:$LogFile /XD "$RECYCLE.BIN" "System Volume Information" ".session"
# build email body
$EmailBody = (Get-Content $Logfile | % { "$_<br/>" -replace "`t","&#09;" -replace " ","&nbsp;" })
#send email
Send-MailMessage @EmailParams -Bodyashtml "<div style='Font-Family:Lucida Console,Courier New,Monospace'>$EmailBody</div>"
#Disconnect Network Drive
Get-PSDrive Z | Remove-PSDrive -Confirm:$false

View File

@ -1,93 +0,0 @@
#!/bin/bash
# Script Name:plesk-backup
# Author: Matt McKinnon
# Date: 04 May 2018
# Description:
# This script will backup your plesk hosting files.
# Send an email report of plesk hosting files that have been backed up.
# Rotate backups for 7 days
#
MAIL="support@comprofix.com"
MAILTO="support@comprofix.com"
MAILFROM="support@comprofix.com"
THISSERVER=$(hostname -f)
SMTP="mail.comprofix.com"
SUBJECT="$(hostname -f) Hosting Files Backup Completed $BAKDATE"
BAKDATE=$(date +%Y%m%d)
BACKUPDIR='/BACKUP'
VHOSTS='/var/www/vhosts/'
LOGFOLDER=/var/log/
LOGFILE=$LOGFOLDER/backuplog-`date +%d-%m-%Y.log`
rotate_backups() {
find $BACKUPDIR -type f -mtime +1 -exec rm -fr {} \;
}
startlogging() {
echo $DASHES2 >> $LOGFILE
echo "$0 started running at $(date)" >> $LOGFILE
echo $DASHES >> $LOGFILE
}
stoplogging() {
echo $DASHES >> $LOGFILE
echo "$0 finished running at $(date)" >> $LOGFILE >> $LOGFILE
echo $DASHES2 >> $LOGFILE
}
DASHES="---------------------------------------------------------------------------------"
DASHES2="================================================================================="
startlogging
rotate_backups
#Backup website files
# Get domain ID
IDS=$(MYSQL_PWD=$(cat /etc/psa/.psa.shadow) mysql -sN -uadmin -e 'select id from psa.domains, psa.hosting where id = dom_id order by id;')
#Use ID to get domain name and www_root folders and create archive using domain name.
for ID in $IDS; do
DOMAIN_NAME=$(MYSQL_PWD=$(cat /etc/psa/.psa.shadow) mysql -sN -uadmin -e 'select name from psa.domains,psa.hosting where id = '$ID' AND dom_id ='$ID' order by id;')
WWW_ROOT=$(MYSQL_PWD=$(cat /etc/psa/.psa.shadow) mysql -sN -uadmin -e 'select www_root from psa.domains,psa.hosting where id = '$ID' AND dom_id ='$ID' order by id;')
echo "$(date) [MESSAGE] Creating archive of $DOMAIN_NAME" >> $LOGFILE
if [ $DOMAIN_NAME = 'cloud.comprofix.com' ]; then
zip -rq $BACKUPDIR/$DOMAIN_NAME.$BAKDATE.zip $WWW_ROOT -x '*data*'
else
zip -rq $BACKUPDIR/$DOMAIN_NAME.$BAKDATE.zip $WWW_ROOT
fi
done
#Backup databases
databases=$(MYSQL_PWD=$(cat /etc/psa/.psa.shadow) mysql -sN -uadmin -e "SHOW DATABASES;" | tr -d "| " | grep -v Database)
for db in $databases; do
if [[ "$db" != "information_schema" ]] && [[ "$db" != "performance_schema" ]] && [[ "$db" != "mysql" ]] && [[ "$db" != _* ]] && [[ "$db" != "apsc" ]] && [[ "$db" != "horde" ]] && [[ "$db" != phpmyadmin_* ]] && [[ "$db" != "psa" ]] && [[ "$db" != "roundcubemail" ]] ; then
echo "$(date) [MESSAGE] Dumping $db to sql file" >> $LOGFILE
mysqldump --force --opt --user=$DBUSER --password=$DBPASS --databases $db > $BACKUPDIR/$db.$BAKDATE.sql
fi
done
#Backup files to offsite location
echo "$(date) [MESSAGE] Copying backup files to offsite location" >> $LOGFILE
#scp -rq -P 2222 $BACKUPDIR/* moe@home.comprofix.com:/data/backup/website
rsync -avz -e "ssh -p 2222 -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" /BACKUP/ administrator@home.comprofix.com:/data/backup/websites/ >> $LOGFILE
echo "$(date) [MESSAGE] Sending email of backup report" >> $LOGFILE
stoplogging
#sendemail -o tls=no -s $SMTP -t $MAILTO -f "$THISSERVER <$MAILFROM>" -u "$SUBJECT" -m "$(cat /tmp/dbbackup.msg)" -q
#Use below if using POSTFIX
cat $LOGFILE | mail -s "$SUBJECT" "$MAIL"

View File

@ -1,59 +0,0 @@
#!/bin/bash
#
# Shorewall blacklist file
# blacklist file
#
BLACKLIST="/etc/shorewall/blacklist"
CUSTOM="/etc/shorewall/custom-blacklist"
#
# get URL
#
URL[0]="http://feeds.dshield.org/block.txt"
URL[1]="http://www.spamhaus.org/drop/drop.lasso"
#Counrtry BlockLists
COUNTRY=(cn tw tr mx il id ua za)
IPDENY="http://www.ipdeny.com/ipblocks/data/countries"
#
# Don't Edit After this line
#
# Temporary dump staging folder
TMP=$(mktemp -d -t tmp.XXXXXXXXXX)
#
# @method to delete Temporary folder
#
function finish {
rm -rf "$TMP"
}
trap finish EXIT
echo "Downloading new blacklists...."
#Blank out existing blacklists
cat /dev/null > "$TMP/blacklist"
cat /dev/null > $BLACKLIST
#Add custom entries
if [[ -s $CUSTOM ]]; then
cat $CUSTOM >> "$TMP/blacklist"
fi
## top 20 attacking class C (/24)
wget -q -O - ${URL[0]} | sed '1,/Start/d' | sed '/#/d' | awk '{print $1,$3}' | sed 's/ /\//' >> "$TMP/blacklist"
## Spamhaus DROP List
wget -q -O - ${URL[1]} | sed '1,/Expires/d' | awk '{print $1}' >> "$TMP/blacklist"
## Country Blocklists
for BLOCK in ${COUNTRY[*]}; do
wget -q -O - $IPDENY/$BLOCK.zone | awk '{print $1}' >> "$TMP/blacklist"
done
#Remove duplicate entries
sort "$TMP/blacklist" | uniq -c | awk '{print $2}' > $BLACKLIST
shorewall refresh

View File

@ -1,28 +0,0 @@
#!/bin/bash
# Script Name: ssl-install
# Author: Matt McKinnon
# Date: 28th May 2018
# Description:
#
# Script used to copy Let's Encrypt Generated Certificates from generating server to remote host .
GITLAB="gitlab.comprofix.com"
PROXMOX="pve1.comprofix.xyz"
TRUENAS="truenas.comprofix.xyz"
scp /mnt/nfs/docker/traefik/config/certificates/comprofix.xyz.cer root@$PROXMOX:/etc/pve/nodes/pve1/pveproxy-ssl.pem
scp /mnt/nfs/docker/traefik/config/certificates/comprofix.xyz.key root@$PROXMOX:/etc/pve/nodes/pve1/pveproxy-ssl.key
ssh -t root@$PROXMOX "systemctl restart pveproxy"
scp /mnt/nfs/docker/traefik/config/certificates/comprofix.xyz.cer root@$TRUENAS:/etc/certificates/truenas_default.crt
scp /mnt/nfs/docker/traefik/config/certificates/comprofix.xyz.key root@$TRUENAS:/etc/certificates/truenas_default.key
ssh -t root@$TRUENAS "systemctl restart nginx"
scp /mnt/nfs/docker/traefik/config/certificates/comprofix.com.cer root@$GITLAB:/etc/gitlab/ssl/gitlab.comprofix.com.crt
scp /mnt/nfs/docker/traefik/config/certificates/comprofix.com.key root@$GITLAB:/etc/gitlab/ssl/gitlab.comprofix.com.key
scp /mnt/nfs/docker/traefik/config/certificates/registry.gitlab.comprofix.com.cer root@$GITLAB:/etc/gitlab/ssl/registry.gitlab.comprofix.com.crt
scp /mnt/nfs/docker/traefik/config/certificates/registry.gitlab.comprofix.com.key root@$GITLAB:/etc/gitlab/ssl/registry.gitlab.comprofix.com.key
ssh -t root@$GITLAB "gitlab-ctl restart nginx"