forked from openemr/openemr
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
40 lines (35 loc) · 1.43 KB
/
Copy pathindex.php
File metadata and controls
40 lines (35 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
/**
* Set the site ID if required.
*
* This must be done before any database access is attempted.
* Use an IIFE to ensure no variables leak.
*/
(function (): void {
// Any directory name in sites that contains a sqlconf.php can be a site id.
$sites_dirs = glob('sites/*', GLOB_ONLYDIR) ?: [];
$valid_site_ids = array_map(
basename(...),
array_filter($sites_dirs, fn($d) => is_file("{$d}/sqlconf.php"))
);
switch(count($valid_site_ids)) {
case 0:
throw new RuntimeException('No valid sites found');
// Often there's only one valid request id, so we can ignore input.
case 1:
$site_id = $valid_site_ids[0];
break;
default:
$site_id = filter_input(INPUT_GET, 'site') ?: (filter_input(INPUT_SERVER, 'HTTP_HOST') ?: 'default');
if (!in_array($site_id, $valid_site_ids, true)) {
throw new RuntimeException('Invalid site id');
};
}
require_once "sites/{$site_id}/sqlconf.php";
/** @var int $config Defined in sqlconf.php */
header('Location: ' . ($config === 1 ? 'interface/login/login.php' : 'setup.php') . "?site=$site_id");
})();