/**
  * Get Results of the Application SelfTest.
  *
  * Fields
  *  - title
  *  - state (OK, WARNING or ERROR)
  *  - hint
  *
  * @return Array
  */
 public static function getResults()
 {
     /**
      * ['title']
      * ['state']    = OK, WARNING, ERROR
      * ['hint']
      */
     $checks = array();
     // Checks PHP Version
     $title = 'PHP - Version - ' . PHP_VERSION;
     if (version_compare(PHP_VERSION, '5.4', '>=')) {
         $checks[] = array('title' => Yii::t('base', $title), 'state' => 'OK');
     } else {
         $checks[] = array('title' => Yii::t('base', $title), 'state' => 'ERROR', 'hint' => 'Minimum 5.4');
     }
     // Checks GD Extension
     $title = 'PHP - GD Extension';
     if (function_exists('gd_info')) {
         $checks[] = array('title' => Yii::t('base', $title), 'state' => 'OK');
     } else {
         $checks[] = array('title' => Yii::t('base', $title), 'state' => 'ERROR', 'hint' => 'Install GD Extension');
     }
     $title = 'PHP - INTL Extension';
     if (function_exists('collator_create')) {
         $checks[] = array('title' => Yii::t('base', $title), 'state' => 'OK');
     } else {
         $checks[] = array('title' => Yii::t('base', $title), 'state' => 'ERROR', 'hint' => 'Install INTL Extension');
     }
     $icuVersion = defined('INTL_ICU_VERSION') ? INTL_ICU_VERSION : 0;
     $icuMinVersion = '4.8.1';
     $title = 'PHP - INTL Extension - ICU Version (' . INTL_ICU_VERSION . ')';
     if (version_compare($icuVersion, $icuMinVersion, '>=')) {
         $checks[] = array('title' => Yii::t('base', $title), 'state' => 'OK');
     } else {
         $checks[] = array('title' => Yii::t('base', $title), 'state' => 'WARNING', 'hint' => 'ICU Data ' . $icuMinVersion . ' or higher is required');
     }
     $icuDataVersion = defined('INTL_ICU_DATA_VERSION') ? INTL_ICU_DATA_VERSION : 0;
     $icuMinDataVersion = '4.8.1';
     $title = 'PHP - INTL Extension - ICU Data Version (' . INTL_ICU_DATA_VERSION . ')';
     if (version_compare($icuDataVersion, $icuMinDataVersion, '>=')) {
         $checks[] = array('title' => Yii::t('base', $title), 'state' => 'OK');
     } else {
         $checks[] = array('title' => Yii::t('base', $title), 'state' => 'WARNING', 'hint' => 'ICU Data ' . $icuMinDataVersion . ' or higher is required');
     }
     // Checks GD Extension
     $title = 'PHP - EXIF Extension';
     if (function_exists('exif_read_data')) {
         $checks[] = array('title' => Yii::t('base', $title), 'state' => 'OK');
     } else {
         $checks[] = array('title' => Yii::t('base', $title), 'state' => 'ERROR', 'hint' => 'Install EXIF Extension');
     }
     // Check FileInfo Extension
     $title = 'PHP - FileInfo Extension';
     if (extension_loaded('fileinfo')) {
         $checks[] = array('title' => Yii::t('base', $title), 'state' => 'OK');
     } else {
         $checks[] = array('title' => Yii::t('base', $title), 'state' => 'ERROR', 'hint' => 'Install FileInfo Extension');
     }
     // Checks CURL Extension
     $title = 'PHP - Multibyte String Functions';
     if (function_exists('mb_substr')) {
         $checks[] = array('title' => Yii::t('base', $title), 'state' => 'OK');
     } else {
         $checks[] = array('title' => Yii::t('base', $title), 'state' => 'ERROR', 'hint' => 'Install PHP Multibyte Extension');
     }
     // Checks CURL Extension
     $title = 'PHP - Curl Extension';
     if (function_exists('curl_version')) {
         $checks[] = array('title' => Yii::t('base', $title), 'state' => 'OK');
     } else {
         $checks[] = array('title' => Yii::t('base', $title), 'state' => 'ERROR', 'hint' => 'Install Curl Extension');
     }
     // Checks ZIP Extension
     $title = 'PHP - ZIP Extension';
     if (class_exists('ZipArchive')) {
         $checks[] = array('title' => Yii::t('base', $title), 'state' => 'OK');
     } else {
         $checks[] = array('title' => Yii::t('base', $title), 'state' => 'ERROR', 'hint' => 'Install PHP Zip Extension');
     }
     // Checks LDAP Extension
     $title = 'LDAP Support';
     if (\humhub\modules\user\libs\Ldap::isAvailable()) {
         $checks[] = array('title' => Yii::t('base', $title), 'state' => 'OK');
     } else {
         $checks[] = array('title' => Yii::t('base', $title), 'state' => 'WARNING', 'hint' => 'Optional - Install PHP LDAP Extension and Zend LDAP Composer Package');
     }
     // Checks APC Extension
     $title = 'PHP - APC Support';
     if (function_exists('apc_add')) {
         $checks[] = array('title' => Yii::t('base', $title), 'state' => 'OK');
     } else {
         $checks[] = array('title' => Yii::t('base', $title), 'state' => 'WARNING', 'hint' => 'Optional - Install APC Extension for APC Caching');
     }
     // Checks SQLite3 Extension
     $title = 'PHP - SQLite3 Support';
     if (class_exists('SQLite3')) {
         $checks[] = array('title' => Yii::t('base', $title), 'state' => 'OK');
     } else {
         $checks[] = array('title' => Yii::t('base', $title), 'state' => 'WARNING', 'hint' => 'Optional - Install SQLite3 Extension for DB Caching');
     }
     // Checks Writeable Config
     /*
      $title = 'Permissions - Config';
      $configFile = dirname(Yii::$app->params['dynamicConfigFile']);
      if (is_writeable($configFile)) {
      $checks[] = array(
      'title' => Yii::t('base', $title),
      'state' => 'OK'
      );
      } else {
      $checks[] = array(
      'title' => Yii::t('base', $title),
      'state' => 'ERROR',
      'hint' => 'Make ' . $configFile . " writable for the webserver/php!"
      );
      }
     */
     // Check Runtime Directory
     $title = 'Permissions - Runtime';
     $path = Yii::getAlias('@runtime');
     if (is_writeable($path)) {
         $checks[] = array('title' => Yii::t('base', $title), 'state' => 'OK');
     } else {
         $checks[] = array('title' => Yii::t('base', $title), 'state' => 'ERROR', 'hint' => 'Make ' . $path . " writable for the webserver/php!");
     }
     // Check Assets Directory
     $title = 'Permissions - Assets';
     $path = Yii::getAlias('@webroot/assets');
     if (is_writeable($path)) {
         $checks[] = array('title' => Yii::t('base', $title), 'state' => 'OK');
     } else {
         $checks[] = array('title' => Yii::t('base', $title), 'state' => 'ERROR', 'hint' => 'Make ' . $path . " writable for the webserver/php!");
     }
     // Check Uploads Directory
     $title = 'Permissions - Uploads';
     $path = Yii::getAlias('@webroot/uploads');
     if (is_writeable($path)) {
         $checks[] = array('title' => Yii::t('base', $title), 'state' => 'OK');
     } else {
         $checks[] = array('title' => Yii::t('base', $title), 'state' => 'ERROR', 'hint' => 'Make ' . $path . " writable for the webserver/php!");
     }
     // Check Custom Modules Directory
     $title = 'Permissions - Module Directory';
     $path = Yii::getAlias(Yii::$app->params['moduleMarketplacePath']);
     if (is_writeable($path)) {
         $checks[] = array('title' => Yii::t('base', $title), 'state' => 'OK');
     } else {
         $checks[] = array('title' => Yii::t('base', $title), 'state' => 'ERROR', 'hint' => 'Make ' . $path . " writable for the webserver/php!");
     }
     // Check Custom Modules Directory
     $title = 'Permissions - Dynamic Config';
     $path = Yii::getAlias(Yii::$app->params['dynamicConfigFile']);
     if (!is_file($path)) {
         $path = dirname($path);
     }
     if (is_writeable($path)) {
         $checks[] = array('title' => Yii::t('base', $title), 'state' => 'OK');
     } else {
         $checks[] = array('title' => Yii::t('base', $title), 'state' => 'ERROR', 'hint' => 'Make ' . $path . " writable for the webserver/php!");
     }
     return $checks;
 }
Пример #2
0
 /**
  * Returns a List of Users
  */
 public function actionAuthenticationLdap()
 {
     $form = new \humhub\modules\admin\models\forms\AuthenticationLdapSettingsForm();
     // Load Defaults
     $form->enabled = Setting::Get('enabled', 'authentication_ldap');
     $form->refreshUsers = Setting::Get('refreshUsers', 'authentication_ldap');
     $form->username = Setting::Get('username', 'authentication_ldap');
     $form->password = Setting::Get('password', 'authentication_ldap');
     $form->hostname = Setting::Get('hostname', 'authentication_ldap');
     $form->port = Setting::Get('port', 'authentication_ldap');
     $form->encryption = Setting::Get('encryption', 'authentication_ldap');
     $form->baseDn = Setting::Get('baseDn', 'authentication_ldap');
     $form->loginFilter = Setting::Get('loginFilter', 'authentication_ldap');
     $form->userFilter = Setting::Get('userFilter', 'authentication_ldap');
     $form->usernameAttribute = Setting::Get('usernameAttribute', 'authentication_ldap');
     $form->emailAttribute = Setting::Get('emailAttribute', 'authentication_ldap');
     if ($form->password != '') {
         $form->password = '******';
     }
     if ($form->load(Yii::$app->request->post()) && $form->validate()) {
         Setting::Set('enabled', $form->enabled, 'authentication_ldap');
         Setting::Set('refreshUsers', $form->refreshUsers, 'authentication_ldap');
         Setting::Set('hostname', $form->hostname, 'authentication_ldap');
         Setting::Set('port', $form->port, 'authentication_ldap');
         Setting::Set('encryption', $form->encryption, 'authentication_ldap');
         Setting::Set('username', $form->username, 'authentication_ldap');
         if ($form->password != '---hidden---') {
             Setting::Set('password', $form->password, 'authentication_ldap');
         }
         Setting::Set('baseDn', $form->baseDn, 'authentication_ldap');
         Setting::Set('loginFilter', $form->loginFilter, 'authentication_ldap');
         Setting::Set('userFilter', $form->userFilter, 'authentication_ldap');
         Setting::Set('usernameAttribute', $form->usernameAttribute, 'authentication_ldap');
         Setting::Set('emailAttribute', $form->emailAttribute, 'authentication_ldap');
         // set flash message
         Yii::$app->getSession()->setFlash('data-saved', Yii::t('AdminModule.controllers_SettingController', 'Saved'));
         Yii::$app->response->redirect(Url::toRoute('/admin/setting/authentication-ldap'));
     }
     $enabled = false;
     $userCount = 0;
     $errorMessage = "";
     if (Setting::Get('enabled', 'authentication_ldap')) {
         $enabled = true;
         try {
             if (Ldap::getInstance()->ldap !== null) {
                 $userCount = Ldap::getInstance()->ldap->count(Setting::Get('userFilter', 'authentication_ldap'), Setting::Get('baseDn', 'authentication_ldap'), \Zend\Ldap\Ldap::SEARCH_SCOPE_SUB);
             } else {
                 $errorMessage = Yii::t('AdminModule.controllers_SettingController', 'Could not load LDAP! - Check PHP Extension');
             }
         } catch (\Zend\Ldap\Exception\LdapException $ex) {
             $errorMessage = $ex->getMessage();
         } catch (Exception $ex) {
             $errorMessage = $ex->getMessage();
         }
     }
     return $this->render('authentication_ldap', array('model' => $form, 'enabled' => $enabled, 'userCount' => $userCount, 'errorMessage' => $errorMessage));
 }
Пример #3
0
 /**
  * Get Results of the Application SelfTest.
  *
  * Fields
  *  - title
  *  - state (OK, WARNING or ERROR)
  *  - hint
  *
  * @return Array
  */
 public static function getResults()
 {
     /**
      * ['title']
      * ['state']    = OK, WARNING, ERROR
      * ['hint']
      */
     $checks = array();
     // Checks PHP Version
     $title = 'PHP - Version - ' . PHP_VERSION;
     # && version_compare(PHP_VERSION, '5.9.0', '<')
     if (version_compare(PHP_VERSION, '5.4.0', '>=')) {
         $checks[] = array('title' => Yii::t('base', $title), 'state' => 'OK');
     } elseif (version_compare(PHP_VERSION, '5.4.0', '<=')) {
         $checks[] = array('title' => Yii::t('base', $title), 'state' => 'WARNING', 'hint' => 'Untested on this version!');
     } else {
         $checks[] = array('title' => Yii::t('base', $title), 'state' => 'ERROR', 'hint' => 'Minimum 5.3');
     }
     // Checks GD Extension
     $title = 'PHP - GD Extension';
     if (function_exists('gd_info')) {
         $checks[] = array('title' => Yii::t('base', $title), 'state' => 'OK');
     } else {
         $checks[] = array('title' => Yii::t('base', $title), 'state' => 'ERROR', 'hint' => 'Install GD Extension');
     }
     // Checks GD Extension
     $title = 'PHP - EXIF Extension';
     if (function_exists('exif_read_data')) {
         $checks[] = array('title' => Yii::t('base', $title), 'state' => 'OK');
     } else {
         $checks[] = array('title' => Yii::t('base', $title), 'state' => 'ERROR', 'hint' => 'Install EXIF Extension');
     }
     // Checks CURL Extension
     $title = 'PHP - Multibyte String Functions';
     if (function_exists('mb_substr')) {
         $checks[] = array('title' => Yii::t('base', $title), 'state' => 'OK');
     } else {
         $checks[] = array('title' => Yii::t('base', $title), 'state' => 'ERROR', 'hint' => 'Install PHP Multibyte Extension');
     }
     // Checks CURL Extension
     $title = 'PHP - Curl Extension';
     if (function_exists('curl_version')) {
         $checks[] = array('title' => Yii::t('base', $title), 'state' => 'OK');
     } else {
         $checks[] = array('title' => Yii::t('base', $title), 'state' => 'ERROR', 'hint' => 'Install Curl Extension');
     }
     // Checks ZIP Extension
     $title = 'PHP - ZIP Extension';
     if (class_exists('ZipArchive')) {
         $checks[] = array('title' => Yii::t('base', $title), 'state' => 'OK');
     } else {
         $checks[] = array('title' => Yii::t('base', $title), 'state' => 'ERROR', 'hint' => 'Install PHP Zip Extension');
     }
     // Checks LDAP Extension
     $title = 'LDAP Support';
     if (\humhub\modules\user\libs\Ldap::isAvailable()) {
         $checks[] = array('title' => Yii::t('base', $title), 'state' => 'OK');
     } else {
         $checks[] = array('title' => Yii::t('base', $title), 'state' => 'WARNING', 'hint' => 'Optional - Install PHP LDAP Extension and Zend LDAP Composer Package');
     }
     // Checks APC Extension
     $title = 'PHP - APC Support';
     if (function_exists('apc_add')) {
         $checks[] = array('title' => Yii::t('base', $title), 'state' => 'OK');
     } else {
         $checks[] = array('title' => Yii::t('base', $title), 'state' => 'WARNING', 'hint' => 'Optional - Install APC Extension for APC Caching');
     }
     // Checks SQLite3 Extension
     $title = 'PHP - SQLite3 Support';
     if (class_exists('SQLite3')) {
         $checks[] = array('title' => Yii::t('base', $title), 'state' => 'OK');
     } else {
         $checks[] = array('title' => Yii::t('base', $title), 'state' => 'WARNING', 'hint' => 'Optional - Install SQLite3 Extension for DB Caching');
     }
     // Checks Writeable Config
     /*
      $title = 'Permissions - Config';
      $configFile = dirname(Yii::$app->params['dynamicConfigFile']);
      if (is_writeable($configFile)) {
      $checks[] = array(
      'title' => Yii::t('base', $title),
      'state' => 'OK'
      );
      } else {
      $checks[] = array(
      'title' => Yii::t('base', $title),
      'state' => 'ERROR',
      'hint' => 'Make ' . $configFile . " writable for the webserver/php!"
      );
      }
     */
     // Check Runtime Directory
     $title = 'Permissions - Runtime';
     $path = Yii::getAlias('@runtime');
     if (is_writeable($path)) {
         $checks[] = array('title' => Yii::t('base', $title), 'state' => 'OK');
     } else {
         $checks[] = array('title' => Yii::t('base', $title), 'state' => 'ERROR', 'hint' => 'Make ' . $path . " writable for the webserver/php!");
     }
     // Check Assets Directory
     $title = 'Permissions - Assets';
     $path = Yii::getAlias('@webroot/assets');
     if (is_writeable($path)) {
         $checks[] = array('title' => Yii::t('base', $title), 'state' => 'OK');
     } else {
         $checks[] = array('title' => Yii::t('base', $title), 'state' => 'ERROR', 'hint' => 'Make ' . $path . " writable for the webserver/php!");
     }
     // Check Uploads Directory
     $title = 'Permissions - Uploads';
     $path = Yii::getAlias('@webroot/uploads');
     if (is_writeable($path)) {
         $checks[] = array('title' => Yii::t('base', $title), 'state' => 'OK');
     } else {
         $checks[] = array('title' => Yii::t('base', $title), 'state' => 'ERROR', 'hint' => 'Make ' . $path . " writable for the webserver/php!");
     }
     // Check Custom Modules Directory
     $title = 'Permissions - Module Directory';
     $path = Yii::getAlias('@app/modules');
     if (is_writeable($path)) {
         $checks[] = array('title' => Yii::t('base', $title), 'state' => 'OK');
     } else {
         $checks[] = array('title' => Yii::t('base', $title), 'state' => 'ERROR', 'hint' => 'Make ' . $path . " writable for the webserver/php!");
     }
     // Check Custom Modules Directory
     $title = 'Permissions - Dynamic Config';
     $path = Yii::getAlias(Yii::$app->params['dynamicConfigFile']);
     if (!is_file($path)) {
         $path = dirname($path);
     }
     if (is_writeable($path)) {
         $checks[] = array('title' => Yii::t('base', $title), 'state' => 'OK');
     } else {
         $checks[] = array('title' => Yii::t('base', $title), 'state' => 'ERROR', 'hint' => 'Make ' . $path . " writable for the webserver/php!");
     }
     return $checks;
 }
Пример #4
0
 /**
  * Finds user by [[username]]
  *
  * @return User|null
  */
 public function getUser()
 {
     if ($this->_user === false) {
         $this->_user = User::find()->where(['username' => $this->username])->orWhere(['email' => $this->username])->one();
         // Could not found user -> lookup in LDAP
         if ($this->_user === null && Ldap::isAvailable() && Setting::Get('enabled', 'authentication_ldap')) {
             try {
                 // Try load/create LDAP user
                 $usernameDn = Ldap::getInstance()->ldap->getCanonicalAccountName($this->username, \Zend\Ldap\Ldap::ACCTNAME_FORM_DN);
                 Ldap::getInstance()->handleLdapUser(Ldap::getInstance()->ldap->getNode($usernameDn));
                 // Check if user is availble now
                 $this->_user = User::find()->where(['username' => $this->username])->orWhere(['email' => $this->username])->one();
             } catch (\Zend\Ldap\Exception\LdapException $ex) {
                 // User not found
             }
         }
     }
     return $this->_user;
 }
 public static function onHourlyCron($event)
 {
     $controller = $event->sender;
     if (Setting::Get('enabled', 'authentication_ldap') && Setting::Get('refreshUsers', 'authentication_ldap') && Ldap::isAvailable()) {
         $controller->stdout("Refresh ldap users... ");
         Ldap::getInstance()->refreshUsers();
         $controller->stdout('done.' . PHP_EOL, \yii\helpers\Console::FG_GREEN);
     }
     // Delete expired session
     foreach (models\Session::find()->where(['<', 'expire', time()])->all() as $session) {
         $session->delete();
     }
 }
Пример #6
0
 public static function onHourlyCron($event)
 {
     $controller = $event->sender;
     if (Setting::Get('enabled', 'authentication_ldap') && Setting::Get('refreshUsers', 'authentication_ldap') && Ldap::isAvailable()) {
         $controller->stdout("Refresh ldap users... ");
         Ldap::getInstance()->refreshUsers();
         $controller->stdout('done.' . PHP_EOL, \yii\helpers\Console::FG_GREEN);
     }
 }
 public function actionLdapRefresh()
 {
     Ldap::getInstance()->refreshUsers();
     Yii::$app->response->redirect(Url::toRoute('/admin/setting/authentication-ldap'));
 }