Esempio n. 1
0
<?php

/**
 * @package Kolab_Storage
 */
require_once 'Horde/Kolab/Storage/List.php';
$list = Kolab_List::singleton();
var_dump($list->listFolders());
Esempio n. 2
0
 /**
  * Regenerate the free/busy cache data.
  *
  * @return NULL
  */
 function &regenerate($reporter)
 {
     $access = new Horde_Kolab_FreeBusy_Access();
     $result = $access->authenticated();
     if (is_a($result, 'PEAR_Error')) {
         return $result->getMessage();
     }
     /* Load the required Kolab libraries */
     require_once "Horde/Kolab/Storage/List.php";
     $list =& Kolab_List::singleton();
     $calendars = $list->getByType('event');
     if (is_a($calendars, 'PEAR_Error')) {
         return $calendars->getMessage();
     }
     $this->_initCache();
     $lines = array();
     foreach ($calendars as $calendar) {
         /**
          * We are using imap folders for our calendar list but
          * the library expects us to follow the trigger format
          * used by pfb.php
          */
         $req_domain = explode('@', $calendar->name);
         if (isset($req_domain[1])) {
             $domain = $req_domain[1];
         } else {
             $domain = null;
         }
         $req_folder = explode('/', $req_domain[0]);
         if ($req_folder[0] == 'user') {
             unset($req_folder[0]);
             $owner = $req_folder[1];
             unset($req_folder[1]);
         } else {
             if ($req_folder[0] == 'INBOX') {
                 $owner = $access->user;
                 unset($req_folder[0]);
             }
         }
         $trigger = $owner . ($domain ? '@' . $domain : '') . '/' . join('/', $req_folder);
         $trigger = Horde_String::convertCharset($trigger, 'UTF7-IMAP', 'UTF-8');
         /* Validate folder access */
         $result = $access->parseFolder($trigger);
         if (is_a($result, 'PEAR_Error')) {
             $reporter->failure($calendar->name, $result->getMessage());
             continue;
         }
         /* Hack for allowing manager access */
         if ($access->user == 'manager') {
             $imapc =& Horde_Kolab_IMAP::singleton($GLOBALS['conf']['kolab']['imap']['server'], $GLOBALS['conf']['kolab']['imap']['port']);
             $result = $imapc->connect($access->user, $GLOBALS['registry']->getAuthCredential('password'));
             if (is_a($result, 'PEAR_Error')) {
                 $reporter->failure($calendar->name, $result->getMessage());
                 continue;
             }
             $acl = $imapc->getACL($calendar->name);
             if (is_a($acl, 'PEAR_Error')) {
                 $reporter->failure($calendar->name, $result->getMessage());
                 continue;
             }
             $oldacl = '';
             if (isset($acl['manager'])) {
                 $oldacl = $acl['manager'];
             }
             $result = $imapc->setACL($calendar->name, 'manager', array('rights' => 'lrs'));
             if (is_a($result, 'PEAR_Error')) {
                 $reporter->failure($calendar->name, $result->getMessage());
                 continue;
             }
         }
         /* Update the cache */
         $result = $this->_cache->store($access);
         if (is_a($result, 'PEAR_Error')) {
             $reporter->failure($calendar->name, $result->getMessage());
             continue;
         }
         /* Revert the acl  */
         if ($access->user == 'manager' && $oldacl) {
             $result = $imapc->setACL($calendar->name, 'manager', array('rights' => $oldacl));
             if (is_a($result, 'PEAR_Error')) {
                 $reporter->failure($calendar->name, $result->getMessage());
                 continue;
             }
         }
         $reporter->success($calendar->name);
     }
     return $lines;
 }
Esempio n. 3
0
 function _imapConnect($id)
 {
     global $conf;
     // Handle virtual domains
     list($user, $domain) = explode('@', $id);
     if (empty($domain)) {
         $domain = $conf['kolab']['filter']['email_domain'];
     }
     $calendar_user = $conf['kolab']['filter']['calendar_id'] . '@' . $domain;
     /* Load the authentication libraries */
     $auth = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Auth')->create(isset($conf['auth']['driver']) ? null : 'kolab');
     $authenticated = $auth->authenticate($calendar_user, array('password' => $conf['kolab']['filter']['calendar_pass']), false);
     if (is_a($authenticated, 'PEAR_Error')) {
         $authenticated->code = OUT_LOG | EX_UNAVAILABLE;
         return $authenticated;
     }
     if (!$authenticated) {
         return PEAR::raiseError(sprintf('Failed to authenticate as calendar user: %s', $auth->getLogoutReasonString()), OUT_LOG | EX_UNAVAILABLE);
     }
     @session_start();
     $secret = $GLOBALS['injector']->getInstance('Horde_Secret');
     $_SESSION['__auth'] = array('authenticated' => true, 'userId' => $calendar_user, 'timestamp' => time(), 'credentials' => $secret->write($secret->getKey(), serialize(array('password' => $conf['kolab']['filter']['calendar_pass']))), 'remote_addr' => isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : null);
     /* Kolab IMAP handling */
     require_once 'Horde/Kolab/Storage/List.php';
     $list =& Kolab_List::singleton();
     $default = $list->getForeignDefault($id, 'event');
     if (!$default || is_a($default, 'PEAR_Error')) {
         $default = new Kolab_Folder();
         $default->setList($list);
         $default->setName($conf['kolab']['filter']['calendar_store']);
         //FIXME: The calendar user needs access here
         $attributes = array('default' => true, 'type' => 'event', 'owner' => $id);
         $result = $default->save($attributes);
         if (is_a($result, 'PEAR_Error')) {
             $result->code = OUT_LOG | EX_UNAVAILABLE;
             return $result;
         }
     }
     return $default;
 }
Esempio n. 4
0
 function testAttachments()
 {
     /* Open our addressbook */
     $this->_kolab->open('INBOX/Contacts', 1);
     $object = array('uid' => 'a', 'given-name' => 'atc', 'last-name' => 'atc', 'full-name' => 'atc atc');
     // Save the contact
     $turba = $GLOBALS['injector']->getInstance('Turba_Factory_Driver')->create('*****@*****.**');
     //$this->assertNoError($turba);
     $this->assertNoError($turba->_add($object));
     $contact = $turba->getObject('a');
     $this->assertNoError($contact);
     $list = Kolab_List::singleton();
     $share =& $list->getByShare('INBOX/Contacts', 'contact');
     $data =& $share->getData();
     $atc1 = Horde_Util::getTempFile();
     $fh = fopen($atc1, 'w');
     fwrite($fh, 'test');
     fclose($fh);
     $info = array('tmp_name' => $atc1, 'name' => 'test.txt');
     $this->assertNoError($contact->addFile($info));
     $objects = $data->getObjects();
     $this->assertEquals(1, count($objects));
     $object = $data->getObject('a');
     $this->assertTrue(isset($object['_attachments']));
     $this->assertEquals(1, count($object['_attachments']));
     $this->assertEquals(1, count($object['link-attachment']));
     $this->assertContains('test.txt', $object['link-attachment']);
     $attachment = $data->getAttachment($object['_attachments']['test.txt']['key']);
     $this->assertEquals("test\n", $attachment);
     $atc1 = Horde_Util::getTempFile();
     $fh = fopen($atc1, 'w');
     fwrite($fh, 'hhhh');
     fclose($fh);
     $info = array('tmp_name' => $atc1, 'name' => 'test.txt');
     $this->assertNoError($contact->addFile($info));
     $objects = $data->getObjects();
     $this->assertEquals(1, count($objects));
     $object = $data->getObject('a');
     $this->assertTrue(isset($object['_attachments']));
     $this->assertEquals(2, count($object['_attachments']));
     $this->assertEquals(2, count($object['link-attachment']));
     $this->assertContains('test[1].txt', $object['link-attachment']);
     $attachment = $data->getAttachment($object['_attachments']['test[1].txt']['key']);
     $this->assertEquals("hhhh\n", $attachment);
     $atc1 = Horde_Util::getTempFile();
     $fh = fopen($atc1, 'w');
     fwrite($fh, 'dummy');
     fclose($fh);
     $info = array('tmp_name' => $atc1, 'name' => 'dummy.txt');
     $this->assertNoError($contact->addFile($info));
     $objects = $data->getObjects();
     $this->assertEquals(1, count($objects));
     $object = $data->getObject('a');
     $this->assertTrue(isset($object['_attachments']));
     $this->assertEquals(3, count($object['_attachments']));
     $this->assertEquals(3, count($object['link-attachment']));
     $this->assertContains('dummy.txt', $object['link-attachment']);
     $attachment = $data->getAttachment($object['_attachments']['dummy.txt']['key']);
     $this->assertEquals("dummy\n", $attachment);
     $this->assertError($contact->deleteFile('doesnotexist.txt'), "Unable to delete VFS file.");
     $this->assertNoError($contact->deleteFile('test[1].txt'));
     $objects = $data->getObjects();
     $this->assertEquals(1, count($objects));
     $object = $data->getObject('a');
     $this->assertTrue(!isset($object['_attachments']['test[1].txt']));
     $this->assertEquals(2, count($object['_attachments']));
     $this->assertEquals(2, count($object['link-attachment']));
     $this->assertNotContains('test[1].txt', $object['link-attachment']);
     $files = $contact->listFiles();
     $this->assertNoError($files);
     $this->assertContains('test.txt', array_keys($files));
     $this->assertContains('dummy.txt', array_keys($files));
     $this->assertNoError($contact->deleteFiles());
     $objects = $data->getObjects();
     $this->assertEquals(1, count($objects));
     $object = $data->getObject('a');
     $this->assertTrue(!isset($object['_attachments']['test.txt']));
     $this->assertTrue(!isset($object['_attachments']));
     $this->assertTrue(!isset($object['link-attachment']));
 }