Merge pull request #6 from cloudflare/COM-40
COM-40 :: Add ZoneLockdown and UA Rules
This commit is contained in:
15
src/Configurations/Configurations.php
Normal file
15
src/Configurations/Configurations.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: junade
|
||||
* Date: 19/09/2017
|
||||
* Time: 15:23
|
||||
*/
|
||||
|
||||
namespace Cloudflare\API\Configurations;
|
||||
|
||||
|
||||
interface Configurations
|
||||
{
|
||||
public function getArray(): array;
|
||||
}
|
||||
29
src/Configurations/UARules.php
Normal file
29
src/Configurations/UARules.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: junade
|
||||
* Date: 19/09/2017
|
||||
* Time: 15:22
|
||||
*/
|
||||
|
||||
namespace Cloudflare\API\Configurations;
|
||||
|
||||
|
||||
class UARules implements Configurations
|
||||
{
|
||||
private $configs = array();
|
||||
|
||||
public function addUA(string $value)
|
||||
{
|
||||
$object = new \stdClass();
|
||||
$object->target = "ua";
|
||||
$object->value = $value;
|
||||
|
||||
array_push($this->configs, $object);
|
||||
}
|
||||
|
||||
public function getArray(): array
|
||||
{
|
||||
return $this->configs;
|
||||
}
|
||||
}
|
||||
38
src/Configurations/ZoneLockdown.php
Normal file
38
src/Configurations/ZoneLockdown.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: junade
|
||||
* Date: 05/09/2017
|
||||
* Time: 13:43
|
||||
*/
|
||||
|
||||
namespace Cloudflare\API\Configurations;
|
||||
|
||||
|
||||
class ZoneLockdown implements Configurations
|
||||
{
|
||||
private $configs = array();
|
||||
|
||||
public function addIP(string $value)
|
||||
{
|
||||
$object = new \stdClass();
|
||||
$object->target = "ip";
|
||||
$object->value = $value;
|
||||
|
||||
array_push($this->configs, $object);
|
||||
}
|
||||
|
||||
public function addIPRange(string $value)
|
||||
{
|
||||
$object = new \stdClass();
|
||||
$object->target = "ip_range";
|
||||
$object->value = $value;
|
||||
|
||||
array_push($this->configs, $object);
|
||||
}
|
||||
|
||||
public function getArray(): array
|
||||
{
|
||||
return $this->configs;
|
||||
}
|
||||
}
|
||||
124
src/Endpoints/UARules.php
Normal file
124
src/Endpoints/UARules.php
Normal file
@@ -0,0 +1,124 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: junade
|
||||
* Date: 19/09/2017
|
||||
* Time: 15:17
|
||||
*/
|
||||
|
||||
namespace Cloudflare\API\Endpoints;
|
||||
|
||||
use Cloudflare\API\Adapter\Adapter;
|
||||
|
||||
class UARules implements API
|
||||
{
|
||||
private $adapter;
|
||||
|
||||
public function __construct(Adapter $adapter)
|
||||
{
|
||||
$this->adapter = $adapter;
|
||||
}
|
||||
|
||||
public function listRules(
|
||||
string $zoneID,
|
||||
int $page = 1,
|
||||
int $perPage = 20
|
||||
): \stdClass {
|
||||
$options = [
|
||||
'page' => $page,
|
||||
'per_page' => $perPage
|
||||
];
|
||||
|
||||
$query = http_build_query($options);
|
||||
|
||||
$user = $this->adapter->get('zones/' . $zoneID . '/firewall/ua_rules?' . $query, []);
|
||||
$body = json_decode($user->getBody());
|
||||
|
||||
$result = new \stdClass();
|
||||
$result->result = $body->result;
|
||||
$result->result_info = $body->result_info;
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function createRule(
|
||||
string $zoneID,
|
||||
string $mode,
|
||||
\Cloudflare\API\Configurations\Configurations $configuration,
|
||||
string $id = null,
|
||||
string $description = null
|
||||
): bool {
|
||||
|
||||
$options = [
|
||||
'mode' => $mode,
|
||||
'configurations' => $configuration->getArray()
|
||||
];
|
||||
|
||||
if ($id !== null) {
|
||||
$options['id'] = $id;
|
||||
}
|
||||
|
||||
if ($description !== null) {
|
||||
$options['description'] = $description;
|
||||
}
|
||||
|
||||
$user = $this->adapter->post('zones/' . $zoneID . '/firewall/ua_rules', [], $options);
|
||||
|
||||
$body = json_decode($user->getBody());
|
||||
|
||||
if (isset($body->result->id)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getRuleDetails(string $zoneID, string $blockID): \stdClass
|
||||
{
|
||||
$user = $this->adapter->get('zones/' . $zoneID . '/firewall/ua_rules/' . $blockID, []);
|
||||
$body = json_decode($user->getBody());
|
||||
return $body->result;
|
||||
}
|
||||
|
||||
public function updateRule(
|
||||
string $zoneID,
|
||||
string $ruleID,
|
||||
string $mode,
|
||||
\Cloudflare\API\Configurations\UARules $configuration,
|
||||
string $description = null
|
||||
): bool {
|
||||
|
||||
$options = [
|
||||
'mode' => $mode,
|
||||
'id' => $ruleID,
|
||||
'configurations' => $configuration->getArray()
|
||||
];
|
||||
|
||||
if ($description !== null) {
|
||||
$options['description'] = $description;
|
||||
}
|
||||
|
||||
$user = $this->adapter->put('zones/' . $zoneID . '/firewall/ua_rules/' . $ruleID, [], $options);
|
||||
|
||||
$body = json_decode($user->getBody());
|
||||
|
||||
if (isset($body->result->id)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function deleteRule(string $zoneID, string $ruleID): bool
|
||||
{
|
||||
$user = $this->adapter->delete('zones/' . $zoneID . '/firewall/ua_rules/' . $ruleID, [], []);
|
||||
|
||||
$body = json_decode($user->getBody());
|
||||
|
||||
if (isset($body->result->id)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
124
src/Endpoints/ZoneLockdown.php
Normal file
124
src/Endpoints/ZoneLockdown.php
Normal file
@@ -0,0 +1,124 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: junade
|
||||
* Date: 04/09/2017
|
||||
* Time: 20:33
|
||||
*/
|
||||
|
||||
namespace Cloudflare\API\Endpoints;
|
||||
|
||||
use Cloudflare\API\Adapter\Adapter;
|
||||
|
||||
class ZoneLockdown implements API
|
||||
{
|
||||
private $adapter;
|
||||
|
||||
public function __construct(Adapter $adapter)
|
||||
{
|
||||
$this->adapter = $adapter;
|
||||
}
|
||||
|
||||
public function listLockdowns(
|
||||
string $zoneID,
|
||||
int $page = 1,
|
||||
int $perPage = 20
|
||||
): \stdClass {
|
||||
$options = [
|
||||
'page' => $page,
|
||||
'per_page' => $perPage
|
||||
];
|
||||
|
||||
$query = http_build_query($options);
|
||||
|
||||
$user = $this->adapter->get('zones/' . $zoneID . '/firewall/lockdowns?' . $query, []);
|
||||
$body = json_decode($user->getBody());
|
||||
|
||||
$result = new \stdClass();
|
||||
$result->result = $body->result;
|
||||
$result->result_info = $body->result_info;
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function createLockdown(
|
||||
string $zoneID,
|
||||
array $urls,
|
||||
\Cloudflare\API\Configurations\ZoneLockdown $configuration,
|
||||
string $id = null,
|
||||
string $description = null
|
||||
): bool {
|
||||
|
||||
$options = [
|
||||
'urls' => $urls,
|
||||
'configurations' => $configuration->getArray()
|
||||
];
|
||||
|
||||
if ($id !== null) {
|
||||
$options['id'] = $id;
|
||||
}
|
||||
|
||||
if ($description !== null) {
|
||||
$options['description'] = $description;
|
||||
}
|
||||
|
||||
$user = $this->adapter->post('zones/' . $zoneID . '/firewall/lockdowns', [], $options);
|
||||
|
||||
$body = json_decode($user->getBody());
|
||||
|
||||
if (isset($body->result->id)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getLockdownDetails(string $zoneID, string $lockdownID): \stdClass
|
||||
{
|
||||
$user = $this->adapter->get('zones/' . $zoneID . '/firewall/lockdowns/' . $lockdownID, []);
|
||||
$body = json_decode($user->getBody());
|
||||
return $body->result;
|
||||
}
|
||||
|
||||
public function updateLockdown(
|
||||
string $zoneID,
|
||||
string $lockdownID,
|
||||
array $urls,
|
||||
\Cloudflare\API\Configurations\ZoneLockdown $configuration,
|
||||
string $description = null
|
||||
): bool {
|
||||
|
||||
$options = [
|
||||
'urls' => $urls,
|
||||
'id' => $lockdownID,
|
||||
'configurations' => $configuration->getArray()
|
||||
];
|
||||
|
||||
if ($description !== null) {
|
||||
$options['description'] = $description;
|
||||
}
|
||||
|
||||
$user = $this->adapter->put('zones/' . $zoneID . '/firewall/lockdowns/' . $lockdownID, [], $options);
|
||||
|
||||
$body = json_decode($user->getBody());
|
||||
|
||||
if (isset($body->result->id)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function deleteLockdown(string $zoneID, string $lockdownID): bool
|
||||
{
|
||||
$user = $this->adapter->delete('zones/' . $zoneID . '/firewall/lockdowns/' . $lockdownID, [], []);
|
||||
|
||||
$body = json_decode($user->getBody());
|
||||
|
||||
if (isset($body->result->id)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user