Skip to content

Commit

Permalink
Annoyingly PF returns a 200 for incorrect input here, so we can't rel…
Browse files Browse the repository at this point in the history
…y on the download blowing up, but we can 'quick-check' the download at least
  • Loading branch information
mintsoft committed Apr 5, 2018
1 parent b0d843c commit bb5870f
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions doBackup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@ password=$3;

([ -z "$hostname" ] || [ -z "$username" ] || [ -z "$password" ]) && echo "all 3 arguments must be specified: hostname username password " && exit 1;

csrf=$(curl -Ss --insecure --cookie-jar /tmp/$hostname-cookies.txt https://$hostname/diag_backup.php | sed -n 's/.*name=.__csrf_magic. value="\([^"]*\)".*/\1/p')
csrf2=$(curl -Ss --insecure --location --cookie-jar /tmp/$hostname-cookies.txt --cookie /tmp/$hostname-cookies.txt --data "login=Login&usernamefld=$username&passwordfld=$password&__csrf_magic=$csrf" https://$hostname/diag_backup.php | sed -n 's/.*var csrfMagicToken = "\([^"]*\)".*/\1/p')
csrf=$(curl -Ss --insecure --cookie-jar /tmp/$hostname-cookies.txt https://$hostname/diag_backup.php | sed -n 's/.*name=.__csrf_magic. value="\([^"]*\)".*/\1/p');
csrf2=$(curl -Ss --insecure --location --cookie-jar /tmp/$hostname-cookies.txt --cookie /tmp/$hostname-cookies.txt --data "login=Login&usernamefld=$username&passwordfld=$password&__csrf_magic=$csrf" https://$hostname/diag_backup.php | sed -n 's/.*var csrfMagicToken = "\([^"]*\)".*/\1/p');

curl -Ss --insecure --cookie /tmp/$hostname-cookies.txt --cookie-jar /tmp/$hostname-cookies.txt --data "download=download&donotbackuprrd=yes&__csrf_magic=$csrf2" https://$hostname/diag_backup.php > config-router-`date +%Y%m%d%H%M%S`.xml
backupfile=config-router-`date +%Y%m%d%H%M%S`.xml;

curl -Ss --insecure --cookie /tmp/$hostname-cookies.txt --cookie-jar /tmp/$hostname-cookies.txt --data "download=download&donotbackuprrd=yes&__csrf_magic=$csrf2" https://$hostname/diag_backup.php > $backupfile;

grep --silent '^<?xml ' $backupfile || echo "Downloaded file is not XML; is probably broken."

rm /tmp/$hostname-cookies.txt;

0 comments on commit bb5870f

Please sign in to comment.