X-Git-Url: http://git.roojs.org/?a=blobdiff_plain;f=DataObjects%2FCore_person.php;h=d0ef8be31322cd50d013f3d3043fe2f90f22ebec;hb=624a8a16f810023c8890b25b9d93a6cc61e478bb;hp=9f39f3a5fc163bc07edb01d282c8613a290062b1;hpb=b318ae248585cf89f80af6c33024da7ae2d15c5f;p=Pman.Core diff --git a/DataObjects/Core_person.php b/DataObjects/Core_person.php index 9f39f3a5..d0ef8be3 100644 --- a/DataObjects/Core_person.php +++ b/DataObjects/Core_person.php @@ -291,12 +291,12 @@ class Pman_Core_DataObjects_Core_person extends DB_DataObject } - // local auth - - $default_admin = false; - if (!empty($ff->Pman['local_autoauth']) && - ($ff->Pman['local_autoauth'] === true) && - (!empty($_SERVER['SERVER_ADDR'])) && - ( + $auto_auth_allow = false; + if (!empty($ff->Pman['local_autoauth']) && $ff->Pman['local_autoauth'] === true) { + $auto_auth_allow = true; + } + if ( + (!empty($_SERVER['SERVER_ADDR'])) && ( $_SERVER['SERVER_ADDR'] == '127.0.0.1' && $_SERVER['REMOTE_ADDR'] == '127.0.0.1' @@ -306,8 +306,19 @@ class Pman_Core_DataObjects_Core_person extends DB_DataObject $_SERVER['SERVER_ADDR'] == '::1' && $_SERVER['REMOTE_ADDR'] == '::1' ) - ) - ) { + + ){ + $auto_auth_allow = true; + } + + + if (empty($_SERVER['PATH_INFO']) || $_SERVER['PATH_INFO'] == '/Login') { + $auto_auth_allow = false; + } + //var_dump($auto_auth_allow); + // local auth - + $default_admin = false; + if ($auto_auth_allow) { $group = DB_DataObject::factory('core_group'); $group->get('name', 'Administrators'); @@ -329,25 +340,13 @@ class Pman_Core_DataObjects_Core_person extends DB_DataObject $u = DB_DataObject::factory($this->tableName()); $ff = HTML_FlexyFramework::get(); - if (!empty($ff->Pman['local_autoauth']) && - (!empty($_SERVER['SERVER_ADDR'])) && - ( - ( - $_SERVER['SERVER_ADDR'] == '127.0.0.1' && - $_SERVER['REMOTE_ADDR'] == '127.0.0.1' - ) - || - ( - $_SERVER['SERVER_ADDR'] == '::1' && - $_SERVER['REMOTE_ADDR'] == '::1' - ) - ) && + if ($auto_auth_allow && ($default_admin || $u->get('email', $ff->Pman['local_autoauth'])) ) { $user = $default_admin ? $default_admin->toArray() : $u->toArray(); - $_SESSION[get_class($this)][$sesPrefix .'-auth'] = serialize((object) $user); + //$_SESSION[get_class($this)][$sesPrefix .'-auth'] = serialize((object) $user); return true; } @@ -370,10 +369,9 @@ class Pman_Core_DataObjects_Core_person extends DB_DataObject } } if (!$n){ // authenticated as there are no users in the system... - return true; + return true; } - - return false; + return false; } @@ -518,15 +516,16 @@ class Pman_Core_DataObjects_Core_person extends DB_DataObject return md5(implode(',' , array($month, $this->email , $this->passwd, $this->id))); } - function checkTwoFactorAuthentication($val, $oath_key) + function checkTwoFactorAuthentication($val) { - // also used in login + + // also used in login require_once 'System.php'; if( empty($this->id) || - empty($oath_key) + empty($this->oath_key) ) { return false; } @@ -537,7 +536,7 @@ class Pman_Core_DataObjects_Core_person extends DB_DataObject return false; } - $cmd = "{$oathtool} --totp --base32 {$oath_key}"; + $cmd = "{$oathtool} --totp --base32 " . escapeshellarg($this->oath_key); $password = exec($cmd); @@ -672,9 +671,11 @@ class Pman_Core_DataObjects_Core_person extends DB_DataObject $aur['oath_key'] = ''; $aur['oath_key_enable'] = !empty($this->oath_key); + $aur['require_oath'] = 1; $s = DB_DataObject::Factory('core_setting'); - $aur['disable_oath'] = (bool) $s->lookup('core', 'two_factor_authentication') ? 1 : 0; + $oath_require = $s->lookup('core', 'two_factor_authentication_requirement'); + $aur['require_oath'] = $oath_require ? $oath_require->val : 0; return $aur; } @@ -767,7 +768,6 @@ class Pman_Core_DataObjects_Core_person extends DB_DataObject { //DB_DataObject::DebugLevel(1); if(!empty($q['_to_qr_code'])){ - $person = DB_DataObject::factory('Core_person'); $person->id = $q['id']; @@ -777,8 +777,13 @@ class Pman_Core_DataObjects_Core_person extends DB_DataObject $hash = $this->generateOathKey(); - $_SESSION[__CLASS__] = isset($_SESSION[__CLASS__]) ? $_SESSION[__CLASS__] : array(); - $_SESSION[__CLASS__]['oath'] = isset($_SESSION[__CLASS__]['oath']) ? $_SESSION[__CLASS__]['oath'] : array(); + $_SESSION[__CLASS__] = + isset($_SESSION[__CLASS__]) ? + $_SESSION[__CLASS__] : array(); + $_SESSION[__CLASS__]['oath'] = + isset($_SESSION[__CLASS__]['oath']) ? + $_SESSION[__CLASS__]['oath'] : array(); + $_SESSION[__CLASS__]['oath'][$person->id] = $hash; $qrcode = $person->generateQRCode($hash); @@ -791,21 +796,14 @@ class Pman_Core_DataObjects_Core_person extends DB_DataObject } if(!empty($q['two_factor_auth_code'])) { - $person = DB_DataObject::factory('core_person'); $person->get($q['id']); + $o = clone($person); + $person->oath_key = $_SESSION[__CLASS__]['oath'][$person->id]; - if($person->checkTwoFactorAuthentication( - $q['two_factor_auth_code'], - $_SESSION[__CLASS__]['oath'][$person->id] - )) { - - $o = clone($person); - $person->oath_key = $_SESSION[__CLASS__]['oath'][$person->id]; + if($person->checkTwoFactorAuthentication($q['two_factor_auth_code'])) { $person->update($o); - unset($_SESSION[__CLASS__]['oath'][$person->id]); - $roo->jok('DONE'); } @@ -813,7 +811,6 @@ class Pman_Core_DataObjects_Core_person extends DB_DataObject } if(!empty($q['oath_key_disable'])) { - $person = DB_DataObject::factory('core_person'); $person->get($q['id']);