2017-04-06 19:18:51 +02:00
|
|
|
<?php
|
2017-04-07 00:05:28 +02:00
|
|
|
/* μlogger
|
|
|
|
*
|
|
|
|
* Copyright(C) 2017 Bartek Fabiszewski (www.fabiszewski.net)
|
|
|
|
*
|
|
|
|
* This is free software; you can redistribute it and/or modify it under
|
|
|
|
* the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2017-04-06 19:18:51 +02:00
|
|
|
|
2017-04-18 09:25:21 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialize on file include
|
|
|
|
*/
|
|
|
|
uConfig::init();
|
|
|
|
|
2017-04-09 23:35:55 +02:00
|
|
|
/**
|
|
|
|
* Handles config values
|
|
|
|
*/
|
|
|
|
class uConfig {
|
2019-04-13 19:45:51 +02:00
|
|
|
/**
|
|
|
|
* @var string Version number
|
|
|
|
*/
|
2019-01-30 23:21:01 +01:00
|
|
|
static $version = "1.0-beta";
|
2017-04-06 19:18:51 +02:00
|
|
|
|
2019-04-13 19:45:51 +02:00
|
|
|
/**
|
|
|
|
* @var string Default map drawing framework
|
|
|
|
*/
|
2017-04-06 19:18:51 +02:00
|
|
|
static $mapapi = "openlayers";
|
|
|
|
|
2019-04-13 19:45:51 +02:00
|
|
|
/**
|
|
|
|
* @var string|null Google maps key
|
|
|
|
*/
|
2017-04-07 16:06:05 +02:00
|
|
|
static $gkey = null;
|
|
|
|
|
2019-04-13 19:45:51 +02:00
|
|
|
/**
|
|
|
|
* @var array Openlayers additional map layers
|
|
|
|
*/
|
2017-09-11 22:10:24 +02:00
|
|
|
static $ol_layers = [];
|
2017-04-06 19:18:51 +02:00
|
|
|
|
2019-04-13 19:45:51 +02:00
|
|
|
/**
|
|
|
|
* @var float Default latitude for initial map
|
|
|
|
*/
|
2017-04-06 19:18:51 +02:00
|
|
|
static $init_latitude = 52.23;
|
2019-04-13 19:45:51 +02:00
|
|
|
/**
|
|
|
|
* @var float Default longitude for initial map
|
|
|
|
*/
|
2017-04-06 19:18:51 +02:00
|
|
|
static $init_longitude = 21.01;
|
|
|
|
|
2019-04-13 19:45:51 +02:00
|
|
|
/**
|
|
|
|
* @var string Database dsn
|
|
|
|
*/
|
|
|
|
static $dbdsn = "";
|
|
|
|
/**
|
|
|
|
* @var string Database user
|
|
|
|
*/
|
|
|
|
static $dbuser = "";
|
|
|
|
/**
|
|
|
|
* @var string Database pass
|
|
|
|
*/
|
|
|
|
static $dbpass = "";
|
|
|
|
/**
|
|
|
|
* @var string Optional table names prefix, eg. "ulogger_"
|
|
|
|
*/
|
|
|
|
static $dbprefix = "";
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var bool Require login/password authentication
|
|
|
|
*/
|
2017-04-08 09:57:15 +02:00
|
|
|
static $require_authentication = true;
|
2017-04-06 19:18:51 +02:00
|
|
|
|
2019-04-13 19:45:51 +02:00
|
|
|
/**
|
|
|
|
* @var bool All users tracks are visible to authenticated user
|
|
|
|
*/
|
2017-04-08 09:57:15 +02:00
|
|
|
static $public_tracks = false;
|
2017-04-06 19:18:51 +02:00
|
|
|
|
2019-04-13 19:45:51 +02:00
|
|
|
/**
|
|
|
|
* @var string Admin user who has access to all users locations
|
|
|
|
* none if empty
|
|
|
|
*/
|
2017-04-06 19:18:51 +02:00
|
|
|
static $admin_user = "";
|
|
|
|
|
2019-04-13 19:45:51 +02:00
|
|
|
/**
|
|
|
|
* @var int Miniumum required length of user password
|
|
|
|
*/
|
2017-04-14 15:55:00 +02:00
|
|
|
static $pass_lenmin = 12;
|
|
|
|
|
2019-04-13 19:45:51 +02:00
|
|
|
/**
|
|
|
|
* @var int Required strength of user password
|
|
|
|
* 0 = no requirements,
|
|
|
|
* 1 = require mixed case letters (lower and upper),
|
|
|
|
* 2 = require mixed case and numbers
|
|
|
|
* 3 = require mixed case, numbers and non-alphanumeric characters
|
|
|
|
*/
|
2017-04-14 15:55:00 +02:00
|
|
|
static $pass_strength = 2;
|
|
|
|
|
2019-04-13 19:45:51 +02:00
|
|
|
/**
|
|
|
|
* @var int Default interval in seconds for live auto reload
|
|
|
|
*/
|
2017-04-06 19:18:51 +02:00
|
|
|
static $interval = 10;
|
|
|
|
|
2019-04-13 19:45:51 +02:00
|
|
|
/**
|
|
|
|
* @var string Default language code
|
|
|
|
*/
|
2017-04-06 19:18:51 +02:00
|
|
|
static $lang = "en";
|
|
|
|
|
2019-04-13 19:45:51 +02:00
|
|
|
/**
|
|
|
|
* @var string Default units
|
|
|
|
*/
|
2017-04-06 19:18:51 +02:00
|
|
|
static $units = "metric";
|
|
|
|
|
2019-04-13 19:45:51 +02:00
|
|
|
/**
|
|
|
|
* @var int Stroke weight
|
|
|
|
*/
|
2018-06-22 19:38:45 +01:00
|
|
|
static $strokeWeight = 2;
|
2019-04-13 19:45:51 +02:00
|
|
|
/**
|
|
|
|
* @var string Stroke color
|
|
|
|
*/
|
2018-06-22 19:38:45 +01:00
|
|
|
static $strokeColor = '#ff0000';
|
2019-04-13 19:45:51 +02:00
|
|
|
/**
|
|
|
|
* @var int Stroke opacity
|
|
|
|
*/
|
2018-06-22 19:38:45 +01:00
|
|
|
static $strokeOpacity = 1;
|
2019-01-30 22:07:50 +01:00
|
|
|
|
2017-04-06 19:18:51 +02:00
|
|
|
private static $fileLoaded = false;
|
|
|
|
|
2017-04-18 09:25:21 +02:00
|
|
|
private static $initialized = false;
|
|
|
|
|
2017-04-09 23:35:55 +02:00
|
|
|
/**
|
2017-04-18 09:25:21 +02:00
|
|
|
* Static initializer
|
2017-04-09 23:35:55 +02:00
|
|
|
*/
|
2017-04-18 09:25:21 +02:00
|
|
|
static public function init() {
|
|
|
|
if (!self::$initialized) {
|
|
|
|
self::setFromFile();
|
|
|
|
self::setFromCookies();
|
|
|
|
self::$initialized = true;
|
|
|
|
}
|
2017-04-09 23:35:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Read config values from "/config.php" file
|
|
|
|
*/
|
2017-04-18 09:25:21 +02:00
|
|
|
private static function setFromFile() {
|
2017-04-11 17:00:40 +02:00
|
|
|
$configFile = ROOT_DIR . "/config.php";
|
2017-04-09 23:35:55 +02:00
|
|
|
if (self::$fileLoaded || !file_exists($configFile)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
self::$fileLoaded = true;
|
|
|
|
include_once($configFile);
|
|
|
|
|
|
|
|
if (isset($mapapi)) { self::$mapapi = $mapapi; }
|
2019-04-13 19:45:51 +02:00
|
|
|
if (isset($gkey) && !empty($gkey)) { self::$gkey = $gkey; }
|
2017-09-11 22:10:24 +02:00
|
|
|
if (isset($ol_layers)) { self::$ol_layers = $ol_layers; }
|
2017-04-09 23:35:55 +02:00
|
|
|
if (isset($init_latitude)) { self::$init_latitude = $init_latitude; }
|
|
|
|
if (isset($init_longitude)) { self::$init_longitude = $init_longitude; }
|
2019-01-23 12:23:25 +01:00
|
|
|
if (isset($dbdsn)) { self::$dbdsn = $dbdsn; }
|
2017-04-09 23:35:55 +02:00
|
|
|
if (isset($dbuser)) { self::$dbuser = $dbuser; }
|
|
|
|
if (isset($dbpass)) { self::$dbpass = $dbpass; }
|
2017-04-17 22:04:33 +02:00
|
|
|
if (isset($dbprefix)) { self::$dbprefix = $dbprefix; }
|
2017-04-09 23:35:55 +02:00
|
|
|
if (isset($require_authentication)) { self::$require_authentication = (bool) $require_authentication; }
|
|
|
|
if (isset($public_tracks)) { self::$public_tracks = (bool) $public_tracks; }
|
|
|
|
if (isset($admin_user)) { self::$admin_user = $admin_user; }
|
2017-04-14 15:55:00 +02:00
|
|
|
if (isset($pass_lenmin)) { self::$pass_lenmin = (int) $pass_lenmin; }
|
|
|
|
if (isset($pass_strength)) { self::$pass_strength = (int) $pass_strength; }
|
|
|
|
if (isset($interval)) { self::$interval = (int) $interval; }
|
2017-04-09 23:35:55 +02:00
|
|
|
if (isset($lang)) { self::$lang = $lang; }
|
|
|
|
if (isset($units)) { self::$units = $units; }
|
2018-06-22 19:38:45 +01:00
|
|
|
if (isset($strokeWeight)) { self::$strokeWeight = $strokeWeight; }
|
|
|
|
if (isset($strokeColor)) { self::$strokeColor = $strokeColor; }
|
|
|
|
if (isset($strokeOpacity)) { self::$strokeOpacity = $strokeOpacity; }
|
2017-04-09 23:35:55 +02:00
|
|
|
|
|
|
|
if (!self::$require_authentication) {
|
|
|
|
// tracks must be public if we don't require authentication
|
|
|
|
self::$public_tracks = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Read config values stored in cookies
|
|
|
|
*/
|
2017-04-18 09:25:21 +02:00
|
|
|
private static function setFromCookies() {
|
2017-04-09 23:35:55 +02:00
|
|
|
if (isset($_COOKIE["ulogger_api"])) { self::$mapapi = $_COOKIE["ulogger_api"]; }
|
|
|
|
if (isset($_COOKIE["ulogger_lang"])) { self::$lang = $_COOKIE["ulogger_lang"]; }
|
|
|
|
if (isset($_COOKIE["ulogger_units"])) { self::$units = $_COOKIE["ulogger_units"]; }
|
|
|
|
if (isset($_COOKIE["ulogger_interval"])) { self::$interval = $_COOKIE["ulogger_interval"]; }
|
|
|
|
}
|
2017-04-14 15:55:00 +02:00
|
|
|
|
2017-04-18 09:25:21 +02:00
|
|
|
/**
|
|
|
|
* Is config loaded from file?
|
|
|
|
*
|
|
|
|
* @return True if loaded, false otherwise
|
|
|
|
*/
|
|
|
|
public static function isFileLoaded() {
|
2017-04-17 13:15:44 +02:00
|
|
|
return self::$fileLoaded;
|
|
|
|
}
|
|
|
|
|
2017-04-14 15:55:00 +02:00
|
|
|
/**
|
|
|
|
* Regex to test if password matches strength and length requirements.
|
|
|
|
* Valid for both php and javascript
|
|
|
|
*/
|
2017-04-18 09:25:21 +02:00
|
|
|
public static function passRegex() {
|
2017-05-23 22:36:26 +02:00
|
|
|
$regex = "";
|
2017-04-14 15:55:00 +02:00
|
|
|
if (self::$pass_strength > 0) {
|
|
|
|
// lower and upper case
|
|
|
|
$regex .= "(?=.*[a-z])(?=.*[A-Z])";
|
|
|
|
}
|
|
|
|
if (self::$pass_strength > 1) {
|
|
|
|
// digits
|
|
|
|
$regex .= "(?=.*[0-9])";
|
|
|
|
}
|
|
|
|
if (self::$pass_strength > 2) {
|
|
|
|
// not latin, not digits
|
|
|
|
$regex .= "(?=.*[^a-zA-Z0-9])";
|
|
|
|
}
|
|
|
|
if (self::$pass_lenmin > 0) {
|
|
|
|
$regex .= "(?=.{" . self::$pass_lenmin . ",})";
|
|
|
|
}
|
2017-05-23 22:36:26 +02:00
|
|
|
if (empty($regex)) {
|
|
|
|
$regex = ".*";
|
2017-04-14 15:55:00 +02:00
|
|
|
}
|
2017-05-23 22:36:26 +02:00
|
|
|
return "/" . $regex . "/";
|
2017-04-14 15:55:00 +02:00
|
|
|
}
|
2017-04-09 23:35:55 +02:00
|
|
|
}
|
2017-04-06 19:18:51 +02:00
|
|
|
|
2018-06-22 19:38:45 +01:00
|
|
|
?>
|