WIP make it run in docker

This commit is contained in:
marko
2024-11-13 13:28:30 +01:00
parent 1d9deebd58
commit b9b47c069a
4 changed files with 650 additions and 577 deletions

View File

@@ -1,12 +1,23 @@
<?php <?php
/// @file some variable definitions /// @file some variable definitions
$config['basePath'] = '/users/cwsvjudo/www'; # define variable holding the config
$config['baseUrl'] = 'http://cwsvjudo.bplaced.net'; if (!isset($config)) {
$config['ressourceUrl'] = 'http://cwsvjudo.bplaced.net/ressourcen'; $config = [];
}
setlocale(LC_ALL, 'de_DE@euro', 'de_DE', 'de', 'ge'); $config["home"] = "/home/cwsvjudo";
set_include_path(implode( $config["basePath"] = "/home/cwsvjudo/www";
PATH_SEPARATOR, $config["baseUrl"] = "http://cwsvjudo.bplaced.net";
[get_include_path(), $config['basePath'], $config['basePath'] . '/ressourcen', $config['basePath'] . '/ressourcen/phpLib', './lib/'] $config["ressourceUrl"] = "http://cwsvjudo.bplaced.net/ressourcen";
));
setlocale(LC_ALL, "de_DE@euro", "de_DE", "de", "ge");
set_include_path(
implode(PATH_SEPARATOR, [
get_include_path(),
$config["basePath"],
$config["basePath"] . "/ressourcen",
$config["basePath"] . "/ressourcen/phpLib",
"./lib/",
])
);

View File

@@ -1,30 +1,31 @@
<?php <?php
setlocale(LC_ALL, 'de_DE@euro', 'de_DE', 'de', 'ge'); setlocale(LC_ALL, "de_DE@euro", "de_DE", "de", "ge");
set_include_path(get_include_path() . PATH_SEPARATOR . './lib/'); set_include_path(get_include_path() . PATH_SEPARATOR . "./lib/");
require_once 'participoLib/participo.php'; require_once "participoLib/participo.php";
require_once 'participoLib/planer.php'; require_once "participoLib/planer.php";
require_once 'config/participo.php'; require_once "config/participo.php";
require_once './local/dbConf.php'; require_once "./local/dbConf.php";
require_once './local/cwsvJudo.php'; require_once "./local/cwsvJudo.php";
require_once './lib/db.php'; require_once "./lib/db.php";
require_once './lib/api.php'; require_once "./lib/api.php";
require_once $config['basePath'] . '/config/cwsvJudo.config.php'; require_once $config["home"] . "/.local/cwsvJudo.config.php";
dbConnector::connect( dbConnector::connect(
$cwsvJudoConfig['db']['host'], $cwsvJudoConfig["db"]["host"],
$cwsvJudoConfig['db']['name'], $cwsvJudoConfig["db"]["name"],
$cwsvJudoConfig['db']['user'], $cwsvJudoConfig["db"]["user"],
$cwsvJudoConfig['db']['password'] $cwsvJudoConfig["db"]["password"]
); );
participo::authentificate(); participo::authentificate();
$meta = [ $meta = [
'title' => 'Event Planer', "title" => "Event Planer",
'description' => 'Planung von (Nicht-)Teilnahmen an Wettkämpfen und anderen Veranstaltungen' "description" =>
"Planung von (Nicht-)Teilnahmen an Wettkämpfen und anderen Veranstaltungen",
]; ];

View File

@@ -1,11 +1,11 @@
<?php <?php
require_once 'participoLib/dbConnector.php'; require_once "participoLib/dbConnector.php";
require_once 'participoLib/user.php'; require_once "participoLib/user.php";
require_once 'participoLib/event.php'; require_once "participoLib/event.php";
require_once 'participoLib/eventPage.php'; require_once "participoLib/eventPage.php";
require_once 'participoLib/starter.php'; require_once "participoLib/starter.php";
require_once 'participoLib/planer.php'; require_once "participoLib/planer.php";
/** /**
* FrameWork for the participoApp * FrameWork for the participoApp
@@ -26,7 +26,11 @@ class participo
} }
private static $db = null; private static $db = null;
private static $message = ['error' => null, 'success' => null, 'notice' => null]; private static $message = [
"error" => null,
"success" => null,
"notice" => null,
];
/** id of session user /** id of session user
* *
@@ -46,7 +50,7 @@ class participo
public static function getSessionUserId() public static function getSessionUserId()
{ {
if (!isset(self::$userId)) { if (!isset(self::$userId)) {
self::$userId = $_SESSION['user']['userId'] ?? null; self::$userId = $_SESSION["user"]["userId"] ?? null;
} }
self::$userId = filterId(self::$userId); self::$userId = filterId(self::$userId);
return self::$userId; return self::$userId;
@@ -69,7 +73,9 @@ class participo
*/ */
public static function isLoginValid() public static function isLoginValid()
{ {
return (isset($_SESSION) && array_key_exists('login', $_SESSION) && $_SESSION['login'] == true); return isset($_SESSION) &&
array_key_exists("login", $_SESSION) &&
$_SESSION["login"] == true;
} }
/** Remove all login data from the session data /** Remove all login data from the session data
@@ -78,7 +84,7 @@ class participo
*/ */
public static function logout() public static function logout()
{ {
foreach (['login', 'user'] as $key) { foreach (["login", "user"] as $key) {
unset($_SESSION[$key]); unset($_SESSION[$key]);
} }
} }
@@ -89,12 +95,15 @@ class participo
*/ */
public static function htmlLoginStatus() public static function htmlLoginStatus()
{ {
return return '<div style="border: 1px solid black">' .
'<div style="border: 1px solid black">' . "Datum: " .
'Datum: ' . date('Y-m-d') . '<br />' . date("Y-m-d") .
'Eingeloggt als <strong>' . htmlspecialchars($_SESSION['user']['username']) . '</strong>.<br />' . "<br />" .
"Eingeloggt als <strong>" .
htmlspecialchars($_SESSION["user"]["username"]) .
"</strong>.<br />" .
'<a href="logout.php">Sitzung beenden</a>' . '<a href="logout.php">Sitzung beenden</a>' .
'</div>'; "</div>";
} }
/** Checking if an action is allowed. A present apiKey overrides (and deletes) a present login. /** Checking if an action is allowed. A present apiKey overrides (and deletes) a present login.
@@ -114,36 +123,43 @@ class participo
* *
* @retval void * @retval void
*/ */
public static function authentificate($action = 'login') public static function authentificate($action = "login")
{ {
// Ensure a session is started // Ensure a session is started
session_start(); session_start();
// check if an apiKey was received // check if an apiKey was received
if (array_key_exists('apiKey', $_GET)) { if (array_key_exists("apiKey", $_GET)) {
self::logout(); self::logout();
$key = ApiKey::loadFromDb($_GET['apiKey']); $key = ApiKey::loadFromDb($_GET["apiKey"]);
if (isset($key) && $key->isValidFor($action)) { if (isset($key) && $key->isValidFor($action)) {
$user = User::loadFromDb($key->getUserId()); $user = User::loadFromDb($key->getUserId());
// case valid login: Set the session data // case valid login: Set the session data
$_SESSION = [ $_SESSION = [
'login' => true, //false, "login" => true, //false,
'apiKey' => $key->getKey(), "apiKey" => $key->getKey(),
'user' => [ "user" => [
'username' => $user->getLoginName(), "username" => $user->getLoginName(),
'userId' => $user->getId(), "userId" => $user->getId(),
'userConfig' => $user->getConfig(), "userConfig" => $user->getConfig(),
] ],
]; ];
logLoginsToJsonFile($user->getLoginName()); logLoginsToJsonFile($user->getLoginName());
// we're not logged in, but authorized for the stuff we want to do. So don't redirect // we're not logged in, but authorized for the stuff we want to do. So don't redirect
return; return;
}; }
} }
// if not returned yet: no login, no valid apiKey -> redirect to login page // if not returned yet: no login, no valid apiKey -> redirect to login page
if (!self::isLoginValid()) { if (!self::isLoginValid()) {
header('Location: login?returnToUrl=' . urlencode($_SERVER['REQUEST_URI'] . ($_POST['fragment'] ?? '')), true, 301); header(
"Location: login?returnToUrl=" .
urlencode(
$_SERVER["REQUEST_URI"] . ($_POST["fragment"] ?? "")
),
true,
301
);
exit(); // shouldn't matter exit(); // shouldn't matter
} }
} }
@@ -160,10 +176,10 @@ class participo
{ {
self::authentificate(); self::authentificate();
self::initDb( self::initDb(
$config['db']['host'], $config["db"]["host"],
$config['db']['name'], $config["db"]["name"],
$config['db']['user'], $config["db"]["user"],
$config['db']['password'] $config["db"]["password"]
); );
} }
@@ -182,8 +198,8 @@ class participo
*/ */
public static function parseParams($params) public static function parseParams($params)
{ {
$method = $_SERVER['REQUEST_METHOD']; $method = $_SERVER["REQUEST_METHOD"];
$request = explode('/', substr(@$_SERVER['PATH_INFO'], 1)); $request = explode("/", substr(@$_SERVER["PATH_INFO"], 1));
$parsedParams = []; $parsedParams = [];
foreach ($params as $paramName => $parseFunction) { foreach ($params as $paramName => $parseFunction) {
@@ -192,11 +208,15 @@ class participo
// case 'PUT': // case 'PUT':
// do_something_with_put($request); // do_something_with_put($request);
// break; // break;
case 'POST': case "POST":
$parsedParams[$paramName] = $parseFunction($_POST[$paramName]); $parsedParams[$paramName] = $parseFunction(
$_POST[$paramName]
);
break; break;
case 'GET': case "GET":
$parsedParams[$paramName] = $parseFunction($_GET[$paramName]); $parsedParams[$paramName] = $parseFunction(
$_GET[$paramName]
);
break; break;
default: default:
// handle_error($request); // handle_error($request);
@@ -213,7 +233,7 @@ class participo
public static function addMessage($type, $message) public static function addMessage($type, $message)
{ {
self::$message[$type] = (self::$message[$type] ?? '') . $message; self::$message[$type] = (self::$message[$type] ?? "") . $message;
} }
/** check password for user /** check password for user
@@ -230,7 +250,7 @@ class participo
// Check for dbConnection // Check for dbConnection
if (!dbConnector::getDbConnection()) { if (!dbConnector::getDbConnection()) {
self::addMessage('error', '<div>No DbConnection available</div>'); self::addMessage("error", "<div>No DbConnection available</div>");
return false; return false;
} }
@@ -239,25 +259,28 @@ class participo
// If there is no such user OR the password isn't valid the login fails // If there is no such user OR the password isn't valid the login fails
if ($user == null || !$user->verifyPassword($password)) { if ($user == null || !$user->verifyPassword($password)) {
sleep(5); // discourage brute force attacks sleep(5); // discourage brute force attacks
self::addMessage('error', '<div>Falsches Passwort oder LoginName</div>'); self::addMessage(
"error",
"<div>Falsches Passwort oder LoginName</div>"
);
return false; return false;
} }
session_start(); session_start();
// case valid login: Set the session data // case valid login: Set the session data
$_SESSION = [ $_SESSION = [
'login' => true, "login" => true,
'user' => [ "user" => [
'username' => $user->getLoginName(), "username" => $user->getLoginName(),
'userId' => $user->getId(), "userId" => $user->getId(),
'userConfig' => $user->getConfig() "userConfig" => $user->getConfig(),
] ],
]; ];
// Logging Logins // Logging Logins
logLoginsToJsonFile($_SESSION['user']['username']); logLoginsToJsonFile($_SESSION["user"]["username"]);
self::addMessage('success', '<div>Anmeldung erfolgreich</div>'); self::addMessage("success", "<div>Anmeldung erfolgreich</div>");
return true; return true;
} }
@@ -269,8 +292,8 @@ class participo
*/ */
public static function isUserAdmin($userId = null) public static function isUserAdmin($userId = null)
{ {
$userId = $userId ?? $_SESSION['user']['userId']; $userId = $userId ?? $_SESSION["user"]["userId"];
return self::hasUserAttribute($userId, 'isAdmin'); return self::hasUserAttribute($userId, "isAdmin");
} }
public static function getUserId() public static function getUserId()
@@ -280,24 +303,26 @@ class participo
/** get current logged in users kids */ /** get current logged in users kids */
public static function getKids($userId = null) public static function getKids($userId = null)
{ {
$userId = $userId ?? $_SESSION['user']['userId'] ?? null; $userId = $userId ?? ($_SESSION["user"]["userId"] ?? null);
$query = $query =
'SELECT * FROM `wkParticipo_Users` ' "SELECT * FROM `wkParticipo_Users` " .
. 'INNER JOIN `vormundschaft` ' "INNER JOIN `vormundschaft` " .
. 'ON `wkParticipo_Users`.`id` = `vormundschaft`.`kidId` ' "ON `wkParticipo_Users`.`id` = `vormundschaft`.`kidId` " .
. 'INNER JOIN `wkParticipo_user<=>userAttributes` ' "INNER JOIN `wkParticipo_user<=>userAttributes` " .
. 'ON `wkParticipo_Users`.`id` = `wkParticipo_user<=>userAttributes`.`userId`' "ON `wkParticipo_Users`.`id` = `wkParticipo_user<=>userAttributes`.`userId`" .
. 'WHERE `vormundschaft`.`userId` = :userId ' "WHERE `vormundschaft`.`userId` = :userId " .
. 'AND `vormundschaft`.`userId` = :userId ' "AND `vormundschaft`.`userId` = :userId " .
. 'AND `wkParticipo_user<=>userAttributes`.`attributeId` = 4;'; "AND `wkParticipo_user<=>userAttributes`.`attributeId` = 4;";
$params = [':userId' => ['value' => $userId, 'data_type' => PDO::PARAM_INT]]; $params = [
":userId" => ["value" => $userId, "data_type" => PDO::PARAM_INT],
];
$response = dbConnector::query($query, $params); $response = dbConnector::query($query, $params);
$kids = []; $kids = [];
foreach ($response as $r) { foreach ($response as $r) {
$kids[] = User::fromDbArray($r, ['id' => 'kidId']); $kids[] = User::fromDbArray($r, ["id" => "kidId"]);
} }
return $kids; return $kids;
} }
@@ -311,17 +336,18 @@ class participo
public static function isWardOf(int $kidId, int $userId = null) public static function isWardOf(int $kidId, int $userId = null)
{ {
// Try to get the Guard from the session data. // Try to get the Guard from the session data.
$userId = $userId ?? $_SESSION['user']['userId'] ?? null; $userId = $userId ?? ($_SESSION["user"]["userId"] ?? null);
$query = 'SELECT `kidId` FROM `vormundschaft` WHERE `userId` = :userId AND `kidId` = :kidId;'; $query =
"SELECT `kidId` FROM `vormundschaft` WHERE `userId` = :userId AND `kidId` = :kidId;";
$params = [ $params = [
':userId' => ['value' => $userId, 'data_type' => PDO::PARAM_INT], ":userId" => ["value" => $userId, "data_type" => PDO::PARAM_INT],
':kidId' => ['value' => $kidId, 'data_type' => PDO::PARAM_INT] ":kidId" => ["value" => $kidId, "data_type" => PDO::PARAM_INT],
]; ];
$response = dbConnector::query($query, $params); $response = dbConnector::query($query, $params);
return (count($response) >= 1); return count($response) >= 1;
} }
/** Checks, if a user as a certain attribute /** Checks, if a user as a certain attribute
@@ -340,13 +366,16 @@ ON `wkParticipo_user<=>userAttributes`.`attributeId` = `wkParticipo_userAttribut
WHERE `wkParticipo_userAttributes`.name = :attributeName AND userId=:userId; WHERE `wkParticipo_userAttributes`.name = :attributeName AND userId=:userId;
SQL; SQL;
$params = [ $params = [
':userId' => ['value' => $userId, 'data_type' => PDO::PARAM_INT], ":userId" => ["value" => $userId, "data_type" => PDO::PARAM_INT],
':attributeName' => ['value' => $attributeName, 'data_type' => PDO::PARAM_STR] ":attributeName" => [
"value" => $attributeName,
"data_type" => PDO::PARAM_STR,
],
]; ];
$attributedUsers = dbConnector::query($query, $params); $attributedUsers = dbConnector::query($query, $params);
// Since the id should be unique, there should only be one result this is just for dealing with empty arrays // Since the id should be unique, there should only be one result this is just for dealing with empty arrays
foreach ($attributedUsers as $u) { foreach ($attributedUsers as $u) {
if ($u['userId'] == $userId) { if ($u["userId"] == $userId) {
return true; return true;
} }
} }
@@ -355,9 +384,9 @@ SQL;
public static function getEventStarter($sinceDate = null) public static function getEventStarter($sinceDate = null)
{ {
$userId = $_SESSION['user']['userId']; $userId = $_SESSION["user"]["userId"];
if (!$sinceDate) { if (!$sinceDate) {
$sinceDate = 'CURDATE()'; $sinceDate = "CURDATE()";
} else { } else {
$sinceDate = 'DATE("' . $sinceDate . '")'; $sinceDate = 'DATE("' . $sinceDate . '")';
} }
@@ -387,14 +416,14 @@ SQL;
class AppCardAction class AppCardAction
{ {
private $caption = null; //< Caption for the action private $caption = null; //< Caption for the action
private $link = '.'; //< link for the action private $link = "."; //< link for the action
/** Constructor for the AppAction /** Constructor for the AppAction
* *
* @param string $caption caption for the action * @param string $caption caption for the action
* @param string $link link to the action * @param string $link link to the action
*/ */
public function __construct($caption, $link = '.') public function __construct($caption, $link = ".")
{ {
//! @todo input sanitation //! @todo input sanitation
$this->link = $link; $this->link = $link;
@@ -407,7 +436,7 @@ class AppCardAction
*/ */
public function htmlCode() public function htmlCode()
{ {
return '<a href="' . $this->link . '">' . $this->caption . '</a>'; return '<a href="' . $this->link . '">' . $this->caption . "</a>";
} }
/** Create AppCardAction from assoziative array /** Create AppCardAction from assoziative array
@@ -417,8 +446,8 @@ class AppCardAction
*/ */
public static function fromArray($member) public static function fromArray($member)
{ {
$caption = $member['caption'] ?? null; $caption = $member["caption"] ?? null;
$link = $member['link'] ?? '.'; $link = $member["link"] ?? ".";
return new AppCardAction($caption, $link); return new AppCardAction($caption, $link);
} }
} }
@@ -427,8 +456,8 @@ class AppCardAction
*/ */
class AppCard class AppCard
{ {
private $title = ''; //< title of the card private $title = ""; //< title of the card
private $description = ''; //< description of the App private $description = ""; //< description of the App
private $link = null; //< link for the card-content private $link = null; //< link for the card-content
private $imgUrl = null; //< url for an image right under the title private $imgUrl = null; //< url for an image right under the title
private $actionList = []; //< list of actions for the bottom of the card private $actionList = []; //< list of actions for the bottom of the card
@@ -442,8 +471,13 @@ class AppCard
* @param string $imgUrl url for an image right under the title * @param string $imgUrl url for an image right under the title
* @param array $actionList list of actions at the bottom of the card * @param array $actionList list of actions at the bottom of the card
*/ */
public function __construct($title, $description, $link = null, $imgUrl = null, $actionList = []) public function __construct(
{ $title,
$description,
$link = null,
$imgUrl = null,
$actionList = []
) {
//! @todo input sanitation //! @todo input sanitation
$this->title = $title; $this->title = $title;
$this->description = $description; $this->description = $description;
@@ -459,22 +493,37 @@ class AppCard
*/ */
public function htmlCode($options = []) public function htmlCode($options = [])
{ {
$extraClass = $options['extraClass'] ?? ''; $extraClass = $options["extraClass"] ?? "";
$actionListCode = ''; $actionListCode = "";
foreach ($this->actionList as $a) { foreach ($this->actionList as $a) {
$actionListCode .= $a->htmlCode(); $actionListCode .= $a->htmlCode();
} }
return return '<div style="padding:1%;" class="col s12 m6 ' .
'<div style="padding:1%;" class="col s12 m6 ' . $extraClass . '">' . $extraClass .
'">' .
'<div style="margin:1%;" class="card blue-grey darken-1">' . '<div style="margin:1%;" class="card blue-grey darken-1">' .
'<div class="card-content white-text">' . '<div class="card-content white-text">' .
(($this->link != null) ? ('<a href="' . $this->link . '">') : ('')) . '<span class="card-title">' . $this->title . '</span>' . (($this->link != null) ? ('</a>') : ('')) . ($this->link != null ? '<a href="' . $this->link . '">' : "") .
(($this->imgUrl != null) ? ('<img alt="' . $this->title . '" style="display:block;margin-left:auto;margin-right:auto;max-height:10vh;" class="responsive-img" src="' . $this->imgUrl . '" />') : ('')) . '<span class="card-title">' .
'<p>' . $this->description . '</p>' . $this->title .
'</div>' . "</span>" .
'<div class="card-action">' . $actionListCode . '</div>' . ($this->link != null ? "</a>" : "") .
'</div>' . ($this->imgUrl != null
'</div>'; ? '<img alt="' .
$this->title .
'" style="display:block;margin-left:auto;margin-right:auto;max-height:10vh;" class="responsive-img" src="' .
$this->imgUrl .
'" />'
: "") .
"<p>" .
$this->description .
"</p>" .
"</div>" .
'<div class="card-action">' .
$actionListCode .
"</div>" .
"</div>" .
"</div>";
} }
/** /**
@@ -485,11 +534,11 @@ class AppCard
*/ */
public static function fromArray($member) public static function fromArray($member)
{ {
$title = $member['title'] ?? ''; $title = $member["title"] ?? "";
$description = $member['description'] ?? ''; $description = $member["description"] ?? "";
$link = $member['link'] ?? null; $link = $member["link"] ?? null;
$imgUrl = $member['imgUrl'] ?? null; $imgUrl = $member["imgUrl"] ?? null;
$actionList = $member['actions'] ?? []; $actionList = $member["actions"] ?? [];
return new AppCard($title, $description, $link, $imgUrl, $actionList); return new AppCard($title, $description, $link, $imgUrl, $actionList);
} }
@@ -500,7 +549,7 @@ class AppCard
* @param string $jsonFileName path to the json file with the logged logins * @param string $jsonFileName path to the json file with the logged logins
* @return string Html table of users last logins * @return string Html table of users last logins
*/ */
function lastLoginTable($jsonFileName = 'lastLogins.json') function lastLoginTable($jsonFileName = "lastLogins.json")
{ {
// load the jsonfile into an associative array // load the jsonfile into an associative array
$lastLogins = json_decode(file_get_contents($jsonFileName), true); $lastLogins = json_decode(file_get_contents($jsonFileName), true);
@@ -508,57 +557,55 @@ function lastLoginTable($jsonFileName = 'lastLogins.json')
// collecting the last login of the users ... // collecting the last login of the users ...
$lastLoginRows = []; $lastLoginRows = [];
foreach ($lastLogins as $userName => $lastLogins) { foreach ($lastLogins as $userName => $lastLogins) {
$lastLoginRows[$userName] = $lastLogins['lastLogins'][0]; $lastLoginRows[$userName] = $lastLogins["lastLogins"][0];
} }
// and sort it so the last login is first in line // and sort it so the last login is first in line
arsort($lastLoginRows); arsort($lastLoginRows);
// build the table // build the table
$lastLoginsTable = $lastLoginsTable =
'<table>' . "<table>" .
'<thead><tr><th>userName</th><th>lastLogin</th></tr></thead>' . "<thead><tr><th>userName</th><th>lastLogin</th></tr></thead>" .
'<tbody>'; "<tbody>";
foreach ($lastLoginRows as $userName => $lastLogin) { foreach ($lastLoginRows as $userName => $lastLogin) {
$lastLoginsTable .= $lastLoginsTable .=
'<tr><td>' . $userName . '</td><td>' . $lastLogin . '</td></tr>'; "<tr><td>" . $userName . "</td><td>" . $lastLogin . "</td></tr>";
} }
$lastLoginsTable .= $lastLoginsTable .= "</tbody>" . "</table>";
'</tbody>' .
'</table>';
return $lastLoginsTable; return $lastLoginsTable;
} }
/// Eine Fehler/Warnung/Notiz/Erfolgsmeldung als divBox im String zurückgeben /// Eine Fehler/Warnung/Notiz/Erfolgsmeldung als divBox im String zurückgeben
function htmlRetMessage($anRetMessage) function htmlRetMessage($anRetMessage)
{ {
$retHtmlString = ''; $retHtmlString = "";
if (!empty($anRetMessage)) { if (!empty($anRetMessage)) {
$retHtmlString .= '<div style="border: 1px solid;">'; $retHtmlString .= '<div style="border: 1px solid;">';
if (!empty($anRetMessage['error'])) { if (!empty($anRetMessage["error"])) {
$retHtmlString .= '<div style="border: 1px solid;">'; $retHtmlString .= '<div style="border: 1px solid;">';
$retHtmlString .= 'ERROR:<br />'; $retHtmlString .= "ERROR:<br />";
$retHtmlString .= $anRetMessage['error']; $retHtmlString .= $anRetMessage["error"];
$retHtmlString .= '</div>'; $retHtmlString .= "</div>";
} }
if (!empty($anRetMessage['warning'])) { if (!empty($anRetMessage["warning"])) {
$retHtmlString .= '<div style="border: 1px solid;">'; $retHtmlString .= '<div style="border: 1px solid;">';
$retHtmlString .= 'WARNING:<br />'; $retHtmlString .= "WARNING:<br />";
$retHtmlString .= $anRetMessage['warning']; $retHtmlString .= $anRetMessage["warning"];
$retHtmlString .= '</div>'; $retHtmlString .= "</div>";
} }
if (!empty($anRetMessage['notice'])) { if (!empty($anRetMessage["notice"])) {
$retHtmlString .= '<div style="border: 1px solid;">'; $retHtmlString .= '<div style="border: 1px solid;">';
$retHtmlString .= 'Info:<br />'; $retHtmlString .= "Info:<br />";
$retHtmlString .= $anRetMessage['notice']; $retHtmlString .= $anRetMessage["notice"];
$retHtmlString .= '</div>'; $retHtmlString .= "</div>";
} }
if (!empty($anRetMessage['success'])) { if (!empty($anRetMessage["success"])) {
$retHtmlString .= '<div style="border: 1px solid;">'; $retHtmlString .= '<div style="border: 1px solid;">';
$retHtmlString .= 'SUCCESS:<br />'; $retHtmlString .= "SUCCESS:<br />";
$retHtmlString .= $anRetMessage['success']; $retHtmlString .= $anRetMessage["success"];
$retHtmlString .= '</div>'; $retHtmlString .= "</div>";
} }
$retHtmlString .= '</div>'; $retHtmlString .= "</div>";
} }
return $retHtmlString; return $retHtmlString;
} }
@@ -576,35 +623,33 @@ function loadMarkdownFile($fileName)
$fileParts = preg_split('/[\n]*[-]{3}[\n]/', $fileText, 3); $fileParts = preg_split('/[\n]*[-]{3}[\n]/', $fileText, 3);
// not all mdFiles have a yamlHeader, so the mdText can be at different indices // not all mdFiles have a yamlHeader, so the mdText can be at different indices
$yaml = []; $yaml = [];
$mdText = ''; $mdText = "";
switch (count($fileParts)) { switch (count($fileParts)) {
case 1:{ case 1:
$mdText = $fileParts[0]; $mdText = $fileParts[0];
break; break;
} case 3:
case 3:{
$yaml = Spyc::YAMLLoadString($fileParts[1]); $yaml = Spyc::YAMLLoadString($fileParts[1]);
$mdText = $fileParts[2]; $mdText = $fileParts[2];
break; break;
} default:
default:{
$mdText = $fileText; $mdText = $fileText;
} }
}
// get a title, if none is in the markdown // get a title, if none is in the markdown
if (!array_key_exists('title', $yaml)) { if (!array_key_exists("title", $yaml)) {
// find the first heading, set it as header and remove it from the markdown // find the first heading, set it as header and remove it from the markdown
if (preg_match('/^#(.*)$/m', $mdText, $matches)) { if (preg_match('/^#(.*)$/m', $mdText, $matches)) {
$yaml['title'] = $matches[1]; $yaml["title"] = $matches[1];
$mdText = preg_replace('/^#(.*)$/m', '', $mdText, 1); $mdText = preg_replace('/^#(.*)$/m', "", $mdText, 1);
} else { } else {
// fallback for the title, if not even one heading is found // fallback for the title, if not even one heading is found
$yaml['title'] = '<fehlender Titel>'; $yaml["title"] = "<fehlender Titel>";
} }
} }
return [ return [
'yaml' => $yaml, 'mdText' => $mdText "yaml" => $yaml,
"mdText" => $mdText,
]; ];
} }
@@ -614,7 +659,7 @@ function loadMarkdownFile($fileName)
* @param string $fileName filename to log to * @param string $fileName filename to log to
* @return void * @return void
*/ */
function logLoginsToJsonFile($userName, $fileName = 'lastLogins.json') function logLoginsToJsonFile($userName, $fileName = "lastLogins.json")
{ {
try { try {
$lastLogins = json_decode(file_get_contents($fileName), true); $lastLogins = json_decode(file_get_contents($fileName), true);
@@ -624,14 +669,16 @@ function logLoginsToJsonFile($userName, $fileName = 'lastLogins.json')
if (!array_key_exists($userName, $lastLogins)) { if (!array_key_exists($userName, $lastLogins)) {
$lastLogins[$userName] = []; $lastLogins[$userName] = [];
} }
if (!array_key_exists('lastLogins', $lastLogins[$userName])) { if (!array_key_exists("lastLogins", $lastLogins[$userName])) {
$lastLogins[$userName]['lastLogins'] = []; $lastLogins[$userName]["lastLogins"] = [];
} }
$usersLastLogins = $lastLogins[$userName]['lastLogins']; $usersLastLogins = $lastLogins[$userName]["lastLogins"];
$usersLastLogins = array_merge([date('Y-m-d H:i:s')], $usersLastLogins); $usersLastLogins = array_merge([date("Y-m-d H:i:s")], $usersLastLogins);
$usersLastLogins = array_slice($usersLastLogins, 0, 10); $usersLastLogins = array_slice($usersLastLogins, 0, 10);
$lastLogins[$userName]['lastLogins'] = $usersLastLogins; $lastLogins[$userName]["lastLogins"] = $usersLastLogins;
if (is_writable($fileName)) {
file_put_contents($fileName, json_encode($lastLogins)); file_put_contents($fileName, json_encode($lastLogins));
}
} catch (Exception $e) { } catch (Exception $e) {
// silently ignore errors // silently ignore errors
} }
@@ -640,15 +687,19 @@ function logLoginsToJsonFile($userName, $fileName = 'lastLogins.json')
/// @brief Gibt die URL der gerade aufgerufenen Seite zurück /// @brief Gibt die URL der gerade aufgerufenen Seite zurück
function getCurPagesUrl() function getCurPagesUrl()
{ {
$pageURL = 'http'; $pageURL = "http";
if ( array_key_exists("HTTPS", $_SERVER) && ($_SERVER['HTTPS'] == 'on')) { if (array_key_exists("HTTPS", $_SERVER) && $_SERVER["HTTPS"] == "on") {
$pageURL .= 's'; $pageURL .= "s";
} }
$pageURL .= '://'; $pageURL .= "://";
if ($_SERVER['SERVER_PORT'] != '80') { if ($_SERVER["SERVER_PORT"] != "80") {
$pageURL .= $_SERVER['SERVER_NAME'] . ':' . $_SERVER['SERVER_PORT'] . $_SERVER['REQUEST_URI']; $pageURL .=
$_SERVER["SERVER_NAME"] .
":" .
$_SERVER["SERVER_PORT"] .
$_SERVER["REQUEST_URI"];
} else { } else {
$pageURL .= $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']; $pageURL .= $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"];
} }
return $pageURL; return $pageURL;
} }
@@ -660,20 +711,25 @@ function getCurPagesUrl()
*/ */
function getHtmlSquareDate($date = null) function getHtmlSquareDate($date = null)
{ {
$date = $date ?? new DateTime; $date = $date ?? new DateTime();
$year = $date->format('Y'); $year = $date->format("Y");
$month = $date->format('M'); $month = $date->format("M");
$day = $date->format('d'); $day = $date->format("d");
return return "<div>" .
'<div>' "<div>" .
. '<div>' '<span style="font-size:large">' .
. '<span style="font-size:large">' . $day . '</span>' $day .
. '<span style="writing-mode: sideways-lr">' . $month . '</span>' "</span>" .
. '</div>' '<span style="writing-mode: sideways-lr">' .
. '<div style="font-size: small">' . $year . '</div>' $month .
. '</div>'; "</span>" .
"</div>" .
'<div style="font-size: small">' .
$year .
"</div>" .
"</div>";
} }
/** filter_var for a pos int /** filter_var for a pos int
@@ -686,7 +742,9 @@ function getHtmlSquareDate($date = null)
* */ * */
function filterPosInt($id) function filterPosInt($id)
{ {
return filter_var($id, FILTER_VALIDATE_INT, ['options' => ['default' => null, 'min_range' => 1]]); return filter_var($id, FILTER_VALIDATE_INT, [
"options" => ["default" => null, "min_range" => 1],
]);
} }
/** filter_var for a (db)id /** filter_var for a (db)id
@@ -713,5 +771,7 @@ function filterId($id)
*/ */
function filterCount($variable, int $min = 0) function filterCount($variable, int $min = 0)
{ {
return filter_var($variable, FILTER_VALIDATE_INT, ['options' => ['default' => null, 'min_range' => 1]]); return filter_var($variable, FILTER_VALIDATE_INT, [
"options" => ["default" => null, "min_range" => 1],
]);
} }

View File

@@ -16,7 +16,7 @@ services:
# nginx config file # nginx config file
- ./nginx.conf:/etc/nginx/conf.d/nginx.conf - ./nginx.conf:/etc/nginx/conf.d/nginx.conf
# the app itself # the app itself
- ./cwsvjudo@bplaced/www/participo:/home/cwsvjudo/httpdocs/participo - ./cwsvjudo@bplaced/www/participo:/home/cwsvjudo/httpdocs/participo:rw
# the apps config files # the apps config files
- ./config-heliohost/cwsvJudo.config.php:/home/cwsvjudo/.local/cwsvJudo.config.php - ./config-heliohost/cwsvJudo.config.php:/home/cwsvjudo/.local/cwsvJudo.config.php
# ressourcen # ressourcen
@@ -45,8 +45,8 @@ services:
# @todo Should credentials be placed here? Even if it is just a test environment # @todo Should credentials be placed here? Even if it is just a test environment
environment: environment:
# MYSQL_TCP_PORT: 1433 # MYSQL_TCP_PORT: 1433
MYSQL_USER: 'cwsvjudo' MYSQL_USER: "cwsvjudo"
MYSQL_DATABASE: 'cwsvjudo' MYSQL_DATABASE: "cwsvjudo"
MYSQL_ROOT_PASSWORD_FILE: /run/secrets/db_root_password MYSQL_ROOT_PASSWORD_FILE: /run/secrets/db_root_password
MYSQL_PASSWORD_FILE: /run/secrets/db_password MYSQL_PASSWORD_FILE: /run/secrets/db_password
volumes: volumes:
@@ -64,6 +64,7 @@ services:
restart: always restart: always
depends_on: depends_on:
- database - database
- php
ports: ports:
- 8080:80 - 8080:80
environment: environment: