From ec068594aa537b48913ba2c813122929663c8bd7 Mon Sep 17 00:00:00 2001 From: Cryol Date: Wed, 4 Dec 2019 04:23:56 +0200 Subject: [PATCH 1/2] add ldap filter --- build/libifm.php | 32 +++++++++++++++++++------------- ifm.php | 32 +++++++++++++++++++------------- src/main.php | 19 +++++++++++++++++-- 3 files changed, 55 insertions(+), 28 deletions(-) diff --git a/build/libifm.php b/build/libifm.php index 57a2765..a1bb221 100644 --- a/build/libifm.php +++ b/build/libifm.php @@ -107,7 +107,7 @@ class IFM { // get list of ace includes $this->config['ace_includes'] = <<<'f00bar' -|ext-searchbox + f00bar; // templates @@ -1320,16 +1320,7 @@ l=0;for(h=f.length;lf)break;if(!u[0]){t.lastIndex=o+=1;if(o>=i.length)break}}}this.searchCounter.textContent=r+" of "+(n>f?f+"+":n)},this.findNext=function(){this.find(!0,!1)},this.findPrev=function(){this.find(!0,!0)},this.findAll=function(){var e=this.editor.findAll(this.searchInput.value,{regExp:this.regExpOption.checked,caseSensitive:this.caseSensitiveOption.checked,wholeWord:this.wholeWordOption.checked}),t=!e&&this.searchInput.value;r.setCssClass(this.searchBox,"ace_nomatch",t),this.editor._emit("findSearchBox",{match:!t}),this.highlight(),this.hide()},this.replace=function(){this.editor.getReadOnly()||this.editor.replace(this.replaceInput.value)},this.replaceAndFindNext=function(){this.editor.getReadOnly()||(this.editor.replace(this.replaceInput.value),this.findNext())},this.replaceAll=function(){this.editor.getReadOnly()||this.editor.replaceAll(this.replaceInput.value)},this.hide=function(){this.active=!1,this.setSearchRange(null),this.editor.off("changeSession",this.setSession),this.element.style.display="none",this.editor.keyBinding.removeKeyboardHandler(this.$closeSearchBarKb),this.editor.focus()},this.show=function(e,t){this.active=!0,this.editor.on("changeSession",this.setSession),this.element.style.display="",this.replaceOption.checked=t,e&&(this.searchInput.value=e),this.searchInput.focus(),this.searchInput.select(),this.editor.keyBinding.addKeyboardHandler(this.$closeSearchBarKb),this.$syncOptions(!0)},this.isFocused=function(){var e=document.activeElement;return e==this.searchInput||e==this.replaceInput}}).call(l.prototype),t.SearchBox=l,t.Search=function(e,t){var n=e.searchBox||new l(e);n.show(e.session.getTextRange(),t)}}); (function() { - ace.require(["ace/ext/searchbox"], function(m) { - if (typeof module == "object" && typeof exports == "object" && module) { - module.exports = m; - } - }); - })(); - - - + /** * IFM constructor * @@ -4072,7 +4063,13 @@ f00bar; break; case "ldap": $authenticated = false; - list( $ldap_server, $rootdn ) = explode( ";", $srcopt ); + $ldapopts = explode( ";", $srcopt ); + if( count( $ldapopts ) === 3 ) { + list( $ldap_server, $rootdn, $ufilter ) = explode( ";", $srcopt ); + } else { + list( $ldap_server, $rootdn ) = explode( ";", $srcopt ); + $ufilter = false; + } $u = "uid=" . $user . "," . $rootdn; if( ! $ds = ldap_connect( $ldap_server ) ) { trigger_error( "Could not reach the ldap server.", E_USER_ERROR ); @@ -4082,7 +4079,16 @@ f00bar; if( $ds ) { $ldbind = @ldap_bind( $ds, $u, $pass ); if( $ldbind ) { - $authenticated = true; + if( $ufilter ) { + if( ldap_count_entries( $ds, ldap_search( $ds, $rootdn, $ufilter ) ) > 0 ){ + $authenticated = true; + } else { + trigger_error( "User not allowed.", E_USER_ERROR ); + $authenticated = false; + } + } else { + $authenticated = true; + } } else { trigger_error( ldap_error( $ds ), E_USER_ERROR ); $authenticated = false; diff --git a/ifm.php b/ifm.php index 4034910..4c72adb 100644 --- a/ifm.php +++ b/ifm.php @@ -107,7 +107,7 @@ class IFM { // get list of ace includes $this->config['ace_includes'] = <<<'f00bar' -|ext-searchbox + f00bar; // templates @@ -1320,16 +1320,7 @@ l=0;for(h=f.length;lf)break;if(!u[0]){t.lastIndex=o+=1;if(o>=i.length)break}}}this.searchCounter.textContent=r+" of "+(n>f?f+"+":n)},this.findNext=function(){this.find(!0,!1)},this.findPrev=function(){this.find(!0,!0)},this.findAll=function(){var e=this.editor.findAll(this.searchInput.value,{regExp:this.regExpOption.checked,caseSensitive:this.caseSensitiveOption.checked,wholeWord:this.wholeWordOption.checked}),t=!e&&this.searchInput.value;r.setCssClass(this.searchBox,"ace_nomatch",t),this.editor._emit("findSearchBox",{match:!t}),this.highlight(),this.hide()},this.replace=function(){this.editor.getReadOnly()||this.editor.replace(this.replaceInput.value)},this.replaceAndFindNext=function(){this.editor.getReadOnly()||(this.editor.replace(this.replaceInput.value),this.findNext())},this.replaceAll=function(){this.editor.getReadOnly()||this.editor.replaceAll(this.replaceInput.value)},this.hide=function(){this.active=!1,this.setSearchRange(null),this.editor.off("changeSession",this.setSession),this.element.style.display="none",this.editor.keyBinding.removeKeyboardHandler(this.$closeSearchBarKb),this.editor.focus()},this.show=function(e,t){this.active=!0,this.editor.on("changeSession",this.setSession),this.element.style.display="",this.replaceOption.checked=t,e&&(this.searchInput.value=e),this.searchInput.focus(),this.searchInput.select(),this.editor.keyBinding.addKeyboardHandler(this.$closeSearchBarKb),this.$syncOptions(!0)},this.isFocused=function(){var e=document.activeElement;return e==this.searchInput||e==this.replaceInput}}).call(l.prototype),t.SearchBox=l,t.Search=function(e,t){var n=e.searchBox||new l(e);n.show(e.session.getTextRange(),t)}}); (function() { - ace.require(["ace/ext/searchbox"], function(m) { - if (typeof module == "object" && typeof exports == "object" && module) { - module.exports = m; - } - }); - })(); - - - + /** * IFM constructor * @@ -4072,7 +4063,13 @@ f00bar; break; case "ldap": $authenticated = false; - list( $ldap_server, $rootdn ) = explode( ";", $srcopt ); + $ldapopts = explode( ";", $srcopt ); + if( count( $ldapopts ) === 3 ) { + list( $ldap_server, $rootdn, $ufilter ) = explode( ";", $srcopt ); + } else { + list( $ldap_server, $rootdn ) = explode( ";", $srcopt ); + $ufilter = false; + } $u = "uid=" . $user . "," . $rootdn; if( ! $ds = ldap_connect( $ldap_server ) ) { trigger_error( "Could not reach the ldap server.", E_USER_ERROR ); @@ -4082,7 +4079,16 @@ f00bar; if( $ds ) { $ldbind = @ldap_bind( $ds, $u, $pass ); if( $ldbind ) { - $authenticated = true; + if( $ufilter ) { + if( ldap_count_entries( $ds, ldap_search( $ds, $rootdn, $ufilter ) ) > 0 ){ + $authenticated = true; + } else { + trigger_error( "User not allowed.", E_USER_ERROR ); + $authenticated = false; + } + } else { + $authenticated = true; + } } else { trigger_error( ldap_error( $ds ), E_USER_ERROR ); $authenticated = false; diff --git a/src/main.php b/src/main.php index 9228a9c..0cdeec5 100644 --- a/src/main.php +++ b/src/main.php @@ -1043,7 +1043,13 @@ f00bar; break; case "ldap": $authenticated = false; - list( $ldap_server, $rootdn ) = explode( ";", $srcopt ); + $ldapopts = explode( ";", $srcopt ); + if( count( $ldapopts ) === 3 ) { + list( $ldap_server, $rootdn, $ufilter ) = explode( ";", $srcopt ); + } else { + list( $ldap_server, $rootdn ) = explode( ";", $srcopt ); + $ufilter = false; + } $u = "uid=" . $user . "," . $rootdn; if( ! $ds = ldap_connect( $ldap_server ) ) { trigger_error( "Could not reach the ldap server.", E_USER_ERROR ); @@ -1053,7 +1059,16 @@ f00bar; if( $ds ) { $ldbind = @ldap_bind( $ds, $u, $pass ); if( $ldbind ) { - $authenticated = true; + if( $ufilter ) { + if( ldap_count_entries( $ds, ldap_search( $ds, $rootdn, $ufilter ) ) > 0 ){ + $authenticated = true; + } else { + trigger_error( "User not allowed.", E_USER_ERROR ); + $authenticated = false; + } + } else { + $authenticated = true; + } } else { trigger_error( ldap_error( $ds ), E_USER_ERROR ); $authenticated = false; From ac1e73850cf99c46c519cf2d77f431bb00c53217 Mon Sep 17 00:00:00 2001 From: Cryol Date: Wed, 4 Dec 2019 13:23:44 +0200 Subject: [PATCH 2/2] WHERE auth in config and logout\? unset\? realy\? --- build/libifm.php | 1 - ifm.php | 1 - src/main.php | 1 - 3 files changed, 3 deletions(-) diff --git a/build/libifm.php b/build/libifm.php index a1bb221..9be5952 100644 --- a/build/libifm.php +++ b/build/libifm.php @@ -3430,7 +3430,6 @@ f00bar; $ret = $this->config; $ret['inline'] = ( $this->mode == "inline" ) ? true : false; $ret['isDocroot'] = ( $this->getRootDir() == $this->getScriptRoot() ) ? true : false; - unset( $ret['auth'] ); unset( $ret['auth_source'] ); $this->jsonResponse( $ret ); } diff --git a/ifm.php b/ifm.php index 4c72adb..961e557 100644 --- a/ifm.php +++ b/ifm.php @@ -3430,7 +3430,6 @@ f00bar; $ret = $this->config; $ret['inline'] = ( $this->mode == "inline" ) ? true : false; $ret['isDocroot'] = ( $this->getRootDir() == $this->getScriptRoot() ) ? true : false; - unset( $ret['auth'] ); unset( $ret['auth_source'] ); $this->jsonResponse( $ret ); } diff --git a/src/main.php b/src/main.php index 0cdeec5..f77f386 100644 --- a/src/main.php +++ b/src/main.php @@ -410,7 +410,6 @@ f00bar; $ret = $this->config; $ret['inline'] = ( $this->mode == "inline" ) ? true : false; $ret['isDocroot'] = ( $this->getRootDir() == $this->getScriptRoot() ) ? true : false; - unset( $ret['auth'] ); unset( $ret['auth_source'] ); $this->jsonResponse( $ret ); }