- /**
- * No SSL necessary
- */
- const SSL_POLICY_NONE = 0;
-
- /**
- * SSL is necessary
- */
- const SSL_POLICY_FULL = 1;
-
- /**
- * SSL is optional, but preferred
- */
- const SSL_POLICY_SELFSIGN = 2;
-
- /**
- * Define the Default SSL scheme
- */
- const DEFAULT_SSL_SCHEME = self::SSL_POLICY_SELFSIGN;
-
- /**
- * The Friendica Config
- *
- * @var Configuration
- */
- private $config;
-
- /**
- * The server side variables
- *
- * @var array
- */
- private $server;
-
- /**
- * The hostname of the Base URL
- *
- * @var string
- */
- private $hostname;
-
- /**
- * The SSL_POLICY of the Base URL
- *
- * @var int
- */
- private $sslPolicy;
-
- /**
- * The URL sub-path of the Base URL
- *
- * @var string
- */
- private $urlPath;
-
- /**
- * The full URL
- *
- * @var string
- */
- private $url;
-
- /**
- * The current scheme of this call
- *
- * @var string
- */
- private $scheme;
-
- /**
- * Returns the hostname of this node
- *
- * @return string
- */
- public function getHostname()
- {
- return $this->hostname;
- }
-
- /**
- * Returns the current scheme of this call
- *
- * @return string
- */
- public function getScheme()
- {
- return $this->scheme;
- }
-
- /**
- * Returns the SSL policy of this node
- *
- * @return int
- */
- public function getSSLPolicy()
- {
- return $this->sslPolicy;
- }
-
- /**
- * Returns the sub-path of this URL
- *
- * @return string
- */
- public function getUrlPath()
- {
- return $this->urlPath;
- }
-
- /**
- * Returns the full URL of this call
- *
- * Note: $ssl parameter value doesn't directly correlate with the resulting protocol
- *
- * @param bool $ssl True, if ssl should get used
- *
- * @return string
- */
- public function get($ssl = false)
- {
- if ($this->sslPolicy === self::SSL_POLICY_SELFSIGN && $ssl) {
- return Network::switchScheme($this->url);
- }
-
- return $this->url;
- }
-
- /**
- * Save current parts of the base Url
- *
- * @param string? $hostname
- * @param int? $sslPolicy
- * @param string? $urlPath
- *
- * @return bool true, if successful
- */
- public function save($hostname = null, $sslPolicy = null, $urlPath = null)
- {
- $currHostname = $this->hostname;
- $currSSLPolicy = $this->sslPolicy;
- $currURLPath = $this->urlPath;
-
- if (!empty($hostname) && $hostname !== $this->hostname) {
- if ($this->config->set('config', 'hostname', $hostname)) {
- $this->hostname = $hostname;
- } else {
- return false;
- }
- }
-
- if (isset($sslPolicy) && $sslPolicy !== $this->sslPolicy) {
- if ($this->config->set('system', 'ssl_policy', $sslPolicy)) {
- $this->sslPolicy = $sslPolicy;
- } else {
- $this->hostname = $currHostname;
- $this->config->set('config', 'hostname', $this->hostname);
- return false;
- }
- }
-
- if (isset($urlPath) && $urlPath !== $this->urlPath) {
- if ($this->config->set('system', 'urlpath', $urlPath)) {
- $this->urlPath = $urlPath;
- } else {
- $this->hostname = $currHostname;
- $this->sslPolicy = $currSSLPolicy;
- $this->config->set('config', 'hostname', $this->hostname);
- $this->config->set('system', 'ssl_policy', $this->sslPolicy);
- return false;
- }
- }
-
- $this->determineBaseUrl();
- if (!$this->config->set('system', 'url', $this->url)) {
- $this->hostname = $currHostname;
- $this->sslPolicy = $currSSLPolicy;
- $this->urlPath = $currURLPath;
- $this->determineBaseUrl();
-
- $this->config->set('config', 'hostname', $this->hostname);
- $this->config->set('system', 'ssl_policy', $this->sslPolicy);
- $this->config->set('system', 'urlpath', $this->urlPath);
- return false;
- }
-
- return true;
- }
-
- /**
- * Save the current url as base URL
- *
- * @param $url
- *
- * @return bool true, if the save was successful
- */
- public function saveByURL($url)