Autoconfigure root_path using __DIR__

This commit is contained in:
Miraty 2023-03-09 14:47:14 +01:00
parent 887ddd2474
commit d41ac85b55
4 changed files with 6 additions and 10 deletions

View file

@ -4,10 +4,6 @@ This document describes the `config.ini` directives. It's an INI file, parsed by
## `[common]`
### `root-path`
Filesystem path to the directory where the root of the program is installed.
### `public_domains[]`
Allowed server names. Used to make the authentication tokens specific to the service.

View file

@ -1,7 +1,6 @@
; Directives here are described in DOCS/configuration.md
[common]
root_path = "/srv/servnest/core"
public_domains[] = "servnest.test"
prefix = ""
service_name = "ServNest"

View file

@ -20,7 +20,7 @@ $domain = formatAbsoluteDomain($_POST['subdomain'] . '.' . $_POST['suffix']);
if (query('select', 'registry', ['domain' => $domain], 'domain') !== [])
output(403, _('This domain is already registered.'));
if (in_array($_POST['subdomain'], explode(LF, file_get_contents(CONF['common']['root_path'] . '/pg-act/reg/reserved.txt'))))
if (in_array($_POST['subdomain'], explode(LF, file_get_contents(ROOT_PATH . '/pg-act/reg/reserved.txt'))))
output(403, _('This domain is reserved.'));
rateLimit();

View file

@ -1,7 +1,8 @@
<?php
define('CONF', parse_ini_file(__DIR__ . '/config.ini', true, INI_SCANNER_TYPED));
const ROOT_PATH = __DIR__;
define('CONF', parse_ini_file(ROOT_PATH . '/config.ini', true, INI_SCANNER_TYPED));
define('DB', new PDO('sqlite:' . CONF['common']['root_path'] . '/db/servnest.db'));
define('DB', new PDO('sqlite:' . ROOT_PATH . '/db/servnest.db'));
$locale = 'en';
foreach (explode(',', preg_replace('/[A-Z0-9]|q=|;|-|\./', '', $_SERVER['HTTP_ACCEPT_LANGUAGE'] ?? '')) as $client_locale) {
@ -23,8 +24,8 @@ const PLACEHOLDER_DOMAIN = 'example'; // From RFC2606: Reserved Top Level DNS Na
const PLACEHOLDER_IPV6 = '2001:db8::3'; // From RFC3849: IPv6 Address Prefix Reserved for Documentation
const PLACEHOLDER_IPV4 = '203.0.113.42'; // From RFC5737: IPv4 Address Blocks Reserved for Documentation
foreach (array_diff(scandir(CONF['common']['root_path'] . '/fn'), ['..', '.']) as $file)
require CONF['common']['root_path'] . '/fn/' . $file;
foreach (array_diff(scandir(ROOT_PATH . '/fn'), ['..', '.']) as $file)
require ROOT_PATH . '/fn/' . $file;
require 'pages.php';