- unset($this->config[$configKey]);
- }
-
- /**
- * Detects the server address (SERVER_ADDR) and set it in configuration
- *
- * @return $serverAddress The detected server address
- * @todo We have to add some more entries from $_SERVER here
- */
- public function detectServerAddress () {
- // Is the entry set?
- if (!$this->isConfigurationEntrySet('server_addr')) {
- // Is it set in $_SERVER?
- if (isset($_SERVER['SERVER_ADDR'])) {
- // Set it from $_SERVER
- $this->setServerAddress($_SERVER['SERVER_ADDR']);
- } elseif (class_exists('ConsoleTools')) {
- // Run auto-detecting through console tools lib
- ConsoleTools::acquireSelfIPAddress();
- }
- } // END - if
-
- // Now get it from configuration
- $serverAddress = $this->getServerAddress();
-
- // Return it
- return $serverAddress;
- }
-
- /**
- * Setter for SERVER_ADDR
- *
- * @param $serverAddress New SERVER_ADDR value to set
- * @return void
- */
- public function setServerAddress ($serverAddress) {
- $this->setConfigEntry('server_addr', (string) $serverAddress);
- }
-
- /**
- * Getter for SERVER_ADDR
- *
- * @return $serverAddress New SERVER_ADDR value to set
- */
- public function getServerAddress () {
- return $this->getConfigEntry('server_addr');
- }
-
- /**
- * Detects the HTTPS flag
- *
- * @return $https The detected HTTPS flag or null if failed
- */
- public function detectHttpSecured () {
- // Default is null
- $https = NULL;
-
- // Is HTTPS set?
- if ($this->isHttpSecured()) {
- // Then use it
- $https = $_SERVER['HTTPS'];
- } // END - if
-
- // Return it
- return $https;
- }
-
- /**
- * Checks whether HTTPS is set in $_SERVER
- *
- * @return $isset Whether HTTPS is set
- */
- public function isHttpSecured () {
- return (isset($_SERVER['HTTPS']));
- }
-
- /**
- * Dectect and return the base URL for all URLs and forms
- *
- * @return $baseUrl Detected base URL
- */
- public function detectBaseUrl () {
- // Initialize the URL
- $baseUrl = 'http';
-
- // Do we have HTTPS?
- if ($this->isHttpSecured()) {
- // Add the >s< for HTTPS
- $baseUrl .= 's';
- } // END - if
-
- // Construct the full URL and secure it against CSRF attacks
- $baseUrl = $baseUrl . '://' . $this->detectDomain() . $this->detectScriptPath();
-
- // Return the URL
- return $baseUrl;
- }
-
- /**
- * Detect safely and return the full domain where this script is installed
- *
- * @return $fullDomain The detected full domain
- */
- public function detectDomain () {
- // Full domain is localnet.invalid by default
- $fullDomain = 'localnet.invalid';
-
- // Is the server name there?
- if (isset($_SERVER['SERVER_NAME'])) {
- // Detect the full domain
- $fullDomain = htmlentities(strip_tags($_SERVER['SERVER_NAME']), ENT_QUOTES);
- } // END - if
-
- // Return it
- return $fullDomain;
- }
-
- /**
- * Detect safely the script path without trailing slash which is the glue
- * between "http://your-domain.invalid/" and "script-name.php"
- *
- * @return $scriptPath The script path extracted from $_SERVER['SCRIPT_NAME']
- */
- public function detectScriptPath () {
- // Default is empty
- $scriptPath = '';
-
- // Is the scriptname set?
- if (isset($_SERVER['SCRIPT_NAME'])) {
- // Get dirname from it and replace back-slashes with slashes for lame OSes...
- $scriptPath = str_replace("\\", '/', dirname($_SERVER['SCRIPT_NAME']));
- } // END - if
-
- // Return it
- return $scriptPath;