diff --git a/user_otp/adminSettings.php b/user_otp/adminSettings.php index 31c78f0..e467cda 100755 --- a/user_otp/adminSettings.php +++ b/user_otp/adminSettings.php @@ -150,6 +150,11 @@ $configOtp[$i]['type']='checkbox'; $configOtp[$i]['default_value']=false; $i++; +$configOtp[$i]['name']='exceptForThisHosts'; +$configOtp[$i]['label']='Skip otp for these hosts ( comma separated )'; +$configOtp[$i]['type']='text'; +$configOtp[$i]['default_value']='localhost'; $i++; + foreach ($allTab as $tab){ foreach ($$tab["arrayConf"] as $input){ switch ($input['type']){ diff --git a/user_otp/lib/otp.php b/user_otp/lib/otp.php index cf5bfa0..2349ca8 100755 --- a/user_otp/lib/otp.php +++ b/user_otp/lib/otp.php @@ -248,6 +248,17 @@ public function checkPassword($uid, $password) { return $userBackend->checkPassword($uid, $password); } + $bypass_hosts = array_map('trim', explode(',', OCP\Config::getAppValue('user_otp','exceptForThisHosts',"localhost"))); + foreach ($bypass_hosts as &$single_host) { + if ($single_host!=null && isset($_SERVER['REMOTE_ADDR'])) { + OC_Log::write('OC_USER_OTP','Checking \''.$_SERVER['REMOTE_ADDR'].'\' against \''.$single_host.'\'', OC_Log::DEBUG); + if (gethostbyname($single_host) === $_SERVER['REMOTE_ADDR'] ) { + OC_Log::write('OC_USER_OTP','Skipping OTP for '.$uid.' from \''.$single_host.'\' ('.$_SERVER['REMOTE_ADDR'].')', OC_Log::INFO); + return $userBackend->checkPassword($uid, $password); + } + } + } + if(!$this->mOtp->CheckUserExists($uid)){ OC_Log::write('OC_USER_OTP','No OTP for user '.$uid.' use user backend', OC_Log::DEBUG); return $userBackend->checkPassword($uid, $password);