Skip to content

Instantly share code, notes, and snippets.

@njnygaard
Last active March 17, 2022 00:26
Show Gist options
  • Save njnygaard/b07217c65f6b90dbab1064f0e68bb5bd to your computer and use it in GitHub Desktop.
Save njnygaard/b07217c65f6b90dbab1064f0e68bb5bd to your computer and use it in GitHub Desktop.
Backup and Restore PiHole via Teleport but Curl

HOST should resolve to your PiHole (here, it resolves via local DNS).

Pi-hole v5.9
FTL v5.14
Web Interface v5.11

Get (POST) a Backup

export HOST="thorn";
export FILENAME="backup.tar.gz";
export COOKIE=`curl -s -I -X GET http://${HOST}/admin/index.php | rg 'Set-Cookie' | awk -F: '{print $2}' | awk -F\; '{print $1}' | xargs`;
export TOKEN=`curl -b "${COOKIE}" -s http://${HOST}/admin/settings.php\?tab\=teleporter | rg 'input type="hidden" name="token" value="' | head -n1 | awk -F\" '{print $6}'`;
curl "http://${HOST}/admin/scripts/pi-hole/php/teleporter.php" \
  -b "${COOKIE}" \
  -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:98.0) Gecko/20100101 Firefox/98.0' \
  -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8' \
  -H 'Accept-Language: en-US,en;q=0.5' \
  -H 'Accept-Encoding: gzip, deflate' \
  -H 'Content-Type: multipart/form-data' \
  -H "Origin: http://${HOST}" \
  -H 'DNT: 1' \
  -H 'Connection: keep-alive' \
  -H "Referer: http://${HOST}/admin/settings.php?tab=teleporter" \
  -H 'Upgrade-Insecure-Requests: 1' \
  -H 'Sec-GPC: 1' \
  -H 'Pragma: no-cache' \
  -H 'Cache-Control: no-cache' \
  --form "zip_file=backup.tar.gz;type=application/x-gzip" \
  --form "token=${TOKEN}" \
  --form "whitelist=true" \
  --form "regex_whitelist=true" \
  --form "blacklist=true" \
  --form "regexlist=true" \
  --form "adlist=true" \
  --form "client=true" \
  --form "group=true" \
  --form "auditlog=true" \
  --form "staticdhcpleases=true" \
  --form "localdnsrecords=true" \
  --form "flushtables=true" \
  --output ${FILENAME}

Put (POST) a Backup

export HOST="thorn";
export FILENAME="backup.tar.gz";
export COOKIE=`curl -s -I -X GET http://${HOST}/admin/index.php | rg 'Set-Cookie' | awk -F: '{print $2}' | awk -F\; '{print $1}' | xargs`;
export TOKEN=`curl -b "${COOKIE}" -s http://${HOST}/admin/settings.php\?tab\=teleporter | rg 'input type="hidden" name="token" value="' | head -n1 | awk -F\" '{print $6}'`;
curl -vvvv "http://${HOST}/admin/scripts/pi-hole/php/teleporter.php" \
  -b "${COOKIE}" \
  -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:98.0) Gecko/20100101 Firefox/98.0' \
  -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8' \
  -H 'Accept-Language: en-US,en;q=0.5' \
  -H 'Accept-Encoding: gzip, deflate' \
  -H 'Content-Type: multipart/form-data' \
  -H "Origin: http://${HOST}" \
  -H 'DNT: 1' \
  -H 'Connection: keep-alive' \
  -H "Referer: http://${HOST}/admin/settings.php?tab=teleporter" \
  -H 'Upgrade-Insecure-Requests: 1' \
  -H 'Sec-GPC: 1' \
  -H 'Pragma: no-cache' \
  -H 'Cache-Control: no-cache' \
  --form "zip_file=@${FILENAME};type=application/x-gzip" \
  --form "token=${TOKEN}" \
  --form "whitelist=true" \
  --form "regex_whitelist=true" \
  --form "blacklist=true" \
  --form "regexlist=true" \
  --form "adlist=true" \
  --form "client=true" \
  --form "group=true" \
  --form "auditlog=true" \
  --form "staticdhcpleases=true" \
  --form "localdnsrecords=true" \
  --form "flushtables=true" \
  --form "action=in"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment