Commit 764f2e3f authored by Karamel's avatar Karamel
Browse files

Single user SysModules, use them by default in sample config file.

Recycled unused StaticDB and LocalIdent.
parent 987d3a2a
......@@ -88,11 +88,11 @@ $filesToCheck = [
'src/lib/System/SysModules/SysModuleFactory.php',
'src/lib/System/SysModules/SysModuleConfigException.php',
'src/lib/System/SysModules/Ident/InifileIdent.php',
'src/lib/System/SysModules/Ident/LocalIdent.php',
'src/lib/System/SysModules/Ident/SingleIdent.php',
'src/lib/System/SysModules/Ident/IdentModule.php',
'src/lib/System/SysModules/SysModule.php',
'src/lib/System/SysModules/Database/DBModule.php',
'src/lib/System/SysModules/Database/StaticDB.php',
'src/lib/System/SysModules/Database/SingleDB.php',
'src/lib/System/SysModules/Database/InifileDB.php',
'src/lib/System/SysModules/Database/DynamicDB.php',
'src/lib/System/DAO/DoctrineModel.php',
......
; Core module ident
;------------------
; Module to use. The value must match a directory in core_modules/ident/
; See the choosen module properties below
core_ident = "inifile"
; Either "inifile" for one ini file per user or "single" for a single user.
; See the choosen module properties below.
core_ident = "single"
; Core ident inifile
; Core ident single (used only when core_ident = "single").
; User login
ident/single/login = "pasteque"
; User password hash
ident/single/password = "$2y$10$5uigA2g7wd3C56YZ8OHQwuxz/dx7kyX0f2zs5Qg09AI.98EZYX1my"
; Core ident inifile (used only when core_ident = "inifile").
; Base path to the directory containing all user's ini files.
; Either relative to the base directory of Pasteque ,start with ./
; or an absolute path.
; Each ini file is named <login>_id.ini, some special characters are
; replaced by 'underscore charcode underscore'
ident/inifile/path = "auth"
; Core ident database
;ident/database/dns = "mysql:host=...;dbname=..."
;ident/database/db_username = "..."
;ident/database/du_password = "..."
; Core module database
;---------------------
; Module to use. The value must match a directory in core_modules/database/
; See the choosen module properties below
core_database = "inifile"
; Either "inifile" for one ini file per user or "single" for a single user.
; See the choosen module properties below.
core_database = "single"
; Core database solo (used only when core_database = "solo").
; Database type, either "mysql" or "postgresql".
database/single/type = "postgresql"
; Database host.
database/single/host = "localhost"
; Database port. Default is 5432 for postgresql and 3306 for mysql.
database/single/port = 5432
; Database user.
database/single/user = "pasteque"
; Database password.
database/single/password = "pasteque"
; Database name.
database/single/name = "pasteque"
; Core database inifile
; Core database inifile (used only when core_database = "inifile").
; Base path to the directory containing all user's ini files.
; Either relative to the base directory of Pasteque ,start with ./
; or an absolute path.
; Each ini file is named <login>_db.ini, some special characters are
; replaced by 'underscore charcode underscore'
database/inifile/path = "auth"
; Core database static
;database/static/type = "mysql"
;database/static/host = "localhost"
;database/static/port = 3306
;database/static/name = "pasteque"
;database/static/user = "user"
;database/static/password = "password"
; JWT auth and origin
;--------------------
......@@ -43,7 +54,7 @@ database/inifile/path = "auth"
jwt_timeout = 600
; Set this to a superstrong password
jwt_secret = "<Change me>"
; Uncomment to allow calls from everywhere ,not recommended
; Uncomment to allow calls from everywhere, not recommended
;allowed_origin = *
; Uncomment to allow calls from a whitelist
;allowed_origin[] = http://<domain>
......
<?php
// Pasteque API
/// Pastèque Web back office, Single ident module
//
// Copyright (C) 2012-2917 Pasteque contributors
// Copyright (C) 2013 Scil (http://scil.coop)
//
// This file is part of Pasteque.
// This file is part of Pastèque.
//
// Pasteque is free software: you can redistribute it and/or modify
// Pastèque 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.
//
// Pasteque is distributed in the hope that it will be useful,
// Pastèque 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 Pasteque. If not, see <http://www.gnu.org/licenses/>.
// along with Pastèque. If not, see <http://www.gnu.org/licenses/>.
namespace Pasteque\Server\System\SysModules\Database;
/** Read database info from configuration (single user only).
/** Read database info from configuration.
* Requires "type", "host", "name", "user", "password" to define
* database url and credentials. */
class StaticDB extends DBModule {
class SingleDB extends DBModule {
protected static $expectedProperties = array(array('name' => 'type', 'default' => 'mysql'),
array('name' => 'host', 'default' => 'localhost'),
array('name' => 'port', 'default' => 3306),
array('name' => 'name', 'default' => 'pasteque'),
'user', 'password');
protected static $expectedProperties = ['type', 'host', 'port',
'name', 'user', 'password'];
public function getDatabase($login) {
return array('type' => $this->getProperty('type'),
return ['type' => $this->getProperty('type'),
'host' => $this->getProperty('host'),
'port' => $this->getProperty('port'),
'name' => $this->getProperty('name'),
'user' => $this->getProperty('user'),
'password' => $this->getProperty('password'));
'password' => $this->getProperty('password')];
}
}
<?php
// Pastèque Web back office, Ini File ident module
// Pastèque Web back office, Single ident module
//
// Copyright (C) 2013 Scil (http://scil.coop)
//
......@@ -20,36 +20,18 @@
namespace Pasteque\Server\System\SysModules\Ident;
/** Read authentication data from database.
/** Read authentication data from configuration.
* Requires "db_dsn", "db_username" and "db_password".
* The database must have a table named pasteque_users
* (user_id, can_login, password). */
class LocalIdent extends IdentModule {
class SingleIdent extends IdentModule {
protected static $expectedProperties = array(
"db_dsn", "db_username", "db_password");
private function getLocalAuthDatabase() {
return new \PDO($this->getProperty('db_dsn'),
$this->getProperty('db_username'),
$this->getProperty('db_password');
}
protected static $expectedProperties = ['login', 'password'];
public function getUser($login) {
// Check in database...
// Get the main database
$dbh_ident = $this->getLocalAuthDatabase();
$stmt = $dbh_ident->prepare('SELECT * FROM pasteque_users '
. 'WHERE can_login AND user_id = :user_id');
$stmt->bindParam(':user_id', $login, \PDO::PARAM_STR);
$stmt->execute();
$result = $stmt->fetchAll();
if (count($result) != 1) {
// Bouh, invalid user
\Pasteque\Log::info(sprintf('Unavailable user %s', $login));
return null;
if ($login == $this->getProperty('login')) {
return ['id' => $login, 'pwd_hash' => $this->getProperty('password')];
}
$userDbData = $result[0];
return array('id' => $login, 'pwd_hash' => $userDbData['password']);
return null;
}
}
\ No newline at end of file
}
......@@ -39,7 +39,7 @@ abstract class SysModule {
}
/** Build a module with configuration properties.
* @throws ModuleConfigException When a required property is missing. */
* @throws SysModuleConfigException When a required property is missing. */
public function __construct($properties) {
$this->properties = array();
foreach (static::$expectedProperties as $prop) {
......@@ -49,7 +49,7 @@ abstract class SysModule {
if (is_array($prop) && array_key_exists('default', $prop)) {
$this->properties[$name] = $prop['default'];
} else {
throw new ModuleConfigException($prop);
throw new SysModuleConfigException($prop);
}
} else {
$this->properties[$name] = $properties[$name];
......
......@@ -32,8 +32,8 @@ class SysModuleFactory {
switch ($name) {
case 'inifile':
return new Ident\InifileIdent($config);
case 'local':
return new Ident\LocalIdent($config);
case 'single':
return new Ident\SingleIdent($config);
default:
throw new SysModuleNotFoundException(sprintf('ident/%s', $name));
}
......@@ -44,8 +44,8 @@ class SysModuleFactory {
switch ($name) {
case 'inifile':
return new Database\InifileDB($config);
case 'static':
return new Database\StaticDB($config);
case 'single':
return new Database\SingleDB($config);
default:
throw new SysModuleNotFoundException(sprintf('database/%s', $name));
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment