[Kolab-devel] event triggered freebusy data generation
hede <[email protected]>
| Newsgroups | gmane.comp.kde.devel.kolab |
|---|---|
| Organization | der-he.de |
| Message-ID | <[email protected]> |
Hi, I asked for documentation to the kolabs freebusy system on the users list. If it is really needed to run a cron job every x minutes to generate the data (kolab-freebusyd). I didn't find any configuration option to let the freebusy data get generated on demand and because no one answered, I implemented it myself, in "my way. (The "my way" means I expect it to be an ugly hack and not accepted upstream. I'm pretty sure there are better ways to implement this. At least my chosen names will hurt any english native speaker...) Instead of running kolab-freebusyd every x minutes, for my use-case it's better to start it on demand. So I do so. The freebusy web script triggers kolab-freebusyd to regenerate and aggregate the data for the corresponding user, if needed, e.g. if the cached ifb-file is too old. If it's not too old, the old one gets used and no kolab-freebusyd is triggered. This way even on high load systems it won't hurt to use this (with a triggertime of 900 it would be like a regular cron job every 15 minutes). This patch adds two new config-options for [directory] type ldap and type static with fbsource of type "file": triggertime and trigger. With this I can configure how old the ifb file must be to get regenerated (in seconds), which value is forwarded to kolab-freebusyd and if its triggered at all or simply using the old style. (Yes, it's backwards compatible; if "trigger" is not set, it behaves as without the patch) See attached patch. I've added my config.ini as an example. (the patch uses /lib/Kolab as base directory, it won't apply in the source directories root) Everything using the "kolab-freebusy" web service should trigger the generation. I tested roundcube and kontact so far. Clients using the imap Freebusy-folder won't trigger anything. That's the drawback. Btw: Why differ between aggregate and regenerate? And why generate inside imap and not directly to /var/lib/kolab-freebusy/? Are there plans to get rid of the ifb-files and use imap instead? Regards hede _______________________________________________ devel mailing list [email protected] https://lists.kolab.org/mailman/listinfo/devel
config.ini
(text/plain, 1.4 KB)
;; Kolab Free/Busy Service configuration ;; Require HTTP authentication to access this service [httpauth] ;; Example for static auth credentials ; type = static ; username = "<user>" ; password = "<pass>" type = ldap host = ldap://localhost:389 bind_dn = "uid=kolab-service,ou=Special Users,dc=example,dc=com" bind_pw = Ultr4S3cr3t base_dn = "dc=example,dc=com" filter = "(&(|(mail=%s)(alias=%s)(uid=%s))(objectclass=inetorgperson))" ; optional, %s is replaced by the username ;; Allow privileged access from these IPs [trustednetworks] allow[] = 127.0.0.1 ;allow[] = 192.168.0.0/16 ;allow[] = 10.10.* allow[] = ::1 [log] driver = file ;path = ./log path = /var/log/kolab-freebusy name = freebusy level = 3 level = 200 [directory "local"] type = static filter = "@example.com" trigger = s triggertime = 300 fbsource = file:/var/lib/kolab-freebusy/%s.ifb loglevel = 200 [directory "kolab-ldap"] type = ldap host = ldap://localhost:389 bind_dn = "uid=kolab-service,ou=Special Users,dc=example,dc=com" bind_pw = Ultr4S3cr3t base_dn = "dc=example,dc=com" filter = "(&(objectClass=kolabInetOrgPerson)(|(uid=%s)(mail=%s)(alias=%s)))" attributes[] = mail lc_attributes[] = mail trigger = mail triggertime = 300 fbsource = file:/var/lib/kolab-freebusy/%mail.ifb loglevel = 100 ;[directory "exchange"] ;type = static ;filter = "@microsoft.com$" ;fbsource = https://externalhost/free-busy/%s.ics ;format = Exchange2010
event_triggered_freebusy.patch
(text/x-patch, 3 KB)
diff -rupN FreeBusy.ori/Directory.php FreeBusy/Directory.php
--- FreeBusy.ori/Directory.php 2014-02-25 19:40:45.948980220 +0100
+++ FreeBusy/Directory.php 2014-02-25 19:41:52.568980207 +0100
@@ -50,8 +50,7 @@ abstract class Directory
{
// resolve user record first
if ($user = $this->resolve($user)) {
- $fbsource = $this->config['fbsource'];
- if ($source = Source::Factory($fbsource)) {
+ if ($source = Source::Factory($this->config)) {
// forward request to Source instance
if ($data = $source->getFreeBusyData($this->postprocessAttrib($user), $extended)) {
// send data through the according format converter
diff -rupN FreeBusy.ori/SourceFile.php FreeBusy/SourceFile.php
--- FreeBusy.ori/SourceFile.php 2014-02-25 19:24:01.518980414 +0100
+++ FreeBusy/SourceFile.php 2014-02-25 19:37:37.268980256 +0100
@@ -12,11 +12,39 @@ class SourceFile extends Source
*/
public function getFreeBusyData($user, $extended)
{
+ // get Logger
+ $log = Logger::get('source');
+
// get source config with placeholders replaced
$config = $this->getUserConfig($user);
+ $trigger = $this->config['mainconf']['trigger'];
+ $triggertime = $this->config['mainconf']['triggertime'];
// deliver file contents if found
if (is_readable($config['path'])) {
+
+ // trigger file generation and aggregation if it's old
+ // 'trigger' should be defined in the config, with the
+ // user value: s for static, [ldap-attribute] for ldap
+ if ($trigger and is_writable($config['path'])) {
+ // use default if triggertime is not defined
+ if (!$triggertime) {
+ $triggertime=900; // seconds
+ }
+ // if file is older than $triggertime seconds...
+ if (time()-filemtime($config['path'])>$triggertime) {
+ $log->addInfo("f/b triggered. ".time()."-".filemtime($config['path']).">".$triggertime." (".(time()-filemtime($config['path'])).")");
+ $log->addInfo("trigger: QT_NO_GLIB=1 kolab-freebusyd -g -a ".$user[$trigger]);
+ // start kolab-freebusyd
+ exec("QT_NO_GLIB=1 kolab-freebusyd -g -a ".$user[$trigger]);
+ // it runs as www-user!
+ // so chmod fb-files and also run the cron script as www-user.
+ }
+ else {
+ $log->addInfo("f/b not triggered. ".time()."-".filemtime($config['path'])."<".$triggertime." (".(time()-filemtime($config['path'])).")");
+ }
+ }
+
return file_get_contents($config['path']);
}
diff -rupN FreeBusy.ori/Source.php FreeBusy/Source.php
--- FreeBusy.ori/Source.php 2014-02-25 19:40:31.588980222 +0100
+++ FreeBusy/Source.php 2014-02-25 19:39:33.788980234 +0100
@@ -14,10 +14,12 @@ abstract class Source
*
* @param array Hash array with config
*/
- public static function factory($url)
+ //public static function factory($url, $trigger)
+ public static function factory($mainconf)
{
- $config = parse_url($url);
- $config['url'] = $url;
+ $config = parse_url($mainconf['fbsource']);
+ $config['url'] = $mainconf['fbsource'];
+ $config['mainconf'] = $mainconf;
switch ($config['scheme']) {
case 'file': return new SourceFile($config);
case 'imap':