Skip to content

Commit

Permalink
Merge remote-tracking branch 'poweradmin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
tswestendorp committed Mar 11, 2016
2 parents 1d8383a + 2deded1 commit d082d38
Show file tree
Hide file tree
Showing 663 changed files with 39,698 additions and 708 deletions.
14 changes: 14 additions & 0 deletions add_record.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
require_once('inc/toolkit.inc.php');
include_once('inc/header.inc.php');

global $pdnssec_use;

/*
Get permissions
*/
Expand Down Expand Up @@ -141,6 +143,12 @@
log_info(sprintf('client_ip:%s user:%s operation:add_record record_type:PTR record:%s content:%s ttl:%s priority:%s',
$_SERVER['REMOTE_ADDR'], $_SESSION["userlogin"],
$content_rev, $fqdn_name, $ttl, $prio));
if ($pdnssec_use) {
if (dnssec_rectify_zone($zone_rev_id)) {
success(SUC_EXEC_PDNSSEC_RECTIFY_ZONE);
}
}

}
} elseif (isset($content_rev)) {
error(sprintf(ERR_REVERS_ZONE_NOT_EXIST, $content_rev));
Expand All @@ -151,6 +159,12 @@
log_info(sprintf('client_ip:%s user:%s operation:add_record record_type:%s record:%s.%s content:%s ttl:%s priority:%s',
$_SERVER['REMOTE_ADDR'], $_SESSION["userlogin"],
$type, $name, $zone_name, $content, $ttl, $prio));
if ($pdnssec_use) {
if (dnssec_rectify_zone($zone_id)) {
success(SUC_EXEC_PDNSSEC_RECTIFY_ZONE);
}
}

$name = $type = $content = $ttl = $prio = "";
}
}
Expand Down
4 changes: 2 additions & 2 deletions add_zone_slave.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,14 @@
error(ERR_DOMAIN_EXISTS);
} elseif (domain_exists($zone) || record_name_exists($zone)) {
error(ERR_DOMAIN_EXISTS);
} elseif (!is_valid_ipv4($master, false) && !is_valid_ipv6($master)) {
} elseif (!are_multipe_valid_ips($master)) {
error(ERR_DNS_IP);
} else {
if (add_domain($zone, $owner, $type, $master, 'none')) {
success("<a href=\"edit.php?id=" . get_zone_id_from_name($zone) . "\">" . SUC_ZONE_ADD . '</a>');
log_info(sprintf('client_ip:%s user:%s operation:add_zone zone:%s zone_type:SLAVE zone_master:%s',
$_SERVER['REMOTE_ADDR'], $_SESSION["userlogin"],
$zone, $master, $zone_template));
$zone, $master));
unset($zone, $owner, $webip, $mailip, $empty, $type, $master);
}
}
Expand Down
22 changes: 22 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"description": "A web-based control panel for PowerDNS.",
"name": "poweradmin/poweradmin",
"type": "project",
"homepage": "http://www.poweradmin.org",
"license": "GPL-3.0",
"support": {
"issues": "https://github.com/poweradmin/poweradmin/issues",
"wiki": "https://github.com/poweradmin/poweradmin/wiki",
"irc": "irc://irc.oftc.net/poweradmin",
"source": "https://github.com/poweradmin/poweradmin"
},
"require": {
"php": ">=5.5.0",
"twig/twig": "~1.0"
},
"autoload": {
"psr-4": {
"Poweradmin\\": "vendor/poweradmin/"
}
}
}
32 changes: 28 additions & 4 deletions dynamic_update.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
*/
require('inc/config.inc.php');
require('inc/database.inc.php');
require('inc/record.inc.php');

$db = dbConnect();

Expand All @@ -44,9 +45,11 @@
function safe($value) {
global $db, $db_type;

if ($db_type == 'mysql') {
if ($db_type == 'mysql' || $db_type == 'sqlite') {
$value = $db->quote($value, 'text');
$value = substr($value, 1, -1); // remove quotes
} elseif ($db_type == 'pgsql') {
$value = pg_escape_string($value);
} else {
return status_exit('baddbtype');
}
Expand Down Expand Up @@ -84,6 +87,24 @@ function status_exit($status) {
return false;
}

/** Check whether the given address is an IP address
*
* @param string $ip Given IP address
*
* @return string A if IPv4, AAAA if IPv6 or 0 if invalid
*/
function valid_ip_address( $ip )
{
if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
$value = 'A';
}elseif (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
$value = 'AAAA';
}else {
$value = 0;
}
return $value;
}

if (!(isset($_SERVER)) && !$_SERVER['HTTP_USER_AGENT']) {
return status_exit('badagent');
}
Expand Down Expand Up @@ -128,8 +149,10 @@ function status_exit($status) {
// Finally get save version of the IP
$ip = safe($given_ip);
// Check its ok...
if (!preg_match('/^((?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/i', $ip)) {
if (!valid_ip_address($ip)) {
return status_exit('dnserr');
}else {
$type = valid_ip_address($ip);
}

if (!strlen($hostname)) {
Expand Down Expand Up @@ -163,13 +186,14 @@ function status_exit($status) {
$was_updated = false;

while ($zone = $zones_result->fetchRow()) {
$name_query = "SELECT name FROM records WHERE domain_id='{$zone["domain_id"]}' and type = 'A'";
$name_query = "SELECT name FROM records WHERE domain_id='{$zone["domain_id"]}' and type = '$type'";
$result = $db->query($name_query);

while ($record = $result->fetchRow()) {
if ($hostname == $record['name']) {
$update_query = "UPDATE records SET content ='{$ip}' where name='{$record["name"]}' and type='A'";
$update_query = "UPDATE records SET content ='{$ip}' where name='{$record["name"]}' and type='$type'";
$update_result = $db->query($update_query);
update_soa_serial($zone['domain_id']);
$was_updated = true;
}
}
Expand Down
44 changes: 25 additions & 19 deletions edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
*/
require_once("inc/toolkit.inc.php");
include_once("inc/header.inc.php");
include_once("inc/RecordLog.class.php");

global $pdnssec_use;

Expand All @@ -48,28 +49,28 @@

if (isset($_POST['commit'])) {
$error = false;
$one_record_changed = false;

if (isset($_POST['record'])) {
foreach ($_POST['record'] as $record) {
$old_record_info = get_record_from_id($record['rid']);

// Check if a record changed and save the state
$log = new RecordLog();
$log->log_prior($record['rid']);
if (!$log->has_changed($record)) {
continue;
} else {
$one_record_changed = true;
}

$edit_record = edit_record($record);
if (false === $edit_record) {
$error = true;
} else {
$new_record_info = get_record_from_id($record["rid"]);
//Figure out if record was updated
unset($new_record_info["change_date"]);
unset($old_record_info["change_date"]);
if ($new_record_info != $old_record_info){
//The record was changed, so log the edit_record operation
log_info(sprintf('client_ip:%s user:%s operation:edit_record'
.' old_record_type:%s old_record:%s old_content:%s old_ttl:%s old_priority:%s'
.' record_type:%s record:%s content:%s ttl:%s priority:%s',
$_SERVER['REMOTE_ADDR'], $_SESSION["userlogin"],
$old_record_info['type'], $old_record_info['name'],
$old_record_info['content'], $old_record_info['ttl'], $old_record_info['prio'],
$new_record_info['type'], $new_record_info['name'],
$new_record_info['content'], $new_record_info['ttl'], $new_record_info['prio']));
}
// Log the state after saving and write it to logging table
$log->log_after($record['rid']);
$log->write();
}
}
}
Expand All @@ -78,7 +79,12 @@

if (false === $error) {
update_soa_serial($_GET['id']);
success(SUC_ZONE_UPD);

if ($one_record_changed) {
success(SUC_ZONE_UPD);
} else {
success(SUC_ZONE_NOCHANGE);
}

if ($pdnssec_use) {
if (dnssec_rectify_zone($_GET['id'])) {
Expand Down Expand Up @@ -226,10 +232,10 @@

if ($domain_type == "SLAVE" || $perm_content_edit == "none" || (($perm_content_edit == "own" || $perm_content_edit == "own_as_client") && $user_is_zone_owner == "0")) {
echo " <td class=\"n\">&nbsp;</td>\n";
}
elseif ( $r['type'] == "SOA" || ($r['type'] == "NS" && $perm_content_edit == "own_as_client")) {
}
elseif ($r['type'] == "SOA" && $perm_content_edit != "all" || ($r['type'] == "NS" && $perm_content_edit == "own_as_client")) {
echo " <td class=\"n\">&nbsp;</td>\n";
}
}
else {
echo " <td class=\"n\">\n";
echo " <a href=\"edit_record.php?id=" . $r['id'] . "&amp;domain=" . $zone_id . "\">
Expand Down
19 changes: 15 additions & 4 deletions inc/PDOLayer.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class PEAR {
* Overrided isError method
*/
public static function isError() {

}

}
Expand Down Expand Up @@ -137,7 +137,7 @@ public function query($str) {
* Dummy method
*/
public function disconnect() {

}

/**
Expand Down Expand Up @@ -222,9 +222,20 @@ public function createTable($name, $fields, $options = array()) {

$query = "CREATE TABLE $name (" . implode(', ', $query_fields) . ')';

if ($db_type == 'mysql' && isset($options['type'])) {
$query .= ' ENGINE=' . $options['type'];
if ($db_type == 'mysql') {
if (isset($options['type'])) {
$query .= ' ENGINE=' . $options['type'];
}

if (isset($options['charset'])) {
$query .= ' DEFAULT CHARSET=' . $options['charset'];
}

if (isset($options['collation'])) {
$query .= ' COLLATE=' . $options['collation'];
}
}

$this->exec($query);
}

Expand Down
64 changes: 64 additions & 0 deletions inc/RecordLog.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php

class RecordLog {

private $record_prior;
private $record_after;

private $record_changed = false;

public function log_prior($rid) {
$this->record_prior = $this->getRecord($rid);
}

public function log_after($rid) {
$this->record_after = $this->getRecord($rid);
}

private function getRecord($rid) {
return get_record_from_id($rid);
}

public function has_changed(array $record) {
// Arrays are assigned by copy.
// Copy arrays to avoid side effects caused by unset().
$record_copy = $record;
$record_prior_copy = $this->record_prior;

// Don't compare the 'change_date'
unset($record_copy["change_date"]);
unset($record_prior_copy["change_date"]);

// PowerDNS only searches for lowercase records
$record_copy['name'] = strtolower($record_copy['name']);
$record_prior_copy['name'] = strtolower($record_prior_copy['name']);

// Quotes are special for SPF and TXT
$type = $record_prior_copy['type'];
if ($type == "SPF" || $type == "TXT") {
$record_prior_copy['content'] = trim($record_prior_copy['content'], '"');
$record_copy['content'] = trim($record_copy['content'], '"');
}

// Make $record_copy and $record_prior_copy compatible
$record_copy['id'] = $record_copy['rid'];
$record_copy['domain_id'] = $record_copy['zid'];
unset($record_copy['zid']);
unset($record_copy['rid']);

// Do the comparison
$this->record_changed = ($record_copy != $record_prior_copy);
return $this->record_changed;
}

public function write() {
log_info(sprintf('client_ip:%s user:%s operation:edit_record'
. ' old_record_type:%s old_record:%s old_content:%s old_ttl:%s old_priority:%s'
. ' record_type:%s record:%s content:%s ttl:%s priority:%s',
$_SERVER['REMOTE_ADDR'], $_SESSION["userlogin"],
$this->record_prior['type'], $this->record_prior['name'],
$this->record_prior['content'], $this->record_prior['ttl'], $this->record_prior['prio'],
$this->record_after['type'], $this->record_after['name'],
$this->record_after['content'], $this->record_after['ttl'], $this->record_after['prio']));
}
}
8 changes: 5 additions & 3 deletions inc/config-me.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
* @copyright 2010-2014 Poweradmin Development Team
* @license http://opensource.org/licenses/GPL-3.0 GPL
*/
// NOTE: Do not edit this file, otherwise it's very likely your changes
// will be overwritten with an upgrade.
// NOTE: Do not edit this file, otherwise it's very likely your changes
// will be overwritten with an upgrade.
// Instead, create the file "inc/config.inc.php" and set the variables you
// want to set there. Your changes will override the defaults provided by us.
// Better description of available configuration settings you can find here:
Expand All @@ -21,14 +21,16 @@
$db_pass = '';
$db_name = '';
$db_type = '';
//$db_charset = 'latin1'; // or utf8
//$db_file = ''; # used only for SQLite, provide full path to database file
//$db_debug = false; # show all SQL queries
//$db_ssl_ca = '';

// Security settings
// This should be changed upon install
$session_key = 'p0w3r4dm1n';
$password_encryption = 'md5'; // or md5salt
$password_encryption = 'bcrypt'; // md5, md5salt or bcrypt
$password_encryption_cost = 12; // needed for bcrypt

// Interface settings
$iface_lang = 'en_EN';
Expand Down
10 changes: 10 additions & 0 deletions inc/database.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ function dbConnect() {
global $db_host;
global $db_port;
global $db_name;
global $db_charset;
global $db_file;
global $db_debug;
global $db_ssl_ca;
Expand Down Expand Up @@ -131,8 +132,17 @@ function dbConnect() {
$dsn = "$db_type:host=$db_host;port=$db_port;dbname=$db_name";
}

if ($db_type === 'mysql' && $db_charset === 'utf8') {
$dsn .= ';charset=utf8';
}

$db = new PDOLayer($dsn, $db_user, $db_pass);

// http://stackoverflow.com/a/4361485/567193
if ($db_type === 'mysql' && $db_charset === 'utf8' && version_compare(phpversion(), '5.3.6', '<')) {
$db->exec('set names utf8');
}

if (isset($db_debug) && $db_debug) {
$db->setOption('debug', 1);
}
Expand Down
Loading

0 comments on commit d082d38

Please sign in to comment.