Skip to content
This repository has been archived by the owner on Jan 17, 2023. It is now read-only.

Commit

Permalink
Add DNS
Browse files Browse the repository at this point in the history
  • Loading branch information
willnode committed Jul 22, 2021
1 parent f83c4f6 commit 25ec9d9
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 2 deletions.
8 changes: 8 additions & 0 deletions public/dns.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

require_once "../vendor/autoload.php";

$dotenv = Dotenv\Dotenv::createImmutable(realpath(__DIR__ . '/../'));
$dotenv->load();

include "../src/dns/main.php";
58 changes: 58 additions & 0 deletions src/dns/main.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

// validate request

if (!isset($_GET['secret'], $_GET['action'])) exit;
if ($_GET['secret'] !== $_SERVER['SECRET_TOKEN']) exit;
if ($_GET['action'] === 'refresh') {
exec($_SERVER['DNS_RELOAD']);
echo "DNS Updated\n";
} else if ($_GET['action'] === 'check') {
$dns_file = file_get_contents($_SERVER['DNS_PATH']);
if (!$dns_file) {
die("ERROR: config not found\n");
}
$record = str_contains($_GET['value'], ':') ? 'AAAA' : 'A';
$theword = "$_GET[host].domcloud.io.\tIN\t$record\t$_GET[value]\n";
echo str_contains($dns_file, $theword) ? '1' : '0';
die();
} else if ($_GET['action'] === 'add') {
$dns_file = file_get_contents($_SERVER['DNS_PATH']);
if (!$dns_file) {
die("ERROR: config not found\n");
}

$record = str_contains($_GET['value'], ':') ? 'AAAA' : 'A';
$theword = "$_GET[host].domcloud.io.\tIN\t$record\t$_GET[value]\n";

$replaced_file = str_replace($theword, "", $dns_file);
$replaced_file = $replaced_file . $theword;

if ($dns_file === $replaced_file) {
die("Updated, nothing changed\n");
}
if (file_put_contents($_SERVER['DNS_PATH'], $replaced_file, LOCK_EX) === false) {
die("ERROR: unable to write config\n");
}
exec($_SERVER['DNS_RELOAD']);
echo "Updated for A Record\n";
} else if ($_GET['action'] === 'del') {
$dns_file = file_get_contents($_SERVER['DNS_PATH']);
if (!$dns_file) {
die("ERROR: config not found\n");
}

$record = str_contains($_GET['value'], ':') ? 'AAAA' : 'A';
$theword = "$_GET[host].domcloud.io.\tIN\t$record\t$_GET[value]\n";

$replaced_file = str_replace($theword, "", $dns_file);

if ($dns_file === $replaced_file) {
die("Updated, Nothing changed\n");
}
if (file_put_contents($_SERVER['DNS_PATH'], $replaced_file, LOCK_EX) === false) {
die("ERROR: unable to write config\n");
}
exec($_SERVER['DNS_RELOAD']);
echo "Updated for A Record\n";
}
2 changes: 1 addition & 1 deletion src/iptables/main.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
if (!isset($_GET['secret'], $_GET['action'])) exit;
if ($_GET['secret'] !== $_SERVER['SECRET_TOKEN']) exit;
if ($_GET['action'] === 'refresh') {
exec($_SERVER['IPTABLES_REFRESH']);
exec($_SERVER['IPTABLES_RELOAD']);
echo "Updated for IPv4\n";
} else if ($_GET['action'] === 'check') {
$iptables_file = file_get_contents($_SERVER['IPTABLES_PATH']);
Expand Down
2 changes: 1 addition & 1 deletion src/iptables/mainv6.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
if (!isset($_GET['secret'], $_GET['action'])) exit;
if ($_GET['secret'] !== $_SERVER['SECRET_TOKEN']) exit;
if ($_GET['action'] === 'refresh') {
exec($_SERVER['IPTABLESV6_REFRESH']);
exec($_SERVER['IPTABLESV6_RELOAD']);
echo "Updated for IPv6\n";
} else if ($_GET['action'] === 'add_user') {
$iptables_file = file_get_contents($_SERVER['IPTABLESV6_PATH']);
Expand Down

0 comments on commit 25ec9d9

Please sign in to comment.