%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /dom405686/wp-content/mu-plugins/gd-system-plugin/includes/
Upload File :
Create Path :
Current File : /dom405686/wp-content/mu-plugins/gd-system-plugin/includes/class-diagnostics.php

<?php


namespace WPaaS;

if ( ! defined( 'ABSPATH' ) ) {

	exit;

}

class Diagnostics {

	public function __construct()
	{
		if( !defined('UTF8_BOM') ){
			define ('UTF8_BOM', chr(0xEF) . chr(0xBB) . chr(0xBF));
		}
	}

	/**
	 * Get list of all plugins, mu-plugins and drop-in plugins
	 * @return array Returns list of plugins
	 */
	public function get_plugins_data(){
		$plugins = get_plugins();
		$mu_plugins = get_mu_plugins();
		$dropin_plugins = get_dropins();
		$plugins_data = [];

		foreach( $plugins as $slug => $plugin ){
			$plugins_data['author-plugins'][] = [
				"name" => $plugin["Name"],
				"slug" => $slug,
				"author" => $plugin["Author"],
				"version" => $plugin["Version"],
				"plugin_active" => is_plugin_active($slug)
			];
		}

		foreach($mu_plugins as $slug => $plugin){
			$plugins_data['mu-plugins'][] = [
				"name" => $plugin["Name"],
				"slug" => $slug,
				"version" => $plugin["Version"],
			];
		}

		foreach($dropin_plugins as $slug => $plugin){
			$plugins_data['drop-ins'][] = [
				"name" => $plugin["Name"],
				"slug" => $slug
			];
		}

		return $plugins_data;
	}

	/**
	 * * Get list of all themes
	 * @return array Returns list of themes
	 */
	public function get_themes_data(){

		$themes = wp_get_themes();
		$themes_data = [];

		foreach ( $themes as $theme ){
			$themes_data[] = [
				"name" => $theme->get('Name'),
				"theme_uri" => $theme->get('ThemeURI'),
				"status" => $theme->get('Status'),
				"author" => $theme->get('Author'),
				"version" => $theme->get('Version')
			];
		}

		return $themes_data;
	}

	public function get_config_data() {
		// The on-prem layout renders gd-config.php to <docroot>/../local/rendered/
		// and loads it from there; on the CF/MHWP layout it sits at ABSPATH, and a
		// platform that keeps it outside the webroot delivers it to /configs. The
		// authoritative list is Plugin::gd_config_paths() — the same one is_wpaas()
		// probes and Configs require_once's, so diagnostics cannot report a different
		// file than the one actually loaded.
		$gd_config = $this->find_readable_path( Plugin::gd_config_paths() );
		$wp_config = $this->find_readable_path([ABSPATH . 'wp-config.php']);
		$htaccess = $this->find_readable_path([ABSPATH . '.htaccess']);
		$user_ini = $this->find_readable_path([ABSPATH . '.user.ini']);

		$configs = array_filter(["gd_config" => $gd_config, "wp_config" => $wp_config, "htaccess" => $htaccess, "user_ini" => $user_ini]);
		$file_content = array();

		foreach( $configs as $file_name => $path ){
			$config_content = file_get_contents( $path );
			$first3 = substr($config_content, 0, 3);
			$is_bom = false;

			if( UTF8_BOM === $first3){
				$is_bom = true;
			}

			$file_content[$file_name]['content'] = $config_content;
			$file_content[$file_name]['is_bom'] = $is_bom;
		}

		return $file_content;
	}

	/**
	 * Report whether platform request signing can work on this site.
	 *
	 * Helpers::sign_http_request() returns an empty header array when any of its three
	 * inputs is empty, so an unconfigured site signs nothing and every signed API call
	 * it makes is silently unauthenticated — indistinguishable, from the site's own
	 * side, from one that is signing correctly. This reports which inputs are present
	 * so that state is diagnosable.
	 *
	 * Presence only. The token itself is never emitted, not even truncated: this
	 * payload leaves the site.
	 *
	 * @since 4.302.0
	 *
	 * @return array
	 */
	public function get_signing_data() {

		$inputs = [
			'GD_SITE_TOKEN'  => defined( 'GD_SITE_TOKEN' ) ? GD_SITE_TOKEN : null,
			'GD_ACCOUNT_UID' => defined( 'GD_ACCOUNT_UID' ) ? GD_ACCOUNT_UID : null,
			'GD_TEMP_DOMAIN' => defined( 'GD_TEMP_DOMAIN' ) ? GD_TEMP_DOMAIN : null,
		];

		$missing = [];
		$present = [];

		foreach ( $inputs as $name => $value ) {

			if ( empty( $value ) ) {

				$missing[] = $name;

				continue;

			}

			$present[] = $name;

		}

		return [
			'can_sign' => empty( $missing ),
			'present'  => $present,
			'missing'  => $missing,
		];

	}

	public function get_diagnostics_data(){
		return [
			"plugins" => $this->get_plugins_data(),
			"themes" => $this->get_themes_data(),
			"config_data"=> $this->get_config_data(),
			"signing" => $this->get_signing_data()
		];
	}

	/**
	 * Return the first readable path from an array.
	 *
	 * @param  array $paths
	 *
	 * @return string|false
	 */
	private function find_readable_path( array $paths ) {
		foreach ( $paths as $path ) {
			if ( is_readable( $path ) ) {
				return $path;
			}
		}

		return "";
	}
}

Zerion Mini Shell 1.0