czds

- ICANN Centralized Zone Data Service Tool
git clone git://git.acid.vegas/czds.git
Log | Files | Refs | Archive | README | LICENSE

commit 01d1e6c4d83ef9f4a7c4784e6d5357287d92ead8
parent 3edd5fbcbc2e540faf693b5df536b5ff7454d92c
Author: acidvegas <acid.vegas@acid.vegas>
Date: Wed, 6 Mar 2024 16:47:25 -0500

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

Diffstat:
MREADME.md | 2+-
Mczds | 13++++++++-----
Mextras/genstats | 0
Aextras/service | 18++++++++++++++++++

4 files changed, 27 insertions(+), 6 deletions(-)

diff --git a/README.md b/README.md
@@ -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!
 
 ___
diff --git a/czds b/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."
 \ No newline at end of file
diff --git a/extras/genstats b/extras/genstats
diff --git a/extras/service b/extras/service
@@ -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 -
+}
+\ No newline at end of file