Skip to content

Commit 44f9fb4

Browse files
committed
Update cf.class.php
1 parent 01c711c commit 44f9fb4

File tree

1 file changed

+8
-42
lines changed

1 file changed

+8
-42
lines changed

cf.class.php

+8-42
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,14 @@ public function logout()
7676
if (!empty($_SESSION["user_key"])) {
7777
unset($_SESSION["user_key"]);
7878
}
79+
if (!empty($_SESSION["api_key"])) {
80+
unset($_SESSION["api_key"]);
81+
}
7982
}
8083

8184
public function is_login()
8285
{
83-
if ((empty($_SESSION["email"])) || (empty($_SESSION["user_key"]))) {
86+
if ((empty($_SESSION["email"])) || (empty($_SESSION["user_key"])) || (empty($_SESSION["api_key"]))) {
8487
header("Location: index.php");
8588
exit(0);
8689
}
@@ -119,29 +122,6 @@ public function zone_lookup($zone_name)
119122
return self::post($data);
120123
}
121124

122-
public function remove_zone_name($zone_name, $data)
123-
{
124-
foreach ($data["hosted_cnames"] as $record => $set) {
125-
if (strlen($record) > strlen($zone_name)) {
126-
$record2 = substr($record, 0, strlen($record) - strlen($zone_name) - 1);
127-
} else {
128-
$record2 = "@";
129-
}
130-
$data["hosted_cnames"][$record2] = $set;
131-
unset($data["hosted_cnames"][$record]);
132-
}
133-
foreach ($data["forward_tos"] as $record => $set) {
134-
if (strlen($record) > strlen($zone_name)) {
135-
$record2 = substr($record, 0, strlen($record) - strlen($zone_name) - 1);
136-
} else {
137-
$record2 = "@";
138-
}
139-
$data["forward_tos"][$record2] = $set;
140-
unset($data["forward_tos"][$record]);
141-
}
142-
return $data;
143-
}
144-
145125
public function get_zone_id($zone_name)
146126
{
147127
return self::user_api_get("https://api.cloudflare.com/client/v4/zones?name=$zone_name")['result'][0]['id'];
@@ -163,32 +143,18 @@ public function add_record($zone_id, $name, $content){
163143
}
164144

165145
public function edit_record($zone_id, $record_id, $name, $content){
166-
$data = [
146+
return self::user_api_post("https://api.cloudflare.com/client/v4/zones/$zone_id/dns_records/$record_id", [
167147
'type' => 'CNAME',
168148
'name' => $name,
169149
'content' => self::add_suffix_for_ip($content),
170150
'ttl' => 1,
171151
"proxied" => true
172-
];
173-
return self::user_api_post("https://api.cloudflare.com/client/v4/zones/$zone_id/dns_records/$record_id", $data, "PUT");
152+
], "PUT");
174153
}
175154

176155
public function delete_record($zone_id, $record_id){
177-
$ch = curl_init();
178-
curl_setopt($ch, CURLOPT_URL, "https://api.cloudflare.com/client/v4/zones/$zone_id/dns_records/$record_id");
179-
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
180-
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
181-
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
182-
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
183-
'Content-Type: application/json',
184-
'X-Auth-Email: ' . $_SESSION['email'],
185-
'X-Auth-Key: ' . $_SESSION['api_key'],
186-
));
187-
$r = curl_exec($ch);
188-
curl_close($ch);
189-
$data = json_decode($r, true);
190-
if ($data['result']['id']==$record_id) $data['success'] = true;
191-
else $data['success'] = false;
156+
$data = self::user_api_post("https://api.cloudflare.com/client/v4/zones/$zone_id/dns_records/$record_id", [], "DELETE");
157+
$data['result']['id']==$record_id ? $data['success'] = true : $data['success'] = false;
192158
return $data;
193159
}
194160

0 commit comments

Comments
 (0)