-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest.php
More file actions
66 lines (51 loc) · 2.39 KB
/
Copy pathtest.php
File metadata and controls
66 lines (51 loc) · 2.39 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
55
56
57
58
59
60
61
62
63
64
65
66
<?php
include './cloudflare/CloudflareConnection.php';
include 'TestVariables.php';
$error_emoticon = '⚠️';
$success_emoticon = '☑️';
$cc = new CloudflareConnection($username, $api_key);
echo 'Authentication method: '.($cc->usesTokenAuthentication() ? 'API Token' : 'Global API Key')."\n";
$login_valid = $cc->validateLogin();
showResult($login_valid, 'Validate login', $cc);
$zone = $cc->getZone($test_domain);
showResult($zone !== null, "Get zone for {$test_domain}", $cc);
if ($zone !== null) {
$dns_records = $cc->getDnsRecordsForZone($zone['id']);
showResult($dns_records !== null, 'Get DNS records ('.count($dns_records ?? []).' found)', $cc);
$record_created = $cc->createDnsRecord($zone['id'], [
'type' => 'TXT',
'name' => 'hostfact-module-test.'.$test_domain,
'content' => 'hostfact-cloudflare-dns test record',
'ttl' => 3600,
]);
showResult(is_array($record_created) && $record_created['success'], 'Create DNS record', $cc);
if (is_array($record_created) && $record_created['success']) {
$record_updated = $cc->updateDnsRecord($zone['id'], $record_created['result']['id'], [
'type' => 'TXT',
'name' => 'hostfact-module-test.'.$test_domain,
'content' => 'hostfact-cloudflare-dns updated test record',
'ttl' => 300,
]);
showResult(is_array($record_updated) && $record_updated['success'], 'Update DNS record', $cc);
$record_deleted = $cc->deleteDnsRecord($zone['id'], $record_created['result']['id']);
showResult(is_array($record_deleted) && $record_deleted['success'], 'Delete DNS record', $cc);
}
}
if ($test_domain_creation_on !== '') {
$zone_created = $cc->createZone($test_domain_creation_on, $account_id);
showResult(is_array($zone_created) && $zone_created['success'], 'Create zone', $cc);
if (is_array($zone_created) && $zone_created['success']) {
$zone_deleted = $cc->deleteZone($zone_created['result']['id']);
showResult(is_array($zone_deleted) && $zone_deleted['success'], 'Delete zone', $cc);
}
}
function showResult(bool $success, string $description, CloudflareConnection $cc)
{
global $error_emoticon, $success_emoticon;
echo ($success ? $success_emoticon : $error_emoticon)." {$description}\n";
if (! $success) {
foreach ($cc->getErrors() as $error) {
echo "* {$error}\n";
}
}
}