File manager - Edit - /usr/local/cpanel/base/frontend/jupiter/cpguard/webuzo/cpguard.php
Back
<?php /* Plugin Name: cPGuard Client Version: 1.0 Description: Client version of cPGuard webserver security suite */ register_activation_hook(__FILE__, "cpguard_activation"); function cpguard_activation() { // Activation tasks } // Load add_filter("plugins_loaded", "cpguard_load_plugin"); function cpguard_load_plugin() { } add_filter('is_modsec_vendors', 'cpguard_check_waf_status'); function cpguard_check_waf_status() { $content = file_get_contents('/etc/cpguard/cpguard_modsec100.conf'); if(str_ireplace(['Include', 'SecRemoteRules'], '', $content) === $content){ return false; } return true; } // Add the admin menu add_filter('admin_menu', 'cpguard_admin_menu', 10, 1); function cpguard_admin_menu($menu) { global $globals, $theme; $menu['cpguard'] = [ 'name' => 'cPGuard Security', 'href' => $globals['ind'] . 'act=cpguard', 'icon' => (isset($globals["panel_url"]) ? $globals["panel_url"] : "") . "cpguard/user_icon.svg", 'attr' => 'width=16' ]; return $menu; } // The action handler admin_act('cpguard', 'cpguard_admin'); function cpguard_admin() { global $globals, $SESS, $WE, $done; $user = posix_getpwuid(posix_geteuid())['name'] ?? ''; if (!in_array($user, ['root', 'webuzo'])) { echo "You are not authorised"; return; } if (isset($_GET['link'])) { $payload = [ 'method' => 'portalLogin', 'user' => $user, 'data' => [] ]; // 2. Invoke Go Binary $binaryPath = '/opt/cpguard/app/cpg-bridge'; $descriptors = [ 0 => ['pipe', 'r'], // STDIN 1 => ['pipe', 'w'], // STDOUT 2 => ['pipe', 'w'] // STDERR ]; $process = proc_open($binaryPath, $descriptors, $pipes); if (is_resource($process)) { fwrite($pipes[0], json_encode($payload)); fclose($pipes[0]); $responseRaw = stream_get_contents($pipes[1]); $errorsRaw = stream_get_contents($pipes[2]); fclose($pipes[1]); fclose($pipes[2]); $exitCode = proc_close($process); if ($exitCode === 0) { $response = json_decode($responseRaw); if ($response && isset($response->response) && filter_var($response->response, FILTER_VALIDATE_URL)) { echo trim($response->response); } else { echo "Invalid response from bridge."; } } else { echo "API failed #E" . $exitCode . " : " . $errorsRaw; } } else { echo "Failed to open bridge process."; } exit(); } else { // Handle Standard Request (The wrapper) // This tells Webuzo to wrap our content in the user theme theme_for_act('cpguard_admin_theme', 'cpguard'); } } function cpguard_admin_theme() { global $globals, $SESS, $WE, $done; include __DIR__ . '/admin_ui.php'; } // Enduser icon add_filter("enduser_cats_icons", "cpguard_enduser_cats_icons", 10, 1); function cpguard_enduser_cats_icons($icons) { global $globals; $icons["security"]["icons"]["cpguard"] = [ "name" => "cPGuard", "icon" => (isset($globals["panel_url"]) ? $globals["panel_url"] : "") . "cpguard/user_icon.svg", "href" => (isset($globals["index"]) ? $globals["index"] : "index.live.php") . "act=cpguard", ]; return $icons; } enduser_act("cpguard", "cpguard_enduser"); function cpguard_enduser() { global $globals, $SESS, $WE, $done; $plugin_dir = dirname(__DIR__); $current_user = $SESS['user']; // 1. Handle Internal Frame Requests (The content INSIDE the iframe) if (isset($_GET['iframe'])) { // SECURITY: Strict routing, do not use $_GET['file'] dynamically for includes try { if (isset($_GET['ajax'])) { include $plugin_dir . '/ajax.live.php'; } else { include $plugin_dir . '/index.live.php'; } } catch (Exception $e) { echo "An error occurred: " . htmlspecialchars($e->getMessage(), ENT_QUOTES); } exit; // Stop Webuzo from loading the rest of the theme } // 2. Handle Standard Request (The wrapper) // This tells Webuzo to wrap our content in the user theme theme_for_act('cpguard_enduser_theme', 'cpguard'); } // --------------------------------------------------------- // FIXED THEME HANDLER (Wrapper Only) // --------------------------------------------------------- function cpguard_enduser_theme() { global $globals; // We removed the dangerous AJAX handling from here because // it is now handled safely in cpguard_enduser above. // This URL calls back to the main function but triggers the 'iframe' block $url = $globals['ind'] . 'act=cpguard&iframe=1'; ?> <style> #iframeLoader { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); display: flex; align-items: center; justify-content: center; background: rgba(255, 255, 255, 0.9); width: 100%; height: 100%; z-index: 10; } .spinner { animation: rotate 2s linear infinite; z-index: 2; position: absolute; top: 50%; left: 50%; margin: -25px 0 0 -25px; width: 50px; height: 50px; } @keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } } #iframeContainer { position: relative; width: 100%; min-height: 80vh; } #cPGuardApp { width: 100%; min-height: 80vh; border: none; display: block; } </style> <div id="iframeContainer"> <div id="iframeLoader"> <div class="spinner"></div> </div> <iframe src="<?php echo $url; ?>" id="cPGuardApp" scrolling="yes" onload="hide_loader();resize_iframe();"></iframe> </div> <script> function hide_loader() { const loader = document.getElementById("iframeLoader"); if (loader) loader.style.display = "none"; } function resize_iframe() { const iframe = document.getElementById("cPGuardApp"); iframe.style.height = "0px"; iframe.style.height = iframe.contentWindow.document.body.scrollHeight + "px"; console.log(iframe.style.height); } window.onresize = resize_iframe; </script> <?php } function API_cpguard_enduser() { global $globals, $SESS, $WE, $done, $W; if (!empty($done)) { $GLOBALS['_api']['done'] = $done; } }
| ver. 1.4 |
Github
|
.
| PHP 8.1.34 | Generation time: 0.04 |
proxy
|
phpinfo
|
Settings