-
Notifications
You must be signed in to change notification settings - Fork 1
/
client_example.php
90 lines (79 loc) · 2.19 KB
/
client_example.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
83
84
85
86
87
88
89
90
<?php
require_once 'vendor/autoload.php';
use Namingo\Bind9Api\ApiClient;
try {
// Initialize the client with the API server's base URL
$apiClient = new ApiClient('http://localhost:7650');
// Authenticate and obtain a token
$apiClient->login('admin', 'password123');
// 1. List all zones
$zones = $apiClient->getZones();
echo "Zones:\n";
print_r($zones);
// 2. Add a new zone
/*
$newZone = 'example.com';
$addZoneResponse = $apiClient->addZone($newZone);
echo "Add Zone Response:\n";
print_r($addZoneResponse);
*/
// 3. Delete a zone
/*
$zoneToDelete = 'example.com';
$deleteZoneResponse = $apiClient->deleteZone($zoneToDelete);
echo "Delete Zone Response:\n";
print_r($deleteZoneResponse);
*/
// 4. List records in a zone
/*
$zoneName = 'example.com';
$records = $apiClient->getRecords($zoneName);
echo "Records in {$zoneName}:\n";
print_r($records);
*/
// 5. Add a DNS record
/*
$zoneName = 'example.com';
$record = [
'name' => 'www',
'type' => 'A',
'ttl' => 3600,
'rdata' => '192.0.2.1'
];
$addRecordResponse = $apiClient->addRecord($zoneName, $record);
echo "Add Record Response:\n";
print_r($addRecordResponse);
*/
// 6. Update a DNS record
/*
$zoneName = 'example.com';
// Define the current record to identify it
$currentRecord = [
'name' => 'www',
'type' => 'A',
'rdata' => '192.0.2.1'
];
// Define the new data for the record
$newRecord = [
'rdata' => '192.0.2.2'
];
$updateRecordResponse = $apiClient->updateRecord($zoneName, $currentRecord, $newRecord);
echo "Update Record Response:\n";
print_r($updateRecordResponse);
*/
// 7. Delete a DNS record
/*
$zoneName = 'example.com';
// Define the record to delete
$record = [
'name' => 'www',
'type' => 'A',
'rdata' => '192.0.2.2'
];
$deleteRecordResponse = $apiClient->deleteRecord($zoneName, $record);
echo "Delete Record Response:\n";
print_r($deleteRecordResponse);
*/
} catch (Exception $e) {
echo "Error: " . $e->getMessage() . "\n";
}