automation

This commit is contained in:
Frans Allen committed 2021-06-20 20:40:27 +07:00
1 parent 978991fd5e
commit 8b5486bde4
5 files changed
+1811

No files matched your search

+23
View File
@@ -0,0 +1,23 @@
name: DNS
on:
push:
branches:
- main
jobs:
main:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Check, update and add DNS records
env:
CF_EMAIL: ${{ secrets.CF_EMAIL }}
CF_API_KEY: ${{ secrets.CF_API_KEY }}
CF_ZONE_ID: ${{ secrets.CF_ZONE_ID }}
MG_KEY: ${{ secrets.MG_KEY }}
MAIL_FROM: ${{ secrets.MAIL_FROM }}
MAIL_TO: ${{ secrets.MAIL_TO }}
run: |
composer install
php dns.php
+8
View File
@@ -0,0 +1,8 @@
{
"require": {
"cloudflare/sdk": "^1.1",
"mailgun/mailgun-php": "^3.5",
"kriswallsmith/buzz": "^1.2",
"nyholm/psr7": "^1.4"
}
}
Generated
+1664
View File
File diff suppressed because it is too large. Load diff
+85
View File
@@ -0,0 +1,85 @@
<?php
require 'vendor/autoload.php';
use Mailgun\Mailgun;
// set variables
$email = getenv('CF_EMAIL');
$apiKey = getenv('CF_API_KEY');
$zoneID = getenv('CF_ZONE_ID');
$mailgunKey = getenv('MG_KEY');
$mailFrom = getenv('MAIL_FROM');
$mailTo = getenv('MAIL_TO');
// instantiation
$key = new Cloudflare\API\Auth\APIKey($email, $apiKey);
$adapter = new Cloudflare\API\Adapter\Guzzle($key);
$dns = new Cloudflare\API\Endpoints\DNS($adapter);
$mg = Mailgun::create($mailgunKey);
// get subdomains
$json = file_get_contents('./subdomains.json');
$data = json_decode($json, true);
function send_mail($subject, $text) {
global $mg;
$mg->messages()->send('upset.dev', [
'from' => $mailFrom,
'to' => $mailTo,
'subject' => $subject,
'text' => $text
]);
}
function get_status($url) {
$ch = curl_init();
curl_setopt_array($ch, [
CURLOPT_URL => $url,
CURLOPT_NOBODY => 1,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_HEADER => 1,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_USERAGENT => 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36 thedev.id-status-check',
]);
$response = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
return $status;
}
foreach ($data as $subdomain => $cname) {
$domain = $subdomain . '.thedev.id';
$recordID = $dns->getRecordID($zoneID, 'CNAME', $domain);
$updatedRecord = [
'type' => 'CNAME',
'name' => $domain,
'content' => $cname,
'ttl' => 0,
'proxied' => false
];
$status = get_status("https://$domain/");
// get & check record ID
if ($recordID == true) {
echo "The subdomain $domain already exist.\n";
// if record exist, update content
if ($dns->updateRecordDetails($zoneID, $recordID, $updatedRecord) == true) {
echo "Updated the subdomain $domain with new content $cname.\n";
if ($status != '200') {
echo "Status for $domain is $status.\n";
send_mail("$domain is not configured properly!", "Please check if the domain $domain is still valid before removing it from the list.");
}
}
} else {
// add new CNAME record
if ($dns->addRecord($zoneID, "CNAME", $subdomain, $cname, 0, false) === true) {
echo "A new CNAME record created for $domain.\n";
}
}
}
+31
View File
@@ -0,0 +1,31 @@
{
"aalfiann": "aalfiann.github.io",
"adryzz": "adryzz.github.io",
"ahmadhayyan": "ahmadhayyan.github.io",
"ahskript": "ahskript.github.io",
"anamolsapkota": "anamolsapkota.github.io",
"anil": "anilseervi.github.io",
"anon": "anondev.vercel.app",
"ash-hnry": "ash-hnry.github.io",
"appls": "appls2appls.github.io",
"ayush": "iddev5.github.io",
"bal": "balloon.bbs.yt",
"bd103": "bd103.github.io",
"cozmo": "cozmodev.github.io",
"crispy": "crispy-cream.github.io",
"dendydharmawan": "dendydharmawan.vercel.app",
"fivenine": "fivenine01.github.io",
"focus": "ffork.github.io",
"frans": "thedev.netlify.app",
"goose": "scalgoon.github.io",
"ibrahim": "minidevz.github.io",
"nikhil": "nikhilmwarrier.github.io",
"Pers0n": "Pers0n-dev.github.io",
"piyush": "officialpiyush.github.io",
"sazid": "palstheintrovert.github.io",
"sidohh": "sidohh.github.io",
"subtra3t": "subtra3t.github.io",
"themoddedchicken": "TheModdedChicken.github.io",
"wiktor": "wiktorwojcik112.github.io",
"zh": "zh.github.io"
}