Exemplo n.º 1
0
 public function formatStoreRecord($record, $model, $store)
 {
     $record['user_name'] = $model->user ? $model->user->name : 'unknown';
     $domainInfo = \GO\Postfixadmin\Model\Mailbox::model()->find(\GO\Base\Db\FindParams::newInstance()->single()->select('COUNT(*) AS mailbox_count, SUM(`usage`) AS `usage`, SUM(`quota`) AS `quota`')->criteria(\GO\Base\Db\FindCriteria::newInstance()->addCondition('domain_id', $model->id)));
     $domainInfo2 = \GO\Postfixadmin\Model\Alias::model()->find(\GO\Base\Db\FindParams::newInstance()->single()->select('COUNT(*) AS alias_count')->criteria(\GO\Base\Db\FindCriteria::newInstance()->addCondition('domain_id', $model->id)));
     $record['usage'] = \GO\Base\Util\Number::formatSize($domainInfo->usage * 1024);
     $record['quota'] = \GO\Base\Util\Number::formatSize($model->total_quota * 1024);
     $record['used_quota'] = \GO\Base\Util\Number::formatSize($domainInfo->quota * 1024);
     $record['mailbox_count'] = $domainInfo->mailbox_count . ' / ' . $model->max_mailboxes;
     $record['alias_count'] = $domainInfo2->alias_count . ' / ' . $model->max_aliases;
     return $record;
 }
Exemplo n.º 2
0
 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);
 }
Exemplo n.º 3
0
 public function __construct($message = '')
 {
     $message = \GO::t('quotaExceeded') . "\n" . sprintf(\GO::t('youAreUsing'), \GO\Base\Util\Number::formatSize($this->getUsage()), \GO\Base\Util\Number::formatSize($this->getQuota())) . $message;
     parent::__construct($message);
 }
Exemplo n.º 4
0
 /**
  * Get the size formatted. eg. 128 kb
  * @return string 
  */
 public function getHumanSize()
 {
     return \GO\Base\Util\Number::formatSize($this->getEstimatedSize());
 }
Exemplo n.º 5
0
 protected function actionAbout($params)
 {
     $response['data']['about'] = GO::t('about');
     if (GO::config()->product_name == 'Group-Office') {
         $response['data']['about'] = str_replace('{company_name}', 'Intermesh B.V.', $response['data']['about']);
     } else {
         $response['data']['about'] = str_replace('{company_name}', GO::config()->product_name, $response['data']['about']);
     }
     $strVersion = GO::config()->version;
     //		$rssUrl = "https://sourceforge.net/api/file/index/project-id/76359/mtime/desc/limit/20/rss";
     //
     //		$httpClient = new  \GO\Base\Util\HttpClient();
     //
     //		$res = $httpClient->request($rssUrl);
     //
     //		$sXml = simplexml_load_string($res);
     //
     //			if($sXml){
     //
     //			$firstItem = $sXml->channel->item[0];
     //
     //			$link = (string) $firstItem->link;
     //
     //			preg_match('/-([0-9]\.[0-9]{1,2}\.[0-9]{1,2})\./', $link, $matches);
     //
     //			$version = $matches[1];
     //
     //			$ret = version_compare(GO::config()->version, $version);
     //
     //			if($ret!== -1){
     //				$strVersion .= " <span style=\"color: red\">(v$version available)</span>";
     //			}else
     //			{
     //				$strVersion .= " (latest)";
     //			}
     //		}
     $response['data']['about'] = str_replace('{version}', $strVersion, $response['data']['about']);
     $response['data']['about'] = str_replace('{current_year}', date('Y'), $response['data']['about']);
     $response['data']['about'] = str_replace('{product_name}', GO::config()->product_name, $response['data']['about']);
     $response['data']['mailbox_usage'] = GO::config()->get_setting('mailbox_usage');
     $response['data']['file_storage_usage'] = GO::config()->get_setting('file_storage_usage');
     $response['data']['database_usage'] = GO::config()->get_setting('database_usage');
     $response['data']['total_usage'] = $response['data']['database_usage'] + $response['data']['file_storage_usage'] + $response['data']['mailbox_usage'];
     $response['data']['has_usage'] = $response['data']['total_usage'] > 0;
     foreach ($response['data'] as $key => $value) {
         if ($key != 'has_usage' && $key != 'about') {
             $response['data'][$key] = \GO\Base\Util\Number::formatSize($value);
         }
     }
     $response['success'] = true;
     return $response;
 }
Exemplo n.º 6
0
 private function _getUsage(\GO\Email\Model\Account $account)
 {
     $usage = "";
     $quota = $account->openImapConnection()->get_quota();
     if (isset($quota['usage'])) {
         if (!empty($quota['limit'])) {
             $percentage = ceil($quota['usage'] * 100 / $quota['limit']);
             $usage = sprintf(\GO::t('usage_limit', 'email'), $percentage . '%', \GO\Base\Util\Number::formatSize($quota['limit'] * 1024));
             $round5 = floor($usage / 5) * 5;
             $usage = '<span class="em-usage-' . $round5 . '">' . $usage . '</span>';
         } else {
             $usage = sprintf(\GO::t('usage', 'email'), \GO\Base\Util\Number::formatSize($quota['usage'] * 1024));
         }
     }
     //var_dump($usage);
     return $usage;
 }
Exemplo n.º 7
0
 /**
  * Compress the selected files and return as download
  * 
  * @param array $params
  * @return boolean
  * @throws \Exception
  */
 protected function actionCompressAndDownload($params)
 {
     if (!isset($params['archive_name'])) {
         throw new \Exception('No name for the archive given');
     }
     ini_set('max_execution_time', 600);
     ini_set('memory_limit', '512M');
     $sources = json_decode($params['sources'], true);
     $workingFolder = false;
     // Read the sources and create objects from them
     $sourceObjects = array();
     // The total filesize in bytes
     $totalFileSize = 0;
     // The maximum filesize that is allowed to zip (Default is 256MB)
     $maxFilesize = GO::config()->zip_max_file_size;
     for ($i = 0; $i < count($sources); $i++) {
         $path = \GO::config()->file_storage_path . $sources[$i];
         $sourceFile = \GO\Base\Fs\Base::createFromPath($path);
         // Increase the total filesize
         $totalFileSize += $sourceFile->size();
         if ($totalFileSize >= $maxFilesize) {
             throw new \Exception(sprintf(\GO::t('zipFilesizeTooBig', 'base'), \GO\Base\Util\Number::formatSize($maxFilesize, 2)));
         }
         // Set the workingFolder
         if (!$workingFolder) {
             $workingFolder = $sourceFile->parent();
         }
         $sourceObjects[] = $sourceFile;
     }
     // Create the zipped temp file object
     $archiveFile = \GO\Base\Fs\File::tempFile($params['archive_name'], 'zip');
     if ($archiveFile->exists()) {
         throw new \Exception(sprintf(\GO::t('filenameExists', 'files'), $archiveFile->stripFileStoragePath()));
     }
     // Create the zipfile
     if (\GO\Base\Fs\Zip::create($archiveFile, $workingFolder, $sourceObjects)) {
         // Output download headers
         //			\GO\Base\Util\Http::outputDownloadHeaders($archiveFile,false,true);
         //			$archiveFile->output();
         $response['archive'] = $archiveFile->stripTempPath();
         $response['success'] = true;
     } else {
         throw new \Exception("ZIP creation failed");
     }
     return $response;
 }
Exemplo n.º 8
0
 protected function actionCacheUsage($params)
 {
     $this->requireCli();
     if (!\GO::modules()->isInstalled('postfixadmin')) {
         trigger_error('Postfixadmin module must be installed', E_USER_ERROR);
     }
     $activeStmt = \GO\Postfixadmin\Model\Mailbox::model()->find();
     while ($mailboxModel = $activeStmt->fetch()) {
         echo 'Calculating size of ' . $mailboxModel->getMaildirFolder()->path() . "\n";
         $mailboxModel->cacheUsage();
         echo \GO\Base\Util\Number::formatSize($mailboxModel->usage * 1024) . "\n";
     }
 }