updated frontend and added unnlimited lifetime
This commit is contained in:
parent
1d02c63f3f
commit
1ebd1e0a92
8 changed files with 113 additions and 67 deletions
21
add.php
21
add.php
|
@ -10,15 +10,23 @@ if (array_key_exists($_REQUEST['zone'], $config['sddns']['zones'])) {
|
|||
$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 {
|
||||
if (isset($_REQUEST['lifetime']) && is_numeric($_REQUEST['lifetime'])) {
|
||||
$lifetime = (int) $_REQUEST['lifetime'];
|
||||
}
|
||||
else {
|
||||
$lifetime = $config['sddns']['std']['lifetime'];
|
||||
}
|
||||
|
||||
if (($lifetime > $config['sddns']['max_lifetime'] && !isAuthentificated()) || $lifetime < 0) {
|
||||
if ($lifetime < 0) {
|
||||
$output->add('invalid lifetime', 'error', $lifetime);
|
||||
$output->send();
|
||||
die();
|
||||
}
|
||||
|
||||
if (($lifetime > $config['sddns']['max_lifetime'] || $lifetime == 0) && !isAuthentificated()) {
|
||||
$output->add('lifetime exceeds limit', 'error');
|
||||
$output->send();
|
||||
die();
|
||||
}
|
||||
|
||||
if ($host->isRegistred($db)) {
|
||||
|
@ -41,8 +49,9 @@ if (array_key_exists($_REQUEST['zone'], $config['sddns']['zones'])) {
|
|||
$host = $host->add($pw, $db); // returns new DBHost
|
||||
$output->add('host added to db' ,'notice', $host);
|
||||
|
||||
if (empty($_REQUEST['pw']))
|
||||
if (empty($_REQUEST['pw'])) {
|
||||
$output->add('generated password' ,'notice', $pw);
|
||||
}
|
||||
}
|
||||
|
||||
if ($type != 'URL') { // pseudo type to create url redirection
|
||||
|
|
40
admin/index.php
Executable file
40
admin/index.php
Executable file
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
require_once '../include/init.php';
|
||||
|
||||
$output = Output::start('html');
|
||||
|
||||
$output->add('hits since launch', 'notice', $site['hits']);
|
||||
|
||||
if (isAuthentificated()) {
|
||||
$output->add('authetificated as', 'notice', $_SERVER['PHP_AUTH_USER']);
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
<div id="admin">
|
||||
<div style="float: right;"><a href="http://0l.de"><img src="../images/nulll_small.png" alt="/dev/nulll" /></a></div>
|
||||
<h1>Tiny DNS & URL</h1>
|
||||
<h3>Administration interface</h3>
|
||||
<p>by <a href="http://www.steffenvogel.de">Steffen Vogel</a></p>
|
||||
<hr style="clear: both;" />
|
||||
|
||||
<ul>
|
||||
<li><a href="cleanup">cleanup</a></li>
|
||||
<li><a href="get">get</a></li>
|
||||
<li><a href="parse">parse</a></li>
|
||||
<li><a href="sync">sync</a></li>
|
||||
</ul>
|
||||
|
||||
<hr />
|
||||
<a href="../expert">expert 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$
|
||||
<a href="javascript:installSearchEngine('<?php echo $site['url']; ?>/opensearch.xml');">search plugin</a>
|
||||
<address><?php echo $_SERVER['SERVER_SIGNATURE']; ?></address>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
$output->send();
|
||||
?>
|
21
expert.php
21
expert.php
|
@ -10,7 +10,7 @@ if (isAuthentificated()) {
|
|||
}
|
||||
|
||||
$ttl = (isset($_REQUEST['ttl'])) ? $_REQUEST['ttl'] : $config['sddns']['std']['ttl'];
|
||||
$lifetime = (isset($_REQUEST['lifetime'])) ? $_REQUEST['lifetime'] : $config['sddns']['std']['lifetime'];
|
||||
$lifetime = (isset($_REQUEST['lifetime'])) ? $_REQUEST['lifetime'] : (isAuthentificated()) ? 0 : $config['sddns']['std']['lifetime'];
|
||||
$checkedClass = (isset($_REQUEST['class'])) ? $_REQUEST['class'] : $config['sddns']['std']['class'];
|
||||
$checkedType = (isset($_REQUEST['type'])) ? $_REQUEST['type'] : $config['sddns']['std']['type'];
|
||||
|
||||
|
@ -18,7 +18,7 @@ $checkedType = (isset($_REQUEST['type'])) ? $_REQUEST['type'] : $config['sddns']
|
|||
<div id="expert">
|
||||
<div style="float: right;"><a href="http://0l.de"><img src="images/nulll_small.png" alt="/dev/nulll" /></a></div>
|
||||
<h1>Tiny DNS & URL</h1>
|
||||
<h3>aka SDDNS - <b>S</b>imple <b>D</b>ynamic <b>D</b>omain <b>N</b>ame <b>S</b>ervice</h3>
|
||||
<h3>Expert interface</h3>
|
||||
<p>by <a href="http://www.steffenvogel.de">Steffen Vogel</a></p>
|
||||
<hr style="clear: both;" />
|
||||
<form onsubmit="submit_expert(this);" method="post">
|
||||
|
@ -58,7 +58,7 @@ $checkedType = (isset($_REQUEST['type'])) ? $_REQUEST['type'] : $config['sddns']
|
|||
|
||||
</select></td><td>optional; random or servername</td></tr>
|
||||
<tr><td><label for="ttl">ttl</label></td><td><input type="text" name="ttl" value="<?php echo $ttl; ?>" /> seconds</td><td>time to live in cache; max <?php echo $config['sddns']['max_ttl']; ?> seconds</td></tr>
|
||||
<tr><td><label for="lifetime">lifetime</label></td><td><input type="text" name="lifetime" value="<?php echo $lifetime; ?>" /> seconds</td><td>lifetime of a record/url without an update; max <?php echo $config['sddns']['max_lifetime']; ?></td></tr>
|
||||
<tr><td><label for="lifetime">lifetime</label></td><td><input type="text" name="lifetime" value="<?php echo $lifetime; ?>" /> seconds</td><td>lifetime of a record/url without being updated/touched; max <?php echo (isAuthentificated()) ? '0 (unlimited)' : $config['sddns']['max_lifetime']; ?></td></tr>
|
||||
<tr>
|
||||
<td><label for="class">class</label></td>
|
||||
<td><select name="class" size="1">
|
||||
|
@ -88,16 +88,17 @@ $checkedType = (isset($_REQUEST['type'])) ? $_REQUEST['type'] : $config['sddns']
|
|||
|
||||
</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> -
|
||||
<a href="javascript:installSearchEngine('<?php echo $site['url']; ?>/opensearch.xml');">search plugin</a>
|
||||
</form>
|
||||
|
||||
<hr />
|
||||
<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> -
|
||||
<a href="javascript:installSearchEngine('<?php echo $site['url']; ?>/opensearch.xml');">search plugin</a>
|
||||
<address><?php echo $_SERVER['SERVER_SIGNATURE']; ?></address>
|
||||
|
||||
</div>
|
||||
|
||||
<?php
|
||||
|
|
|
@ -189,6 +189,14 @@ class HtmlOutput extends Output {
|
|||
|
||||
protected function getOutput() {
|
||||
$site = Registry::get('site');
|
||||
$columnCount = 0;
|
||||
$messages = $this->getMessages();
|
||||
$html = ob_get_clean();
|
||||
|
||||
foreach ($messages as $message) {
|
||||
if (count($message['data']) > $columnCount)
|
||||
$columnCount = count($message['data']);
|
||||
}
|
||||
|
||||
$str = '<?xml version="1.0" ?>
|
||||
<!DOCTYPE html>
|
||||
|
@ -204,16 +212,11 @@ class HtmlOutput extends Output {
|
|||
</head>
|
||||
<body>';
|
||||
|
||||
$maxDataCount = 0;
|
||||
$messages = $this->getMessages();
|
||||
foreach ($messages as $message) {
|
||||
if (count($message['data']) > $maxDataCount)
|
||||
$maxDataCount = count($message['data']);
|
||||
}
|
||||
$str .= '<div id="content">' . $html . '</div>';
|
||||
|
||||
if (count($messages)) {
|
||||
$str .= '<table id="messages">
|
||||
<tr><th>type</th><th>index</th><th>time</th><th>description</th><th colspan="100">data</th></tr>';
|
||||
$str .= '<table id="messages" style="' . ((strlen($html)) ? 'bottom' : 'top') . ': 0">
|
||||
<tr><th class="type">type</th><th class="index">index</th><th class="time">time</th><th>description</th><th colspan="100">data</th></tr>';
|
||||
|
||||
foreach ($messages as $index => $message) {
|
||||
$str .= '<tr class="' . $message['type'] . '">
|
||||
|
@ -222,7 +225,7 @@ class HtmlOutput extends Output {
|
|||
<td>' . date('Y-m-d H:i:s', $message['time']) . '</td>
|
||||
<td>' . $message['description'] . '</td>';
|
||||
|
||||
for($i = 0; $i < $maxDataCount; $i++) {
|
||||
for($i = 0; $i < $columnCount; $i++) {
|
||||
$str .= '<td>';
|
||||
if (isset($message['data'][$i])) {
|
||||
$data = $message['data'][$i];
|
||||
|
@ -242,11 +245,7 @@ class HtmlOutput extends Output {
|
|||
$str .= '</table>';
|
||||
}
|
||||
|
||||
$str .= '<div id="content">';
|
||||
$str .= ob_get_clean();
|
||||
$str .= '</div>
|
||||
</body>
|
||||
</html>';
|
||||
$str .= '</body></html>';
|
||||
|
||||
return $str;
|
||||
}
|
||||
|
|
|
@ -29,18 +29,6 @@ function fade(elm) {
|
|||
}
|
||||
}
|
||||
|
||||
function slide_iframe(elm, currheight, maxheight, addheight) {
|
||||
var newheight = currheight + addheight;
|
||||
|
||||
elm.style.height = newheight + "px";
|
||||
|
||||
if (newheight < maxheight) {
|
||||
window.setTimeout(function() {
|
||||
slide_iframe(elm, newheight, maxheight, addheight);
|
||||
}, 30);
|
||||
}
|
||||
}
|
||||
|
||||
function installSearchEngine(openSearchXml) {
|
||||
if (window.external && ("AddSearchProvider" in window.external)) {
|
||||
window.external.AddSearchProvider(openSearchXml);
|
||||
|
@ -71,13 +59,3 @@ document.onmousemove = function() {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
window.onload = function () {
|
||||
var ifr = parent.document.getElementById('ifr');
|
||||
if (ifr) {
|
||||
var msgs = parent.frames.ifr.document.getElementById('messages');
|
||||
if (msgs) {
|
||||
slide_iframe(ifr, 0, msgs.clientHeight, 5)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,20 +16,25 @@ h3 {
|
|||
margin-top: 5px;
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
|
||||
dl {
|
||||
width: 300px;
|
||||
margin: auto;
|
||||
}
|
||||
|
||||
dt {
|
||||
float: left;
|
||||
}
|
||||
|
||||
dt a {
|
||||
color: #555
|
||||
}
|
||||
|
||||
dd {
|
||||
text-align: right;
|
||||
padding-bottom: 4px
|
||||
}
|
||||
|
||||
hr {
|
||||
border: 1px solid #000000;
|
||||
height: 1px;
|
||||
|
@ -45,6 +50,15 @@ td, th {
|
|||
border: 1px solid grey;
|
||||
}
|
||||
|
||||
th.index,
|
||||
th.type {
|
||||
width: 40px;
|
||||
}
|
||||
|
||||
th.time {
|
||||
width: 170px;
|
||||
}
|
||||
|
||||
a img {
|
||||
border: 0px;
|
||||
}
|
||||
|
@ -57,8 +71,9 @@ iframe {
|
|||
|
||||
#messages {
|
||||
width: 100%;
|
||||
padding: 0px;
|
||||
margin: 1px 1px 1px 1px;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
position: absolute;
|
||||
}
|
||||
|
||||
#content {
|
||||
|
|
|
@ -29,25 +29,30 @@ class Zone extends NameServer implements Object {
|
|||
$sql = 'DELETE r FROM ' . $config['db']['tbl']['records'] . ' AS r
|
||||
LEFT JOIN ' . $config['db']['tbl']['hosts'] . ' AS h
|
||||
ON h.id = r.host_id
|
||||
WHERE
|
||||
((r.last_accessed + INTERVAL r.lifetime SECOND) < NOW() &&
|
||||
h.zone = \'' . $db->escape($this->name) . '\') || h.id IS NULL';
|
||||
WHERE (
|
||||
(r.last_accessed + INTERVAL r.lifetime SECOND) < NOW()
|
||||
&& h.zone = \'' . $db->escape($this->name) . '\'
|
||||
&& r.lifetime != 0
|
||||
) || h.id IS NULL';
|
||||
|
||||
$db->execute($sql);
|
||||
if ($db->affectedRows() > 0)
|
||||
if ($db->affectedRows() > 0) {
|
||||
$output->add('records deleted from db', 'success', $db->affectedRows(), $this);
|
||||
}
|
||||
|
||||
// expired urls & uris without host
|
||||
$sql = 'DELETE u FROM ' . $config['db']['tbl']['uris'] . ' AS u
|
||||
LEFT JOIN ' . $config['db']['tbl']['hosts'] . ' AS h
|
||||
ON h.id = u.host_id
|
||||
WHERE
|
||||
((u.last_accessed + INTERVAL u.lifetime SECOND) < NOW() &&
|
||||
h.zone = \'' . $db->escape($this->name) . '\') || h.id IS NULL';
|
||||
WHERE (
|
||||
(u.last_accessed + INTERVAL u.lifetime SECOND) < NOW()
|
||||
&& h.zone = \'' . $db->escape($this->name) . '\'
|
||||
&& u.lifetime != 0
|
||||
) || h.id IS NULL';
|
||||
|
||||
$db->execute($sql);
|
||||
if ($db->affectedRows() > 0)
|
||||
if ($db->affectedRows() > 0) {
|
||||
$output->add('urls deleted from db', 'success', $db->affectedRows(), $this);
|
||||
}
|
||||
|
||||
// hosts without records or url
|
||||
$sql = 'DELETE h
|
||||
|
@ -61,8 +66,9 @@ class Zone extends NameServer implements Object {
|
|||
h.zone = \'' . $db->escape($this->name) . '\'';
|
||||
|
||||
$db->execute($sql);
|
||||
if ($db->affectedRows() > 0)
|
||||
if ($db->affectedRows() > 0) {
|
||||
$output->add('hosts deleted from db', 'success', $db->affectedRows(), $this);
|
||||
}
|
||||
}
|
||||
|
||||
public function sync(Database $db) {
|
||||
|
|
|
@ -9,7 +9,7 @@ $output = Output::start('html');
|
|||
<h1>Tiny DNS & URL</h1>
|
||||
</header>
|
||||
|
||||
<form name="formular" target="ifr" action="add.php" method="post" onsubmit="submit_simple(this);">
|
||||
<form name="formular" action="add.html" method="post" onsubmit="submit_simple(this);">
|
||||
<dl>
|
||||
<dt><label for="host"><a href="http://de.wikipedia.org/wiki/Domain">Domain</a></label></dt>
|
||||
<dd>
|
||||
|
@ -38,8 +38,6 @@ if (!isAuthentificated()) {
|
|||
<input type="hidden" name="type" value="A" />
|
||||
</form>
|
||||
|
||||
<iframe name="ifr" id="ifr"></iframe>
|
||||
|
||||
<footer>
|
||||
<p>by <a href="http://www.steffenvogel.de">Steffen Vogel</a> - <a href="expert">expert mode</a> - <a href="http://0l.de/projects/sddns/usage">usage help</a> - <a href="javascript:installSearchEngine('<?php echo $site['url']; ?>/opensearch.xml');">searchplugin</a></p>
|
||||
<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"><img style="margin-bottom: -6px;" src="images/bookmarklet.gif" alt="/dev/nulll/url bookmarklet" /></a> drag this button into your bookmarks for creating tiny urls easily!<p>
|
||||
|
|
Loading…
Add table
Reference in a new issue