-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdnsapi.php_default
More file actions
55 lines (51 loc) · 1.36 KB
/
Copy pathdnsapi.php_default
File metadata and controls
55 lines (51 loc) · 1.36 KB
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
<?php
$file='/usr/local/dnspod-sr/conf/root.z';
$method = $_SERVER['REQUEST_METHOD'];
parse_str(file_get_contents('php://input'), $data);
$domain=$data['domain'];
$ip=$data['ip'];
$ttl=$data['ttl'];
$type=$data['type'];
$new_ip=$data['newip'];
if ($method == "POST") {
if ($ttl == "" || $type == "") {
$ttl="36000";
$type="A";
}
if ($domain == "" || $ip == "") {
echo "no domain or ip";
exit;
}
$str=($domain.". ".$ttl." IN ".$type." ".$ip."\n");
$content = file_get_contents($file);
file_put_contents($file,$str.$content);
}
elseif ($method == "DELETE") {
$content=file($file);
foreach($content as $key => $values) {
if (strpos($values,$domain) !== false && strpos($values,$ip)) {
unset($content[$key]);
}
}
file_put_contents($file,$content);
}
elseif ($method == "UPDATE") {
$content=file($file);
foreach($content as $key => $values) {
if (strpos($values,$domain) !== false && strpos($values,$ip)) {
$n=$content[$key];
$content[$key]=str_replace($ip,$new_ip,$n);
}
}
file_put_contents($file,$content);
}
elseif ($method == "SELECT"){
$content=file($file);
foreach($content as $key => $values) {
if (strpos($values,$domain) !== false || strpos($values,$ip)) {
$str=explode(" ",$content[$key]);
echo json_encode(array('IP' => chop($str[4]),'Type' => $str[3],'TTL' => $str[1],'Domain' => $str[0] ));
}
}
}
?>