diff --git a/Source/lang/strings_english.txt b/Source/lang/strings_english.txt index 8a7ca47..ca8573f 100644 --- a/Source/lang/strings_english.txt +++ b/Source/lang/strings_english.txt @@ -65,6 +65,7 @@ $s_plugin_Source_import_stats = 'Imported %s changesets, %s files, and %s bug references.'; $s_plugin_Source_invalid_checkin_url = 'Invalid remote check-in address'; +$s_plugin_Source_invalid_import_url = 'Invalid remote import address'; $s_plugin_Source_invalid_repo = 'Invalid repository name'; $s_plugin_Source_invalid_changeset = 'Changeset information could not be loaded'; diff --git a/Source/pages/repo_import_latest.php b/Source/pages/repo_import_latest.php index b045317..362b432 100644 --- a/Source/pages/repo_import_latest.php +++ b/Source/pages/repo_import_latest.php @@ -11,17 +11,70 @@ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. -# TODO: Implement cron-able usage similar to checkin.php? +$t_address = $_SERVER['REMOTE_ADDR']; +$t_valid = false; -access_ensure_global_level( plugin_config_get( 'manage_threshold' ) ); +# Always allow the same machine to import +if ( '127.0.0.1' == $t_address || '127.0.1.1' == $t_address ) { + $t_valid = true; +} + +# Allow a logged-in user to import +if ( !$t_valid && auth_is_user_authenticated() ) { + access_ensure_global_level( plugin_config_get( 'manage_threshold' ) ); + helper_ensure_confirmed( plugin_lang_get( 'ensure_import_latest' ), plugin_lang_get( 'import_latest' ) ); + + $t_valid = true; +} + +helper_begin_long_process(); + +# Check for allowed remote IP/URL addresses +if ( !$t_valid && ON == plugin_config_get( 'remote_import' ) ) { + $t_import_urls = unserialize( plugin_config_get( 'import_urls' ) ); + preg_match( '/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/', $t_address, $t_address_matches ); + + foreach ( $t_import_urls as $t_url ) { + if ( $t_valid ) break; + + $t_url = trim( $t_url ); + + if ( preg_match( '/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/', $t_url, $t_remote_matches ) ) { # IP + if ( $t_url == $t_address ) { + $t_valid = true; + break; + } + + $t_match = true; + for( $i = 1; $i <= 4; $i++ ) { + if ( $t_remote_matches[$i] == '0' || $t_address_matches[$i] == $t_remote_matches[$i] ) { + } else { + $t_match = false; + break; + } + } + + $t_valid = $t_match; + + } else { + $t_ip = gethostbyname( $t_url ); + if ( $t_ip == $t_address ) { + $t_valid = true; + break; + } + } + } +} + +# Not validated by this point gets the boot! +if ( !$t_valid ) { + die( plugin_lang_get( 'invalid_import_url' ) ); +} $f_repo_id = gpc_get_string( 'id' ); $t_repo = SourceRepo::load( $f_repo_id ); -helper_ensure_confirmed( plugin_lang_get( 'ensure_import_latest' ), plugin_lang_get( 'import_latest' ) ); -helper_begin_long_process(); - html_page_top1(); html_page_top2();