Created
March 15, 2013 08:24
-
-
Save mosladil/5168301 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once 'src/KerioControlApi.php'; | |
$api = new KerioControlApi('Setup Custom HTTP Rule', 'Miroslav Osladil', '1.0'); | |
try { | |
$session = $api->login('fw.company.local', 'username', 'password'); | |
/* get current http rules */ | |
$result = $api->sendRequest('HttpPolicy.get'); | |
$rulesList = $result['list']; | |
/* create a new rule */ | |
$newRule = array( | |
'enabled' => TRUE, | |
'name' => 'My HTTP Rule', | |
'description' => 'My HTTP rule which disables example.com', | |
'urlCondition' => array( | |
'type' => 'UrlString', | |
'url' => 'example.com'), | |
'action' => 'Deny', | |
'denialCondition' => array( | |
'denialText' => 'Sorry, access to example.com is not allowed!', | |
'canUnlockRule' => TRUE) | |
); | |
$rulesList[] = $newRule; | |
/* save rules list */ | |
$params = array('rules' => $rulesList); | |
$api->sendRequest('HttpPolicy.set', $params); | |
} | |
catch (KerioApiException $e) { | |
print $e->getMessage(); | |
} | |
if (isset($session)) $api->logout(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment