-
Notifications
You must be signed in to change notification settings - Fork 42
/
index.php
329 lines (284 loc) · 12.8 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
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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
<?php
/*
* Copyright 2011-2021 Li Kexian
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* DNSPod API PHP Web 示例
* https://www.likexian.com/
*/
error_reporting(0);
header('Content-type:text/html; charset=utf-8');
require './dnspod.php';
$dnspod = new dnspod();
@session_start();
if ($_GET['action'] == 'domainlist') {
if ($_POST['token_id'] == '') {
if ($_SESSION['token_id'] == '') {
$dnspod->message('danger', '请输入Token ID。', -1);
}
} else {
$_SESSION['token_id'] = $_POST['token_id'];
}
if ($_POST['token_key'] == '') {
if ($_SESSION['token_key'] == '') {
$dnspod->message('danger', '请输入Token Key。', -1);
}
} else {
$_SESSION['token_key'] = $_POST['token_key'];
}
$response = $dnspod->api_call('Domain.List', array());
$list = '';
$domain_sub = file_get_contents('./template/domain_sub.html');
foreach ($response['domains'] as $id => $domain) {
$list_sub = str_replace('{{id}}', $domain['id'], $domain_sub);
$list_sub = str_replace('{{domain}}', $domain['name'], $list_sub);
$list_sub = str_replace('{{grade}}', $dnspod->grade_list[$domain['grade']], $list_sub);
$list_sub = str_replace('{{status}}', $dnspod->status_list[$domain['status']], $list_sub);
$list_sub = str_replace('{{status_new}}', $domain['status'] == 'pause' ? 'enable' : 'disable', $list_sub);
$list_sub = str_replace('{{status_text}}', $domain['status'] == 'pause' ? '启用' : '暂停', $list_sub);
$list_sub = str_replace('{{records}}', $domain['records'], $list_sub);
$list_sub = str_replace('{{updated_on}}', $domain['updated_on'], $list_sub);
$list .= $list_sub;
}
$text = $dnspod->get_template('domain');
$text = str_replace('{{title}}', '域名列表', $text);
$text = str_replace('{{list}}', $list, $text);
} elseif ($_GET['action'] == 'domaincreate') {
if ($_POST['domain'] == '') {
$dnspod->message('danger', '参数错误。', -1);
}
$response = $dnspod->api_call('Domain.Create', array('domain' => $_POST['domain']));
$dnspod->message('success', '添加成功。', '?action=domainlist');
} elseif ($_GET['action'] == 'domainstatus') {
if ($_GET['domain_id'] == '') {
$dnspod->message('danger', '参数错误。', -1);
}
if ($_GET['status'] == '') {
$dnspod->message('danger', '参数错误。', -1);
}
$response = $dnspod->api_call('Domain.Status', array('domain_id' => $_GET['domain_id'], 'status' => $_GET['status']));
$dnspod->message('success', ($_GET['status'] == 'enable' ? '启用' : '暂停') . '成功。', '?action=domainlist');
} elseif ($_GET['action'] == 'domainremove') {
if ($_GET['domain_id'] == '') {
$dnspod->message('danger', '参数错误。', -1);
}
$response = $dnspod->api_call('Domain.Remove', array('domain_id' => $_GET['domain_id']));
$dnspod->message('success', '删除成功。', '?action=domainlist');
} elseif ($_GET['action'] == 'recordlist') {
if ($_GET['domain_id'] == '') {
$dnspod->message('danger', '参数错误。', -1);
}
$response = $dnspod->api_call('Record.List', array('domain_id' => $_GET['domain_id']));
$list = '';
$record_sub = file_get_contents('./template/record_sub.html');
foreach ($response['records'] as $id => $record) {
$list_sub = str_replace('{{domain_id}}', $_GET['domain_id'], $record_sub);
$list_sub = str_replace('{{id}}', $record['id'], $list_sub);
$list_sub = str_replace('{{name}}', $record['name'], $list_sub);
$list_sub = str_replace('{{value}}', $record['value'], $list_sub);
$list_sub = str_replace('{{type}}', $record['type'], $list_sub);
$list_sub = str_replace('{{line}}', $record['line'], $list_sub);
$list_sub = str_replace('{{enabled}}', $record['enabled'] ? '启用' : '暂停', $list_sub);
$list_sub = str_replace('{{status_new}}', $record['enabled'] ? 'disable' : 'enable', $list_sub);
$list_sub = str_replace('{{status_text}}', $record['enabled'] ? '暂停' : '启用', $list_sub);
$list_sub = str_replace('{{mx}}', $record['mx'] ? $record['mx'] : '-', $list_sub);
$list_sub = str_replace('{{ttl}}', $record['ttl'], $list_sub);
$list_sub = str_replace('{{remark}}', $record['remark'], $list_sub);
$list .= $list_sub;
}
$text = $dnspod->get_template('record');
$text = str_replace('{{title}}', '记录列表 - ' . $response['domain']['name'], $text);
$text = str_replace('{{list}}', $list, $text);
$text = str_replace('{{domain_id}}', $response['domain']['id'], $text);
$text = str_replace('{{grade}}', $response['domain']['grade'], $text);
} elseif ($_GET['action'] == 'recordcreatef') {
if ($_GET['domain_id'] == '') {
$dnspod->message('danger', '参数错误。', -1);
}
if (!$_SESSION['type_' . $_GET['grade']]) {
$response = $dnspod->api_call('Record.Type', array('domain_grade' => $_GET['grade']));
$_SESSION['type_' . $_GET['grade']] = $response['types'];
}
if (!$_SESSION['line_' . $_GET['domain_id']]) {
$response = $dnspod->api_call('Record.Line',
array('domain_id' => $_GET['domain_id'], 'domain_grade' => $_GET['grade']));
$_SESSION['line_' . $_GET['domain_id']] = $response['lines'];
}
$type_list = '';
foreach ($_SESSION['type_' . $_GET['grade']] as $key => $value) {
$type_list .= '<option value="' . $value . '">' . $value . '</option>';
}
$line_list = '';
foreach ($_SESSION['line_' . $_GET['domain_id']] as $key => $value) {
$line_list .= '<option value="' . $value . '">' . $value . '</option>';
}
$text = $dnspod->get_template('recordcreatef');
$text = str_replace('{{title}}', '添加记录', $text);
$text = str_replace('{{action}}', 'recordcreate', $text);
$text = str_replace('{{domain_id}}', $_GET['domain_id'], $text);
$text = str_replace('{{record_id}}', $_GET['record_id'], $text);
$text = str_replace('{{type_list}}', $type_list, $text);
$text = str_replace('{{line_list}}', $line_list, $text);
$text = str_replace('{{sub_domain}}', '', $text);
$text = str_replace('{{value}}', '', $text);
$text = str_replace('{{mx}}', '10', $text);
$text = str_replace('{{ttl}}', '600', $text);
$text = str_replace('{{remark}}', '', $text);
} elseif ($_GET['action'] == 'recordcreate') {
if ($_GET['domain_id'] == '') {
$dnspod->message('danger', '参数错误。', -1);
}
if (!$_POST['sub_domain']) {
$_POST['sub_domain'] = '@';
}
if (!$_POST['value']) {
$dnspod->message('danger', '请输入记录值。', -1);
}
if ($_POST['type'] == 'MX' && !$_POST['mx']) {
$_POST['mx'] = 10;
}
if (!$_POST['ttl']) {
$_POST['ttl'] = 600;
}
$response = $dnspod->api_call('Record.Create',
array('domain_id' => $_GET['domain_id'],
'sub_domain' => $_POST['sub_domain'],
'record_type' => $_POST['type'],
'record_line' => $_POST['line'],
'value' => $_POST['value'],
'mx' => $_POST['mx'],
'ttl' => $_POST['ttl'],
)
);
if ($_POST['remark'] != "") {
$response = $dnspod->api_call('Record.Remark',
array('domain_id' => $_GET['domain_id'],
'record_id' => $response['record']['id'],
'remark' => $_POST['remark'],
)
);
}
$dnspod->message('success', '添加成功。', '?action=recordlist&domain_id=' . $_GET['domain_id']);
} elseif ($_GET['action'] == 'recordeditf') {
if ($_GET['domain_id'] == '') {
$dnspod->message('danger', '参数错误。', -1);
}
if ($_GET['record_id'] == '') {
$dnspod->message('danger', '参数错误。', -1);
}
$response = $dnspod->api_call('Record.Info', array('domain_id' => $_GET['domain_id'], 'record_id' => $_GET['record_id']));
$record = $response['record'];
if (!$_SESSION['type_' . $_GET['grade']]) {
$response = $dnspod->api_call('Record.Type', array('domain_grade' => $_GET['grade']));
$_SESSION['type_' . $_GET['grade']] = $response['types'];
}
if (!$_SESSION['line_' . $_GET['domain_id']]) {
$response = $dnspod->api_call('Record.Line',
array('domain_id' => $_GET['domain_id'], 'domain_grade' => $_GET['grade']));
$_SESSION['line_' . $_GET['domain_id']] = $response['lines'];
}
$type_list = '';
foreach ($_SESSION['type_' . $_GET['grade']] as $key => $value) {
$type_list .= '<option value="' . $value . '" ' . ($record['record_type'] == $value ? 'selected="selected"' : '') . '>' . $value . '</option>';
}
$line_list = '';
foreach ($_SESSION['line_' . $_GET['domain_id']] as $key => $value) {
$line_list .= '<option value="' . $value . '" ' . ($record['record_line'] == $value ? 'selected="selected"' : '') . '>' . $value . '</option>';
}
$text = $dnspod->get_template('recordcreatef');
$text = str_replace('{{title}}', '修改记录', $text);
$text = str_replace('{{action}}', 'recordedit', $text);
$text = str_replace('{{domain_id}}', $_GET['domain_id'], $text);
$text = str_replace('{{record_id}}', $_GET['record_id'], $text);
$text = str_replace('{{type_list}}', $type_list, $text);
$text = str_replace('{{line_list}}', $line_list, $text);
$text = str_replace('{{sub_domain}}', $record['sub_domain'], $text);
$text = str_replace('{{value}}', $record['value'], $text);
$text = str_replace('{{mx}}', $record['mx'], $text);
$text = str_replace('{{ttl}}', $record['ttl'], $text);
$text = str_replace('{{remark}}', $record['remark'], $text);
} elseif ($_GET['action'] == 'recordedit') {
if ($_GET['domain_id'] == '') {
$dnspod->message('danger', '参数错误。', -1);
}
if ($_GET['record_id'] == '') {
$dnspod->message('danger', '参数错误。', -1);
}
if (!$_POST['sub_domain']) {
$_POST['sub_domain'] = '@';
}
if (!$_POST['value']) {
$dnspod->message('danger', '请输入记录值。', -1);
}
if ($_POST['type'] == 'MX' && !$_POST['mx']) {
$_POST['mx'] = 10;
}
if (!$_POST['ttl']) {
$_POST['ttl'] = 600;
}
$response = $dnspod->api_call('Record.Modify',
array('domain_id' => $_GET['domain_id'],
'record_id' => $_GET['record_id'],
'sub_domain' => $_POST['sub_domain'],
'record_type' => $_POST['type'],
'record_line' => $_POST['line'],
'value' => $_POST['value'],
'mx' => $_POST['mx'],
'ttl' => $_POST['ttl'],
)
);
if ($_POST['remark'] != $_POST['oremark']) {
$response = $dnspod->api_call('Record.Remark',
array('domain_id' => $_GET['domain_id'],
'record_id' => $_GET['record_id'],
'remark' => $_POST['remark'],
)
);
}
$dnspod->message('success', '修改成功。', '?action=recordlist&domain_id=' . $_GET['domain_id']);
} elseif ($_GET['action'] == 'recordremove') {
if ($_GET['domain_id'] == '') {
$dnspod->message('danger', '参数错误。', -1);
}
if ($_GET['record_id'] == '') {
$dnspod->message('danger', '参数错误。', -1);
}
$response = $dnspod->api_call('Record.Remove',
array('domain_id' => $_GET['domain_id'],
'record_id' => $_GET['record_id'],
)
);
$dnspod->message('success', '删除成功。', '?action=recordlist&domain_id=' . $_GET['domain_id']);
} elseif ($_GET['action'] == 'recordstatus') {
if ($_GET['domain_id'] == '') {
$dnspod->message('danger', '参数错误。', -1);
}
if ($_GET['record_id'] == '') {
$dnspod->message('danger', '参数错误。', -1);
}
if ($_GET['status'] == '') {
$dnspod->message('danger', '参数错误。', -1);
}
$response = $dnspod->api_call('Record.Status',
array('domain_id' => $_GET['domain_id'],
'record_id' => $_GET['record_id'],
'status' => $_GET['status'],
)
);
$dnspod->message('success', ($_GET['status'] == 'enable' ? '启用' : '暂停') . '成功。', '?action=recordlist&domain_id=' . $_GET['domain_id']);
} else {
$text = $dnspod->get_template('login');
$text = str_replace('{{title}}', '用户登录', $text);
}
echo $text;