Hi,
Like Lee, I don't see the point of doing automated backups.
But the original poster seems to need it, so here is a quick and dirty bash script that should do the trick :
#! /bin/bash
PROTO='http://'
if [ -x curl ]; then
echo "You need curl to run this script!"
fi
if [ $# -lt 1 -o $# -gt 2 ]; then
echo "usage: $0 <m0n0wall box's IP or hostname> [ssl]"
echo " ssl: if used, then curl will use https to access your box."
exit 1
elif [ $# -eq 2 -a "$2" = "ssl" ]; then
PROTO='https://'
fi
read -s -p "Enter admin password:" PASSWORD
CURL_OPTS="--basic --user admin:${PASSWORD} --insecure --stderr /dev/null"
IP="$1"
BACKUP_URL=${PROTO}${IP}/diag_backup.php
BACKUP_FILE="config-${IP}-$(date +%Y%m%d%H%M%S).xml"
echo -e "\nTrying to retrieve configuration from ${IP}..."
echo "Step 1 - Connecting to m0n0wall box to retrieve CSRF magic..."
CSRF=$(curl ${CURL_OPTS} ${BACKUP_URL} | \
grep '__csrf_magic' | \
sed "s#.*value=\"\(.*\)\".*#\1#")
if [ -z ${CSRF} ]; then
echo "Failed!"
exit 1
fi
echo "Done!"
echo "Step 2 - Downloading configuration from m0n0wall box..."
UPLOADED=$(curl ${CURL_OPTS} --referer ${BACKUP_URL} \
--form Submit=Download --form __csrf_magic=${CSRF} \
${BACKUP_URL} -o ${BACKUP_FILE}; echo $?)
if [ $UPLOADED -ne 0 ]; then
echo "Failed!"
exit 1
fi
echo "Done!"
Usage is simple :
pierre@tala:~/tmp$ ./m0n0backup.sh loki ssl
Enter admin password:
Trying to retrieve configuration from loki...
Step 1 - Connecting to m0n0wall box to retrieve CSRF magic...
Done!
Step 2 - Downloading configuration from m0n0wall box...
Done!
pierre@tala:~/tmp$ ls -lh config-*
-rw-rw-r-- 1 pierre pierre 27K déc. 11 17:28 config-loki-20131211172816.xml
Hope it'll help...
Pierre