APLawrence.com -  Resources for Unix and Linux Systems, Bloggers and the self-employed

Exposing hidden data to users (API method)


At "Exposing Hidden Data to Users", I mentioned that you can also grab group members using the Kerio API. That does require a bit more setup - you have to download the libraries and if you intend to use them in a web server as I did here, you may need to configure that server to execute php scripts.

Note that you don't need a web server: all you really need is php and the API libraries. Even the examples Kerio provides will run perfectly fine from the command line. They generate HTML, so they'll be hard to read, but you can run them.

That's true for this script also. I wrote it to display a web page, but you could strip out the HTML and use it from the command line too.

The purpose is to show the members of certain groups. You'd probably use this for internal employee access only so that they can see who is in particular groups. In the code below, I skipped one domain and then skipped a group also, just to show you that you can control exactly what you choose to expose.

Here's the PHP script. Things you'll want to change are in red.

 * Get some group members.
 * @copyright	Copyright &copy; 2013 A.P.Lawrence
* Feel free to use it; credit appreciated but not demanded * @version */ require_once(dirname(__FILE__) '/../config.php'); require_once(dirname(__FILE__) . '/../class/MyApi.php'); require_once(dirname(__FILE__) . '/../class/HtmlHelper.php'); date_default_timezone_set('America/New_York'); $hostname = 'mail.aplawrence.com'; $username = 'admin'; $password = 'NotActuallyMyPassword'; $name = 'Get group members'; $api = new MyApi($name, $vendor, $version); $html = new HtmlHelper(); $html->printHeader($name); $html->printInfo('Expose certain group members to users'); /* Main application */ try { /* Login */ $login = $api->login($hostname, $username, $password); /* Get domains */ $fields = array('id', 'name'); $domainsList = $api->getDomains($fields); $constants = $api->getConstants(); foreach ($domainsList as $domain) { /* Skip domains we don't want */ /* (or invert this and show only some) */ if ($domain['name'] == 'foobar.com') { continue; } printf('<h2>Domain: %s</h2>', $domain['name']); $params = array( 'query' => array( 'fields' => array('id', 'name','emailAddresses' ), 'orderBy' => array(array( 'columnName' => 'name', 'direction' => 'Asc' )) ), 'domainId' => $domain['id'] ); $response = $api->sendRequest('Groups.get', $params); foreach ($response['list'] as $group) { /* Skip groups we don't want */ /* (or invert this and show only some) */ if ($group['name'] == 'tooby') { continue; } printf('Group %s<br /> ', $group['name']); $fields = array('id', 'loginName','userGroups'); $conditions = array(array( 'fieldName' => 'userGroups', 'comparator' => $constants['kerio_web_Eq'], 'value' => $group['id'] )); $userList = $api->getUsers($fields, $domain['id'],$conditions); foreach ($userList as $user) { printf("- %s <br />", $user['loginName']); } } // groups } //foreach domain } //try catch (KerioApiException $error) { /* Catch possible errors */ $html->printError($error->getMessage()); } /* Logout */ if (isset($session)) { $api->logout(); } $html->printFooter();

Here's what it looks like on my server:

Exposing groups with the Connect API

Got something to add? Send me email.

(OLDER)    <- More Stuff -> (NEWER)    (NEWEST)   

Printer Friendly Version

-> -> Exposing hidden data to users (API method)

Increase ad revenue 50-250% with Ezoic

More Articles by

Find me on Google+

© Anthony Lawrence

Kerio Connect Mailserver

Kerio Samepage

Kerio Control Firewall

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.

Contact us

Computer Science is embarrassed by the computer. (Alan Perlis)

Within C++, there is a much smaller and cleaner language struggling to get out. (Bjarne Stroustrup)

This post tagged: