Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sets up feature. WIP #103

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions src/alley/wp/alleyvate/features/class-limit-xmlrpc-access.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php
/**
* Class file for Limit_Xmlrpc_access
*
* (c) Alley <info@alley.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @package wp-alleyvate
*/

namespace Alley\WP\Alleyvate\Features;

use Alley\WP\Types\Feature;

final class Limit_Xmlrpc_Access implements Feature {
public function boot(): void {
// Init whatever we want to do here.

// Prior art Copypasta'd from https://github.com/alleyinteractive/national-review/blob/production/mu-plugins/xmlrpc.php.
// Probably need to pull this into its own function.
if ( empty( $_SERVER['REMOTE_ADDR'] ) ) {
return false;
}

$jetpack_ips = get_transient( 'jetpack_ips' );

if ( false === $jetpack_ips ) {
$jetpack_ips = \Mantle\Http_Client\Factory::get( 'https://jetpack.com/ips-v4.json' )->json();

set_transient(
'jetpack_ips',
$jetpack_ips,
is_array( $jetpack_ips ) ? WEEK_IN_SECONDS : HOUR_IN_SECONDS, // Lower TTL for error in response.
);
}

if ( empty( $jetpack_ips ) || ! is_array( $jetpack_ips ) ) {
return false;
}

if ( IpUtils::checkIp( $_SERVER['REMOTE_ADDR'], $jetpack_ips ) ) {
return true;
}

return isset( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ? IpUtils::checkIp( $_SERVER['HTTP_X_FORWARDED_FOR'], $jetpack_ips ) : false;
}
}
4 changes: 4 additions & 0 deletions src/alley/wp/alleyvate/load.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ function load(): void {
'disable_block_editor_rest_api_preload_paths',
new Features\Disable_Block_Editor_Rest_Api_Preload_Paths(),
),
new Feature(
'limit_xmlrpc_access',
new Features\Limit_Xmlrpc_Access(),
),
);

$plugin->boot();
Expand Down
Loading