Skip to content

Commit

Permalink
Enhancements to check-redirects script: have an explicit list of excl…
Browse files Browse the repository at this point in the history
…usions, and skip anything that's a 'redirect' and not a 'redirect_asis' as those are not so easy to check
  • Loading branch information
bfenster committed Nov 6, 2024
1 parent 51e6284 commit 7167b24
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion tools/check-redirects.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@
$sites = parse( file( dirname(__DIR__) . '/maps/sites.map' ) );
$checks = [];

$exclude = [
'_/rsvp',
'_/google',
'_/google/calendar',
'_/google/docs',
'_/google/drive',
'_/google/sites'
];

$start = time();

$i = 0;
Expand All @@ -29,12 +38,14 @@
date_default_timezone_set( 'America/New_York' );
echo 'Checking all URLs. This will take about ' . $estimate . '. It is ' . date('H:i') . ' now (Eastern). No changes are made during these checks. Redirects to Check: ' . count($redirects) . "\n";
foreach( $redirects as $key => $url ) {
if ( in_array( $key, $exclude ) ) {
$checks[ $key ] = null;
}
$checks[ $key ] = check_url( $url );
if ( $i++ % 20 == 19 )
echo " " . $i . " done (" . (time() - $start) . " seconds)\n";
}


$i = 0;

// Note: we do not iterate over sites. This reporting is explicitly for redirects.
Expand All @@ -43,6 +54,11 @@
$i++;
$counter = '[' . str_pad( $i, 3, ' ', STR_PAD_LEFT ) . '/' . str_pad( count($redirects), 3, ' ', STR_PAD_LEFT ) . '] ';

if ( in_array( $key, $exclude ) ) {
echo $counter . $key . " - Excluded from checking\n";
continue;
}

if ( !isset( $sites[ $key ] ) ) {
echo $counter . $key . "\n";
echo " Found in redirects.map but not in sites.map\n";
Expand All @@ -66,6 +82,11 @@

$check = $checks[ $key ];
if ( $check ) {
if ( $sites[ $key ] === 'redirect' ) {
echo $counter . $key . " - This is a 'redirect' not a 'redirect_asis'. Skipping.\n";
continue;
}

if ( preg_match( '/Second order redirect: (.*)$/', $check, $match ) ) {
if ( $match[1] == $url . '/' || str_replace( 'http://', 'https://', $url ) == $match[1] ) {
// Automatically replace when it's just about a trailing slash or HTTPS
Expand Down Expand Up @@ -159,6 +180,8 @@ function check_url( $url ) {
return null; // Second-order redirects are expected for these URLs.
if ( stristr( $redirect, '/wp-app/shibboleth/' ) )
return null; // Second-order redirects are expected for these URLs.
if ( stristr( $redirect, '/Shibboleth.sso/Login/' ) )
return null; // Second-order redirects are expected for these URLs.

return 'Second order redirect: ' . $redirect;
}
Expand Down

0 comments on commit 7167b24

Please sign in to comment.