improved usability and coding style
This commit is contained in:
parent
1bf7aa8b7a
commit
30ab353a10
14 changed files with 133 additions and 93 deletions
|
@ -1,9 +1,9 @@
|
||||||
RewriteEngine on
|
RewriteEngine on
|
||||||
|
|
||||||
RewriteCond %{REQUEST_FILENAME} (/(?:add|delete|update|ip))\.(xml|html|gif|txt|csv) [OR]
|
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) [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) [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)
|
RewriteCond %{REQUEST_FILENAME} (/admin/stats/types)\.(xml|html|gif|txt|csv|png|json)
|
||||||
RewriteRule .* %1.php?format=%2 [QSA]
|
RewriteRule .* %1.php?format=%2 [QSA]
|
||||||
|
|
||||||
RewriteCond %{QUERY_STRING} !zone=(0l.de|d.eta.li)
|
RewriteCond %{QUERY_STRING} !zone=(0l.de|d.eta.li)
|
||||||
|
|
20
add.php
20
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'];
|
$rdata = (empty($_REQUEST['rdata']) && $type = 'A') ? $_SERVER['REMOTE_ADDR'] : $_REQUEST['rdata'];
|
||||||
$host = (empty($_REQUEST['host'])) ? Host::unique($zone, $db) : new Host($_REQUEST['host'], $zone);
|
$host = (empty($_REQUEST['host'])) ? Host::unique($zone, $db) : new Host($_REQUEST['host'], $zone);
|
||||||
$pw = (empty($_REQUEST['pw'])) ? randomString(8) : $_REQUEST['pw'];
|
$pw = (empty($_REQUEST['pw'])) ? randomString(8) : $_REQUEST['pw'];
|
||||||
|
|
||||||
if (empty($_REQUEST['lifetime']) || !is_int($_REQUEST['lifetime'])) {
|
if (empty($_REQUEST['lifetime']) || !is_int($_REQUEST['lifetime'])) {
|
||||||
$lifetime = $config['sddns']['std']['lifetime'];
|
$lifetime = $config['sddns']['std']['lifetime'];
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$lifetime = (int) $_REQUEST['lifetime'];
|
$lifetime = (int) $_REQUEST['lifetime'];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (($lifetime > $config['sddns']['max_lifetime'] && !isAuthentificated()) || $lifetime < 0) {
|
if (($lifetime > $config['sddns']['max_lifetime'] && !isAuthentificated()) || $lifetime < 0) {
|
||||||
$output->add('invalid lifetime', 'error', $lifetime);
|
$output->add('invalid lifetime', 'error', $lifetime);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($host->isRegistred($db)) {
|
if ($host->isRegistred($db)) {
|
||||||
if ($type == 'URL') {
|
if ($type == 'URL') {
|
||||||
$output->add('host is already registred', 'error', $host);
|
$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);
|
$host = new DBHost($host->isRegistred($db), $db);
|
||||||
$output->add('found existing host' ,'notice', $host);
|
$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->add('not authentificated for host', 'error', $host);
|
||||||
$output->send();
|
$output->send();
|
||||||
die();
|
die();
|
||||||
|
@ -40,21 +40,21 @@ if (array_key_exists($_REQUEST['zone'], $config['sddns']['zones'])) {
|
||||||
else {
|
else {
|
||||||
$host = $host->add($pw, $db); // returns new DBHost
|
$host = $host->add($pw, $db); // returns new DBHost
|
||||||
$output->add('host added to db' ,'notice', $host);
|
$output->add('host added to db' ,'notice', $host);
|
||||||
|
|
||||||
if (empty($_REQUEST['pw']))
|
if (empty($_REQUEST['pw']))
|
||||||
$output->add('generated password' ,'notice', $pw);
|
$output->add('generated password' ,'notice', $pw);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($type != 'URL') { // pseudo type to create url redirection
|
if ($type != 'URL') { // pseudo type to create url redirection
|
||||||
$ttl = (empty($_REQUEST['ttl'])) ? $config['sddns']['std']['ttl'] : (int) $_REQUEST['ttl'];
|
$ttl = (empty($_REQUEST['ttl'])) ? $config['sddns']['std']['ttl'] : (int) $_REQUEST['ttl'];
|
||||||
$class = (empty($_REQUEST['class'])) ? $config['sddns']['std']['class'] : $_REQUEST['class'];
|
$class = (empty($_REQUEST['class'])) ? $config['sddns']['std']['class'] : $_REQUEST['class'];
|
||||||
|
|
||||||
$record = new Record($host, $ttl, $class, $type, $rdata);
|
$record = new Record($host, $ttl, $class, $type, $rdata);
|
||||||
|
|
||||||
if (!$record->isRegistred($db)) {
|
if (!$record->isRegistred($db)) {
|
||||||
$record = $record->add($db, $lifetime);
|
$record = $record->add($db, $lifetime);
|
||||||
$output->add('record added to db', 'success', $record);
|
$output->add('record added to db', 'success', $record);
|
||||||
|
|
||||||
$zone->cleanup($db);
|
$zone->cleanup($db);
|
||||||
$zone->sync($db);
|
$zone->sync($db);
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,28 +4,28 @@ require_once '../include/init.php';
|
||||||
$output = Output::start();
|
$output = Output::start();
|
||||||
|
|
||||||
$dataTables = array(
|
$dataTables = array(
|
||||||
'hosts' => null, // table name => date field
|
'hosts' => null, // table name => date field
|
||||||
'records' => 'created',
|
'records' => 'created',
|
||||||
'queries' => 'queried',
|
'queries' => 'queried',
|
||||||
'logs' => 'logged',
|
'logs' => 'logged',
|
||||||
'uris' => 'created'
|
'uris' => 'created'
|
||||||
);
|
);
|
||||||
|
|
||||||
$perModes = array(
|
$perModes = array(
|
||||||
'hour' => false, // mySQL funtion => is timestamp
|
'hour' => false, // mySQL funtion => is timestamp
|
||||||
'day' => false,
|
'day' => false,
|
||||||
'date' => true,
|
'date' => true,
|
||||||
'week' => false,
|
'week' => false,
|
||||||
'month' => false,
|
'month' => false,
|
||||||
'weekday' => false
|
'weekday' => false
|
||||||
);
|
);
|
||||||
|
|
||||||
$colors = array(
|
$colors = array(
|
||||||
'records' => 'blue',
|
'records' => 'blue',
|
||||||
'queries' => 'red',
|
'queries' => 'red',
|
||||||
'logs' => 'orange',
|
'logs' => 'orange',
|
||||||
'uris' => 'black'
|
'uris' => 'black'
|
||||||
);
|
);
|
||||||
|
|
||||||
$get = array();
|
$get = array();
|
||||||
if (isset($_REQUEST['data'])) {
|
if (isset($_REQUEST['data'])) {
|
||||||
|
@ -37,11 +37,11 @@ if (isset($_REQUEST['data'])) {
|
||||||
$output->add('invalid data', 'error', $tmp);
|
$output->add('invalid data', 'error', $tmp);
|
||||||
$output->send();
|
$output->send();
|
||||||
die();
|
die();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$get = array('queries');
|
$get = array('records');
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($output instanceof GraphOutput) {
|
if ($output instanceof GraphOutput) {
|
||||||
|
@ -64,7 +64,7 @@ if ($output instanceof GraphOutput) {
|
||||||
|
|
||||||
$graph = $output->getGraph(700, 300);
|
$graph = $output->getGraph(700, 300);
|
||||||
$graph->img->SetAntiAliasing();
|
$graph->img->SetAntiAliasing();
|
||||||
|
|
||||||
if ($perModes[$per]) {
|
if ($perModes[$per]) {
|
||||||
$graph->SetScale('datint');
|
$graph->SetScale('datint');
|
||||||
$graph->xaxis->scale->SetTimeAlign(HOURADJ_1);
|
$graph->xaxis->scale->SetTimeAlign(HOURADJ_1);
|
||||||
|
@ -123,8 +123,8 @@ if ($output instanceof GraphOutput) {
|
||||||
array_walk($plotData['x'], function(&$value) { $value = strtotime($value); });
|
array_walk($plotData['x'], function(&$value) { $value = strtotime($value); });
|
||||||
|
|
||||||
$plot = new LinePlot($plotData['y'], $plotData['x']);
|
$plot = new LinePlot($plotData['y'], $plotData['x']);
|
||||||
$plot->SetColor($colors[$table]);
|
$plot->SetColor($colors[$table]);
|
||||||
$plot->SetLegend($table);
|
$plot->SetLegend($table);
|
||||||
$plot->SetLineWeight(2);
|
$plot->SetLineWeight(2);
|
||||||
|
|
||||||
$graph->Add($plot);
|
$graph->Add($plot);
|
||||||
|
@ -138,51 +138,51 @@ else {
|
||||||
$filter = array();
|
$filter = array();
|
||||||
if (array_key_exists($_REQUEST['zone'], $config['sddns']['zones'])) {
|
if (array_key_exists($_REQUEST['zone'], $config['sddns']['zones'])) {
|
||||||
$filter['zone'] = $config['sddns']['zones'][$_REQUEST['zone']];
|
$filter['zone'] = $config['sddns']['zones'][$_REQUEST['zone']];
|
||||||
|
|
||||||
if (!empty($_REQUEST['host'])) {
|
if (!empty($_REQUEST['host'])) {
|
||||||
$filter['host'] = $_REQUEST['host'];
|
$filter['host'] = $_REQUEST['host'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$data = DBHost::get($db, $filter);
|
$data = DBHost::get($db, $filter);
|
||||||
$dateField = null;
|
$dateField = null;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'logs':
|
case 'logs':
|
||||||
$data = $db->query('SELECT logged, id, program, message FROM logs ORDER BY logged DESC', 1000);
|
$data = $db->query('SELECT logged, id, program, message FROM logs ORDER BY logged DESC', 1000);
|
||||||
$dateField = 'logged';
|
$dateField = 'logged';
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'queries':
|
case 'queries':
|
||||||
$data = $db->query('SELECT queried, id, ip, port, hostname, class, type, options FROM queries ORDER BY queried DESC', 1000);
|
$data = $db->query('SELECT queried, id, ip, port, hostname, class, type, options FROM queries ORDER BY queried DESC', 1000);
|
||||||
$dateField = 'queried';
|
$dateField = 'queried';
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'uris':
|
case 'uris':
|
||||||
$filter = array();
|
$filter = array();
|
||||||
if (array_key_exists($_REQUEST['zone'], $config['sddns']['zones'])) {
|
if (array_key_exists($_REQUEST['zone'], $config['sddns']['zones'])) {
|
||||||
$filter['zone'] = $config['sddns']['zones'][$_REQUEST['zone']];
|
$filter['zone'] = $config['sddns']['zones'][$_REQUEST['zone']];
|
||||||
|
|
||||||
if (!empty($_REQUEST['host'])) {
|
if (!empty($_REQUEST['host'])) {
|
||||||
$filter['host'] = $_REQUEST['host'];
|
$filter['host'] = $_REQUEST['host'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$data = DBUri::get($db, $filter);
|
$data = DBUri::get($db, $filter);
|
||||||
$dateField = 'created';
|
$dateField = 'created';
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'records':
|
case 'records':
|
||||||
default:
|
default:
|
||||||
$filter = array();
|
$filter = array();
|
||||||
if (array_key_exists($_REQUEST['zone'], $config['sddns']['zones'])) {
|
if (array_key_exists($_REQUEST['zone'], $config['sddns']['zones'])) {
|
||||||
$filter['zone'] = $config['sddns']['zones'][$_REQUEST['zone']];
|
$filter['zone'] = $config['sddns']['zones'][$_REQUEST['zone']];
|
||||||
|
|
||||||
if (!empty($_REQUEST['host'])) {
|
if (!empty($_REQUEST['host'])) {
|
||||||
$filter['host'] = $_REQUEST['host'];
|
$filter['host'] = $_REQUEST['host'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($_REQUEST['class']) && in_array($_REQUEST['class'], $config['sddns']['classes']))
|
if (!empty($_REQUEST['class']) && in_array($_REQUEST['class'], $config['sddns']['classes']))
|
||||||
$filter['class'] = $_REQUEST['class'];
|
$filter['class'] = $_REQUEST['class'];
|
||||||
if (!empty($_REQUEST['ttl']))
|
if (!empty($_REQUEST['ttl']))
|
||||||
|
@ -192,22 +192,41 @@ else {
|
||||||
if (!empty($_REQUEST['rdata']) && Record::isRData($_REQUEST['rdata'], $filter['type']))
|
if (!empty($_REQUEST['rdata']) && Record::isRData($_REQUEST['rdata'], $filter['type']))
|
||||||
$filter['rdata'] = $_REQUEST['rdata'];
|
$filter['rdata'] = $_REQUEST['rdata'];
|
||||||
}
|
}
|
||||||
|
|
||||||
$data = DBRecord::get($db, $filter);
|
$data = DBRecord::get($db, $filter);
|
||||||
$dateField = 'created';
|
$dateField = 'created';
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($data as $row) {
|
foreach ($data as $row) {
|
||||||
switch (@$_REQUEST['data']) {
|
switch ($get[0]) {
|
||||||
case 'uris':
|
case 'uris':
|
||||||
$output->add('', 'data', $row->host, $row);
|
$params = 'host=' . $row->host->toPunycode() . '&zone=' . $row->host->zone->name . '&type=URL&rdata=' . $row->uri;
|
||||||
|
$actions = '<a href="../delete.php?' . $params . '"><img alt="delete" src="../images/delete.png" /></a>';
|
||||||
|
$actions .= '<a href="../expert.php?' . $params . '&command=update"><img alt="edit" src="../images/edit.png" /></a>';
|
||||||
|
|
||||||
|
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;
|
break;
|
||||||
case 'hosts':
|
case 'hosts':
|
||||||
|
$params = 'host=' . $row->toPunycode() . '&zone=' . $row->zone->name;
|
||||||
|
$actions = '<a href="../delete.php?' . $params . '"><img alt="delete" src="../images/delete.png" /></a>';
|
||||||
|
$actions .= '<a href="../expert.php?' . $params . '&command=update"><img alt="edit" src="../images/edit.png" /></a>';
|
||||||
|
|
||||||
|
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 = '<a href="../delete.php?' . $params . '"><img alt="delete" src="../images/delete.png" /></a>';
|
||||||
|
$actions .= '<a href="../expert.php?' . $params . '&command=update"><img alt="edit" src="../images/edit.png" /></a>';
|
||||||
|
|
||||||
|
if ($output instanceof HtmlOutput) $output->add(get_class($row), 'data', $row, $actions);
|
||||||
|
else $output->add(get_class($row), 'data', $row);
|
||||||
|
break;
|
||||||
case 'logs':
|
case 'logs':
|
||||||
case 'queries':
|
case 'queries':
|
||||||
case 'records':
|
|
||||||
default:
|
default:
|
||||||
$output->add('', 'data', $row);
|
$output->add('data', 'data', $row);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
13
delete.php
13
delete.php
|
@ -2,25 +2,24 @@
|
||||||
require_once 'include/init.php';
|
require_once 'include/init.php';
|
||||||
|
|
||||||
$output = Output::start();
|
$output = Output::start();
|
||||||
|
|
||||||
$pw = @$_REQUEST['pw'];
|
$pw = @$_REQUEST['pw'];
|
||||||
|
|
||||||
if (array_key_exists($_REQUEST['zone'], $config['sddns']['zones'])) {
|
if (array_key_exists($_REQUEST['zone'], $config['sddns']['zones'])) {
|
||||||
$zone = $config['sddns']['zones'][$_REQUEST['zone']];
|
$zone = $config['sddns']['zones'][$_REQUEST['zone']];
|
||||||
|
|
||||||
if (!empty($_REQUEST['host'])) {
|
if (!empty($_REQUEST['host'])) {
|
||||||
if ($host = reset(DBHost::get($db, array('host' => $_REQUEST['host'], 'zone' => $zone)))) {
|
if ($host = reset(DBHost::get($db, array('host' => $_REQUEST['host'], 'zone' => $zone)))) {
|
||||||
if ($host->checkPassword($pw) || isAuthentificated()) {
|
if ($host->checkPassword($pw) || isAuthentificated()) {
|
||||||
if (isset($_REQUEST['class']) && in_array($_REQUEST['class'], $config['sddns']['classes']))
|
if (isset($_REQUEST['class']) && in_array($_REQUEST['class'], $config['sddns']['classes']))
|
||||||
$class = $_REQUEST['class'];
|
$class = $_REQUEST['class'];
|
||||||
|
|
||||||
if (isset($_REQUEST['type']) && in_array($_REQUEST['type'], $config['sddns']['types'])) {
|
if (isset($_REQUEST['type']) && in_array($_REQUEST['type'], $config['sddns']['types'])) {
|
||||||
$type = $_REQUEST['type'];
|
$type = $_REQUEST['type'];
|
||||||
|
|
||||||
if (isset($_REQUEST['rdata']) && Record::isRData($_REQUEST['rdata'], $type))
|
if (isset($_REQUEST['rdata']) && Record::isRData($_REQUEST['rdata'], $type))
|
||||||
$rdata = $_REQUEST['rdata'];
|
$rdata = $_REQUEST['rdata'];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (@$type == 'URL' || empty($type)) {
|
if (@$type == 'URL' || empty($type)) {
|
||||||
$uris = DBUri::get($db, array('zone' => $zone, 'host' => $host));
|
$uris = DBUri::get($db, array('zone' => $zone, 'host' => $host));
|
||||||
foreach ($uris as $uri) {
|
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);
|
$output->add('uri deleted from db', 'success', $uri);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (@$type != 'URL' || empty($type)) {
|
if (@$type != 'URL' || empty($type)) {
|
||||||
$records = DBRecord::get($db, array('zone' => $zone, 'host' => $host, 'type' => @$type, 'class' => @$class, 'rdata' => @$rdata));
|
$records = DBRecord::get($db, array('zone' => $zone, 'host' => $host, 'type' => @$type, 'class' => @$class, 'rdata' => @$rdata));
|
||||||
foreach ($records as $record) {
|
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);
|
$output->add('record deleted from db', 'success', $record);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$zone->cleanup($db);
|
$zone->cleanup($db);
|
||||||
$zone->sync($db);
|
$zone->sync($db);
|
||||||
}
|
}
|
||||||
|
|
|
@ -84,12 +84,13 @@ $checkedType = (isset($_REQUEST['type'])) ? $_REQUEST['type'] : $config['sddns']
|
||||||
<option><i>all</i></option></select></td>
|
<option><i>all</i></option></select></td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr><td><label for="rdata">rdata</label></td><td><input value="<?php echo (empty($_REQUEST['rdata']) && $checkedType == 'A') ? $_SERVER['REMOTE_ADDR'] : @$_REQUEST['rdata']; ?>" type="text" name="rdata" /></td><td><input type="checkbox" value="1" name="frame" /> hide uri in a frameset</td></tr>
|
<tr><td><label for="rdata">rdata</label></td><td><input value="<?php echo (empty($_REQUEST['rdata']) && $checkedType == 'A') ? $_SERVER['REMOTE_ADDR'] : @$_REQUEST['rdata']; ?>" type="text" name="rdata" /></td><td><input type="checkbox" value="1" name="frame" /> hide uri in a frameset</td></tr>
|
||||||
<tr><td><label for="pw">password</label></td><td><input type="password" name="pw" /></td><td>optional; random generated</td></tr>
|
<?php if (!isAuthentificated()) echo '<tr><td><label for="pw">password</label></td><td><input type="password" name="pw" /></td><td>optional; random generated</td></tr>'; ?>
|
||||||
|
|
||||||
</table>
|
</table>
|
||||||
<input type="submit" />
|
<input type="submit" />
|
||||||
<p>
|
<p>
|
||||||
<a href="simple">simple mode</a> -
|
<a href="simple">simple mode</a> -
|
||||||
|
<?php if (isAuthentificated()) echo '<a href="admin/">admin</a> - '; ?>
|
||||||
<a href="http://0l.de/projects/sddns/usage">usage</a> -
|
<a href="http://0l.de/projects/sddns/usage">usage</a> -
|
||||||
<a href="http://0l.de/projects/sddns/">wiki</a> -
|
<a href="http://0l.de/projects/sddns/">wiki</a> -
|
||||||
<a href="javascript:u='http://d.0l.de/add.html?type=URL&rdata='+encodeURIComponent(location.href);h=encodeURIComponent(window.getSelection().toString().replace(/[\s\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2A\x2B\x2C\x2E\x2F\x3A\x3B\x3C\x3D\x3F\x40\x5B\x5C\x5D\x5E\x5F\x60\x7B\x7C\x7C\x7D\x7E]+/gi,'-').replace(/^\-+/,'').replace(/\-+$/,''));if(!h){h=prompt('Subdomain','');}if(h){u+='&host='+h;}location.href=u">bookmarklet</a> -
|
<a href="javascript:u='http://d.0l.de/add.html?type=URL&rdata='+encodeURIComponent(location.href);h=encodeURIComponent(window.getSelection().toString().replace(/[\s\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2A\x2B\x2C\x2E\x2F\x3A\x3B\x3C\x3D\x3F\x40\x5B\x5C\x5D\x5E\x5F\x60\x7B\x7C\x7C\x7D\x7E]+/gi,'-').replace(/^\-+/,'').replace(/\-+$/,''));if(!h){h=prompt('Subdomain','');}if(h){u+='&host='+h;}location.href=u">bookmarklet</a> -
|
||||||
|
|
BIN
images/delete.png
Normal file
BIN
images/delete.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 715 B |
BIN
images/edit.png
Normal file
BIN
images/edit.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 714 B |
|
@ -64,15 +64,15 @@ abstract class DBResultSet implements Iterator {
|
||||||
public function valid() {
|
public function valid() {
|
||||||
return (bool) is_array($this->current());
|
return (bool) is_array($this->current());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function first() {
|
public function first() {
|
||||||
return (isset($this->_rows[0])) ? $this->_rows[0] : null;
|
return (isset($this->_rows[0])) ? $this->_rows[0] : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function last() {
|
public function last() {
|
||||||
return $this->_rows[$this->_num_rows - 1];
|
return $this->_rows[$this->_num_rows - 1];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function count() {
|
public function count() {
|
||||||
return $this->_num_rows;
|
return $this->_num_rows;
|
||||||
}
|
}
|
||||||
|
@ -141,4 +141,4 @@ abstract class Database implements IDatabase {
|
||||||
protected $statements = array();
|
protected $statements = array();
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
function isAuthentificated() {
|
function isAuthentificated() {
|
||||||
$config = Registry::get('config');
|
$config = Registry::get('config');
|
||||||
$htpasswd = file('../.htpasswd');
|
$htpasswd = file('/var/www/nulll/.htpasswd');
|
||||||
|
|
||||||
foreach ($htpasswd as $line) {
|
foreach ($htpasswd as $line) {
|
||||||
list($user, $crypt) = explode(':', $line);
|
list($user, $crypt) = explode(':', $line);
|
||||||
|
|
|
@ -2,16 +2,16 @@
|
||||||
|
|
||||||
class Host implements Object {
|
class Host implements Object {
|
||||||
private $punycode;
|
private $punycode;
|
||||||
public $zone;
|
public $zone;
|
||||||
public $generated;
|
public $generated;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Constructor & Factory
|
* Constructor & Factory
|
||||||
*/
|
*/
|
||||||
public function __construct($hostname, Zone $zone, $generated = false) {
|
public function __construct($hostname, Zone $zone, $generated = false) {
|
||||||
$hostname = strtolower($hostname);
|
$hostname = strtolower($hostname);
|
||||||
if (self::isValid(idn_to_ascii($hostname))) {
|
if (self::isValid(idn_to_ascii($hostname))) {
|
||||||
$this->punycode = idn_to_ascii($hostname);
|
$this->punycode = idn_to_ascii($hostname);
|
||||||
$this->zone = $zone;
|
$this->zone = $zone;
|
||||||
$this->generated = $generated;
|
$this->generated = $generated;
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,7 @@ class Host implements Object {
|
||||||
throw new UserException('Invalid hostname: ' . idn_to_ascii($hostname));
|
throw new UserException('Invalid hostname: ' . idn_to_ascii($hostname));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function unique(Zone $zone, Database $db) {
|
public static function unique(Zone $zone, Database $db) {
|
||||||
$config = Registry::get('config');
|
$config = Registry::get('config');
|
||||||
|
|
||||||
|
@ -32,25 +32,25 @@ class Host implements Object {
|
||||||
generated = TRUE &&
|
generated = TRUE &&
|
||||||
zone = \'' . $db->escape($zone->name) . '\'
|
zone = \'' . $db->escape($zone->name) . '\'
|
||||||
ORDER BY id DESC';
|
ORDER BY id DESC';
|
||||||
|
|
||||||
$result = $db->query($sql, 1);
|
$result = $db->query($sql, 1);
|
||||||
$first = $result->first();
|
$first = $result->first();
|
||||||
$last_id = base_convert($first['hostname'], 36, 10);
|
$last_id = base_convert($first['hostname'], 36, 10);
|
||||||
|
|
||||||
while ($result->count() > 0 || !Host::isValid(base_convert($last_id, 10, 36))) {
|
while ($result->count() > 0 || !Host::isValid(base_convert($last_id, 10, 36))) {
|
||||||
|
|
||||||
$sql = 'SELECT hostname
|
$sql = 'SELECT hostname
|
||||||
FROM ' . $config['db']['tbl']['hosts'] . '
|
FROM ' . $config['db']['tbl']['hosts'] . '
|
||||||
WHERE
|
WHERE
|
||||||
hostname = \'' . base_convert(++$last_id, 10, 36) . '\' &&
|
hostname = \'' . base_convert(++$last_id, 10, 36) . '\' &&
|
||||||
zone = \'' . $db->escape($zone->name) . '\'';
|
zone = \'' . $db->escape($zone->name) . '\'';
|
||||||
|
|
||||||
$result = $db->query($sql, 1);
|
$result = $db->query($sql, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new self(base_convert($last_id, 10, 36), $zone, true);
|
return new self(base_convert($last_id, 10, 36), $zone, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Checks
|
* Checks
|
||||||
*/
|
*/
|
||||||
|
@ -58,7 +58,7 @@ class Host implements Object {
|
||||||
$hostExpr = '[a-z0-9](?:[a-z0-9\-]*[a-z0-9])?';
|
$hostExpr = '[a-z0-9](?:[a-z0-9\-]*[a-z0-9])?';
|
||||||
return preg_match('/^(?:\*|(\*\.)?(' . $hostExpr . '\.)*(' . $hostExpr . '))$/i', $hostname);
|
return preg_match('/^(?:\*|(\*\.)?(' . $hostExpr . '\.)*(' . $hostExpr . '))$/i', $hostname);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function isRegistred(Database $db) {
|
public function isRegistred(Database $db) {
|
||||||
$config = Registry::get('config');
|
$config = Registry::get('config');
|
||||||
|
|
||||||
|
@ -71,7 +71,7 @@ class Host implements Object {
|
||||||
|
|
||||||
return ($result->count() > 0) ? $host['id'] : false;
|
return ($result->count() > 0) ? $host['id'] : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Database
|
* Database
|
||||||
*/
|
*/
|
||||||
|
@ -86,35 +86,35 @@ class Host implements Object {
|
||||||
' . (int) $this->generated . ')';
|
' . (int) $this->generated . ')';
|
||||||
|
|
||||||
$db->execute($sql);
|
$db->execute($sql);
|
||||||
|
|
||||||
return new DBHost($db->lastId(), $db);
|
return new DBHost($db->lastId(), $db);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Output
|
* Output
|
||||||
*/
|
*/
|
||||||
public function toUnicode() {
|
public function toUnicode() {
|
||||||
return idn_to_utf8($this->punycode);
|
return idn_to_utf8($this->punycode);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function toPunycode() {
|
public function toPunycode() {
|
||||||
return $this->punycode;
|
return $this->punycode;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function __toString() {
|
public function __toString() {
|
||||||
return $this->toPunycode() . '.' . $this->zone->name;
|
return $this->toPunycode() . '.' . $this->zone->name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function toXml(DOMDocument $doc) {
|
public function toXml(DOMDocument $doc) {
|
||||||
$xmlHost = $doc->createElement('host');
|
$xmlHost = $doc->createElement('host');
|
||||||
|
|
||||||
$xmlHost->appendChild($doc->createElement('hostname', $this->toPunycode()));
|
$xmlHost->appendChild($doc->createElement('hostname', $this->toPunycode()));
|
||||||
$xmlHost->appendChild($doc->createElement('idn', $this->toUnicode()));
|
$xmlHost->appendChild($doc->createElement('idn', $this->toUnicode()));
|
||||||
$xmlHost->appendChild($this->zone->toXml($doc));
|
$xmlHost->appendChild($this->zone->toXml($doc));
|
||||||
|
|
||||||
return $xmlHost;
|
return $xmlHost;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function toHtml() {
|
public function toHtml() {
|
||||||
return '<a target="_blank" href="http://' . $this . '">' . $this->toUnicode() . '.' . $this->zone->name . '</a>';
|
return '<a target="_blank" href="http://' . $this . '">' . $this->toUnicode() . '.' . $this->zone->name . '</a>';
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,11 +42,11 @@ class MySql extends Database {
|
||||||
$this->connect($host, $user, $pw);
|
$this->connect($host, $user, $pw);
|
||||||
$this->select($db);
|
$this->select($db);
|
||||||
}
|
}
|
||||||
|
|
||||||
function __destruct() {
|
function __destruct() {
|
||||||
$this->close();
|
$this->close();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief create database connection
|
* @brief create database connection
|
||||||
* @param string $host IP or domain of the database host
|
* @param string $host IP or domain of the database host
|
||||||
|
@ -60,7 +60,7 @@ class MySql extends Database {
|
||||||
error_reporting($__er);
|
error_reporting($__er);
|
||||||
throw new MySqlException();
|
throw new MySqlException();
|
||||||
}
|
}
|
||||||
|
|
||||||
error_reporting($__er);
|
error_reporting($__er);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,6 +90,8 @@ class MySql extends Database {
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public function execute($sql) {
|
public function execute($sql) {
|
||||||
|
if ($output = Registry::get('output')) $output->add('db query', 'debug', 8, $sql);
|
||||||
|
|
||||||
if (!($result = mysql_unbuffered_query($sql, $this->resource)))
|
if (!($result = mysql_unbuffered_query($sql, $this->resource)))
|
||||||
throw new MySqlException();
|
throw new MySqlException();
|
||||||
return $result;
|
return $result;
|
||||||
|
@ -107,7 +109,7 @@ class MySql extends Database {
|
||||||
$sql .= sprintf(' LIMIT %d, %d', $offset, $limit);
|
$sql .= sprintf(' LIMIT %d, %d', $offset, $limit);
|
||||||
return new MySqlResult($this->execute($sql));
|
return new MySqlResult($this->execute($sql));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief mysql escape
|
* @brief mysql escape
|
||||||
* @param string $sql query
|
* @param string $sql query
|
||||||
|
@ -115,11 +117,11 @@ class MySql extends Database {
|
||||||
public function escape($sql) {
|
public function escape($sql) {
|
||||||
return mysql_real_escape_string($sql, $this->resource);
|
return mysql_real_escape_string($sql, $this->resource);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function lastId() {
|
public function lastId() {
|
||||||
return mysql_insert_id($this->resource);
|
return mysql_insert_id($this->resource);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function affectedRows() {
|
public function affectedRows() {
|
||||||
return mysql_affected_rows($this->resource);
|
return mysql_affected_rows($this->resource);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,21 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
class JsonOutput extends Output {
|
||||||
|
public function __construct($debug) {
|
||||||
|
parent::__construct('application/json', 'UTF-8', $debug);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getOutput() {
|
||||||
|
return json_encode($this->getMessages());
|
||||||
|
|
||||||
|
$json = array();
|
||||||
|
|
||||||
|
foreach ($this->getMessages() as $index => $message) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class XmlOutput extends Output {
|
class XmlOutput extends Output {
|
||||||
public function __construct($debug) {
|
public function __construct($debug) {
|
||||||
parent::__construct('text/xml', 'UTF-8', $debug);
|
parent::__construct('text/xml', 'UTF-8', $debug);
|
||||||
|
@ -327,6 +343,9 @@ abstract class Output {
|
||||||
return new GifOutput();
|
return new GifOutput();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'json':
|
||||||
|
return new JsonOutput($debug);
|
||||||
|
|
||||||
case 'html':
|
case 'html':
|
||||||
case 'php':
|
case 'php':
|
||||||
default:
|
default:
|
||||||
|
@ -339,7 +358,7 @@ abstract class Output {
|
||||||
global $argc;
|
global $argc;
|
||||||
|
|
||||||
$site = Registry::get('site');
|
$site = Registry::get('site');
|
||||||
|
|
||||||
if (isset($forced))
|
if (isset($forced))
|
||||||
$format = $forced;
|
$format = $forced;
|
||||||
elseif (isset($argc))
|
elseif (isset($argc))
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
class Zone extends NameServer implements Object {
|
class Zone extends NameServer implements Object {
|
||||||
public $name;
|
public $name;
|
||||||
public $key;
|
private $key;
|
||||||
|
|
||||||
function __construct($nserver, $name, $key, $nsport = 53) {
|
function __construct($nserver, $name, $key, $nsport = 53) {
|
||||||
parent::__construct($nserver, $nsport);
|
parent::__construct($nserver, $nsport);
|
||||||
|
@ -42,7 +42,7 @@ class Zone extends NameServer implements Object {
|
||||||
LEFT JOIN ' . $config['db']['tbl']['hosts'] . ' AS h
|
LEFT JOIN ' . $config['db']['tbl']['hosts'] . ' AS h
|
||||||
ON h.id = u.host_id
|
ON h.id = u.host_id
|
||||||
WHERE
|
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';
|
h.zone = \'' . $db->escape($this->name) . '\') || h.id IS NULL';
|
||||||
|
|
||||||
$db->execute($sql);
|
$db->execute($sql);
|
||||||
|
|
|
@ -68,12 +68,12 @@ if (!empty($zone)) {
|
||||||
$records[0]->lastAccessed = time();
|
$records[0]->lastAccessed = time();
|
||||||
$records[0]->update();
|
$records[0]->update();
|
||||||
$output->add('record updated in db', 'success', $records[0]);
|
$output->add('record updated in db', 'success', $records[0]);
|
||||||
|
|
||||||
for ($i = 1; $i < count($records); $i++) {
|
for ($i = 1; $i < count($records); $i++) {
|
||||||
$records[$i]->delete();
|
$records[$i]->delete();
|
||||||
$output->add('record deleted from db', 'warning', $records[$i]);
|
$output->add('record deleted from db', 'warning', $records[$i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
$zone->cleanup($db);
|
$zone->cleanup($db);
|
||||||
$zone->sync($db);
|
$zone->sync($db);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue