diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/web/config.php | 5 | ||||
-rw-r--r-- | src/web/helpers/auth.php | 2 | ||||
-rw-r--r-- | src/web/helpers/ldap.php | 20 | ||||
-rw-r--r-- | src/web/helpers/schema.php | 12 | ||||
-rw-r--r-- | src/web/index.php | 1 | ||||
-rw-r--r-- | src/web/router.php | 2 |
6 files changed, 24 insertions, 18 deletions
diff --git a/src/web/config.php b/src/web/config.php new file mode 100644 index 0000000..b33fd7b --- /dev/null +++ b/src/web/config.php @@ -0,0 +1,5 @@ +<?php /* Copyright (c) 2024 Freya Murphy */ + +define('CONFIG', array_merge(getenv(), array( + // custom settings +))); diff --git a/src/web/helpers/auth.php b/src/web/helpers/auth.php index 4d7f184..d6c4573 100644 --- a/src/web/helpers/auth.php +++ b/src/web/helpers/auth.php @@ -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; } diff --git a/src/web/helpers/ldap.php b/src/web/helpers/ldap.php index 46bbe69..5ae12c7 100644 --- a/src/web/helpers/ldap.php +++ b/src/web/helpers/ldap.php @@ -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; diff --git a/src/web/helpers/schema.php b/src/web/helpers/schema.php index 6afa43f..5259ae1 100644 --- a/src/web/helpers/schema.php +++ b/src/web/helpers/schema.php @@ -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' diff --git a/src/web/index.php b/src/web/index.php index c4417ea..428da57 100644 --- a/src/web/index.php +++ b/src/web/index.php @@ -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'); diff --git a/src/web/router.php b/src/web/router.php index 536e228..57b69c0 100644 --- a/src/web/router.php +++ b/src/web/router.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"]; } /** |