@@ -1883,22 +1883,33 @@ public function is_blacklisted_web_path($path) {
18831883 function web_folder_protection ($ document_root , $ protect ) {
18841884 global $ app , $ conf ;
18851885
1886- if ($ this ->checkpath ($ document_root ) == false ) {
1886+ // Ensure $document_root is a string and not null
1887+ $ document_root = is_string ($ document_root ) ? trim ($ document_root ) : '' ;
1888+
1889+ // Check if the path is valid
1890+ if ($ this ->checkpath ($ document_root ) === false ) {
18871891 $ app ->log ("Action aborted, target is a symlink: $ document_root " , LOGLEVEL_DEBUG );
18881892 return false ;
18891893 }
18901894
1891- //* load the server configuration options
1895+ // Load the server configuration options
18921896 $ app ->uses ('getconf ' );
18931897 $ web_config = $ app ->getconf ->get_server_config ($ conf ['server_id ' ], 'web ' );
18941898
1895- if ($ protect == true && $ web_config ['web_folder_protection ' ] == 'y ' ) {
1896- //* Add protection
1897- if ($ document_root != '' && $ document_root != '/ ' && strlen ($ document_root ) > 6 && !stristr ($ document_root , '.. ' )) $ this ->exec_safe ('chattr +i ? ' , $ document_root );
1899+ // Add or remove protection based on $protect and configuration
1900+ if ($ protect === true && isset ($ web_config ['web_folder_protection ' ]) && $ web_config ['web_folder_protection ' ] === 'y ' ) {
1901+ // Add protection
1902+ if ($ document_root !== '' && $ document_root !== '/ ' && strlen ($ document_root ) > 6 && strpos ($ document_root , '.. ' ) === false ) {
1903+ $ this ->exec_safe ('chattr +i ? ' , $ document_root );
1904+ }
18981905 } else {
1899- //* Remove protection
1900- if ($ document_root != '' && $ document_root != '/ ' && strlen ($ document_root ) > 6 && !stristr ($ document_root , '.. ' )) $ this ->exec_safe ('chattr -i ? ' , $ document_root );
1906+ // Remove protection
1907+ if ($ document_root !== '' && $ document_root !== '/ ' && strlen ($ document_root ) > 6 && strpos ($ document_root , '.. ' ) === false ) {
1908+ $ this ->exec_safe ('chattr -i ? ' , $ document_root );
1909+ }
19011910 }
1911+
1912+ return true ;
19021913 }
19031914
19041915 function usermod ($ username , $ uid = 0 , $ gid = 0 , $ home = '' , $ shell = '' , $ password = '' , $ login = '' ) {
0 commit comments