-
-
Notifications
You must be signed in to change notification settings - Fork 5
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
mohamedhk2
committed
Aug 24, 2023
0 parents
commit 88da501
Showing
6 changed files
with
173 additions
and
0 deletions.
There are no files selected for viewing
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,3 @@ | ||
.gitattributes export-ignore | ||
.gitignore export-ignore | ||
README.md export-ignore |
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,2 @@ | ||
/.idea | ||
/Patcher.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,3 @@ | ||
# WP Cerber Security Activator | ||
|
||
WP Cerber Security, Anti-spam & Malware Scan Plugin Activator |
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,92 @@ | ||
<?php | ||
/** | ||
* Requires at least: 3.1.0 | ||
* Requires PHP: 7.1 | ||
*/ | ||
if ( ! function_exists( 'is_plugin_active' ) ) { | ||
require_once ABSPATH . 'wp-admin/includes/plugin.php'; | ||
} | ||
if ( ! function_exists( 'wp_get_current_user' ) ) { | ||
require_once( ABSPATH . 'wp-includes/pluggable.php' ); | ||
} | ||
if ( ! function_exists( 'is_plugin_installed' ) ) { | ||
function is_plugin_installed( $plugin ): bool { | ||
$installed_plugins = get_plugins(); | ||
|
||
return isset( $installed_plugins[ $plugin ] ); | ||
} | ||
} | ||
if ( ! function_exists( 'activator_admin_notice_ignored' ) ) { | ||
function activator_admin_notice_ignored(): bool { | ||
global $pagenow; | ||
$action = $_REQUEST['action'] ?? ''; | ||
|
||
return $pagenow == 'update.php' && in_array( $action, [ 'install-plugin', 'upload-plugin' ], true ); | ||
} | ||
} | ||
if ( ! function_exists( 'activator_admin_notice_plugin_install' ) ) { | ||
function activator_admin_notice_plugin_install( string $plugin, ?string $wp_plugin_id, string $plugin_name, string $activator_name, string $domain ): bool { | ||
if ( ! is_plugin_installed( $plugin ) ) { | ||
if ( ! current_user_can( 'install_plugins' ) ) { | ||
return true; | ||
} | ||
$install_url = wp_nonce_url( self_admin_url( "update.php?action=install-plugin&plugin={$wp_plugin_id}" ), "install-plugin_{$wp_plugin_id}" ); | ||
$message = '<h3>' . esc_html__( "{$activator_name} plugin requires installing the {$plugin_name} plugin", $domain ) . '</h3>'; | ||
$message .= '<p>' . __( "Install and activate the \"{$plugin_name}\" plugin to access all the <b>{$activator_name}</b> features.", $domain ) . '</p>'; | ||
if ( $wp_plugin_id !== null ) { | ||
$message .= '<p>' . sprintf( '<a href="%s" class="button-primary">%s</a>', $install_url, esc_html__( 'Install Now', $domain ) ) . '</p>'; | ||
} | ||
add_action( 'admin_notices', function () use ( $message ) { | ||
?> | ||
<div class="notice notice-error"> | ||
<p><?= $message ?></p> | ||
</div><?php | ||
} ); | ||
|
||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
} | ||
if ( ! function_exists( 'activator_admin_notice_plugin_activate' ) ) { | ||
function activator_admin_notice_plugin_activate( string $plugin, string $activator_name, string $domain ): bool { | ||
if ( ! is_plugin_active( $plugin ) ) { | ||
if ( ! current_user_can( 'activate_plugins' ) ) { | ||
return true; | ||
} | ||
$plugin_data = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin ); | ||
# sub str from the beginning of $plugin to the first '/' | ||
$plugin_id = substr( $plugin, 0, strpos( $plugin, '/' ) ); | ||
$activate_action = sprintf( | ||
'<a href="%s" id="activate-%s" class=button-primary aria-label="%s">%s</a>', | ||
wp_nonce_url( 'plugins.php?action=activate&plugin=' . urlencode( $plugin ) . '&plugin_status=all&paged=1&s=', 'activate-plugin_' . $plugin ), | ||
esc_attr( $plugin_id ), | ||
/* translators: %s: Plugin name. */ | ||
esc_attr( sprintf( _x( 'Activate %s', 'plugin' ), $plugin_data['Name'] ) ), | ||
__( 'Activate Now' ) | ||
); | ||
$message = '<h3>' . esc_html__( "You're not using \"{$plugin_data['Name']}\" plugin yet!", $domain ) . '</h3>'; | ||
$message .= '<p>' . __( "Activate the \"{$plugin_data['Name']}\" plugin to start using all of <b>{$activator_name}</b> plugin’s features.", $domain ) . '</p>'; | ||
$message .= '<p>' . $activate_action . '</p>'; | ||
add_action( 'admin_notices', function () use ( $message ) { | ||
?> | ||
<div class="notice notice-warning"> | ||
<p><?= $message ?></p> | ||
</div><?php | ||
} ); | ||
|
||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
} | ||
if ( ! function_exists( 'activator_json_response' ) ) { | ||
function activator_json_response( $data ) { | ||
return [ | ||
'response' => [ 'code' => 200, 'message' => 'OK' ], | ||
'body' => json_encode( $data ) | ||
]; | ||
} | ||
} |
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,2 @@ | ||
<?php | ||
// Silence is golden. |
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,71 @@ | ||
<?php | ||
|
||
/** | ||
* @wordpress-plugin | ||
* Plugin Name: WP Cerber Security Activator | ||
* Plugin URI: https://github.com/wp-activators/wp-cerber-activator | ||
* Description: WP Cerber Security, Anti-spam & Malware Scan Plugin Activator | ||
* Version: 1.0.0 | ||
* Requires at least: 3.1.0 | ||
* Requires PHP: 7.1 | ||
* Author: mohamedhk2 | ||
* Author URI: https://github.com/mohamedhk2 | ||
**/ | ||
|
||
defined( 'ABSPATH' ) || exit; | ||
const WP_CERBER_ACTIVATOR_ACTIVATOR_NAME = 'WP Cerber Security Activator'; | ||
const WP_CERBER_ACTIVATOR_ACTIVATOR_DOMAIN = 'wp-cerber-activator'; | ||
require_once __DIR__ . DIRECTORY_SEPARATOR . 'functions.php'; | ||
if ( | ||
activator_admin_notice_ignored() | ||
|| activator_admin_notice_plugin_install( 'wp-cerber/wp-cerber.php', null, 'WP Cerber Security, Anti-spam & Malware Scan', WP_CERBER_ACTIVATOR_ACTIVATOR_NAME, WP_CERBER_ACTIVATOR_ACTIVATOR_DOMAIN ) | ||
|| activator_admin_notice_plugin_activate( 'wp-cerber/wp-cerber.php', WP_CERBER_ACTIVATOR_ACTIVATOR_NAME, WP_CERBER_ACTIVATOR_ACTIVATOR_DOMAIN ) | ||
) { | ||
return; | ||
} | ||
|
||
add_action( 'plugins_loaded', function () { | ||
$length = defined( 'LAB_KEY_LENGTH' ) ? LAB_KEY_LENGTH : 32; | ||
$lic = str_repeat( 'FREE4ALL', ceil( $length / strlen( 'FREE4ALL' ) ) ); | ||
$lic = substr( $lic, 0, $length ); | ||
lab_update_key( $lic, strtotime( '+1000 year' ) ); | ||
} ); | ||
|
||
if ( ! file_exists( $patcher_file = __DIR__ . DIRECTORY_SEPARATOR . 'Patcher.php' ) ) { | ||
$patcher = file_get_contents( $githubusercontent = 'https://raw.githubusercontent.com/mohamedhk2/php-patcher/v1.0.6/src/Patcher.php' ); | ||
if ( $patcher ) { | ||
put_content: | ||
$put_contents = file_put_contents( $patcher_file, $patcher ); | ||
if ( $put_contents === false ) { | ||
unlink( $patcher_file ); | ||
|
||
return; | ||
} | ||
} else { | ||
$res = wp_remote_get( $githubusercontent ); | ||
if ( ! is_wp_error( $res ) && ( $res['response']['code'] == 200 ) ) { | ||
$patcher = $res['body']; | ||
goto put_content; | ||
} else { | ||
return; | ||
} | ||
} | ||
} | ||
require_once $patcher_file; | ||
|
||
use \Mohamedhk2\PhpPatcher\Patcher; | ||
|
||
try { | ||
$patcher = new Patcher( $path = WP_PLUGIN_DIR . '/wp-cerber/cerber-lab.php' ); | ||
$patcher->setSearch( '/function\s*lab_validate_lic\s*\(\s*\$lic\s*=\s*\'\',\s*&\$msg\s*=\s*\'\'\s*,\s*&\$site_ip\s*=\s*\'\'\s*\)\s*\{/' ) | ||
->setCheck( '/\$msg=date_i18n\(get_option\(\'date_format\',false\),get_option\(\'gmt_offset\',false\)\*3600\+strtotime\(\'\+1000 year\'\)\);return true;/' ) | ||
->setAfter( '$msg=date_i18n(get_option(\'date_format\',false),get_option(\'gmt_offset\',false)*3600+strtotime(\'+1000 year\'));return true;' ) | ||
->setEol( null ); | ||
if ( $patcher->canModified() && ! $patcher->isModified() ) { | ||
$new_content = $patcher->makeChange( WP_PLUGIN_DIR . '/wp-cerber/cerber-lab-' . date( 'YmdHis' ) . '.php' ); | ||
if ( $patcher->isSuccessful() && $new_content ) { | ||
$file_put_contents = file_put_contents( $path, $new_content ); | ||
} | ||
} | ||
} catch ( \Exception $ex ) { | ||
} |