1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Incapsula\Api; |
4
|
|
|
|
5
|
|
|
class SitesApi extends AbstractApi |
6
|
|
|
{ |
7
|
|
|
private $apiUri = 'https://my.incapsula.com/api/prov/v1/sites'; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* @param int $pageSize |
11
|
|
|
* @param int $pageNum |
12
|
|
|
* |
13
|
|
|
* @return array |
14
|
|
|
*/ |
15
|
|
|
|
16
|
|
|
public function list($pageSize = 50, $pageNum = 0) |
17
|
|
|
{ |
18
|
|
|
return $this->client->send(sprintf('%s/list', $this->apiUri), [ |
19
|
|
|
'page_size' => $pageSize, |
20
|
|
|
'page_num' => $pageNum, |
21
|
|
|
]); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @param array $params |
26
|
|
|
* |
27
|
|
|
* @return array |
28
|
|
|
*/ |
29
|
|
|
|
30
|
|
|
public function add($params = []) |
31
|
|
|
{ |
32
|
|
|
return $this->client->send(sprintf('%s/add', $this->apiUri), $params); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @param string $siteId |
37
|
|
|
* |
38
|
|
|
* @return array |
39
|
|
|
*/ |
40
|
|
|
|
41
|
|
|
public function delete($siteId) |
42
|
|
|
{ |
43
|
|
|
return $this->client->send(sprintf('%s/delete', $this->apiUri), [ |
44
|
|
|
'site_id' => $siteId, |
45
|
|
|
]); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @param string $siteId |
50
|
|
|
* @param string $certificate |
51
|
|
|
* @param string $privateKey |
52
|
|
|
* |
53
|
|
|
* @return array |
54
|
|
|
*/ |
55
|
|
|
|
56
|
|
|
public function uploadCustomCertificate($siteId, $certificate, $privateKey) |
57
|
|
|
{ |
58
|
|
|
return $this->client->send(sprintf('%s/uploadCustomCertificate', $this->apiUri), [ |
59
|
|
|
'site_id' => $siteId, |
60
|
|
|
'certificate' => base64_encode($certificate), |
61
|
|
|
'private_key' => base64_encode($privateKey), |
62
|
|
|
]); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @param string $siteId |
67
|
|
|
* |
68
|
|
|
* @return array |
69
|
|
|
*/ |
70
|
|
|
|
71
|
|
|
public function removeCustomCertificate($siteId) |
72
|
|
|
{ |
73
|
|
|
return $this->client->send(sprintf('%s/removeCustomCertificate', $this->apiUri), [ |
74
|
|
|
'site_id' => $siteId, |
75
|
|
|
]); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @param string $siteId site to purge |
80
|
|
|
* @param string $purgePattern is optional but to purge specific resources the format is as follows |
81
|
|
|
* purge all urls that contain text requires no additional formatting, e.g. image.jpg, |
82
|
|
|
* or to purge URLs starting with a pattern use '^' e.g. "^maps/" , |
83
|
|
|
* or to purge all URLs that end with a pattern use '$' e.g. ".jpg$" |
84
|
|
|
* See incapsula docs for details |
85
|
|
|
* https://docs.incapsula.com/Content/API/sites-api.htm#Purge |
86
|
|
|
* @return array |
87
|
|
|
*/ |
88
|
|
|
|
89
|
|
|
public function purgeCache($siteId, $purgePattern = "") |
90
|
|
|
{ |
91
|
|
|
return $this->client->send(sprintf('%s/cache/purge', $this->apiUri), [ |
92
|
|
|
'site_id' => $siteId, |
93
|
|
|
'purge_pattern' => $purgePattern |
94
|
|
|
]); |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|