Defined output directory to a variable and created a systemd timer and cronjob script in extras for collecting czds data monthly

This commit is contained in:
Dionysus 2024-03-06 16:47:25 -05:00
parent 3edd5fbcbc
commit 01d1e6c4d8
Signed by: acidvegas
GPG Key ID: EF4B922DB85DC9DE
4 changed files with 26 additions and 6 deletions

View File

@ -28,7 +28,7 @@ python czds.py [--username <username> --password <password>] [--concurrency <int
./czds ./czds
``` ```
## Respects ## Respects & extras
While ICANN does have an official [czds-api-client-python](https://github.com/icann/czds-api-client-python) repository, I rewrote it from scratch to be more streamline & included a [POSIX version](./czds) for portability. There is some [official documentation](https://raw.githubusercontent.com/icann/czds-api-client-java/master/docs/ICANN_CZDS_api.pdf) that was referenced in the creation of the POSIX version. Either way, big props to ICANN for allowing me to use the CZDS for research purposes! While ICANN does have an official [czds-api-client-python](https://github.com/icann/czds-api-client-python) repository, I rewrote it from scratch to be more streamline & included a [POSIX version](./czds) for portability. There is some [official documentation](https://raw.githubusercontent.com/icann/czds-api-client-java/master/docs/ICANN_CZDS_api.pdf) that was referenced in the creation of the POSIX version. Either way, big props to ICANN for allowing me to use the CZDS for research purposes!
___ ___

13
czds
View File

@ -8,6 +8,9 @@ echo "ICANN Zone Data Service Script"
# Define the current date for data organization # Define the current date for data organization
now=$(date +"%Y-%m-%d") now=$(date +"%Y-%m-%d")
# Define the output directory
output="zonefiles/$now"
# Get username and password (interactive if not set by environment variables) # Get username and password (interactive if not set by environment variables)
username=${CZDS_USER:-$(read -p "ICANN Username: " user && echo "$user")} username=${CZDS_USER:-$(read -p "ICANN Username: " user && echo "$user")}
password=${CZDS_PASS:-$(read -sp "ICANN Password: " pass && echo "$pass")} password=${CZDS_PASS:-$(read -sp "ICANN Password: " pass && echo "$pass")}
@ -29,17 +32,17 @@ access_token=$(echo "$response" | grep -o '"accessToken":"[^"]*' | cut -d '"' -f
echo "Authenticated successfully & recieved access_token $access_token" echo "Authenticated successfully & recieved access_token $access_token"
# Create output directory # Create output directory
mkdir -p zonefiles/$now mkdir -p $output
echo "Fetching zone report..." echo "Fetching zone report..."
# Get your zone report stats from the API # Get your zone report stats from the API
curl --progress-bar -o zonefiles/$now/.stats.csv -H "Authorization: Bearer $access_token" https://czds-api.icann.org/czds/requests/report curl --progress-bar -o $output/.stats.csv -H "Authorization: Bearer $access_token" https://czds-api.icann.org/czds/requests/report
echo "Scrubbing report for privacy..." echo "Scrubbing report for privacy..."
# Redact username from report for privacy # Redact username from report for privacy
sed -i 's/$username/nobody@no.name/g' zonefiles/$now/report.csv sed -i 's/$username/nobody@no.name/g' $output/report.csv
echo "Fetching zone file links..." echo "Fetching zone file links..."
@ -53,12 +56,12 @@ for url in $zone_links; do
echo "Downloading $url..." echo "Downloading $url..."
# Make the GET request and save the response to a file # Make the GET request and save the response to a file
curl --progress-bar -o zonefiles/$now/$tld.txt.gz -H "Authorization: Bearer $access_token" "$url" curl --progress-bar -o $output/$tld.txt.gz -H "Authorization: Bearer $access_token" "$url"
echo "Downloaded $tld zone file to zonefiles/$tld.txt.gz (extracting...)" echo "Downloaded $tld zone file to zonefiles/$tld.txt.gz (extracting...)"
# Unzip the zone file # Unzip the zone file
gunzip zonefiles/$now/$tld.txt.gz gunzip $output/$tld.txt.gz
done done
echo "All zone files downloaded." echo "All zone files downloaded."

0
extras/genstats Normal file → Executable file
View File

17
extras/service Executable file
View File

@ -0,0 +1,17 @@
#!/bin/sh
# systemd user service timer setup for czds - developed by acidvegas (https://git.acid.vegas/czds)
# dont forget to export your CZDS_USER and CZDS_PASS before running
CZDS='/path/to/czds'
systemd_service() {
mkdir -p $HOME/.config/systemd/user
printf "[Unit]\nDescription=ICANN Centralized Zone Data Service (CZDS) Updater\n\n[Service]\nType=oneshot\nExecStart=$CZDS" > $HOME/.config/systemd/user/czds.service
printf "[Unit]\nDescription=Timer for ICANN Centralized Zone Data Service (CZDS) Updater\n\n[Timer]\nOnCalendar=monthly\nPersistent=true\n\n[Install]\nWantedBy=timers.target" > $HOME/.config/systemd/user/czds.timer
systemctl --user daemon-reload
systemctl --user enable czds.timer && systemctl --user start czds.timer
}
cronjob() {
(crontab -l 2>/dev/null; echo "0 3 1 * * $CZDS") | crontab -
}