-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrecord.php
executable file
·149 lines (122 loc) · 4.39 KB
/
record.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
<?php
class Record extends DNS_Controller
{
public function __construct() {
parent::__construct();
if (empty($this->account_list)) {
header('Location:/');
}
$this->load->library('encrypt');
//获取当前账户的用户名和密码
$cur_account = $this->account_list[$this->account_id];
$this->cur_account['login_email'] = $cur_account['dnspod_username'];
$this->cur_account['login_password'] = $this->encrypt->decode($cur_account['dnspod_password']);
//加载API类
$this->load->library('dnsapi', $this->cur_account);
}
public function index($domain_id = 0)
{
$domain = '';
$records = array();
$error = '';
try {
$api_data = $this->dnsapi->get('Record.List', array('domain_id' => $domain_id));
// print_r($api_data);exit;
$domain = $api_data['domain']['name'];
$records= $api_data['records'];
}
catch(Exception $e) {
$error = $e->getMessage();
}
$view_data = array(
'domain' => $domain,
'records' => $records,
'error' => $error,
'domain_id' => $domain_id
);
$this->load_view('record_list', $view_data);
}
public function add($domain_id = 0, $record_id = 0)
{
$domain = array();
$record = array();
$error = NULL;
try {
$api_data = $this->dnsapi->get('Record.Info', array('domain_id' => $domain_id, 'record_id' => $record_id));
$domain = $api_data['domain'];
$record = $api_data['record'];
} catch (Exception $e) {
$error = $e->getMessage();
}
//获取域名相关信息
if (empty($domain)) {
try {
$api_data = $this->dnsapi->get('Domain.Info', array('domain_id' => $domain_id));
$domain = $api_data['domain'];
$domain['domain'] = $domain['name']; //为了跟'Record.Info'获取到的域名信息兼容
} catch (Exception $e) {}
}
$view_data = array(
'domain' => $domain,
'record' => $record,
'error' => $error
);
$this->load_view('record_add', $view_data);
}
/**
* 插入或编辑一条记录
*/
public function insert()
{
$api_data = array();
foreach (array('domain_id', 'sub_domain', 'record_type', 'record_line', 'value', 'mx', 'ttl') as $d) {
$api_data[$d] = $this->input->post($d);
}
//如果POST中含有record_id字段,则为编辑状态,否则添加
$api = 'Record.Create';
if (($record_id = $this->input->post('record_id')) > 0) {
$api = 'Record.Modify';
$api_data['record_id'] = $record_id;
}
$this->load->helper('ajax');
try {
$this->dnsapi->get($api, $api_data);
} catch (Exception $e) {
return ajax_error($e->getMessage());
}
ajax_success();
}
/**
* 锁定或者解除锁定
*/
public function lock()
{
$record_id = $this->input->post('id');
$domain_id = $this->input->post('domain_id');
$status = $this->input->post('status') ? 'disable' : 'enable';
$this->load->helper('ajax');
try {
$this->dnsapi->get('Record.Status', array('domain_id' => $domain_id, 'record_id' => $record_id, 'status' => $status));
} catch (Exception $e) {
return ajax_error($e->getMessage());
}
ajax_success();
}
/**
* 删除记录
*/
public function delete()
{
$api_data = array(
'domain_id' => $this->input->post('domain_id'),
'record_id' => $this->input->post('id')
);
$this->load->helper('ajax');
try {
$this->dnsapi->get('Record.Remove', $api_data);
} catch (Exception $e) {
return ajax_error($e->getMessage());
}
ajax_success();
}
}