Browse Source

Make settings.php an array, not a bunch of defines

master
Skylar Ittner 10 months ago
parent
commit
c179ed7ebb
6 changed files with 65 additions and 72 deletions
  1. 5
    5
      app.php
  2. 8
    8
      index.php
  3. 4
    2
      lib/AccountHubApi.lib.php
  4. 6
    2
      lib/User.lib.php
  5. 11
    11
      required.php
  6. 31
    44
      settings.template.php

+ 5
- 5
app.php View File

@@ -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 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">

@@ -127,7 +127,7 @@ END;
</button>
<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" />
<?php echo SITE_TITLE; ?>
<?php echo $SETTINGS['site_title']; ?>
</a>

<div class="collapse navbar-collapse py-0" id="navbar-collapse">
@@ -163,7 +163,7 @@ END;
</div>
<div class="navbar-nav ml-auto py-0" id="navbar-right">
<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>&nbsp;<?php echo $_SESSION['realname'] ?></span>
</a>
</span>
@@ -183,8 +183,8 @@ END;
?>
</div>
<div class="footer">
<?php echo FOOTER_TEXT; ?><br />
Copyright &copy; <?php echo date('Y'); ?> <?php echo COPYRIGHT_NAME; ?>
<?php echo $SETTINGS['footer_text']; ?><br />
Copyright &copy; <?php echo date('Y'); ?> <?php echo $SETTINGS['copyright']; ?>
</div>
</div>
<script src="static/js/jquery-3.3.1.min.js"></script>

+ 8
- 8
index.php View File

@@ -21,7 +21,7 @@ if (Login::checkLoginServer()) {
if (empty($VARS['progress'])) {
// Easy way to remove "undefined" warnings.
} 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 = "";
$user = User::byUsername($VARS['username']);
if ($user->exists()) {
@@ -41,7 +41,7 @@ if (Login::checkLoginServer()) {
break;
case "ALERT_ON_ACCESS":
$mail_resp = $user->sendAlertEmail();
if (DEBUG) {
if ($SETTINGS['debug']) {
var_dump($mail_resp);
}
$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 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 href="static/css/bootstrap.min.css" rel="stylesheet">
<link href="static/css/material-color/material-color.min.css" rel="stylesheet">
<link href="static/css/index.css" rel="stylesheet">
<?php if (CAPTCHA_ENABLED) { ?>
<script src="<?php echo CAPTCHA_SERVER ?>/captcheck.dist.js"></script>
<?php if ($SETTINGS['captcha']['enabled']) { ?>
<script src="<?php echo $SETTINGS['captcha']['server'] ?>/captcheck.dist.js"></script>
<?php } ?>
</head>
<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="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>
<br />
<?php } ?>
@@ -165,8 +165,8 @@ header("Link: <static/js/bootstrap.bundle.min.js>; rel=preload; as=script", fals
</div>
</div>
<div class="footer">
<?php echo FOOTER_TEXT; ?><br />
Copyright &copy; <?php echo date('Y'); ?> <?php echo COPYRIGHT_NAME; ?>
<?php echo $SETTINGS['footer_text']; ?><br />
Copyright &copy; <?php echo date('Y'); ?> <?php echo $SETTINGS['copyright']; ?>
</div>
</div>
<script src="static/js/jquery-3.3.1.min.js"></script>

+ 4
- 2
lib/AccountHubApi.lib.php View File

@@ -9,9 +9,11 @@
class AccountHubApi {

public static function get(string $action, array $data = null, bool $throwex = false) {
global $SETTINGS;

$content = [
"action" => $action,
"key" => PORTAL_KEY
"key" => $SETTINGS['accounthub']['key']
];
if (!is_null($data)) {
$content = array_merge($content, $data);
@@ -27,7 +29,7 @@ class AccountHubApi {
];

$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);
if ($result === false || !AccountHubApi::checkHttpRespCode($http_response_header) || json_last_error() != JSON_ERROR_NONE) {
if ($throwex) {

+ 6
- 2
lib/User.lib.php View File

@@ -140,8 +140,12 @@ class User {
}
}

function sendAlertEmail(string $appname = SITE_TITLE) {
$resp = AccountHubApi::get("alertemail", ['username' => $this->username, 'appname' => SITE_TITLE]);
function sendAlertEmail(string $appname = null) {
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") {
return true;

+ 11
- 11
required.php View File

@@ -32,7 +32,7 @@ session_start(); // stick some cookies in it
// renew session cookie
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) {
header("Content-Security-Policy: "
. "default-src 'self';"
@@ -69,7 +69,7 @@ foreach ($libs as $lib) {
require_once $lib;
}

$Strings = new Strings(LANGUAGE);
$Strings = new Strings($SETTINGS['language']);

/**
* Kill off the running process and spit out an error message
@@ -93,7 +93,7 @@ function sendError($error) {
. "<p>" . htmlspecialchars($error) . "</p>");
}

date_default_timezone_set(TIMEZONE);
date_default_timezone_set($SETTINGS['timezone']);

// Database settings
// Also inits database and stuff
@@ -102,12 +102,12 @@ use Medoo\Medoo;
$database;
try {
$database = new Medoo([
'database_type' => DB_TYPE,
'database_name' => DB_NAME,
'server' => DB_SERVER,
'username' => DB_USER,
'password' => DB_PASS,
'charset' => DB_CHARSET
'database_type' => $SETTINGS['database']['type'],
'database_name' => $SETTINGS['database']['name'],
'server' => $SETTINGS['database']['server'],
'username' => $SETTINGS['database']['user'],
'password' => $SETTINGS['database']['password'],
'charset' => $SETTINGS['database']['charset']
]);
} catch (Exception $ex) {
//header('HTTP/1.1 500 Internal Server Error');
@@ -115,7 +115,7 @@ try {
}


if (!DEBUG) {
if (!$SETTINGS['debug']) {
error_reporting(0);
} else {
error_reporting(E_ALL);
@@ -158,7 +158,7 @@ function checkDBError($specials = []) {

function redirectIfNotLoggedIn() {
if ($_SESSION['loggedin'] !== TRUE) {
header('Location: ' . URL . '/index.php');
header('Location: ' . $SETTINGS['url'] . '/index.php');
die();
}
}

+ 31
- 44
settings.template.php View File

@@ -1,47 +1,34 @@
<?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
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

// Whether to show debugging data in output.
// DO NOT SET TO TRUE IN PRODUCTION!!!
define("DEBUG", false);

// Database connection settings
// See http://medoo.in/api/new for info
define("DB_TYPE", "mysql");
define("DB_NAME", "app");
define("DB_SERVER", "localhost");
define("DB_USER", "app");
define("DB_PASS", "");
define("DB_CHARSET", "utf8");

// Name of the app.
define("SITE_TITLE", "Web App Template");


// URL of the AccountHub API endpoint
define("PORTAL_API", "http://localhost/accounthub/api/");
// URL of the AccountHub home page
define("PORTAL_URL", "http://localhost/accounthub/home.php");
// AccountHub API Key
define("PORTAL_KEY", "123");

// For supported values, see http://php.net/manual/en/timezones.php
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");
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

$SETTINGS = [
"debug" => false,
"database" => [
"type" => "mysql",
"name" => "app",
"server" => "localhost",
"user" => "app",
"password" => "",
"charset" => "utf8"
],
"site_title" => "Web App Template",
"accounthub" => [
"api" => "http://localhost/accounthub/api/",
"home" => "http://localhost/accounthub/home.php",
"key" => "123"
],
"timezone" => "America/Denver",
"captcha" => [
"enabled" => false,
"server" => "https://captcheck.netsyms.com"
],
"language" => "en",
"footer_text" => "",
"copyright" => "Netsyms Technologies",
"url" => "."
];

Loading…
Cancel
Save