2010-08-17 01:23:57 +02:00
|
|
|
<?php
|
2013-04-23 16:18:48 +02:00
|
|
|
/**
|
|
|
|
* Update action
|
|
|
|
*
|
|
|
|
* @copyright 2013 Steffen Vogel
|
|
|
|
* @license http://www.gnu.org/licenses/gpl.txt GNU Public License
|
|
|
|
* @author Steffen Vogel <post@steffenvogel.de>
|
|
|
|
* @link http://www.steffenvogel.de
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* This file is part of sddns
|
|
|
|
*
|
|
|
|
* sddns is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* any later version.
|
|
|
|
*
|
|
|
|
* sddns is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with sddns. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2010-08-17 01:23:57 +02:00
|
|
|
|
|
|
|
require_once 'include/init.php';
|
2017-08-05 17:29:32 +02:00
|
|
|
|
2010-10-07 14:22:51 +02:00
|
|
|
$output = Output::start();
|
2010-08-17 01:23:57 +02:00
|
|
|
|
2017-08-05 17:29:32 +02:00
|
|
|
// default arguments
|
|
|
|
$ttl = (!empty($_REQUEST['ttl'])) ? $_REQUEST['ttl'] : $config['sddns']['std']['ttl'];
|
|
|
|
$class = (!empty($_REQUEST['class'])) ? $_REQUEST['class'] : $config['sddns']['std']['class'];
|
|
|
|
$rdata = (!empty($_REQUEST['rdata'])) ? $_REQUEST['rdata'] : $_SERVER['REMOTE_ADDR'];
|
|
|
|
|
|
|
|
// zone
|
|
|
|
if (!empty($_REQUEST['zone'])) {
|
|
|
|
if (array_key_exists($_REQUEST['zone'], $config['sddns']['zones'])) {
|
|
|
|
$zone = $config['sddns']['zones'][$_REQUEST['zone']];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
throw new UserException('invalid zone', $_REQUEST['zone']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
throw new UserException('missing zone');
|
|
|
|
}
|
|
|
|
|
2010-08-17 01:23:57 +02:00
|
|
|
// password
|
|
|
|
if (!empty($_REQUEST['pw'])) {
|
|
|
|
$pw = $_REQUEST['pw'];
|
|
|
|
}
|
2017-08-05 17:29:32 +02:00
|
|
|
else if (!empty($_SERVER['PHP_AUTH_PW'])) {
|
|
|
|
$pw = $_SERVER['PHP_AUTH_PW'];
|
|
|
|
}
|
2013-03-08 03:13:47 +01:00
|
|
|
else {
|
2017-08-05 17:29:32 +02:00
|
|
|
throw new AuthentificationException('missing password');
|
2010-08-17 01:23:57 +02:00
|
|
|
}
|
|
|
|
|
2017-08-05 17:29:32 +02:00
|
|
|
// type
|
|
|
|
if (!empty($_REQUEST['type'])) {
|
|
|
|
if (in_array($_REQUEST['type'], $config['sddns']['types'])) {
|
|
|
|
$type = $_REQUEST['type'];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
throw new UserException('invalid type');
|
2010-08-17 01:23:57 +02:00
|
|
|
}
|
|
|
|
}
|
2017-08-05 17:29:32 +02:00
|
|
|
else if (IpV4::isValid($rdata)) {
|
|
|
|
$type = 'A';
|
2010-08-17 01:23:57 +02:00
|
|
|
}
|
2017-08-05 17:29:32 +02:00
|
|
|
else if (IpV6::isValid($rdata)) {
|
|
|
|
$type = 'AAAA';
|
2010-08-17 01:23:57 +02:00
|
|
|
}
|
2017-08-05 17:29:32 +02:00
|
|
|
else {
|
|
|
|
throw new UserException('missing type');
|
2010-08-17 01:23:57 +02:00
|
|
|
}
|
2017-08-05 17:29:32 +02:00
|
|
|
|
|
|
|
// search host
|
|
|
|
if (!empty($_REQUEST['host'])) {
|
|
|
|
$host = new Host($_REQUEST['host'], $zone);
|
|
|
|
|
|
|
|
if ($host->isRegistred($db)) {
|
|
|
|
$host = new DBHost($host->isRegistred($db), $db);
|
|
|
|
$output->add('found existing host', 'success', $host);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
throw new UserException('host not found', $_REQUEST['host']);
|
|
|
|
}
|
2010-08-17 01:23:57 +02:00
|
|
|
}
|
|
|
|
else {
|
2017-08-05 17:29:32 +02:00
|
|
|
throw new UserException('missing host');
|
2010-08-17 01:23:57 +02:00
|
|
|
}
|
|
|
|
|
2017-08-05 17:29:32 +02:00
|
|
|
if ($host->checkPassword($pw) || isAuthentificated()) {
|
|
|
|
// search entries
|
|
|
|
if ($type == 'URL') {
|
|
|
|
$entries = DBUri::get($db, array('host' => $host, 'zone' => $zone));
|
2010-08-17 01:23:57 +02:00
|
|
|
}
|
|
|
|
else {
|
2017-08-05 17:29:32 +02:00
|
|
|
$entries = DBRecord::get($db, array('host' => $host, 'zone' => $zone, 'class' => $class, 'type' => $type));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (empty($entries)) {
|
|
|
|
throw new UserException('no records found to update');
|
2010-08-17 01:23:57 +02:00
|
|
|
}
|
2017-08-05 17:29:32 +02:00
|
|
|
|
|
|
|
$entry = array_shift($entries);
|
|
|
|
|
|
|
|
if ($type == 'URL') {
|
|
|
|
$entry->frame = (isset($_REQUEST['frame']) && $_REQUEST['frame']) ? 1 : 0;
|
|
|
|
$entry->setUri($rdata);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$entry->setTtl($ttl);
|
|
|
|
$entry->setRData($rdata);
|
|
|
|
}
|
|
|
|
|
|
|
|
$entry->lastAccessed = time();
|
|
|
|
$entry->update();
|
|
|
|
|
|
|
|
$output->add('entry updated in db', 'success', $entry);
|
|
|
|
|
|
|
|
// delete other entries
|
|
|
|
foreach ($entries as $entry) {
|
|
|
|
$entry->delete();
|
|
|
|
$output->add('record deleted from db', 'warning', $entry);
|
|
|
|
}
|
|
|
|
|
|
|
|
$zone->cleanup($db);
|
|
|
|
$zone->sync($db);
|
2010-08-17 01:23:57 +02:00
|
|
|
}
|
|
|
|
else {
|
2017-08-05 17:29:32 +02:00
|
|
|
throw new AuthentificationException('not authentificated for host', $host);
|
2010-08-17 01:23:57 +02:00
|
|
|
}
|