-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
221 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
<?php | ||
require_once __DIR__ . '/../Providers/vendor/autoload.php'; | ||
|
||
$config = include __DIR__ . '/../../../config.php'; | ||
$c = $config["db"]; | ||
|
||
use Badcow\DNS\Zone; | ||
use Badcow\DNS\Rdata\Factory; | ||
use Badcow\DNS\ResourceRecord; | ||
use Badcow\DNS\Classes; | ||
use Badcow\DNS\AlignedBuilder; | ||
|
||
try { | ||
$dsn = $c["type"] . ":host=" . $c["host"] . ";port=" . $c["port"] . ";dbname=" . $c["name"]; | ||
$pdo = new PDO($dsn, $c["user"], $c["password"]); | ||
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); | ||
|
||
// Fetch domain names and IDs from service_dns table | ||
$domainsStmt = $pdo->query("SELECT id, domain_name FROM service_dns"); | ||
$domains = $domainsStmt->fetchAll(PDO::FETCH_ASSOC); | ||
$timestamp = time(); | ||
|
||
foreach ($domains as $domain) { | ||
$domainName = $domain['domain_name']; | ||
$domainId = $domain['id']; | ||
|
||
$stmt = $pdo->prepare("SELECT * FROM service_dns_records WHERE domain_id = :domainId"); | ||
$stmt->execute(['domainId' => $domainId]); | ||
|
||
$zone = new Zone($domainName.'.'); | ||
$zone->setDefaultTtl(3600); | ||
|
||
$soa = new ResourceRecord; | ||
$soa->setName('@'); | ||
$soa->setClass(Classes::INTERNET); | ||
$soa->setRdata(Factory::Soa( | ||
'example.com.', | ||
'post.example.com.', | ||
$timestamp, | ||
3600, | ||
14400, | ||
604800, | ||
3600 | ||
)); | ||
$zone->addResourceRecord($soa); | ||
|
||
$ns1 = new ResourceRecord; | ||
$ns1->setName('@'); | ||
$ns1->setClass(Classes::INTERNET); | ||
$ns1->setRdata(Factory::Ns('ns1.nameserver.com.')); | ||
$zone->addResourceRecord($ns1); | ||
|
||
$ns2 = new ResourceRecord; | ||
$ns2->setName('@'); | ||
$ns2->setClass(Classes::INTERNET); | ||
$ns2->setRdata(Factory::Ns('ns2.nameserver.com.')); | ||
$zone->addResourceRecord($ns2); | ||
|
||
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { | ||
$recordType = $row['type']; | ||
$host = $row['host']; | ||
$value = $row['value']; | ||
$ttl = $row['ttl'] ?? 3600; // Default TTL | ||
|
||
$record = new ResourceRecord(); | ||
$record->setName($host); | ||
$record->setTtl($ttl); | ||
|
||
switch ($recordType) { | ||
case 'A': | ||
$record->setRdata(Factory::A($value)); | ||
break; | ||
case 'AAAA': | ||
$record->setRdata(Factory::Aaaa($value)); | ||
break; | ||
case 'MX': | ||
$priority = $row['priority'] ?? 0; | ||
$record->setRdata(Factory::Mx($priority, $value)); | ||
break; | ||
case 'CNAME': | ||
$record->setRdata(Factory::Cname($value)); | ||
break; | ||
case 'TXT': | ||
$formattedValue = trim($value, '"'); | ||
$record->setRdata(Factory::Txt($formattedValue)); | ||
break; | ||
case 'SPF': | ||
$formattedValue = trim($value, '"'); | ||
$record->setRdata(Factory::Spf($formattedValue)); | ||
break; | ||
case 'DS': | ||
// DS record typically requires key tag, algorithm, digest type, and digest | ||
// Assuming these are provided in a formatted string or individual columns | ||
// $value format should be "keyTag algorithm digestType digest" | ||
list($keyTag, $algorithm, $digestType, $digest) = explode(' ', $value); | ||
$record->setRdata(Factory::Ds($keyTag, $algorithm, $digestType, $digest)); | ||
break; | ||
// ... Other record types | ||
} | ||
|
||
$zone->addResourceRecord($record); | ||
} | ||
|
||
// Generate zone file content for each domain | ||
$builder = new AlignedBuilder(); | ||
$zoneFileContent = $builder->build($zone); | ||
|
||
// Generate zone for each domain and reload BIND | ||
file_put_contents("/var/lib/bind/db.$domainName", $zoneFileContent); | ||
|
||
exec("rndc reload {$domainName}.", $output, $return_var); | ||
exec("rndc notify {$domainName}.", $output, $return_var); | ||
} | ||
|
||
} catch (PDOException $e) { | ||
echo "Connection failed: " . $e->getMessage(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
<?php | ||
|
||
namespace Box\Mod\Servicedns\Providers; | ||
|
||
class Bind implements DnsHostingProviderInterface { | ||
|
||
public function __construct() { | ||
} | ||
|
||
public function createDomain($domainName) { | ||
if (empty($domainName)) { | ||
throw new \FOSSBilling\Exception("Domain name cannot be empty"); | ||
} | ||
|
||
return json_decode($domainName, true); | ||
} | ||
|
||
public function listDomains() { | ||
throw new \FOSSBilling\Exception("Not yet implemented"); | ||
} | ||
|
||
public function getDomain($domainName) { | ||
throw new \FOSSBilling\Exception("Not yet implemented"); | ||
} | ||
|
||
public function getResponsibleDomain($qname) { | ||
throw new \FOSSBilling\Exception("Not yet implemented"); | ||
} | ||
|
||
public function exportDomainAsZonefile($domainName) { | ||
throw new \FOSSBilling\Exception("Not yet implemented"); | ||
} | ||
|
||
public function deleteDomain($domainName) { | ||
if (empty($domainName)) { | ||
throw new \FOSSBilling\Exception("Domain name cannot be empty"); | ||
} | ||
|
||
return json_decode($domainName, true); | ||
} | ||
|
||
public function createRRset($domainName, $rrsetData) { | ||
if (empty($domainName)) { | ||
throw new \FOSSBilling\Exception("Domain name cannot be empty"); | ||
} | ||
|
||
return json_decode($domainName, true); | ||
} | ||
|
||
public function createBulkRRsets($domainName, $rrsetDataArray) { | ||
throw new \FOSSBilling\Exception("Not yet implemented"); | ||
} | ||
|
||
public function retrieveAllRRsets($domainName) { | ||
throw new \FOSSBilling\Exception("Not yet implemented"); | ||
} | ||
|
||
public function retrieveSpecificRRset($domainName, $subname, $type) { | ||
throw new \FOSSBilling\Exception("Not yet implemented"); | ||
} | ||
|
||
public function modifyRRset($domainName, $subname, $type, $rrsetData) { | ||
if (empty($domainName)) { | ||
throw new \FOSSBilling\Exception("Domain name cannot be empty"); | ||
} | ||
|
||
return json_decode($domainName, true); | ||
} | ||
|
||
public function modifyBulkRRsets($domainName, $rrsetDataArray) { | ||
throw new \FOSSBilling\Exception("Not yet implemented"); | ||
} | ||
|
||
public function deleteRRset($domainName, $subname, $type, $value) { | ||
if (empty($domainName)) { | ||
throw new \FOSSBilling\Exception("Domain name cannot be empty"); | ||
} | ||
|
||
return json_decode($domainName, true); | ||
} | ||
|
||
public function deleteBulkRRsets($domainName, $rrsetDataArray) { | ||
throw new \FOSSBilling\Exception("Not yet implemented"); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters