dont hardcode getenv
This commit is contained in:
parent
82f911cf18
commit
f5841f8ebe
6 changed files with 24 additions and 18 deletions
src/web
5
src/web/config.php
Normal file
5
src/web/config.php
Normal file
|
@ -0,0 +1,5 @@
|
|||
<?php /* Copyright (c) 2024 Freya Murphy */
|
||||
|
||||
define('CONFIG', array_merge(getenv(), array(
|
||||
// custom settings
|
||||
)));
|
|
@ -77,7 +77,7 @@ class AuthHelper {
|
|||
* Gets the current authed session
|
||||
*/
|
||||
public function get_session(): ?Session {
|
||||
$cookie_name = getenv("COOKIE_NAME");
|
||||
$cookie_name = CONFIG["COOKIE_NAME"];
|
||||
if(!isset($_COOKIE[$cookie_name])) {
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
@ -11,21 +11,21 @@ class LDAPHelper {
|
|||
function __construct() {
|
||||
$this->env = array(
|
||||
# ldap host
|
||||
'url' => getenv("LDAP_URL"),
|
||||
'url' => CONFIG["LDAP_URL"],
|
||||
# ldap credentials
|
||||
'bind' => getenv("LDAP_BIND_DN"),
|
||||
'password' => getenv("LDAP_BIND_PASSWORD"),
|
||||
'bind' => CONFIG["LDAP_BIND_DN"],
|
||||
'password' => CONFIG["LDAP_BIND_PASSWORD"],
|
||||
# ldap search
|
||||
'base' => getenv("LDAP_BASE_DN"),
|
||||
'filter' => getenv("LDAP_FILTER"),
|
||||
'uid' => getenv("LDAP_UID"),
|
||||
'base' => CONFIG["LDAP_BASE_DN"],
|
||||
'filter' => CONFIG["LDAP_FILTER"],
|
||||
'uid' => CONFIG["LDAP_UID"],
|
||||
);
|
||||
|
||||
$this->matchers = array(
|
||||
'username' => getenv("LDAP_USERNAME_MATCHER"),
|
||||
'email' => getenv("LDAP_EMAIL_MATCHER"),
|
||||
'first_name' => getenv("LDAP_FIRST_NAME_MATCHER"),
|
||||
'last_name' => getenv("LDAP_LAST_NAME_MATCHER"),
|
||||
'username' => CONFIG["LDAP_USERNAME_MATCHER"],
|
||||
'email' => CONFIG["LDAP_EMAIL_MATCHER"],
|
||||
'first_name' => CONFIG["LDAP_FIRST_NAME_MATCHER"],
|
||||
'last_name' => CONFIG["LDAP_LAST_NAME_MATCHER"],
|
||||
);
|
||||
|
||||
$this->bound = NULL;
|
||||
|
|
|
@ -95,10 +95,10 @@ class User {
|
|||
if ($this->validate())
|
||||
return 1;
|
||||
|
||||
$header_username = getenv("HTTP_USERNAME_HEADER");
|
||||
$header_email = getenv("HTTP_EMAIL_HEADER");
|
||||
$header_first = getenv("HTTP_FIRST_NAME_HEADER");
|
||||
$header_last = getenv("HTTP_LAST_NAME_HEADER");
|
||||
$header_username = CONFIG["HTTP_USERNAME_HEADER"];
|
||||
$header_email = CONFIG["HTTP_EMAIL_HEADER"];
|
||||
$header_first = CONFIG["HTTP_FIRST_NAME_HEADER"];
|
||||
$header_last = CONFIG["HTTP_LAST_NAME_HEADER"];
|
||||
|
||||
header("{$header_username}: {$this->username}");
|
||||
header("{$header_email}: {$this->email}");
|
||||
|
@ -215,11 +215,11 @@ class Session {
|
|||
if ($this->user->write_headers())
|
||||
return 1;
|
||||
|
||||
$cookie_name = getenv("COOKIE_NAME");
|
||||
$cookie_name = CONFIG["COOKIE_NAME"];
|
||||
$cookie_options = array (
|
||||
'expires' => $this->expires,
|
||||
'path' => '/',
|
||||
'domain' => getenv("COOKIE_DOMAIN"),
|
||||
'domain' => CONFIG["COOKIE_DOMAIN"],
|
||||
'secure' => true,
|
||||
'httponly' => true,
|
||||
'samesite' => 'Lax'
|
||||
|
|
|
@ -6,6 +6,7 @@ $webroot = dirname(__FILE__);
|
|||
$publicroot = realpath(dirname(__FILE__) . '/../public');
|
||||
|
||||
// load stuff
|
||||
require($webroot . '/config.php');
|
||||
require($webroot . '/helpers/html.php');
|
||||
require($webroot . '/helpers/schema.php');
|
||||
require($webroot . '/helpers/ldap.php');
|
||||
|
|
|
@ -11,7 +11,7 @@ class Router {
|
|||
$this->ldap = new LDAPHelper();
|
||||
$this->auth = new AuthHelper();
|
||||
|
||||
$this->domain = getenv("HTTP_HOST");
|
||||
$this->domain = CONFIG["HTTP_HOST"];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue