diff --git a/_inc/client/components/jetpack-notices/state-notices.jsx b/_inc/client/components/jetpack-notices/state-notices.jsx
index 71fc4a83e0678..d1a047007b0dc 100644
--- a/_inc/client/components/jetpack-notices/state-notices.jsx
+++ b/_inc/client/components/jetpack-notices/state-notices.jsx
@@ -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',
@@ -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' :
@@ -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 = (
+
+ { __( 'Learn More' ) }
+
+ );
+ 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;
@@ -217,14 +231,16 @@ const JetpackStateNotices = React.createClass( {
const messageData = this.getMessageFromKey( message );
noticeText = messageData[0];
status = messageData[1];
+ action = messageData[2]
}
return (
- { noticeText }
+ { action }
);
},
diff --git a/class.jetpack.php b/class.jetpack.php
index e55632132243d..18f5fec918709 100644
--- a/class.jetpack.php
+++ b/class.jetpack.php
@@ -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
diff --git a/modules/protect.php b/modules/protect.php
index 12a2917e30059..2a6e34eb261e3 100644
--- a/modules/protect.php
+++ b/modules/protect.php
@@ -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.
diff --git a/modules/protect/shared-functions.php b/modules/protect/shared-functions.php
index 443bab9e96a0a..9431eb5598d6d 100644
--- a/modules/protect/shared-functions.php
+++ b/modules/protect/shared-functions.php
@@ -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;
@@ -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 ) ) {