Recent versions of Kerio® Connect support the "Administration API for Kerio Connect". This allows you to perform administrative tasks through scripting. This can be very convenient for making mass changes based on specific conditions.
For example, one of my customers wants to apply a 1 MB quota to any user who has never logged in and does not already have a quota set. That may sound like a strange request, but they are a large company and have many users that aren't necessarily using email yet. When they originally setup users, they did not assign quotas, but have started doing so to some users. Going in to find all the inactive users would be a lot of work to do manually, but an API script can do it quickly and easily.
I modified one of the example scripts that Kerio provides and also got some help from Lukas Nemec at the Kerio Developers forum. I had been playing with an earlier version of the API and was causing myself some trouble by reading current documentation without upgrading. Once I installed the current version, things worked MUCH better :)
To use this script, you'll need to download the Kerio api and install it per the instructions in the reference documentation found at the same link.
You'll also want to look at the documentation at http://manuals.kerio.com/connect/api/en/reference/index.html.
The script as presented here does not do extensive error checking. I have tested it against test servers, but (as usual) you need to understand what this does and you will use it at your own risk.
The script could be made more efficient by building an array of user id's and setting them all at once rather than individually. I didn't want to complicate this by doing that; it's easier to understand without it.
Here is sample output from two back-to-back runs.
<!--
/**
* Administration API Sample Application.
*
* Display all users with any administrator rights.
*
* @copyright Copyright © 1997-2011 Kerio Technologies s.r.o.
* and modified by A.P. Lawrence
*
* See http://aplawrence.com/Kerio/api_user_quota.html
*
*/
-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Strict//EN">
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="style.css">
<link rel="shortcut icon" href="favicon.ico">
<title>Administration API</title>
</head>
<body>
<?php
require_once(dirname(__FILE__) . '/examples/class/MyApi.php');
/* Application details */
$name = 'Set user quota';
$vendor = 'A.P. Lawrence';
$version = '1.0';
$hostname = '192.168.11.9';
$username = 'Admin';
$password = '753tkerioaHw2s93!';
$Api = new MyApi($name, $vendor, $version);
//$Api->setDebug(TRUE);
/* Local functions */
function getDomainList() {
global $Api;
$method = 'Domains.get';
$params = array(
'query' => array(
'fields' => array(
'id',
'name'
)
)
);
$result = $Api->sendRequest($method, $params);
return $result['list'];
}
function getUserList($domainId) {
global $Api;
$method = 'Users.get';
$params = array(
'query' => array(
'fields' => array(
'loginName',
'id',
'fullName',
'lastLoginInfo',
'consumedSize'
),
'orderBy' => array(array(
'columnName' => 'loginName',
'direction' => 'Asc'
))
),
'domainId' => $domainId
);
$result = $Api->sendRequest($method, $params);
return $result['list'];
}
/* Main application */
print "<h1> Display users with no login and set quota</h1>";
try {
/* Register application */
date_default_timezone_set('America/New_York');
/* Login */
$login = $Api->login($hostname, $username, $password);
/* Get domain list */
$domainList = $Api->getDomains(array('id', 'name'));
foreach ($domainList as $domain) {
$userList = $Api->getUsers(array('id','loginName',
'fullName', 'diskSizeLimit', 'lastLoginInfo'),
$domain['id']);
foreach ($userList as $user) {
$quota = $user['diskSizeLimit']['limit']['value'];
if (! $user['lastLoginInfo']['dateTime']) {
$id=$user['id'];
$set="Already set";
if (false == $user['diskSizeLimit']['isActive']) {
$set="Will set to 1 MB";
$params = array(
'userIds' => array(
$user['id']
),
'pattern' => array(
'diskSizeLimit' => array(
'isActive' => TRUE,
'limit' => array(
'value' => 1,
'units' => 'MegaBytes'
)
)
)
);
$response = $Api->sendRequest('Users.set', $params);
$quota = '(From unlimited)';
}
$username = $user['loginName'] . '@' . $domain['name'];
$fullname = $user['fullName'];
printf('%s (%s) %s %s <br>', $username, $fullname, $set , $quota);
}
}
}
} catch (Exception $error) {
/* Catch possible errors */
print $error->getMessage();
}
/* Logout */
if(isset($login)) {
$Api->logout();
}
print '<hr>';
print date(DATE_RSS);
?>
</body>
</html>
Kerio®, and related trademarks, names and logos are the property of Kerio Technologies, Inc. and are registered and/or used in the U.S. and other countries. Used under license from Kerio Technologies, Inc.
More Articles by Anthony Lawrence - Find me on Google+

Have you tried Searching this site?
Unix/Linux/Mac OS X support by phone, email or on-site: Support Rates
This is a Unix/Linux resource website. It contains technical articles about Unix, Linux and general computing related subjects, opinion, news, help files, how-to's, tutorials and more. We appreciate comments and article submissions.
Many of the products and books I review are things I purchased for my own use. Some were given to me specifically for the purpose of reviewing them. I resell or can earn commissions from the sale of some of these items. Links within these pages may be affiliate links that pay me for referring you to them. That's mostly insignificant amounts of money; whenever it is not I have made my relationship plain. I also may own stock in companies mentioned here. If you have any question, please do feel free to contact me.
Specific links that take you to pages that allow you to purchase the item I reviewed are very likely to pay me a commission. Many of the books I review were given to me by the publishers specifically for the purpose of writing a review. These gifts and referral fees do not affect my opinions; I often give bad reviews anyway.
We use Google third-party advertising companies to serve ads when you visit our website. These companies may use information (not including your name, address, email address, or telephone number) about your visits to this and other websites in order to provide advertisements about goods and services of interest to you. If you would like more information about this practice and to know your choices about not having this information used by these companies, click here.
Click here to add your comments
Don't miss responses! Subscribe to Comments by RSS or by Email
Click here to add your comments
If you want a picture to show with your comment, go get a Gravatar