Example #1
0
 protected function actionGetUsage($params)
 {
     $domains = json_decode($params['domains']);
     $response['success'] = true;
     $record = \GO\Postfixadmin\Model\Mailbox::model()->find(\GO\Base\Db\FindParams::newInstance()->single()->select('SUM(`usage`) AS `usage`')->joinModel(array('model' => 'GO\\Postfixadmin\\Model\\Domain', 'localField' => 'domain_id', 'tableAlias' => 'd'))->criteria(\GO\Base\Db\FindCriteria::newInstance()->addInCondition('domain', $domains, 'd')));
     $response['usage'] = $record->usage;
     return $response;
 }
Example #2
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)
 {
     $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);
     }
 }
Example #3
0
 private function _createMailbox($domainModel, $demo)
 {
     $demoMailbox = \GO\Postfixadmin\Model\Mailbox::model()->findSingleByAttribute('username', $demo->email);
     if (!$demoMailbox) {
         $demoMailbox = new \GO\Postfixadmin\Model\Mailbox();
         $demoMailbox->domain_id = $domainModel->id;
         $demoMailbox->username = $demo->email;
         $demoMailbox->password = '******';
         $demoMailbox->name = $demo->name;
         $demoMailbox->save();
     }
     $accountModel = \GO\Email\Model\Account::model()->findSingleByAttribute('username', $demoMailbox->username);
     if (!$accountModel) {
         $accountModel = new \GO\Email\Model\Account();
         $accountModel->user_id = $demo->id;
         //			$accountModel->checkImapConnectionOnSave=false;
         $accountModel->host = 'localhost';
         $accountModel->port = 143;
         $accountModel->username = $demoMailbox->username;
         $accountModel->password = '******';
         $accountModel->smtp_host = "localhost";
         $accountModel->smtp_port = 25;
         $accountModel->save();
         $accountModel->addAlias($accountModel->username, $demoMailbox->name);
     }
 }
Example #4
0
 public function actionCreateManyUsers($params)
 {
     if (!\GO::user()->isAdmin()) {
         throw new \Exception("You must be logged in as admin");
     }
     \GO::config()->password_validate = false;
     \GO::session()->closeWriting();
     $amount = 50;
     $prefix = 'user';
     $domain = 'intermesh.dev';
     echo '<pre>';
     for ($i = 1; $i <= $amount; $i++) {
         echo "Creating {$prefix}{$i}\n";
         $user = \GO\Base\Model\User::model()->findSingleByAttribute('username', $prefix . $i);
         if (!$user) {
             $user = new \GO\Base\Model\User();
             $user->username = $prefix . $i;
             $user->email = $prefix . $i . '@' . $domain;
             $user->password = $prefix . $i;
             $user->first_name = $prefix;
             $user->last_name = $i;
             if (!$user->save()) {
                 var_dump($user->getValidationErrors());
                 exit;
             }
             $user->checkDefaultModels();
         }
         if (\GO::modules()->isInstalled('email') && \GO::modules()->isInstalled('postfixadmin')) {
             $domainModel = \GO\Postfixadmin\Model\Domain::model()->findSingleByAttribute('domain', $domain);
             if (!$domainModel) {
                 $domainModel = new \GO\Postfixadmin\Model\Domain();
                 $domainModel->domain = $domain;
                 $domainModel->save();
             }
             $mailboxModel = \GO\Postfixadmin\Model\Mailbox::model()->findSingleByAttributes(array('domain_id' => $domainModel->id, 'username' => $user->email));
             if (!$mailboxModel) {
                 $mailboxModel = new \GO\Postfixadmin\Model\Mailbox();
                 $mailboxModel->domain_id = $domainModel->id;
                 $mailboxModel->username = $user->email;
                 $mailboxModel->password = $prefix . $i;
                 $mailboxModel->name = $user->name;
                 $mailboxModel->save();
             }
             $accountModel = \GO\Email\Model\Account::model()->findSingleByAttributes(array('user_id' => $user->id, 'username' => $user->email));
             if (!$accountModel) {
                 $accountModel = new \GO\Email\Model\Account();
                 $accountModel->user_id = $user->id;
                 $accountModel->host = "localhost";
                 $accountModel->port = 143;
                 $accountModel->name = $user->name;
                 $accountModel->username = $user->email;
                 $accountModel->password = $prefix . $i;
                 $accountModel->smtp_host = 'localhost';
                 $accountModel->smtp_port = 25;
                 $accountModel->save();
                 $accountModel->addAlias($user->email, $user->name);
             }
         }
     }
     echo "Done\n\n";
 }
Example #5
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";
     }
 }