functions.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. // Set UTC timeone
  3. date_default_timezone_set("UTC");
  4. // Autoload frameworks
  5. require_once(__DIR__ . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php');
  6. // Include all function files
  7. foreach (glob(__DIR__ . DIRECTORY_SEPARATOR . 'functions' . DIRECTORY_SEPARATOR . '*.php') as $filename) {
  8. require_once $filename;
  9. }
  10. // Set Root Directory
  11. $GLOBALS['root'] = dirname(__DIR__, 1);
  12. $GLOBALS['uuid'] = '';
  13. $GLOBALS['rememberMeDays'] = '99';
  14. $GLOBALS['timeExecution'] = timeExecution();
  15. // Add in default and custom settings
  16. configLazy();
  17. // Define Logs and files after db location is set
  18. if (isset($GLOBALS['dbLocation'])) {
  19. $GLOBALS['organizrLog'] = $GLOBALS['dbLocation'] . 'organizrLog.json';
  20. $GLOBALS['organizrLoginLog'] = $GLOBALS['dbLocation'] . 'organizrLoginLog.json';
  21. $GLOBALS['paths'] = array(
  22. 'Root Folder' => dirname(__DIR__, 2) . DIRECTORY_SEPARATOR,
  23. 'API Folder' => dirname(__DIR__, 1) . DIRECTORY_SEPARATOR,
  24. 'DB Folder' => $GLOBALS['dbLocation']
  25. );
  26. if (($GLOBALS['uuid'] == '')) {
  27. $uuid = gen_uuid();
  28. $GLOBALS['uuid'] = $uuid;
  29. updateConfig(array('uuid' => $uuid));
  30. }
  31. if ($GLOBALS['docker']) {
  32. $getBranch = file_get_contents(dirname(__DIR__, 1) . DIRECTORY_SEPARATOR . 'Docker.txt');
  33. $getBranch = (empty($getBranch)) ? 'v2-master' : trim($getBranch);
  34. $GLOBALS['branch'] = $getBranch;
  35. if (!isset($GLOBALS['commit']) || $GLOBALS['commit'] == 'n/a') {
  36. $GLOBALS['commit'] = $GLOBALS['quickCommit'];
  37. }
  38. }
  39. // Oauth?
  40. if($GLOBALS['authProxyEnabled'] && $GLOBALS['authProxyHeaderName'] !== '' && $GLOBALS['authProxyWhitelist'] !== ''){
  41. if(isset(getallheaders()[$GLOBALS['authProxyHeaderName']])){
  42. if(isset($_COOKIE['organizrOAuth'])){
  43. coookie('delete','organizrOAuth');
  44. }else{
  45. coookieSeconds('set', 'organizrOAuth', 'true', 60000);
  46. }
  47. }
  48. }
  49. //Upgrade Check
  50. upgradeCheck();
  51. }
  52. // Reset RememberMe if zero
  53. $GLOBALS['rememberMeDays'] = ($GLOBALS['rememberMeDays'] == '0') ? '99' : $GLOBALS['rememberMeDays'];
  54. // Cookie name
  55. $GLOBALS['cookieName'] = $GLOBALS['uuid'] !== '' ? 'organizr_token_' . $GLOBALS['uuid'] : 'organizr_token_temp';
  56. // Validate Token if set and set guest if not - sets GLOBALS
  57. getOrganizrUserToken();
  58. // Include all pages files
  59. foreach (glob(__DIR__ . DIRECTORY_SEPARATOR . 'pages' . DIRECTORY_SEPARATOR . "*.php") as $filename) {
  60. require_once $filename;
  61. }
  62. // Include all custom pages files
  63. foreach (glob(__DIR__ . DIRECTORY_SEPARATOR . 'pages' . DIRECTORY_SEPARATOR . 'custom' . DIRECTORY_SEPARATOR . "*.php") as $filename) {
  64. require_once $filename;
  65. }
  66. // Include all plugin files
  67. foreach (glob(__DIR__ . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . "*.php") as $filename) {
  68. require_once $filename;
  69. }