<?php /** * Script to edit domain ***************************/ /* functions */ require dirname(__FILE__) . '/../../../functions/functions.php'; # initialize user object $Database = new Database_PDO(); $User = new User($Database); $Admin = new Admin($Database); $Result = new Result(); $PowerDNS = new PowerDNS($Database); # verify that user is logged in $User->check_user_session(); # fetch old record if ($_POST['action'] != "add") { $record = $PowerDNS->fetch_record($_POST['id']); $record !== false ?: $Result->show("danger", _("Invalid ID"), true, true); } # edit and add - check that smth is in name and content! if ($_POST['action'] != "delete") { if (strlen($_POST['name']) < 2) { $Result->show("danger", _("Invalid name"), true); } if (strlen($_POST['content']) < 2) { $Result->show("danger", _("Invalid content"), true); } } # validate and set values if ($_POST['action'] == "edit") {
<?php /** * Script to display IP address info and history ***********************************************/ # verify that user is logged in $User->check_user_session(); # powerdns class $PowerDNS = new PowerDNS($Database); # checks if (!is_numeric($_GET['subnetId'])) { $Result->show("danger", _("Invalid ID"), true); } if (!is_numeric($_GET['section'])) { $Result->show("danger", _("Invalid ID"), true); } if (!is_numeric($_GET['ipaddrid'])) { $Result->show("danger", _("Invalid ID"), true); } # get IP a nd subnet details $address = (array) $Addresses->fetch_address(null, $_GET['ipaddrid']); $subnet = (array) $Subnets->fetch_subnet(null, $address['subnetId']); # fetch all custom fields $custom_fields = $Tools->fetch_custom_fields('ipaddresses'); # set hidden custom fields $hidden_cfields = json_decode($User->settings->hiddenCustomFields, true); $hidden_cfields = is_array($hidden_cfields['ipaddresses']) ? $hidden_cfields['ipaddresses'] : array(); # set selected address fields array $selected_ip_fields = $User->settings->IPfilter; $selected_ip_fields = explode(";", $selected_ip_fields); //format to array
$values['discoverSubnet'] = $Admin->verify_checkbox(@$_POST['discoverSubnet']); } if (isset($_POST['pingSubnet'])) { $values['pingSubnet'] = $Admin->verify_checkbox(@$_POST['pingSubnet']); } # propagate changes if (sizeof($Subnets->slaves) > 0) { foreach ($Subnets->slaves as $slaveId) { $Admin->object_modify("subnets", "edit", "id", array_merge(array("id" => $slaveId), $values)); } } } # powerDNS if ($User->settings->enablePowerDNS == 1) { # powerDNS class $PowerDNS = new PowerDNS($Database); if ($PowerDNS->db_check() === false) { $Result->show("danger", _("Cannot connect to powerDNS database"), true); } // set zone $zone = $_POST['action'] == "add" ? $PowerDNS->get_ptr_zone_name($_POST['subnet'], $_POST['mask']) : $PowerDNS->get_ptr_zone_name($subnet_old_details['ip'], $subnet_old_details['mask']); // try to fetch domain $domain = $PowerDNS->fetch_domain_by_name($zone); // POST DNSrecursive not set, fake it if old is also 0 if (!isset($_POST['DNSrecursive']) && @$subnet_old_details['DNSrecursive'] == 0) { $_POST['DNSrecursive'] = 0; } //delete if ($_POST['action'] == "delete") { // if zone exists if ($domain !== false) {
$hStatus = "hidden"; $hTooltip = ""; } // gateway $gw = $addresses[$n]->is_gateway == 1 ? "gateway" : ""; print "\t<td class='ipaddress {$gw}'><span class='status status-{$hStatus}' {$hTooltip}></span><a href='" . create_link("subnets", $subnet['sectionId'], $_REQUEST['subnetId'], "address-details", $addresses[$n]->id) . "'>" . $Subnets->transform_to_dotted($addresses[$n]->ip_addr); if ($addresses[$n]->is_gateway == 1) { print " <i class='fa fa-info-circle fa-gateway' rel='tooltip' title='" . _('Address is marked as gateway') . "'></i>"; } print $Addresses->address_type_format_tag($addresses[$n]->state); print "</td>"; # search for DNS records if ($User->settings->enablePowerDNS == 1 && $subnet['DNSrecords'] == 1) { # for ajax-loaded subnets if (!isset($PowerDNS)) { $PowerDNS = new PowerDNS($Database); } $records = $PowerDNS->search_records("name", $addresses[$n]->dns_name, 'name', true); $ptr = $PowerDNS->fetch_record($addresses[$n]->PTR); unset($dns_records); if ($records !== false || $ptr !== false) { $dns_records[] = "<hr>"; $dns_records[] = "<ul class='submenu-dns'>"; if ($records !== false) { foreach ($records as $r) { if ($r->type != "SOA" && $r->type != "NS") { $dns_records[] = "<li><i class='icon-gray fa fa-gray fa-angle-right'></i> <span class='badge badge1 badge2 editRecord' data-action='edit' data-id='{$r->id}' data-domain_id='{$r->domain_id}'>{$r->type}</span> {$r->content} </li>"; } } } if ($ptr !== false) {
<?php /** * Script to edit domain ***************************/ /* functions */ require dirname(__FILE__) . '/../../../functions/functions.php'; # initialize user object $Database = new Database_PDO(); $User = new User($Database); $Admin = new Admin($Database); $Result = new Result(); $PowerDNS = new PowerDNS($Database); # verify that user is logged in $User->check_user_session(); # strip input tags $_POST = $Admin->strip_input_tags($_POST); # validate csrf cookie $User->csrf_cookie("validate", "domain", $_POST['csrf_cookie']) === false ? $Result->show("danger", _("Invalid CSRF cookie"), true) : ""; # checks / validation if ($_POST['action'] != "delete") { // fqdn if ($_POST['action'] == "add") { if ($Result->validate_hostname($_POST['name']) === false) { $Result->show("danger", "Invalid domain name", true); } } // master if (strlen($_POST['master']) > 0) { // if multilpe masters if (strpos($_POST['master'], ",") !== false) {
<div class="powerDNS"> <!-- display existing groups --> <h4><?php print _('PowerDNS management'); ?> </h4> <hr><br> <?php if ($User->settings->enablePowerDNS == 1) { ?> <?php # powerDNS class $PowerDNS = new PowerDNS($Database); // check connection $test = $PowerDNS->db_check(); // save settings for powerDNS default $pdns = $PowerDNS->db_settings; // check if TTL is set if ($test !== false) { $test_ttl = json_decode($User->settings->powerDNS); if ($test_ttl->ttl == NULL) { $Result->show("warning", "Please set <a href='" . create_link("administration", "powerDNS", "defaults") . "'>default powerDNS values</a>!", false); } } ?> <!-- tabs --> <ul class="nav nav-tabs"> <?php
print "<tr>"; print "\t<th>" . _('Discover new hosts') . "</th>"; if ($subnet['discoverSubnet'] == 1) { print "\t<td>" . _('enabled') . "</td>"; } else { print "\t<td class='info2'>" . _('disabled') . "</td>"; } # no print "</tr>"; } # autocreate PTR records if ($User->settings->enablePowerDNS == 1) { // initialize class if ($subnet['DNSrecursive'] == 1 || $subnet['DNSrecords'] == 1) { # powerDNS class $PowerDNS = new PowerDNS($Database); } if ($subnet['DNSrecursive'] == 1) { if ($PowerDNS->db_check() !== false) { // set name $zone = $PowerDNS->get_ptr_zone_name($subnet['ip'], $subnet['mask']); // fetch domain $domain = $PowerDNS->fetch_domain_by_name($zone); // count PTR records if ($domain !== false) { if ($User->is_admin()) { $btns[] = "<div class='btn-group'>"; $btns[] = " <a class='btn btn-default btn-xs' href='" . create_link("administration", "powerDNS", "domains", "records", $domain->name) . "'><i class='fa fa-eye'></i></a>"; $btns[] = "\t<a class='btn btn-default btn-xs refreshPTRsubnet' data-subnetid='{$subnet['id']}'><i class='fa fa-refresh'></i></a>"; $btns[] = "</div>"; $btns = implode("\n", $btns);
<?php /** * Edit powerDNS domain ************************************************/ /* functions */ require dirname(__FILE__) . '/../../../functions/functions.php'; # initialize user object $Database = new Database_PDO(); $User = new User($Database); $Admin = new Admin($Database); $Tools = new Tools($Database); $Result = new Result(); $PowerDNS = new PowerDNS($Database); # verify that user is logged in $User->check_user_session(); # create csrf token $csrf = $User->create_csrf_cookie(); # save settings for powerDNS default $pdns = $PowerDNS->db_settings; # get VRF if ($_POST['action'] != "add") { $domain = $PowerDNS->fetch_domain($_POST['id']); $domain !== false ?: $Result->show("danger", _("Invalid ID"), true, true); } # disable edit on delete $readonly = $_POST['action'] == "delete" ? "readonly" : ""; ?> <!-- header -->
<?php /** * Edit powerDNS record ************************************************/ /* functions */ require dirname(__FILE__) . '/../../../functions/functions.php'; # initialize user object $Database = new Database_PDO(); $User = new User($Database); $Admin = new Admin($Database); $Tools = new Tools($Database); $Result = new Result(); $PowerDNS = new PowerDNS($Database); # verify that user is logged in $User->check_user_session(); // save settings for powerDNS default $pdns = $PowerDNS->db_settings; // default post $post = $_POST; # get record if ($_POST['action'] != "add") { $record = $PowerDNS->fetch_record($_POST['id']); $record !== false ?: $Result->show("danger", _("Invalid ID"), true, true); } else { // from IP table // we provide record hostname and strip domain from it if (!is_numeric($_POST['domain_id']) && !is_numeric($_POST['id'])) { // fetch all domains foreach ($PowerDNS->fetch_all_domains() as $domain_s) { if (strpos($_POST['domain_id'], $domain_s->name) !== false) {
<?php /** * Edit powerDNS record ************************************************/ /* functions */ require dirname(__FILE__) . '/../../../functions/functions.php'; # initialize user object $Database = new Database_PDO(); $User = new User($Database); $Admin = new Admin($Database, false); $Tools = new Tools($Database); $Result = new Result(); $PowerDNS = new PowerDNS($Database); # verify that user is logged in $User->check_user_session(); # create csrf token $csrf = $User->csrf_cookie("create", "record"); # save settings for powerDNS default $pdns = $PowerDNS->db_settings; # default post $post = $_POST; # get record if ($_POST['action'] != "add") { $record = $PowerDNS->fetch_record($_POST['id']); $record !== false ?: $Result->show("danger", _("Invalid ID"), true, true); } else { // from IP table // we provide record hostname and strip domain from it if (!is_numeric($_POST['domain_id']) && !is_numeric($_POST['id'])) { // fetch all domains
<?php /** * * This script refreshes PTR records for subnet * */ /* functions */ require dirname(__FILE__) . '/../../../functions/functions.php'; # initialize user object $Database = new Database_PDO(); $User = new User($Database); $Result = new Result(); $Subnets = new Subnets($Database); $Addresses = new Addresses($Database); $PowerDNS = new PowerDNS($Database); # verify that user is logged in $User->check_user_session(); # fetch subnet $subnet = $Subnets->fetch_subnet("id", $_POST['subnetId']); # checks if ($subnet === false) { $Result->show("danger", _("Invalid subnet"), true); } if ($subnet->DNSrecursive != 1) { $Result->show("danger", _("Automatic PTR creation for this subnet is disabled"), true); } if ($User->settings->enablePowerDNS != 1) { $Result->show("danger", _("PowerDNS not enabled"), true); } // set zone
//we can exclude individual IP addresses from PTR creation if (@$address['PTRignore'] == "1") { $checked = "checked='checked'"; } else { $checked = ""; } print '<tr>'; print '<td>' . _("PTR exclude") . '</td>'; print '<td>'; print ' <input type="checkbox" class="ip_addr input-switch" name="PTRignore" value="1" ' . $checked . ' ' . $delete . '> <span class="text-muted">' . _('Dont create PTR records') . '</span>'; print '</td>'; print '</tr>'; //remove all associated queries if delete if ($_POST['action'] == "delete") { // check $PowerDNS = new PowerDNS($Database); $records = $PowerDNS->search_records("name", $address['dns_name'], 'name', true); $records2 = $PowerDNS->search_records("content", $address['ip'], 'content', true); if ($records !== false || $records2 !== false) { // form print '<tr>'; print '<td>' . _("Remove DNS records") . '</td>'; print '<td>'; print ' <input type="checkbox" class="ip_addr input-switch-danger alert-danger" data-on-color="danger" name="remove_all_dns_records" value="1" checked> <span class="text-muted">' . _('Remove all associated DNS records:') . '</span>'; print '</td>'; print '</tr>'; // records print '<tr>'; print '<td></td>'; print '<td>'; print "<hr>";
$values->username = $_POST['username']; $values->password = $_POST['password']; $values->port = $_POST['port']; $values->autoserial = isset($_POST['autoserial']) ? "Yes" : "No"; // get old settings for defaults $old_values = json_decode($User->settings->powerDNS); $values->ns = $old_values->ns; $values->hostmaster = $old_values->hostmaster; $values->def_ptr_domain = $old_values->def_ptr_domain; $values->refresh = $old_values->refresh; $values->retry = $old_values->retry; $values->expire = $old_values->expire; $values->nxdomain_ttl = $old_values->nxdomain_ttl; $values->ttl = $old_values->ttl; # set update values $values_new = array("id" => 1, "powerDNS" => json_encode($values)); if (!$Admin->object_modify("settings", "edit", "id", $values_new)) { $Result->show("danger", _("Cannot update settings"), false); } else { $Result->show("success", _("Settings updated successfully"), false); } # autoserial change - set default SOA for all records ! if ($values->autoserial !== @$old_values->autoserial) { // start class $PowerDNS = new PowerDNS($Database); // check connection if ($PowerDNS->db_check() !== false) { // update all serials $PowerDNS->update_all_soa_serials($values->autoserial); } }
} elseif ($addresses[$n]->lastSeen == "1970-01-01 00:00:01") { $hStatus = "neutral"; $hTooltip = "rel='tooltip' data-container='body' data-html='true' data-placement='left' title='" . _("Address is offline") . "<hr>" . _("Last seen") . ": " . _("Never") . "'"; } else { $hStatus = "neutral"; $hTooltip = "rel='tooltip' data-container='body' data-html='true' data-placement='left' title='" . _("Address status unknown") . "'"; } } else { $hStatus = "hidden"; $hTooltip = ""; } # search for DNS records if ($User->settings->enablePowerDNS == 1 && $subnet['DNSrecords'] == 1) { # for ajax-loaded subnets if (!isset($PowerDNS)) { $PowerDNS = new PowerDNS($Database); } // search for hostname records $records = $PowerDNS->search_records("name", $addresses[$n]->dns_name, 'name', true); $ptr = $PowerDNS->fetch_record($addresses[$n]->PTR); $ptr_name = $PowerDNS->get_ip_ptr_name(long2ip($addresses[$n]->ip_addr)); if (!$ptr || $ptr_name != $ptr->name) { $ptr = $PowerDNS->search_records("name", $ptr_name); if ($ptr) { $ptr = array_pop($ptr); $Addresses->ptr_link($addresses[$n]->id, $ptr->id); } else { $Addresses->ptr_link($addresses[$n]->id, 0); } } unset($dns_records);
$subnet = $Subnets->fetch_subnet(null, $_POST['subnetId']); # verify that user has write permissions for subnet $subnetPerm = $Subnets->check_permission($User->user, $subnet->id); if ($subnetPerm < 3) { $Result->show("danger", _('You do not have permissions to resize subnet') . '!', true, true); } # truncate network if (!$Subnets->subnet_truncate($subnet->id)) { $Result->show("danger", _("Failed to truncate subnet"), false); } else { $Result->show("success", _("Subnet truncated succesfully") . "!", false); } # check for DNS PTR records if ($User->settings->enablePowerDNS == "1" && $subnet->DNSrecursive == "1") { # powerDNS class $PowerDNS = new PowerDNS($Database); if ($PowerDNS->db_check() !== false) { // set name $zone = $PowerDNS->get_ptr_zone_name($subnet->ip, $subnet->mask); // fetch domain $domain = $PowerDNS->fetch_domain_by_name($zone); // if it exist remove all PTR records if ($domain !== false) { // remove existing records and links $PowerDNS->remove_all_ptr_records($domain->id); // ok $Result->show("success", "PTR records removed", false); } } else { $Result->show("danger", "Cannot connect to powerDNS database", false); }
// only in accordance with the terms of such license and with the // inclusion of the above copyright notice. This software or any other // copies thereof may not be provided or otherwise made available to any // other person. No title to and ownership of the software is hereby // transferred. // // You may not reverse engineer, decompile, defeat license encryption // mechanisms, or disassemble this software product or software product // license. CyanDark may terminate this license if you don't comply with // any of the terms and conditions set forth in our end user license // agreement (EULA). In such event, licensee agrees to return licensor // or destroy all copies of software upon termination of the license include 'config.php'; include 'PowerDNS.php'; header('Content-Type: text/plain'); $PowerDNS = new PowerDNS($db['host'], $db['user'], $db['pass'], $db['name'], $db['port']); $output = json_encode(array("status" => "error", "msg" => "Unauthorized")); // Verifiy API Key if ($_GET['key'] == $api['key']) { // Default Output $output = json_encode(array("status" => "error", "msg" => "Action not defined.")); // Add Domain if ($_GET['action'] == 'add_domain') { if (!empty($_GET['domain'])) { if ($PowerDNS->isValidDomain($_GET['domain']) && count(explode(".", $_GET['domain'])) > 1) { $response = $PowerDNS->addDomain($_GET['domain'], $_GET['solusvm_cid']); $output = json_encode($response); } else { $output = json_encode(array("status" => "error", "msg" => "Invalid Domain.")); } } else {