forked from Netrvin/CFPMP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cf.class.php
137 lines (124 loc) · 3.93 KB
/
cf.class.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
<?php
include_once("config.php");
session_start();
class CF {
public function post($data){
$data["host_key"]=HOST_KEY;
$ch=curl_init();
curl_setopt($ch,CURLOPT_URL,"https://api.cloudflare.com/host-gw.html");
curl_setopt($ch,CURLOPT_POSTFIELDS,$data);
curl_setopt($ch,CURLOPT_TIMEOUT,10);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
$r=curl_exec($ch);
curl_close($ch);
return json_decode($r,true);
}
public function login($email,$password){
$data["act"]="user_create";
$data["cloudflare_email"]=$email;
$data["cloudflare_pass"]=$password;
$data["unique_id"]=NULL;
return self::post($data);
}
public function logout(){
if (!empty($_SESSION["email"])){
unset($_SESSION["email"]);
}
if (!empty($_SESSION["user_key"])){
unset($_SESSION["user_key"]);
}
}
public function is_login(){
if ((empty($_SESSION["email"]))||(empty($_SESSION["user_key"]))){
header("Location: index.php");
exit(0);
}
}
public function user_lookup(){
$data["act"]="user_lookup";
$data["cloudflare_email"]=$_SESSION["email"];
return self::post($data);
}
public function zone_set($zone_name,$resolve_to,$subdomains){
$data["act"] = "zone_set";
$data["user_key"] = $_SESSION["user_key"];
$data["zone_name"] = $zone_name;
$data["resolve_to"] = $resolve_to;
$data["subdomains"] = $subdomains;
return self::post($data);
}
public function zone_delete($zone_name){
$data["act"] = "zone_delete";
$data["user_key"] = $_SESSION["user_key"];
$data["zone_name"] = $zone_name;
return self::post($data);
}
public function zone_lookup($zone_name){
$data["act"] = "zone_lookup";
$data["user_key"] = $_SESSION["user_key"];
$data["zone_name"] = $zone_name;
return self::post($data);
}
public function update_record($zone_name,$record){
if (empty($record["@"])){
$record["@"]=$zone_name;
}
$at=$record["@"];
unset($record["@"]);
$str="";
foreach ($record as $key => $value){
$str.=$key.":".$value.",";
}
if (empty($str)){$str="www:".$zone_name;}else{
$str=substr($str,0,strlen($str)-1);
}
return self::zone_set($zone_name,$at,$str);
}
public function remove_zone_name($zone_name,$data){
foreach ($data["hosted_cnames"] as $record => $set)
{
if (strlen($record) > strlen($zone_name)){
$record2 = substr($record,0,strlen($record)-strlen($zone_name)-1);
}else{
$record2="@";
}
$data["hosted_cnames"][$record2] = $set;
unset($data["hosted_cnames"][$record]);
}
foreach ($data["forward_tos"] as $record => $set)
{
if (strlen($record) > strlen($zone_name)){
$record2 = substr($record,0,strlen($record)-strlen($zone_name)-1);
}else{
$record2="@";
}
$data["forward_tos"][$record2] = $set;
unset($data["forward_tos"][$record]);
}
return $data;
}
public function reCAPTCHA($response){
$url= "https://www.recaptcha.net/recaptcha/api/siteverify";
$data=array (
"secret" => reCAPTCHA_Secret,
"response" => $response
);
$ch=curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POSTFIELDS,$data);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,10);
$r=curl_exec($ch);
curl_close($ch);
$re=json_decode($r,true);
if (!empty($re["success"])){
if ($re["success"]=="true"){
return true;
}else{
return false;
}
}else{
return false;
}
}
}