/**
  * shows all the cron jobs
  *
  */
 public function indexAction()
 {
     $this->view->acl = array('add' => false, 'edit' => false, 'toggle' => $this->_helper->hasAccess('toggle'), 'acl' => $this->_helper->hasAccess('index', 'ot_acl'));
     $role = new Ot_Model_DbTable_Role();
     $statusModel = new Ot_Model_DbTable_CronStatus();
     $statusMarkers = $statusModel->fetchAll();
     $cjStatus = array();
     foreach ($statusMarkers as $s) {
         $cjStatus[$s->jobKey] = array('status' => $s->status, 'lastRunDt' => $s->lastRunDt);
     }
     $jobs = array();
     $cjr = new Ot_Cron_JobRegister();
     $registeredJobs = $cjr->getJobs();
     foreach ($registeredJobs as $j) {
         $cschedule = $j->getSchedule();
         if (count(explode(' ', $cschedule)) == 5) {
             $cschedule .= ' *';
         }
         $parts = explode(' ', $cschedule);
         $parts[0] = preg_replace('/\\*\\//', '0-59/', $parts[0]);
         $parts[1] = preg_replace('/\\*\\//', '0-23/', $parts[1]);
         $parts[2] = preg_replace('/\\*\\//', '1-31/', $parts[2]);
         $parts[3] = preg_replace('/\\*\\//', '1-12/', $parts[3]);
         $parts[4] = preg_replace('/\\*\\//', '0-6/', $parts[4]);
         $cschedule = implode($parts, ' ');
         try {
             $schedule = Ot_Cron_Schedule::fromCronString($cschedule);
         } catch (Exception $e) {
             $schedule = null;
         }
         $jobs[] = array('job' => $j, 'isEnabled' => isset($cjStatus[$j->getKey()]) && $cjStatus[$j->getKey()]['status'] == 'enabled', 'lastRunDt' => isset($cjStatus[$j->getKey()]) ? $cjStatus[$j->getKey()]['lastRunDt'] : 0, 'schedule' => is_null($schedule) ? $cschedule : $schedule->asNaturalLanguage());
     }
     $this->view->assign(array('defaultRole' => $role->find($this->_helper->configVar('defaultRole')), 'guestHasAccess' => $this->_helper->hasAccess('index', 'ot_cronjob', $this->_helper->configVar('defaultRole')), 'cronjobs' => $jobs));
     $this->_helper->pageTitle('ot-cron-index:title');
 }
 public function __construct($options = array())
 {
     parent::__construct($options);
     $this->setAttrib('id', 'userSearchForm')->setDecorators(array('FormElements', array('HtmlTag', array('tag' => 'div', 'class' => 'well')), 'Form'))->setMethod(Zend_Form::METHOD_GET);
     $username = $this->createElement('text', 'username', array('label' => 'Username:'******'select', 'role', array('label' => 'Role:'));
     $role->addMultiOption('', 'Any Role');
     foreach ($allRoles as $r) {
         $role->addMultiOption($r->roleId, $r->name);
     }
     $firstName = $this->createElement('text', 'firstName', array('label' => 'First Name:'));
     $lastName = $this->createElement('text', 'lastName', array('label' => 'Last Name:'));
     $this->addElements(array($username, $firstName, $lastName, $role));
     $this->setElementDecorators(array('ViewHelper', array(array('wrapperField' => 'HtmlTag'), array('tag' => 'div', 'class' => 'elm')), array('Errors', array('placement' => 'append')), array('Label', array('placement' => 'prepend')), array(array('wrapperAll' => 'HtmlTag'), array('tag' => 'div', 'class' => 'criteria'))));
     $sort = $this->createElement('hidden', 'sort');
     $sort->setDecorators(array('ViewHelper'));
     $direction = $this->createElement('hidden', 'direction');
     $direction->setDecorators(array('ViewHelper'));
     $submit = $this->createElement('submit', 'submitButton', array('label' => 'Filter Results'));
     $submit->setAttrib('class', 'btn btn-danger');
     $submit->setDecorators(array(array('ViewHelper', array('helper' => 'formSubmit')), array(array('wrapperAll' => 'HtmlTag'), array('tag' => 'div', 'class' => 'submit')), array('HtmlTag', array('tag' => 'div', 'class' => 'clearfix'))));
     $this->addElements(array($submit, $sort, $direction));
     return $this;
 }
Exemple #3
0
 public function getAvailableRoles($role = '', $scope = 'application')
 {
     if (!is_null($this->_roles)) {
         return $this->_roles;
     }
     $role = new Ot_Model_DbTable_Role();
     return $role->getRoles($scope);
 }
 /**
  * Adds a user to the system
  *
  */
 public function addAction()
 {
     $account = new Ot_Model_DbTable_Account();
     $defaultRole = $this->_helper->configVar('defaultRole');
     $form = new Ot_Form_Account(true);
     $form->populate(array('roleSelect' => array($defaultRole)));
     $acl = Zend_Registry::get('acl');
     $permissions = $acl->getResources($defaultRole);
     if ($this->_request->isPost()) {
         if ($form->isValid($_POST)) {
             $password = $account->generatePassword();
             $accountData = array('username' => $form->getValue('username'), 'password' => md5($password), 'realm' => $form->getValue('realm'), 'firstName' => $form->getValue('firstName'), 'lastName' => $form->getValue('lastName'), 'emailAddress' => $form->getValue('emailAddress'), 'timezone' => $form->getValue('timezone'), 'role' => (array) $form->getValue('role'));
             if (!isset($accountData['role']) || count($accountData['role']) < 1) {
                 $accountData['role'] = $this->_helper->configVar('defaultRole');
             }
             $dba = Zend_Db_Table::getDefaultAdapter();
             $dba->beginTransaction();
             if ($account->accountExists($accountData['username'], $accountData['realm'])) {
                 $this->_helper->messenger->addError('msg-error-accountTaken');
             } else {
                 try {
                     $accountData['accountId'] = $account->insert($accountData);
                     $aar = new Ot_Account_Attribute_Register();
                     $vars = $aar->getVars($accountData['accountId']);
                     $values = $form->getValues();
                     foreach ($vars as $varName => $var) {
                         if (isset($values['accountAttributes'][$varName])) {
                             $var->setValue($values['accountAttributes'][$varName]);
                             $aar->save($var, $this->_userData['accountId']);
                         }
                     }
                     $cahr = new Ot_CustomAttribute_HostRegister();
                     $thisHost = $cahr->getHost('Ot_Profile');
                     if (is_null($thisHost)) {
                         throw new Ot_Exception_Data('msg-error-objectNotSetup');
                     }
                     $customAttributes = $thisHost->getAttributes($accountData['accountId']);
                     foreach ($customAttributes as $attributeName => $a) {
                         if (array_key_exists($attributeName, $values['customAttributes'])) {
                             $a['var']->setValue($values['customAttributes'][$attributeName]);
                             $thisHost->saveAttribute($a['var'], $this->_userData['accountId'], $a['attributeId']);
                         }
                     }
                 } catch (Exception $e) {
                     $dba->rollback();
                     throw $e;
                 }
                 $accountData['password'] = $password;
                 $this->_helper->messenger->addSuccess('msg-info-accountCreated');
                 $td = new Ot_Trigger_Dispatcher();
                 $td->setVariables($accountData);
                 $role = new Ot_Model_DbTable_Role();
                 $roles = array();
                 foreach ($accountData['role'] as $r) {
                     $roles[] = $role->find($r)->name;
                 }
                 $otAuthAdapter = new Ot_Model_DbTable_AuthAdapter();
                 $thisAdapter = $otAuthAdapter->find($accountData['realm']);
                 $td->role = implode(',', $roles);
                 $td->loginMethod = $thisAdapter->name;
                 $authAdapter = new $thisAdapter->class();
                 if ($authAdapter->manageLocally()) {
                     $this->_helper->messenger->addSuccess('msg-info-accountPasswordCreated');
                     $td->dispatch('Admin_Account_Create_Password');
                 } else {
                     $td->dispatch('Admin_Account_Create_NoPassword');
                 }
                 $dba->commit();
                 $logOptions = array('attributeName' => 'accountId', 'attributeId' => $accountData['accountId']);
                 $this->_helper->log(Zend_Log::INFO, 'Account was added', $logOptions);
                 $this->_helper->redirector->gotoRoute(array('action' => 'all'), 'account', true);
             }
         } else {
             $this->_helper->messenger->addError('msg-error-invalidForm');
         }
     }
     $this->view->headScript()->appendFile($this->view->baseUrl() . '/scripts/ot/jquery.tooltip.min.js');
     $this->view->headScript()->appendFile($this->view->baseUrl() . '/scripts/ot/account/permissionsTable.js');
     $this->_helper->pageTitle('ot-account-add:title');
     $this->view->assign(array('form' => $form, 'permissions' => $permissions, 'permissionList' => Zend_Json::encode($permissions)));
 }
Exemple #5
0
 protected function _mergeAccountData(Zend_Db_Table_Row $data)
 {
     $data = (object) $data->toArray();
     $accountRolesModel = new Ot_Model_DbTable_AccountRoles();
     $rolesModel = new Ot_Model_DbTable_Role();
     $select = $this->getAdapter()->select()->from(array('a' => $accountRolesModel->info('name')))->join(array('r' => $rolesModel->info('name')), 'a.roleId = r.roleId')->where('accountId = ?', $data->accountId);
     $stmt = $select->query();
     $roles = $stmt->fetchAll();
     $roleList = array();
     foreach ($roles as $r) {
         $roleList[$r['name']] = $r['roleId'];
     }
     $data->role = $roleList;
     $aar = new Ot_Account_Attribute_Register();
     $vars = $aar->getVars($data->accountId);
     $data->accountAttributes = array();
     foreach ($vars as $varName => $var) {
         $data->accountAttributes[$varName] = $var;
     }
     $cahr = new Ot_CustomAttribute_HostRegister();
     $thisHost = $cahr->getHost('Ot_Profile');
     $attributes = $thisHost->getAttributes($data->accountId);
     $data->customAttributes = array();
     foreach ($attributes as $a) {
         $data->customAttributes[$a['var']->getName()] = $a['var'];
     }
     $authAdapter = new Ot_Model_DbTable_AuthAdapter();
     $adapter = $authAdapter->find($data->realm);
     $data->authAdapter = array('obj' => new $adapter->class(), 'enabled' => $adapter->enabled, 'name' => $adapter->name, 'description' => $adapter->description);
     return $data;
 }
 /**
  * Deletes a role from the ACL
  *
  */
 public function deleteAction()
 {
     $roleId = $this->_getParam('roleId', null);
     if (is_null($roleId)) {
         throw new Ot_Exception_Input('msg-error-roleIdNotSet');
     }
     $role = new Ot_Model_DbTable_Role();
     $thisRole = $role->find($roleId);
     if (is_null($thisRole)) {
         throw new Ot_Exception_Data('msg-error-noRole');
     }
     if ($thisRole->editable != 1) {
         throw new Ot_Exception_Access('msg-error-unallowedRoleEdit');
     }
     $availableRoles = $this->_acl->getAvailableRoles();
     if (!isset($availableRoles[$roleId])) {
         throw new Ot_Exception_Data('msg-error-noRole');
     }
     $account = new Ot_Model_DbTable_Account();
     $affectedAccounts = $account->getAccountsForRole($get->roleId);
     $defaultRole = $this->_helper->configVar('defaultRole');
     if (!isset($availableRoles[$defaultRole])) {
         throw new Ot_Exception_Data('msg-error-noDefaultRole');
     }
     if ($defaultRole == $roleId) {
         throw new Ot_Exception_Data('msg-error-deleteDefaultRole');
     }
     $inheritedRoles = array();
     $inheritedRoles = $this->_acl->getChildrenOfRole($roleId);
     if (count($inheritedRoles) > 0) {
         throw new Ot_Exception_Data($this->view->translate('msg-error-dependedRoleCannotDelete', $roleList));
     }
     if ($this->_request->isPost()) {
         $role = new Ot_Model_DbTable_Role();
         $accountRoles = new Ot_Model_DbTable_AccountRoles();
         $dba = $role->getAdapter();
         $dba->beginTransaction();
         try {
             $role->deleteRole($roleId);
         } catch (Exception $e) {
             $dba->rollback();
             throw $e;
         }
         // aList is an array of all the affected accountIds
         $aList = array();
         if (count($affectedAccounts) > 0) {
             foreach ($affectedAccounts as $a) {
                 $aList[] = $a->accountId;
             }
             if (count($aList) > 0) {
                 // get a list of all the accounts that still have a role after removing one so we can diff()
                 // it to find the accounts that no longer have a role
                 $accountRolesDba = $accountRoles->getAdapter();
                 $where = $accountRolesDba->quoteInto('accountId IN(?)', $aList);
                 $affectedAccountsStillWithRoles = $accountRoles->fetchAll($where);
                 $affectedAccountsStillWithRolesIds = array();
                 foreach ($affectedAccountsStillWithRoles as $a) {
                     $affectedAccountsStillWithRolesIds[] = $a->accountId;
                 }
                 // here's the list of accounts that don't have a role, so we have to add $defaultRole to them.
                 $affectedAccountsWithNoRoles = array_diff($aList, $affectedAccountsStillWithRolesIds);
                 try {
                     foreach ($affectedAccountsWithNoRoles as $a) {
                         $accountRoles->insert(array('accountId' => $a, 'roleId' => $defaultRole));
                     }
                 } catch (Exception $e) {
                     $dba->rollback();
                     throw $e;
                 }
             }
         }
         $dba->commit();
         $logOptions = array('attributeName' => 'accessRole', 'attributeId' => $roleId);
         $this->_helper->log(Zend_Log::INFO, 'Role ' . $thisRole['name'] . ' was deleted', $logOptions);
         $this->_helper->messenger->addWarning('Role was deleted successfully');
         $this->_helper->redirector->gotoRoute(array('controller' => 'acl'), 'ot', true);
     } else {
         throw new Ot_Exception_Access('You can not access this method directly');
     }
 }