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:
parent
3edd5fbcbc
commit
01d1e6c4d8
@ -28,7 +28,7 @@ python czds.py [--username <username> --password <password>] [--concurrency <int
|
||||
./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!
|
||||
|
||||
___
|
||||
|
13
czds
13
czds
@ -8,6 +8,9 @@ echo "ICANN Zone Data Service Script"
|
||||
# Define the current date for data organization
|
||||
now=$(date +"%Y-%m-%d")
|
||||
|
||||
# Define the output directory
|
||||
output="zonefiles/$now"
|
||||
|
||||
# Get username and password (interactive if not set by environment variables)
|
||||
username=${CZDS_USER:-$(read -p "ICANN Username: " user && echo "$user")}
|
||||
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"
|
||||
|
||||
# Create output directory
|
||||
mkdir -p zonefiles/$now
|
||||
mkdir -p $output
|
||||
|
||||
echo "Fetching zone report..."
|
||||
|
||||
# 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..."
|
||||
|
||||
# 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..."
|
||||
|
||||
@ -53,12 +56,12 @@ for url in $zone_links; do
|
||||
echo "Downloading $url..."
|
||||
|
||||
# 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...)"
|
||||
|
||||
# Unzip the zone file
|
||||
gunzip zonefiles/$now/$tld.txt.gz
|
||||
gunzip $output/$tld.txt.gz
|
||||
done
|
||||
|
||||
echo "All zone files downloaded."
|
0
extras/genstats
Normal file → Executable file
0
extras/genstats
Normal file → Executable file
17
extras/service
Executable file
17
extras/service
Executable 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 -
|
||||
}
|
Loading…
Reference in New Issue
Block a user