From 2a37becfa695eb09d66e2e42bfcbb6f4cb9300b8 Mon Sep 17 00:00:00 2001 From: Marco Dickert Date: Mon, 26 Mar 2018 17:15:36 +0200 Subject: [PATCH] Allow authentication via header for scripting purposes --- build/libifm.php | 6 ++++++ ifm.php | 6 ++++++ src/main.php | 6 ++++++ 3 files changed, 18 insertions(+) diff --git a/build/libifm.php b/build/libifm.php index da6cb9b..6e71721 100644 --- a/build/libifm.php +++ b/build/libifm.php @@ -3985,6 +3985,12 @@ function IFM( params ) { if( $this->config['auth'] == 0 ) return true; + if( isset( $_SERVER['HTTP_X_IFM_AUTH'] ) && ! empty( $_SERVER['HTTP_X_IFM_AUTH'] ) ) { + $cred = split( ":", base64_decode( $_SERVER['HTTP_X_IFM_AUTH'] ) ); + if( count( $cred ) == 2 && $this->checkCredentials( $cred[0], $cred[1] ) ) + return true; + } + if( session_status() !== PHP_SESSION_ACTIVE ) { if( isset( $this->config['session_lifetime'] ) ) ini_set( 'session.gc_maxlifetime', $this->config['session_lifetime'] ); diff --git a/ifm.php b/ifm.php index 0cb7518..d7b6372 100644 --- a/ifm.php +++ b/ifm.php @@ -3985,6 +3985,12 @@ function IFM( params ) { if( $this->config['auth'] == 0 ) return true; + if( isset( $_SERVER['HTTP_X_IFM_AUTH'] ) && ! empty( $_SERVER['HTTP_X_IFM_AUTH'] ) ) { + $cred = split( ":", base64_decode( $_SERVER['HTTP_X_IFM_AUTH'] ) ); + if( count( $cred ) == 2 && $this->checkCredentials( $cred[0], $cred[1] ) ) + return true; + } + if( session_status() !== PHP_SESSION_ACTIVE ) { if( isset( $this->config['session_lifetime'] ) ) ini_set( 'session.gc_maxlifetime', $this->config['session_lifetime'] ); diff --git a/src/main.php b/src/main.php index a1f8bb3..d2b0d52 100644 --- a/src/main.php +++ b/src/main.php @@ -965,6 +965,12 @@ f00bar; if( $this->config['auth'] == 0 ) return true; + if( isset( $_SERVER['HTTP_X_IFM_AUTH'] ) && ! empty( $_SERVER['HTTP_X_IFM_AUTH'] ) ) { + $cred = split( ":", base64_decode( $_SERVER['HTTP_X_IFM_AUTH'] ) ); + if( count( $cred ) == 2 && $this->checkCredentials( $cred[0], $cred[1] ) ) + return true; + } + if( session_status() !== PHP_SESSION_ACTIVE ) { if( isset( $this->config['session_lifetime'] ) ) ini_set( 'session.gc_maxlifetime', $this->config['session_lifetime'] );