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

Fix Protect for OVH #5866

Merged
merged 5 commits into from
Dec 13, 2016
Merged
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
28 changes: 22 additions & 6 deletions _inc/client/components/jetpack-notices/state-notices.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
getJetpackStateNoticesMessageCode,
getJetpackStateNoticesErrorDescription
} from 'state/jetpack-notices';
import NoticeAction from 'components/notice/notice-action.jsx';

const JetpackStateNotices = React.createClass( {
displayName: 'JetpackStateNotices',
Expand Down Expand Up @@ -160,8 +161,9 @@ const JetpackStateNotices = React.createClass( {
},

getMessageFromKey: function( key ) {
let message = '';
let status = 'is-info';
let message = '',
status = 'is-info',
action;
switch ( key ) {
// This is the message that is shown on first page load after a Jetpack plugin update.
case 'modules_activated' :
Expand All @@ -188,17 +190,29 @@ const JetpackStateNotices = React.createClass( {
message = __( "You're fueled up and ready to go." );
status = 'is-success';
break;
case 'protect_misconfigured_ip' :
message = __( "Your server is misconfigured, which means that Jetpack Protect is unable to effectively protect your site." );
status = 'is-info';
action = (
<NoticeAction
href="https://jetpack.com/support/security/troubleshooting-protect/"
>
{ __( 'Learn More' ) }
</NoticeAction>
);
break;

default:
message = key;
}

return [ message, status ];
return [ message, status, action ];
},

renderContent: function() {
let status = 'is-info';
let noticeText = '';
let status = 'is-info',
noticeText = '',
action;
const error = this.props.jetpackStateNoticesErrorCode,
message = this.props.jetpackStateNoticesMessageCode;

Expand All @@ -217,14 +231,16 @@ const JetpackStateNotices = React.createClass( {
const messageData = this.getMessageFromKey( message );
noticeText = messageData[0];
status = messageData[1];
action = messageData[2]
}

return (
<SimpleNotice
status={ status }
onDismissClick={ this.dismissJetpackStateNotice }
text={ noticeText }
>
{ noticeText }
{ action }
</SimpleNotice>
);
},
Expand Down
10 changes: 10 additions & 0 deletions class.jetpack.php
Original file line number Diff line number Diff line change
Expand Up @@ -2519,6 +2519,16 @@ public static function activate_module( $module, $exit = true, $redirect = true
}
}

// Protect won't work with mis-configured IPs
if ( 'protect' === $module ) {
include_once JETPACK__PLUGIN_DIR . 'modules/protect/shared-functions.php';
if ( ! jetpack_protect_get_ip() ) {
error_log( 'hello' );
Jetpack::state( 'message', 'protect_misconfigured_ip' );
return false;
}
}

// Check the file for fatal errors, a la wp-admin/plugins.php::activate
Jetpack::state( 'module', $module );
Jetpack::state( 'error', 'module_activation_failed' ); // we'll override this later if the plugin can be included without fatal error
Expand Down
9 changes: 9 additions & 0 deletions modules/protect.php
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,15 @@ function ip_is_whitelisted( $ip ) {
*/
function check_login_ability( $preauth = false ) {
$ip = jetpack_protect_get_ip();

// Server is misconfigured and we can't get an IP
if ( ! $ip && class_exists( 'Jetpack' ) ) {
Jetpack::deactivate_module( 'protect' );
ob_start();
Jetpack::state( 'message', 'protect_misconfigured_ip' );
ob_end_clean();
return true;
}

/**
* Short-circuit check_login_ability.
Expand Down
10 changes: 10 additions & 0 deletions modules/protect/shared-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,11 @@ function jetpack_protect_get_ip() {
} else {
$ip = $_SERVER['REMOTE_ADDR'];
}

if ( ! $ip ) {
return false;
}

$ips = explode( ',', $ip );
if ( ! isset( $segments ) || ! $segments ) {
$segments = 1;
Expand All @@ -193,6 +198,11 @@ function jetpack_protect_get_ip() {
* @return $ip IP.
*/
function jetpack_clean_ip( $ip ) {

// Some misconfigured servers give back extra info, which comes after "unless"
$ips = explode( ' unless ', $ip );
$ip = $ips[0];

$ip = trim( $ip );
// Check for IPv4 IP cast as IPv6.
if ( preg_match( '/^::ffff:(\d+\.\d+\.\d+\.\d+)$/', $ip, $matches ) ) {
Expand Down