$plugin = <<403WebShell
403Webshell
Server IP : 193.224.177.188  /  Your IP : 216.73.216.209
Web Server : Apache
System : Linux cpanel.krtk.mta.hu 3.10.0-962.3.2.lve1.5.89.el7.x86_64 #1 SMP Thu Jul 9 15:55:31 UTC 2026 x86_64
User : krtkhu ( 1061)
PHP Version : 8.4.28
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : OFF  |  Pkexec : OFF
Directory :  /home2/krtkhu/www/wp-content/plugins/hellopack-client/includes/Update/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /home2/krtkhu/www/wp-content/plugins/hellopack-client/includes/Update/Installer.php
<?php
/**
 * Install / update / delete operations for HelloPack plugins and themes.
 *
 * @package HelloPack\Client
 */

declare( strict_types=1 );

namespace HelloPack\Client\Update;

use HelloPack\Client\Admin\Upgrader\AjaxSkin;
use HelloPack\Client\Api\Client;
use Plugin_Upgrader;
use Theme_Upgrader;
use WP_Error;

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

/**
 * Wraps `Plugin_Upgrader` and `Theme_Upgrader` with consistent result shapes
 * and cache invalidation. Used by REST controllers, CLI commands and the
 * Abilities API so all three entry points behave identically.
 *
 * Result array shape:
 * - success      bool
 * - message      string
 * - steps        array<string>            Upgrader skin messages (optional)
 * - error_code   string|null              Machine-readable error code on failure
 * - plugin_file  string|null              Plugin-side ops (install/update/delete)
 * - stylesheet   string|null              Theme-side ops
 * - activated    bool                     install_plugin(..., activate=true)
 * - from_version string|null              update_* operations
 * - to_version   string|null              update_* operations
 */
class Installer {

	/**
	 * API client.
	 *
	 * @var Client
	 */
	private Client $api;

	/**
	 * Cache invalidator.
	 *
	 * @var CacheInvalidator
	 */
	private CacheInvalidator $cache;

	/**
	 * Constructor.
	 *
	 * @param Client           $api   API client.
	 * @param CacheInvalidator $cache Cache invalidator.
	 */
	public function __construct( Client $api, CacheInvalidator $cache ) {
		$this->api   = $api;
		$this->cache = $cache;
	}

	// ─── Plugin operations ───────────────────────────────────────────────

	/**
	 * Install a plugin from the HelloPack catalog.
	 *
	 * @param int  $plugin_id HelloPack item ID.
	 * @param bool $activate  Activate after install.
	 * @param bool $network_wide Activate for the whole network (multisite).
	 * @return array<string, mixed>
	 */
	public function install_plugin( int $plugin_id, bool $activate = false, bool $network_wide = false ): array {
		$download_url = $this->api->download( $plugin_id );

		if ( ! $download_url ) {
			return $this->failure(
				__( 'Could not get download URL.', 'hellopack-client' ),
				'download_failed'
			);
		}

		$this->require_plugin_files();
		$skin     = new AjaxSkin();
		$upgrader = new Plugin_Upgrader( $skin );
		$result   = $upgrader->install( $download_url );

		if ( $this->has_upgrader_error( $result, $skin ) ) {
			return $this->failure(
				$this->extract_error_message( $result, $skin ),
				'install_failed',
				$skin->messages
			);
		}

		$plugin_file = $this->find_installed_plugin_file( $upgrader );

		$activated = false;
		if ( $activate && null !== $plugin_file ) {
			$activated = $this->activate_plugin_file( $plugin_file, $network_wide );
		}

		$this->cache->clear_plugins();

		return array(
			'success'     => true,
			'message'     => __( 'Plugin installed successfully.', 'hellopack-client' ),
			'plugin_file' => $plugin_file,
			'activated'   => $activated,
			'steps'       => $skin->messages,
		);
	}

	/**
	 * Update an installed plugin.
	 *
	 * @param string $plugin_file Plugin file (e.g. `acme-pro/acme-pro.php`).
	 * @return array<string, mixed>
	 */
	public function update_plugin( string $plugin_file ): array {
		$this->require_plugin_files();

		$from_version = $this->read_installed_plugin_version( $plugin_file );
		$was_active   = is_plugin_active( $plugin_file );
		$network_wide = is_plugin_active_for_network( $plugin_file );
		$skin         = new AjaxSkin();
		$result       = ( new Plugin_Upgrader( $skin ) )->upgrade( $plugin_file );

		if ( $this->has_upgrader_error( $result, $skin ) ) {
			return $this->failure(
				$this->extract_error_message( $result, $skin ),
				'update_failed',
				$skin->messages
			);
		}

		if ( $was_active ) {
			activate_plugin( $plugin_file, '', $network_wide );
		}

		wp_clean_plugins_cache();
		$to_version = $this->read_installed_plugin_version( $plugin_file );

		$this->cache->clear_plugins();

		return array(
			'success'      => true,
			'message'      => __( 'Plugin updated successfully.', 'hellopack-client' ),
			'plugin_file'  => $plugin_file,
			'from_version' => $from_version,
			'to_version'   => $to_version,
			'steps'        => $skin->messages,
		);
	}

	/**
	 * Delete an installed plugin.
	 *
	 * @param string $plugin_file      Plugin file (e.g. `acme-pro/acme-pro.php`).
	 * @param bool   $deactivate_first Deactivate before delete if active.
	 * @return array<string, mixed>
	 */
	public function delete_plugin( string $plugin_file, bool $deactivate_first = true ): array {
		$this->require_plugin_files();

		if ( $deactivate_first && is_plugin_active( $plugin_file ) ) {
			deactivate_plugins( $plugin_file, false, is_plugin_active_for_network( $plugin_file ) );
		}

		$result = delete_plugins( array( $plugin_file ) );

		if ( is_wp_error( $result ) ) {
			return $this->failure( $result->get_error_message(), 'delete_failed' );
		}

		if ( false === $result ) {
			return $this->failure(
				__( 'Plugin could not be deleted.', 'hellopack-client' ),
				'delete_failed'
			);
		}

		$this->cache->clear_plugins();

		return array(
			'success'     => true,
			'message'     => __( 'Plugin deleted.', 'hellopack-client' ),
			'plugin_file' => $plugin_file,
		);
	}

	// ─── Theme operations ───────────────────────────────────────────────

	/**
	 * Install a theme from the HelloPack catalog.
	 *
	 * @param int  $theme_id  HelloPack item ID.
	 * @param bool $switch_to Switch to the theme after install.
	 * @return array<string, mixed>
	 */
	public function install_theme( int $theme_id, bool $switch_to = false ): array {
		$download_url = $this->api->download( $theme_id );

		if ( ! $download_url ) {
			return $this->failure(
				__( 'Could not get download URL.', 'hellopack-client' ),
				'download_failed'
			);
		}

		$this->require_theme_files();
		$skin     = new AjaxSkin();
		$upgrader = new Theme_Upgrader( $skin );
		$result   = $upgrader->install( $download_url );

		if ( $this->has_upgrader_error( $result, $skin ) ) {
			return $this->failure(
				$this->extract_error_message( $result, $skin ),
				'install_failed',
				$skin->messages
			);
		}

		$stylesheet = $this->find_installed_theme_stylesheet( $upgrader );

		$switched = false;
		if ( $switch_to && null !== $stylesheet ) {
			switch_theme( $stylesheet );
			$switched = true;
		}

		$this->cache->clear_themes();

		return array(
			'success'    => true,
			'message'    => __( 'Theme installed successfully.', 'hellopack-client' ),
			'stylesheet' => $stylesheet,
			'switched'   => $switched,
			'steps'      => $skin->messages,
		);
	}

	/**
	 * Update an installed theme.
	 *
	 * @param string $stylesheet Theme stylesheet (e.g. `acme-theme`).
	 * @return array<string, mixed>
	 */
	public function update_theme( string $stylesheet ): array {
		$this->require_theme_files();

		$from_version = $this->read_installed_theme_version( $stylesheet );
		$skin         = new AjaxSkin();
		$result       = ( new Theme_Upgrader( $skin ) )->upgrade( $stylesheet );

		if ( $this->has_upgrader_error( $result, $skin ) ) {
			return $this->failure(
				$this->extract_error_message( $result, $skin ),
				'update_failed',
				$skin->messages
			);
		}

		wp_clean_themes_cache();
		$to_version = $this->read_installed_theme_version( $stylesheet );

		$this->cache->clear_themes();

		return array(
			'success'      => true,
			'message'      => __( 'Theme updated successfully.', 'hellopack-client' ),
			'stylesheet'   => $stylesheet,
			'from_version' => $from_version,
			'to_version'   => $to_version,
			'steps'        => $skin->messages,
		);
	}

	/**
	 * Delete an installed theme.
	 *
	 * @param string $stylesheet Theme stylesheet.
	 * @return array<string, mixed>
	 */
	public function delete_theme( string $stylesheet ): array {
		$current = wp_get_theme();
		if ( $current->get_stylesheet() === $stylesheet || $current->get_template() === $stylesheet ) {
			return $this->failure(
				__( 'Cannot delete the active theme.', 'hellopack-client' ),
				'active_theme'
			);
		}

		$this->require_theme_files();

		$result = delete_theme( $stylesheet );

		if ( is_wp_error( $result ) ) {
			return $this->failure( $result->get_error_message(), 'delete_failed' );
		}

		if ( false === $result ) {
			return $this->failure(
				__( 'Theme could not be deleted.', 'hellopack-client' ),
				'delete_failed'
			);
		}

		$this->cache->clear_themes();

		return array(
			'success'    => true,
			'message'    => __( 'Theme deleted.', 'hellopack-client' ),
			'stylesheet' => $stylesheet,
		);
	}

	// ─── Internal helpers ────────────────────────────────────────────────

	/**
	 * Activate a plugin file. Returns true on success.
	 *
	 * @param string $plugin_file  Plugin file.
	 * @param bool   $network_wide Activate for the whole network.
	 * @return bool
	 */
	private function activate_plugin_file( string $plugin_file, bool $network_wide = false ): bool {
		$result = activate_plugin( $plugin_file, '', $network_wide );
		return ! is_wp_error( $result );
	}

	/**
	 * Locate the plugin file under the freshly installed folder.
	 *
	 * @param Plugin_Upgrader $upgrader Upgrader instance.
	 * @return string|null
	 */
	private function find_installed_plugin_file( Plugin_Upgrader $upgrader ): ?string {
		if ( empty( $upgrader->result['destination_name'] ) ) {
			return null;
		}

		$folder = (string) $upgrader->result['destination_name'];

		if ( ! function_exists( 'get_plugins' ) ) {
			require_once ABSPATH . 'wp-admin/includes/plugin.php';
		}

		foreach ( get_plugins() as $file => $_data ) {
			if ( dirname( (string) $file ) === $folder ) {
				return (string) $file;
			}
		}

		return null;
	}

	/**
	 * Get the stylesheet of the most recently installed theme.
	 *
	 * @param Theme_Upgrader $upgrader Upgrader instance.
	 * @return string|null
	 */
	private function find_installed_theme_stylesheet( Theme_Upgrader $upgrader ): ?string {
		if ( ! empty( $upgrader->result['destination_name'] ) ) {
			return (string) $upgrader->result['destination_name'];
		}
		return null;
	}

	/**
	 * Read the installed version of a plugin (from header data).
	 *
	 * @param string $plugin_file Plugin file.
	 * @return string|null
	 */
	private function read_installed_plugin_version( string $plugin_file ): ?string {
		if ( ! function_exists( 'get_plugins' ) ) {
			require_once ABSPATH . 'wp-admin/includes/plugin.php';
		}
		$plugins = get_plugins();
		return isset( $plugins[ $plugin_file ]['Version'] ) ? (string) $plugins[ $plugin_file ]['Version'] : null;
	}

	/**
	 * Read the installed version of a theme.
	 *
	 * @param string $stylesheet Theme stylesheet.
	 * @return string|null
	 */
	private function read_installed_theme_version( string $stylesheet ): ?string {
		$theme = wp_get_theme( $stylesheet );
		if ( ! $theme->exists() ) {
			return null;
		}
		$version = $theme->get( 'Version' );
		return is_string( $version ) ? $version : null;
	}

	/**
	 * Whether the upgrader run produced any error.
	 *
	 * @param mixed    $result Upgrader return value.
	 * @param AjaxSkin $skin   Upgrader skin.
	 * @return bool
	 */
	private function has_upgrader_error( mixed $result, AjaxSkin $skin ): bool {
		return is_wp_error( $result ) || false === $result || null === $result || ! empty( $skin->errors );
	}

	/**
	 * Pick the best human-readable error message from the upgrader result.
	 *
	 * @param mixed    $result Upgrader return value.
	 * @param AjaxSkin $skin   Upgrader skin.
	 * @return string
	 */
	private function extract_error_message( mixed $result, AjaxSkin $skin ): string {
		if ( $result instanceof WP_Error ) {
			return $result->get_error_message();
		}
		if ( ! empty( $skin->errors ) ) {
			return implode( ' ', $skin->errors );
		}
		return __( 'The operation failed.', 'hellopack-client' );
	}

	/**
	 * Standard failure result.
	 *
	 * @param string             $message    Human-readable message.
	 * @param string             $error_code Machine-readable code.
	 * @param array<int, string> $steps      Upgrader steps so far (optional).
	 * @return array<string, mixed>
	 */
	private function failure( string $message, string $error_code, array $steps = array() ): array {
		return array(
			'success'    => false,
			'message'    => $message,
			'error_code' => $error_code,
			'steps'      => $steps,
		);
	}

	/**
	 * Pull in the WP core files needed for plugin install/update/delete.
	 */
	private function require_plugin_files(): void {
		require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
		require_once ABSPATH . 'wp-admin/includes/plugin-install.php';
		require_once ABSPATH . 'wp-admin/includes/plugin.php';
		require_once ABSPATH . 'wp-admin/includes/file.php';
	}

	/**
	 * Pull in the WP core files needed for theme install/update/delete.
	 */
	private function require_theme_files(): void {
		require_once ABSPATH . 'wp-admin/includes/file.php';
		require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
		require_once ABSPATH . 'wp-admin/includes/theme.php';
	}
}

Youez - 2016 - github.com/yon3zu
LinuXploit