-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3fffbb3
commit c6a9f82
Showing
2 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
src/alley/wp/alleyvate/features/class-limit-xmlrpc-access.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
/** | ||
* Class file for Limit_Xmlrpc_access | ||
* | ||
* (c) Alley <[email protected]> | ||
* | ||
* 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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters