forked from Business/BinStack
		
	Make settings.php an array, not a bunch of defines
This commit is contained in:
		
							parent
							
								
									f1a85f47fd
								
							
						
					
					
						commit
						c179ed7ebb
					
				
							
								
								
									
										10
									
								
								app.php
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								app.php
									
									
									
									
									
								
							| @ -39,7 +39,7 @@ header("Link: <static/js/bootstrap.bundle.min.js>; rel=preload; as=script", fals | |||||||
|         <meta http-equiv="X-UA-Compatible" content="IE=edge"> |         <meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||||||
|         <meta name="viewport" content="width=device-width, initial-scale=1"> |         <meta name="viewport" content="width=device-width, initial-scale=1"> | ||||||
| 
 | 
 | ||||||
|         <title><?php echo SITE_TITLE; ?></title>
 |         <title><?php echo $SETTINGS['site_title']; ?></title>
 | ||||||
| 
 | 
 | ||||||
|         <link rel="icon" href="static/img/logo.svg"> |         <link rel="icon" href="static/img/logo.svg"> | ||||||
| 
 | 
 | ||||||
| @ -127,7 +127,7 @@ END; | |||||||
|             </button> |             </button> | ||||||
|             <a class="navbar-brand py-0 mr-auto" href="app.php"> |             <a class="navbar-brand py-0 mr-auto" href="app.php"> | ||||||
|                 <img src="static/img/logo.svg" alt="" class="d-none d-<?php echo $navbar_breakpoint; ?>-inline brand-img py-0" /> |                 <img src="static/img/logo.svg" alt="" class="d-none d-<?php echo $navbar_breakpoint; ?>-inline brand-img py-0" /> | ||||||
|                 <?php echo SITE_TITLE; ?>
 |                 <?php echo $SETTINGS['site_title']; ?>
 | ||||||
|             </a> |             </a> | ||||||
| 
 | 
 | ||||||
|             <div class="collapse navbar-collapse py-0" id="navbar-collapse"> |             <div class="collapse navbar-collapse py-0" id="navbar-collapse"> | ||||||
| @ -163,7 +163,7 @@ END; | |||||||
|                 </div> |                 </div> | ||||||
|                 <div class="navbar-nav ml-auto py-0" id="navbar-right"> |                 <div class="navbar-nav ml-auto py-0" id="navbar-right"> | ||||||
|                     <span class="nav-item py-<?php echo $navbar_breakpoint; ?>-0"> |                     <span class="nav-item py-<?php echo $navbar_breakpoint; ?>-0"> | ||||||
|                         <a class="nav-link py-<?php echo $navbar_breakpoint; ?>-0" href="<?php echo PORTAL_URL; ?>"> |                         <a class="nav-link py-<?php echo $navbar_breakpoint; ?>-0" href="<?php echo $SETTINGS['accounthub']['home']; ?>"> | ||||||
|                             <i class="fas fa-user fa-fw"></i><span> <?php echo $_SESSION['realname'] ?></span>
 |                             <i class="fas fa-user fa-fw"></i><span> <?php echo $_SESSION['realname'] ?></span>
 | ||||||
|                         </a> |                         </a> | ||||||
|                     </span> |                     </span> | ||||||
| @ -183,8 +183,8 @@ END; | |||||||
|                 ?>
 |                 ?>
 | ||||||
|             </div> |             </div> | ||||||
|             <div class="footer"> |             <div class="footer"> | ||||||
|                 <?php echo FOOTER_TEXT; ?><br />
 |                 <?php echo $SETTINGS['footer_text']; ?><br />
 | ||||||
|                 Copyright © <?php echo date('Y'); ?> <?php echo COPYRIGHT_NAME; ?>
 |                 Copyright © <?php echo date('Y'); ?> <?php echo $SETTINGS['copyright']; ?>
 | ||||||
|             </div> |             </div> | ||||||
|         </div> |         </div> | ||||||
|         <script src="static/js/jquery-3.3.1.min.js"></script> |         <script src="static/js/jquery-3.3.1.min.js"></script> | ||||||
|  | |||||||
							
								
								
									
										16
									
								
								index.php
									
									
									
									
									
								
							
							
						
						
									
										16
									
								
								index.php
									
									
									
									
									
								
							| @ -21,7 +21,7 @@ if (Login::checkLoginServer()) { | |||||||
|     if (empty($VARS['progress'])) { |     if (empty($VARS['progress'])) { | ||||||
|         // Easy way to remove "undefined" warnings.
 |         // Easy way to remove "undefined" warnings.
 | ||||||
|     } else if ($VARS['progress'] == "1") { |     } else if ($VARS['progress'] == "1") { | ||||||
|         if (!CAPTCHA_ENABLED || (CAPTCHA_ENABLED && Login::verifyCaptcha($VARS['captcheck_session_code'], $VARS['captcheck_selected_answer'], CAPTCHA_SERVER . "/api.php"))) { |         if (!$SETTINGS['captcha']['enabled'] || ($SETTINGS['captcha']['enabled'] && Login::verifyCaptcha($VARS['captcheck_session_code'], $VARS['captcheck_selected_answer'], $SETTINGS['captcha']['server'] . "/api.php"))) { | ||||||
|             $autherror = ""; |             $autherror = ""; | ||||||
|             $user = User::byUsername($VARS['username']); |             $user = User::byUsername($VARS['username']); | ||||||
|             if ($user->exists()) { |             if ($user->exists()) { | ||||||
| @ -41,7 +41,7 @@ if (Login::checkLoginServer()) { | |||||||
|                         break; |                         break; | ||||||
|                     case "ALERT_ON_ACCESS": |                     case "ALERT_ON_ACCESS": | ||||||
|                         $mail_resp = $user->sendAlertEmail(); |                         $mail_resp = $user->sendAlertEmail(); | ||||||
|                         if (DEBUG) { |                         if ($SETTINGS['debug']) { | ||||||
|                             var_dump($mail_resp); |                             var_dump($mail_resp); | ||||||
|                         } |                         } | ||||||
|                         $username_ok = true; |                         $username_ok = true; | ||||||
| @ -105,15 +105,15 @@ header("Link: <static/js/bootstrap.bundle.min.js>; rel=preload; as=script", fals | |||||||
|         <meta http-equiv="X-UA-Compatible" content="IE=edge"> |         <meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||||||
|         <meta name="viewport" content="width=device-width, initial-scale=1"> |         <meta name="viewport" content="width=device-width, initial-scale=1"> | ||||||
| 
 | 
 | ||||||
|         <title><?php echo SITE_TITLE; ?></title>
 |         <title><?php echo $SETTINGS['site_title']; ?></title>
 | ||||||
| 
 | 
 | ||||||
|         <link rel="icon" href="static/img/logo.svg"> |         <link rel="icon" href="static/img/logo.svg"> | ||||||
| 
 | 
 | ||||||
|         <link href="static/css/bootstrap.min.css" rel="stylesheet"> |         <link href="static/css/bootstrap.min.css" rel="stylesheet"> | ||||||
|         <link href="static/css/material-color/material-color.min.css" rel="stylesheet"> |         <link href="static/css/material-color/material-color.min.css" rel="stylesheet"> | ||||||
|         <link href="static/css/index.css" rel="stylesheet"> |         <link href="static/css/index.css" rel="stylesheet"> | ||||||
|         <?php if (CAPTCHA_ENABLED) { ?>
 |         <?php if ($SETTINGS['captcha']['enabled']) { ?>
 | ||||||
|             <script src="<?php echo CAPTCHA_SERVER ?>/captcheck.dist.js"></script> |             <script src="<?php echo $SETTINGS['captcha']['server'] ?>/captcheck.dist.js"></script> | ||||||
|         <?php } ?>
 |         <?php } ?>
 | ||||||
|     </head> |     </head> | ||||||
|     <body> |     <body> | ||||||
| @ -140,7 +140,7 @@ header("Link: <static/js/bootstrap.bundle.min.js>; rel=preload; as=script", fals | |||||||
|                             ?>
 |                             ?>
 | ||||||
|                             <input type="text" class="form-control" name="username" placeholder="<?php $Strings->get("username"); ?>" required="required" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" autofocus /><br /> |                             <input type="text" class="form-control" name="username" placeholder="<?php $Strings->get("username"); ?>" required="required" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" autofocus /><br /> | ||||||
|                             <input type="password" class="form-control" name="password" placeholder="<?php $Strings->get("password"); ?>" required="required" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" /><br /> |                             <input type="password" class="form-control" name="password" placeholder="<?php $Strings->get("password"); ?>" required="required" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" /><br /> | ||||||
|                             <?php if (CAPTCHA_ENABLED) { ?>
 |                             <?php if ($SETTINGS['captcha']['enabled']) { ?>
 | ||||||
|                                 <div class="captcheck_container" data-stylenonce="<?php echo $SECURE_NONCE; ?>"></div> |                                 <div class="captcheck_container" data-stylenonce="<?php echo $SECURE_NONCE; ?>"></div> | ||||||
|                                 <br /> |                                 <br /> | ||||||
|                             <?php } ?>
 |                             <?php } ?>
 | ||||||
| @ -165,8 +165,8 @@ header("Link: <static/js/bootstrap.bundle.min.js>; rel=preload; as=script", fals | |||||||
|             </div> |             </div> | ||||||
|         </div> |         </div> | ||||||
|         <div class="footer"> |         <div class="footer"> | ||||||
|             <?php echo FOOTER_TEXT; ?><br />
 |             <?php echo $SETTINGS['footer_text']; ?><br />
 | ||||||
|             Copyright © <?php echo date('Y'); ?> <?php echo COPYRIGHT_NAME; ?>
 |             Copyright © <?php echo date('Y'); ?> <?php echo $SETTINGS['copyright']; ?>
 | ||||||
|         </div> |         </div> | ||||||
|     </div> |     </div> | ||||||
|     <script src="static/js/jquery-3.3.1.min.js"></script> |     <script src="static/js/jquery-3.3.1.min.js"></script> | ||||||
|  | |||||||
| @ -9,9 +9,11 @@ | |||||||
| class AccountHubApi { | class AccountHubApi { | ||||||
| 
 | 
 | ||||||
|     public static function get(string $action, array $data = null, bool $throwex = false) { |     public static function get(string $action, array $data = null, bool $throwex = false) { | ||||||
|  |         global $SETTINGS; | ||||||
|  | 
 | ||||||
|         $content = [ |         $content = [ | ||||||
|             "action" => $action, |             "action" => $action, | ||||||
|             "key" => PORTAL_KEY |             "key" => $SETTINGS['accounthub']['key'] | ||||||
|         ]; |         ]; | ||||||
|         if (!is_null($data)) { |         if (!is_null($data)) { | ||||||
|             $content = array_merge($content, $data); |             $content = array_merge($content, $data); | ||||||
| @ -27,7 +29,7 @@ class AccountHubApi { | |||||||
|         ]; |         ]; | ||||||
| 
 | 
 | ||||||
|         $context = stream_context_create($options); |         $context = stream_context_create($options); | ||||||
|         $result = file_get_contents(PORTAL_API, false, $context); |         $result = file_get_contents($SETTINGS['accounthub']['api'], false, $context); | ||||||
|         $response = json_decode($result, true); |         $response = json_decode($result, true); | ||||||
|         if ($result === false || !AccountHubApi::checkHttpRespCode($http_response_header) || json_last_error() != JSON_ERROR_NONE) { |         if ($result === false || !AccountHubApi::checkHttpRespCode($http_response_header) || json_last_error() != JSON_ERROR_NONE) { | ||||||
|             if ($throwex) { |             if ($throwex) { | ||||||
|  | |||||||
| @ -140,8 +140,12 @@ class User { | |||||||
|         } |         } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     function sendAlertEmail(string $appname = SITE_TITLE) { |     function sendAlertEmail(string $appname = null) { | ||||||
|         $resp = AccountHubApi::get("alertemail", ['username' => $this->username, 'appname' => SITE_TITLE]); |         global $SETTINGS; | ||||||
|  |         if (is_null($appname)) { | ||||||
|  |             $appname = $SETTINGS['site_title']; | ||||||
|  |         } | ||||||
|  |         $resp = AccountHubApi::get("alertemail", ['username' => $this->username, 'appname' => $SETTINGS['site_title']]); | ||||||
| 
 | 
 | ||||||
|         if ($resp['status'] == "OK") { |         if ($resp['status'] == "OK") { | ||||||
|             return true; |             return true; | ||||||
|  | |||||||
							
								
								
									
										22
									
								
								required.php
									
									
									
									
									
								
							
							
						
						
									
										22
									
								
								required.php
									
									
									
									
									
								
							| @ -32,7 +32,7 @@ session_start(); // stick some cookies in it | |||||||
| // renew session cookie
 | // renew session cookie
 | ||||||
| setcookie(session_name(), session_id(), time() + $session_length, "/", false, false); | setcookie(session_name(), session_id(), time() + $session_length, "/", false, false); | ||||||
| 
 | 
 | ||||||
| $captcha_server = (CAPTCHA_ENABLED === true ? preg_replace("/http(s)?:\/\//", "", CAPTCHA_SERVER) : ""); | $captcha_server = ($SETTINGS['captcha']['enabled'] === true ? preg_replace("/http(s)?:\/\//", "", $SETTINGS['captcha']['server']) : ""); | ||||||
| if ($_SESSION['mobile'] === TRUE) { | if ($_SESSION['mobile'] === TRUE) { | ||||||
|     header("Content-Security-Policy: " |     header("Content-Security-Policy: " | ||||||
|             . "default-src 'self';" |             . "default-src 'self';" | ||||||
| @ -69,7 +69,7 @@ foreach ($libs as $lib) { | |||||||
|     require_once $lib; |     require_once $lib; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| $Strings = new Strings(LANGUAGE); | $Strings = new Strings($SETTINGS['language']); | ||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
|  * Kill off the running process and spit out an error message |  * Kill off the running process and spit out an error message | ||||||
| @ -93,7 +93,7 @@ function sendError($error) { | |||||||
|             . "<p>" . htmlspecialchars($error) . "</p>"); |             . "<p>" . htmlspecialchars($error) . "</p>"); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| date_default_timezone_set(TIMEZONE); | date_default_timezone_set($SETTINGS['timezone']); | ||||||
| 
 | 
 | ||||||
| // Database settings
 | // Database settings
 | ||||||
| // Also inits database and stuff
 | // Also inits database and stuff
 | ||||||
| @ -102,12 +102,12 @@ use Medoo\Medoo; | |||||||
| $database; | $database; | ||||||
| try { | try { | ||||||
|     $database = new Medoo([ |     $database = new Medoo([ | ||||||
|         'database_type' => DB_TYPE, |         'database_type' => $SETTINGS['database']['type'], | ||||||
|         'database_name' => DB_NAME, |         'database_name' => $SETTINGS['database']['name'], | ||||||
|         'server' => DB_SERVER, |         'server' => $SETTINGS['database']['server'], | ||||||
|         'username' => DB_USER, |         'username' => $SETTINGS['database']['user'], | ||||||
|         'password' => DB_PASS, |         'password' => $SETTINGS['database']['password'], | ||||||
|         'charset' => DB_CHARSET |         'charset' => $SETTINGS['database']['charset'] | ||||||
|     ]); |     ]); | ||||||
| } catch (Exception $ex) { | } catch (Exception $ex) { | ||||||
|     //header('HTTP/1.1 500 Internal Server Error');
 |     //header('HTTP/1.1 500 Internal Server Error');
 | ||||||
| @ -115,7 +115,7 @@ try { | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| if (!DEBUG) { | if (!$SETTINGS['debug']) { | ||||||
|     error_reporting(0); |     error_reporting(0); | ||||||
| } else { | } else { | ||||||
|     error_reporting(E_ALL); |     error_reporting(E_ALL); | ||||||
| @ -158,7 +158,7 @@ function checkDBError($specials = []) { | |||||||
| 
 | 
 | ||||||
| function redirectIfNotLoggedIn() { | function redirectIfNotLoggedIn() { | ||||||
|     if ($_SESSION['loggedin'] !== TRUE) { |     if ($_SESSION['loggedin'] !== TRUE) { | ||||||
|         header('Location: ' . URL . '/index.php'); |         header('Location: ' . $SETTINGS['url'] . '/index.php'); | ||||||
|         die(); |         die(); | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | |||||||
| @ -1,47 +1,34 @@ | |||||||
| <?php | <?php | ||||||
| 
 | 
 | ||||||
| /* This Source Code Form is subject to the terms of the Mozilla Public | /* | ||||||
|  |  * This Source Code Form is subject to the terms of the Mozilla Public | ||||||
|  * License, v. 2.0. If a copy of the MPL was not distributed with this |  * License, v. 2.0. If a copy of the MPL was not distributed with this | ||||||
|  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |  * file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||||||
|  |  */ | ||||||
| 
 | 
 | ||||||
| // Whether to show debugging data in output.
 | $SETTINGS = [ | ||||||
| // DO NOT SET TO TRUE IN PRODUCTION!!!
 |     "debug" => false, | ||||||
| define("DEBUG", false); |     "database" => [ | ||||||
| 
 |         "type" => "mysql", | ||||||
| // Database connection settings
 |         "name" => "app", | ||||||
| // See http://medoo.in/api/new for info
 |         "server" => "localhost", | ||||||
| define("DB_TYPE", "mysql"); |         "user" => "app", | ||||||
| define("DB_NAME", "app"); |         "password" => "", | ||||||
| define("DB_SERVER", "localhost"); |         "charset" => "utf8" | ||||||
| define("DB_USER", "app"); |     ], | ||||||
| define("DB_PASS", ""); |     "site_title" => "Web App Template", | ||||||
| define("DB_CHARSET", "utf8"); |     "accounthub" => [ | ||||||
| 
 |         "api" => "http://localhost/accounthub/api/", | ||||||
| // Name of the app.
 |         "home" => "http://localhost/accounthub/home.php", | ||||||
| define("SITE_TITLE", "Web App Template"); |         "key" => "123" | ||||||
| 
 |     ], | ||||||
| 
 |     "timezone" => "America/Denver", | ||||||
| // URL of the AccountHub API endpoint
 |     "captcha" => [ | ||||||
| define("PORTAL_API", "http://localhost/accounthub/api/"); |         "enabled" => false, | ||||||
| // URL of the AccountHub home page
 |         "server" => "https://captcheck.netsyms.com" | ||||||
| define("PORTAL_URL", "http://localhost/accounthub/home.php"); |     ], | ||||||
| // AccountHub API Key
 |     "language" => "en", | ||||||
| define("PORTAL_KEY", "123"); |     "footer_text" => "", | ||||||
| 
 |     "copyright" => "Netsyms Technologies", | ||||||
| // For supported values, see http://php.net/manual/en/timezones.php
 |     "url" => "." | ||||||
| define("TIMEZONE", "America/Denver"); | ]; | ||||||
| 
 |  | ||||||
| // Base URL for site links.
 |  | ||||||
| define('URL', '.'); |  | ||||||
| 
 |  | ||||||
| // Use Captcheck on login screen
 |  | ||||||
| // https://captcheck.netsyms.com
 |  | ||||||
| define("CAPTCHA_ENABLED", FALSE); |  | ||||||
| define('CAPTCHA_SERVER', 'https://captcheck.netsyms.com'); |  | ||||||
| 
 |  | ||||||
| // See lang folder for language options
 |  | ||||||
| define('LANGUAGE', "en_us"); |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| define("FOOTER_TEXT", ""); |  | ||||||
| define("COPYRIGHT_NAME", "Netsyms Technologies"); |  | ||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user