@@ -1195,7 +1195,7 @@ function server_ip($event_name,$data) {
11951195 //* Create or update the .htaccess folder protection
11961196 function web_folder_user ($ event_name ,$ data ) {
11971197 global $ app , $ conf ;
1198-
1198+
11991199 $ app ->uses ('system ' );
12001200
12011201 if ($ event_name == 'web_folder_user_delete ' ) {
@@ -1213,17 +1213,19 @@ function web_folder_user($event_name,$data) {
12131213 }
12141214
12151215 //* Get the folder path.
1216- $ folder_path = realpath ($ website ['document_root ' ].'/web/ ' .$ folder ['path ' ]);
1216+ if (substr ($ folder ['path ' ],0 ,1 ) == '/ ' ) $ folder ['path ' ] = substr ($ folder ['path ' ],1 );
1217+ if (substr ($ folder ['path ' ],-1 ) == '/ ' ) $ folder ['path ' ] = substr ($ folder ['path ' ],0 ,-1 );
1218+ $ folder_path = escapeshellcmd ($ website ['document_root ' ].'/web/ ' .$ folder ['path ' ]);
12171219 if (substr ($ folder_path ,-1 != '/ ' )) $ folder_path .= '/ ' ;
12181220
12191221 //* Check if the resulting path is inside the docroot
1220- if (substr ($ folder_path ,0 , strlen ( $ website [ ' document_root ' ])) != $ website [ ' document_root ' ] ) {
1221- $ app ->log ('Folder path is outside of docroot . ' ,LOGLEVEL_DEBUG );
1222+ if (stristr ($ folder_path ,' .. ' ) || stristr ( $ folder_path , ' ./ ' ) || stristr ( $ folder_path , '\\' ) ) {
1223+ $ app ->log ('Folder path " ' . $ folder_path . ' " contains .. or ./ . ' ,LOGLEVEL_DEBUG );
12221224 return false ;
12231225 }
12241226
12251227 //* Create the folder path, if it does not exist
1226- if (!is_dir ($ folder_path )) exec ('mkdir -p ' .escapehsellarg ( $ folder_path) );
1228+ if (!is_dir ($ folder_path )) exec ('mkdir -p ' .$ folder_path );
12271229
12281230 //* Create empty .htpasswd file, if it does not exist
12291231 if (!is_file ($ folder_path .'.htpasswd ' )) {
@@ -1232,13 +1234,20 @@ function web_folder_user($event_name,$data) {
12321234 $ app ->log ('Created file ' .$ folder_path .'.htpasswd ' ,LOGLEVEL_DEBUG );
12331235 }
12341236
1237+ if ($ data ['new ' ]['username ' ] != $ data ['old ' ]['username ' ] || $ data ['new ' ]['active ' ] == 'n ' ) {
1238+ $ app ->system ->removeLine ($ folder_path .'.htpasswd ' ,$ data ['old ' ]['username ' ].': ' );
1239+ $ app ->log ('Removed user: ' .$ data ['old ' ]['username ' ],LOGLEVEL_DEBUG );
1240+ }
1241+
12351242 //* Add or remove the user from .htpasswd file
12361243 if ($ event_name == 'web_folder_user_delete ' ) {
1237- $ app ->system ->removeLine ($ folder_path .'.htpasswd ' ,$ data ['new ' ]['username ' ].': ' );
1238- $ app ->log ('Removed user: ' .$ data ['new ' ]['username ' ],LOGLEVEL_DEBUG );
1244+ $ app ->system ->removeLine ($ folder_path .'.htpasswd ' ,$ data ['old ' ]['username ' ].': ' );
1245+ $ app ->log ('Removed user: ' .$ data ['old ' ]['username ' ],LOGLEVEL_DEBUG );
12391246 } else {
1240- $ app ->system ->replaceLine ($ folder_path .'.htpasswd ' ,$ data ['new ' ]['username ' ].': ' ,$ data ['new ' ]['username ' ].': ' .$ data ['new ' ]['password ' ],0 ,1 );
1241- $ app ->log ('Added or updated user: ' .$ data ['new ' ]['username ' ],LOGLEVEL_DEBUG );
1247+ if ($ data ['new ' ]['active ' ] == 'y ' ) {
1248+ $ app ->system ->replaceLine ($ folder_path .'.htpasswd ' ,$ data ['new ' ]['username ' ].': ' ,$ data ['new ' ]['username ' ].': ' .$ data ['new ' ]['password ' ],0 ,1 );
1249+ $ app ->log ('Added or updated user: ' .$ data ['new ' ]['username ' ],LOGLEVEL_DEBUG );
1250+ }
12421251 }
12431252
12441253 //* Create the .htaccess file
0 commit comments