improved usability and coding style

This commit is contained in:
Steffen Vogel 2011-08-19 20:55:53 +02:00
parent 1bf7aa8b7a
commit 30ab353a10
14 changed files with 133 additions and 93 deletions

View file

@ -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)

View file

@ -31,7 +31,7 @@ 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();

View file

@ -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'])) {
@ -41,7 +41,7 @@ if (isset($_REQUEST['data'])) {
}
}
else {
$get = array('queries');
$get = array('records');
}
if ($output instanceof GraphOutput) {
@ -198,16 +198,35 @@ else {
}
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 = '<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;
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 'queries':
case 'records':
default:
$output->add('', 'data', $row);
$output->add('data', 'data', $row);
}
}
}

View file

@ -2,7 +2,6 @@
require_once 'include/init.php';
$output = Output::start();
$pw = @$_REQUEST['pw'];
if (array_key_exists($_REQUEST['zone'], $config['sddns']['zones'])) {

View file

@ -84,12 +84,13 @@ $checkedType = (isset($_REQUEST['type'])) ? $_REQUEST['type'] : $config['sddns']
<option><i>all</i></option></select></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>
<input type="submit" />
<p>
<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/">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> -

BIN
images/delete.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 715 B

BIN
images/edit.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 714 B

View file

@ -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);

View file

@ -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;

View file

@ -1,5 +1,21 @@
<?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 {
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:

View file

@ -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);