-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodifydomain.php
More file actions
211 lines (175 loc) · 9.52 KB
/
modifydomain.php
File metadata and controls
211 lines (175 loc) · 9.52 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Modify Domain - regist.cc</title>
<!-- Include Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/halfmoon@2.0.0/css/halfmoon.min.css" rel="stylesheet" integrity="sha256-pfT/Otf/lK1xFNInb5QQR1uRF9cOP/8zDICH+QQ6o2c=" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.1/font/bootstrap-icons.css">
</head>
<body>
<?php include "header.php"; ?>
<!-- Header -->
<header>
<div class="container">
<div class="card bg-light mt-4">
<div class="card-body text-center">
<h1 class="display-4"><i class="bi bi-r-square"></i> Modify Domain</h1>
<p class="lead">Update or delete your subdomain information!</p>
</div>
</div>
</div>
</header>
<div class="container">
<div class="card mt-4">
<div class="card-body">
<b>Make sure to keep the URL in a safe place, like in a USB flash drive.</b>
<?php
// Cloudflare API Credentials
$apiKey = '4a74860627f5b10bd9d4fc36d17c475f1aa63';
$zoneId = '4b16fd630b65102537ebde875f4be31d';
// Function to update a DNS record in Cloudflare
function updateDNSRecord($zoneId, $recordId, $type, $content, $domain)
{
global $apiKey;
$url = "https://api.cloudflare.com/client/v4/zones/{$zoneId}/dns_records/{$recordId}";
$data = [
'content' => $content,
'name' => $domain, // Replace with the appropriate domain name
'proxied' => false,
'type' => $type,
'comment' => 'Domain verification record',
'tags' => ['owner:dns-team'],
'ttl' => 3600,
];
$headers = [
'Content-Type: application/json',
'X-Auth-Email: backuptabletinfo@gmail.com',
'X-Auth-Key: ' . $apiKey
];
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PATCH');
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Curl error: ' . curl_error($ch);
}
curl_close($ch);
return json_decode($response, true);
}
// Function to delete a DNS record in Cloudflare
function deleteDNSRecord($zoneId, $recordId)
{
global $apiKey;
$url = "https://api.cloudflare.com/client/v4/zones/{$zoneId}/dns_records/{$recordId}";
$headers = [
'Content-Type: application/json',
'X-Auth-Email: backuptabletinfo@gmail.com',
'X-Auth-Key: ' . $apiKey
];
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($ch);
curl_close($ch);
return json_decode($response, true);
}
// Database connection settings
$servername = "localhost"; // Change this to your MySQL server hostname
$username = "oujhymth_regist"; // Change this to your MySQL username
$password = "pQVpmkhTor"; // Change this to your MySQL password
$dbname = "oujhymth_regist";
// Create a new database connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check the connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Check if a request is detected
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$action = $_POST['action'];
$uniqueHash = $_POST['hash']; // Unique hash received from the form
if ($action === 'update') {
$type = $_POST['type'];
$content = $_POST['content'];
// Retrieve the record from the database using the unique hash
$sql = "SELECT * FROM subdomain_records WHERE hash = '$uniqueHash'";
$result = $conn->query($sql);
if ($result->num_rows === 1) {
$row = $result->fetch_assoc();
$recordId = $row['record_id']; // Get the Cloudflare record ID from the database
// Update DNS record
$result = updateDNSRecord($zoneId, $recordId, $type, $content, $domain);
if (isset($result['success']) && $result['success']) {
// Success
var_dump($result);
} else {
// Failure
echo 'Error updating DNS record: ' . var_dump($result);//['errors'][0]['message'];
}
} else {
echo 'Error: Invalid or expired hash.';
}
} elseif ($action === 'delete') {
// Retrieve the record from the database using the unique hash
$sql = "SELECT * FROM subdomain_records WHERE hash = '$uniqueHash'";
$result = $conn->query($sql);
if ($result->num_rows === 1) {
$row = $result->fetch_assoc();
$recordId = $row['record_id']; // Get the Cloudflare record ID from the database
$domain = $row['domain_name'];
// Delete DNS record
$result = deleteDNSRecord($zoneId, $recordId);
if ($result['success']) {
// Delete the record from the database
$deleteSql = "DELETE FROM subdomain_records WHERE hash = '$uniqueHash'";
if ($conn->query($deleteSql) === TRUE) {
echo '<h2 class="card-title">Domain deleted successfully!</h2>';
} else {
echo 'Error deleting from the database: ' . $conn->error;
}
} else {
echo 'Error deleting DNS record: ' . $result['errors'][0]['message'];
}
} else {
echo 'Error: Invalid or expired hash.';
}
}
} else {
$hash = $_GET['hash'];
echo '<form method="POST">
<h2 class="card-title">Update or Delete Domain</h2>
<input type="hidden" name="hash" value="' . $hash . '">
<div class="mb-3">
<label for="type" class="form-label">Select Record Type:</label>
<select name="type" id="type" class="form-select" required>
<option value="A">A (IPv4 Address)</option>
<option value="AAAA">AAAA (IPv6 Address)</option>
<option value="CNAME">CNAME (Alias)</option>
<option value="NS">NS (Nameservers)</option>
<option value="TXT">TXT (Text Record)</option>
</select>
</div>
<div class="mb-3 input-group-lg">
<label for="content" class="form-label">Enter New Destination:</label>
<input type="text" name="content" id="content" class="form-control" placeholder="e.g., 192.168.0.1 or example.com" required>
</div>
<div class="mb-3 input-group-lg">
<button type="submit" name="action" value="update" class="btn btn-primary">Update Domain</button>
<button type="submit" name="action" value="delete" class="btn btn-danger">Delete Domain</button>
</div>
</form>';
}
// Close the database connection
$conn->close();
?>
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.1/dist/js/bootstrap.bundle.min.js" integrity="sha384-HwwvtgBNo3bZJJLYd8oVXjrBZt8cqVSpeBNS5n7C8IVInixGAoxmnlMuBnhbgrkm" crossorigin="anonymous"></script>
</body>
</html>