Changeset 584844
- Timestamp:
- 08/13/2012 12:36:27 PM (14 years ago)
- Location:
- 6scan-protection/trunk
- Files:
-
- 5 edited
-
6scan.php (modified) (1 diff)
-
admin/includes/common.php (modified) (7 diffs)
-
admin/includes/htaccess.php (modified) (2 diffs)
-
admin/includes/installation.php (modified) (3 diffs)
-
modules/signatures/update.php (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
6scan-protection/trunk/6scan.php
r580294 r584844 24 24 define( 'SIXSCAN_PLUGIN_DIR' , trailingslashit( dirname(__FILE__) ) ); 25 25 define( 'SIXSCAN_PLUGIN_URL' , trailingslashit( plugins_url( basename ( dirname (__FILE__) ) ) ) ); 26 define( 'SIXSCAN_PLUGIN_DIRNAME' , basename( dirname ( __FILE__ ) ) ); 26 27 27 28 /* Platform type */ -
6scan-protection/trunk/admin/includes/common.php
r580294 r584844 64 64 define ( 'SIXSCAN_LOGIN_LOCKED_OUT_MINUTES' , 'login_locked_out_minutes' ); 65 65 define ( 'SIXSCAN_LOGIN_NOTIFY_ADMIN_EMAIL' , 'login_notify_admin_email' ); 66 67 define ( 'SIXSCAN_ANTISPAM_PROTECTION_ON_OPTION' , 'antispam_protection_on' );68 define ( 'SIXSCAN_ANTISPAM_DELETE_OLD_OPTION' , 'antispam_delete_old_spam' );69 66 70 67 define ( 'SIXSCAN_UPDATE_OK_RESPONSE_CODE', 200 ); … … 114 111 define ( 'SIXSCAN_ANALYTICS_OK_STRING', 'ok' ); 115 112 define ( 'SIXSCAN_ANALYTICS_FAIL_PREFIX_STRING', 'error_' ); 116 117 define( 'SIXSCAN_HTACCESS_FILE', ABSPATH . '/.htaccess' ); 118 define ( 'SIXSCAN_HTACCESS_6SCAN_GATE_FILE_NAME', '6scan-gate.php' );113 define ( 'SIXSCAN_HTACCESS_FILE', ABSPATH . '/.htaccess' ); 114 115 define ( 'SIXSCAN_HTACCESS_6SCAN_GATE_FILE_NAME', '6scan-gate.php' ); 119 116 120 117 define( 'SIXSCAN_ADMIN_ACCESS_COOKIE_NAME', 'sixscan_wpblog_admin' ); … … 126 123 127 124 /* If this script is included from outside, we will not have SIXSCAN_PLUGIN_DIR defined, but we do not really need it */ 128 if ( defined( 'SIXSCAN_PLUGIN_DIR' ) ){ 125 if ( defined( 'SIXSCAN_PLUGIN_DIR' ) ){ 126 129 127 define( 'SIXSCAN_HTACCESS_6SCAN', SIXSCAN_PLUGIN_DIR . '/data/.htaccess.dat' ); 128 function sixscan_common_get_src_htaccess( $is_direct = TRUE ){ 129 if ( $is_direct == TRUE ) 130 return SIXSCAN_HTACCESS_6SCAN; 131 132 global $wp_filesystem; 133 return $wp_filesystem->find_folder( SIXSCAN_HTACCESS_6SCAN ); 134 } 135 136 130 137 define( 'SIXSCAN_SIGNATURE_SRC', SIXSCAN_PLUGIN_DIR . '/data/' . SIXSCAN_COMM_SIGNATURE_FILENAME ); 138 function sixscan_common_get_signature_src( $is_direct = TRUE ){ 139 if ( $is_direct == TRUE ) 140 return SIXSCAN_SIGNATURE_SRC; 141 142 global $wp_filesystem; 143 return $wp_filesystem->find_folder( SIXSCAN_SIGNATURE_SRC ); 144 } 145 131 146 define( 'SIXSCAN_HTACCESS_6SCAN_GATE_SOURCE', SIXSCAN_PLUGIN_DIR . '/data/' . SIXSCAN_HTACCESS_6SCAN_GATE_FILE_NAME ); 147 function sixscan_common_get_gate_src( $is_direct = TRUE ){ 148 if ( $is_direct == TRUE ) 149 return SIXSCAN_HTACCESS_6SCAN_GATE_SOURCE; 150 151 global $wp_filesystem; 152 return $wp_filesystem->find_folder( SIXSCAN_HTACCESS_6SCAN_GATE_SOURCE ); 153 } 132 154 define( 'SIXSCAN_ANALYZER_LOG_FILEPATH', SIXSCAN_PLUGIN_DIR . SIXSCAN_SECURITY_LOG_FILENAME ); 133 155 } 134 156 135 define( 'SIXSCAN_HTACCESS_6SCAN_GATE_DEST', ABSPATH . SIXSCAN_HTACCESS_6SCAN_GATE_FILE_NAME ); 136 define( 'SIXSCAN_SIGNATURE_DEST', ABSPATH . SIXSCAN_COMM_SIGNATURE_FILENAME ); 157 137 158 define( 'SIXSCAN_COMMON_DASHBOARD_URL', 'six-scan-dashboard' ); 138 159 define( 'SIXSCAN_COMMON_SETTINGS_URL', 'six-scan-settings' ); … … 159 180 EOD 160 181 ); 182 183 184 function sixscan_common_get_htaccess_file_path( $is_direct ){ 185 if ( $is_direct == TRUE ) 186 return SIXSCAN_HTACCESS_FILE; 187 188 global $wp_filesystem; 189 return $wp_filesystem->abspath() . '.htaccess'; 190 } 191 192 function sixscan_common_get_htaccess_dest_path( $is_direct = TRUE ){ 193 if ( $is_direct == TRUE ) 194 return ABSPATH . SIXSCAN_HTACCESS_6SCAN_GATE_FILE_NAME; 195 196 global $wp_filesystem; 197 return $wp_filesystem->abspath() . SIXSCAN_HTACCESS_6SCAN_GATE_FILE_NAME; 198 } 199 200 function sixscan_common_get_signature_dest_path( $is_direct = TRUE ){ 201 if ( $is_direct == TRUE ) 202 return ABSPATH . SIXSCAN_COMM_SIGNATURE_FILENAME; 203 204 global $wp_filesystem; 205 return $wp_filesystem->abspath() . SIXSCAN_COMM_SIGNATURE_FILENAME; 206 } 161 207 162 208 function sixscan_common_set_site_id( $site_id ){ … … 379 425 $submission_data .= "Is access through proxy: $is_through_proxy\n"; 380 426 381 $htaccess_contents = file_get_contents( SIXSCAN_HTACCESS_FILE);427 $htaccess_contents = file_get_contents( sixscan_common_get_htaccess_file_path( TRUE ) ); 382 428 if ( $htaccess_contents == FALSE ) 383 429 $htaccess_contents = "Empty"; … … 409 455 global $wp_filesystem; 410 456 411 $tmp_fname = tempnam( untrailingslashit( $dir_name ) , 'sixscantmp_');457 $tmp_fname = untrailingslashit( $dir_name ) . 'sixscantmp_'; 412 458 413 459 $ftmp_result = $wp_filesystem->put_contents( $tmp_fname , 'write_test' ); … … 417 463 418 464 /* Cleanup */ 419 unlink( $tmp_fname );465 $wp_filesystem->delete( $tmp_fname ); 420 466 return TRUE; 421 467 } -
6scan-protection/trunk/admin/includes/htaccess.php
r580294 r584844 7 7 $ret_error = array(); 8 8 9 $htaccess_sixscan = trim ( $wp_filesystem->get_contents( SIXSCAN_HTACCESS_6SCAN . $htaccess_sixscan_version ) ) . "\n\n"; 10 11 if ( ! $wp_filesystem->copy( SIXSCAN_HTACCESS_6SCAN_GATE_SOURCE, SIXSCAN_HTACCESS_6SCAN_GATE_DEST , TRUE , 0755 ) ) { 12 $ret_error[ 'user_message' ] = 'Failed copying ' . SIXSCAN_HTACCESS_6SCAN_GATE_FILE_NAME . ' during installation'; 9 $is_direct = ( $wp_filesystem->method == 'direct' ); 10 $local_htaccess_path = sixscan_common_get_htaccess_file_path( $is_direct ); 11 $htaccess_sixscan = trim ( $wp_filesystem->get_contents( sixscan_common_get_src_htaccess( $is_direct ) . $htaccess_sixscan_version ) ) . "\n\n"; 12 13 if ( ! $wp_filesystem->copy( sixscan_common_get_gate_src( $is_direct ) , sixscan_common_get_htaccess_dest_path( $is_direct ) , TRUE , 0755 ) ) { 14 $ret_error[ 'user_message' ] = 'Failed copying ' . sixscan_common_get_htaccess_dest_path( $is_direct ) . ' during installation'; 13 15 $ret_error[ 'short_description' ] = 'Failed copying htaccess during installation'; 14 16 return $ret_error; 15 17 } 16 18 17 if ( ! $wp_filesystem->copy( SIXSCAN_SIGNATURE_SRC, SIXSCAN_SIGNATURE_DEST, TRUE , 0755 ) ) {18 $ret_error[ 'user_message' ] = 'Failed copying ' . SIXSCAN_SIGNATURE_SRC. ' during installation';19 if ( ! $wp_filesystem->copy( sixscan_common_get_signature_src( $is_direct ), sixscan_common_get_signature_dest_path( $is_direct ) , TRUE , 0755 ) ) { 20 $ret_error[ 'user_message' ] = 'Failed copying ' . sixscan_common_get_signature_src( $is_direct ) . ' during installation'; 19 21 $ret_error[ 'short_description' ] = 'Failed copying signature during installation'; 20 22 return $ret_error; 21 23 } 22 24 23 if ( $wp_filesystem->exists( SIXSCAN_HTACCESS_FILE) ) {24 $htaccess_content = $wp_filesystem->get_contents( SIXSCAN_HTACCESS_FILE);25 if ( $wp_filesystem->exists( $local_htaccess_path ) ) { 26 $htaccess_content = $wp_filesystem->get_contents( $local_htaccess_path ); 25 27 $htaccess_sixscan .= preg_replace( '@# Created by 6Scan plugin(.*?)# End of 6Scan plugin@s' , '' , $htaccess_content ) ; 26 $wp_filesystem->delete( SIXSCAN_HTACCESS_FILE);28 $wp_filesystem->delete( $local_htaccess_path ); 27 29 } 28 30 29 if ( $wp_filesystem->put_contents( SIXSCAN_HTACCESS_FILE, $htaccess_sixscan ) === FALSE ){31 if ( $wp_filesystem->put_contents( $local_htaccess_path , $htaccess_sixscan ) === FALSE ){ 30 32 $ret_error[ 'user_message' ] = 'Failed opening htaccess during installation'; 31 33 $ret_error[ 'short_description' ] = 'Failed opening htaccess during installation'; … … 42 44 WP_Filesystem(); 43 45 46 $is_direct = ( $wp_filesystem->method == 'direct' ); 47 $local_htaccess_path = sixscan_common_get_htaccess_file_path( $is_direct ); 48 44 49 try { 45 if ( $wp_filesystem->exists( SIXSCAN_HTACCESS_FILE) ) {46 $htaccess_content = $wp_filesystem->get_contents( SIXSCAN_HTACCESS_FILE);50 if ( $wp_filesystem->exists( $local_htaccess_path ) ) { 51 $htaccess_content = $wp_filesystem->get_contents( $local_htaccess_path ); 47 52 $a = preg_replace( '@# Created by 6Scan plugin(.*?)# End of 6Scan plugin@s', '', $htaccess_content) ; 53 54 if ( $wp_filesystem->put_contents( $local_htaccess_path , $a ) === FALSE ) 55 throw new Exception('Failed to open htaccess during installation'); 48 56 } 49 50 if ( $wp_filesystem->put_contents( SIXSCAN_HTACCESS_FILE , $a ) === FALSE )51 throw new Exception('Failed to open htaccess during installation');52 53 if ( filesize( SIXSCAN_HTACCESS_FILE ) == 1 )54 $wp_filesystem->delete( SIXSCAN_HTACCESS_FILE );55 57 56 if ( $wp_filesystem->exists( SIXSCAN_HTACCESS_6SCAN_GATE_DEST) )57 $wp_filesystem->delete( SIXSCAN_HTACCESS_6SCAN_GATE_DEST);58 if ( $wp_filesystem->exists( sixscan_common_get_htaccess_dest_path( $is_direct ) ) ) 59 $wp_filesystem->delete( sixscan_common_get_htaccess_dest_path( $is_direct ) ); 58 60 59 if ( $wp_filesystem->exists( SIXSCAN_SIGNATURE_DEST) )60 $wp_filesystem->delete ( SIXSCAN_SIGNATURE_DEST) ;61 if ( $wp_filesystem->exists( sixscan_common_get_signature_dest_path( $is_direct ) ) ) 62 $wp_filesystem->delete ( sixscan_common_get_signature_dest_path( $is_direct ) ) ; 61 63 62 64 } catch( Exception $e ) { -
6scan-protection/trunk/admin/includes/installation.php
r580294 r584844 15 15 if ( sixscan_installation_wpfs_init( $tmp_key ) == FALSE) 16 16 return; 17 17 18 18 /* Run the install */ 19 19 $install_result = sixscan_installation_install( $tmp_key ); … … 117 117 118 118 /* Make sure we can create signature file and update the site's .htaccess file */ 119 if ( sixscan_common_test_dir_writable( ABSPATH) == FALSE ){119 if ( sixscan_common_test_dir_writable( $wp_filesystem->abspath() ) == FALSE ){ 120 120 $err_message = "6Scan Install <b>Error</b>: Failed creating signature file at Wordpress directory " . ABSPATH . SIXSCAN_COMM_SIGNATURE_FILENAME . 121 121 "<br/><br/>Please see <a href='http://codex.wordpress.org/Changing_File_Permissions' target='_blank'>this Wordpress article</a> for more information on how to add write permissions." . … … 339 339 define( 'FS_METHOD' , 'direct' ); 340 340 else if ( $wpfs_detect_try == 'ftpext' ) 341 define( 'FS_METHOD' , 'ftpext' ); 342 341 define( 'FS_METHOD' , 'ftpext' ); 343 342 if ( WP_Filesystem() ){ 344 343 $config_key = ""; -
6scan-protection/trunk/modules/signatures/update.php
r566110 r584844 66 66 global $wp_filesystem; 67 67 /* Prepare temporary names */ 68 $temp_upgrade_dir = get_temp_dir() . trailingslashit( "6scan_update" ); 69 $temp_zip_file = get_temp_dir() . "bguard.zip"; 70 68 $temp_upgrade_dir_local = trailingslashit( WP_CONTENT_DIR ) . trailingslashit( "6scan_update" ); 69 $temp_upgrade_dir = $wp_filesystem->wp_content_dir() . trailingslashit( "6scan_update" ); 70 $temp_zip_file_local = trailingslashit( WP_CONTENT_DIR ) . "bguard.zip"; 71 $temp_zip_file = $wp_filesystem->wp_content_dir() . "bguard.zip"; 72 71 73 /* Create temp directory for update */ 72 if ( ( $wp_filesystem->is_dir( $temp_upgrade_dir ) == FALSE ) && ( $wp_filesystem->mkdir( $temp_upgrade_dir ) == FALSE ) ) 74 if ( $wp_filesystem->exists( $temp_upgrade_dir ) ) 75 $wp_filesystem->delete ( $temp_upgrade_dir , TRUE ); 76 77 if ( ($wp_filesystem->is_dir( $temp_upgrade_dir ) == FALSE ) && ( $wp_filesystem->mkdir( $temp_upgrade_dir ) == FALSE ) ) 73 78 return "Failed creating temp directory for update at " . $temp_upgrade_dir; 74 79 75 /* Write the zip file */ 80 /* Write the zip file */ 81 if ( $wp_filesystem->exists( $temp_zip_file ) ) 82 $wp_filesystem->delete( $temp_zip_file ); 83 76 84 if ( $wp_filesystem->put_contents( $temp_zip_file , $zipped_program ) == FALSE ) 77 85 return "Failed writing file to " . $temp_zip_file; 78 86 79 /* unzip_file returns mixed on failure. It uses global $wp_filesystem */80 if ( unzip_file( $temp_zip_file , $temp_upgrade_dir ) !== TRUE )87 /* unzip_file returns mixed on failure. It uses global $wp_filesystem. */ 88 if ( unzip_file( $temp_zip_file_local , $temp_upgrade_dir ) !== TRUE ){ 81 89 return "unzip_file() from $temp_zip_file to $temp_upgrade_dir failed"; 90 } 82 91 83 92 /* Remove the no longer required zip file */ 84 93 $wp_filesystem->delete( $temp_zip_file ); 85 94 86 $plugin_main_directory = plugin_dir_path( __FILE__ ) . "../../"; 87 88 $temp_upgrade_dir_internal = sixscan_signatures_update_find_plugin_dir( $temp_upgrade_dir ); 89 if ( $temp_upgrade_dir_internal == "") 90 return "Couldn't find plugin dir in the unzipped folder $temp_upgrade_dir"; 91 95 $plugin_main_directory = plugin_dir_path( __FILE__ ) . "../../"; 96 $plugin_main_directory = $wp_filesystem->wp_plugins_dir() . SIXSCAN_PLUGIN_DIRNAME; 97 98 $temp_upgrade_dir_internal = sixscan_signatures_update_find_plugin_dir( $temp_upgrade_dir_local ); 99 100 if ( $temp_upgrade_dir_internal == "" ) 101 return "Couldn't find plugin dir in the unzipped folder $temp_upgrade_dir_local"; 102 103 $temp_upgrade_dir_internal = untrailingslashit( $wp_filesystem->find_folder( $temp_upgrade_dir_internal ) ); 104 92 105 /* Now bulk copy the rest of files to their places: */ 93 106 sixscan_signatures_update_move_dir_recursive( $temp_upgrade_dir_internal , $plugin_main_directory ); 94 107 95 /* Remove the tmp directory */ 96 $wp_filesystem->delete ( $temp_upgrade_dir_internal ); 97 $wp_filesystem->delete ( $temp_upgrade_dir ); 108 /* Remove the tmp directory */ 109 $wp_filesystem->delete ( $temp_upgrade_dir , TRUE ); 98 110 99 111 return TRUE; … … 141 153 142 154 function sixscan_signatures_update_parse( $raw_data ) { 143 144 $signature_filename = ABSPATH . "/" . SIXSCAN_COMM_SIGNATURE_FILENAME; 155 global $wp_filesystem; 156 157 $signature_filename = $wp_filesystem->find_folder( ABSPATH ) . SIXSCAN_COMM_SIGNATURE_FILENAME; 145 158 $signature_filename_tmp = $signature_filename . ".tmp"; 146 159 $signature_offset = strpos( $raw_data , SIXSCAN_SIGNATURE_MULTIPART_DELIMITER ); 147 global $wp_filesystem;160 148 161 149 162 if ($signature_offset === FALSE) … … 189 202 global $wp_filesystem; 190 203 191 if ( file_exists( SIXSCAN_HTACCESS_FILE ) ) { 192 $htaccess_content = $wp_filesystem->get_contents( SIXSCAN_HTACCESS_FILE ); 204 $htaccess_fpath = sixscan_common_get_htaccess_file_path( $wp_filesystem->method == 'direct' ); 205 206 if ( $wp_filesystem->exists( $htaccess_fpath ) ) { 207 $htaccess_content = $wp_filesystem->get_contents( $htaccess_fpath ); 193 208 /* Remove old 6Scan signature contents */ 194 209 $new_content = trim( preg_replace( '@# Created by 6Scan plugin(.*?)# End of 6Scan plugin@s', '', $htaccess_content) ); … … 287 302 $htaccess_links .= $vuln_urls; 288 303 289 $tmp_htaccess_file = SIXSCAN_HTACCESS_FILE. ".tmp";304 $tmp_htaccess_file = $htaccess_fpath . ".tmp"; 290 305 291 306 $new_content = "# Created by 6Scan plugin … … 315 330 $wp_filesystem->put_contents( $tmp_htaccess_file , $new_content ); 316 331 317 if ( sixscan_signatures_update_copy_file( $tmp_htaccess_file , SIXSCAN_HTACCESS_FILE) == FALSE )318 return "Failed moving htaccess from $tmp_htaccess_file to " . SIXSCAN_HTACCESS_FILE;332 if ( sixscan_signatures_update_copy_file( $tmp_htaccess_file , $htaccess_fpath ) == FALSE ) 333 return "Failed moving htaccess from $tmp_htaccess_file to " . $htaccess_fpath; 319 334 320 335 return TRUE; … … 349 364 $wp_filesystem->mkdir( $dest ); 350 365 351 $file_list = scandir( $source ); 352 353 foreach( $file_list as $current_file ) { 366 //$file_list = scandir( $source ); 367 $file_list = $wp_filesystem->dirlist( $source ); 368 369 foreach( $file_list as $farray => $current_fname ) { 370 $current_file = $current_fname['name']; 371 354 372 if( $current_file == "." || $current_file == ".." ) { 355 373 /* skip "current" and "previous" directory */ … … 357 375 } 358 376 359 if( is_dir( $source . "/" . $current_file ) ) {377 if( $wp_filesystem->is_dir( $source . "/" . $current_file ) ) { 360 378 /* If it is directory , we have to call the recursion.*/ 361 379 sixscan_signatures_update_move_dir_recursive( $source . "/" . $current_file, $dest. "/" . $current_file ); … … 416 434 global $wp_filesystem; 417 435 436 $wp_filesystem->delete( $dst_file ); 418 437 return $wp_filesystem->move( $src_file , $dst_file , TRUE ); 419 438 } … … 449 468 return WP_Filesystem(); 450 469 } 451 470 452 471 $cfg_arr = unserialize( sixscan_common_decrypt_string( base64_decode ( $wp_fs_param ) , $config_key ) ); 453 472 454 $wp_fs = WP_Filesystem( $cfg_arr ); 455 if ( $wp_fs ){ 456 $wp_filesystem->connect(); 457 return $wp_fs; 458 } 473 $wp_fs = WP_Filesystem( $cfg_arr ); 459 474 460 475 return $wp_fs;
Note: See TracChangeset
for help on using the changeset viewer.