Skip to content

Commit

Permalink
Merge pull request #933 from ByteHamster/configure-baseuri
Browse files Browse the repository at this point in the history
Added config option for base uri
  • Loading branch information
ByteHamster authored Jun 12, 2020
2 parents fd05722 + 244b6ec commit f599a9c
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 27 deletions.
5 changes: 3 additions & 2 deletions Core/Frameworks/Baikal/Model/Config/Standard.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,9 @@ class Standard extends \Baikal\Model\Config {
"cal_enabled" => true,
"dav_auth_type" => "Digest",
"admin_passwordhash" => "",
"auth_realm" => "BaikalDAV"
];
"auth_realm" => "BaikalDAV",
"base_uri" => ""
];

function __construct() {
$this->aData["invite_from"] = "noreply@" . $_SERVER['SERVER_NAME']; // Default value
Expand Down
68 changes: 43 additions & 25 deletions Core/Frameworks/Flake/Framework.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,31 +172,7 @@ static function bootstrap() {

define("PROJECT_PATH_DOCUMENTROOT", PROJECT_PATH_ROOT . "html/");

# Determine PROJECT_BASEURI
$sScript = substr($_SERVER["SCRIPT_FILENAME"], strlen($_SERVER["DOCUMENT_ROOT"]));
$sDirName = str_replace("\\", "/", dirname($sScript)); # fix windows backslashes

if ($sDirName !== ".") {
$sDirName = self::appendSlash($sDirName);
} else {
$sDirName = "/";
}

$sBaseUrl = self::rmBeginSlash(self::rmProjectContext($sDirName));
define("PROJECT_BASEURI", self::prependSlash($sBaseUrl)); # SabreDAV needs a "/" at the beginning of BASEURL

# Determine PROJECT_URI
$sProtocol = \Flake\Util\Tools::getCurrentProtocol();
$sHttpBaseUrl = strtolower($_SERVER["REQUEST_URI"]);
$sHttpBaseUrl = self::rmQuery($sHttpBaseUrl);
$sHttpBaseUrl = self::rmScriptName($sHttpBaseUrl, $sScript);
$sHttpBaseUrl = self::rmProjectContext($sHttpBaseUrl);
define("PROJECT_URI", $sProtocol . "://" . $_SERVER["HTTP_HOST"] . $sHttpBaseUrl);
unset($sScript);
unset($sDirName);
unset($sBaseUrl);
unset($sProtocol);
unset($sHttpBaseUrl);
self::defineBaseUri();

#################################################################################################

Expand Down Expand Up @@ -227,6 +203,48 @@ static function bootstrap() {
self::initDb();
}

protected static function defineBaseUri() {
try {
$config = Yaml::parseFile(PROJECT_PATH_CONFIG . "baikal.yaml");
if (isset($config["system"]["base_uri"]) && $config["system"]["base_uri"] !== "") {
// SabreDAV needs a "/" at the beginning of BASEURL
define("PROJECT_BASEURI",
self::prependSlash(self::appendSlash($config["system"]["base_uri"])));
define("PROJECT_URI", \Flake\Util\Tools::getCurrentProtocol() . "://"
. $_SERVER["HTTP_HOST"] . PROJECT_BASEURI);

return;
}
} catch (\Exception $e) {
error_log($e);
}

$sScript = substr($_SERVER["SCRIPT_FILENAME"], strlen($_SERVER["DOCUMENT_ROOT"]));
$sDirName = str_replace("\\", "/", dirname($sScript)); // fix windows backslashes

if ($sDirName !== ".") {
$sDirName = self::appendSlash($sDirName);
} else {
$sDirName = "/";
}

$sBaseUrl = self::rmBeginSlash(self::rmProjectContext($sDirName));
define("PROJECT_BASEURI", self::prependSlash($sBaseUrl)); // SabreDAV needs a "/" at the beginning of BASEURL

# Determine PROJECT_URI
$sProtocol = \Flake\Util\Tools::getCurrentProtocol();
$sHttpBaseUrl = strtolower($_SERVER["REQUEST_URI"]);
$sHttpBaseUrl = self::rmQuery($sHttpBaseUrl);
$sHttpBaseUrl = self::rmScriptName($sHttpBaseUrl, $sScript);
$sHttpBaseUrl = self::rmProjectContext($sHttpBaseUrl);
define("PROJECT_URI", $sProtocol . "://" . $_SERVER["HTTP_HOST"] . $sHttpBaseUrl);
unset($sScript);
unset($sDirName);
unset($sBaseUrl);
unset($sProtocol);
unset($sHttpBaseUrl);
}

protected static function initDb() {
try {
$config = Yaml::parseFile(PROJECT_PATH_CONFIG . "baikal.yaml");
Expand Down
1 change: 1 addition & 0 deletions config/baikal.yaml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ system:
dav_auth_type: 'Digest'
admin_passwordhash: 5fe794627e1f841f8debba065e2c807a
auth_realm: BaikalDAV
base_uri: ''
database:
encryption_key: 5d3f0fa0192e3058ea70f1bb20924add
sqlite_file: "absolute/path/to/Specific/db/db.sqlite"
Expand Down

0 comments on commit f599a9c

Please sign in to comment.