Esempio n. 1
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";
 }
Esempio n. 2
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);
     }
 }
Esempio n. 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);
     }
 }
Esempio n. 4
0
 public function createEmailAccount($user, $config, $username, $password)
 {
     if (\GO::modules()->isInstalled('email')) {
         \GO::debug('IMAPAUTH: Creating IMAP account for user');
         $account['user_id'] = $user->id;
         $account['type'] = 'imap';
         //$config['proto'];
         $account['host'] = $config['host'];
         $account['smtp_host'] = $config['smtp_host'];
         $account['smtp_port'] = $config['smtp_port'];
         $account['smtp_encryption'] = $config['smtp_encryption'];
         if (!empty($config['smtp_use_login_credentials'])) {
             $account['smtp_username'] = $username;
             $account['smtp_password'] = $password;
         } elseif (isset($config['smtp_username'])) {
             $account['smtp_username'] = $config['smtp_username'];
             $account['smtp_password'] = $config['smtp_password'];
         }
         $account['port'] = $config['port'];
         $account['use_ssl'] = empty($config['ssl']) ? 0 : 1;
         $account['mbroot'] = $config['mbroot'];
         $account['username'] = $username;
         $account['store_password'] = !isset($config['store_password']) || !empty($config['store_password']) ? 1 : 0;
         $account['store_smtp_password'] = !empty($account['store_password']) && !empty($config['smtp_use_login_credentials']) ? 1 : 0;
         $account['password'] = $password;
         //set session pass.
         $model = new \GO\Email\Model\Account();
         $model->setAttributes($account);
         $model->save();
         if (!$model->save()) {
             throw new \Exception("Could not save e-mail account: " . implode("\n", $model->getValidationErrors()));
         }
         $model->addAlias($user->email, $user->name);
     } else {
         \GO::debug('IMAPAUTH: E-mail module not installed. Skipping e-mail account creation.');
     }
 }