diff --git a/.htaccess b/.htaccess
index 8be8a63..c9e4147 100644
--- a/.htaccess
+++ b/.htaccess
@@ -1,9 +1,9 @@
RewriteEngine on
-RewriteCond %{REQUEST_FILENAME} (/(?:add|delete|update|ip))\.(xml|html|gif|txt|csv) [OR]
-RewriteCond %{REQUEST_FILENAME} (/admin/(?:cleanup|sync|parse))\.(xml|html|gif|txt|csv) [OR]
-RewriteCond %{REQUEST_FILENAME} (/admin/get)\.(xml|html|gif|txt|csv|png) [OR]
-RewriteCond %{REQUEST_FILENAME} (/admin/stats/types)\.(xml|html|gif|txt|csv|png)
+RewriteCond %{REQUEST_FILENAME} (/(?:add|delete|update|ip))\.(xml|html|gif|txt|csv|json) [OR]
+RewriteCond %{REQUEST_FILENAME} (/admin/(?:cleanup|sync|parse))\.(xml|html|gif|txt|csv|json) [OR]
+RewriteCond %{REQUEST_FILENAME} (/admin/get)\.(xml|html|gif|txt|csv|png|json) [OR]
+RewriteCond %{REQUEST_FILENAME} (/admin/stats/types)\.(xml|html|gif|txt|csv|png|json)
RewriteRule .* %1.php?format=%2 [QSA]
RewriteCond %{QUERY_STRING} !zone=(0l.de|d.eta.li)
diff --git a/add.php b/add.php
index 0ec8f1f..8409563 100755
--- a/add.php
+++ b/add.php
@@ -9,18 +9,18 @@ if (array_key_exists($_REQUEST['zone'], $config['sddns']['zones'])) {
$rdata = (empty($_REQUEST['rdata']) && $type = 'A') ? $_SERVER['REMOTE_ADDR'] : $_REQUEST['rdata'];
$host = (empty($_REQUEST['host'])) ? Host::unique($zone, $db) : new Host($_REQUEST['host'], $zone);
$pw = (empty($_REQUEST['pw'])) ? randomString(8) : $_REQUEST['pw'];
-
+
if (empty($_REQUEST['lifetime']) || !is_int($_REQUEST['lifetime'])) {
$lifetime = $config['sddns']['std']['lifetime'];
}
else {
$lifetime = (int) $_REQUEST['lifetime'];
}
-
+
if (($lifetime > $config['sddns']['max_lifetime'] && !isAuthentificated()) || $lifetime < 0) {
$output->add('invalid lifetime', 'error', $lifetime);
}
-
+
if ($host->isRegistred($db)) {
if ($type == 'URL') {
$output->add('host is already registred', 'error', $host);
@@ -30,8 +30,8 @@ if (array_key_exists($_REQUEST['zone'], $config['sddns']['zones'])) {
$host = new DBHost($host->isRegistred($db), $db);
$output->add('found existing host' ,'notice', $host);
-
- if (!$host->checkPassword($pw)) {
+
+ if (!$host->checkPassword($pw) && !isAuthentificated()) {
$output->add('not authentificated for host', 'error', $host);
$output->send();
die();
@@ -40,21 +40,21 @@ if (array_key_exists($_REQUEST['zone'], $config['sddns']['zones'])) {
else {
$host = $host->add($pw, $db); // returns new DBHost
$output->add('host added to db' ,'notice', $host);
-
+
if (empty($_REQUEST['pw']))
$output->add('generated password' ,'notice', $pw);
}
-
+
if ($type != 'URL') { // pseudo type to create url redirection
$ttl = (empty($_REQUEST['ttl'])) ? $config['sddns']['std']['ttl'] : (int) $_REQUEST['ttl'];
$class = (empty($_REQUEST['class'])) ? $config['sddns']['std']['class'] : $_REQUEST['class'];
-
+
$record = new Record($host, $ttl, $class, $type, $rdata);
-
+
if (!$record->isRegistred($db)) {
$record = $record->add($db, $lifetime);
$output->add('record added to db', 'success', $record);
-
+
$zone->cleanup($db);
$zone->sync($db);
}
diff --git a/admin/get.php b/admin/get.php
index 2ef18eb..8628826 100755
--- a/admin/get.php
+++ b/admin/get.php
@@ -4,28 +4,28 @@ require_once '../include/init.php';
$output = Output::start();
$dataTables = array(
- 'hosts' => null, // table name => date field
- 'records' => 'created',
- 'queries' => 'queried',
- 'logs' => 'logged',
- 'uris' => 'created'
- );
+ 'hosts' => null, // table name => date field
+ 'records' => 'created',
+ 'queries' => 'queried',
+ 'logs' => 'logged',
+ 'uris' => 'created'
+);
$perModes = array(
- 'hour' => false, // mySQL funtion => is timestamp
- 'day' => false,
- 'date' => true,
- 'week' => false,
- 'month' => false,
- 'weekday' => false
- );
+ 'hour' => false, // mySQL funtion => is timestamp
+ 'day' => false,
+ 'date' => true,
+ 'week' => false,
+ 'month' => false,
+ 'weekday' => false
+);
$colors = array(
- 'records' => 'blue',
- 'queries' => 'red',
- 'logs' => 'orange',
- 'uris' => 'black'
- );
+ 'records' => 'blue',
+ 'queries' => 'red',
+ 'logs' => 'orange',
+ 'uris' => 'black'
+);
$get = array();
if (isset($_REQUEST['data'])) {
@@ -37,11 +37,11 @@ if (isset($_REQUEST['data'])) {
$output->add('invalid data', 'error', $tmp);
$output->send();
die();
- }
+ }
}
}
else {
- $get = array('queries');
+ $get = array('records');
}
if ($output instanceof GraphOutput) {
@@ -64,7 +64,7 @@ if ($output instanceof GraphOutput) {
$graph = $output->getGraph(700, 300);
$graph->img->SetAntiAliasing();
-
+
if ($perModes[$per]) {
$graph->SetScale('datint');
$graph->xaxis->scale->SetTimeAlign(HOURADJ_1);
@@ -123,8 +123,8 @@ if ($output instanceof GraphOutput) {
array_walk($plotData['x'], function(&$value) { $value = strtotime($value); });
$plot = new LinePlot($plotData['y'], $plotData['x']);
- $plot->SetColor($colors[$table]);
- $plot->SetLegend($table);
+ $plot->SetColor($colors[$table]);
+ $plot->SetLegend($table);
$plot->SetLineWeight(2);
$graph->Add($plot);
@@ -138,51 +138,51 @@ else {
$filter = array();
if (array_key_exists($_REQUEST['zone'], $config['sddns']['zones'])) {
$filter['zone'] = $config['sddns']['zones'][$_REQUEST['zone']];
-
+
if (!empty($_REQUEST['host'])) {
$filter['host'] = $_REQUEST['host'];
}
}
-
+
$data = DBHost::get($db, $filter);
$dateField = null;
break;
-
+
case 'logs':
$data = $db->query('SELECT logged, id, program, message FROM logs ORDER BY logged DESC', 1000);
$dateField = 'logged';
break;
-
+
case 'queries':
$data = $db->query('SELECT queried, id, ip, port, hostname, class, type, options FROM queries ORDER BY queried DESC', 1000);
$dateField = 'queried';
break;
-
+
case 'uris':
$filter = array();
if (array_key_exists($_REQUEST['zone'], $config['sddns']['zones'])) {
$filter['zone'] = $config['sddns']['zones'][$_REQUEST['zone']];
-
+
if (!empty($_REQUEST['host'])) {
$filter['host'] = $_REQUEST['host'];
}
}
-
+
$data = DBUri::get($db, $filter);
$dateField = 'created';
break;
-
+
case 'records':
default:
$filter = array();
if (array_key_exists($_REQUEST['zone'], $config['sddns']['zones'])) {
$filter['zone'] = $config['sddns']['zones'][$_REQUEST['zone']];
-
+
if (!empty($_REQUEST['host'])) {
$filter['host'] = $_REQUEST['host'];
}
}
-
+
if (!empty($_REQUEST['class']) && in_array($_REQUEST['class'], $config['sddns']['classes']))
$filter['class'] = $_REQUEST['class'];
if (!empty($_REQUEST['ttl']))
@@ -192,22 +192,41 @@ else {
if (!empty($_REQUEST['rdata']) && Record::isRData($_REQUEST['rdata'], $filter['type']))
$filter['rdata'] = $_REQUEST['rdata'];
}
-
+
$data = DBRecord::get($db, $filter);
$dateField = 'created';
}
foreach ($data as $row) {
- switch (@$_REQUEST['data']) {
+ switch ($get[0]) {
case 'uris':
- $output->add('', 'data', $row->host, $row);
+ $params = 'host=' . $row->host->toPunycode() . '&zone=' . $row->host->zone->name . '&type=URL&rdata=' . $row->uri;
+ $actions = '';
+ $actions .= '
';
+
+ if ($output instanceof HtmlOutput) $output->add(get_class($row), 'data', $row->host, $row, $actions);
+ else $output->add(get_class($row), 'data', $row->host, $row);
break;
case 'hosts':
+ $params = 'host=' . $row->toPunycode() . '&zone=' . $row->zone->name;
+ $actions = '
';
+ $actions .= '
';
+
+ if ($output instanceof HtmlOutput) $output->add(get_class($row), 'data', $row, $actions);
+ else $output->add(get_class($row), 'data', $row);
+ break;
+ case 'records':
+ $params = 'host=' . $row->host->toPunycode() . '&zone=' . $row->host->zone->name . '&type=' . $row->type . '&class=' . $row->class . '&rdata=' . $row->rdata;
+ $actions = '
';
+ $actions .= '
';
+
+ if ($output instanceof HtmlOutput) $output->add(get_class($row), 'data', $row, $actions);
+ else $output->add(get_class($row), 'data', $row);
+ break;
case 'logs':
case 'queries':
- case 'records':
default:
- $output->add('', 'data', $row);
+ $output->add('data', 'data', $row);
}
}
}
diff --git a/delete.php b/delete.php
index 4e467ca..59f6a54 100755
--- a/delete.php
+++ b/delete.php
@@ -2,25 +2,24 @@
require_once 'include/init.php';
$output = Output::start();
-
$pw = @$_REQUEST['pw'];
if (array_key_exists($_REQUEST['zone'], $config['sddns']['zones'])) {
$zone = $config['sddns']['zones'][$_REQUEST['zone']];
-
+
if (!empty($_REQUEST['host'])) {
if ($host = reset(DBHost::get($db, array('host' => $_REQUEST['host'], 'zone' => $zone)))) {
if ($host->checkPassword($pw) || isAuthentificated()) {
if (isset($_REQUEST['class']) && in_array($_REQUEST['class'], $config['sddns']['classes']))
$class = $_REQUEST['class'];
-
+
if (isset($_REQUEST['type']) && in_array($_REQUEST['type'], $config['sddns']['types'])) {
$type = $_REQUEST['type'];
-
+
if (isset($_REQUEST['rdata']) && Record::isRData($_REQUEST['rdata'], $type))
$rdata = $_REQUEST['rdata'];
}
-
+
if (@$type == 'URL' || empty($type)) {
$uris = DBUri::get($db, array('zone' => $zone, 'host' => $host));
foreach ($uris as $uri) {
@@ -28,7 +27,7 @@ if (array_key_exists($_REQUEST['zone'], $config['sddns']['zones'])) {
$output->add('uri deleted from db', 'success', $uri);
}
}
-
+
if (@$type != 'URL' || empty($type)) {
$records = DBRecord::get($db, array('zone' => $zone, 'host' => $host, 'type' => @$type, 'class' => @$class, 'rdata' => @$rdata));
foreach ($records as $record) {
@@ -36,7 +35,7 @@ if (array_key_exists($_REQUEST['zone'], $config['sddns']['zones'])) {
$output->add('record deleted from db', 'success', $record);
}
}
-
+
$zone->cleanup($db);
$zone->sync($db);
}
diff --git a/expert.php b/expert.php
index c3b427d..c58508a 100755
--- a/expert.php
+++ b/expert.php
@@ -84,12 +84,13 @@ $checkedType = (isset($_REQUEST['type'])) ? $_REQUEST['type'] : $config['sddns']
simple mode - + admin - '; ?> usage - wiki - bookmarklet - diff --git a/images/delete.png b/images/delete.png new file mode 100644 index 0000000..08f2493 Binary files /dev/null and b/images/delete.png differ diff --git a/images/edit.png b/images/edit.png new file mode 100644 index 0000000..af486c9 Binary files /dev/null and b/images/edit.png differ diff --git a/include/db.php b/include/db.php index 768e220..95b9b03 100755 --- a/include/db.php +++ b/include/db.php @@ -64,15 +64,15 @@ abstract class DBResultSet implements Iterator { public function valid() { return (bool) is_array($this->current()); } - + public function first() { return (isset($this->_rows[0])) ? $this->_rows[0] : null; } - + public function last() { return $this->_rows[$this->_num_rows - 1]; } - + public function count() { return $this->_num_rows; } @@ -141,4 +141,4 @@ abstract class Database implements IDatabase { protected $statements = array(); } -?> \ No newline at end of file +?> diff --git a/include/functions.php b/include/functions.php index 5e39300..000118f 100755 --- a/include/functions.php +++ b/include/functions.php @@ -2,7 +2,7 @@ function isAuthentificated() { $config = Registry::get('config'); - $htpasswd = file('../.htpasswd'); + $htpasswd = file('/var/www/nulll/.htpasswd'); foreach ($htpasswd as $line) { list($user, $crypt) = explode(':', $line); diff --git a/include/host.php b/include/host.php index 57016dd..dac0386 100755 --- a/include/host.php +++ b/include/host.php @@ -2,16 +2,16 @@ class Host implements Object { private $punycode; - public $zone; + public $zone; public $generated; - + /* * Constructor & Factory */ public function __construct($hostname, Zone $zone, $generated = false) { $hostname = strtolower($hostname); if (self::isValid(idn_to_ascii($hostname))) { - $this->punycode = idn_to_ascii($hostname); + $this->punycode = idn_to_ascii($hostname); $this->zone = $zone; $this->generated = $generated; } @@ -22,7 +22,7 @@ class Host implements Object { throw new UserException('Invalid hostname: ' . idn_to_ascii($hostname)); } } - + public static function unique(Zone $zone, Database $db) { $config = Registry::get('config'); @@ -32,25 +32,25 @@ class Host implements Object { generated = TRUE && zone = \'' . $db->escape($zone->name) . '\' ORDER BY id DESC'; - + $result = $db->query($sql, 1); $first = $result->first(); $last_id = base_convert($first['hostname'], 36, 10); while ($result->count() > 0 || !Host::isValid(base_convert($last_id, 10, 36))) { - + $sql = 'SELECT hostname FROM ' . $config['db']['tbl']['hosts'] . ' WHERE hostname = \'' . base_convert(++$last_id, 10, 36) . '\' && zone = \'' . $db->escape($zone->name) . '\''; - + $result = $db->query($sql, 1); } return new self(base_convert($last_id, 10, 36), $zone, true); } - + /* * Checks */ @@ -58,7 +58,7 @@ class Host implements Object { $hostExpr = '[a-z0-9](?:[a-z0-9\-]*[a-z0-9])?'; return preg_match('/^(?:\*|(\*\.)?(' . $hostExpr . '\.)*(' . $hostExpr . '))$/i', $hostname); } - + public function isRegistred(Database $db) { $config = Registry::get('config'); @@ -71,7 +71,7 @@ class Host implements Object { return ($result->count() > 0) ? $host['id'] : false; } - + /* * Database */ @@ -86,35 +86,35 @@ class Host implements Object { ' . (int) $this->generated . ')'; $db->execute($sql); - + return new DBHost($db->lastId(), $db); } - + /* * Output */ public function toUnicode() { return idn_to_utf8($this->punycode); } - + public function toPunycode() { return $this->punycode; } - + public function __toString() { return $this->toPunycode() . '.' . $this->zone->name; } - + public function toXml(DOMDocument $doc) { $xmlHost = $doc->createElement('host'); $xmlHost->appendChild($doc->createElement('hostname', $this->toPunycode())); $xmlHost->appendChild($doc->createElement('idn', $this->toUnicode())); $xmlHost->appendChild($this->zone->toXml($doc)); - + return $xmlHost; } - + public function toHtml() { return '' . $this->toUnicode() . '.' . $this->zone->name . ''; } diff --git a/include/mysql.php b/include/mysql.php index 93c573f..71e3abd 100755 --- a/include/mysql.php +++ b/include/mysql.php @@ -42,11 +42,11 @@ class MySql extends Database { $this->connect($host, $user, $pw); $this->select($db); } - + function __destruct() { $this->close(); } - + /** * @brief create database connection * @param string $host IP or domain of the database host @@ -60,7 +60,7 @@ class MySql extends Database { error_reporting($__er); throw new MySqlException(); } - + error_reporting($__er); } @@ -90,6 +90,8 @@ class MySql extends Database { * @return mixed */ public function execute($sql) { + if ($output = Registry::get('output')) $output->add('db query', 'debug', 8, $sql); + if (!($result = mysql_unbuffered_query($sql, $this->resource))) throw new MySqlException(); return $result; @@ -107,7 +109,7 @@ class MySql extends Database { $sql .= sprintf(' LIMIT %d, %d', $offset, $limit); return new MySqlResult($this->execute($sql)); } - + /** * @brief mysql escape * @param string $sql query @@ -115,11 +117,11 @@ class MySql extends Database { public function escape($sql) { return mysql_real_escape_string($sql, $this->resource); } - + public function lastId() { return mysql_insert_id($this->resource); } - + public function affectedRows() { return mysql_affected_rows($this->resource); } diff --git a/include/output.php b/include/output.php index be42a5a..b5ade11 100755 --- a/include/output.php +++ b/include/output.php @@ -1,5 +1,21 @@ getMessages()); + + $json = array(); + + foreach ($this->getMessages() as $index => $message) { + + } + } +} + class XmlOutput extends Output { public function __construct($debug) { parent::__construct('text/xml', 'UTF-8', $debug); @@ -327,6 +343,9 @@ abstract class Output { return new GifOutput(); break; + case 'json': + return new JsonOutput($debug); + case 'html': case 'php': default: @@ -339,7 +358,7 @@ abstract class Output { global $argc; $site = Registry::get('site'); - + if (isset($forced)) $format = $forced; elseif (isset($argc)) diff --git a/include/zone.php b/include/zone.php index 8706b2c..32bd7d9 100755 --- a/include/zone.php +++ b/include/zone.php @@ -2,7 +2,7 @@ class Zone extends NameServer implements Object { public $name; - public $key; + private $key; function __construct($nserver, $name, $key, $nsport = 53) { parent::__construct($nserver, $nsport); @@ -42,7 +42,7 @@ class Zone extends NameServer implements Object { LEFT JOIN ' . $config['db']['tbl']['hosts'] . ' AS h ON h.id = u.host_id WHERE - ((u.last_accessed + INTERVAL u.lifetime SECOND) < NOW()&& + ((u.last_accessed + INTERVAL u.lifetime SECOND) < NOW() && h.zone = \'' . $db->escape($this->name) . '\') || h.id IS NULL'; $db->execute($sql); diff --git a/update.php b/update.php index 1f0879a..52f0ce7 100755 --- a/update.php +++ b/update.php @@ -68,12 +68,12 @@ if (!empty($zone)) { $records[0]->lastAccessed = time(); $records[0]->update(); $output->add('record updated in db', 'success', $records[0]); - + for ($i = 1; $i < count($records); $i++) { $records[$i]->delete(); $output->add('record deleted from db', 'warning', $records[$i]); } - + $zone->cleanup($db); $zone->sync($db); }