1
0
mirror of https://github.com/misterunknown/ifm.git synced 2025-08-09 17:46:31 +02:00

Revert to old authentication function for now.

Signed-off-by: Marco Dickert <marco@misterunknown.de>
This commit is contained in:
Marco Dickert
2020-07-18 19:01:23 +02:00
parent d286c0a07c
commit 3bc1e0ee97

View File

@@ -972,7 +972,7 @@ IFM_ASSETS
$item = utf8_encode( $item );
}
public function checkAuth() {
function checkAuth() {
if( $this->config['auth'] == 0 )
return true;
@@ -994,16 +994,13 @@ IFM_ASSETS
if( ! isset( $_SESSION['ifmauth'] ) || $_SESSION['ifmauth'] !== true ) {
$login_failed = false;
$login_message = "";
if( isset( $_POST["inputLogin"] ) && isset( $_POST["inputPassword"] ) ) {
$state = $this->checkCredentials( $_POST["inputLogin"], $_POST["inputPassword"] );
if($state['status']) {
if( $this->checkCredentials( $_POST["inputLogin"], $_POST["inputPassword"] ) ) {
$_SESSION['ifmauth'] = true;
}
else {
$_SESSION['ifmauth'] = false;
$login_failed = true;
$login_message = $state['message'];
}
}
@@ -1016,7 +1013,7 @@ IFM_ASSETS
else
$this->jsonResponse( array( "status"=>"ERROR", "message"=>"not authenticated" ) );
} else {
$this->loginForm($login_failed, $login_message);
$this->loginForm($login_failed);
}
return false;
}
@@ -1026,7 +1023,6 @@ IFM_ASSETS
}
private function checkCredentials( $user, $pass ) {
$authenticated = array("status" => false, "message" => "");
list( $src, $srcopt ) = explode( ";", $this->config['auth_source'], 2 );
switch( $src ) {
case "inline":
@@ -1039,11 +1035,12 @@ IFM_ASSETS
$htpasswd = new Htpasswd( $srcopt );
return $htpasswd->verify( $user, $pass );
} else {
// trigger_error( "IFM: Fatal: Credential file does not exist or is not readable" );
return $authenticated;
trigger_error( "IFM: Fatal: Credential file does not exist or is not readable" );
return false;
}
break;
case "ldap":
$authenticated = false;
$ldapopts = explode( ";", $srcopt );
if( count( $ldapopts ) === 3 ) {
list( $ldap_server, $rootdn, $ufilter ) = explode( ";", $srcopt );
@@ -1053,8 +1050,8 @@ IFM_ASSETS
}
$u = "uid=" . $user . "," . $rootdn;
if( ! $ds = ldap_connect( $ldap_server ) ) {
$authenticated['status'] = false;
$authenticated['message'] = "Could not reach the ldap server.";
trigger_error( "Could not reach the ldap server.", E_USER_ERROR );
return false;
}
ldap_set_option( $ds, LDAP_OPT_PROTOCOL_VERSION, 3 );
if( $ds ) {
@@ -1062,29 +1059,28 @@ IFM_ASSETS
if( $ldbind ) {
if( $ufilter ) {
if( ldap_count_entries( $ds, ldap_search( $ds, $rootdn, $ufilter ) ) > 0 ){
$authenticated['status'] = true;
$authenticated = true;
} else {
$authenticated['status'] = false;
$authenticated['message'] = "User not allowed.";
trigger_error( "User not allowed.", E_USER_ERROR );
$authenticated = false;
}
} else {
$authenticated['status'] = true;
$authenticated = true;
}
} else {
$authenticated['status'] = false;
$authenticated['message'] = ldap_error( $ds );
trigger_error( ldap_error( $ds ), E_USER_ERROR );
$authenticated = false;
}
ldap_unbind( $ds );
} else {
$authenticated['status'] = false;
}
} else
$authenticated = false;
return $authenticated;
break;
}
return $authenticated;
return false;
}
private function loginForm($loginFailed=false, $loginMessage) {
private function loginForm($loginFailed=false, $loginMessage="") {
$err = "";
if( $loginFailed )
$err = '<div class="alert alert-danger" role="alert">'.$loginMessage.'</div>';