Plugin Directory

Changeset 1235366


Ignore:
Timestamp:
09/01/2015 12:02:09 PM (11 years ago)
Author:
samface
Message:

bugfix release v0.8.3

Location:
angry-creative-logger/trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • angry-creative-logger/trunk/classes/wp_cli.php

    r1214050 r1235366  
    4040        }
    4141
    42         if ( $assoc_args['force'] ) {
     42        if ( array_key_exists( 'force', $assoc_args ) && !empty( $assoc_args['force'] ) ) {
    4343            $force_inspect = true;
    4444        }
  • angry-creative-logger/trunk/plugin.php

    r1214702 r1235366  
    44Plugin URI: http://angrycreative.se
    55Description: Inspects and logs possible issues with your Wordpress installation.
    6 Version: 0.8.2
     6Version: 0.8.3
    77Author: Robin Björklund, Sammy Nordström, Angry Creative AB
    88*/
    99
    10 define( 'ACI_PLUGIN_VERSION', '0.8.2' );
     10define( 'ACI_PLUGIN_VERSION', '0.8.3' );
    1111
    1212define( 'ACI_PLUGIN_DIR', dirname( __FILE__ ) );
  • angry-creative-logger/trunk/readme.txt

    r1214702 r1235366  
    44Requires at least: 4.0
    55Tested up to: 4.2.4
    6 Stable tag: 0.8.2
     6Stable tag: 0.8.3
    77License: GPLv2 or later
    88License URI: http://www.gnu.org/licenses/gpl-2.0.html
  • angry-creative-logger/trunk/routines/file_permissions.php

    r1214702 r1235366  
    7171
    7272        if ( !is_array( self::$_options ) ) {
    73                 self::$_options = array();
    74             }
     73            self::$_options = array();
     74        }
    7575
    7676        if ( self::$_force_default_allowed_dirs ) {
     
    123123        }
    124124
     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
    125174    }
    126175
     
    129178        if ( defined( 'WP_CLI' ) && WP_CLI ) {
    130179
    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;
    155182            }
    156183
     
    165192        foreach($folders2check as $folder) {
    166193
    167             $folder_base = trim( str_replace( '/*', '', str_replace('//', '/', str_replace( trim( ABSPATH, '/' ) , '', $folder ) ) ), '/' );
    168194            $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                }
    172204            } 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                }
    174210            }
    175211
     
    182218
    183219            if ($recursive) {
    184                 if ( "/*" == $folder && in_array( "/*", self::$_options['allowed_dirs'] ) ) {
     220                if ( in_array( $folder, self::$_options['allowed_dirs'] ) ) {
    185221                    $allowed_dir = true;
    186222                } else if ( !empty( $folder_base ) ) {
     
    206242
    207243                    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.');
    209245                    }
    210246
     
    216252
    217253                    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.');
    219255                    }
    220256
     
    225261                AC_Inspector::log( $e->getMessage(), __CLASS__ );
    226262
     263                $bad_folder_perm = true;
     264
    227265                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();
    232272                        }
    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;
    237274                    }
    238                     $halt_on_error = false;
    239                 }
    240 
    241                 $bad_folder_perm = true;
     275                }
    242276
    243277            }
     
    258292
    259293                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();
    264300                        }
    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;
    269302                    }
    270                     $halt_on_error = false;
    271303                }
    272304
     
    287319
    288320                    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                        }
    290327                    }
    291328
     
    298335        if ( defined( 'WP_CLI' ) && WP_CLI ) {
    299336
    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;
    310344
    311345    }
     
    319353        $path = rtrim( $path, '/' );
    320354
    321         if ( is_link( $path ) ) {
     355        if ( !empty( $path ) && is_link( $path ) ) {
    322356            $path = realpath( readlink( $path ) );
     357        }
     358
     359        if ( empty( $path ) ) {
     360            return;
    323361        }
    324362
     
    374412                    }
    375413                    if ( $recursive || !is_dir( $fullpath ) ) {
    376                         if ( self::chown( $fullpath, $owner, $group, $recursive ) ) {
     414                        if ( false !== self::chown( $fullpath, $owner, $group, $recursive ) ) {
    377415                            if ( is_dir( $fullpath ) && $verbose ) {
    378416                                AC_Inspector::log( "Changed ownership of files in '$fullpath' to $ownership_str", __CLASS__, array( 'success' => true ) );
     
    431469        $path = rtrim( $path, '/' );
    432470
    433         if ( is_link( $path ) ) {
     471        if ( !empty( $path ) && is_link( $path ) ) {
    434472            $path = realpath( readlink( $path ) );
     473        }
     474
     475        if ( empty( $path ) ) {
     476            return;
    435477        }
    436478
     
    460502                    }
    461503                    if ( $recursive || !is_dir( $fullpath ) ) {
    462                         if ( self::chmod( $fullpath, $filemode, $dirmode, $recursive ) ) {
     504                        if ( false !== self::chmod( $fullpath, $filemode, $dirmode, $recursive ) ) {
    463505                            if ( is_dir( $fullpath ) && $verbose ) {
    464506                                AC_Inspector::log( "Applied filemode '$filemode_str' on files in '$fullpath'", __CLASS__, array( 'success' => true ) );
     
    534576        }
    535577
    536         if ( !self::chown( self::$_real_abspath, $owner, $group, true, true ) ) {
     578        if ( false === self::chown( self::$_real_abspath, $owner, $group, true, true ) ) {
    537579            if ( defined( 'WP_CLI' ) && WP_CLI ) {
    538580                WP_CLI::confirm( "There where errors while trying to set file ownerships (chown), proceed with setting file permissions (chmod) anyway?" );
     
    542584        }
    543585
    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        }
    545589
    546590        foreach(self::$_options['allowed_dirs'] as $folder) {
     
    548592            $folder_base = trim( str_replace( '/*', '', str_replace('//', '/', str_replace( self::$_real_abspath , '', $folder ) ) ), '/' );
    549593
    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                }
    552601            } 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                }
    554607            }
    555608
  • angry-creative-logger/trunk/routines/site_visibility.php

    r1214050 r1235366  
    109109
    110110            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__ );
    114114            }
    115115
Note: See TracChangeset for help on using the changeset viewer.