diff --git a/.github/workflows/domains.yml b/.github/workflows/domains.yml new file mode 100644 index 0000000..fe25d91 --- /dev/null +++ b/.github/workflows/domains.yml @@ -0,0 +1,61 @@ +name: Domains + +on: + workflow_dispatch: {} + + push: + branches: [main] + + schedule: + - cron: "0 0 * * *" + +jobs: + ping: + name: Ping + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - name: Create ping_results.txt + run: touch domains/ping_results.txt + + - name: Ping Domains + run: | + cd domains + for file in *.json; do + if [[ -f $file && ! -d $file ]]; then + while read -r line; do + record_type=$(echo "$line" | jq -r 'keys[]') + record_value=$(echo "$line" | jq -r '.[]') + + if [[ "$record_type" =~ ^(A|AAAA)$ ]]; then + IFS=$'\n' read -r -a record_values <<< "$record_value" + for val in "${record_values[@]}"; do + ping_result=$(ping -c 1 "$val") + + if [[ $? -eq 0 ]]; then + echo "PASS ${file%.json} $record_type $val" + else + echo "FAIL ${file%.json} $record_type $val" + fi + done + elif [[ "$record_type" == "CNAME" ]]; then + ping_result=$(ping -c 1 "$record_value") + + if [[ $? -eq 0 ]]; then + echo "PASS ${file%.json} $record_type $record_value" + else + echo "FAIL ${file%.json} $record_type $record_value" + fi + fi + done < <(jq -c '.records | to_entries[] | {"key": .key, "value": .value}' "$file") + fi + done + + - name: Push Data + run: | + git config --global user.email "bot@freesubdomains.org" + git config --global user.name "free-domains-bot" + git add domains/ping_results.txt + git commit -m "Update Ping Results" + git push