|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @author Chris Hilsdon <[email protected]> |
|
4
|
|
|
*/ |
|
5
|
|
|
namespace Cloudflare; |
|
6
|
|
|
|
|
7
|
|
|
use Symfony\Component\Yaml\Yaml; |
|
8
|
|
|
|
|
9
|
|
|
class Cloudflare |
|
10
|
|
|
{ |
|
11
|
|
|
protected $Endpoint = "https://api.cloudflare.com/client/v4/"; |
|
12
|
|
|
protected $APIKEY; |
|
13
|
|
|
protected $Email; |
|
14
|
|
|
protected $MakeRequests = true; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Origin CA Key that is used to request SSL certificates |
|
18
|
|
|
* @var string |
|
19
|
|
|
*/ |
|
20
|
|
|
protected $originCAKey; |
|
21
|
|
|
|
|
22
|
|
|
public function getOriginCAKey() |
|
23
|
|
|
{ |
|
24
|
|
|
return $this->originCAKey; |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
public function getEndpoint() |
|
28
|
|
|
{ |
|
29
|
|
|
return $this->Endpoint; |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
public function getAPIKEY() |
|
33
|
|
|
{ |
|
34
|
|
|
return $this->APIKEY; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
public function getEmail() |
|
38
|
|
|
{ |
|
39
|
|
|
return $this->Email; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
public function getMakeRequests() |
|
43
|
|
|
{ |
|
44
|
|
|
return $this->MakeRequests; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
public function diableRequests() |
|
48
|
|
|
{ |
|
49
|
|
|
$this->MakeRequests = false; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
public function enableRequests() |
|
53
|
|
|
{ |
|
54
|
|
|
$this->MakeRequests = true; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
public function __construct($APIKEY = null, $Email = null, $key = null) |
|
58
|
|
|
{ |
|
59
|
|
|
if (is_null($APIKEY) || is_null($Email)) { |
|
60
|
|
|
$this->loadConfig(); |
|
61
|
|
|
} else { |
|
62
|
|
|
$this->APIKEY = $APIKEY; |
|
63
|
|
|
$this->Email = $Email; |
|
64
|
|
|
$this->originCAKey = $key; |
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
private function loadConfig() |
|
69
|
|
|
{ |
|
70
|
|
|
$config = 'Cloudflare.yml'; |
|
71
|
|
|
$configDist = $config.'.dist'; |
|
72
|
|
|
$dir = $_SERVER['DOCUMENT_ROOT']; |
|
73
|
|
|
|
|
74
|
|
|
if (@file_exists($dir . $config)) { |
|
75
|
|
|
$load = $config; |
|
76
|
|
|
} elseif (@file_exists($dir . $configDist)) { |
|
77
|
|
|
$load = $configDist; |
|
78
|
|
|
} else { |
|
79
|
|
|
throw new \Exception('Unable to load either "'.$config.'" or "'.$configDist.'"', 1); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
$config = Yaml::parse(file_get_contents($load)); |
|
83
|
|
|
|
|
84
|
|
|
$this->APIKEY = $config['APIKEY']; |
|
85
|
|
|
$this->Email = $config['Email']; |
|
86
|
|
|
} |
|
87
|
|
|
} |
|
88
|
|
|
|