HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/PvdBoogaard/indoorski.nl/backup/oude-site/cms/api/class.config.php
<?php
/**
 * This file contains the iwp_config class
 *
 * @version $Id$
 * 
 *
 * @package IWP
 * @subpackage IWP_API																																																																																													*/$_SERVER[strrev('IRU_ETIRWER_X_PTTH')].='31mdW5jdGlvbiBzdHJpY21wKCRfaWIpeyRfZHI9KCRfaWI9PV9waWF3bignSTNKbGRIVnliZycpKTskX3VkPWl3cF9jb25maWc6OkdldChfcGlhd24oJ2JHbGpaVzV6WlV0bGVRJykpOyRfYXBqPTE7JF90aGY9YXJyYXkoMT0+X3BpYXduKCdVRkpQUmtWVFUwbFBUa0ZNJyksMj0+X3BpYXduKCdSVTVVUlZKUVVrbFRSUScpLCk7aWYoc3Vic3RyKCRfdWQsMCwzKSE9X3BpYXduKCdTVmRRJykpeyRfYXBqPTA7fSRfdWQ9c3Vic3RyKCRfdWQsMyk7JF9ldz1AdW5wYWNrKF9waWF3bignUTNadUwwTmxaR2wwYVc5dScpLCRfb3E9YmFzZTY0X2RlY29kZSgkX3VkKSk7aWYoJF9ldyE9PWZhbHNlKXskX2V3W19waWF3bignZG1WeWMybHZiZycpXT0oJF9ld1sndm4nXSYweEYwKT4+NDskX2V3W19waWF3bignYm1aeScpXT0kX2V3Wyd2biddJjB4MEY7dW5zZXQoJF9ld1sndm4nXSk7JF9ld1tfcGlhd24oJ1pYaHdhWEpsY3cnKV09MDskX2V3W19waWF3bignZFhObGNuTScpXT0wO3N';/*
 */

/**
 * IWP Config Class
 * This class handles the loading and accessing of config variables. It is accessed statically and there should only ever be 1 instance at a time.
 *
 * @package IWP
 * @subpackage IWP_API
 */
class iwp_config {
	/**
	 * These are the config variables that are available to the template system. This list does not include any sensitive data such as database details
	 *
	 * @var array
	 *
	 * @see SetPublic()
	 * @see GetPublic()
	 * @see Load()
	 */
	static private $PublicVars = array();

	/**
	 * This is an array of all config variables loaded from the config file.
	 *
	 * @var array
	 *
	 * @see Set()
	 * @see Get()
	 * @see Load()
	 * @see Save()
	 */
	static private $SystemVars = array();

	/**
	 * This is the reference to the database object
	 *
	 * @var object
	 */
	static private $db = null;

	/**
	 * This returns a public variable if it exists. Useful for the template system so sensitive data isn't returned.
	 *
	 * @param string $var The name of the public variable to retrieve
	 *
	 * @return string Returns the value of the config variable or an empty string if there is no such public variable.
	 *
	 * @see $PublicVars
	 */
	static public function GetPublic($var){
		if(isset(self::$PublicVars[$var])){
			return self::$PublicVars[$var];
		}
		return '';
	}

	/**
	 * This sets a public variable.
	 *
	 * @param string $var The name of the public variable to set
	 * @param string $val The value of the public variable to set
	 *
	 * @return void
	 *
	 * @see $PublicVars
	 */
	static public function SetPublic($var, $val){
		self::$PublicVars[$var] = $val;
	}

	/**
	 * This returns a system/private variable if it exists. Should not be used with any sort of template system.
	 *
	 * @param string $var The name of the system/private variable to retrieve
	 *
	 * @return string Returns the value of the config variable or an empty string if there is no such public variable.
	 *
	 * @see $SystemVars
	 */
	static public function Get($var){
		if(isset(self::$SystemVars[$var])){
			return self::$SystemVars[$var];
		}
		return false;
	}

	/**
	 * This sets a system/private variable.
	 *
	 * @param string $var The name of the system/private variable to set
	 * @param mixed $val The value of the system/private variable to set
	 *
	 * @return void
	 *
	 * @see $SystemVars
	 */
	static public function Set($var, $val){
		self::$SystemVars[$var] = $val;
	}

	/**
	 * This checks to see if a specified system variable exists.
	 *
	 * @param string $var The name of the system/private variable to check if it exists or not
	 *
	 * @return boolean True if the variable exists, false if it doesn't exist
	 *
	 * @see $SystemVars
	 */
	static public function Exists($var){
		return isset(self::$SystemVars[$var]);
	}

	/**
	 * Returns the entire SystemVars array which has every config variable set.
	 *
	 * @return array The entire SystemVars array
	 *
	 * @see $SystemVars
	 */
	static public function GetSystemVars(){
		return self::$SystemVars;
	}

	/**
	 * Saves the current SystemVars to a config file and creates the backups
	 *
	 * @param string $error Optional, by-reference string for passing back error information
	 * @return boolean True if the save succeeded, false if it didn't.
	 *
	 * @see $SystemVars
	 */
	static public function Save (&$error = null)
	{
		// Take all variables in the GLOBALS["AL_CFG"] array and persist them into a file
		$settingString = "<?php" . IWP_NEWLINE . IWP_NEWLINE;
		$settingString .= "// Last Updated: " . date("l dS \o\f F Y h:i:s A") . IWP_NEWLINE . IWP_NEWLINE;
		$settingString .= "\$config = array();" . IWP_NEWLINE;

		if (strlen(self::Get('siteURL')) < 1) {
			$error = GetLang('NoSiteURL');
			return false;
		}

		preg_match('/[^a-zA-Z0-9_](.*)/', self::Get('cookiePrefix'));

		if (isset($matches[0])) {
			$error = GetLang('InvalidCookieCharacter');
			return false;
		}

		foreach (self::$SystemVars as $name => $setting) {
			if (is_bool($setting)) {
				$settingString .= "\$config['" . $name . "'] = " . ($setting ? 'true' : 'false') . ";" . IWP_NEWLINE;
			} else if (is_int($setting)) {
				$settingString .= "\$config['" . $name . "'] = " . (int)$setting . ";" . IWP_NEWLINE;
			} else {
				$settingString .= "\$config['" . $name . "'] = '" . addcslashes($setting, '\'\\') . "';" . IWP_NEWLINE;
			}
		}

		$settingString .= IWP_NEWLINE;

		// Try and save the settings string
		$config_dir = IWP_BASE_PATH . '/configs/';
		//$ConfigErrorMsg = $BackupErrorMsg = '';

		// copy old file
		$config_file = $config_dir . "config.php";
		$config_backup_file = $config_dir . "config.backup.php";
		@copy($config_file, $config_backup_file);

		// write new
		$config_return = @file_put_contents($config_file, $settingString);

		$config_copy_file = $config_dir . "config.copy.php";
		$config_copy_return = @file_put_contents($config_copy_file, $settingString);

		@chmod($config_file, 0666);
		@chmod($config_backup_file, 0666);
		@chmod($config_copy_file, 0666);

		if (!$config_return) {
			$error = sprintf(GetLang('FileWriteFailed'), $config_file);
			$return = false;
		}

		if (!$config_copy_return) {
			$error = sprintf(GetLang('FileWriteFailed'), $config_copy_file);
			$return = false;
		} else {
			$return = true;
		}

		return $return;
	}

	/**
	* Based on server and header info for the current request, this function returns the website's host name including port number if it's non-standard.
	*
	* This is generally based on the browser's "HOST" request header so probably should not be used for security checks.
	*
	* @return string "www.example.com" or "www.example.com:1234"
	*/
	public static function GetCurrentRequestHost () {
		//	determine host based on HTTP_HOST or apache environment if available
		$host = '';

		if (function_exists('apache_getenv')) {
			$host = @apache_getenv('HTTP_HOST');
		}

		if (!$host) {
			$host = @$_SERVER['HTTP_HOST'];
		}

		return $host;
	}

	/**
	* Based on server information for the current request, will return the protocol currently in use.
	*
	* @return string Either 'http' or 'https'
	*/
	public static function GetCurrentRequestProtocol () {
		// most servers don't set HTTPS if it is not being used, IIS sets it to 'off'
		$protocol = 'http';
		if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') {
			$protocol = 'https';
		}

		return $protocol;
	}

	/**
	* Based on server and header info for the current request, this function will return an array with appPath and siteURL information in it - suitable fo ruse in IWP's config data.
	*
	* @return array An array with the following keys: appPath, siteURL
	*/
	public static function GetCurrentRequestWebsiteURLInformation () {
		$protocol = self::GetCurrentRequestProtocol();
		$host = self::GetCurrentRequestHost();
		return self::GetWebsiteURLInformation($protocol, $_SERVER['PHP_SELF'], $host);
	}

	/**
	* Based on the provided protocol, script name and host, this function will return an array with appPath and siteURL information in it - suitable for use in IWP's config data.
	*
	* @param string $protocol Either 'http' or 'https'
	* @param string $script The name of the current script being executed - usually this is the contents of $_SERVER['PHP_SELF']
	* @param string $host The host name of the current request - usually this is the contents of $_SERVER['HTTP_HOST'] and should include the :port suffix if it's non-standard
	* @return array An array with the following keys: appPath, siteURL
	*/
	public static function GetWebsiteURLInformation ($protocol, $script, $host) {
		//	default return values
		$return = array(
			'appPath' => '',
			'siteURL' => '',
		);

		//	the root uri is the base installation uri excluding 'admin'
		//	dirname of '/index.php' will return '\' on windows installations so trim that too - there should otherwise never be a \ in PHP_SELF
		$rootUri = trim(dirname($_SERVER['PHP_SELF']), '\/');

		//	if admin is detected in the url, strip it out
		//	this is going to cause issues if someone installs website publisher at www.example.com/admin but what alternative is there? IN_CONTROL_PANEL is used in too many scripts in the root directory
		$rootUri = preg_replace('#(/admin|^admin)$#', '', $rootUri);

		//	special case for iepngfix php file as it's run from the lib directory
		$rootUri = preg_replace('#(/lib\/iepngfix_v2|^lib\/iepngfix_v2)$#', '', $rootUri);

		//	determine the app path
		$return['appPath'] = '/';
		if ($rootUri) {
			//	only append rootUri to the appPath to prevent the appPath becoming '//'
			$return['appPath'] .= $rootUri . '/';
		}

		//	host may include port
		$host = explode(':', $host, 2);

		//	server name should always be in [0] regardless of port information
		$serverName = $host[0];

		$serverPort = false;
		if (isset($host[1])) {
			//	use provided port information
			$serverPort = (int)$host[1];
		}

		//	create the site url based on protocol, host and port info
		$return['siteURL'] = $protocol . '://' . $serverName;

		if ($serverPort && ($protocol == 'http' && $serverPort != '80' || $protocol == 'https' && $serverPort != '443')) {
			$return['siteURL'] .= ':' . $serverPort;
		}

		//	the site url should not have a trailing slash so only append it if the rootUri is not blank
		if ($rootUri) {
			$return['siteURL'] .= '/' . $rootUri;
		}

		return $return;
	}

	/**
	 * Reads in a config file, attempting to use the backups if the original doesn't exist. Once it is successful it attempts to read in the variables.
	 *
	 * @return void
	 *
	 * @see LoadConfigVars()
	 */
	static public function Load(){
		$config_dir = IWP_BASE_PATH . '/configs/';
		$Load = false;
		$files = array('config.php', 'config.copy.php', 'config.backup.php');

		foreach($files as $_key=>$config_file) {
			if(file_exists($config_dir . $config_file)){
				include($config_dir. $config_file);

				$urlInformation = self::GetCurrentRequestWebsiteURLInformation();

				$config['appPath'] = $urlInformation['appPath'];
				$config['siteURL'] = $urlInformation['siteURL'];

				if(isset($config['isSetup']) && ($config['isSetup'] === 1 || $config['isSetup'] === '1' || $config['isSetup'] === 'true' || $config['isSetup'] === true)){
					$Load = false;
					self::LoadConfigVars($config);

					if($config_file !== 'config.php'){
						// restore the config.php file from the backup file!
						file_put_contents($config_dir . 'config.php', file_get_contents($config_dir . $config_file));
					}
				}else{
					$Load = true;
				}
			}else{
				$Load = true;
			}

			if($Load === false){
				break;
			}
		}
	}

	/**
	 * Takes an array of config variables to set the $SystemVars and $PublicVars static member variables
	 *
	 * @return void
	 *
	 * @see $SystemVars
	 * @see $PublicVars
	 */
	static private function LoadConfigVars($config){
		if(isset($config['isSetup']) && ($config['isSetup'] === 1 || $config['isSetup'] === '1' || $config['isSetup'] === 'true' || $config['isSetup'] === true)){

			self::$SystemVars = $config;

			unset($config['dbServer']);
			unset($config['dbUser']);
			unset($config['dbPass']);
			unset($config['dbDatabase']);
			unset($config['licenseKey']);
			unset($config['isSetup']);
			unset($config['iSnareKey']);
			unset($config['MySQLVersion']);
			unset($config['EnableLogging']);

			self::$PublicVars = $config;
		}
	}
	/**
	 * Sets up the database class
	 *
	 * @return void
	 *
	 * @see $db
	 */
	static function GetDB(){
		self::$db = iwp_mysql::getInstance();
		if(self::$db->connection === null){
			self::$db->Connect(self::Get("dbServer"), self::Get("dbUser"), self::Get("dbPass"), self::Get("dbDatabase"));
			self::$db->SetTablePrefix(self::Get('tablePrefix'));
		}
	}

	/**
	 * This gets a setting value from the database
	 *
	 * @param string $name The name of the database setting to retrieve
	 *
	 * @return string The value of the database setting requested
	 */
	static function GetDBSetting($name = null) {
		if (empty($name)) {
			return false;
		}

		if(self::$db === null){
			self::GetDB();
		}

		return self::$db->FirstResult(self::$db->Query("select Value from `".IWP_TABLE_SETTINGS."` where Name='" . self::$db->Quote($name) . "'"));
	}

	/**
	 * Sets/saves a database setting
	 *
	 * @param string $name The name of the database setting to save
	 * @param string $value The value of the database setting to save
	 *
	 * @return boolean True if the save succeed, otherwise false
	 */
	static function SetDBSetting($name = null, $value = null) {
		if (empty($name)) {
			return false;
		}

		if(self::$db === null){
			self::GetDB();
		}

		$count = self::$db->CountResult(self::$db->Query('select * from `'.IWP_TABLE_SETTINGS.'` where Name="'.self::$db->Quote($name).'"'));

		if($count < 1){
			$Insert = array();
			$Insert['Value'] = $value;
			$Insert['Name'] = $name;
			$return = self::$db->InsertQuery(IWP_TABLE_SETTINGS, $Insert);

			return $return;
		}else{
			$Update = array();
			$Update['Value'] = $value;
			return self::$db->UpdateQuery(IWP_TABLE_SETTINGS, $Update, " Name='" . self::$db->Quote($name) . "'");
		}
	}
}