diff --git a/resources/autoload.php b/resources/autoload.php index 0942efc6..2eb533a1 100644 --- a/resources/autoload.php +++ b/resources/autoload.php @@ -26,5 +26,5 @@ require_once __DIR__ . "/lib/UnityGithub.php"; require_once __DIR__ . "/lib/exceptions/SSOException.php"; -// run init script +require_once __DIR__ . "/config.php"; require __DIR__ . "/init.php"; diff --git a/resources/config.php b/resources/config.php new file mode 100644 index 00000000..ac43e9ed --- /dev/null +++ b/resources/config.php @@ -0,0 +1,5 @@ +exists(); $_SESSION["is_pi"] = $USER->isPI(); - $SEND_PIMESG_TO_ADMINS = $CONFIG["mail"]["send_pimesg_to_admins"]; + $SEND_PIMESG_TO_ADMINS = CONFIG["mail"]["send_pimesg_to_admins"]; $SQL->addLog( $OPERATOR->uid, diff --git a/resources/lib/UnityLDAP.php b/resources/lib/UnityLDAP.php index e34ff6e3..3c22de77 100644 --- a/resources/lib/UnityLDAP.php +++ b/resources/lib/UnityLDAP.php @@ -24,13 +24,7 @@ class UnityLDAP extends ldapConn "top" ); - // string vars for OUs - private $STR_BASEOU; - private $STR_USEROU; - private $STR_GROUPOU; - private $STR_PIGROUPOU; - private $STR_ORGGROUPOU; - private $STR_ADMINGROUP; + private $custom_mappings_path = __DIR__ . "/../../deployment/custom_user_mappings"; // Instance vars for various ldapEntry objects private $baseOU; @@ -40,45 +34,19 @@ class UnityLDAP extends ldapConn private $org_groupOU; private $adminGroup; private $userGroup; - - private $custom_mappings_path; - private $def_user_shell; - public function __construct( - $host, - $dn, - $pass, - $custom_user_mappings, - $base_ou, - $user_ou, - $group_ou, - $pigroup_ou, - $orggroup_ou, - $admin_group, - $user_group_dn, - $def_user_shell - ) { - parent::__construct($host, $dn, $pass); - - $this->STR_BASEOU = $base_ou; - $this->STR_USEROU = $user_ou; - $this->STR_GROUPOU = $group_ou; - $this->STR_PIGROUPOU = $pigroup_ou; - $this->STR_ORGGROUPOU = $orggroup_ou; - $this->STR_ADMINGROUP = $admin_group; - - $this->baseOU = $this->getEntry($base_ou); - $this->userOU = $this->getEntry($user_ou); - $this->groupOU = $this->getEntry($group_ou); - $this->pi_groupOU = $this->getEntry($pigroup_ou); - $this->org_groupOU = $this->getEntry($orggroup_ou); - $this->adminGroup = $this->getEntry($admin_group); - $this->userGroup = $this->getEntry($user_group_dn); - - $this->custom_mappings_path = $custom_user_mappings; - - $this->def_user_shell = $def_user_shell; + public function __construct() + { + parent::__construct(CONFIG["ldap"]["uri"], CONFIG["ldap"]["user"], CONFIG["ldap"]["pass"]); + $this->baseOU = $this->getEntry(CONFIG["ldap"]["basedn"]); + $this->userOU = $this->getEntry(CONFIG["ldap"]["user_ou"]); + $this->groupOU = $this->getEntry(CONFIG["ldap"]["group_ou"]); + $this->pi_groupOU = $this->getEntry(CONFIG["ldap"]["pigroup_ou"]); + $this->org_groupOU = $this->getEntry(CONFIG["ldap"]["orggroup_ou"]); + $this->adminGroup = $this->getEntry(CONFIG["ldap"]["admin_group"]); + $this->userGroup = $this->getEntry(CONFIG["ldap"]["user_group"]); + $this->def_user_shell = CONFIG["ldap"]["def_user_shell"]; } public function getUserOU() @@ -429,24 +397,24 @@ public function getAllOrgGroupsAttributes($attributes) public function getUserEntry($uid) { $uid = ldap_escape($uid, "", LDAP_ESCAPE_DN); - return $this->getEntry(unityLDAP::RDN . "=$uid," . $this->STR_USEROU); + return $this->getEntry(unityLDAP::RDN . "=$uid," . CONFIG["ldap"]["user_ou"]); } public function getGroupEntry($gid) { $gid = ldap_escape($gid, "", LDAP_ESCAPE_DN); - return $this->getEntry(unityLDAP::RDN . "=$gid," . $this->STR_GROUPOU); + return $this->getEntry(unityLDAP::RDN . "=$gid," . CONFIG["ldap"]["group_ou"]); } public function getPIGroupEntry($gid) { $gid = ldap_escape($gid, "", LDAP_ESCAPE_DN); - return $this->getEntry(unityLDAP::RDN . "=$gid," . $this->STR_PIGROUPOU); + return $this->getEntry(unityLDAP::RDN . "=$gid," . CONFIG["ldap"]["pigroup_ou"]); } public function getOrgGroupEntry($gid) { $gid = ldap_escape($gid, "", LDAP_ESCAPE_DN); - return $this->getEntry(unityLDAP::RDN . "=$gid," . $this->STR_ORGGROUPOU); + return $this->getEntry(unityLDAP::RDN . "=$gid," . CONFIG["ldap"]["orggroup_ou"]); } } diff --git a/resources/lib/UnityMailer.php b/resources/lib/UnityMailer.php index c976f30f..9a8d4756 100644 --- a/resources/lib/UnityMailer.php +++ b/resources/lib/UnityMailer.php @@ -10,8 +10,8 @@ */ class UnityMailer extends PHPMailer { - private $template_dir; // location of all email templates - private $override_template_dir; + private $template_dir = __DIR__ . "/../mail"; // location of all email templates + private $override_template_dir = __DIR__ . "/../../deployment/mail_overrides"; private $MSG_LINKREF; private $MSG_SENDER_EMAIL; @@ -23,38 +23,31 @@ class UnityMailer extends PHPMailer private $MSG_PI_APPROVAL_EMAIL; private $MSG_PI_APPROVAL_NAME; - public function __construct( - $template_dir, - $override_template_dir, - $hostname, - $port, - $security, - $user, - $pass, - $ssl_verify, - $msg_linkref, - $msg_sender_email, - $msg_sender_name, - $msg_support_email, - $msg_support_name, - $msg_admin_email, - $msg_admin_name, - $msg_pi_approval_email, - $msg_pi_approval_name - ) { + public function __construct() + { parent::__construct(); $this->isSMTP(); - if (empty($hostname)) { + $this->MSG_LINKREF = CONFIG["site"]["url"] . CONFIG["site"]["prefix"]; + $this->MSG_SENDER_EMAIL = CONFIG["mail"]["sender"]; + $this->MSG_SENDER_NAME = CONFIG["mail"]["sender_name"]; + $this->MSG_SUPPORT_EMAIL = CONFIG["mail"]["support"]; + $this->MSG_SUPPORT_NAME = CONFIG["mail"]["support_name"]; + $this->MSG_ADMIN_EMAIL = CONFIG["mail"]["admin"]; + $this->MSG_ADMIN_NAME = CONFIG["mail"]["admin_name"]; + $this->MSG_PI_APPROVAL_EMAIL = CONFIG["mail"]["pi_approve"]; + $this->MSG_PI_APPROVAL_NAME = CONFIG["mail"]["pi_approve_name"]; + if (empty(CONFIG["smtp"]["host"])) { throw new Exception("SMTP server hostname not set"); } - $this->Host = $hostname; + $this->Host = CONFIG["smtp"]["host"]; - if (empty($port)) { + if (empty(CONFIG["smtp"]["port"])) { throw new Exception("SMTP server port not set"); } - $this->Port = $port; + $this->Port = CONFIG["smtp"]["port"]; + $security = CONFIG["smtp"]["security"]; $security_conf_valid = empty($security) || $security == "tls" || $security == "ssl"; if (!$security_conf_valid) { throw new Exception( @@ -63,18 +56,18 @@ public function __construct( } $this->SMTPSecure = $security; - if (!empty($user)) { + if (!empty(CONFIG["smtp"]["user"])) { $this->SMTPAuth = true; - $this->Username = $user; + $this->Username = CONFIG["smtp"]["user"]; } else { $this->SMTPAuth = false; } - if (!empty($pass)) { - $this->Password = $pass; + if (!empty(CONFIG["smtp"]["pass"])) { + $this->Password = CONFIG["smtp"]["pass"]; } - if ($ssl_verify == "false") { + if (CONFIG["smtp"]["ssl_verify"] == "false") { $this->SMTPOptions = array( 'ssl' => array( 'verify_peer' => false, @@ -83,19 +76,6 @@ public function __construct( ) ); } - - $this->template_dir = $template_dir; - $this->override_template_dir = $override_template_dir; - - $this->MSG_LINKREF = $msg_linkref; - $this->MSG_SENDER_EMAIL = $msg_sender_email; - $this->MSG_SENDER_NAME = $msg_sender_name; - $this->MSG_SUPPORT_EMAIL = $msg_support_email; - $this->MSG_SUPPORT_NAME = $msg_support_name; - $this->MSG_ADMIN_EMAIL = $msg_admin_email; - $this->MSG_ADMIN_NAME = $msg_admin_name; - $this->MSG_PI_APPROVAL_EMAIL = $msg_pi_approval_email; - $this->MSG_PI_APPROVAL_NAME = $msg_pi_approval_name; } public function sendMail($recipients, $template = null, $data = null) diff --git a/resources/lib/UnityRedis.php b/resources/lib/UnityRedis.php index 5a467445..4dcf6693 100644 --- a/resources/lib/UnityRedis.php +++ b/resources/lib/UnityRedis.php @@ -11,8 +11,10 @@ class UnityRedis private $enabled; - public function __construct($host, $port) + public function __construct() { + $host = @CONFIG["redis"]["host"] ?? ""; + $port = @CONFIG["redis"]["port"] ?? ""; if (empty($host)) { $this->enabled = false; } else { diff --git a/resources/lib/UnitySQL.php b/resources/lib/UnitySQL.php index f623c895..dad0e0bd 100644 --- a/resources/lib/UnitySQL.php +++ b/resources/lib/UnitySQL.php @@ -24,9 +24,13 @@ class UnitySQL private $conn; - public function __construct($db_host, $db, $db_user, $db_pass) + public function __construct() { - $this->conn = new PDO("mysql:host=" . $db_host . ";dbname=" . $db, $db_user, $db_pass); + $this->conn = new PDO( + "mysql:host=" . CONFIG["sql"]["host"] . ";dbname=" . CONFIG["sql"]["dbname"], + CONFIG["sql"]["user"], + CONFIG["sql"]["pass"] + ); $this->conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } diff --git a/resources/lib/UnityWebhook.php b/resources/lib/UnityWebhook.php index c2fd5749..3f479eb2 100644 --- a/resources/lib/UnityWebhook.php +++ b/resources/lib/UnityWebhook.php @@ -4,24 +4,16 @@ class UnityWebhook { - private $template_dir; - private $override_template_dir; - private $url; + private $template_dir = __DIR__ . "/../mail"; + private $override_template_dir = __DIR__ . "/../../deployment/mail_overrides"; + private $url = CONFIG["webhook"]["url"]; private $MSG_LINKREF; private $Subject; // set by template - public function __construct( - $template_dir, - $override_template_dir, - $url, - $msg_linkref - ) { - $this->template_dir = $template_dir; - $this->override_template_dir = $override_template_dir; - $this->url = $url; - $this->MSG_LINKREF = $msg_linkref; + public function __construct() + { + $this->MSG_LINKREF = CONFIG["site"]["url"] . CONFIG["site"]["prefix"]; } - public function htmlToMarkdown($html) { // Define regex patterns for each markdown format diff --git a/resources/templates/footer.php b/resources/templates/footer.php index 9c74c223..e5cd3d2c 100644 --- a/resources/templates/footer.php +++ b/resources/templates/footer.php @@ -4,13 +4,13 @@