Skip to content

Instantly share code, notes, and snippets.

@mosladil
Created March 15, 2013 08:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mosladil/5168301 to your computer and use it in GitHub Desktop.
Save mosladil/5168301 to your computer and use it in GitHub Desktop.
<?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