Changeset 1235366
- Timestamp:
- 09/01/2015 12:02:09 PM (11 years ago)
- Location:
- angry-creative-logger/trunk
- Files:
-
- 5 edited
-
classes/wp_cli.php (modified) (1 diff)
-
plugin.php (modified) (1 diff)
-
readme.txt (modified) (1 diff)
-
routines/file_permissions.php (modified) (18 diffs)
-
routines/site_visibility.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
angry-creative-logger/trunk/classes/wp_cli.php
r1214050 r1235366 40 40 } 41 41 42 if ( $assoc_args['force']) {42 if ( array_key_exists( 'force', $assoc_args ) && !empty( $assoc_args['force'] ) ) { 43 43 $force_inspect = true; 44 44 } -
angry-creative-logger/trunk/plugin.php
r1214702 r1235366 4 4 Plugin URI: http://angrycreative.se 5 5 Description: Inspects and logs possible issues with your Wordpress installation. 6 Version: 0.8. 26 Version: 0.8.3 7 7 Author: Robin Björklund, Sammy Nordström, Angry Creative AB 8 8 */ 9 9 10 define( 'ACI_PLUGIN_VERSION', '0.8. 2' );10 define( 'ACI_PLUGIN_VERSION', '0.8.3' ); 11 11 12 12 define( 'ACI_PLUGIN_DIR', dirname( __FILE__ ) ); -
angry-creative-logger/trunk/readme.txt
r1214702 r1235366 4 4 Requires at least: 4.0 5 5 Tested up to: 4.2.4 6 Stable tag: 0.8. 26 Stable tag: 0.8.3 7 7 License: GPLv2 or later 8 8 License URI: http://www.gnu.org/licenses/gpl-2.0.html -
angry-creative-logger/trunk/routines/file_permissions.php
r1214702 r1235366 71 71 72 72 if ( !is_array( self::$_options ) ) { 73 self::$_options = array();74 }73 self::$_options = array(); 74 } 75 75 76 76 if ( self::$_force_default_allowed_dirs ) { … … 123 123 } 124 124 125 self::$_options['allowed_dirs'] = array_filter( array_unique( self::$_options['allowed_dirs'] ) ); 126 127 } 128 129 private static function switch_to_httpd_user() { 130 131 if ( !defined( 'HTTPD_USER' ) ) { 132 AC_Inspector::log( 'Unable to determine the user your web server is running as, please define HTTPD_USER in your wp-config.php.', __CLASS__, array( 'error' => true ) ); 133 return false; 134 } 135 136 $httpd_usr = posix_getpwnam( HTTPD_USER ); 137 138 if ( !$httpd_usr ) { 139 AC_Inspector::log( 'Unable to get retrieve information about a user named ' . HTTPD_USER . ', please check your HTTPD_USER setting in the wp-config.php file.', __CLASS__, array( 'error' => true ) ); 140 return false; 141 } 142 143 $original_gid = posix_getegid(); 144 $original_uid = posix_geteuid(); 145 146 if ( !posix_setegid( $httpd_usr['gid'] ) || $httpd_usr['gid'] != posix_getegid() ) { 147 $groupinfo = posix_getgrgid( $httpd_usr['gid'] ); 148 AC_Inspector::log( 'Unable change the group of the current process to ' . $groupinfo['name'] . ' (gid: ' . $httpd_usr['gid'] . '), do you have the appropriate sudo privileges?', __CLASS__, array( 'error' => true ) ); 149 return false; 150 } 151 152 if ( !posix_seteuid( $httpd_usr['uid'] ) || $httpd_usr['uid'] != posix_geteuid() ) { 153 AC_Inspector::log( 'Unable change the owner of the current process to ' . HTTPD_USER . ' (uid: ' . $httpd_usr['uid'] . '), do you have the appropriate sudo privileges?', __CLASS__, array( 'error' => true ) ); 154 return false; 155 } 156 157 return true; 158 159 } 160 161 private static function restore_wp_cli_user() { 162 163 if ( !posix_setegid( $original_gid ) || $original_gid != posix_getegid() ) { 164 AC_Inspector::log( 'Unable to restore the group of the current process (gid: ' . $original_gid . '). File permissions will have to be repaired manually.', __CLASS__, array( 'error' => true ) ); 165 return false; 166 } 167 if ( !posix_seteuid( $original_uid ) || $original_uid != posix_geteuid() ) { 168 AC_Inspector::log( 'Unable to restore the owner of the current process (uid: ' . $original_uid . '). File permissions will have to be repaired manually.', __CLASS__, array( 'error' => true ) ); 169 return false; 170 } 171 172 return true; 173 125 174 } 126 175 … … 129 178 if ( defined( 'WP_CLI' ) && WP_CLI ) { 130 179 131 if ( !defined( 'HTTPD_USER' ) ) { 132 AC_Inspector::log( 'Unable to determine the user your web server is running as, please define HTTPD_USER in your wp-config.php.', __CLASS__, array( 'error' => true ) ); 133 return; 134 } 135 136 $httpd_usr = posix_getpwnam( HTTPD_USER ); 137 138 if ( !$httpd_usr ) { 139 AC_Inspector::log( 'Unable to get retrieve information about a user named ' . HTTPD_USER . ', please check your HTTPD_USER setting in the wp-config.php file.', __CLASS__, array( 'error' => true ) ); 140 return; 141 } 142 143 $original_gid = posix_getegid(); 144 $original_uid = posix_geteuid(); 145 146 if ( !posix_setegid( $httpd_usr['gid'] ) || $httpd_usr['gid'] != posix_getegid() ) { 147 $groupinfo = posix_getgrgid( $httpd_usr['gid'] ); 148 AC_Inspector::log( 'Unable change the group of the current process to ' . $groupinfo['name'] . ' (gid: ' . $httpd_usr['gid'] . '), do you have the appropriate sudo privileges?', __CLASS__, array( 'error' => true ) ); 149 return; 150 } 151 152 if ( !posix_seteuid( $httpd_usr['uid'] ) || $httpd_usr['uid'] != posix_geteuid() ) { 153 AC_Inspector::log( 'Unable change the owner of the current process to ' . HTTPD_USER . ' (uid: ' . $httpd_usr['uid'] . '), do you have the appropriate sudo privileges?', __CLASS__, array( 'error' => true ) ); 154 return; 180 if ( !self::switch_to_httpd_user() ) { 181 return false; 155 182 } 156 183 … … 165 192 foreach($folders2check as $folder) { 166 193 167 $folder_base = trim( str_replace( '/*', '', str_replace('//', '/', str_replace( trim( ABSPATH, '/' ) , '', $folder ) ) ), '/' );168 194 $recursive = substr($folder, -2) == "/*" ? true : false; 169 170 if ( is_link( self::$_real_abspath.'/'.$folder_base ) ) { 171 $resolved_folder_path = realpath( readlink( self::$_real_abspath.'/'.$folder_base ) ); 195 $folder_base = trim( str_replace( '/*', '', str_replace('//', '/', str_replace( self::$_real_abspath , '', $folder ) ) ), '/' ); 196 197 if ( !file_exists( self::$_real_abspath.'/'.$folder_base ) && file_exists( '/'.$folder_base ) ) { 198 $folder_base = '/'.$folder_base; 199 if ( is_link( $folder_base ) ) { 200 $resolved_folder_path = realpath( readlink( $folder_base ) ); 201 } else { 202 $resolved_folder_path = $folder_base; 203 } 172 204 } else { 173 $resolved_folder_path = self::$_real_abspath.'/'.$folder_base; 205 if ( is_link( self::$_real_abspath.'/'.$folder_base ) ) { 206 $resolved_folder_path = realpath( readlink( self::$_real_abspath.'/'.$folder_base ) ); 207 } else { 208 $resolved_folder_path = self::$_real_abspath.'/'.$folder_base; 209 } 174 210 } 175 211 … … 182 218 183 219 if ($recursive) { 184 if ( "/*" == $folder && in_array( "/*", self::$_options['allowed_dirs'] ) ) {220 if ( in_array( $folder, self::$_options['allowed_dirs'] ) ) { 185 221 $allowed_dir = true; 186 222 } else if ( !empty( $folder_base ) ) { … … 206 242 207 243 if ( $allowed_dir ) { 208 throw new Exception('Was not able to create a file in allowed folder `' . $ folder_base. '`. Check your file permissions.');244 throw new Exception('Was not able to create a file in allowed folder `' . $resolved_folder_path . '`. Check your file permissions.'); 209 245 } 210 246 … … 216 252 217 253 if ( !$allowed_dir ) { 218 throw new Exception('Was able to create a file in disallowed folder `' . $ folder_base. '`. Check your file permissions.');254 throw new Exception('Was able to create a file in disallowed folder `' . $resolved_folder_path . '`. Check your file permissions.'); 219 255 } 220 256 … … 225 261 AC_Inspector::log( $e->getMessage(), __CLASS__ ); 226 262 263 $bad_folder_perm = true; 264 227 265 if ( defined( 'WP_CLI' ) && WP_CLI && $halt_on_error ) { 228 $response = cli\choose( "Bad file permissions detected, continue the inspection", $choices = 'yn', $default = 'n' ); 229 if ( $response !== 'y' ) { 230 if ( !posix_setegid( $original_gid ) || $original_gid != posix_getegid() ) { 231 AC_Inspector::log( 'Unable to restore the group of the current process (gid: ' . $original_gid . '). File permissions will have to be repaired manually.', __CLASS__, array( 'error' => true ) ); 266 $response = cli\choose( "Bad permissions detected, continue inspecting file permissions", $choices = 'yn', $default = 'n' ); 267 if ( $response == 'y' ) { 268 $halt_on_error = false; 269 } else { 270 if ( defined( 'WP_CLI' ) && WP_CLI ) { 271 self::restore_wp_cli_user(); 232 272 } 233 if ( !posix_seteuid( $original_uid ) || $original_uid != posix_geteuid() ) { 234 AC_Inspector::log( 'Unable to restore the owner of the current process (uid: ' . $original_uid . '). File permissions will have to be repaired manually.', __CLASS__, array( 'error' => true ) ); 235 } 236 return; 273 return false; 237 274 } 238 $halt_on_error = false; 239 } 240 241 $bad_folder_perm = true; 275 } 242 276 243 277 } … … 258 292 259 293 if ( defined( 'WP_CLI' ) && WP_CLI && $bad_file_perm && $halt_on_error ) { 260 $response = cli\choose( "Bad file permissions detected, continue the inspection", $choices = 'yn', $default = 'n' ); 261 if ( $response !== 'y' ) { 262 if ( !posix_setegid( $original_gid ) || $original_gid != posix_getegid() ) { 263 AC_Inspector::log( 'Unable to restore the group of the current process (gid: ' . $original_gid . '). File permissions will have to be repaired manually.', __CLASS__, array( 'error' => true ) ); 294 $response = cli\choose( "Bad permissions detected, continue inspecting file permissions", $choices = 'yn', $default = 'n' ); 295 if ( $response == 'y' ) { 296 $halt_on_error = false; 297 } else { 298 if ( defined( 'WP_CLI' ) && WP_CLI ) { 299 self::restore_wp_cli_user(); 264 300 } 265 if ( !posix_seteuid( $original_uid ) || $original_uid != posix_geteuid() ) { 266 AC_Inspector::log( 'Unable to restore the owner of the current process (uid: ' . $original_uid . '). File permissions will have to be repaired manually.', __CLASS__, array( 'error' => true ) ); 267 } 268 return; 301 return false; 269 302 } 270 $halt_on_error = false;271 303 } 272 304 … … 287 319 288 320 if ( is_array($subfolders) && count($subfolders) > 0 && !empty($subfolders[0]) ) { 289 self::inspect( $subfolders, $halt_on_error ); 321 if ( false === self::inspect( $subfolders, $halt_on_error ) ) { 322 if ( defined( 'WP_CLI' ) && WP_CLI ) { 323 self::restore_wp_cli_user(); 324 } 325 return false; 326 } 290 327 } 291 328 … … 298 335 if ( defined( 'WP_CLI' ) && WP_CLI ) { 299 336 300 if ( !posix_setegid( $original_gid ) || $original_gid != posix_getegid() ) { 301 AC_Inspector::log( 'Unable to restore the group of the current process (gid: ' . $original_gid . '). File permissions will have to be repaired manually.', __CLASS__, array( 'error' => true ) ); 302 } 303 if ( !posix_seteuid( $original_uid ) || $original_uid != posix_geteuid() ) { 304 AC_Inspector::log( 'Unable to restore the owner of the current process (uid: ' . $original_uid . '). File permissions will have to be repaired manually.', __CLASS__, array( 'error' => true ) ); 305 } 306 307 } 308 309 return; 337 if ( !self::restore_wp_cli_user() ) { 338 return false; 339 } 340 341 } 342 343 return true; 310 344 311 345 } … … 319 353 $path = rtrim( $path, '/' ); 320 354 321 if ( is_link( $path ) ) {355 if ( !empty( $path ) && is_link( $path ) ) { 322 356 $path = realpath( readlink( $path ) ); 357 } 358 359 if ( empty( $path ) ) { 360 return; 323 361 } 324 362 … … 374 412 } 375 413 if ( $recursive || !is_dir( $fullpath ) ) { 376 if ( self::chown( $fullpath, $owner, $group, $recursive ) ) {414 if ( false !== self::chown( $fullpath, $owner, $group, $recursive ) ) { 377 415 if ( is_dir( $fullpath ) && $verbose ) { 378 416 AC_Inspector::log( "Changed ownership of files in '$fullpath' to $ownership_str", __CLASS__, array( 'success' => true ) ); … … 431 469 $path = rtrim( $path, '/' ); 432 470 433 if ( is_link( $path ) ) {471 if ( !empty( $path ) && is_link( $path ) ) { 434 472 $path = realpath( readlink( $path ) ); 473 } 474 475 if ( empty( $path ) ) { 476 return; 435 477 } 436 478 … … 460 502 } 461 503 if ( $recursive || !is_dir( $fullpath ) ) { 462 if ( self::chmod( $fullpath, $filemode, $dirmode, $recursive ) ) {504 if ( false !== self::chmod( $fullpath, $filemode, $dirmode, $recursive ) ) { 463 505 if ( is_dir( $fullpath ) && $verbose ) { 464 506 AC_Inspector::log( "Applied filemode '$filemode_str' on files in '$fullpath'", __CLASS__, array( 'success' => true ) ); … … 534 576 } 535 577 536 if ( !self::chown( self::$_real_abspath, $owner, $group, true, true ) ) {578 if ( false === self::chown( self::$_real_abspath, $owner, $group, true, true ) ) { 537 579 if ( defined( 'WP_CLI' ) && WP_CLI ) { 538 580 WP_CLI::confirm( "There where errors while trying to set file ownerships (chown), proceed with setting file permissions (chmod) anyway?" ); … … 542 584 } 543 585 544 self::chmod( self::$_real_abspath, 0644, 0755, true, true ); 586 if ( count( self::$_options['allowed_dirs'] ) != 1 || !in_array( '/*', self::$_options['allowed_dirs'] ) ) { 587 self::chmod( self::$_real_abspath, 0644, 0755, true, true ); 588 } 545 589 546 590 foreach(self::$_options['allowed_dirs'] as $folder) { … … 548 592 $folder_base = trim( str_replace( '/*', '', str_replace('//', '/', str_replace( self::$_real_abspath , '', $folder ) ) ), '/' ); 549 593 550 if ( is_link( self::$_real_abspath.'/'.$folder_base ) ) { 551 $resolved_folder_path = realpath( readlink( self::$_real_abspath.'/'.$folder_base ) ); 594 if ( !file_exists( self::$_real_abspath.'/'.$folder_base ) && file_exists( '/'.$folder_base ) ) { 595 $folder_base = '/'.$folder_base; 596 if ( is_link( $folder_base ) ) { 597 $resolved_folder_path = realpath( readlink( $folder_base ) ); 598 } else { 599 $resolved_folder_path = $folder_base; 600 } 552 601 } else { 553 $resolved_folder_path = self::$_real_abspath.'/'.$folder_base; 602 if ( is_link( self::$_real_abspath.'/'.$folder_base ) ) { 603 $resolved_folder_path = realpath( readlink( self::$_real_abspath.'/'.$folder_base ) ); 604 } else { 605 $resolved_folder_path = self::$_real_abspath.'/'.$folder_base; 606 } 554 607 } 555 608 -
angry-creative-logger/trunk/routines/site_visibility.php
r1214050 r1235366 109 109 110 110 if ( !self::is_visible() && true === self::should_be_visible() ) { 111 AC_Inspector::log( 'The site should be visible to search engines, please check your site visibility settings.', __CLASS__ , array( 'site_id' => $site_id ));112 } else if ( self::is_visible( $site_id ) && false === self::should_be_visible( $site_id) ) {113 AC_Inspector::log( 'The site should not be visible to search engines, please check your site visibility settings.', __CLASS__ , array( 'site_id' => $site_id ));111 AC_Inspector::log( 'The site should be visible to search engines, please check your site visibility settings.', __CLASS__ ); 112 } else if ( self::is_visible() && false === self::should_be_visible() ) { 113 AC_Inspector::log( 'The site should not be visible to search engines, please check your site visibility settings.', __CLASS__ ); 114 114 } 115 115
Note: See TracChangeset
for help on using the changeset viewer.