Skip to content

Commit

Permalink
Add zonekeys object (#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
ShaneMcC committed Nov 8, 2018
1 parent e5c9619 commit 990718f
Show file tree
Hide file tree
Showing 5 changed files with 486 additions and 4 deletions.
28 changes: 28 additions & 0 deletions admin/init_functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,34 @@ public function run($pdo) {
MYSQLQUERY
);


// ------------------------------------------------------------------------
// Zone Keys
// ------------------------------------------------------------------------
$dataChanges[18] = new DBChange(<<<MYSQLQUERY
CREATE TABLE `zonekeys` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`key_id` int(11) NOT NULL,
`domain_id` int(11) NOT NULL,
`flags` int(11) NOT NULL,
`keyprivate` TEXT,
`keypublic` TEXT,
`created` int(11) NOT NULL,
`publish` int(11) NOT NULL,
`activate` int(11) NOT NULL,
`revoke` int(11),
`inactive` int(11),
`delete` int(11),
`syncPublish` int(11),
`syncDelete` int(11),
`comment` VARCHAR(250),
PRIMARY KEY (`id`),
CONSTRAINT `zonekeys_domain_id` FOREIGN KEY (`domain_id`) REFERENCES `domains` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
UNIQUE INDEX `zonekeys_keyid_domainid` (`domain_id` ASC, `key_id` ASC)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
MYSQLQUERY
);

return $dataChanges;
}
}
1 change: 1 addition & 0 deletions admin/seed.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
$pdo->exec('DROP TABLE twofactordevices;');
$pdo->exec('DROP TABLE domainkeys;');
$pdo->exec('DROP TABLE domainhooks;');
$pdo->exec('DROP TABLE zonekeys;');
$pdo->exec('DROP TABLE __MetaData;');
$pdo->exec('SET FOREIGN_KEY_CHECKS = 1;');
initDataServer(DB::get());
Expand Down
33 changes: 29 additions & 4 deletions classes/domain.php
Original file line number Diff line number Diff line change
Expand Up @@ -247,12 +247,20 @@ public function getSOARecord($fresh = FALSE) {
*
* @return Array of `Record` objects for DNSSEC public ksk data.
*/
public function getDSKeys() {
// TODO: Pull from Database.
$keys = getDSKeys($this->getDomainRaw());

public function getDSKeys($fromDB = false) {
$result = [];

$keys = $this->getZoneKeys(257);
if (!empty($keys)) {
foreach ($keys as $key) {
foreach ($key->getKeyPublicRecords() as $rec) {
$result[] = $rec;
}
}
}

// TODO: Remove legacy file support.
$keys = getDSKeys($this->getDomainRaw());
if ($keys !== FALSE) {
foreach ($keys as $key) {
if (!empty($key)) {
Expand All @@ -273,6 +281,23 @@ public function getDSKeys() {
return $result;
}

/**
* Get the ZoneKeys for this domain.
*
* @param $flags [Default: NULL] Limit to keys with the given flags value.
* @return Array of `ZoneKey` objects for DNSSEC public ksk data.
*/
public function getZoneKeys($flags = NULL) {
$searchParams = ['domain_id' => $this->getID()];
if ($flags !== NULL) { $searchParams['flags'] = $flags; }

$search = ZoneKey::getSearch($this->getDB());

$search = $search->order('created');
$result = $search->search($searchParams);
return ($result) ? $result : [];
}

/**
* Get the next serial number to use.
*
Expand Down
Loading

0 comments on commit 990718f

Please sign in to comment.