-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
82 lines (64 loc) · 2.19 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?php include_once 'config/init.php';
$fnc = new Functions;
$API = new API;
// Request url: https://api.cloudflare-dyndns.com/request/?domain=example.domain.com&ip=127.0.0.1&token=CloudflareAPIToken
$fullDomain = urlencode($_GET["domain"]);
// Extract domain if record domain is subdomain (example.domain.com => domail.com)
// NOTE: This does not work on example.co.uk domains!
$secondLevelDomain = $fnc->getSecondLevelDomain($fullDomain);
// TODO: Add IPV6
$ip = $_GET['ipv4'];
$token = $_GET['token'];
if (isset($ip)) {
$fnc->ip = $ip;
}
if (isset($fullDomain)) {
$fnc->fullDomain = $fullDomain;
}
// Check if all parameters are complete
if (!isset($_GET["domain"]) || !isset($_GET['ipv4']) || !isset($_GET['token'])) {
$status = $fnc->errorMessage('Parameters incorrect.');
die($fnc->response($status, '400'));
}
// Check if ip-adress is valid
if (!filter_var($ip, FILTER_VALIDATE_IP)) {
$status = $fnc->errorMessage('Invalid IP-adress entered.');
die($fnc->response($status, '400'));
}
// TODO: Add user input to allow domain proxy
$proxied = false;
// Set authentication headers
$status = $API->initAPI($token);
if ($status !== true) {
$API->close();
die($fnc->response($status, '400'));
}
// Get domain id from cloudflare api
$domainID = $API->getDomainID($secondLevelDomain);
$userData = $API->getUserData();
$fnc->saveUserData($userData);
// if the domain id is empty, the domain does not exist on the account
if ($domainID === false) {
$status = $fnc->errorMessage('Domain not found.');
$API->close();
die($fnc->response($status, '400'));
}
// Get record information from cloudflare api
$API->getRecordInformation($domainID, $fullDomain);
$recordID = $API->getRecordID();
if ($recordID === false) {
$status = $fnc->errorMessage('Record not found.');
$API->close();
die($fnc->response($status, '400'));
}
$currentIP = $API->getRecordIP();
if ($ip == $currentIP) {
$status = $fnc->successMessage();
die($fnc->response($status, '200'));
}
$status = $API->changeRecord($domainID, $recordID, $fullDomain, $ip);
if ($status === true) {
$status = $fnc->successMessage();
die($fnc->response($status, '200'));
}
die($fnc->response($status, '400'));