-
Notifications
You must be signed in to change notification settings - Fork 1
/
dyndnsda.php
73 lines (59 loc) · 1.77 KB
/
dyndnsda.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
67
68
69
70
71
72
73
<?php
/*
* Example of config.inc.php
*
* <?php
*
* return array(
* "username" => "username",
* "password" => "password",
* "url" => "https://myhostingprovider.com:2222",
* "domain" => "domain.name.in.admin.panel.to.use"
* );
*/
$config = include 'config.inc.php';
function DARequest($request) {
global $config;
$headers = array (
'Authorization: Basic ' . base64_encode ( $config ['username'] . ':' . $config ['password'] )
);
$ch = curl_init ();
curl_setopt_array ( $ch, array (
CURLOPT_HTTPHEADER => $headers,
CURLOPT_URL => $config ['url'] . "/$request",
CURLOPT_FAILONERROR => 1,
CURLOPT_TIMEOUT => 15,
CURLOPT_RETURNTRANSFER => 1
) );
if (isset ( $config ['curlopts'] )) {
curl_setopt_array ( $ch, $config ['curlopts'] );
}
$res = curl_exec ( $ch );
if (! $res) {
error_log ( "CONNECTION ERROR " . curl_errno ( $ch ) . ": " . curl_error ( $ch ) );
}
curl_close ( $ch );
return $res;
}
$ddns_name = strtolower ( $_GET ['name'] ? $_GET ['name'] : $argv [1] );
$ddns_ip = $_SERVER ['REMOTE_ADDR'] ? $_SERVER ['REMOTE_ADDR'] : $argv [2];
$exists = false;
$dnsconf = DARequest ( 'CMD_API_DNS_CONTROL?domain=' . $config ['domain'] );
foreach ( explode ( "\n", $dnsconf ) as $row ) {
list ( $name, $ttl, $in, $type, $value ) = explode ( "\t", $row );
$name = strtolower ( $name );
if ($type == "A") {
if ($name == $ddns_name) {
if ($value == $ddns_ip) {
$exists = true;
} else {
DARequest ( 'CMD_API_DNS_CONTROL?domain=' . $config ['domain'] . '&action=select&arecs0=' . urlencode ( "name=$name&value=$value" ) );
}
}
}
}
if (! $exists) {
DARequest ( 'CMD_API_DNS_CONTROL?domain=' . $config ['domain'] . "&action=add&type=A&name=$ddns_name&value=$ddns_ip" );
}
echo $ddns_name . '.' . $config ['domain'] . ' ' . $ddns_ip;
?>