actifend_validEmail($actifend_email)) { $error = 0; $actifend_timestamp = time(); $actifend_asset_name = $_SERVER['SERVER_NAME']; $actifend_req = $actifend_email . $actifend_asset_name . $actifend_timestamp . ACTIFEND_ASSET_TYPE . ACTIFEND_SALT2; $actifend_reqhash = hash_hmac('sha512', $actifend_req, ACTIFEND_SALT1); $payloadArray = array(); $payloadArray["ACTIFEND_EMAIL"] = $actifend_email; $payloadArray["ACTIFEND_ASSET_NAME"] = $actifend_asset_name; $payloadArray["ACTIFEND_ASSET_TYPE"] = ACTIFEND_ASSET_TYPE; $payloadArray["ACTIFEND_FQDN"] = get_site_url(); // ZIP extension check for backup and restore features if (!extension_loaded('zip')) $payloadArray['ZIP_ENABLED'] = 'false'; else $payloadArray['ZIP_ENABLED'] = 'true'; // check file privileges for restore feature $utilityObj->check_file_privileges(); if (get_option('FilePrivilegesInsufficient') === 0) $payloadArray['FILE_PRIVILEGES_INSUFFICIENT'] = 'false'; else $payloadArray['FILE_PRIVILEGES_INSUFFICIENT'] = 'true'; debug_log("Low File Privileges: " . $payloadArray['FILE_PRIVILEGES_INSUFFICIENT']); $actifend_result = $this->actifend_register(ACTIFEND_REGISTER_END_POINT, ACTIFEND_SALT2, $actifend_reqhash, $payloadArray); $RESULT = json_decode($actifend_result); $OUT = @json_decode($RESULT->output); if (empty($OUT)) { $ERROR_MSG = "ERROR: Received invalid response from server. Please try again after sometime"; } else { $asset_id = $OUT->Result; $response_code = $OUT->ResponseCode; if ($utilityObj->actifend_isValidAssetId($asset_id, $response_code)) { $last_checked = date("Y-m-d H:i:s"); global $wpdb; $actifend_optin = 1; $actifend_table_name = $wpdb->prefix . ACTIFEND_TABLE_NAME; $wpdb->insert($actifend_table_name, array("asset_id" => $asset_id, "actifend_email" => $actifend_email, "actifend_optin" => $actifend_optin, "last_checked" => $last_checked) ); debug_log("Actifend Registration Completed!"); $utilityObj->actifend_pluginInstallation_log(); update_option('actifendActivated', 1); } else { $ERROR_MSG = "ERROR: Received invalid asset_id ($asset_id). Please try again after sometime"; } } } // Step 3 of 3 // this would also display the error messages in ERROR_MSG $actifend_dir = plugin_dir_path( __FILE__ ); $utilityObj->get_asset_status(get_site_url(), $actifend_email); $app_activated = get_option('mapp_activated'); if ($app_activated == 1) require_once(trailingslashit($actifend_dir) . "done.php"); else require_once(trailingslashit($actifend_dir) . "store.php"); debug_log("Actifend Plugin Activated."); // send the output buffers and turn off ob_end_flush(); } catch (Exception $e) { debug_log($e->getMessage()); return false; } } /** * autoRegisterTrial * register the plugin automatically with just the public url * get the asset id from the endpoint */ public function autoRegisterTrial() { try { $utilityObj = new Utility; $error = 0; $actifend_timestamp = time(); $actifend_asset_name = $_SERVER['SERVER_NAME']; $actifend_req = $actifend_asset_name . $actifend_timestamp . ACTIFEND_ASSET_TYPE . ACTIFEND_SALT2; $actifend_reqhash = hash_hmac('sha512', $actifend_req, ACTIFEND_SALT1); $payloadArray = array(); $payloadArray["ACTIFEND_ASSET_NAME"] = $actifend_asset_name; $payloadArray["ACTIFEND_ASSET_TYPE"] = ACTIFEND_ASSET_TYPE; $payloadArray["ACTIFEND_FQDN"] = get_site_url(); // ZIP extension check for backup and restore features if (!extension_loaded('zip')) $payloadArray['ZIP_ENABLED'] = 'false'; else $payloadArray['ZIP_ENABLED'] = 'true'; // check file privileges for restore feature $utilityObj->check_file_privileges(); if (get_option('FilePrivilegesInsufficient') === 0) $payloadArray['FILE_PRIVILEGES_INSUFFICIENT'] = 'false'; else $payloadArray['FILE_PRIVILEGES_INSUFFICIENT'] = 'true'; debug_log("Low File Privileges: " . $payloadArray['FILE_PRIVILEGES_INSUFFICIENT']); $actifend_result = $this->actifend_register(ACTIFEND_REGISTER_END_POINT, ACTIFEND_SALT2, $actifend_reqhash, $payloadArray); $RESULT = json_decode($actifend_result); $OUT = @json_decode($RESULT->output); if (empty($OUT)) { $ERROR_MSG = "ERROR: Received invalid response from server. Please try again after sometime"; } else { // If Result is an object then it should be properly dealt with if (is_object($OUT->Result)) { $asset_id = ($OUT->Result->asset_id); debug_log("Asset ID: " . $asset_id); $isoList = $OUT->Result->iso; # Check if the admin is in the iso list $admin_email = sha1(get_bloginfo('admin_email')); if (in_array($admin_email, $isoList)) { $is_registered = true; debug_log("Admin email is already registered with Actifend."); } else { $is_registered = false; debug_log("Admin email is NOT registered with Actifend."); } $mappActivated = $OUT->Result->mapp_activated; if ($mappActivated === 1) update_option('mapp_activated', 0); else update_option('mapp_activated', 1); } else { $asset_id = $OUT->Result; $is_registered = false; } $response_code = $OUT->ResponseCode; if ($utilityObj->actifend_isValidAssetId($asset_id, $response_code)) { $last_checked = date("Y-m-d H:i:s"); global $wpdb; if ($is_registered) { $actifend_optin = 1; $admin_email = get_bloginfo('admin_email'); update_option('actifendActivated', 1); } else { $actifend_optin = 0; $admin_email = 'None'; update_option('actifendActivated', 0); } $actifend_table_name = $wpdb->prefix . ACTIFEND_TABLE_NAME; $wpdb->insert($actifend_table_name, array("asset_id" => $asset_id, "actifend_email" => $admin_email, "actifend_optin" => $actifend_optin, "last_checked" => $last_checked)); debug_log("Actifend Trial Registration Completed!"); $utilityObj->actifend_pluginInstallation_log(); } } debug_log("Actifend Plugin Activated but onboarding is not complete!"); } catch (Exception $e) { debug_log($e->getMessage()); return false; } } /** * actifend_register_step2 * Step 2: Update email with Actifend * @param assetid, email * @return 200 response */ public function actifend_register_step2($actifend_email) { try { $utilityObj = new Utility; if ($utilityObj->actifend_validEmail($actifend_email)) { $error = 0; $actifend_timestamp = time(); $actifend_asset_name = $_SERVER['SERVER_NAME']; $actifend_req = $actifend_email . $actifend_asset_name . $actifend_timestamp . ACTIFEND_ASSET_TYPE . ACTIFEND_SALT2; $actifend_reqhash = hash_hmac('sha512', $actifend_req, ACTIFEND_SALT1); $custom_headers = array('actifend_client_id' => ACTIFEND_SALT2, 'actifend_signature' => $actifend_reqhash); $result = $utilityObj->getActifendInfo(); if (isset($result->asset_id) && !empty($result->asset_id)) { $asset_id = $result->asset_id; } else { debug_log("No ASSET ID assigned .... "); return 'NO_ASSETID'; } $payloadArray = array('ACTIFEND_EMAIL' => $actifend_email, 'ACTIFEND_ASSET_ID' => $asset_id); $actifend_result = $utilityObj->actifend_postViaCurl(ACTIFEND_REGISTER_END_POINT, json_encode($payloadArray), "PATCH", $custom_headers); $RESULT = json_decode($actifend_result); $OUT = @json_decode($RESULT->output); if (empty($OUT)) { $ERROR_MSG = "ERROR: Received invalid response from server. Please try again after sometime"; } else { if ($OUT->ResponseCode == '2000') { $last_checked = date("Y-m-d H:i:s"); global $wpdb; $actifend_optin = 1; $last_checked = date("Y-m-d H:i:s"); $actifend_table_name = $wpdb->prefix . ACTIFEND_TABLE_NAME; $res = $wpdb->update($actifend_table_name, array("actifend_email" => $actifend_email, "actifend_optin" => $actifend_optin, "last_checked" => $last_checked), array("asset_id" => $asset_id)); if (false === $res) { debug_log("DB record not updated with email."); } debug_log("Actifend Registration Completed!"); $utilityObj->actifend_pluginInstallation_log(); update_option('actifendActivated', 1); } else { $ERROR_MSG = "ERROR: Received invalid asset_id ($OUT->Message). Please try again after sometime"; debug_log($ERROR_MSG); } } } // Step 3 of 3 // this would also display the error messages in ERROR_MSG $actifend_dir = plugin_dir_path( __FILE__ ); // This call will update the option $utilityObj->get_asset_status(get_site_url(), $actifend_email); $mapp_activated = get_option('mapp_activated'); if ($mapp_activated == 1) require_once(trailingslashit($actifend_dir) . "done.php"); else require_once(trailingslashit($actifend_dir) . "store.php"); debug_log("Actifend Plugin Step 2 completed"); // send the output buffers and turn off ob_end_flush(); } catch (Exception $e) { debug_log($e->getMessage()); return false; } } /** * actifend_register * * Send the client detail to the endpoint. * @param string $actifend_url endpoint url * @param string $actifend_h1 header used in url * @param string $actifend_h2 header info * @param string $actifend_params client detail. * @return string $return */ public function actifend_register ($actifend_url, $actifend_h1, $actifend_h2, $actifend_params) { try { $utilObj = new Utility; $custom_headers = array('actifend_client_id' => $actifend_h1, 'actifend_signature' => $actifend_h2); $response = $utilObj->actifend_postViaCurl($actifend_url, $actifend_params, 'POST', $custom_headers); return $response; } catch (Exception $e) { debug_log($e->getMessage()); return $e->getMessage(); } } } ?>