Refactor config class
This commit is contained in:
parent
652655a90f
commit
33afc33405
@ -1,6 +1,7 @@
|
||||
<?php
|
||||
|
||||
if (!defined("ROOT_DIR")) { define("ROOT_DIR", __DIR__ . "/../.."); }
|
||||
require_once(__DIR__ . "/../../helpers/config.php");
|
||||
|
||||
abstract class BaseDatabaseTestCase extends PHPUnit_Extensions_Database_TestCase {
|
||||
|
||||
@ -14,6 +15,8 @@ abstract class BaseDatabaseTestCase extends PHPUnit_Extensions_Database_TestCase
|
||||
private $conn;
|
||||
static private $driver = "mysql";
|
||||
|
||||
protected $mockConfig;
|
||||
|
||||
protected $testUser = "testUser";
|
||||
protected $testUser2 = "testUser2";
|
||||
protected $testAdminUser = "admin";
|
||||
@ -44,6 +47,7 @@ abstract class BaseDatabaseTestCase extends PHPUnit_Extensions_Database_TestCase
|
||||
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
$this->mockConfig = new uConfig(false);
|
||||
}
|
||||
|
||||
public static function setUpBeforeClass() {
|
||||
|
@ -6,6 +6,8 @@ require_once(__DIR__ . "/../lib/UloggerDatabaseTestCase.php");
|
||||
|
||||
class ConfigTest extends UloggerDatabaseTestCase {
|
||||
|
||||
private $config;
|
||||
|
||||
private $mapApi;
|
||||
private $latitude;
|
||||
private $longitude;
|
||||
@ -26,6 +28,7 @@ class ConfigTest extends UloggerDatabaseTestCase {
|
||||
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
$this->config = uConfig::getInstance();
|
||||
$this->initConfigValues();
|
||||
}
|
||||
|
||||
@ -60,25 +63,75 @@ class ConfigTest extends UloggerDatabaseTestCase {
|
||||
}
|
||||
|
||||
public function testSetFromDatabase() {
|
||||
uConfig::setFromDatabase();
|
||||
$this->assertEquals($this->mapApi, uConfig::$mapApi);
|
||||
$this->assertEquals($this->latitude, uConfig::$initLatitude);
|
||||
$this->assertEquals($this->longitude, uConfig::$initLongitude);
|
||||
$this->assertEquals($this->googleKey, uConfig::$googleKey);
|
||||
$this->assertEquals($this->requireAuth, uConfig::$requireAuthentication);
|
||||
$this->assertEquals($this->publicTracks, uConfig::$publicTracks);
|
||||
$this->assertEquals($this->passLenMin, uConfig::$passLenMin);
|
||||
$this->assertEquals($this->passStrength, uConfig::$passStrength);
|
||||
$this->assertEquals($this->interval, uConfig::$interval);
|
||||
$this->assertEquals($this->lang, uConfig::$lang);
|
||||
$this->assertEquals($this->units, uConfig::$units);
|
||||
$this->assertEquals($this->strokeWeight, uConfig::$strokeWeight);
|
||||
$this->assertEquals($this->strokeColor, uConfig::$strokeColor);
|
||||
$this->assertEquals($this->strokeOpacity, uConfig::$strokeOpacity);
|
||||
$this->assertEquals($this->mapApi, $this->config->mapApi);
|
||||
$this->assertEquals($this->latitude, $this->config->initLatitude);
|
||||
$this->assertEquals($this->longitude, $this->config->initLongitude);
|
||||
$this->assertEquals($this->googleKey, $this->config->googleKey);
|
||||
$this->assertEquals($this->requireAuth, $this->config->requireAuthentication);
|
||||
$this->assertEquals($this->publicTracks, $this->config->publicTracks);
|
||||
$this->assertEquals($this->passLenMin, $this->config->passLenMin);
|
||||
$this->assertEquals($this->passStrength, $this->config->passStrength);
|
||||
$this->assertEquals($this->interval, $this->config->interval);
|
||||
$this->assertEquals($this->lang, $this->config->lang);
|
||||
$this->assertEquals($this->units, $this->config->units);
|
||||
$this->assertEquals($this->strokeWeight, $this->config->strokeWeight);
|
||||
$this->assertEquals($this->strokeColor, $this->config->strokeColor);
|
||||
$this->assertEquals($this->strokeOpacity, $this->config->strokeOpacity);
|
||||
|
||||
$this->assertEquals($this->testLayer, uConfig::$olLayers[0]->name);
|
||||
$this->assertEquals($this->testUrl, uConfig::$olLayers[0]->url);
|
||||
$this->assertEquals($this->testPriority, uConfig::$olLayers[0]->priority);
|
||||
$this->assertEquals($this->testLayer, $this->config->olLayers[0]->name);
|
||||
$this->assertEquals($this->testUrl, $this->config->olLayers[0]->url);
|
||||
$this->assertEquals($this->testPriority, $this->config->olLayers[0]->priority);
|
||||
}
|
||||
|
||||
public function testSave() {
|
||||
$this->config->mapApi = 'newApi';
|
||||
$this->config->initLatitude = 33.11;
|
||||
$this->config->initLongitude = 22.11;
|
||||
$this->config->googleKey = 'newKey';
|
||||
$this->config->requireAuthentication = false;
|
||||
$this->config->publicTracks = false;
|
||||
$this->config->passLenMin = 31;
|
||||
$this->config->passStrength = 31;
|
||||
$this->config->interval = 661;
|
||||
$this->config->lang = 'newLang';
|
||||
$this->config->units = 'newUnits';
|
||||
$this->config->strokeWeight = 551;
|
||||
$this->config->strokeColor = '#bfbfbf';
|
||||
$this->config->strokeOpacity = 0.11;
|
||||
$this->config->olLayers = [];
|
||||
$this->config->olLayers[0] = new uLayer(11, 'newLayer', 'newUrl', 51);
|
||||
|
||||
$this->config->save();
|
||||
|
||||
$this->assertEquals(1, $this->getConnection()->getRowCount('config'), "Wrong row count");
|
||||
$expected = [
|
||||
"map_api" => $this->config->mapApi,
|
||||
"latitude" => $this->config->initLatitude,
|
||||
"longitude" => $this->config->initLongitude,
|
||||
"google_key" => $this->config->googleKey,
|
||||
"require_auth" => $this->config->requireAuthentication,
|
||||
"public_tracks" => $this->config->publicTracks,
|
||||
"pass_lenmin" => $this->config->passLenMin,
|
||||
"pass_strength" => $this->config->passStrength,
|
||||
"interval_seconds" => $this->config->interval,
|
||||
"lang" => $this->config->lang,
|
||||
"units" => $this->config->units,
|
||||
"stroke_weight" => $this->config->strokeWeight,
|
||||
"stroke_color" => hexdec(str_replace('#', '', $this->config->strokeColor)),
|
||||
"stroke_opacity" => (int) ($this->config->strokeOpacity * 100)
|
||||
];
|
||||
$actual = $this->getConnection()->createQueryTable("config", "SELECT * FROM config");
|
||||
$this->assertTableContains($expected, $actual, "Wrong actual table data: " . implode(', ', $actual->getRow(0)));
|
||||
|
||||
$this->assertEquals(1, $this->getConnection()->getRowCount('ol_layers'), "Wrong row count");
|
||||
$expected = [
|
||||
"id" => $this->config->olLayers[0]->id,
|
||||
"name" => $this->config->olLayers[0]->name,
|
||||
"url" => $this->config->olLayers[0]->url,
|
||||
"priority" => $this->config->olLayers[0]->priority
|
||||
];
|
||||
$actual = $this->getConnection()->createQueryTable("ol_layers", "SELECT * FROM ol_layers");
|
||||
$this->assertTableContains($expected, $actual, "Wrong actual table data: " . implode(', ', $actual->getRow(0)));
|
||||
}
|
||||
|
||||
private function initConfigValues() {
|
||||
@ -102,35 +155,35 @@ class ConfigTest extends UloggerDatabaseTestCase {
|
||||
}
|
||||
|
||||
public function testPassRegex() {
|
||||
uConfig::$passLenMin = 0;
|
||||
uConfig::$passStrength = 0;
|
||||
$this->config->passLenMin = 0;
|
||||
$this->config->passStrength = 0;
|
||||
$password0 = "password";
|
||||
$password1 = "PASSword";
|
||||
$password2 = "PASSword1234";
|
||||
$password3 = "PASSword1234-;";
|
||||
|
||||
$regex = uConfig::passRegex();
|
||||
$regex = $this->config->passRegex();
|
||||
$this->assertRegExp($regex, $password0, "Regex: \"$regex\", password: \"$password0\"");
|
||||
$this->assertRegExp($regex, $password1, "Regex: \"$regex\", password: \"$password1\"");
|
||||
$this->assertRegExp($regex, $password2, "Regex: \"$regex\", password: \"$password2\"");
|
||||
$this->assertRegExp($regex, $password3, "Regex: \"$regex\", password: \"$password3\"");
|
||||
|
||||
uConfig::$passStrength = 1;
|
||||
$regex = uConfig::passRegex();
|
||||
$this->config->passStrength = 1;
|
||||
$regex = $this->config->passRegex();
|
||||
$this->assertNotRegExp($regex, $password0, "Regex: \"$regex\", password: \"$password0\"");
|
||||
$this->assertRegExp($regex, $password1, "Regex: \"$regex\", password: \"$password1\"");
|
||||
$this->assertRegExp($regex, $password2, "Regex: \"$regex\", password: \"$password2\"");
|
||||
$this->assertRegExp($regex, $password3, "Regex: \"$regex\", password: \"$password3\"");
|
||||
|
||||
uConfig::$passStrength = 2;
|
||||
$regex = uConfig::passRegex();
|
||||
$this->config->passStrength = 2;
|
||||
$regex = $this->config->passRegex();
|
||||
$this->assertNotRegExp($regex, $password0, "Regex: \"$regex\", password: \"$password0\"");
|
||||
$this->assertNotRegExp($regex, $password1, "Regex: \"$regex\", password: \"$password1\"");
|
||||
$this->assertRegExp($regex, $password2, "Regex: \"$regex\", password: \"$password2\"");
|
||||
$this->assertRegExp($regex, $password3, "Regex: \"$regex\", password: \"$password3\"");
|
||||
|
||||
uConfig::$passStrength = 3;
|
||||
$regex = uConfig::passRegex();
|
||||
$this->config->passStrength = 3;
|
||||
$regex = $this->config->passRegex();
|
||||
$this->assertNotRegExp($regex, $password0, "Regex: \"$regex\", password: \"$password0\"");
|
||||
$this->assertNotRegExp($regex, $password1, "Regex: \"$regex\", password: \"$password1\"");
|
||||
$this->assertNotRegExp($regex, $password2, "Regex: \"$regex\", password: \"$password2\"");
|
||||
@ -138,19 +191,19 @@ class ConfigTest extends UloggerDatabaseTestCase {
|
||||
|
||||
$password_len5 = "12345";
|
||||
$password_len10 = "1234567890";
|
||||
uConfig::$passLenMin = 5;
|
||||
uConfig::$passStrength = 0;
|
||||
$regex = uConfig::passRegex();
|
||||
$this->config->passLenMin = 5;
|
||||
$this->config->passStrength = 0;
|
||||
$regex = $this->config->passRegex();
|
||||
$this->assertRegExp($regex, $password_len5, "Regex: \"$regex\", password: \"$password_len5\"");
|
||||
$this->assertRegExp($regex, $password_len10, "Regex: \"$regex\", password: \"$password_len10\"");
|
||||
|
||||
uConfig::$passLenMin = 7;
|
||||
$regex = uConfig::passRegex();
|
||||
$this->config->passLenMin = 7;
|
||||
$regex = $this->config->passRegex();
|
||||
$this->assertNotRegExp($regex, $password_len5, "Regex: \"$regex\", password: \"$password_len5\"");
|
||||
$this->assertRegExp($regex, $password_len10, "Regex: \"$regex\", password: \"$password_len10\"");
|
||||
|
||||
uConfig::$passLenMin = 12;
|
||||
$regex = uConfig::passRegex();
|
||||
$this->config->passLenMin = 12;
|
||||
$regex = $this->config->passRegex();
|
||||
$this->assertNotRegExp($regex, $password_len5, "Regex: \"$regex\", password: \"$password_len5\"");
|
||||
$this->assertNotRegExp($regex, $password_len10, "Regex: \"$regex\", password: \"$password_len10\"");
|
||||
}
|
||||
|
@ -626,7 +626,7 @@ class ImportTest extends UloggerAPITestCase {
|
||||
}
|
||||
|
||||
public function testImportNoLongitude() {
|
||||
$lang = (new uLang("en"))->getStrings();
|
||||
$lang = (new uLang($this->mockConfig))->getStrings();
|
||||
$this->assertTrue($this->authenticate(), "Authentication failed");
|
||||
|
||||
$this->assertEquals(0, $this->getConnection()->getRowCount("tracks"), "Wrong row count");
|
||||
@ -673,7 +673,7 @@ class ImportTest extends UloggerAPITestCase {
|
||||
}
|
||||
|
||||
public function testImportNoLatitude() {
|
||||
$lang = (new uLang("en"))->getStrings();
|
||||
$lang = (new uLang($this->mockConfig))->getStrings();
|
||||
$this->assertTrue($this->authenticate(), "Authentication failed");
|
||||
|
||||
$this->assertEquals(0, $this->getConnection()->getRowCount("tracks"), "Wrong row count");
|
||||
@ -720,7 +720,7 @@ class ImportTest extends UloggerAPITestCase {
|
||||
}
|
||||
|
||||
public function testImportNoGPX() {
|
||||
$lang = (new uLang("en"))->getStrings();
|
||||
$lang = (new uLang($this->mockConfig))->getStrings();
|
||||
$this->assertTrue($this->authenticate(), "Authentication failed");
|
||||
|
||||
$this->assertEquals(0, $this->getConnection()->getRowCount("tracks"), "Wrong row count");
|
||||
@ -761,7 +761,7 @@ class ImportTest extends UloggerAPITestCase {
|
||||
}
|
||||
|
||||
public function testImportCorrupt() {
|
||||
$lang = (new uLang("en"))->getStrings();
|
||||
$lang = (new uLang($this->mockConfig))->getStrings();
|
||||
$this->assertTrue($this->authenticate(), "Authentication failed");
|
||||
|
||||
$this->assertEquals(0, $this->getConnection()->getRowCount("tracks"), "Wrong row count");
|
||||
|
@ -666,7 +666,7 @@ class InternalAPITest extends UloggerAPITestCase {
|
||||
}
|
||||
|
||||
public function testHandleTrackDeleteOtherUser() {
|
||||
$lang = (new uLang("en"))->getStrings();
|
||||
$lang = (new uLang($this->mockConfig))->getStrings();
|
||||
$this->addTestUser($this->testUser, password_hash($this->testPass, PASSWORD_DEFAULT));
|
||||
$this->assertEquals(2, $this->getConnection()->getRowCount("users"), "Wrong row count");
|
||||
$this->assertTrue($this->authenticate($this->testUser, $this->testPass), "Authentication failed");
|
||||
@ -728,7 +728,7 @@ class InternalAPITest extends UloggerAPITestCase {
|
||||
}
|
||||
|
||||
public function testHandleTrackUpdateEmptyName() {
|
||||
$lang = (new uLang("en"))->getStrings();
|
||||
$lang = (new uLang($this->mockConfig))->getStrings();
|
||||
$this->assertTrue($this->authenticate(), "Authentication failed");
|
||||
$userId = $this->addTestUser($this->testUser, password_hash($this->testPass, PASSWORD_DEFAULT));
|
||||
$this->assertEquals(2, $this->getConnection()->getRowCount("users"), "Wrong row count");
|
||||
@ -752,7 +752,7 @@ class InternalAPITest extends UloggerAPITestCase {
|
||||
}
|
||||
|
||||
public function testHandleTrackUpdateNonexistantTrack() {
|
||||
$lang = (new uLang("en"))->getStrings();
|
||||
$lang = (new uLang($this->mockConfig))->getStrings();
|
||||
$newName = "New name";
|
||||
$this->assertTrue($this->authenticate(), "Authentication failed");
|
||||
$userId = $this->addTestUser($this->testUser, password_hash($this->testPass, PASSWORD_DEFAULT));
|
||||
@ -776,7 +776,7 @@ class InternalAPITest extends UloggerAPITestCase {
|
||||
}
|
||||
|
||||
public function testHandleTrackMissingAction() {
|
||||
$lang = (new uLang("en"))->getStrings();
|
||||
$lang = (new uLang($this->mockConfig))->getStrings();
|
||||
$this->assertTrue($this->authenticate(), "Authentication failed");
|
||||
|
||||
$options = [
|
||||
@ -794,7 +794,7 @@ class InternalAPITest extends UloggerAPITestCase {
|
||||
/* handleuser.php */
|
||||
|
||||
public function testHandleUserMissingAction() {
|
||||
$lang = (new uLang("en"))->getStrings();
|
||||
$lang = (new uLang($this->mockConfig))->getStrings();
|
||||
$this->assertTrue($this->authenticate(), "Authentication failed");
|
||||
|
||||
$options = [
|
||||
@ -809,7 +809,7 @@ class InternalAPITest extends UloggerAPITestCase {
|
||||
}
|
||||
|
||||
public function testHandleUserNonAdmin() {
|
||||
$lang = (new uLang("en"))->getStrings();
|
||||
$lang = (new uLang($this->mockConfig))->getStrings();
|
||||
$this->addTestUser($this->testUser, password_hash($this->testPass, PASSWORD_DEFAULT));
|
||||
$this->assertEquals(2, $this->getConnection()->getRowCount("users"), "Wrong row count");
|
||||
$this->assertTrue($this->authenticate($this->testUser, $this->testPass), "Authentication failed");
|
||||
@ -829,7 +829,7 @@ class InternalAPITest extends UloggerAPITestCase {
|
||||
}
|
||||
|
||||
public function testHandleUserSelf() {
|
||||
$lang = (new uLang("en"))->getStrings();
|
||||
$lang = (new uLang($this->mockConfig))->getStrings();
|
||||
$this->assertTrue($this->authenticate(), "Authentication failed");
|
||||
$this->assertEquals(1, $this->getConnection()->getRowCount("users"), "Wrong row count");
|
||||
|
||||
@ -847,7 +847,7 @@ class InternalAPITest extends UloggerAPITestCase {
|
||||
}
|
||||
|
||||
public function testHandleUserEmptyLogin() {
|
||||
$lang = (new uLang("en"))->getStrings();
|
||||
$lang = (new uLang($this->mockConfig))->getStrings();
|
||||
$this->assertTrue($this->authenticate(), "Authentication failed");
|
||||
$this->assertEquals(1, $this->getConnection()->getRowCount("users"), "Wrong row count");
|
||||
|
||||
@ -865,7 +865,7 @@ class InternalAPITest extends UloggerAPITestCase {
|
||||
}
|
||||
|
||||
public function testHandleUserNoAuth() {
|
||||
$lang = (new uLang("en"))->getStrings();
|
||||
$lang = (new uLang($this->mockConfig))->getStrings();
|
||||
$this->addTestUser($this->testUser, password_hash($this->testPass, PASSWORD_DEFAULT));
|
||||
$this->assertEquals(2, $this->getConnection()->getRowCount("users"), "Wrong row count");
|
||||
|
||||
@ -908,7 +908,7 @@ class InternalAPITest extends UloggerAPITestCase {
|
||||
}
|
||||
|
||||
public function testHandleUserAddSameLogin() {
|
||||
$lang = (new uLang("en"))->getStrings();
|
||||
$lang = (new uLang($this->mockConfig))->getStrings();
|
||||
$this->assertTrue($this->authenticate(), "Authentication failed");
|
||||
$this->addTestUser($this->testUser, password_hash($this->testPass, PASSWORD_DEFAULT));
|
||||
$this->assertEquals(2, $this->getConnection()->getRowCount("users"), "Wrong row count");
|
||||
|
@ -1,11 +1,20 @@
|
||||
<?php
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
if (!defined("ROOT_DIR")) { define("ROOT_DIR", __DIR__ . "/../.."); }
|
||||
|
||||
require_once(__DIR__ . "/../../helpers/config.php");
|
||||
require_once(__DIR__ . "/../../helpers/lang.php");
|
||||
|
||||
class LangTest extends TestCase {
|
||||
|
||||
protected $mockConfig;
|
||||
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
$this->mockConfig = new uConfig(false);
|
||||
}
|
||||
|
||||
public function testGetLanguages() {
|
||||
$languages = uLang::getLanguages();
|
||||
$this->assertNotEmpty($languages);
|
||||
@ -16,16 +25,18 @@ class LangTest extends TestCase {
|
||||
}
|
||||
|
||||
public function testGetStrings() {
|
||||
$lang = new uLang("en");
|
||||
$lang = new uLang($this->mockConfig);
|
||||
$this->assertEquals("User", $lang->getStrings()["user"]);
|
||||
$lang = new uLang("pl");
|
||||
$this->mockConfig->lang = "pl";
|
||||
$lang = new uLang($this->mockConfig);
|
||||
$this->assertEquals("Użytkownik", $lang->getStrings()["user"]);
|
||||
}
|
||||
|
||||
public function testGetSetupStrings() {
|
||||
$lang = new uLang("en");
|
||||
$lang = new uLang($this->mockConfig);
|
||||
$this->assertEquals("Congratulations!", $lang->getSetupStrings()["congratulations"]);
|
||||
$lang = new uLang("pl");
|
||||
$this->mockConfig->lang = "pl";
|
||||
$lang = new uLang($this->mockConfig);
|
||||
$this->assertEquals("Gratulacje!", $lang->getSetupStrings()["congratulations"]);
|
||||
}
|
||||
}
|
||||
|
@ -50,7 +50,7 @@
|
||||
$action = uUtils::postString('action');
|
||||
|
||||
$auth = new uAuth();
|
||||
if (!$auth->isAuthenticated() && $action != "auth") {
|
||||
if ($action !== "auth" && !$auth->isAuthenticated()) {
|
||||
$auth->sendUnauthorizedHeader();
|
||||
exitWithError("Unauthorized");
|
||||
}
|
||||
|
@ -30,12 +30,12 @@
|
||||
/** @var bool Is user authenticated */
|
||||
private $isAuthenticated = false;
|
||||
/** @var null|uUser */
|
||||
public $user = null;
|
||||
public $user;
|
||||
|
||||
public function __construct() {
|
||||
$this->sessionStart();
|
||||
|
||||
$user = (new uUser())->getFromSession();
|
||||
$user = uUser::getFromSession();
|
||||
if ($user->isValid) {
|
||||
$this->setAuthenticated($user);
|
||||
}
|
||||
|
@ -20,75 +20,60 @@
|
||||
require_once(ROOT_DIR . "/helpers/db.php");
|
||||
require_once(ROOT_DIR . "/helpers/layer.php");
|
||||
|
||||
/**
|
||||
* Initialize on file include
|
||||
*/
|
||||
uConfig::init();
|
||||
|
||||
/**
|
||||
* Handles config values
|
||||
*/
|
||||
class uConfig {
|
||||
/**
|
||||
* Singleton instance
|
||||
*
|
||||
* @var uConfig Object instance
|
||||
*/
|
||||
private static $instance;
|
||||
/**
|
||||
* @var string Version number
|
||||
*/
|
||||
public static $version = "1.0-beta";
|
||||
public $version = "1.0-beta";
|
||||
|
||||
/**
|
||||
* @var string Default map drawing framework
|
||||
*/
|
||||
public static $mapApi = "openlayers";
|
||||
public $mapApi = "openlayers";
|
||||
|
||||
/**
|
||||
* @var string|null Google maps key
|
||||
*/
|
||||
public static $googleKey;
|
||||
public $googleKey;
|
||||
|
||||
/**
|
||||
* @var uLayer[] Openlayers extra map layers
|
||||
*/
|
||||
public static $olLayers = [];
|
||||
public $olLayers = [];
|
||||
|
||||
/**
|
||||
* @var float Default latitude for initial map
|
||||
*/
|
||||
public static $initLatitude = 52.23;
|
||||
public $initLatitude = 52.23;
|
||||
/**
|
||||
* @var float Default longitude for initial map
|
||||
*/
|
||||
public static $initLongitude = 21.01;
|
||||
|
||||
/**
|
||||
* @var string Database DSN
|
||||
*/
|
||||
public static $dbdsn = "";
|
||||
/**
|
||||
* @var string Database user
|
||||
*/
|
||||
public static $dbuser = "";
|
||||
/**
|
||||
* @var string Database pass
|
||||
*/
|
||||
public static $dbpass = "";
|
||||
/**
|
||||
* @var string Optional table names prefix, eg. "ulogger_"
|
||||
*/
|
||||
public static $dbprefix = "";
|
||||
public $initLongitude = 21.01;
|
||||
|
||||
/**
|
||||
* @var bool Require login/password authentication
|
||||
*/
|
||||
public static $requireAuthentication = true;
|
||||
public $requireAuthentication = true;
|
||||
|
||||
/**
|
||||
* @var bool All users tracks are visible to authenticated user
|
||||
*/
|
||||
public static $publicTracks = false;
|
||||
public $publicTracks = false;
|
||||
|
||||
/**
|
||||
* @var int Miniumum required length of user password
|
||||
*/
|
||||
public static $passLenMin = 10;
|
||||
public $passLenMin = 10;
|
||||
|
||||
/**
|
||||
* @var int Required strength of user password
|
||||
@ -97,49 +82,65 @@ class uConfig {
|
||||
* 2 = require mixed case and numbers
|
||||
* 3 = require mixed case, numbers and non-alphanumeric characters
|
||||
*/
|
||||
public static $passStrength = 2;
|
||||
public $passStrength = 2;
|
||||
|
||||
/**
|
||||
* @var int Default interval in seconds for live auto reload
|
||||
*/
|
||||
public static $interval = 10;
|
||||
public $interval = 10;
|
||||
|
||||
/**
|
||||
* @var string Default language code
|
||||
*/
|
||||
public static $lang = "en";
|
||||
public $lang = "en";
|
||||
|
||||
/**
|
||||
* @var string Default units
|
||||
*/
|
||||
public static $units = "metric";
|
||||
public $units = "metric";
|
||||
|
||||
/**
|
||||
* @var int Stroke weight
|
||||
*/
|
||||
public static $strokeWeight = 2;
|
||||
public $strokeWeight = 2;
|
||||
/**
|
||||
* @var string Stroke color
|
||||
*/
|
||||
public static $strokeColor = '#ff0000';
|
||||
public $strokeColor = '#ff0000';
|
||||
/**
|
||||
* @var int Stroke opacity
|
||||
* @var float Stroke opacity
|
||||
*/
|
||||
public static $strokeOpacity = 1;
|
||||
public $strokeOpacity = 1.0;
|
||||
|
||||
private static $fileLoaded = false;
|
||||
private static $initialized = false;
|
||||
|
||||
/**
|
||||
* Static initializer
|
||||
*/
|
||||
public static function init() {
|
||||
if (!self::$initialized) {
|
||||
self::setFromFile();
|
||||
self::setFromDatabase();
|
||||
self::setFromCookies();
|
||||
self::$initialized = true;
|
||||
public function __construct($useDatabase = true) {
|
||||
if ($useDatabase) {
|
||||
$this->setFromDatabase();
|
||||
}
|
||||
$this->setFromCookies();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns singleton instance
|
||||
*
|
||||
* @return uConfig Singleton instance
|
||||
*/
|
||||
public static function getInstance() {
|
||||
if (!self::$instance) {
|
||||
self::$instance = new self();
|
||||
}
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns singleton instance
|
||||
*
|
||||
* @return uConfig Singleton instance
|
||||
*/
|
||||
public static function getOfflineInstance() {
|
||||
if (!self::$instance) {
|
||||
self::$instance = new self(false);
|
||||
}
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -154,7 +155,7 @@ class uConfig {
|
||||
/**
|
||||
* Read config values from database
|
||||
*/
|
||||
public static function setFromDatabase() {
|
||||
public function setFromDatabase() {
|
||||
try {
|
||||
$query = "SELECT map_api, latitude, longitude, google_key, require_auth, public_tracks,
|
||||
pass_lenmin, pass_strength, interval_seconds, lang, units,
|
||||
@ -163,30 +164,91 @@ class uConfig {
|
||||
$result = self::db()->query($query);
|
||||
$row = $result->fetch();
|
||||
if ($row) {
|
||||
if (!empty($row['map_api'])) { self::$mapApi = $row['map_api']; }
|
||||
if (is_numeric($row['latitude'])) { self::$initLatitude = $row['latitude']; }
|
||||
if (is_numeric($row['longitude'])) { self::$initLongitude = $row['longitude']; }
|
||||
if (!empty($row['google_key'])) { self::$googleKey = $row['google_key']; }
|
||||
if (is_numeric($row['require_auth']) || is_bool($row['require_auth'])) { self::$requireAuthentication = (bool) $row['require_auth']; }
|
||||
if (is_numeric($row['public_tracks']) || is_bool($row['public_tracks'])) { self::$publicTracks = (bool) $row['public_tracks']; }
|
||||
if (is_numeric($row['pass_lenmin'])) { self::$passLenMin = $row['pass_lenmin']; }
|
||||
if (is_numeric($row['pass_strength'])) { self::$passStrength = $row['pass_strength']; }
|
||||
if (is_numeric($row['interval_seconds'])) { self::$interval = $row['interval_seconds']; }
|
||||
if (!empty($row['lang'])) { self::$lang = $row['lang']; }
|
||||
if (!empty($row['units'])) { self::$units = $row['units']; }
|
||||
if (is_numeric($row['stroke_weight'])) { self::$strokeWeight = $row['stroke_weight']; }
|
||||
if (is_numeric($row['stroke_color'])) { self::$strokeColor = self::getColorAsHex($row['stroke_color']); }
|
||||
if (is_numeric($row['stroke_opacity'])) { self::$strokeOpacity = $row['stroke_opacity'] / 100; }
|
||||
if (!empty($row['map_api'])) { $this->mapApi = $row['map_api']; }
|
||||
if (is_numeric($row['latitude'])) { $this->initLatitude = (float) $row['latitude']; }
|
||||
if (is_numeric($row['longitude'])) { $this->initLongitude = (float) $row['longitude']; }
|
||||
if (!empty($row['google_key'])) { $this->googleKey = $row['google_key']; }
|
||||
if (is_numeric($row['require_auth']) || is_bool($row['require_auth'])) { $this->requireAuthentication = (bool) $row['require_auth']; }
|
||||
if (is_numeric($row['public_tracks']) || is_bool($row['public_tracks'])) { $this->publicTracks = (bool) $row['public_tracks']; }
|
||||
if (is_numeric($row['pass_lenmin'])) { $this->passLenMin = (int) $row['pass_lenmin']; }
|
||||
if (is_numeric($row['pass_strength'])) { $this->passStrength = (int) $row['pass_strength']; }
|
||||
if (is_numeric($row['interval_seconds'])) { $this->interval = (int) $row['interval_seconds']; }
|
||||
if (!empty($row['lang'])) { $this->lang = $row['lang']; }
|
||||
if (!empty($row['units'])) { $this->units = $row['units']; }
|
||||
if (is_numeric($row['stroke_weight'])) { $this->strokeWeight = (int) $row['stroke_weight']; }
|
||||
if (is_numeric($row['stroke_color'])) { $this->strokeColor = self::getColorAsHex($row['stroke_color']); }
|
||||
if (is_numeric($row['stroke_opacity'])) { $this->strokeOpacity = $row['stroke_opacity'] / 100; }
|
||||
}
|
||||
self::setLayersFromDatabase();
|
||||
if (!self::$requireAuthentication) {
|
||||
$this->setLayersFromDatabase();
|
||||
if (!$this->requireAuthentication) {
|
||||
// tracks must be public if we don't require authentication
|
||||
self::$publicTracks = true;
|
||||
$this->publicTracks = true;
|
||||
}
|
||||
} catch (PDOException $e) {
|
||||
// TODO: handle exception
|
||||
syslog(LOG_ERR, $e->getMessage());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Save config values to database
|
||||
* @return bool True on success, false otherwise
|
||||
*/
|
||||
public function save() {
|
||||
$ret = false;
|
||||
try {
|
||||
$query = "UPDATE " . self::db()->table('config') . "
|
||||
SET map_api = ?, latitude = ?, longitude = ?, google_key = ?, require_auth = ?, public_tracks = ?,
|
||||
pass_lenmin = ?, pass_strength = ?, interval_seconds = ?, lang = ?, units = ?,
|
||||
stroke_weight = ?, stroke_color = ?, stroke_opacity = ?";
|
||||
$stmt = self::db()->prepare($query);
|
||||
$params = [
|
||||
$this->mapApi,
|
||||
$this->initLatitude,
|
||||
$this->initLongitude,
|
||||
$this->googleKey,
|
||||
(int) $this->requireAuthentication,
|
||||
(int) $this->publicTracks,
|
||||
$this->passLenMin,
|
||||
$this->passStrength,
|
||||
$this->interval,
|
||||
$this->lang,
|
||||
$this->units,
|
||||
$this->strokeWeight,
|
||||
self::getColorAsInt($this->strokeColor),
|
||||
(int) ($this->strokeOpacity * 100)
|
||||
];
|
||||
$stmt->execute($params);
|
||||
$this->saveLayers();
|
||||
$ret = true;
|
||||
} catch (PDOException $e) {
|
||||
// TODO: handle exception
|
||||
syslog(LOG_ERR, $e->getMessage());
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Truncate ol_layers table
|
||||
* @throws PDOException
|
||||
*/
|
||||
private function deleteLayers() {
|
||||
$query = "DELETE FROM " . self::db()->table('ol_layers');
|
||||
self::db()->exec($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* Save layers to database
|
||||
* @throws PDOException
|
||||
*/
|
||||
private function saveLayers() {
|
||||
$this->deleteLayers();
|
||||
if (!empty($this->olLayers)) {
|
||||
$query = "INSERT INTO " . self::db()->table('ol_layers') . " (id, name, url, priority) VALUES (?, ?, ?, ?)";
|
||||
$stmt = self::db()->prepare($query);
|
||||
foreach ($this->olLayers as $layer) {
|
||||
$stmt->execute([ $layer->id, $layer->name, $layer->url, $layer->priority]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -194,50 +256,34 @@ class uConfig {
|
||||
* Read config values from database
|
||||
* @throws PDOException
|
||||
*/
|
||||
private static function setLayersFromDatabase() {
|
||||
self::$olLayers = [];
|
||||
private function setLayersFromDatabase() {
|
||||
$this->olLayers = [];
|
||||
$query = "SELECT id, name, url, priority FROM " . self::db()->table('ol_layers');
|
||||
$result = self::db()->query($query);
|
||||
while ($row = $result->fetch()) {
|
||||
self::$olLayers[] = new uLayer($row['id'], $row['name'], $row['url'], $row['priority']);
|
||||
$this->olLayers[] = new uLayer($row['id'], $row['name'], $row['url'], $row['priority']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Read config values from "/config.php" file
|
||||
* @noinspection IssetArgumentExistenceInspection
|
||||
* @noinspection DuplicatedCode
|
||||
* @noinspection PhpIncludeInspection
|
||||
*/
|
||||
private static function setFromFile() {
|
||||
$configFile = ROOT_DIR . "/config.php";
|
||||
if (self::$fileLoaded || !file_exists($configFile)) { return; }
|
||||
self::$fileLoaded = true;
|
||||
include_once($configFile);
|
||||
|
||||
if (isset($dbdsn)) { self::$dbdsn = $dbdsn; }
|
||||
if (isset($dbuser)) { self::$dbuser = $dbuser; }
|
||||
if (isset($dbpass)) { self::$dbpass = $dbpass; }
|
||||
if (isset($dbprefix)) { self::$dbprefix = $dbprefix; }
|
||||
}
|
||||
|
||||
/**
|
||||
* Read config values stored in cookies
|
||||
*/
|
||||
private static function setFromCookies() {
|
||||
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"]; }
|
||||
private function setFromCookies() {
|
||||
if (isset($_COOKIE["ulogger_api"])) { $this->mapApi = $_COOKIE["ulogger_api"]; }
|
||||
if (isset($_COOKIE["ulogger_lang"])) { $this->lang = $_COOKIE["ulogger_lang"]; }
|
||||
if (isset($_COOKIE["ulogger_units"])) { $this->units = $_COOKIE["ulogger_units"]; }
|
||||
if (isset($_COOKIE["ulogger_interval"])) { $this->interval = $_COOKIE["ulogger_interval"]; }
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Is config loaded from file?
|
||||
* Check if given password matches user's one
|
||||
*
|
||||
* @return bool True if loaded, false otherwise
|
||||
* @param String $password Password
|
||||
* @return bool True if matches, false otherwise
|
||||
*/
|
||||
public static function isFileLoaded() {
|
||||
return self::$fileLoaded;
|
||||
public function validPassStrength($password) {
|
||||
return preg_match($this->passRegex(), $password);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -245,22 +291,22 @@ class uConfig {
|
||||
* Valid for both php and javascript
|
||||
* @return string
|
||||
*/
|
||||
public static function passRegex() {
|
||||
public function passRegex() {
|
||||
$regex = "";
|
||||
if (self::$passStrength > 0) {
|
||||
if ($this->passStrength > 0) {
|
||||
// lower and upper case
|
||||
$regex .= "(?=.*[a-z])(?=.*[A-Z])";
|
||||
}
|
||||
if (self::$passStrength > 1) {
|
||||
if ($this->passStrength > 1) {
|
||||
// digits
|
||||
$regex .= "(?=.*[0-9])";
|
||||
}
|
||||
if (self::$passStrength > 2) {
|
||||
if ($this->passStrength > 2) {
|
||||
// not latin, not digits
|
||||
$regex .= "(?=.*[^a-zA-Z0-9])";
|
||||
}
|
||||
if (self::$passLenMin > 0) {
|
||||
$regex .= "(?=.{" . self::$passLenMin . ",})";
|
||||
if ($this->passLenMin > 0) {
|
||||
$regex .= "(?=.{" . $this->passLenMin . ",})";
|
||||
}
|
||||
if (empty($regex)) {
|
||||
$regex = ".*";
|
||||
|
@ -17,8 +17,6 @@
|
||||
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
require_once(ROOT_DIR . "/helpers/config.php");
|
||||
|
||||
/**
|
||||
* PDO wrapper
|
||||
*/
|
||||
@ -44,6 +42,23 @@
|
||||
*/
|
||||
protected static $driver;
|
||||
|
||||
/**
|
||||
* @var string Database DSN
|
||||
*/
|
||||
private static $dbdsn = "";
|
||||
/**
|
||||
* @var string Database user
|
||||
*/
|
||||
private static $dbuser = "";
|
||||
/**
|
||||
* @var string Database pass
|
||||
*/
|
||||
private static $dbpass = "";
|
||||
/**
|
||||
* @var string Optional table names prefix, eg. "ulogger_"
|
||||
*/
|
||||
private static $dbprefix = "";
|
||||
|
||||
/**
|
||||
* PDO constuctor
|
||||
*
|
||||
@ -73,7 +88,7 @@
|
||||
*/
|
||||
private function initTables() {
|
||||
self::$tables = [];
|
||||
$prefix = preg_replace('/[^a-z0-9_]/i', '', uConfig::$dbprefix);
|
||||
$prefix = preg_replace('/[^a-z0-9_]/i', '', self::$dbprefix);
|
||||
self::$tables['positions'] = $prefix . "positions";
|
||||
self::$tables['tracks'] = $prefix . "tracks";
|
||||
self::$tables['users'] = $prefix . "users";
|
||||
@ -88,11 +103,38 @@
|
||||
*/
|
||||
public static function getInstance() {
|
||||
if (!self::$instance) {
|
||||
self::$instance = new self(uConfig::$dbdsn, uConfig::$dbuser, uConfig::$dbpass);
|
||||
self::getConfig();
|
||||
self::$instance = new self(self::$dbdsn, self::$dbuser, self::$dbpass);
|
||||
}
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read database setup from config file
|
||||
* @noinspection IssetArgumentExistenceInspection
|
||||
* @noinspection PhpIncludeInspection
|
||||
*/
|
||||
private static function getConfig() {
|
||||
$configFile = dirname(__DIR__) . "/config.php";
|
||||
if (!file_exists($configFile)) {
|
||||
header("HTTP/1.1 503 Service Unavailable");
|
||||
die("Missing config.php file!");
|
||||
}
|
||||
include($configFile);
|
||||
if (isset($dbdsn)) {
|
||||
self::$dbdsn = $dbdsn;
|
||||
}
|
||||
if (isset($dbuser)) {
|
||||
self::$dbuser = $dbuser;
|
||||
}
|
||||
if (isset($dbpass)) {
|
||||
self::$dbpass = $dbpass;
|
||||
}
|
||||
if (isset($dbprefix)) {
|
||||
self::$dbprefix = $dbprefix;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get full table name including prefix
|
||||
*
|
||||
|
@ -61,9 +61,10 @@
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param string $language Language code (IANA)
|
||||
* @param uConfig $config Config
|
||||
*/
|
||||
public function __construct($language = "en") {
|
||||
public function __construct($config) {
|
||||
$language = $config->lang;
|
||||
$lang = [];
|
||||
$langSetup = [];
|
||||
// always load en base
|
||||
@ -76,9 +77,9 @@
|
||||
}
|
||||
|
||||
// choose password messages based on config
|
||||
$passRules = "passrules_" . uConfig::$passStrength;
|
||||
$passRules = "passrules_" . $config->passStrength;
|
||||
$lang['passrules'] = isset($lang[$passRules]) ? $lang[$passRules] : "";
|
||||
$lang['passlenmin'] = sprintf($lang["passlenmin"], uConfig::$passLenMin);
|
||||
$lang['passlenmin'] = sprintf($lang["passlenmin"], $config->passLenMin);
|
||||
$this->strings = $lang;
|
||||
$this->setupStrings = $langSetup;
|
||||
}
|
||||
|
@ -16,7 +16,6 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
require_once(ROOT_DIR . "/helpers/config.php");
|
||||
require_once(ROOT_DIR . "/helpers/db.php");
|
||||
require_once(ROOT_DIR . "/helpers/track.php");
|
||||
require_once(ROOT_DIR . "/helpers/position.php");
|
||||
@ -75,7 +74,7 @@
|
||||
*/
|
||||
public static function add($login, $pass, $isAdmin = false) {
|
||||
$userid = false;
|
||||
if (!empty($login) && !empty($pass) && self::validPassStrength($pass)) {
|
||||
if (!empty($login) && !empty($pass)) {
|
||||
$hash = password_hash($pass, PASSWORD_DEFAULT);
|
||||
$table = self::db()->table('users');
|
||||
try {
|
||||
@ -152,7 +151,7 @@
|
||||
*/
|
||||
public function setPass($pass) {
|
||||
$ret = false;
|
||||
if (!empty($this->login) && !empty($pass) && self::validPassStrength($pass)) {
|
||||
if (!empty($this->login) && !empty($pass)) {
|
||||
$hash = password_hash($pass, PASSWORD_DEFAULT);
|
||||
try {
|
||||
$query = "UPDATE " . self::db()->table('users') . " SET password = ? WHERE login = ?";
|
||||
@ -178,16 +177,6 @@
|
||||
return password_verify($password, $this->hash);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if given password matches user's one
|
||||
*
|
||||
* @param String $password Password
|
||||
* @return bool True if matches, false otherwise
|
||||
*/
|
||||
private static function validPassStrength($password) {
|
||||
return preg_match(uConfig::passRegex(), $password);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store uUser object in session
|
||||
*/
|
||||
@ -199,16 +188,17 @@
|
||||
* Fill uUser object properties from session data
|
||||
* @return uUser
|
||||
*/
|
||||
public function getFromSession() {
|
||||
public static function getFromSession() {
|
||||
$user = new uUser();
|
||||
if (isset($_SESSION['user'])) {
|
||||
$sessionUser = $_SESSION['user'];
|
||||
$this->id = $sessionUser->id;
|
||||
$this->login = $sessionUser->login;
|
||||
$this->hash = $sessionUser->hash;
|
||||
$this->isAdmin = $sessionUser->isAdmin;
|
||||
$this->isValid = $sessionUser->isValid;
|
||||
$user->id = $sessionUser->id;
|
||||
$user->login = $sessionUser->login;
|
||||
$user->hash = $sessionUser->hash;
|
||||
$user->isAdmin = $sessionUser->isAdmin;
|
||||
$user->isValid = $sessionUser->isValid;
|
||||
}
|
||||
return $this;
|
||||
return $user;
|
||||
}
|
||||
|
||||
/**
|
||||
|
23
index.php
23
index.php
@ -28,7 +28,8 @@
|
||||
$pass = uUtils::postPass('pass');
|
||||
$action = uUtils::postString('action');
|
||||
|
||||
$lang = (new uLang(uConfig::$lang))->getStrings();
|
||||
$config = uConfig::getInstance();
|
||||
$lang = (new uLang($config))->getStrings();
|
||||
$langsArr = uLang::getLanguages();
|
||||
|
||||
$auth = new uAuth();
|
||||
@ -39,13 +40,13 @@
|
||||
if ($action === 'auth' && !$auth->isAuthenticated()) {
|
||||
$auth->exitWithRedirect('login.php?auth_error=1');
|
||||
}
|
||||
if (uConfig::$requireAuthentication && !$auth->isAuthenticated()) {
|
||||
if ($config->requireAuthentication && !$auth->isAuthenticated()) {
|
||||
$auth->exitWithRedirect('login.php');
|
||||
}
|
||||
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="<?= uConfig::$lang ?>">
|
||||
<html lang="<?= $config->lang ?>">
|
||||
<head>
|
||||
<title><?= $lang['title'] ?></title>
|
||||
<?php include('meta.php'); ?>
|
||||
@ -78,7 +79,7 @@
|
||||
<label for="track"><?= $lang['track'] ?></label>
|
||||
<select id="track" data-bind="currentTrackId" name="track"></select>
|
||||
<input id="latest" type="checkbox" data-bind="showLatest"> <label for="latest"><?= $lang['latest'] ?></label><br>
|
||||
<input id="auto-reload" type="checkbox" data-bind="autoReload"> <label for="auto-reload"><?= $lang['autoreload'] ?></label> (<a id="set-interval" data-bind="onSetInterval"><span id="interval" data-bind="interval"><?= uConfig::$interval ?></span></a> s)<br>
|
||||
<input id="auto-reload" type="checkbox" data-bind="autoReload"> <label for="auto-reload"><?= $lang['autoreload'] ?></label> (<a id="set-interval" data-bind="onSetInterval"><span id="interval" data-bind="interval"><?= $config->interval ?></span></a> s)<br>
|
||||
<a id="force-reload" data-bind="onReload"> <?= $lang['reload'] ?></a><br>
|
||||
</div>
|
||||
|
||||
@ -91,8 +92,8 @@
|
||||
<div>
|
||||
<label for="api"><?= $lang['api'] ?></label>
|
||||
<select id="api" name="api" data-bind="mapApi">
|
||||
<option value="gmaps"<?= (uConfig::$mapApi === 'gmaps') ? ' selected' : '' ?>>Google Maps</option>
|
||||
<option value="openlayers"<?= (uConfig::$mapApi === 'openlayers') ? ' selected' : '' ?>>OpenLayers</option>
|
||||
<option value="gmaps"<?= ($config->mapApi === 'gmaps') ? ' selected' : '' ?>>Google Maps</option>
|
||||
<option value="openlayers"<?= ($config->mapApi === 'openlayers') ? ' selected' : '' ?>>OpenLayers</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
@ -100,7 +101,7 @@
|
||||
<label for="lang"><?= $lang['language'] ?></label>
|
||||
<select id="lang" name="lang" data-bind="lang">
|
||||
<?php foreach ($langsArr as $langCode => $langName): ?>
|
||||
<option value="<?= $langCode ?>"<?= (uConfig::$lang === $langCode) ? ' selected' : '' ?>><?= $langName ?></option>
|
||||
<option value="<?= $langCode ?>"<?= ($config->lang === $langCode) ? ' selected' : '' ?>><?= $langName ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
@ -108,9 +109,9 @@
|
||||
<div class="section">
|
||||
<label for="units"><?= $lang['units'] ?></label>
|
||||
<select id="units" name="units" data-bind="units">
|
||||
<option value="metric"<?= (uConfig::$units === 'metric') ? ' selected' : '' ?>><?= $lang['metric'] ?></option>
|
||||
<option value="imperial"<?= (uConfig::$units === 'imperial') ? ' selected' : '' ?>><?= $lang['imperial'] ?></option>
|
||||
<option value="nautical"<?= (uConfig::$units === 'nautical') ? ' selected' : '' ?>><?= $lang['nautical'] ?></option>
|
||||
<option value="metric"<?= ($config->units === 'metric') ? ' selected' : '' ?>><?= $lang['metric'] ?></option>
|
||||
<option value="imperial"<?= ($config->units === 'imperial') ? ' selected' : '' ?>><?= $lang['imperial'] ?></option>
|
||||
<option value="nautical"<?= ($config->units === 'nautical') ? ' selected' : '' ?>><?= $lang['nautical'] ?></option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
@ -142,7 +143,7 @@
|
||||
|
||||
</div>
|
||||
<div id="menu-button"><a data-bind="onMenuToggle"></a></div>
|
||||
<div id="footer"><a target="_blank" href="https://github.com/bfabiszewski/ulogger-server"><span class="mi">μ</span>logger</a> <?= uConfig::$version ?></div>
|
||||
<div id="footer"><a target="_blank" href="https://github.com/bfabiszewski/ulogger-server"><span class="mi">μ</span>logger</a> <?= $config->version ?></div>
|
||||
</div>
|
||||
|
||||
<div id="main">
|
||||
|
@ -23,11 +23,12 @@
|
||||
|
||||
$auth_error = uUtils::getBool('auth_error', false);
|
||||
|
||||
$lang = (new uLang(uConfig::$lang))->getStrings();
|
||||
$config = uConfig::getInstance();
|
||||
$lang = (new uLang($config))->getStrings();
|
||||
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="<?= uConfig::$lang ?>">
|
||||
<html lang="<?= $config->lang ?>">
|
||||
<head>
|
||||
<title><?= $lang["title"] ?></title>
|
||||
<?php include("meta.php"); ?>
|
||||
@ -49,7 +50,7 @@
|
||||
<br>
|
||||
<input type="submit" value="<?= $lang["login"] ?>">
|
||||
<input type="hidden" name="action" value="auth">
|
||||
<?php if (!uConfig::$requireAuthentication): ?>
|
||||
<?php if (!$config->requireAuthentication): ?>
|
||||
<div id="cancel"><a href="<?= BASE_URL ?>"><?= $lang["cancel"] ?></a></div>
|
||||
<?php endif; ?>
|
||||
</form>
|
||||
|
@ -33,7 +33,7 @@ if (file_exists(ROOT_DIR . '/vendor/autoload.php')) {
|
||||
}
|
||||
|
||||
// check we are running in CLI mode
|
||||
if (PHP_SAPI != 'cli') {
|
||||
if (PHP_SAPI !== 'cli') {
|
||||
exit('Call me on CLI only!' . PHP_EOL);
|
||||
}
|
||||
|
||||
@ -90,7 +90,9 @@ if (!$getopt->getOption('import-existing-track')) {
|
||||
$gpxFiles = $getopt->getOperand('gpx');
|
||||
foreach ($gpxFiles as $i => $gpxFile) {
|
||||
// skip last track?
|
||||
if ($getopt->getOption('skip-last-track') && $i === count($gpxFiles) - 1) continue;
|
||||
if ($getopt->getOption('skip-last-track') && $i === count($gpxFiles) - 1) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$gpxName = basename($gpxFile);
|
||||
|
||||
@ -105,7 +107,8 @@ foreach ($gpxFiles as $i => $gpxFile) {
|
||||
|
||||
print('importing ' . $gpxFile.'...' . PHP_EOL);
|
||||
|
||||
$lang = (new uLang(uConfig::$lang))->getStrings();
|
||||
$config = uConfig::getInstance();
|
||||
$lang = (new uLang($config))->getStrings();
|
||||
|
||||
$gpx = false;
|
||||
libxml_use_internal_errors(true);
|
||||
@ -125,7 +128,7 @@ foreach ($gpxFiles as $i => $gpxFile) {
|
||||
}
|
||||
uUtils::exitWithError($message);
|
||||
}
|
||||
else if ($gpx->getName() != "gpx") {
|
||||
else if ($gpx->getName() !== "gpx") {
|
||||
uUtils::exitWithError($lang["iparsefailure"]);
|
||||
}
|
||||
else if (empty($gpx->trk)) {
|
||||
|
@ -30,6 +30,21 @@ if (version_compare(PHP_VERSION, "5.5.0", "<")) {
|
||||
}
|
||||
|
||||
define("ROOT_DIR", dirname(__DIR__));
|
||||
$dbConfig = ROOT_DIR . "/config.php";
|
||||
$dbConfigLoaded = false;
|
||||
$configDSN = "";
|
||||
$configUser = "";
|
||||
$configPass = "";
|
||||
$configPrefix = "";
|
||||
if (file_exists($dbConfig)) {
|
||||
/** @noinspection PhpIncludeInspection */
|
||||
include($dbConfig);
|
||||
$dbConfigLoaded = true;
|
||||
if (isset($dbdsn)) { $configDSN = $dbdsn; }
|
||||
if (isset($dbuser)) { $configUser = $dbuser; }
|
||||
if (isset($dbpass)) { $configPass = $dbpass; }
|
||||
if (isset($dbprefix)) { $configPrefix = $dbprefix; }
|
||||
}
|
||||
require_once(ROOT_DIR . "/helpers/db.php");
|
||||
require_once(ROOT_DIR . "/helpers/config.php");
|
||||
require_once(ROOT_DIR . "/helpers/lang.php");
|
||||
@ -37,11 +52,14 @@ require_once(ROOT_DIR . "/helpers/user.php");
|
||||
require_once(ROOT_DIR . "/helpers/utils.php");
|
||||
|
||||
$command = uUtils::postString("command");
|
||||
$language = uUtils::getString("lang", "en");
|
||||
|
||||
$lang = (new uLang(uConfig::$lang))->getStrings();
|
||||
$langSetup = (new uLang(uConfig::$lang))->getSetupStrings();
|
||||
$config = uConfig::getOfflineInstance();
|
||||
$config->lang = $language;
|
||||
$lang = (new uLang($config))->getStrings();
|
||||
$langSetup = (new uLang($config))->getSetupStrings();
|
||||
|
||||
$prefix = preg_replace("/[^a-z0-9_]/i", "", uConfig::$dbprefix);
|
||||
$prefix = preg_replace("/[^a-z0-9_]/i", "", $configPrefix);
|
||||
$tPositions = $prefix . "positions";
|
||||
$tTracks = $prefix . "tracks";
|
||||
$tUsers = $prefix . "users";
|
||||
@ -79,7 +97,7 @@ switch ($command) {
|
||||
if (!$error) {
|
||||
$messages[] = "<span class=\"ok\">{$langSetup["dbtablessuccess"]}</span>";
|
||||
$messages[] = $langSetup["setupuser"];
|
||||
$form = "<form id=\"userForm\" method=\"post\" action=\"setup.php\" onsubmit=\"return validateForm()\"><input type=\"hidden\" name=\"command\" value=\"adduser\">";
|
||||
$form = "<form id=\"userForm\" method=\"post\" action=\"setup.php?lang=$language\" onsubmit=\"return validateForm()\"><input type=\"hidden\" name=\"command\" value=\"adduser\">";
|
||||
$form .= "<label><b>{$lang["username"]}</b></label><input type=\"text\" placeholder=\"{$lang["usernameenter"]}\" name=\"login\" required>";
|
||||
$form .= "<label><b>{$lang["password"]}</b></label><input type=\"password\" placeholder=\"{$lang["passwordenter"]}\" name=\"pass\" required>";
|
||||
$form .= "<label><b>{$lang["passwordrepeat"]}</b></label><input type=\"password\" placeholder=\"{$lang["passwordenter"]}\" name=\"pass2\" required>";
|
||||
@ -90,6 +108,7 @@ switch ($command) {
|
||||
break;
|
||||
|
||||
case "adduser":
|
||||
$config->save();
|
||||
$login = uUtils::postString("login");
|
||||
$pass = uUtils::postPass("pass");
|
||||
|
||||
@ -104,43 +123,54 @@ switch ($command) {
|
||||
break;
|
||||
|
||||
default:
|
||||
$langsArr = uLang::getLanguages();
|
||||
$langsOpts = "";
|
||||
foreach ($langsArr as $langCode => $langName) {
|
||||
$langsOpts .= "<option value=\"$langCode\"" . ($config->lang === $langCode ? " selected" : "") . ">$langName</option>";
|
||||
}
|
||||
$messages[] = "<div id=\"language\">
|
||||
<label for=\"lang\">{$lang['language']}</label>
|
||||
<select id=\"lang\" name=\"lang\" onchange=\"return changeLang(this)\">
|
||||
$langsOpts
|
||||
</select>
|
||||
</div>";
|
||||
$messages[] = "<img src=\"../icons/favicon-32x32.png\" alt=\"µLogger\">" . $langSetup["welcome"];
|
||||
if (!isset($enabled) || $enabled === false) {
|
||||
$messages[] = sprintf($langSetup["disabledwarn"], "<b>\$enabled</b>", "<b>true</b>");
|
||||
$messages[] = sprintf($langSetup["lineshouldread"], "<br><span class=\"warn\">\$enabled = false;</span><br>", "<br><span class=\"ok\">\$enabled = true;</span>");
|
||||
$messages[] = $langSetup["dorestart"];
|
||||
$messages[] = "<form method=\"post\" action=\"setup.php\"><button>{$langSetup["restartbutton"]}</button></form>";
|
||||
$messages[] = "<form method=\"post\" action=\"setup.php?lang=$language\"><button>{$langSetup["restartbutton"]}</button></form>";
|
||||
break;
|
||||
}
|
||||
if (!uConfig::isFileLoaded()) {
|
||||
if (!$dbConfigLoaded) {
|
||||
$messages[] = $langSetup["createconfig"];
|
||||
$messages[] = $langSetup["dorestart"];
|
||||
$messages[] = "<form method=\"post\" action=\"setup.php\"><button>{$langSetup["restartbutton"]}</button></form>";
|
||||
$messages[] = "<form method=\"post\" action=\"setup.php?lang=$language\"><button>{$langSetup["restartbutton"]}</button></form>";
|
||||
break;
|
||||
}
|
||||
if (ini_get("session.auto_start") === "1") {
|
||||
$messages[] = sprintf($langSetup["optionwarn"], "session.auto_start", "0 (off)");
|
||||
$messages[] = $langSetup["dorestart"];
|
||||
$messages[] = "<form method=\"post\" action=\"setup.php\"><button>{$langSetup["restartbutton"]}</button></form>";
|
||||
$messages[] = "<form method=\"post\" action=\"setup.php?lang=$language\"><button>{$langSetup["restartbutton"]}</button></form>";
|
||||
break;
|
||||
}
|
||||
if (!extension_loaded("pdo")) {
|
||||
$messages[] = sprintf($langSetup["extensionwarn"], "PDO");
|
||||
$messages[] = $langSetup["dorestart"];
|
||||
$messages[] = "<form method=\"post\" action=\"setup.php\"><button>{$langSetup["restartbutton"]}</button></form>";
|
||||
$messages[] = "<form method=\"post\" action=\"setup.php?lang=$language\"><button>{$langSetup["restartbutton"]}</button></form>";
|
||||
break;
|
||||
}
|
||||
if (empty(uConfig::$dbdsn)) {
|
||||
if (empty($configDSN)) {
|
||||
$messages[] = sprintf($langSetup["nodbsettings"], "\$dbdsn");
|
||||
$messages[] = $langSetup["dorestart"];
|
||||
$messages[] = "<form method=\"post\" action=\"setup.php\"><button>{$langSetup["restartbutton"]}</button></form>";
|
||||
$messages[] = "<form method=\"post\" action=\"setup.php?lang=$language\"><button>{$langSetup["restartbutton"]}</button></form>";
|
||||
break;
|
||||
}
|
||||
try {
|
||||
$pdo = getPdo();
|
||||
} catch (PDOException $e) {
|
||||
$isSqlite = stripos(uConfig::$dbdsn, "sqlite") === 0;
|
||||
if (!$isSqlite && empty(uConfig::$dbuser)) {
|
||||
$isSqlite = stripos($configDSN, "sqlite") === 0;
|
||||
if (!$isSqlite && empty($configUser)) {
|
||||
$messages[] = sprintf($langSetup["nodbsettings"], "\$dbuser, \$dbpass");
|
||||
} else {
|
||||
$messages[] = $langSetup["dbconnectfailed"];
|
||||
@ -148,15 +178,15 @@ switch ($command) {
|
||||
$messages[] = sprintf($langSetup["serversaid"], "<b>" . htmlentities($e->getMessage()) . "</b>");
|
||||
}
|
||||
$messages[] = $langSetup["dorestart"];
|
||||
$messages[] = "<form method=\"post\" action=\"setup.php\"><button>{$langSetup["restartbutton"]}</button></form>";
|
||||
$messages[] = "<form method=\"post\" action=\"setup.php?lang=$language\"><button>{$langSetup["restartbutton"]}</button></form>";
|
||||
break;
|
||||
}
|
||||
$pdo = null;
|
||||
$dbName = uDb::getDbName(uConfig::$dbdsn);
|
||||
$dbName = uDb::getDbName($configDSN);
|
||||
$dbName = empty($dbName) ? '""' : "<b>" . htmlentities($dbName) . "</b>";
|
||||
$messages[] = sprintf($langSetup["scriptdesc"], "'$tPositions', '$tTracks', '$tUsers'", $dbName);
|
||||
$messages[] = $langSetup["scriptdesc2"];
|
||||
$messages[] = "<form method=\"post\" action=\"setup.php\"><input type=\"hidden\" name=\"command\" value=\"setup\"><button>{$langSetup["startbutton"]}</button></form>";
|
||||
$messages[] = "<form method=\"post\" action=\"setup.php?lang=$language\"><input type=\"hidden\" name=\"command\" value=\"setup\"><button>{$langSetup["startbutton"]}</button></form>";
|
||||
break;
|
||||
}
|
||||
|
||||
@ -417,14 +447,15 @@ function getQueries($dbDriver) {
|
||||
* @throws PDOException
|
||||
*/
|
||||
function getPdo() {
|
||||
global $configDSN, $configUser, $configPass;
|
||||
$options = [ PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION ];
|
||||
return new PDO(uConfig::$dbdsn, uConfig::$dbuser, uConfig::$dbpass, $options);
|
||||
return new PDO($configDSN, $configUser, $configPass, $options);
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang="<?= uConfig::$lang ?>">
|
||||
<html lang="<?= $language ?>">
|
||||
<head>
|
||||
<title><?= $lang["title"] ?></title>
|
||||
<meta http-equiv="Content-type" content="text/html;charset=UTF-8">
|
||||
@ -455,6 +486,14 @@ function getPdo() {
|
||||
-webkit-border-radius: 5px;
|
||||
}
|
||||
|
||||
#language {
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
#language label {
|
||||
font-size: small;
|
||||
}
|
||||
|
||||
.warn {
|
||||
color: #ffc747;
|
||||
}
|
||||
@ -466,7 +505,6 @@ function getPdo() {
|
||||
<!--suppress ES6ConvertVarToLetConst -->
|
||||
<script>
|
||||
var lang = <?= json_encode($lang) ?>;
|
||||
var pass_regex = <?= uConfig::passRegex() ?>;
|
||||
|
||||
function validateForm() {
|
||||
var form = document.getElementById('userForm');
|
||||
@ -481,12 +519,13 @@ function getPdo() {
|
||||
alert(lang['passnotmatch']);
|
||||
return false;
|
||||
}
|
||||
if (!pass_regex.test(pass)) {
|
||||
alert(lang['passlenmin'] + '\n' + lang['passrules']);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function changeLang(el) {
|
||||
window.location = '?lang=' + el.value;
|
||||
return false;
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
|
||||
|
@ -18,9 +18,11 @@
|
||||
*/
|
||||
|
||||
require_once(dirname(__DIR__) . "/helpers/auth.php");
|
||||
require_once(ROOT_DIR . "/helpers/config.php");
|
||||
require_once(ROOT_DIR . "/helpers/utils.php");
|
||||
|
||||
$auth = new uAuth();
|
||||
$config = uConfig::getInstance();
|
||||
if (!$auth->isAuthenticated()) {
|
||||
$auth->sendUnauthorizedHeader();
|
||||
uUtils::exitWithError("Unauthorized");
|
||||
@ -33,6 +35,9 @@
|
||||
if (empty($pass)) {
|
||||
uUtils::exitWithError("Empty password");
|
||||
}
|
||||
if (!$config->validPassStrength($pass)) {
|
||||
uUtils::exitWithError("Invalid password strength");
|
||||
}
|
||||
if (empty($login)) {
|
||||
uUtils::exitWithError("Empty login");
|
||||
}
|
||||
|
@ -23,7 +23,8 @@ require_once(ROOT_DIR . "/helpers/lang.php");
|
||||
require_once(ROOT_DIR . "/helpers/config.php");
|
||||
|
||||
$auth = new uAuth();
|
||||
$lang = (new uLang(uConfig::$lang))->getStrings();
|
||||
$config = uConfig::getInstance();
|
||||
$lang = (new uLang($config))->getStrings();
|
||||
|
||||
/**
|
||||
* Add kml marker style element
|
||||
@ -62,13 +63,13 @@ $type = uUtils::getString('type', 'kml');
|
||||
$userId = uUtils::getInt('userid');
|
||||
$trackId = uUtils::getInt('trackid');
|
||||
|
||||
if (!uConfig::$publicTracks &&
|
||||
if (!$config->publicTracks &&
|
||||
(!$auth->isAuthenticated() || (!$auth->isAdmin() && $auth->user->id !== $userId))) {
|
||||
// unauthorized
|
||||
exit();
|
||||
}
|
||||
|
||||
if (uConfig::$units === "imperial") {
|
||||
if ($config->units === "imperial") {
|
||||
$factor_kmh = 0.62; //to mph
|
||||
$unit_kmh = "mph";
|
||||
$factor_m = 3.28; // to feet
|
||||
@ -185,7 +186,7 @@ if ($trackId && $userId) {
|
||||
$xml->writeAttributeNs("xsi", "schemaLocation", NULL, "http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd https://github.com/bfabiszewski/ulogger-android/1 https://raw.githubusercontent.com/bfabiszewski/ulogger-server/master/scripts/gpx_extensions1.xsd");
|
||||
$xml->writeAttributeNs("xmlns", "xsi", NULL, "http://www.w3.org/2001/XMLSchema-instance");
|
||||
$xml->writeAttributeNs("xmlns", "ulogger", NULL, "https://github.com/bfabiszewski/ulogger-android/1");
|
||||
$xml->writeAttribute("creator", "μlogger-server " . uConfig::$version);
|
||||
$xml->writeAttribute("creator", "μlogger-server " . $config->version);
|
||||
$xml->writeAttribute("version", "1.1");
|
||||
$xml->startElement("metadata");
|
||||
$xml->writeElement("name", $positionsArr[0]->trackName);
|
||||
|
@ -22,7 +22,8 @@ require_once(ROOT_DIR . "/helpers/config.php");
|
||||
require_once(ROOT_DIR . "/helpers/lang.php");
|
||||
|
||||
$auth = new uAuth();
|
||||
$langStrings = (new uLang(uConfig::$lang))->getStrings();
|
||||
$config = uConfig::getInstance();
|
||||
$langStrings = (new uLang($config))->getStrings();
|
||||
|
||||
$result = [];
|
||||
$resultAuth = [
|
||||
@ -35,20 +36,20 @@ if ($auth->isAuthenticated()) {
|
||||
}
|
||||
|
||||
$resultConfig = [
|
||||
"interval" => uConfig::$interval,
|
||||
"units" => uConfig::$units,
|
||||
"lang" => uConfig::$lang,
|
||||
"mapApi" => uConfig::$mapApi,
|
||||
"gkey" => uConfig::$googleKey,
|
||||
"initLatitude" => uConfig::$initLatitude,
|
||||
"initLongitude" => uConfig::$initLongitude,
|
||||
"passRegex" => uConfig::passRegex(),
|
||||
"strokeWeight" => uConfig::$strokeWeight,
|
||||
"strokeColor" => uConfig::$strokeColor,
|
||||
"strokeOpacity" => uConfig::$strokeOpacity,
|
||||
"interval" => $config->interval,
|
||||
"units" => $config->units,
|
||||
"lang" => $config->lang,
|
||||
"mapApi" => $config->mapApi,
|
||||
"gkey" => $config->googleKey,
|
||||
"initLatitude" => $config->initLatitude,
|
||||
"initLongitude" => $config->initLongitude,
|
||||
"passRegex" => $config->passRegex(),
|
||||
"strokeWeight" => $config->strokeWeight,
|
||||
"strokeColor" => $config->strokeColor,
|
||||
"strokeOpacity" => $config->strokeOpacity,
|
||||
"olLayers" => []
|
||||
];
|
||||
foreach (uConfig::$olLayers as $key => $val) {
|
||||
foreach ($config->olLayers as $key => $val) {
|
||||
$resultConfig["olLayers"][$key] = $val;
|
||||
}
|
||||
|
||||
|
@ -18,10 +18,12 @@
|
||||
*/
|
||||
|
||||
require_once(dirname(__DIR__) . "/helpers/auth.php");
|
||||
require_once(ROOT_DIR . "/helpers/config.php");
|
||||
require_once(ROOT_DIR . "/helpers/position.php");
|
||||
require_once(ROOT_DIR . "/helpers/utils.php");
|
||||
|
||||
$auth = new uAuth();
|
||||
$config = uConfig::getInstance();
|
||||
|
||||
$userId = uUtils::getInt('userid');
|
||||
$trackId = uUtils::getInt('trackid');
|
||||
@ -30,7 +32,7 @@ $last = uUtils::getBool('last');
|
||||
|
||||
$positionsArr = [];
|
||||
if ($userId) {
|
||||
if (uConfig::$publicTracks ||
|
||||
if ($config->publicTracks ||
|
||||
($auth->isAuthenticated() && ($auth->isAdmin() || $auth->user->id === $userId))) {
|
||||
if ($trackId) {
|
||||
// get all track data
|
||||
@ -44,7 +46,7 @@ if ($userId) {
|
||||
}
|
||||
}
|
||||
} else if ($last) {
|
||||
if (uConfig::$publicTracks || ($auth->isAuthenticated() && ($auth->isAdmin()))) {
|
||||
if ($config->publicTracks || ($auth->isAuthenticated() && ($auth->isAdmin()))) {
|
||||
$positionsArr = uPosition::getLastAllUsers();
|
||||
}
|
||||
}
|
||||
|
@ -18,15 +18,17 @@
|
||||
*/
|
||||
|
||||
require_once(dirname(__DIR__) . "/helpers/auth.php");
|
||||
require_once(ROOT_DIR . "/helpers/config.php");
|
||||
require_once(ROOT_DIR . "/helpers/track.php");
|
||||
|
||||
$auth = new uAuth();
|
||||
$config = uConfig::getInstance();
|
||||
|
||||
$userId = uUtils::getInt('userid');
|
||||
|
||||
$tracksArr = [];
|
||||
if ($userId) {
|
||||
if (uConfig::$publicTracks ||
|
||||
if ($config->publicTracks ||
|
||||
($auth->isAuthenticated() && ($auth->isAdmin() || $auth->user->id === $userId))) {
|
||||
$tracksArr = uTrack::getAll($userId);
|
||||
}
|
||||
|
@ -19,12 +19,14 @@
|
||||
*/
|
||||
|
||||
require_once(dirname(__DIR__) . "/helpers/auth.php");
|
||||
require_once(ROOT_DIR . "/helpers/config.php");
|
||||
require_once(ROOT_DIR . "/helpers/track.php");
|
||||
|
||||
$auth = new uAuth();
|
||||
$config = uConfig::getInstance();
|
||||
|
||||
$usersArr = [];
|
||||
if (uConfig::$publicTracks || $auth->isAdmin()) {
|
||||
if ($config->publicTracks || $auth->isAdmin()) {
|
||||
$usersArr = uUser::getAll();
|
||||
} else if ($auth->isAuthenticated()) {
|
||||
$usersArr = [ $auth->user ];
|
||||
|
@ -29,7 +29,8 @@
|
||||
$positionId = uUtils::postInt('posid');
|
||||
$comment = uUtils::postString('comment');
|
||||
|
||||
$lang = (new uLang(uConfig::$lang))->getStrings();
|
||||
$config = uConfig::getInstance();
|
||||
$lang = (new uLang($config))->getStrings();
|
||||
|
||||
if (empty($action) || empty($positionId)) {
|
||||
uUtils::exitWithError($lang["servererror"]);
|
||||
|
@ -29,7 +29,8 @@
|
||||
$trackId = uUtils::postInt('trackid');
|
||||
$trackName = uUtils::postString('trackname');
|
||||
|
||||
$lang = (new uLang(uConfig::$lang))->getStrings();
|
||||
$config = uConfig::getInstance();
|
||||
$lang = (new uLang($config))->getStrings();
|
||||
|
||||
if (empty($action) || empty($trackId)) {
|
||||
uUtils::exitWithError($lang["servererror"]);
|
||||
|
@ -23,15 +23,16 @@
|
||||
require_once(ROOT_DIR . "/helpers/utils.php");
|
||||
|
||||
$auth = new uAuth();
|
||||
$config = uConfig::getInstance();
|
||||
|
||||
$action = uUtils::postString('action');
|
||||
$login = uUtils::postString('login');
|
||||
$pass = uUtils::postPass('pass');
|
||||
$admin = uUtils::postBool('admin', false);
|
||||
|
||||
$lang = (new uLang(uConfig::$lang))->getStrings();
|
||||
$lang = (new uLang($config))->getStrings();
|
||||
|
||||
if (!$auth->isAuthenticated() || !$auth->isAdmin() || $auth->user->login === $login || empty($action) || empty($login)) {
|
||||
if ($auth->user->login === $login || empty($action) || empty($login) || !$auth->isAuthenticated() || !$auth->isAdmin()) {
|
||||
uUtils::exitWithError($lang["servererror"]);
|
||||
}
|
||||
|
||||
@ -47,7 +48,7 @@
|
||||
if ($aUser->isValid) {
|
||||
uUtils::exitWithError($lang["userexists"]);
|
||||
}
|
||||
if (empty($pass) || ($userId = uUser::add($login, $pass, $admin)) === false) {
|
||||
if (empty($pass) || !$config->validPassStrength($pass) || ($userId = uUser::add($login, $pass, $admin)) === false) {
|
||||
uUtils::exitWithError($lang["servererror"]);
|
||||
} else {
|
||||
$data = [ 'id' => $userId ];
|
||||
@ -58,7 +59,7 @@
|
||||
if ($aUser->setAdmin($admin) === false) {
|
||||
uUtils::exitWithError($lang["servererror"]);
|
||||
}
|
||||
if (!empty($pass) && $aUser->setPass($pass) === false) {
|
||||
if (!empty($pass) && (!$config->validPassStrength($pass) || $aUser->setPass($pass) === false)) {
|
||||
uUtils::exitWithError($lang["servererror"]);
|
||||
}
|
||||
break;
|
||||
|
@ -26,7 +26,8 @@ require_once(ROOT_DIR . "/helpers/lang.php");
|
||||
|
||||
$auth = new uAuth();
|
||||
|
||||
$lang = (new uLang(uConfig::$lang))->getStrings();
|
||||
$config = uConfig::getInstance();
|
||||
$lang = (new uLang($config))->getStrings();
|
||||
|
||||
$uploadErrors = [];
|
||||
$uploadErrors[UPLOAD_ERR_INI_SIZE] = "The uploaded file exceeds the upload_max_filesize directive in php.ini";
|
||||
|
Loading…
x
Reference in New Issue
Block a user