Ejemplo n.º 1
0
 /**
  * Run method for CronRunner
  *
  * @param type $args
  */
 public function run($args)
 {
     $this->printHeader('Cron Interface');
     if (!isset($args[0]) || $args[0] != "daily" && $args[0] != 'hourly') {
         print "\n Run with parameter:\n" . "\t daily - for Daily Interval\n" . "\t hourly - for Hourly Interval \n";
         print "\n\n";
         exit;
     }
     // Set current interval to attribute
     if ($args[0] == 'daily') {
         $this->interval = self::INTERVAL_DAILY;
     } elseif ($args[0] == 'hourly') {
         $this->interval = self::INTERVAL_HOURLY;
     } else {
         throw new CException(500, 'Invalid cron interval!');
     }
     // Do some base tasks, handle by event in future
     if ($this->interval == self::INTERVAL_HOURLY) {
         // Raise Event for Module specific tasks
         if ($this->hasEventHandler('onHourlyRun')) {
             $this->onHourlyRun(new CEvent($this));
         }
         print "- Optimizing Search Index\n";
         // Optimize Search Index
         HSearch::getInstance()->Optimize();
         if (HSetting::Get('enabled', 'authentication_ldap') && HSetting::Get('refreshUsers', 'authentication_ldap')) {
             print "- Updating LDAP Users\n";
             HLdap::getInstance()->refreshUsers();
         }
         print "- Invoking EMailing hourly\n\n";
         // Execute Hourly Mailing Runner
         Yii::import('application.commands.shell.EMailing.*');
         $command = new EMailing('test', 'test');
         $command->run(array('hourly'));
         HSetting::Set('cronLastHourlyRun', time());
     } elseif ($this->interval == self::INTERVAL_DAILY) {
         // Raise Event for Module specific tasks
         if ($this->hasEventHandler('onDailyRun')) {
             $this->onDailyRun(new CEvent($this));
         }
         // Execute Daily Mailing Runner
         print "- Invoking EMailing daily\n\n";
         Yii::import('application.commands.shell.EMailing.*');
         $command = new EMailing('test', 'test');
         $command->run(array('daily'));
         HSetting::Set('cronLastDailyRun', time());
     }
 }
Ejemplo n.º 2
0
 /**
  * Validates password of user against internal database or ldap
  *
  * @param User $user
  * @return Succeess
  * @throws CException
  */
 private function validatePassword(User $user)
 {
     if ($user->auth_mode == User::AUTH_MODE_LOCAL) {
         // Authenticate via Local DB
         if ($user->currentPassword != null && $user->currentPassword->validatePassword($this->password)) {
             return true;
         }
     } elseif ($user->auth_mode == User::AUTH_MODE_LDAP) {
         // Authenticate via LDAP
         if (HLdap::getInstance()->authenticate($user->username, $this->password)) {
             return true;
         }
     } else {
         throw new CException("Invalid user authentication mode!");
     }
     return false;
 }
Ejemplo n.º 3
0
 /**
  * Returns a List of Users
  */
 public function actionAuthenticationLdap()
 {
     Yii::import('admin.forms.*');
     $form = new AuthenticationLdapSettingsForm();
     // Load Defaults
     $form->enabled = HSetting::Get('enabled', 'authentication_ldap');
     $form->username = HSetting::Get('username', 'authentication_ldap');
     $form->password = HSetting::Get('password', 'authentication_ldap');
     $form->hostname = HSetting::Get('hostname', 'authentication_ldap');
     $form->port = HSetting::Get('port', 'authentication_ldap');
     $form->encryption = HSetting::Get('encryption', 'authentication_ldap');
     $form->baseDn = HSetting::Get('baseDn', 'authentication_ldap');
     $form->loginFilter = HSetting::Get('loginFilter', 'authentication_ldap');
     $form->userFilter = HSetting::Get('userFilter', 'authentication_ldap');
     $form->usernameAttribute = HSetting::Get('usernameAttribute', 'authentication_ldap');
     if ($form->password != '') {
         $form->password = '******';
     }
     // uncomment the following code to enable ajax-based validation
     if (isset($_POST['ajax']) && $_POST['ajax'] === 'authentication-ldap-settings-form') {
         echo CActiveForm::validate($form);
         Yii::app()->end();
     }
     if (isset($_POST['AuthenticationLdapSettingsForm'])) {
         $_POST['AuthenticationLdapSettingsForm'] = Yii::app()->input->stripClean($_POST['AuthenticationLdapSettingsForm']);
         $form->attributes = $_POST['AuthenticationLdapSettingsForm'];
         if ($form->validate()) {
             HSetting::Set('enabled', $form->enabled, 'authentication_ldap');
             HSetting::Set('hostname', $form->hostname, 'authentication_ldap');
             HSetting::Set('port', $form->port, 'authentication_ldap');
             HSetting::Set('encryption', $form->encryption, 'authentication_ldap');
             HSetting::Set('username', $form->username, 'authentication_ldap');
             if ($form->password != '---hidden---') {
                 HSetting::Set('password', $form->password, 'authentication_ldap');
             }
             HSetting::Set('baseDn', $form->baseDn, 'authentication_ldap');
             HSetting::Set('loginFilter', $form->loginFilter, 'authentication_ldap');
             HSetting::Set('userFilter', $form->userFilter, 'authentication_ldap');
             HSetting::Set('usernameAttribute', $form->usernameAttribute, 'authentication_ldap');
             // set flash message
             Yii::app()->user->setFlash('data-saved', Yii::t('AdminModule.controllers_SettingController', 'Saved'));
             $this->redirect(Yii::app()->createUrl('//admin/setting/authenticationLdap'));
         }
     }
     $enabled = false;
     $userCount = 0;
     $errorMessage = "";
     if (HSetting::Get('enabled', 'authentication_ldap')) {
         $enabled = true;
         try {
             if (HLdap::getInstance()->ldap !== null) {
                 $userCount = HLdap::getInstance()->ldap->count(HSetting::Get('userFilter', 'authentication_ldap'), HSetting::Get('baseDn', 'authentication_ldap'), Zend_Ldap::SEARCH_SCOPE_ONE);
             } else {
                 $errorMessage = Yii::t('AdminModule.controllers_SettingController', 'Could not load LDAP! - Check PHP Extension');
             }
         } catch (Exception $ex) {
             $errorMessage = $ex->getMessage();
         }
     }
     $this->render('authentication_ldap', array('model' => $form, 'enabled' => $enabled, 'userCount' => $userCount, 'errorMessage' => $errorMessage));
 }