Пример #1
0
 /**
  * The code that needs to be called when the cron is running
  * 
  * If $this->enableUserAndGroupSupport() returns TRUE then the run function 
  * will be called for each $user. (The $user parameter will be given)
  * 
  * If $this->enableUserAndGroupSupport() returns FALSE then the 
  * $user parameter is null and the run function will be called only once.
  * 
  * @param CronJob $cronJob
  * @param \GO\Base\Model\User $user [OPTIONAL]
  */
 public function run(CronJob $cronJob, \GO\Base\Model\User $user = null)
 {
     \GO::session()->runAsRoot();
     $usersStmt = \GO\Base\Model\User::model()->findByAttribute('mail_reminders', 1);
     while ($userModel = $usersStmt->fetch()) {
         \GO::debug("Sending mail reminders to " . $userModel->username);
         $remindersStmt = \GO\Base\Model\Reminder::model()->find(\GO\Base\Db\FindParams::newInstance()->joinModel(array('model' => 'GO\\Base\\Model\\ReminderUser', 'localTableAlias' => 't', 'localField' => 'id', 'foreignField' => 'reminder_id', 'tableAlias' => 'ru'))->criteria(\GO\Base\Db\FindCriteria::newInstance()->addCondition('user_id', $userModel->id, '=', 'ru')->addCondition('time', time(), '<', 'ru')->addCondition('mail_sent', '0', '=', 'ru')));
         while ($reminderModel = $remindersStmt->fetch()) {
             //					$relatedModel = $reminderModel->getRelatedModel();
             //					var_dump($relatedModel->name);
             //					$modelName = $relatedModel ? $relatedModel->localizedName : \GO::t('unknown');
             $subject = \GO::t('reminder') . ': ' . $reminderModel->name;
             $time = !empty($reminderModel->vtime) ? $reminderModel->vtime : $reminderModel->time;
             date_default_timezone_set($userModel->timezone);
             $body = \GO::t('time') . ': ' . date($userModel->completeDateFormat . ' ' . $userModel->time_format, $time) . "\n";
             $body .= \GO::t('name') . ': ' . str_replace('<br />', ',', $reminderModel->name) . "\n";
             //					date_default_timezone_set(\GO::user()->timezone);
             $message = \GO\Base\Mail\Message::newInstance($subject, $body);
             $message->addFrom(\GO::config()->noreply_email, \GO::config()->title);
             $message->addTo($userModel->email, $userModel->name);
             \GO\Base\Mail\Mailer::newGoInstance()->send($message, $failedRecipients);
             if (!empty($failedRecipients)) {
                 trigger_error("Reminder mail failed for recipient: " . implode(',', $failedRecipients), E_USER_NOTICE);
             }
             $reminderUserModelSend = \GO\Base\Model\ReminderUser::model()->findSingleByAttributes(array('user_id' => $userModel->id, 'reminder_id' => $reminderModel->id));
             $reminderUserModelSend->mail_sent = 1;
             $reminderUserModelSend->save();
         }
         date_default_timezone_set(\GO::user()->timezone);
     }
 }
Пример #2
0
 public function rebuildCache($user_id, $force = false)
 {
     $lastBuildTime = $force ? 0 : \GO::config()->get_setting('files_shared_cache_ctime', $user_id);
     if (!$lastBuildTime || $this->_getLastMtime($user_id) > $lastBuildTime) {
         $home = \GO\Files\Model\Folder::model()->findHomeFolder(GO::user());
         $homeFolder = $home->path;
         \GO::debug("Rebuilding shared cache");
         $this->deleteByAttribute('user_id', $user_id);
         $stmt = $this->_findShares($user_id);
         //sort by path and only list top level shares
         $shares = array();
         while ($folder = $stmt->fetch()) {
             //$folder->checkFsSync();
             //sort by path and only list top level shares
             $shares[$folder->path] = $folder;
         }
         ksort($shares);
         foreach ($shares as $path => $folder) {
             $isSubDir = isset($lastPath) && strpos($path . '/', $lastPath . '/') === 0;
             $isInHome = strpos($path . '/', $homeFolder . '/') === 0;
             if (!$isSubDir && !$isInHome) {
                 $sharedRoot = new SharedRootFolder();
                 $sharedRoot->user_id = $user_id;
                 $sharedRoot->folder_id = $folder->id;
                 $sharedRoot->save();
                 $lastPath = $path;
             }
         }
         \GO::config()->save_setting('files_shared_cache_ctime', time(), $user_id);
         return time();
     } else {
         return $lastBuildTime;
     }
 }
Пример #3
0
 public static function includeZpushFiles()
 {
     $moduleFolder = self::getModuleFolder();
     \GO::debug("Using z-push folder: " . $moduleFolder);
     if (self::zpushAdminFileExists($moduleFolder)) {
         include_once \GO::config()->root_path . 'modules/' . $moduleFolder . '/lib/utils/zpushadmin.php';
         include_once \GO::config()->root_path . 'modules/' . $moduleFolder . '/lib/core/zpushdefs.php';
         include_once \GO::config()->root_path . 'modules/' . $moduleFolder . '/lib/core/zpush.php';
         include_once \GO::config()->root_path . 'modules/' . $moduleFolder . '/lib/core/stateobject.php';
         include_once \GO::config()->root_path . 'modules/' . $moduleFolder . '/lib/core/syncparameters.php';
         include_once \GO::config()->root_path . 'modules/' . $moduleFolder . '/lib/core/bodypreference.php';
         include_once \GO::config()->root_path . 'modules/' . $moduleFolder . '/lib/core/contentparameters.php';
         include_once \GO::config()->root_path . 'modules/' . $moduleFolder . '/lib/core/synccollections.php';
         include_once \GO::config()->root_path . 'modules/' . $moduleFolder . '/lib/core/zlog.php';
         include_once \GO::config()->root_path . 'modules/' . $moduleFolder . '/lib/core/statemanager.php';
         include_once \GO::config()->root_path . 'modules/' . $moduleFolder . '/lib/core/streamer.php';
         include_once \GO::config()->root_path . 'modules/' . $moduleFolder . '/lib/core/asdevice.php';
         include_once \GO::config()->root_path . 'modules/' . $moduleFolder . '/lib/core/interprocessdata.php';
         include_once \GO::config()->root_path . 'modules/' . $moduleFolder . '/lib/core/loopdetection.php';
         include_once \GO::config()->root_path . 'modules/' . $moduleFolder . '/lib/exceptions/exceptions.php';
         include_once \GO::config()->root_path . 'modules/' . $moduleFolder . '/lib/utils/utils.php';
         include_once \GO::config()->root_path . 'modules/' . $moduleFolder . '/lib/utils/zpushadmin.php';
         include_once \GO::config()->root_path . 'modules/' . $moduleFolder . '/lib/request/request.php';
         include_once \GO::config()->root_path . 'modules/' . $moduleFolder . '/lib/request/requestprocessor.php';
         include_once \GO::config()->root_path . 'modules/' . $moduleFolder . '/lib/interface/ibackend.php';
         include_once \GO::config()->root_path . 'modules/' . $moduleFolder . '/lib/interface/ichanges.php';
         include_once \GO::config()->root_path . 'modules/' . $moduleFolder . '/lib/interface/iexportchanges.php';
         include_once \GO::config()->root_path . 'modules/' . $moduleFolder . '/lib/interface/iimportchanges.php';
         include_once \GO::config()->root_path . 'modules/' . $moduleFolder . '/lib/interface/isearchprovider.php';
         include_once \GO::config()->root_path . 'modules/' . $moduleFolder . '/lib/interface/istatemachine.php';
         include_once \GO::config()->root_path . 'modules/' . $moduleFolder . '/lib/syncobjects/syncobject.php';
         include_once \GO::config()->root_path . 'modules/' . $moduleFolder . '/lib/syncobjects/syncbasebody.php';
         include_once \GO::config()->root_path . 'modules/' . $moduleFolder . '/lib/syncobjects/syncbaseattachment.php';
         include_once \GO::config()->root_path . 'modules/' . $moduleFolder . '/lib/syncobjects/syncmailflags.php';
         include_once \GO::config()->root_path . 'modules/' . $moduleFolder . '/lib/syncobjects/syncrecurrence.php';
         include_once \GO::config()->root_path . 'modules/' . $moduleFolder . '/lib/syncobjects/syncappointment.php';
         include_once \GO::config()->root_path . 'modules/' . $moduleFolder . '/lib/syncobjects/syncappointmentexception.php';
         include_once \GO::config()->root_path . 'modules/' . $moduleFolder . '/lib/syncobjects/syncattachment.php';
         include_once \GO::config()->root_path . 'modules/' . $moduleFolder . '/lib/syncobjects/syncattendee.php';
         include_once \GO::config()->root_path . 'modules/' . $moduleFolder . '/lib/syncobjects/syncmeetingrequestrecurrence.php';
         include_once \GO::config()->root_path . 'modules/' . $moduleFolder . '/lib/syncobjects/syncmeetingrequest.php';
         include_once \GO::config()->root_path . 'modules/' . $moduleFolder . '/lib/syncobjects/syncmail.php';
         include_once \GO::config()->root_path . 'modules/' . $moduleFolder . '/lib/syncobjects/syncnote.php';
         include_once \GO::config()->root_path . 'modules/' . $moduleFolder . '/lib/syncobjects/synccontact.php';
         include_once \GO::config()->root_path . 'modules/' . $moduleFolder . '/lib/syncobjects/syncfolder.php';
         include_once \GO::config()->root_path . 'modules/' . $moduleFolder . '/lib/syncobjects/syncprovisioning.php';
         include_once \GO::config()->root_path . 'modules/' . $moduleFolder . '/lib/syncobjects/synctaskrecurrence.php';
         include_once \GO::config()->root_path . 'modules/' . $moduleFolder . '/lib/syncobjects/synctask.php';
         include_once \GO::config()->root_path . 'modules/' . $moduleFolder . '/lib/syncobjects/syncoofmessage.php';
         include_once \GO::config()->root_path . 'modules/' . $moduleFolder . '/lib/syncobjects/syncoof.php';
         include_once \GO::config()->root_path . 'modules/' . $moduleFolder . '/lib/syncobjects/syncuserinformation.php';
         include_once \GO::config()->root_path . 'modules/' . $moduleFolder . '/lib/syncobjects/syncdeviceinformation.php';
         include_once \GO::config()->root_path . 'modules/' . $moduleFolder . '/lib/syncobjects/syncdevicepassword.php';
         include_once \GO::config()->root_path . 'modules/' . $moduleFolder . '/lib/syncobjects/syncitemoperationsattachment.php';
         include_once \GO::config()->root_path . 'modules/' . $moduleFolder . '/config.php';
         include_once \GO::config()->root_path . 'modules/' . $moduleFolder . '/version.php';
         set_include_path(get_include_path() . PATH_SEPARATOR . BASE_PATH);
         \ZPush::CheckConfig();
     }
 }
Пример #4
0
 /**
  * Moves a file from one location to another
  *
  * @param string $sourcePath The path to the file which should be moved
  * @param string $destinationPath The full destination path, so not just the destination parent node
  * @return int
  */
 public function move($sourcePath, $destinationPath)
 {
     \GO::debug("ObjectTree::move({$sourcePath}, {$destinationPath})");
     $moveable = $this->getNodeForPath($sourcePath);
     $destination = $this->getNodeForPath(dirname($destinationPath));
     $targetServerPath = $destination->getServerPath() . '/' . \GO\Base\Fs\File::utf8Basename($destinationPath);
     $moveable->move($targetServerPath);
 }
Пример #5
0
 public static function save(&$file)
 {
     try {
         if (\GO::router()->getController() && \GO::router()->getController()->getRoute() != 'maintenance') {
             Model\Filesearch::model()->createFromFile($file, !empty(\GO::config()->filesearch_direct_index));
         }
     } catch (\Exception $e) {
         \GO::debug((string) $e);
     }
 }
Пример #6
0
 /**
  * Returns an array with all the child nodes
  *
  * @return Sabre\DAV\INode[]
  */
 public function getChildren()
 {
     \GO::debug('Shared::getChildren()');
     $shares = \GO\Files\Model\Folder::model()->getTopLevelShares(\GO\Base\Db\FindParams::newInstance()->limit(100));
     $nodes = array();
     foreach ($shares as $folder) {
         $nodes[] = new \GO\DAV\FS\Directory($folder->path);
     }
     return $nodes;
 }
Пример #7
0
 public function __construct(Account $account, $attributes)
 {
     $this->_account = $account;
     \GO::debug("GO\\Email\\Model\\ImapMailbox:" . var_export($attributes, true));
     $this->_attributes = $attributes;
     //		if(isset($this->_attributes['name']))
     //			$this->_attributes['name']=\GO\Base\Mail\Utils::utf7_decode($this->_attributes["name"]);
     //throw new \Exception(var_export($attributes, true));
     //$this->_children = array();
 }
Пример #8
0
 /**
  * Movesthe node
  *
  * @param string $name The new name
  * @return void
  */
 public function move($newPath)
 {
     $this->checkWritePermission();
     \GO::debug('DAVFile::move(' . $this->path . ' -> ' . $newPath . ')');
     $destFsFolder = new \GO\Base\Fs\Folder(dirname($newPath));
     $destFolder = \GO\Files\Model\Folder::model()->findByPath($destFsFolder->stripFileStoragePath());
     $file = \GO\Files\Model\File::model()->findByPath($this->relpath);
     $file->folder_id = $destFolder->id;
     $file->name = \GO\Base\Fs\File::utf8Basename($newPath);
     $file->save();
     $this->relpath = $file->path;
     $this->path = \GO::config()->file_storage_path . $this->relpath;
 }
Пример #9
0
 /**
  * The code that needs to be called when the cron is running
  * 
  * If $this->enableUserAndGroupSupport() returns TRUE then the run function 
  * will be called for each $user. (The $user parameter will be given)
  * 
  * If $this->enableUserAndGroupSupport() returns FALSE then the 
  * $user parameter is null and the run function will be called only once.
  * 
  * @param \GO\Base\Cron\CronJob $cronJob
  * @param \GO\Base\Model\User $user [OPTIONAL]
  */
 public function run(\GO\Base\Cron\CronJob $cronJob, \GO\Base\Model\User $user = null)
 {
     \GO::session()->runAsRoot();
     \GO::debug("Start updating public calendars.");
     $calendars = \GO\Calendar\Model\Calendar::model()->findByAttribute('public', true);
     foreach ($calendars as $calendar) {
         $file = new \GO\Base\Fs\File($calendar->getPublicIcsPath());
         if (!$file->exists()) {
             \GO::debug("Creating " . $file->path() . ".");
             $file->touch(true);
         }
         $file->putContents($calendar->toVObject());
         \GO::debug("Updating " . $calendar->name . " to " . $file->path() . ".");
     }
     \GO::debug("Finished updating public calendars.");
 }
Пример #10
0
 public static function beforeLogin($params, &$response)
 {
     $oldIgnoreAcl = \GO::setIgnoreAclPermissions(true);
     $ia = new Authenticator();
     if ($ia->setCredentials($params['username'], $params['password'])) {
         if ($ia->imapAuthenticate()) {
             if (!$ia->user) {
                 \GO::debug("IMAPAUTH: Group-Office user doesn't exist.");
                 if (!isset($params['first_name'])) {
                     $response['needCompleteProfile'] = true;
                     $response['success'] = false;
                     $response['feedback'] = \GO::t('pleaseCompleteProfile', 'imapauth');
                     return false;
                 } else {
                     //user doesn't exist. create it now
                     $user = new \GO\Base\Model\User();
                     $user->email = $ia->email;
                     $user->username = $ia->goUsername;
                     $user->password = $ia->imapPassword;
                     $user->first_name = $params['first_name'];
                     $user->middle_name = $params['middle_name'];
                     $user->last_name = $params['last_name'];
                     try {
                         if (!$user->save()) {
                             throw new \Exception("Could not save user: "******"\n", $user->getValidationErrors()));
                         }
                         if (!empty($ia->config['groups'])) {
                             $user->addToGroups($ia->config['groups']);
                         }
                         $ia->user = $user;
                         $user->checkDefaultModels();
                         //todo testen of deze regel nodig is om e-mail account aan te maken voor nieuwe gebruiker
                         $ia->createEmailAccount($user, $ia->config, $ia->imapUsername, $ia->imapPassword);
                     } catch (\Exception $e) {
                         \GO::debug('IMAPAUTH: Failed creating user ' . $ia->goUsername . ' and e-mail ' . $ia->email . 'Exception: ' . $e->getMessage(), E_USER_WARNING);
                     }
                 }
             }
         } else {
             $response['feedback'] = GO::t('badLogin') . ' (IMAP)';
             return false;
         }
     }
     \GO::setIgnoreAclPermissions($oldIgnoreAcl);
 }
Пример #11
0
 protected function afterDisplay(&$response, &$model, &$params)
 {
     \GO::debug(get_class($this));
     $response['data']['photo_url'] = $model->photoThumbURL;
     $response['data']['original_photo_url'] = $model->photoURL;
     $response['data']['addressbook_name'] = $model->addressbook->name;
     $response['data']['google_maps_link'] = \GO\Base\Util\Common::googleMapsLink($model->address, $model->address_no, $model->city, $model->country);
     $response['data']['formatted_address'] = nl2br($model->getFormattedAddress());
     $response['data']['post_google_maps_link'] = \GO\Base\Util\Common::googleMapsLink($model->post_address, $model->post_address_no, $model->post_city, $model->post_country);
     $response['data']['post_formatted_address'] = nl2br($model->getFormattedPostAddress());
     $response['data']['employees'] = array();
     $sortAlias = \GO::user()->sort_name == "first_name" ? array('first_name', 'last_name') : array('last_name', 'first_name');
     $stmt = $model->contacts(\GO\Base\Db\FindParams::newInstance()->order($sortAlias));
     while ($contact = $stmt->fetch()) {
         $response['data']['employees'][] = array('id' => $contact->id, 'name' => $contact->getName(\GO::user()->sort_name), 'function' => $contact->function, 'email' => $contact->email);
     }
     if (\GO::modules()->customfields && isset($response['data']['customfields']) && \GO\Customfields\Model\DisableCategories::isEnabled("GO\\Addressbook\\Model\\Company", $model->addressbook_id)) {
         $ids = \GO\Customfields\Model\EnabledCategory::model()->getEnabledIds("GO\\Addressbook\\Model\\Company", $model->addressbook_id);
         $enabled = array();
         foreach ($response['data']['customfields'] as $cat) {
             if (in_array($cat['id'], $ids)) {
                 $enabled[] = $cat;
             }
         }
         $response['data']['customfields'] = $enabled;
     }
     if (\GO::modules()->isInstalled('customfields')) {
         $response['data']['items_under_blocks'] = array();
         $enabledBlocksStmt = \GO\Customfields\Model\EnabledBlock::getEnabledBlocks($model->addressbook_id, 'GO\\Addressbook\\Model\\Addressbook', $model->className());
         foreach ($enabledBlocksStmt as $i => $enabledBlockModel) {
             $items = $enabledBlockModel->block->getItemNames($model->id, $model->name);
             if (!empty($items)) {
                 $blockedItemsEl = array('id' => $i, 'block_name' => $enabledBlockModel->block->name, 'items' => $items);
                 $blockedItemsEl['model_name'] = !empty($items[0]) ? $items[0]['model_name'] : '';
                 $modelNameArr = explode('_', $blockedItemsEl['model_name']);
                 $blockedItemsEl['type'] = !empty($modelNameArr[3]) ? $modelNameArr[3] : '';
                 $response['data']['items_under_blocks'][] = $blockedItemsEl;
             }
         }
     }
     return parent::afterDisplay($response, $model, $params);
 }
Пример #12
0
 /**
  * Runs a controller action with the given params
  * 
  * @param array $params 
  */
 public function runController($params = false)
 {
     if (!$params) {
         $params = array_merge($_REQUEST, \GO::request()->post);
     }
     $r = !empty($params['r']) ? explode('/', $params['r']) : array();
     $this->_r = isset($params['r']) ? $params['r'] : "";
     if (\GO::config()->debug || \GO::config()->debug_log) {
         $log = 'Controller route r=';
         if (isset($params['r'])) {
             $log .= $params['r'];
         } else {
             $log = 'No r parameter given';
         }
         \GO::debug($log);
     }
     $first = isset($r[0]) ? ucfirst($r[0]) : 'Auth';
     if (empty($r[2]) && file_exists(\GO::config()->root_path . 'controller/' . $first . 'Controller.php')) {
         //this is a controller name that belongs to the Group-Office framework
         $module = 'Core';
         $controller = $first;
         $action = isset($r[1]) ? $r[1] : '';
     } else {
         //it must be pointing to a module
         $module = strtolower($r[0]);
         $controller = isset($r[1]) ? ucfirst($r[1]) : 'Default';
         $action = isset($r[2]) ? $r[2] : '';
     }
     $action = strtolower($action);
     $controllerClass = 'GO\\';
     if (!empty($module)) {
         $controllerClass .= ucfirst($module) . '\\';
     }
     $controllerClass .= 'Controller\\' . $controller . 'Controller';
     if (preg_match('/[^A-Za-z0-9_\\\\]+/', $controllerClass, $matches)) {
         $err = "Only these charactes are allowed in controller names: A-Za-z0-9_";
         echo $err;
         trigger_error($err, E_USER_ERROR);
     }
     $this->_action = $action;
     if (!class_exists($controllerClass)) {
         if (!headers_sent()) {
             header("HTTP/1.0 404 Not Found");
             header("Status: 404 Not Found");
         }
         if (empty($_SERVER['QUERY_STRING'])) {
             $_SERVER['QUERY_STRING'] = "[EMPTY QUERY_STRING]";
         }
         $errorMsg = "Controller('" . $controllerClass . "') not found: " . $_SERVER['QUERY_STRING'] . " " . var_export($_REQUEST, true);
         echo '<h1>404 Not found</h1>';
         echo '<p>' . $errorMsg . '</p>';
         if (\GO::config()->debug) {
             trigger_error($errorMsg, E_USER_ERROR);
         }
     }
     try {
         $this->_controller = new $controllerClass();
         $this->_controller->run($action, $params);
     } catch (Exception\NotFound $e) {
         header("HTTP/1.0 404 Not Found");
         header("Status: 404 Not Found");
         if (empty($_SERVER['QUERY_STRING'])) {
             $_SERVER['QUERY_STRING'] = "[EMPTY QUERY_STRING]";
         }
         $errorMsg = "Controller action '" . $action . " not found in controller class '" . $controllerClass . "': " . $_SERVER['QUERY_STRING'] . " " . var_export($_REQUEST, true);
         echo '<h1>404 Not found</h1>';
         echo '<p>' . $errorMsg . '</p>';
         if (\GO::config()->debug) {
             trigger_error($errorMsg, E_USER_ERROR);
         }
     }
 }
Пример #13
0
 function send_command($command, $piped = false)
 {
     if ($piped) {
         $final_command = '';
         foreach ($command as $v) {
             $final_command .= 'A' . $this->command_number() . ' ' . $v;
         }
         $command = $final_command;
     } else {
         $command = 'A' . $this->command_number() . ' ' . $command;
     }
     if (!is_resource($this->handle)) {
         throw new \Exception("Lost connection to " . $this->server);
     }
     $this->lastCommand = $command;
     if (!fputs($this->handle, $command)) {
         throw new \Exception("Lost connection to " . $this->server);
         //				eturn false;
     }
     if (!empty(\GO::session()->values['debugSql'])) {
         \GO::debug("S: " . $command);
     }
     $this->commands[trim($command)] = \GO\Base\Util\Date::getmicrotime();
 }
Пример #14
0
 /**
  * Fire an event so that listener functions will be called.
  * 
  * @param String $eventName Name fo the event
  * @param Array $params Paramters for the listener function
  * 
  * @return boolean If one listerner returned false it will stop execution of 
  *  other listeners and will return false.
  */
 public function fireEvent($eventName, $params = array())
 {
     $className = str_replace('\\', '-', get_class($this));
     //		do{
     if (!isset(self::$listeners[$className])) {
         //listeners array will be loaded from a file. Because addListener is only called once when there is no cache.
         $listeners = array();
         $cacheFile = \GO::config()->orig_tmpdir . 'cache/listeners/' . $className . '.php';
         //			$cacheFile = \GO::config()->orig_tmpdir.'cache/listeners/'.$className.'.php';
         if (file_exists($cacheFile)) {
             require $cacheFile;
         }
         self::$listeners[$className] = $listeners;
     }
     if (isset(self::$listeners[$className][$eventName])) {
         foreach (self::$listeners[$className][$eventName] as $listener) {
             \GO::debug('Firing listener for class ' . $className . ' event ' . $eventName . ': ' . $listener[0] . '::' . $listener[1]);
             $method = !empty($listener[0]) ? array($listener[0], $listener[1]) : $listener[1];
             $return = call_user_func_array($method, $params);
             if ($return === false) {
                 \GO::debug("Event '{$eventName}' cancelled by " . $listener[0] . '::' . $listener[1]);
                 return false;
             }
         }
     }
     //		}
     //		while($className = get_parent_class($className));
     return true;
 }
Пример #15
0
 private function _removeQuota()
 {
     if (\GO::config()->quota > 0) {
         \GO::debug("Removing quota: {$this->size}");
         \GO::config()->save_setting("file_storage_usage", \GO::config()->get_setting('file_storage_usage') - $this->size);
     }
     if ($this->folder->quotaUser) {
         $this->folder->quotaUser->calculatedDiskUsage(0 - $this->size)->save(true);
     }
 }
Пример #16
0
require '../../GO.php';
//require_once \GO::config()->root_path.'go/vendor/SabreDAV/lib/Sabre/autoload.php';
// Authentication backend
$authBackend = new \GO\Dav\Auth\Backend();
if (!\GO::modules()->isInstalled('dav')) {
    $msg = 'DAV module not installed. Install it at Start menu -> Apps.';
    trigger_error($msg, E_USER_WARNING);
    exit($msg);
}
$root = new \GO\Dav\Fs\RootDirectory();
$tree = new \GO\Dav\ObjectTree($root);
// The rootnode needs in turn to be passed to the server class
$server = new Sabre\DAV\Server($tree);
$server->debugExceptions = \GO::config()->debug;
$server->subscribeEvent('exception', function ($e) {
    \GO::debug((string) $e);
});
//baseUri can also be /webdav/ with:
//Alias /webdav/ /path/to/files.php
$baseUri = strpos($_SERVER['REQUEST_URI'], 'files.php') ? \GO::config()->host . 'modules/dav/files.php/' : '/webdav/';
$server->setBaseUri($baseUri);
$tmpDir = \GO::config()->getTempFolder()->createChild('dav', false);
$locksDir = $tmpDir->createChild('locksdb', false);
$locksDir->create();
// Support for LOCK and UNLOCK
//$lockBackend = new Sabre\DAV\Locks\Backend\FS($locksDir->path());
$lockBackend = new Sabre\DAV\Locks\Backend\PDO(\GO::getDbConnection(), 'dav_locks');
$lockPlugin = new Sabre\DAV\Locks\Plugin($lockBackend);
$server->addPlugin($lockPlugin);
// Support for html frontend
$browser = new Sabre\DAV\Browser\Plugin();
Пример #17
0
 public static function checkFolderTrigger(&$self, &$response, &$model, &$params, $modifiedAttributes)
 {
     $trigger = Model\Trigger::model()->findSingleByAttributes(array('model_type_id' => \GO\Files\Model\File::model()->modelTypeId(), 'model_attribute' => 'folder_id', 'model_attribute_value' => $model->id));
     if (!empty($params['wf_process_id'])) {
         if (!$trigger) {
             \GO::debug('NO EXISTING TRIGGER FOUND, CREATE NEW TRIGGER');
             $trigger = new Model\Trigger();
             $trigger->model_type_id = \GO\Files\Model\File::model()->modelTypeId();
             $trigger->model_attribute = 'folder_id';
             $trigger->model_attribute_value = $model->id;
         }
         $trigger->process_id = $params['wf_process_id'];
         $trigger->save();
     } elseif ($trigger) {
         $trigger->delete();
     }
 }
Пример #18
0
 /**
  * This is the function that is called from the server's cron deamon.
  * The cron deamon is supposed to call this function every minute.
  * 
  * TODO: Check if 1 minute doesn't set the server under heavy load.
  */
 protected function actionRun($params)
 {
     //		$this->requireCli();
     $jobAvailable = false;
     \GO::debug('CRONJOB START (PID:' . getmypid() . ')');
     while ($cronToHandle = $this->_findNextCron()) {
         $jobAvailable = true;
         \GO::debug('CRONJOB FOUND');
         $cronToHandle->run();
     }
     if (!$jobAvailable) {
         \GO::debug('NO CRONJOB FOUND');
     }
     \GO::debug('CRONJOB STOP (PID:' . getmypid() . ')');
     \GO::config()->save_setting('cron_last_run', time());
 }
Пример #19
0
 private static function _addAccount($user, $domainName)
 {
     if (\GO::modules()->isInstalled('email')) {
         \GO::debug("SERVERCLIENT: Adding e-mail account for " . $user->username . '@' . $domainName);
         $accountModel = new \GO\Email\Model\Account();
         $accountModel->user_id = $user->id;
         $accountModel->mbroot = \GO::config()->serverclient_mbroot;
         $accountModel->use_ssl = \GO::config()->serverclient_use_ssl;
         $accountModel->novalidate_cert = \GO::config()->serverclient_novalidate_cert;
         //			$accountModel->type=\GO::config()->serverclient_type;
         $accountModel->host = \GO::config()->serverclient_host;
         $accountModel->port = \GO::config()->serverclient_port;
         //			$accountModel->name=$user->name;
         $accountModel->username = $user->username;
         if (empty(\GO::config()->serverclient_dont_add_domain_to_imap_username)) {
             $accountModel->username .= '@' . $domainName;
         }
         $accountModel->password = $user->getUnencryptedPassword();
         $accountModel->smtp_host = \GO::config()->serverclient_smtp_host;
         $accountModel->smtp_port = \GO::config()->serverclient_smtp_port;
         $accountModel->smtp_encryption = \GO::config()->serverclient_smtp_encryption;
         $accountModel->smtp_username = \GO::config()->serverclient_smtp_username;
         $accountModel->smtp_password = \GO::config()->serverclient_smtp_password;
         $accountModel->save();
         $alias = strpos($user->email, '@' . $domainName) ? $user->email : $accountModel->username;
         if (!strpos($alias, '@')) {
             $alias .= '@' . $domainName;
         }
         $accountModel->addAlias($alias, $user->name);
     }
 }
Пример #20
0
 private function _launchBatchSend($mailing_id)
 {
     $mailing = \GO\Addressbook\Model\SentMailing::model()->findByPk($mailing_id);
     if (!$mailing) {
         throw new \Exception("Mailing not found!\n");
     }
     $joinCriteria = \GO\Base\Db\FindCriteria::newInstance()->addRawCondition('t.id', 'a.account_id');
     $findParams = \GO\Base\Db\FindParams::newInstance()->single()->join(\GO\Email\Model\Alias::model()->tableName(), $joinCriteria, 'a')->criteria(\GO\Base\Db\FindCriteria::newInstance()->addCondition('id', $mailing->alias_id, '=', 'a'));
     $account = \GO\Email\Model\Account::model()->find($findParams);
     $pwdParam = '';
     if ($account && !empty(\GO::session()->values['emailModule']['smtpPasswords'][$account->id])) {
         $mailing->temp_pass = \GO::session()->values['emailModule']['smtpPasswords'][$account->id];
         $mailing->save();
         $pwdParam = '--smtp_password='******'emailModule']['smtpPasswords'][$account->id];
     }
     $log = \GO::config()->file_storage_path . 'log/mailings/';
     if (!is_dir($log)) {
         mkdir($log, 0755, true);
     }
     $log .= $mailing_id . '.log';
     $cmd = \GO::config()->cmd_php . ' ' . \GO::config()->root_path . 'groupofficecli.php -r=addressbook/sentMailing/batchSend -c="' . \GO::config()->get_config_file() . '" --mailing_id=' . $mailing_id . ' ' . $pwdParam . ' >> ' . $log;
     if (!\GO\Base\Util\Common::isWindows()) {
         $cmd .= ' 2>&1 &';
     }
     file_put_contents($log, \GO\Base\Util\Date::get_timestamp(time()) . "\r\n" . $cmd . "\r\n\r\n", FILE_APPEND);
     if (\GO\Base\Util\Common::isWindows()) {
         pclose(popen("start /B " . $cmd, "r"));
     } else {
         exec($cmd, $outputarr, $returnvar);
         \GO::debug('===== CMD =====');
         \GO::debug($cmd);
         \GO::debug('===== OUTPUT ARR =====');
         \GO::debug(var_export($outputarr, true));
         \GO::debug('===== RETURN VAR =====');
         \GO::debug(var_export($returnvar, true));
     }
 }
Пример #21
0
 /**
  * Login to a Group-Office installation
  * 
  * @param string $baseUrl eg. http://customer.group-office.com/
  * @param string $username
  * @param string $password
  * @return boolean
  * @throws Exception 
  */
 public function groupofficeLogin($baseUrl, $username, $password)
 {
     $postfields = array('username' => $username, 'password' => $password);
     \GO::debug("Request: " . $baseUrl . '?r=auth/login');
     $response = $this->request($baseUrl . '?r=auth/login', $postfields);
     \GO::debug("Response: " . $response);
     $response = json_decode($response, true);
     //		var_dump($response);
     if (!isset($response['success']) || !$response['success']) {
         \GO::debug($response);
         $feedback = "Could not connect to " . \GO::config()->product_name . " installation at " . $baseUrl;
         if (isset($response['feedback'])) {
             $feedback .= "\n\n" . $response['feedback'];
         } else {
             $feedback .= "\n\n" . var_export($response, true);
         }
         throw new \Exception($feedback);
     }
     $this->baseParams['security_token'] = $response['security_token'];
     return true;
 }
Пример #22
0
 /**
  * 
  * @param Participant $participant
  * @return Event 
  */
 public function createCopyForParticipant(Participant $participant)
 {
     //		$calendar = Calendar::model()->getDefault($user);
     //
     //		return $this->duplicate(array(
     //			'user_id'=>$user->id,
     //			'calendar_id'=>$calendar->id,
     //			'is_organizer'=>false
     //		));
     \GO::debug("Creating event copy for " . $participant->name);
     //create event in participant's default calendar if the current user has the permission to do that
     $calendar = $participant->getDefaultCalendar();
     if ($calendar && $calendar->userHasCreatePermission()) {
         //find if an event for this exception already exists.
         $exceptionDate = $this->exception_for_event_id != 0 ? $this->start_time : false;
         $existing = Event::model()->findByUuid($this->uuid, 0, $calendar->id, $exceptionDate);
         if (!$existing) {
             //ignore acl permissions because we allow users to schedule events directly when they have access through
             //the special freebusypermissions module.
             $participantEvent = $this->duplicate(array('calendar_id' => $calendar->id, 'user_id' => $participant->user_id, 'is_organizer' => false), true, true);
             return $participantEvent;
         } else {
             \GO::debug("Found existing event: " . $existing->id . ' - ' . $existing->getAttribute('start_time', 'formatted'));
             //correct errors that somehow occurred.
             $attributes = $this->getAttributeSelection(array('name', 'start_time', 'end_time', 'rrule', 'repeat_end_time', 'location', 'description', 'private'), 'raw');
             $existing->setAttributes($attributes, false);
             if ($existing->isModified()) {
                 $existing->updatingRelatedEvent = true;
                 $existing->save(true);
             }
             return $existing;
         }
     }
     return false;
 }
Пример #23
0
 protected function afterDisplay(&$response, &$model, &$params)
 {
     $response['data']['path'] = $model->path;
     $response['data']['size'] = \GO\Base\Util\Number::formatSize($model->fsFile->size());
     $response['data']['extension'] = strtolower($model->fsFile->extension());
     $response['data']['type'] = \GO::t($response['data']['extension'], 'base', 'filetypes');
     $response['data']['locked_user_name'] = $model->lockedByUser ? $model->lockedByUser->name : '';
     $response['data']['locked'] = $model->isLocked();
     $response['data']['unlock_allowed'] = $model->unlockAllowed();
     if (!empty($model->random_code) && time() < $model->expire_time) {
         $response['data']['expire_time'] = \GO\Base\Util\Date::get_timestamp(\GO\Base\Util\Date::date_add($model->expire_time, -1), false);
         $response['data']['download_link'] = $model->emailDownloadURL;
     } else {
         $response['data']['expire_time'] = "";
         $response['data']['download_link'] = "";
     }
     $response['data']['url'] = \GO::url('files/file/download', array('id' => $model->id), false, true);
     if ($model->fsFile->isImage()) {
         $response['data']['thumbnail_url'] = $model->thumbURL;
     } else {
         $response['data']['thumbnail_url'] = "";
     }
     $response['data']['handler'] = 'startjs:function(){' . $model->getDefaultHandler()->getHandler($model) . '}:endjs';
     try {
         if (\GO::modules()->filesearch) {
             $filesearch = \GO\Filesearch\Model\Filesearch::model()->findByPk($model->id);
             //				if(!$filesearch){
             //					$filesearch = \GO\Filesearch\Model\Filesearch::model()->createFromFile($model);
             //				}
             if ($filesearch) {
                 $response['data'] = array_merge($filesearch->getAttributes('formatted'), $response['data']);
                 if (!empty($params['query_params'])) {
                     $qp = json_decode($params['query_params'], true);
                     if (isset($qp['content_all'])) {
                         $c = new \GO\Filesearch\Controller\FilesearchController();
                         $response['data']['text'] = $c->highlightSearchParams($qp, $response['data']['text']);
                     }
                 }
             } else {
                 $response['data']['text'] = \GO::t('notIndexedYet', 'filesearch');
             }
         }
     } catch (\Exception $e) {
         \GO::debug((string) $e);
         $response['data']['text'] = "Index out of date. Please rebuild it using the admin tools.";
     }
     return parent::afterDisplay($response, $model, $params);
 }
Пример #24
0
 /**
  * Search the LDAP directory
  * 
  * @param string $baseDN
  * @param string $query
  * @param array $attributes
  * @return Result 
  */
 public function search($baseDN, $query, $attributes = null)
 {
     \GO::debug("LDAP::search({$baseDN}, {$query})");
     $this->connect();
     if (isset($attributes)) {
         $searchId = ldap_search($this->_link, $baseDN, $query, $attributes);
     } else {
         $searchId = ldap_search($this->_link, $baseDN, $query);
     }
     if (!$searchId) {
         throw new \Exception("Invalid LDAP search BaseDN: {$baseDN}, Query: {$query}");
     }
     return new Result($this, $searchId);
 }
Пример #25
0
 protected function actionCheckUnseen($params)
 {
     $response = array("success" => true);
     $response['email_status']['total_unseen'] = 0;
     $response['email_status']['unseen'] = array();
     \GO::session()->closeWriting();
     $findParams = \GO\Base\Db\FindParams::newInstance()->ignoreAdminGroup()->select('t.*');
     $stmt = \GO\Email\Model\Account::model()->find($findParams);
     while ($account = $stmt->fetch()) {
         try {
             if ($account->getDefaultAlias()) {
                 $checkMailboxArray = $account->getAutoCheckMailboxes();
                 //$imap = $account->openImapConnection();
                 $existingCheckMailboxArray = array();
                 foreach ($checkMailboxArray as $checkMailboxName) {
                     if (!empty($checkMailboxName)) {
                         $mailbox = new \GO\Email\Model\ImapMailbox($account, array('name' => $checkMailboxName));
                         if ($mailbox->exists()) {
                             if (!isset($response['email_status']['has_new']) && $mailbox->hasAlarm()) {
                                 $response['email_status']['has_new'] = true;
                             }
                             $mailbox->snoozeAlarm();
                             $response['email_status']['unseen'][] = array('account_id' => $account->id, 'mailbox' => $checkMailboxName, 'unseen' => $mailbox->unseen);
                             $response['email_status']['total_unseen'] += $mailbox->unseen;
                             $existingCheckMailboxArray[] = $checkMailboxName;
                         }
                     }
                 }
                 $account->check_mailboxes = implode(',', $existingCheckMailboxArray);
                 if ($account->isModified("check_mailboxes")) {
                     $account->save();
                 }
                 if ($imap = $account->getImapConnection()) {
                     $imap->disconnect();
                 }
             }
         } catch (\Exception $e) {
             \GO::debug($e->getMessage());
         }
     }
     \GO::debug("Total unseen: " . $response['email_status']['total_unseen']);
     //$response['email_status']['has_new']=true;
     return $response;
 }
Пример #26
0
 /**
  * Close writing to session so other concurrent requests won't be blocked.
  * When a PHP session is open the webserver won't process a new request until 
  * the session is closed again.
  */
 public function closeWriting()
 {
     \GO::debug("Session writing closed");
     session_write_close();
 }
Пример #27
0
 protected function actionModelTypes($params)
 {
     $filesupport = false;
     if (isset($params['filesupport'])) {
         $filesupport = $params['filesupport'] === "true" || $params['filesupport'] === "1" ? true : false;
     }
     $forLinks = isset($params['for_links']) && ($params['for_links'] === "true" || $params['for_links'] === "1");
     $stmt = ModelType::model()->find();
     $typesString = \GO::config()->get_setting('link_type_filter', \GO::user()->id);
     $typesArr = explode(',', $typesString);
     $types = array();
     while ($modelType = $stmt->fetch()) {
         if (class_exists($modelType->model_name)) {
             $model = \GO::getModel($modelType->model_name);
             $module = $modelType->model_name == "GO\\Base\\Model\\User" ? "users" : $model->module;
             if (GO::modules()->{$module}) {
                 if ((!$filesupport || $filesupport && $model->hasFiles()) && (!$forLinks || $modelType->model_name != 'GO\\Comments\\Model\\Comment')) {
                     $types[$model->localizedName . $modelType->id] = array('id' => $modelType->id, 'model_name' => $modelType->model_name, 'name' => $model->localizedName, 'checked' => in_array($modelType->id, $typesArr));
                 }
             }
         } else {
             \GO::debug("Missing class " . $modelType->model_name);
         }
     }
     ksort($types);
     $response['total'] = count($types);
     $response['results'] = array_values($types);
     return $response;
 }
Пример #28
0
 /**
  * Find's messages in a given mailbox
  * 
  * @param Account $account
  * @param string $mailbox
  * @param int $start
  * @param int $limit
  * @param sring $sortField See constants in \GO\Base\Mail\Imap::SORT_*
  * @param boolean $descending Sort descending
  * @param string $query
  * @param string $searchIn In what folder(s) are we searching ('current', 'all', 'recursive')
  * @return array
  */
 public function find(Account $account, $mailbox = "INBOX", $start = 0, $limit = 50, $sortField = \GO\Base\Mail\Imap::SORT_DATE, $descending = true, $query = 'ALL', $searchIn = 'current')
 {
     $results = array();
     if ($searchIn == "all") {
         foreach ($account->getRootMailboxes(false, true) as $mailbox) {
             //only search visable mailboxes not subscriptions
             if (!$mailbox->isVisible() || $mailbox->noselect) {
                 continue;
             }
             $results = array_merge($results, $this->find($account, $mailbox->name, $start, $limit, $sortField, $descending, $query, 'recursive'));
         }
         return $results;
     }
     /** @var $imap \GO\Base\Mail\Imap */
     $imap = $account->openImapConnection($mailbox);
     $headersSet = $imap->get_message_headers_set($start, $limit, $sortField, $descending, $query);
     foreach ($headersSet as $uid => $headers) {
         $message = ImapMessage::model()->createFromHeaders($account, $mailbox, $headers);
         $results[] = $message;
     }
     \GO::debug($mailbox);
     //find recursive in subfolders
     if ($searchIn === 'recursive') {
         $mailboxObj = new ImapMailbox($account, array('name' => $mailbox));
         $children = $mailboxObj->getChildren(true, false);
         foreach ($children as $child) {
             //only search visible mailboxes not subscriptions
             if (!$child->isVisible() || $child->noselect) {
                 continue;
             }
             $results = array_merge($results, $this->find($account, $child->name, $start, $limit, $sortField, $descending, $query, 'recursive'));
         }
     }
     return $results;
 }
Пример #29
0
 /**
  * Copy a file to another folder.
  * 
  * @param Folder $destinationFolder 
  * @return File
  */
 public function copy(Folder $destinationFolder, $newFileName = false)
 {
     if (!$newFileName) {
         $newFileName = $this->name();
     }
     $newPath = $destinationFolder->path() . '/' . $newFileName;
     \GO::debug('copy: ' . $this->path . ' > ' . $newPath);
     if (!copy($this->path, $newPath)) {
         $old = str_replace(\GO::config()->file_storage_path, '', $this->path);
         $new = str_replace(\GO::config()->file_storage_path, '', $newPath);
         throw new \Exception("Could not copy " . $old . " to " . $new);
     }
     chmod($newPath, octdec(\GO::config()->file_create_mode));
     if (\GO::config()->file_change_group) {
         chgrp($newPath, \GO::config()->file_change_group);
     }
     return new File($newPath);
 }
Пример #30
0
 /**
  * Check if a user has events between two given times.
  * 
  * @param type $periodStartTime
  * @param type $periodEndTime
  * @param type $userId
  * @param type $ignoreEvent
  * @return boolean 
  */
 public static function userIsAvailable($periodStartTime, $periodEndTime, $userId, $ignoreEvent = false)
 {
     $findParams = \GO\Base\Db\FindParams::newInstance()->ignoreAcl();
     $joinCriteria = \GO\Base\Db\FindCriteria::newInstance()->addRawCondition('t.calendar_id', 'c.id');
     $findParams->join(Calendar::model()->tableName(), $joinCriteria, 'c');
     $findParams->getCriteria()->addCondition('user_id', $userId, '=', 'c');
     if ($ignoreEvent) {
         $findParams->getCriteria()->addModel(Event::model())->addCondition('id', $ignoreEvent->id, '!=')->addCondition('uuid', $ignoreEvent->uuid, '!=');
     }
     $events = Event::model()->findCalculatedForPeriod($findParams, $periodStartTime, $periodEndTime, true);
     foreach ($events as $event) {
         \GO::debug($event->getName());
     }
     return count($events) == 0;
 }