Ejemplo n.º 1
0
 /**
  * Action FOR ADMINS AND SUPERADMINS to change the password of a mailbox.
  */
 public function passwordAction()
 {
     if (!$this->_mailbox) {
         $this->_helper->viewRenderer->setNoRender(true);
         $this->addMessage(_('No mailbox id passed.'), ViMbAdmin_Message::ERROR);
         return print $this->view->render('close_colorbox_reload_parent.phtml');
     }
     $this->view->mailbox = $this->_mailbox;
     $form = new ViMbAdmin_Form_Admin_Password();
     if ($this->getRequest()->isPost() && $form->isValid($_POST)) {
         $plainPassword = $form->getValue('password');
         $this->_mailbox->hashPassword($this->_options['defaults']['mailbox']['password_scheme'], $plainPassword, $this->_options['defaults']['mailbox']['password_hash']);
         $this->_mailbox->save();
         if ($form->getValue('email')) {
             $mailer = new Zend_Mail();
             $mailer->setSubject(_('New Password for ' . $this->_mailbox['username']));
             $mailer->setFrom($this->_options['server']['email']['address'], $this->_options['server']['email']['name']);
             $mailer->addTo($this->_mailbox['username'], $this->_mailbox['name']);
             $this->view->newPassword = $form->getValue('password');
             $mailer->setBodyText($this->view->render('mailbox/email/change_password.phtml'));
             try {
                 $mailer->send();
             } catch (Zend_Mail_Exception $vException) {
                 $this->getLogger()->debug($vException->getTraceAsString());
                 $this->addMessage(_('Could not send email.'), ViMbAdmin_Message::ALERT);
                 return false;
             }
         }
         LogTable::log('MAILBOX_PW_CHANGE', "Changed password for {$this->_mailbox['username']}", $this->getAdmin(), $this->_mailbox['domain']);
         $this->_helper->viewRenderer->setNoRender(true);
         $this->addMessage(_('Password has been sucessfully changed.'), ViMbAdmin_Message::SUCCESS);
         print $this->view->render('close_colorbox_reload_parent.phtml');
     }
     $this->view->form = $form;
 }
Ejemplo n.º 2
0
 /**
  * Purges a mailbox, removes all the related entries from the other tables.
  * Prints 'ok' on success or 'ko' otherwise to stdout.
  */
 public function ajaxPurgeAction()
 {
     $this->authorise(true);
     Doctrine_Query::create()->delete()->from('Mailbox')->where('domain = ?', $this->_domain['domain'])->execute();
     Doctrine_Query::create()->delete()->from('Log')->where('domain = ?', $this->_domain['domain'])->execute();
     Doctrine_Query::create()->delete()->from('DomainAdmin')->where('domain = ?', $this->_domain['domain'])->execute();
     Doctrine_Query::create()->delete()->from('Alias')->where('domain = ?', $this->_domain['domain'])->execute();
     $this->_domain->delete();
     LogTable::log('DOMAIN_PURGE', "Purged {$this->_domain['domain']}", $this->getAdmin(), null);
     print 'ok';
 }
Ejemplo n.º 3
0
 /**
  * Adds a new admin or superadmin to the system. Optionally it can send a welcome email.
  */
 public function addAction()
 {
     $form = new ViMbAdmin_Form_Admin_Edit();
     $form->removeElement('salt');
     if ($this->getRequest()->isPost() && $form->isValid($_POST)) {
         $adminModel = new Admin();
         $adminModel->fromArray($form->getValues());
         $adminModel->setPassword($form->getValue('password'), $this->_options['securitysalt'], false);
         $adminModel->save();
         LogTable::log('ADMIN_ADD', "Added new " . ($adminModel['super'] ? 'super ' : '') . "admin {$adminModel['username']}", $this->getAdmin());
         if ($form->getValue('welcome_email')) {
             try {
                 $mailer = new Zend_Mail();
                 $mailer->setSubject(_('ViMbAdmin :: Your New Administrator Account'));
                 $mailer->addTo($adminModel->username);
                 $mailer->setFrom($this->_options['server']['email']['address'], $this->_options['server']['email']['name']);
                 $this->view->username = $adminModel->username;
                 $this->view->password = $form->getValue('password');
                 $mailer->setBodyText($this->view->render('admin/email/new_admin.phtml'));
                 $mailer->send();
             } catch (Exception $e) {
                 $this->getLogger()->debug($e->getTraceAsString());
                 $this->addMessage(_('Could not send welcome email'), ViMbAdmin_Message::ALERT);
             }
         }
         $this->addMessage(_('You have successfully added a new administrator to the system.'), ViMbAdmin_Message::SUCCESS);
         $this->_helper->viewRenderer->setNoRender(true);
         return print $this->view->render('close_colorbox_reload_parent.phtml');
     }
     $this->view->form = $form;
 }
Ejemplo n.º 4
0
 /**
  * Edit an alias.
  */
 public function editAction()
 {
     if (!$this->_alias) {
         $this->_alias = new Alias();
         if ($this->_domain) {
             $this->view->domainModel = $this->_domain;
         }
     } else {
         // if editing, then use that domain
         $this->view->domainModel = $this->_alias['Domain'];
     }
     $this->view->aliasModel = $this->_alias;
     $domainList = DomainTable::getDomains($this->getAdmin());
     $this->view->domainList = $domainList;
     $editForm = new ViMbAdmin_Form_Alias_Edit(null, $domainList);
     if ($this->getRequest()->isPost()) {
         if ($this->_alias['id']) {
             $editForm->removeElement('local_part');
             $editForm->removeElement('domain');
         }
         if ($editForm->isValid($_POST)) {
             $postValues = $editForm->getValues();
             if (isset($postValues['domain'])) {
                 $this->_domain = $this->loadDomain($postValues['domain']);
             }
             if (!$this->_domain || !$this->authorise(false, $this->_domain, false)) {
                 $this->addMessage(_("Invalid, unauthorised or non-existent domain."), ViMbAdmin_Message::ERROR);
                 $this->_redirect($this->getRequest()->getPathInfo());
             }
             if (!$this->_alias['id']) {
                 $alias = Doctrine::getTable('Alias')->findOneByAddress("{$postValues['local_part']}@{$this->_domain['domain']}");
                 if ($alias) {
                     if ($this->_options['mailboxAliases']) {
                         if ($alias->address == $alias->goto) {
                             $this->addMessage(_('A mailbox alias exists for') . " {$postValues['local_part']}@{$this->_domain['domain']}", ViMbAdmin_Message::ERROR);
                         } else {
                             $this->addMessage(_('Alias already exists for') . " {$postValues['local_part']}@{$this->_domain['domain']}", ViMbAdmin_Message::ERROR);
                         }
                     } else {
                         $this->addMessage(_('Alias already exists for') . " {$postValues['local_part']}@{$this->_domain['domain']}", ViMbAdmin_Message::ERROR);
                     }
                     $this->_redirect($this->getRequest()->getPathInfo());
                 }
             }
             if (!$postValues['goto']) {
                 $editForm->getElement('goto')->addError(_('You must have at least one goto address.'));
             } else {
                 // is the alias valid (allowing for wildcard domains (i.e. with no local part)
                 if (!$this->_alias['id'] && $postValues['local_part'] != '' && !Zend_Validate::is("{$postValues['local_part']}@{$this->_domain['domain']}", 'EmailAddress', array(1, null))) {
                     $editForm->getElement('local_part')->addError(_('Invalid email address.'));
                 }
                 foreach ($postValues['goto'] as $key => $oneGoto) {
                     $oneGoto = trim($oneGoto);
                     if ($oneGoto == '') {
                         unset($postValues['goto'][$key]);
                     } else {
                         if (!Zend_Validate::is($oneGoto, 'EmailAddress', array(1, null))) {
                             $editForm->getElement('goto')->addError(_('Invalid email address(es).'));
                         }
                     }
                 }
                 if (!$postValues['goto']) {
                     $editForm->getElement('goto')->addError(_('You must have at least one goto address.'));
                 }
                 if (!$editForm->getElement('goto')->hasErrors() && ($editForm->getElement('local_part') === null || !$editForm->getElement('local_part')->hasErrors())) {
                     $this->_alias->fromArray($postValues);
                     if (!$this->_alias['id']) {
                         // do we have available mailboxes?
                         if (!$this->getAdmin()->isSuper() && $this->_domain['aliases'] != 0 && $this->_domain->countAliases() >= $this->_domain['aliases']) {
                             $this->_helper->viewRenderer->setNoRender(true);
                             $this->addMessage(_('You have used all of your allocated aliases.'), ViMbAdmin_Message::ERROR);
                             return print $this->view->render('close_colorbox_reload_parent.phtml');
                         }
                         $this->_alias['domain'] = $this->_domain['domain'];
                         $this->_alias['address'] = "{$postValues['local_part']}@{$this->_domain['domain']}";
                         LogTable::log('ALIAS_ADD', "Added {$this->_alias['address']} -> {$this->_alias['goto']}", $this->getAdmin(), $this->_alias['domain']);
                     } else {
                         LogTable::log('ALIAS_EDIT', "Edited {$this->_alias['address']} -> {$this->_alias['goto']}", $this->getAdmin(), $this->_alias['domain']);
                     }
                     $this->_alias['goto'] = implode(',', array_unique($postValues['goto']));
                     $this->_alias->save();
                     $this->_helper->viewRenderer->setNoRender(true);
                     $this->addMessage(_('You have successfully added/edited the alias.'), ViMbAdmin_Message::SUCCESS);
                     return print $this->view->render('close_colorbox_reload_parent.phtml');
                 }
             }
         }
     } else {
         if ($this->_domain) {
             $editForm->getElement('domain')->setValue($this->_domain->id);
         }
         if ($this->_mailbox) {
             $this->view->defaultGoto = "{$this->_mailbox->local_part}@{$this->_mailbox->Domain->domain}";
         }
         if ($this->_alias['id']) {
             $editForm->setDefaults($this->_alias->toArray());
             $editForm->getElement('local_part')->setValue(str_replace("@{$this->_alias['domain']}", '', $this->_alias['address']))->setAttrib('disabled', 'disabled');
             $editForm->getElement('domain')->setAttrib('disabled', 'disabled');
         }
     }
     if ($this->_domain) {
         $editForm->getElement('domain')->setValue($this->_domain['id']);
     }
     $this->view->editForm = $editForm;
 }