Skip to content

Commit

Permalink
Merge pull request #11 from MrMarioMichel/development
Browse files Browse the repository at this point in the history
Main-Beta-v5.0
  • Loading branch information
DRIgnazGortngschirl authored Oct 4, 2019
2 parents b4ca66c + c9c0359 commit 9450ec2
Show file tree
Hide file tree
Showing 21 changed files with 350 additions and 172 deletions.
2 changes: 1 addition & 1 deletion Archive/resources/themes/bootstrap/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<head>

<title>Directory listing of <?php echo $lister->getListedPath(); ?></title>
<title>Config-Backupper <?php echo $lister->getListedPath(); ?></title>
<link rel="shortcut icon" href="<?php echo THEMEPATH; ?>/img/folder.png">

<!-- STYLES -->
Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions Devices/Cisco/sgX00.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

14 changes: 0 additions & 14 deletions Devices/DELL/DELL-Devices.txt

This file was deleted.

1 change: 1 addition & 0 deletions Devices/DELL/nXXXX.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

33 changes: 17 additions & 16 deletions Main-Launcher.sh
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
#!/bin/bash
date=`date +%d%m%y`
date=$(date +%d%m%y)
# ---------------------------------------------
cd PLACEHOLDERFORINSTALLATIONPATH
# ---------------------------------------------
#
echo "[i]: Start of backup @ $(date +%H:%m)" >> ./Log/Backup/log$date.txt

### Backup Modules ###
./Modules/Backup/Fortinet/Fortinet.sh &>> ./Log/Fortinet/log$date.txt
#./Modules/Backup/Fortinet/Fortinet-Special.sh &>> ./Log/Fortinet/log$date.txt ### Disabled by default ###
./Modules/Backup/Cisco/Cisco.sh &>> ./Log/Cisco/log$date.txt ### Only for sgx00 series working ###
#./Modules/Backup/DELL/DELL.sh &>> ./Log/DELL/log$date.txt ### NOT YET FUNCTIONAL! ###
#./Modules/Backup/HP/HP.sh &>> ./Log/HP/log$date.txt ### NOT YET FUNCTIONAL! ###
# ./Modules/Backup/Fortinet/Fortinet.sh &>> ./Log/Fortinet/log$date.txt ### FUNCTIONAL ###
# ./Modules/Backup/Fortinet/Fortinet-Special.sh &>> ./Log/Fortinet/log$date.txt ### Disabled by default FUNCTIONAL ###
# ./Modules/Backup/Cisco/Cisco.sh &>> ./Log/Cisco/log$date.txt ### Only for sgx00 & n3XXX series working ###
# ./Modules/Backup/DELL/DELL.sh &>> ./Log/DELL/log$date.txt ### Only for nXXXX series working ###
# ./Modules/Backup/HP/HP.sh &>> ./Log/HP/log$date.txt ### NOT YET FUNCTIONAL! ###

### Archive Compression/Stats/Debugs & Loging ###
### Archive Compression/Debugs & Stats ###

# Compression
./Modules/Archive/OldConfigsArchiver.sh &> ./Log/Backup/log$date.txt ### Used for compression and deleteion of old configs ###
./Modules/Archive/OldLogsArchiver.sh &> ./Log/Backup/log$date.txt ### Used for compression and deleteion of old logs ###

# Stats
./Modules/Archive/ArchiveStats.sh &> ./Log/Backup/log$date.txt ### Used for displaying archive stats ###
./Modules/Archive/OldConfigs/Archiver.sh &>> ./Log/Backup/log$date.txt ### Used for compression and deleteion of old configs ###
./Modules/Archive/OldLogs/Archiver.sh &>> ./Log/Backup/log$date.txt ### Used for compression and deleteion of old logs ###

# Debug
./Modules/Archive/Checker.sh &> ./Log/Backup/log$date.txt ### Used for config copy debugging ###
./Modules/Archive/Fastdebug.sh > ./Log/Failed/Failed-$date.txt ### Used for check failed backup attempts

#./Modules/FirmwareCheck/Fortinet/FirmwareChecker.sh | sed $'s/<br>/\\\n/g' | sed 'N;s/\n/ /' > ./Devices/Firmware-Versions/Fortinet-Firmware-$date.txt ### Disabled by default ###
./Modules/Archive/Fastdebug.sh &>> ./Log/Failed/Failed-$date.txt ### Used for config copy debugging ###

# Stats
./Modules/Archive/ArchiveStats.sh &>> ./Log/Backup/log$date.txt ### Used for displaying archive and varius stats ###
# ./Modules/FirmwareCheck/Fortinet/FirmwareChecker.sh ### Disabled by default ###
echo "[i}: End of backup @ $(date +%H:%m)" >> ./Log/Backup/log$date.txt
36 changes: 33 additions & 3 deletions Modules/Archive/ArchiveStats.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,34 @@
#!/bin/bash
date=`date +%d%m%y`
echo "Current size of ./Archive : $(du -sh ./Archive)"
echo "Current configs in ./Archive $(tree | grep .conf | wc -l)"

# Stats
currentsizearchive=$(du -sh ./Archive --exclude=./Archive/resources | awk '{print $1}')B
totalconfigsarchive=$(tree | grep .conf | wc -l)
totallines=$(find ./Archive -name "*.conf" -mmin -120 -exec cat {} + | wc -l)
configsinarchive=$(find ./Archive -maxdepth 2 -type f -name "*.conf" -mmin -120 | wc -l)
fortinethostfilecount=$(egrep -v "^\s*(#|$)" ./Devices/Fortinet/Fortinet-Devices.txt | grep -oE "\b([0-9]{1,3}\.){3}[0-9]{1,3}\b" | wc -l)
hphostfilecount=$(egrep -v "^\s*(#|$)" ./Devices/HP/HP-Devices.txt | grep -oE "\b([0-9]{1,3}\.){3}[0-9]{1,3}\b" | wc -l)
ciscohostfilecount=$(egrep -v "^\s*(#|$)" ./Devices/Cisco/Cisco-Devices.txt | grep -oE "\b([0-9]{1,3}\.){3}[0-9]{1,3}\b" | wc -l)
dellhostfilecount=$(egrep -v "^\s*(#|$)" ./Devices/DELL/DELL-Devices.txt | grep -oE "\b([0-9]{1,3}\.){3}[0-9]{1,3}\b" | wc -l)
dirsinarchive=$(find ./Archive -maxdepth 1 -type d | wc -l)
minus2=2 # Caused by also counting the ./Archive and ./Archive/resources as a folder
minus1=1 # Caused by also counting the./Archive/resources/config.php as a .conf file

# Quick Math
avglinesinconfig=$((expr $totallines / $configsinarchive))
total=$((expr $fortinethostfilecount + $hphostfilecount + $ciscohostfilecount + $dellhostfilecount))
dirsinarchive=$((expr $dirsinarchive - $minus2))
totalconfigsarchive=$((expr $totalconfigsarchive - $minus1))

echo "------------------------------------------------"
echo "Fortinet hosts in host file .......... $fortinethostfilecount"
echo "HP hosts in host file ................ $hphostfilecount"
echo "Cisco hosts in host file ............. $ciscohostfilecount"
echo "DELL hosts in host file .............. $dellhostfilecount"
echo "Total hosts in host files ............ $total"
echo "Directories in Archiv ................ $dirsinarchive"
echo "Current Configs in Archive ........... $configsinarchive"
echo "Total configs in ./Archive ........... $totalconfigsarchive"
echo "Current size of ./Archive ............ $currentsizearchive"
echo "Total lines operating firewalls ...... $totallines"
echo "Average lines in conifig file ........ $avglinesinconfig"
echo "------------------------------------------------"
26 changes: 0 additions & 26 deletions Modules/Archive/Checker.sh

This file was deleted.

9 changes: 5 additions & 4 deletions Modules/Archive/Fastdebug.sh
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
#!/bin/bash

date=`date +%d%m%y`
date=$(date +%d%m%y)

echo "Backup Errors"
echo "Fortinet:"
echo "--------------------------------------------------------------------------------------------------"
join <(sort ./Devices/Fortinet/Fortinet-Devices.txt) <(sort ./Log/Fortinet/log$date.txt | grep '\[i]:' | grep -e "not reachable" -e "failed" | sed -e 's/\[i]: //')
# join <(sort ./Modules/Backup/Fortinet-Special.sh | grep "#" | grep -v '#!/bin/bash' | sed 's/# //') <(sort ./Log/Fortinet/log$date.txt| grep '\[i]:' | grep -e "not reachable" -e "failed" | sed -e 's/\[i]: //')
join <(sort ./Devices/Fortinet/Fortinet-Devices.txt | egrep -v "^\s*(#|$)") <(sort ./Log/Fortinet/log$date.txt | grep '\[i]:' | grep -e "Name not found" -e "not reachable" -e "backup failed" | sed -e 's/\[i]: //')
# join <(sort ./Modules/Backup/Fortinet-Special.sh | grep '#' | grep -v '#!/bin/bash' | sed 's/# //') <(sort ./Log/Fortinet/log$date.txt | grep '\[i]:' | grep -e "Name not found" -e "not reachable" -e "backup failed" | sed -e 's/\[i]: //')
echo "--------------------------------------------------------------------------------------------------"
echo "Cisco:"
echo "--------------------------------------------------------------------------------------------------"
join <(sort ./Devices/Cisco/Cisco-Devices.txt) <(sort ./Log/Cisco/log$date.txt | grep '\[i]:' | grep -e "not reachable" -e "failed" | sed -e 's/\[i]: //')
join <(sort ./Devices/Cisco/Cisco-sgX00.txt | egrep -v "^\s*(#|$)") <(sort ./Log/Cisco/log$date.txt | grep '\[i]:' | grep -e "Name not found" -e "not reachable" -e "backup failed" | sed -e 's/\[i]: //')
join <(sort ./Devices/Cisco/Cisco-n3XXX-txt | egrep -v "^\s*(#|$)") <(sort ./Log/Cisco/log$date.txt | grep '\[i]:' | grep -e "Name not found" -e "not reachable" -e "backup failed" | sed -e 's/\[i]: //')
echo "--------------------------------------------------------------------------------------------------"
#echo "DELL :"
#echo "----------------------------------------------------------------------------"
Expand Down
27 changes: 2 additions & 25 deletions Modules/Backup/Cisco/Cisco.sh
Original file line number Diff line number Diff line change
@@ -1,29 +1,6 @@
#!/bin/bash

user=backup

echo "[i]: Started Backup of Configs : CISCO"

for device in `cat ./Devices/Cisco/Cisco-Devices.txt | egrep -v "^\s*(#|$)" | grep -oE "\b([0-9]{1,3}\.){3}[0-9]{1,3}\b"`
do
echo -e "[i]: Host --> $device"
if ping -c 3 $device &> /dev/null
then
echo "[i]: $device reachable"
./sgX00.sh $device
name=`cat BackupConfigCisco | grep hostname | sed 's|["?]||g' | sed 's/hostname //'`
mkdir -v Archive/$name
date=`date +"%H-%M_%d-%m-%Y"`
mv -v BackupConfigCisco ./Archive/$name/$name-$date.conf
if [ -f ./Archive/$name/$name-$date.conf ]
then
echo "[i]: File $name-$date.conf found!"
echo "[i]: $device backup succeeded"
else
echo "[i]: File $name-$date.conf not found!"
echo "[i]: $device backup failed"
fi
else
echo "[i]: $device not reachable"
fi
done
# ./Modules/Backup/Cisco/sgX00.sh
# ./Modules/Backup/Cisco/n3XXX.sh
41 changes: 41 additions & 0 deletions Modules/Backup/Cisco/n3XXX.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/bin/bash

user="cisco"
passwd="XXXXXXPASSWORDXXXXXX"

echo "[i]: Started Backup of Configs : Cisco (n3XXX.sh)"

for device in $(egrep -v "^\s*(#|$)" ./Devices/Cisco/Cisco-N3xxx-txt | grep -oE "\b([0-9]{1,3}\.){3}[0-9]{1,3}\b")
do
echo -e "[i]: Host --> $device"
if ping -c 3 $device &> /dev/null
then
echo "[i]: $device reachable"
sshpass -p "$passwd" ssh -tt $user@$device <<EOF > BackupConfigCiscoTEMP1
terminal length 0
show startup-config
exit
EOF
name=$(grep hostname ./BackupConfigCiscoTEMP1 | sed 's|["?]||g' | sed 's/hostname //' | tr -dc '[:print:]')
grep -v "$name#" BackupConfigCiscoTEMP1 | sed 's/terminal length 0//g' | sed 's/show startup-config//g' | sed 's/exit//g' > BackupConfigCisco
if [ -z "$name" ]
then
echo "[i]: $device Name not found"
else
echo "[i]: $device Name found $name"
mkdir -v ./Archive/$name
date=$(date +"%H-%M_%d-%m-%Y")
mv -v ./BackupConfigCisco ./Archive/$name/$name-$date.conf
if [ -f ./Archive/$name/$name-$date.conf ]
then
echo "[i]: File $name-$date.conf found"
echo "[i]: $device backup succeeded"
else
echo "[i]: File $name-$date.conf not found"
echo "[i]: $device backup failed"
fi
fi
else
echo "[i]: $device not reachable"
fi
done
61 changes: 48 additions & 13 deletions Modules/Backup/Cisco/sgX00.sh
Original file line number Diff line number Diff line change
@@ -1,30 +1,44 @@
#!/bin/bash

echo "[i]: Started Backup of Configs : CISCO (sgX00.sh)"

for device in $(egrep -v "^\s*(#|$)" ./Devices/Cisco/Cisco-Devices.txt | grep -oE "\b([0-9]{1,3}\.){3}[0-9]{1,3}\b")
do
echo -e "[i]: Host --> $device"
if ping -c 3 $device &> /dev/null
then
echo "[i]: $device reachable"

# For: Cisco Small Business SG200 26/50 port switch
# v.0.0.1 09/29/2014
# v.0.0.2 09/30/2016

# from https://github.com/pgporada/cisco-sg200-config-retriever/blob/master/cisco-sg200-config-retriever.sh

# Show help if first argv does not exist
IP=$1
if [ -z ${IP} ]; then
echo "Error: IP missing on CLI"
echo "Usage: ./$(basename $0) xxx.xxx.xxx.xxx"
exit
fi
IP=$device
HTTPorHTTPS=HTTP # Use this to define if HTTP or HTTPS service should be used to acsses the switch. Default is HTTP

# USERNAME=cisco
# PASSWORD=XXXXXXPASSWORDXXXXXX
# IP=$1
# if [ -z ${IP} ]; then
# echo "Error: IP missing on CLI"
# echo "Usage: ./$(basename $0) xxx.xxx.xxx.xxx"
# exit
# fi


USERNAME="cisco"
PASSWORD=XXXXXXPASSWORDXXXXXX

USERAGENT="'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.124 Safari/537.36'"

# Referer line
REF="'http://${IP}/cs34055c2b/config/log_off_page.htm'"
REF="'${HTTPorHTTPS}://${IP}/cs34055c2b/config/log_off_page.htm'"

INITIALCOOKIE="'cisco_numberOfEntriesPerPage=50; pg=00000000000000000000000000000000000000000000000000000000000; isStackableDevice=false; userStatus=ok; activeLangId=English; firstWelcomeBanner=false'"

# Unencrypted login line. Encrypted uses some long convoluted RSA encryption scheme written in Javascript. I tried for hours to parse it but couldn't figure it out. Maybe another set of eyes will have better luck.
LOGIN="'http://${IP}/cs34055c2b/config/System.xml?action=login&user=${USERNAME}&password=${PASSWORD}&ssd=true&'"
LOGIN="'${HTTPorHTTPS}://${IP}/cs34055c2b/config/System.xml?action=login&user=${USERNAME}&password=${PASSWORD}&ssd=true&'"

# Get the headers for the session so we can parse the output and build our real session string
SESSION=$(eval curl -i -s -k -b ${INITIALCOOKIE} -A ${USERAGENT} -e ${REF} ${LOGIN} | grep "sessionID")
Expand All @@ -37,13 +51,12 @@ SESSIONID=$(echo ${SESSION} | cut -d'&' -f2)
MYCOOKIE="'cisco_numberOfEntriesPerPage=50; pg=00000000000000000000000000000000000000000000000000000000000; isStackableDevice=false; userStatus=ok; sessionID=UserId=${USERID}&${SESSIONID}&; usernme=cisco; activeLangId=English; firstWelcomeBanner=false'"

# Set the referer line to a new value
REF="'http://${IP}/cs34055c2b/FileMgmt/maintenance_file_fileUpload_m.htm'"
REF="'${HTTPorHTTPS}://${IP}/cs34055c2b/FileMgmt/maintenance_file_fileUpload_m.htm'"

# The rl options here get me an http download of the running config from the switch to my machine
INDEX=$(date +%H%M%S)
DLURL="'http://${IP}/cs34055c2b/FileMgmt/stupCfg.ber?rlCopyFreeHistoryIndex=${INDEX}&&rlCopyDestinationFileType=2&&rlCopyOptionsRequestedSsdAccess=3&&redirect=/device/copyfiles.xml'"
DLURL="'${HTTPorHTTPS}://${IP}/cs34055c2b/FileMgmt/stupCfg.ber?rlCopyFreeHistoryIndex=${INDEX}&&rlCopyDestinationFileType=2&&rlCopyOptionsRequestedSsdAccess=3&&redirect=/device/copyfiles.xml'"

TSTAMP=$(date +%Y%m%d-%H%M%S)
FILENAME=BackupConfigCisco

# Actually download the file
Expand All @@ -67,3 +80,25 @@ then
else
echo "[i]: (sgX00.sh) Saved the config for ${IP}"
fi
name=$(grep hostname ./BackupConfigCisco | sed 's|["?]||g' | sed 's/hostname //')
if [ -z "$name" ]
then
echo "[i]: $device Name not found"
else
echo "[i]: $device Name found $name"
mkdir -v ./Archive/$name
date=$(date +"%H-%M_%d-%m-%Y")
mv -v ./BackupConfigCisco ./Archive/$name/$name-$date.conf
if [ -f ./Archive/$name/$name-$date.conf ]
then
echo "[i]: File $name-$date.conf found"
echo "[i]: $device backup succeeded"
else
echo "[i]: File $name-$date.conf not found"
echo "[i]: $device backup failed"
fi
fi
else
echo "[i]: $device not reachable"
fi
done
18 changes: 2 additions & 16 deletions Modules/Backup/DELL/DELL.sh
Original file line number Diff line number Diff line change
@@ -1,19 +1,5 @@
# _ _ _ _ _____ ______ _____ _____ ____ _ _ _____ _______ _____ _ _ _____ _______ _____ ____ _ _
# | | | | \ | | __ \| ____| __ \ / ____/ __ \| \ | |/ ____|__ __| __ \| | | |/ ____|__ __|_ _/ __ \| \ | |
# | | | | \| | | | | |__ | |__) | | | | | | | \| | (___ | | | |__) | | | | | | | | || | | | \| |
# | | | | . ` | | | | __| | _ / | | | | | | . ` |\___ \ | | | _ /| | | | | | | | || | | | . ` |
# | |__| | |\ | |__| | |____| | \ \ | |___| |__| | |\ |____) | | | | | \ \| |__| | |____ | | _| || |__| | |\ |
# \____/|_| \_|_____/|______|_| \_\ \_____\____/|_| \_|_____/ |_| |_| \_\\____/ \_____| |_| |_____\____/|_| \_|

# Still working on this. (NOT YET FUNCTIONAL!)

#!/bin/bash

user=backup

echo "Started Backup of Config's"

for device in `cat ./Devices/DELL/DELL-Devices.txt | egrep -v "^\s*(#|$)"` # Will have a look in the file "DELL-Devices.txt" for all DELL devices
do
echo "[i]: Started Backup of Configs : DELL"

done
# ./Modules/Backup/DELL/nXXXX.sh
31 changes: 31 additions & 0 deletions Modules/Backup/DELL/nXXXX.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash

user="dell"
passwd="XXXXXXPASSWORDXXXXXX"

echo "[i]: Started Backup of Configs : DELL (nXXXX.sh)"
for device in $(egrep -v "^\s*(#|$)" ./Devices/DELL/NXXXX.txt | grep -oE "\b([0-9]{1,3}\.){3}[0-9]{1,3}\b")
do
echo -e "[i]: Host --> $device"
sshpass -p "$passwd" \ssh -v $user@$device <<EOF > BackupConfigDELLTEMP1
enable
show running-config
exit
exit
exit
EOF
name=$(grep "hostname" BackupConfigDELLTEMP1 | sed 's|["?]||g' | sed 's/hostname //' | tr -dc '[:print:]')
grep -v "$name>" BackupConfigDELLTEMP1 | grep -v "$name#"> BackupConfigDELL
mkdir -v Archive/$name
date=$(date +"%H-%M_%d-%m-%Y")
mv -v BackupConfigDELL ./Archive/$name/$name-$date.conf
rm BackupConfigDELLTEMP1
if [ -f ./Archive/$name/$name-$date.conf ]
then
echo "[i]: File $name-$date.conf found!"
echo "[i]: $device backup succeeded"
else
echo "[i]: File $name-$date.conf not found!"
echo "[i]: $device backup failed"
fi
done
Loading

0 comments on commit 9450ec2

Please sign in to comment.