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); } }
public function formatStoreRecord($record, $model, $store) { $r = new \GO\Base\Mail\EmailRecipients(); $r->addRecipient($model->email, $model->name); $record['from'] = (string) $r; $record['html_signature'] = \GO\Base\Util\String::text_to_html($model->signature); $record['plain_signature'] = $model->signature; $record['signature_below_reply'] = $model->account->signature_below_reply; $record['template_id'] = 0; if (\GO::modules()->addressbook) { $defaultAccountTemplateModel = \GO\Addressbook\Model\DefaultTemplateForAccount::model()->findByPk($model->account_id); if ($defaultAccountTemplateModel) { $record['template_id'] = $defaultAccountTemplateModel->template_id; } else { $defaultUserTemplateModel = \GO\Addressbook\Model\DefaultTemplate::model()->findByPk(\GO::user()->id); if (!$defaultUserTemplateModel) { $defaultUserTemplateModel = new \GO\Addressbook\Model\DefaultTemplateForAccount(); $defaultUserTemplateModel->account_id = $model->account_id; $defaultUserTemplateModel->save(); } $record['template_id'] = $defaultUserTemplateModel->template_id; } } unset($record['signature']); return parent::formatStoreRecord($record, $model, $store); }
protected function actionGroupsWithResources($params) { $stmt = \GO\Calendar\Model\Group::model()->find(\GO\Base\Db\FindParams::newInstance()->order('t.name')->criteria(\GO\Base\Db\FindCriteria::newInstance()->addCondition('id', 1, '>'))); $response['results'] = array(); $response['total'] = 0; while ($group = $stmt->fetch()) { $record = $group->getAttributes('formatted'); if (\GO::modules()->customfields) { $record['customfields'] = \GO\Customfields\Controller\CategoryController::getEnabledCategoryData("GO\\Calendar\\Model\\Event", $group->id); } else { $record['customfields'] = array(); } $record['resources'] = array(); $calStmt = \GO\Calendar\Model\Calendar::model()->find(\GO\Base\Db\FindParams::newInstance()->permissionLevel(\GO\Base\Model\Acl::READ_PERMISSION)->joinCustomFields()->order('t.name')->criteria(\GO\Base\Db\FindCriteria::newInstance()->addCondition('group_id', $group->id))); while ($resource = $calStmt->fetch()) { $resourceRecord = $resource->getAttributes('formatted'); $record['resources'][] = $resourceRecord; } $num_resources = count($record['resources']); if ($num_resources > 0) { $response['results'][] = $record; $response['total'] += $num_resources; } } return $response; }
protected function afterDelete() { if (\GO::modules()->isInstalled('log')) { Log::create(Log::ACTION_DELETE, 'Removed ' . $this->contact->name . ' from addresslist ' . $this->addresslist->name, $this->className(), $this->contact_id . ':' . $this->addresslist_id); } return parent::afterDelete(); }
protected function actionLoad($params) { $scheduleCall = new \GO\Tasks\Model\Task(); $remoteComboFields = array('category_id' => '$model->category->name', 'tasklist_id' => '$model->tasklist->name'); if (\GO::modules()->projects) { $remoteComboFields['project_id'] = '$model->project->path'; } echo $this->renderForm($scheduleCall, $remoteComboFields); }
public function send(\Swift_Mime_Message $message, &$failedRecipients = null) { if (!empty(\GO::config()->disable_mail)) { throw new \Exception("E-mail sending is disabled!"); } if (\GO::config()->debug) { $getTo = $message->getTo(); if (!empty($getTo)) { $getTo = implode(",", array_keys($getTo)); } else { $getTo = ''; } \GO::debug("Sending e-mail to " . $getTo); } if (\GO::modules()->isInstalled("log")) { $str = ""; $from = $message->getFrom(); if (!empty($from)) { $str .= implode(",", array_keys($from)); } else { $str .= "unknown"; } $str .= " -> "; $to = $message->getTo(); if (!empty($to)) { $str .= implode(",", array_keys($to)); } $to = $message->getCc(); if (!empty($to)) { $str .= implode(",", array_keys($to)); } $to = $message->getBcc(); if (!empty($to)) { $str .= implode(",", array_keys($to)); } \GO\Log\Model\Log::create("email", $str); } // debug_print_backtrace(); // exit("NO MAIL"); //workaround https://github.com/swiftmailer/swiftmailer/issues/335 $messageId = $message->getId(); $count = parent::send($message, $failedRecipients); $message->setId($messageId); // Check if a tmp dir is created to store attachments. // If so, then remove the tmp dir if the mail is send successfully. $tmpDir = $message->getTmpDir(); if (!empty($tmpDir)) { $folder = new \GO\Base\Fs\Folder($tmpDir); // Check if folder is deleted successfully if ($folder->delete()) { \GO::debug('Clear attachments tmp directory: ' . $tmpDir); } else { \GO::debug('Failed to clear attachments tmp directory: ' . $tmpDir); } } return $count; }
public static function initListeners() { if (\GO::modules()->isInstalled('calendar')) { \GO\Calendar\Model\Event::model()->addListener("delete", "GO\\Caldav\\CaldavModule", "deleteEvent"); } if (\GO::modules()->isInstalled('tasks')) { \GO\Tasks\Model\Task::model()->addListener("delete", "GO\\Caldav\\CaldavModule", "deleteTask"); } }
public function formatStoreRecord($record, $model, $store) { $record['user_name'] = $model->user ? $model->user->name : 'unknown'; if (\GO::modules()->customfields) { $record['contactCustomfields'] = \GO\Customfields\Controller\CategoryController::getEnabledCategoryData("GO\\Addressbook\\Model\\Contact", $model->id); $record['companyCustomfields'] = \GO\Customfields\Controller\CategoryController::getEnabledCategoryData("GO\\Addressbook\\Model\\Company", $model->id); } return parent::formatStoreRecord($record, $model, $store); }
protected function afterSave($wasNew) { if ($this->aclItem) { //Add log message for activitylog here if (\GO::modules()->isInstalled("log")) { \GO\Log\Model\Log::create("acl", $this->aclItem->description, $this->aclItem->className(), $this->aclItem->id); } $this->aclItem->touch(); } return parent::afterSave($wasNew); }
protected function getThumbURL() { if ($this->logo != '') { if ($this->public_icon == '1') { return \GO::modules()->host . 'modules/bookmarks/' . $this->logo; } else { return \GO::url('core/thumb', array('src' => $this->logo, 'w' => 16, 'h' => 16)); } } else { return false; } }
public function checkDatabase() { //delete if module is no longer installed. This should happen automatically //after module uninstall but in some cases this went wrong. $parts = explode('\\', $this->model_name); $module = strtolower($parts[1]); if ($module != 'base' && !\GO::modules()->isInstalled($module)) { $this->delete(); } else { return parent::checkDatabase(); } }
/** * Will check if the event listeners have been cached and will * cache them when necessary. * * At the moment this function is called in index.php In the future this * should be called at the new entry point of the application. */ public static function cacheListeners() { \GO::debug("GO\\Base\\Observable::cacheListeners"); $cacheFolder = \GO::config()->getCacheFolder(); $folder = $cacheFolder->createChild('listeners', false); if (\GO::config()->debug) { $folder->delete(); } if (!$folder->exists()) { $folder->create(); \GO::modules()->callModuleMethod('initListeners'); } }
public function install() { if (\GO::modules()->isInstalled('site')) { $alreadyExists = \GO\Site\Model\Site::model()->findSingleByAttribute('module', 'defaultsite'); if (!$alreadyExists) { $siteProperties = array('name' => \GO::t('name', 'defaultsite'), 'user_id' => 1, 'domain' => '*', 'module' => 'defaultsite', 'ssl' => '0', 'mod_rewrite' => '0', 'mod_rewrite_base_path' => '/', 'base_path' => '', 'language' => ''); $defaultSite = new \GO\Site\Model\Site(); $defaultSite->setAttributes($siteProperties); $defaultSite->save(); } } return parent::install(); }
/** * Get all available CronJobClasses * * @return array */ public function getAllCronJobClasses() { $modules = \GO::modules()->getAllModules(); $foundCronJobClasses = array(); foreach ($modules as $module) { if (in_array($module->id, $this->_excludedModules)) { continue; } $foundCronJobClasses = array_merge($this->getModuleCronJobClasses($module), $foundCronJobClasses); } $foundCronJobClasses = array_merge($this->getCoreCronJobClasses(), $foundCronJobClasses); $foundCronJobClasses = array_merge($this->getFileStorageCronJobClasses(), $foundCronJobClasses); return $foundCronJobClasses; }
protected function actionLoad($params) { $user = \GO\Base\Model\User::model()->findByPk($params['id']); $response['data'] = $user->getAttributes('formatted'); unset($response['data']['password']); if ($user->contact) { $response['data'] = array_merge($response['data'], $user->contact->getAttributes('formatted')); } if (!empty($response['data']['date_separator']) && !empty($response['data']['date_format'])) { $response['data']['dateformat'] = $response['data']['date_separator'] . ':' . $response['data']['date_format']; } $response['success'] = true; \GO::modules()->callModuleMethod('loadSettings', array(&$this, &$params, &$response, $user)); return $response; }
public function __construct($prefixString = '') { if (!\GO::modules()->isInstalled('files')) { throw new \Exception('The current action requires the files module to be activated for the current user.'); } // Make sure the current user's folder exists. $userFolderModel = \GO\Files\Model\Folder::model()->findHomeFolder(\GO::user()); if (empty($userFolderModel)) { $userFolder = new \GO\Base\Fs\Folder(\GO::config()->file_storage_path . 'users/' . \GO::user()->username); $userFolder->create(); $userFolderModel = new \GO\Files\Model\Folder(); $userFolderModel->findByPath('users/' . \GO::user()->username, true); } parent::__construct(\GO::config()->file_storage_path . $userFolderModel->path . '/' . $prefixString . \GO\Base\Util\Date::get_timestamp(time(), true) . '.log'); }
/** * Enable Smime for this message. * The Smime module needs to be installed for this function to work. Otherwise it will return an exception. * The Smime password needs to be set in the $config['smtp_account_smime_password'] parameter in the Group-Office config file otherwise this function will throw an error. * * @throws Exception */ private function _setSmime() { // Check if the smime module is installed if (!\GO::modules()->isInstalled("smime")) { throw new \Exception('Smime module not installed'); } if (empty(\GO::config()->smtp_account_smime_password)) { throw new \Exception('No password for smime set in the Group-Office config file'); } // Check for a certificate for the give email account $cert = \GO\Smime\Model\Certificate::model()->findByPk($this->_account->id); if (!$cert || empty($cert->cert)) { throw new \Exception('No certificate enabled for the given account'); } // If the certificate is found, then get the password and attach the certificate to the message $this->setSignParams($cert->cert, \GO::config()->smtp_account_smime_password); }
protected function afterLoad(&$response, &$model, &$params) { if (\GO::modules()->customfields) { $response['customfields'] = \GO\Customfields\Controller\CategoryController::getEnabledCategoryData("GO\\Addressbook\\Model\\Company", $model->addressbook_id); } $response['data']['photo_url'] = $model->photoThumbURL; $response['data']['original_photo_url'] = $model->photoURL; $stmt = $model->addresslists(); while ($addresslist = $stmt->fetch()) { $response['data']['addresslist_' . $addresslist->id] = 1; } $response['data']['name_and_name2'] = $model->name; if (!empty($model->name2)) { $response['data']['name_and_name2'] .= ' - ' . $model->name2; } return parent::afterLoad($response, $model, $params); }
/** * 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) { $stmt = \GO::getDbConnection()->query("SHOW TABLE STATUS FROM `" . \GO::config()->db_name . "`;"); $database_usage = 0; while ($r = $stmt->fetch()) { $database_usage += $r['Data_length']; $database_usage += $r['Index_length']; } \GO::config()->save_setting('database_usage', $database_usage); $folder = new \GO\Base\Fs\Folder(\GO::config()->file_storage_path); \GO::config()->save_setting('file_storage_usage', $folder->calculateSize()); if (\GO::modules()->postfixadmin) { $findParams = \GO\Base\Db\FindParams::newInstance()->select('sum(`usage`) AS `usage`')->ignoreAcl()->single(); $result = \GO\Postfixadmin\Model\Mailbox::model()->find($findParams); \GO::config()->save_setting('mailbox_usage', $result->usage * 1024); } }
/** * Check if a class can be used. * This function checks if the class exists and if the module for the class is installed (So the tables are available, when it's an active record) * * @param string $className * @return boolean */ public static function classExists($className) { $parts = explode('\\', $className); $module = strtolower($parts[1]); if ($module != 'base' && (!GO::modules()->isInstalled($module) || !GO::modules()->isAvailable($module)) || !class_exists($className)) { return false; } else { return true; } // // if(class_exists($className)){ // // $clsParts = explode('\\',$className); // // if($clsParts[1] == 'Base' || GO::modules()->isInstalled(strtolower($clsParts[1]))) // return true; // } // // return false; }
protected function actionSwitch($params) { // // if(!\GO::user()->isAdmin()) // throw new \Exception("This feature is for admins only!"); $oldUsername = \GO::user()->username; $debug = !empty(\GO::session()->values['debug']); $user = \GO\Base\Model\User::model()->findByPk($params['user_id']); \GO::session()->values = array(); //clear session \GO::session()->setCurrentUser($user->id); //\GO::session()->setCompatibilitySessionVars(); if ($debug) { \GO::session()->values['debug'] = $debug; } \GO::infolog("ADMIN logged-in as user: \"" . $user->username . "\" from IP: " . $_SERVER['REMOTE_ADDR']); if (\GO::modules()->isInstalled('log')) { \GO\Log\Model\Log::create('switchuser', "'" . $oldUsername . "' logged in as '" . $user->username . "'"); } $this->redirect(); }
/** * * @return \GO\Base\Util\ReflectionClass[] */ public static function getCustomfieldModels() { $cfModels = array(); $moduleObjects = \GO::modules()->getAllModules(); foreach ($moduleObjects as $moduleObject) { $file = $moduleObject->path . ucfirst($moduleObject->id) . 'Module.php'; //todo load listeners if (file_exists($file)) { // require_once($file); $class = 'GO\\' . ucfirst($moduleObject->id) . '\\' . ucfirst($moduleObject->id) . 'Module'; $object = new $class(); $models = $object->findClasses("customfields/model"); foreach ($models as $customFieldModel) { if ($customFieldModel->isSubclassOf('GO\\Customfields\\Model\\AbstractCustomFieldsRecord')) { $cfModels[] = $customFieldModel; } } } } return $cfModels; }
protected function afterLoad(&$response, &$model, &$params) { //Join the contact that belongs to the user in the form response. if (\GO::modules()->isInstalled('addressbook')) { $contact = false; if (!empty($model->id)) { $contact = $model->contact; } elseif (!empty($params['contact_id'])) { $contact = \GO\Addressbook\Model\Contact::model()->findByPk($params['contact_id']); $response['data']['contact_id'] = $contact->id; } if (!$contact) { $contact = new \GO\Addressbook\Model\Contact(); } if ($contact) { $attr = $contact->getAttributes(); // Set the default addressbook ID to the "Users" addressbook when it is a new User if ($model->isNew) { $addressbook = \GO\Addressbook\Model\Addressbook::model()->getUsersAddressbook(); if ($addressbook) { $attr['addressbook_id'] = $addressbook->id; if (empty($response['remoteComboTexts'])) { $response['remoteComboTexts'] = array(); } $response['remoteComboTexts']['addressbook_id'] = $addressbook->name; // Add remote combo text } } $response['data'] = array_merge($attr, $response['data']); if (empty($response['data']['company_id'])) { $response['data']['company_id'] = ""; } } if (!empty($response['data']['date_separator']) && !empty($response['data']['date_format'])) { $response['data']['dateformat'] = $response['data']['date_separator'] . ':' . $response['data']['date_format']; } unset($response['data']['password']); } return parent::afterLoad($response, $model, $params); }
protected function actionSubmit($params) { if (\GO::modules()->addressbook && \GO::modules()->customfields) { // Remove all existing records from the table $tabs = \GO\Users\Model\CfSettingTab::model()->find(); foreach ($tabs as $t) { $t->delete(); } $contactClassName = \GO\Addressbook\Model\Contact::model()->className(); $customfieldsCategories = \GO\Customfields\Model\Category::model()->findByModel($contactClassName); // Add the posted records back to the table (go_cf_setting_tabs) foreach ($customfieldsCategories as $cfc) { if (isset($params['tab_cf_cat_' . $cfc->id])) { $cft = new \GO\Users\Model\CfSettingTab(); $cft->cf_category_id = $cfc->id; $cft->save(); } } } $settings = \GO\Users\Model\Settings::load(); return array('success' => $settings->saveFromArray($params), 'data' => $settings->getArray()); }
/** * Get all models that should exist by default for a user. * * @param int $user_id * @return \GO\Base\Db\ActiveRecord */ public static function getAllUserDefaultModels($user_id = 0) { $oldIgnoreAcl = \GO::setIgnoreAclPermissions(true); if (!isset(self::$_allUserDefaultModels)) { self::$_allUserDefaultModels = array(); $modules = \GO::modules()->getAllModules(); while ($module = array_shift($modules)) { $permissionLevel = $user_id ? Acl::getUserPermissionLevel($module->acl_id, $user_id) : 1; if ($permissionLevel) { if ($module->moduleManager) { $classes = $module->moduleManager->findClasses('model'); foreach ($classes as $class) { if ($class->isSubclassOf('GO\\Base\\Model\\AbstractUserDefaultModel')) { self::$_allUserDefaultModels[] = \GO::getModel($class->getName()); } } } } } } \GO::setIgnoreAclPermissions($oldIgnoreAcl); return self::$_allUserDefaultModels; }
protected function actionInstallModules($params) { $response = array('success' => true, 'feedback' => ''); if (!\GO::modules()->isAvailable('site')) { throw new \Exception("site module is not available!"); } if (!\GO::modules()->isAvailable('defaultsite')) { throw new \Exception("defaultsite module is not available!"); } $siteModule = new \GO\Base\Model\Module(); $siteModule->id = 'site'; if (\GO::modules()->isInstalled('site') || $siteModule->save()) { $defaultSiteModule = new \GO\Base\Model\Module(); $defaultSiteModule->id = 'defaultsite'; if (!$defaultSiteModule->save()) { $response['success'] = false; $response['feedback'] = \GO::t('installdefaultsiteerror', 'defaultsite'); } } else { $response['success'] = false; $response['feedback'] = \GO::t('installsiteerror', 'defaultsite'); } echo $this->renderJson($response); }
protected function afterLoad(&$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']['name'] = $model->fsFile->nameWithoutExtension(); if (!empty($model->user)) { $response['data']['username'] = $model->user->name; } if (!empty($model->mUser)) { $response['data']['musername'] = $model->mUser->name; } $response['data']['locked_user_name'] = $model->lockedByUser ? $model->lockedByUser->name : ''; if (\GO::modules()->customfields) { $response['customfields'] = \GO\Customfields\Controller\CategoryController::getEnabledCategoryData("GO\\Files\\Model\\File", $model->folder_id); } $fh = \GO\Files\Model\FileHandler::model()->findByPk(array('extension' => $model->extension, 'user_id' => \GO::user()->id)); if ($fh) { $fileHandler = new $fh->cls(); $response['data']['handlerCls'] = $fh->cls; $response['data']['handlerName'] = $fileHandler->getName(); } else { $response['data']['handlerCls'] = ""; $response['data']['handlerName'] = ""; } return parent::afterLoad($response, $model, $params); }
public function getDependencies() { $depends = $this->depends(); $moduleIds = array(); foreach ($depends as $moduleId) { if (!($module = \GO::modules()->isInstalled($moduleId)) || $module->isAvailable()) { foreach ($depends as $moduleId) { $moduleIds[] = $moduleId; } } } return $moduleIds; }
<?php $GO_SCRIPTS_JS .= 'GO.addressbook.lang.defaultSalutationExpression="' . \GO\Base\Util\String::escape_javascript(\GO::t('defaultSalutation', 'addressbook')) . '";'; $export_acl_id = \GO::config()->get_setting('go_addressbook_export', 0); if (!$export_acl_id) { $acl = new \GO\Base\Model\Acl(); $acl->description = 'addressbook_export'; $acl->save(); $export_acl_id = $acl->id; \GO::config()->save_setting('go_addressbook_export', $acl->id, 0); } $GO_SCRIPTS_JS .= 'GO.addressbook.export_acl_id="' . $export_acl_id . '";'; $acl_level = \GO\Base\Model\Acl::getUserPermissionLevel($export_acl_id, \GO::user()->id); $GO_SCRIPTS_JS .= 'GO.addressbook.exportPermission="' . ($acl_level ? 1 : 0) . '";'; if (\GO::modules()->customfields) { $GO_SCRIPTS_JS .= ' GO.customfields.settingsPanels={ name: "' . \GO\Addressbook\Model\Contact::model()->localizedName . '", panels: [] };' . "\n"; $stmt = \GO\Users\Model\CfSettingTab::model()->getSettingTabs(); while ($category = $stmt->fetch()) { $fields = array(); $fstmt = $category->fields(); while ($field = $fstmt->fetch()) { $fields[] = $field->toJsonArray(); } // Makes global, client-side, editable form panels for every customfield category $GO_SCRIPTS_JS .= "\n\n" . 'GO.customfields.settingsPanels.panels.push({xtype : "customformpanel", itemId:"cf-panel-' . $category->id . '", category_id: ' . $category->id . ', title : "' . htmlspecialchars($category->name, ENT_QUOTES, 'UTF-8') . '", customfields : ' . json_encode($fields) . '});' . "\n"; }
<?php if (\GO::modules()->files) { $folder = \GO\Files\Model\Folder::model()->findByPath('public/customcss', true); $GO_SCRIPTS_JS .= 'GO.customcss.filesFolderId=' . $folder->id . ';'; }