too much to describe :D

This commit is contained in:
Steffen Vogel 2013-03-08 03:25:44 +01:00
parent c2a93a2d2b
commit 553d7d8be1
12 changed files with 102 additions and 40 deletions

View file

@ -1,5 +1,6 @@
<?php
$config['htpasswd'] = '/var/www/nulll/.htpasswd';
$config['path']['web'] = '';
$config['db']['host'] = 'localhost';
@ -15,7 +16,7 @@ $config['sddns']['htpasswd'] = $site['path']['server'] . '/../.htpasswd';
$key = array('hmac' => 'gDlXSZtESw78I47O68UEigpPofn0XbpSpo5Vba+9IY38EYagPO/2C2Ch lZL+AvtN/ozRdra+p3+wLOKvVvqdrA==', 'name' => 'info.steffenvogel.de.');
$zones = array('0l.de');
$config['sddns']['ns']['hostname'] = 'ns0.0l.de';
$config['sddns']['ns']['hostname'] = 'localhost';
$config['sddns']['ns']['port'] = 53;
foreach ($zones as $zone) {

View file

@ -12,7 +12,7 @@ class CustomException extends Exception {
$xmlRecord->appendChild($doc->createElement('message', $this->message));
$xmlRecord->appendChild($doc->createElement('line', $this->line));
$xmlRecord->appendChild($doc->createElement('file', $this->file));
$xmlRecord->appendChild(backtrace2xml($this->getTrace(), $doc));
return $xmlRecord;

View file

@ -1,8 +1,13 @@
<?php
function doAuthentification() {
header('WWW-Authenticate: Basic realm="Administration Area"');
header('HTTP/1.0 401 Unauthorized');
}
function isAuthentificated() {
$config = Registry::get('config');
$htpasswd = file('/var/www/nulll/.htpasswd');
$htpasswd = file($config['htpasswd']);
foreach ($htpasswd as $line) {
list($user, $crypt) = explode(':', $line);

View file

@ -1,7 +1,7 @@
<?php
class Host implements Object {
private $punycode;
public $punycode;
public $zone;
public $generated;

View file

@ -29,7 +29,7 @@ require_once $site['path']['server'] . '/include/config.php';
Registry::set('config', $config);
// get relevant runtime information
$site['hostname'] = @$_SERVER[ 'SERVER_NAME'];
$site['hostname'] = @$_SERVER['SERVER_NAME'];
$site['path']['web'] = $config['path']['web'];
$site['url'] = 'http://' . $site['hostname'] . $site['path']['web'];

View file

@ -90,10 +90,12 @@ class MySql extends Database {
* @return mixed
*/
public function execute($sql) {
if ($output = Registry::get('output')) $output->add('db query', 'debug', 8, $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

@ -6,12 +6,19 @@ class JsonOutput extends Output {
}
protected function getOutput() {
return json_encode($this->getMessages());
$json = array();
foreach ($this->getMessages() as $index => $message) {
array_push($json, $message);
}
// JSONP
if (!empty($_REQUEST['callback'])) {
return $_REQUEST['callback'] . '(' . json_encode($json) . ');';
}
else {
return json_encode($json);
}
}
}
@ -31,8 +38,9 @@ class XmlOutput extends Output {
$xmlMessage = $doc->createElement('message');
$xmlMessage->setAttribute('type', $message['type']);
if ($message['type'] == 'debug')
$xmlMessage->setAttribute('level', $message['level']);
if ($message['type'] == 'debug') {
$xmlMessage->setAttribute('level', $message['level']);
}
$xmlMessage->appendChild($doc->createElement('description', $message['description']));
@ -210,7 +218,8 @@ class HtmlOutput extends Output {
<link rel="icon" href="/favicon.png" type="image/png" />
<link rel="search" type="application/opensearchdescription+xml" title="Tiny DNS &amp; URL" href="' . $site['path']['web'] . '/opensearch.xml" />
</head>
<body>';
<body>
<div id="wrapper">';
$str .= '<div id="content">' . $html . '</div>';
@ -220,16 +229,16 @@ class HtmlOutput extends Output {
foreach ($messages as $index => $message) {
$str .= '<tr class="' . $message['type'] . '">
<td><img alt="' . $message['type'] . '" src="' . $site['path']['web'] . '/images/' . $message['type'] . '.png" title="' . @$message['level'] . '" /></td>
<td><img alt="' . $message['type'] . '" title="' . $message['type'] . '" src="' . $site['path']['web'] . '/images/' . $message['type'] . '.png" title="' . @$message['level'] . '" /></td>
<td>#' . $index . '</td>
<td>' . date('Y-m-d H:i:s', $message['time']) . '</td>
<td>' . date('Y-m-d H:i', $message['time']) . '</td>
<td>' . $message['description'] . '</td>';
for($i = 0; $i < $columnCount; $i++) {
$str .= '<td>';
if (isset($message['data'][$i])) {
$data = $message['data'][$i];
if (method_exists($data, 'toHtml')) {
if (is_object($data) && method_exists($data, 'toHtml')) {
$str .= $data->toHtml();
}
else {
@ -245,7 +254,7 @@ class HtmlOutput extends Output {
$str .= '</table>';
}
$str .= '</body></html>';
$str .= '</div></body></html>';
return $str;
}
@ -389,7 +398,9 @@ abstract class Output {
}
function exception_handler($exception) {
$this->add('unhandled ' . get_class($exception), 'exception', $exception);
$this->add('unhandled ' . get_class($exception), 'exception', (array) $exception);
$this->debug = 7; // increase verbosity in case of an exception
$this->send();
}
function error_handler($errno, $errstr, $errfile, $errline) {

View file

@ -102,6 +102,11 @@ class Record implements Object {
$valid = Host::isValid($rdata);
break;
case 'MX':
@list($priority, $hostname) = explode($rdata, ' ');
$valid = (is_numeric($priority) && Host::isValid($hostname));
break;
case 'URL':
$valid = Uri::isValid($rdata);
@ -189,7 +194,7 @@ class Record implements Object {
break;
}
return $html;
return $html;
}
}

View file

@ -1,5 +1,10 @@
html, body {
height: 100%;
}
body {
margin: 0px;
margin: 0;
padding: 0;
font-family: sans-serif;
}
@ -18,21 +23,21 @@ h3 {
}
dl {
width: 300px;
margin: auto;
width: 300px;
margin: auto;
}
dt {
float: left;
float: left;
}
dt a {
color: #555
color: #555
}
dd {
text-align: right;
padding-bottom: 4px
text-align: right;
padding-bottom: 4px
}
hr {
@ -69,6 +74,15 @@ iframe {
border: 0;
}
* html #wrapper {
height: 100%;
}
#wrapper {
position: relative;
min-height: 100%;
}
#messages {
width: 100%;
padding: 0;
@ -77,7 +91,8 @@ iframe {
}
#content {
margin: 8px;
margin: 0;
padding: 10px;
}
#simple {
@ -118,6 +133,9 @@ iframe {
.data {
background-color: #FFFFFF;
}
.data a {
font-family: Fixedsys,Courier,monospace;
}

View file

@ -1,9 +1,9 @@
<?php
class Uri implements Object {
public $uri, $host, $frame;
/*
* Constructor
*/
@ -11,7 +11,7 @@ class Uri implements Object {
$this->uri = $uri;
$this->host = $host;
}
/*
* Database
*/
@ -27,37 +27,50 @@ class Uri implements Object {
NOW(),
NOW(),
\'' . $_SERVER['REMOTE_ADDR'] . '\')';
$db->execute($sql);
return new DBUri($db->lastId(), $db);
}
/*
* Checks
*/
static function isValid($uri) {
return true; // TODO
}
/*
* Setter & Getter
*/
public function setUri($uri) {
if ($this->isValid($uri)) {
$this->uri = $uri;
}
else {
throw new ValidationException('Invalid uri: ' . $uri);
}
}
/*
* Output
*/
public function __toString() {
return $this->uri;
}
public function toHtml() {
return '<a target="_blank" href="' . $this . '">' . $this . '</a>';
}
public function toXml(DOMDocument $doc) {
$xmlUri = $doc->createElement('uri');
$xmlUri->appendChild($doc->createElement('uri', $this->uri));
$xmlUri->appendChild($this->host->toXml($doc));
return $xmlUri;
}
}

View file

@ -51,7 +51,7 @@ class Zone extends NameServer implements Object {
) || h.id IS NULL';
if ($db->affectedRows() > 0) {
$output->add('urls deleted from db', 'success', $db->affectedRows(), $this);
$output->add('uris deleted from db', 'success', $db->affectedRows(), $this);
}
// hosts without records or url
@ -91,6 +91,7 @@ class Zone extends NameServer implements Object {
}
public function add(Record $record) {
global $output;
$config = Registry::get('config');
if ($record->host->zone->name != $this->name) {
@ -100,7 +101,7 @@ class Zone extends NameServer implements Object {
parent::add($record);
$nsresult = $this->sendQueue();
if($nsresult['code'] != 0) {
if ($nsresult['code'] != 0) {
throw new NameServerException('error during nameserver update: ' . $nsresult['stderr']);
}

View file

@ -12,19 +12,25 @@ if (count($uris) == 1) {
$uri->lastAccessed = time();
$uri->update();
$fullUri = $uri->uri;
if ($_SERVER['REQUEST_URI'] != '/') {
$fullUri .= $_SERVER['REQUEST_URI'];
}
if ($uri->frame) {
echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head><title>/dev/nulll - Frame</title></head>
<body style="margin: 0; padding: 0; overflow: hidden;">
<iframe style="height: 100%; width: 100%; position: absolute; top: 0; left: 0;" height="100%" width="100%" frameborder="0" marginheight="0" marginwidth="0" src="' . $uri->uri . '"></iframe>
<iframe style="height: 100%; width: 100%; position: absolute; top: 0; left: 0;" height="100%" width="100%" frameborder="0" marginheight="0" marginwidth="0" src="' . $fullUri . '"></iframe>
</body>
</html>';
}
else {
header('Location: ' . $uri->uri);
header('Location: ' . $fullUri);
}
}
else {