improved output

added uri frame support
This commit is contained in:
root 2010-10-07 14:22:51 +02:00
parent d8209893c7
commit 5f61820c54
21 changed files with 120 additions and 51 deletions

View file

@ -1,6 +1,8 @@
<?php
require_once 'include/init.php';
$output = Output::start();
if (array_key_exists($_REQUEST['zone'], $config['sddns']['zones'])) {
$zone = $config['sddns']['zones'][$_REQUEST['zone']];
@ -66,4 +68,6 @@ else {
$output->add('zone not found', 'error', $_REQUEST['zone']);
}
Output::send();
?>

View file

@ -1,5 +1,7 @@
<?php
$output = Output::start();
require_once dirname(__FILE__) . '/../include/init.php';
if (empty($_REQUEST['zone']) || $_REQUEST['zone'] == 'all') {
@ -17,5 +19,6 @@ foreach ($zones as $zone) {
$zone->cleanup($db);
}
Output::send();
?>

View file

@ -1,6 +1,8 @@
<?php
require_once '../include/init.php';
$output = Output::start();
$dataTables = array(
'hosts' => null, // table name => date field
'records' => 'created',
@ -200,4 +202,7 @@ else {
}
}
}
Output::send();
?>

View file

@ -1,6 +1,7 @@
<?php
require_once dirname(__FILE__) . '/../include/init.php';
$output = Output::start();
$sql = 'SELECT *
FROM logs
@ -59,4 +60,6 @@ else {
$output->add('no queries to parse', 'debug', 1);
}
Output::send();
?>

View file

@ -1,5 +1,6 @@
<?php
require_once '../include/init.php';
$output = Output::start();
$ns = new NameServer($config['sddns']['ns']['hostname'], $config['sddns']['ns']['port']);
@ -18,4 +19,6 @@ foreach ($results as $result) {
$output->add('', 'data', $result);
}
Output::send();
?>

View file

@ -1,6 +1,7 @@
<?php
require_once '../../include/init.php';
$output = Output::start();
$result = $db->query('SELECT DISTINCT hostname, COUNT(hostname) AS sum FROM queries GROUP BY hostname ORDER BY sum DESC', (empty($_GET['n'])) ? 1000 : (int) $_GET['n']);
@ -8,4 +9,6 @@ foreach ($result as $row) {
$output->add($row['hostname'], 'data', $row['sum']);
}
Output::send();
?>

View file

@ -1,6 +1,7 @@
<?php
require_once '../../include/init.php';
$output = Output::start();
$result = $db->query('SELECT COUNT(*) AS count FROM queries', 1)->first();
$count = $result['count'];
@ -43,4 +44,6 @@ else {
}
}
Output::send();
?>

View file

@ -1,6 +1,7 @@
<?php
require_once dirname(__FILE__) . '/../include/init.php';
$output = Output::start();
if (empty($_REQUEST['zone']) || $_REQUEST['zone'] == 'all') {
$zones = $config['sddns']['zones'];
@ -14,5 +15,6 @@ foreach ($zones as $zone) {
$zone->sync($db);
}
Output::send();
?>

View file

@ -1,6 +1,7 @@
<?php
require_once 'include/init.php';
$output = Output::start();
$pw = @$_REQUEST['pw'];
@ -57,4 +58,6 @@ else {
$output->add('zone not found', 'error', $_REQUEST['zone']);
}
Output::send();
?>

View file

@ -1,6 +1,8 @@
<?php
require_once 'include/init.php';
$output = Output::start('html');
$output->add('hits since launch', 'notice', $site['hits']);
if (isAuthentificated()) {
@ -100,3 +102,7 @@ $checkedType = (isset($_REQUEST['type'])) ? $_REQUEST['type'] : $config['sddns']
<hr />
<address><?= $_SERVER['SERVER_SIGNATURE'] ?></address>
</div>
<?php
Output::send();
?>

View file

@ -24,6 +24,7 @@ class DBUri extends Uri implements DBObject {
$this->lastAccessed = strtotime($uri['last_accessed']);
$this->lifetime = $uri['lifetime'];
$this->accessed = $uri['accessed'];
$this->frame = $uri['frame'];
$this->host = new DBHost($uri['host_id'], $this->db);
parent::__construct($uri['uri'], $this->host);
@ -40,6 +41,7 @@ class DBUri extends Uri implements DBObject {
SET
host_id = ' . (int) $this->host->id . ',
uri = \'' . $this->db->escape($this->uri) . '\',
frame = ' . (($this->frame) ? 1 : 0) . ',
accessed = ' . (int) $this->accessed . ',
last_accessed = \'' . date('Y-m-d H:i:s', $this->lastAccessed) . '\',
lifetime = ' . (int) $this->lifetime . '

View file

@ -1 +1 @@
58953
59012

View file

@ -35,42 +35,17 @@ $site['url'] = 'http://' . $site['hostname'] . $site['path']['web'];
// debug mode
if (@isset($_REQUEST['debug'])) {
$debug = (int) $_REQUEST['debug'];
$site['debug'] = (int) $_REQUEST['debug'];
}
else {
if (isAuthentificated()) {
$debug = 1;
$site['debug'] = 3;
}
else {
$debug = 0;
$site['debug'] = 0;
}
}
// output
if (isset($argc))
$format = 'txt';
elseif ($_SERVER['SERVER_NAME'] === 'members.dyndns.org')
$format = 'dyndns';
elseif (empty($_REQUEST['format']) || @$_REQUEST['format'] == 'php')
$format = 'html';
else
$format = $_REQUEST['format'];
$output = Output::getInstance($format, $debug);
Registry::set('output', $output);
// errorhandling
set_exception_handler(array($output, 'exception_handler'));
set_error_handler(array($output, 'error_handler'), E_ALL);
$parameters = array();
foreach ($_REQUEST as $parName => $parValue) {
$parameters[] = $parName . ' => ' . $parValue;
}
$output->add('debug level', 'debug', 2, $output->debug);
$output->add('parameters', 'debug', 2, $parameters);
// simple hit counting
$file = $site['path']['server'] . '/include/hits.txt';
$handle = fopen($file, 'r+') ;

View file

@ -335,6 +335,41 @@ abstract class Output {
}
}
static function start($forced = null) {
global $argc;
$site = Registry::get('site');
if (isset($forced))
$format = $forced;
elseif (isset($argc))
$format = 'txt';
elseif ($_SERVER['SERVER_NAME'] === 'members.dyndns.org')
$format = 'dyndns';
elseif (empty($_REQUEST['format']) || @$_REQUEST['format'] == 'php')
$format = 'html';
else
$format = $_REQUEST['format'];
$output = self::getInstance($format, $site['debug']);
Registry::set('output', $output);
// errorhandling
set_exception_handler(array($output, 'exception_handler'));
set_error_handler(array($output, 'error_handler'), E_ALL);
// debugging
$parameters = array();
foreach ($_REQUEST as $parName => $parValue) {
$parameters[] = $parName . ' => ' . $parValue;
}
$output->add('debug level', 'debug', 2, $output->debug);
$output->add('parameters', 'debug', 2, $parameters);
return $output;
}
function exception_handler($exception) {
$this->add('unhandled ' . get_class($exception), 'exception', $exception);
}
@ -370,8 +405,9 @@ abstract class Output {
abstract protected function getOutput();
public function __destruct() {
echo $this->getOutput();
static function send() {
if ($output = Registry::get('output'))
echo $output->getOutput();
}
}

View file

@ -49,6 +49,12 @@ a img {
border: 0px;
}
iframe {
width: 100%;
height: 100%;
border: 0;
}
#messages {
width: 100%;
padding: 0px;

View file

@ -2,7 +2,7 @@
class Uri implements Object {
public $uri, $host;
public $uri, $host, $frame;
/*
* Constructor
@ -19,9 +19,10 @@ class Uri implements Object {
$config = Registry::get('config');
$db = Registry::get('db');
$sql = 'INSERT INTO ' . $config['db']['tbl']['uris'] . ' (host_id, uri, lifetime, last_accessed, created, ip) VALUES(
$sql = 'INSERT INTO ' . $config['db']['tbl']['uris'] . ' (host_id, uri, frame, lifetime, last_accessed, created, ip) VALUES(
' . $this->host->id . ',
\'' . $this->uri . '\',
' . (($this->frame) ? 1 : 0) . ',
' . $lifetime . ',
NOW(),
NOW(),

View file

@ -12,7 +12,22 @@ if (count($uris) == 1) {
$uri->lastAccessed = time();
$uri->update();
header('Location: ' . $uri->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;">
<table style="height: 100%; width: 100%; position: absolute; top: 0; left: 0;"><tr><td>
<iframe height="100%" width="100%" frameborder="0" marginheight="0" marginwidth="0" src="' . $uri->uri . '"></iframe>
</td></tr></table>
</body>
</html>';
}
else {
header('Location: ' . $uri->uri);
}
}
else {
if (!empty($_SERVER['QUERY_STRING'])) {

3
ip.php
View file

@ -1,9 +1,12 @@
<?php
require_once 'include/init.php';
$output = Output::start()
$ip = new IpV4($_SERVER['REMOTE_ADDR']);
$output->add('your current internet ip address', 'notice', $ip);
Output::send();
?>

View file

@ -1,15 +1,13 @@
<?php
require_once 'include/init.php';
Output::start('html');
if (!isAuthentificated()) {
header('WWW-Authenticate: Basic realm="Administration area"');
header('HTTP/1.0 401 Unauthorized');
echo '<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>401 Authorization Required</title>
</head><body>
<h1>Authorization Required</h1>
echo '<h1>Authorization Required</h1>
<p>This server could not verify that you
are authorized to access the document
requested. Either you supplied the wrong
@ -17,10 +15,11 @@ credentials (e.g., bad password), or your
browser doesn\'t understand how to supply
the credentials required.</p>
<hr>
<address>' . $_SERVER['SERVER_SIGNATURE'] . '</address>
</body></html>';
<address>' . $_SERVER['SERVER_SIGNATURE'] . '</address>';
} else {
$output->add('authentificated as', 'notice', $_SERVER['PHP_AUTH_USER']);
}
Output::send()
?>

View file

@ -1,5 +1,6 @@
<?php
require_once 'include/init.php';
$output = Output::start('html');
?>
<div id="simple">
@ -45,3 +46,7 @@ if (!isAuthentificated())
</footer>
</div>
<?php
Output::send();
?>

View file

@ -1,6 +1,7 @@
<?php
require_once 'include/init.php';
$output = Output::start();
// http://www.dyndns.com/developers/specs/syntax.html
/*$user = $_SERVER['PHP_AUTH_USER']; // unused!
@ -92,14 +93,5 @@ else {
$output->add('zone not found', 'error', $_REQUEST['host'], $_REQUEST['zone']);
}
Output::send();
?>