-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.php
66 lines (58 loc) · 1.96 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
/**
* Insert as followed into FritzBox: somedomain.net/path/dynbind.php?hostname=<domain>&myip=<ipaddr>
* user and password will be automatically send
*
*
* @license http://www.gnu.org/licenses/lgpl-3.0.txt GNU LESSER GENERAL PUBLIC LICENSE
*/
require_once 'DynBind/log.php';
require_once 'DynBind/Config.php';
require_once 'DynBind/NsUpdateDnsUpdater.php';
require_once 'DynBind/DynDotComProtocol.php';
$conf = new Config();
foreach(array('dynbind.conf.xml', '/etc/dynbind.conf.xml') as $conffile){
try{
$conf->load($conffile);
break;
} catch(Exception $e){
continue;
}
}
if(!$conf->isLoaded()){
die(UpdateStatus::STATUS_INTERNAL_ERROR." - service not configured");
}
log::setFile($conf->getLogfile());
log::setLevel($conf->getLoglevel());
// Init Input Protocols
$protocol = new DynDotComProtocol($conf);
foreach($conf->getAuthMethods() as $method){
$protocol->addAuthMethod($method=='basic'?DynDotComProtocol::AUTH_BASIC:DynDotComProtocol::AUTH_DIGEST);
}
$protocol->setAuthRealm($conf->getAuthRealm());
try{
$protocol->parseRequest($_SERVER, $_GET, $_POST);
$user = $protocol->getUser();
$update_stati = array();
foreach($protocol->getEntries() as $entry){
if($user->ownsDnsEntry($entry)){ /* @var $entry DnsEntry */
foreach($conf->getZones() as $zone){ /* @var $zone Zone */
if($zone->containsDnsEntry($entry)){
$update_stati[] = $zone->getUpdater()->update($entry);
break;
}
}
} else {
log::write("denied user $user->name updating $entry->name to $entry->entry", 3);
$update_stati[] = new UpdateStatus(UpdateStatus::STATUS_AUTH_ERROR, $entry);
}
}
$protocol->answerRequest($update_stati);
log::write("send headers:\n".implode("\n",headers_list()), 4);
exit();
} catch(Exception $e){
log::write($e->getMessage(), 3);
$protocol->answerRequest(array(new UpdateStatus($e->getCode())));
log::write("send headers:\n".implode("\n",headers_list()), 4);
exit();
}