Compare commits
5 commits
53133a18bc
...
f57612c00f
Author | SHA1 | Date | |
---|---|---|---|
bernd | f57612c00f | ||
bernd | 493827cb67 | ||
bernd | 7778a24b8e | ||
bernd | 2a56eabf5d | ||
bernd | 8ae028dfaf |
|
@ -33,9 +33,10 @@ database=requests
|
|||
user=besitzer der datenbank requests
|
||||
password=total geheimes passwort
|
||||
|
||||
; Loglevel festlegen. Derzeit sind error, warn, info und debug gültige
|
||||
; Werte. Die Angabe ist nicht Case-Sesitive.
|
||||
loglevel=debug
|
||||
; Loglevel festlegen. Die Funktion syslog() akzeptiert folgende Werte:
|
||||
; LOG_EMERG, LOG_ALERT, LOG_CRIT, LOG_ERR, LOG_WARNING, LOG_NOTICE,
|
||||
; LOG_INFO oder LOG_DEBUG.
|
||||
loglevel=LOG_INFO
|
||||
|
||||
; Logdatei festlegen. Der Benutzer, unter dem der Dienst läuft braucht
|
||||
; Schreibrechte für das Verzeichnis.
|
||||
|
|
|
@ -16,7 +16,6 @@ $saved = false;
|
|||
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
// echo '<pre>' . htmlspecialchars(var_export($_POST, true)) . '</pre>';
|
||||
$inputLogin = $_POST['login'] ?? '';
|
||||
$inputEmail = $_POST['email'] ?? '';
|
||||
$inputCaptcha = $_POST['captcha'] ?? '';
|
||||
|
|
|
@ -44,13 +44,14 @@ class BaseClass {
|
|||
} catch (Exception $e) {
|
||||
throw new Exception("Can't create logger instance");
|
||||
}
|
||||
$this->log->d("Create a instance of BaseClass");
|
||||
$this->log->d("Base class instance successfull created");
|
||||
/**
|
||||
* Instanz der Klasse Config erstellen und Konfigurationsdatei
|
||||
* einlesen lassen.
|
||||
*/
|
||||
try {
|
||||
$this->config = new Config();
|
||||
$this->log->d("Configuration object successfull created");
|
||||
$this->config->loadConfig($this->config_path);
|
||||
$this->log->d("Configuration file parsed");
|
||||
} catch (Exception $e) {
|
||||
|
|
|
@ -55,8 +55,8 @@ class Config {
|
|||
return $password;
|
||||
}
|
||||
|
||||
public function getLogLevel(): string {
|
||||
$loglevel = strtoupper($this->config['loglevel']) ?? "INFO";
|
||||
public function getLogLevel(): int {
|
||||
$loglevel = strtoupper($this->config['loglevel']) ?? LOG_INFO;
|
||||
return $loglevel;
|
||||
}
|
||||
|
||||
|
|
|
@ -102,7 +102,7 @@ class Database {
|
|||
{
|
||||
$this->pdo = $pdo;
|
||||
$this->log = $log;
|
||||
$this->log->d(Databaseobject created);
|
||||
$this->log->d("Databaseobject successfull created");
|
||||
// hier vielleicht TableCreate hin
|
||||
|
||||
}
|
||||
|
@ -162,7 +162,7 @@ class Database {
|
|||
$uid = $this->getNick($array['name']);
|
||||
$this->log->d("Compare {$nick} with {$uid}");
|
||||
if ($uid === $nick) {
|
||||
$this->log->i("MID localpart already exists: {$nick}");
|
||||
$this->log->i("MXID localpart already exists: {$nick}");
|
||||
return true;
|
||||
} else {
|
||||
$this->log->d("False");
|
||||
|
|
|
@ -18,53 +18,90 @@ class Logger {
|
|||
* angefragte Key im Array existiert.
|
||||
*/
|
||||
|
||||
private $levelnumbers = array(
|
||||
"ERROR" => 10,
|
||||
"WARN" => 20,
|
||||
"INFO" => 30,
|
||||
"DEBUG" => 40,
|
||||
);
|
||||
public $loglevel = "INFO";
|
||||
private $logfile = "log/register.log";
|
||||
public $loglevel = LOG_INFO;
|
||||
private $app = "matrix-register";
|
||||
private $logopen = false;
|
||||
|
||||
|
||||
public function __construct() {
|
||||
if (openlog($this->app, LOG_PID | LOG_PERROR , LOG_SYSLOG) === true) {
|
||||
$this->logopen = true;
|
||||
}
|
||||
}
|
||||
|
||||
public function __destruct() {
|
||||
$this->logopen = false;
|
||||
closelog();
|
||||
}
|
||||
|
||||
public function a(string $msg) {
|
||||
$this->logMsg(LOG_ALERT, $msg);
|
||||
}
|
||||
|
||||
public function c(string $msg) {
|
||||
$this->logMsg(LOG_CRIT, $msg);
|
||||
}
|
||||
|
||||
public function e(string $msg) {
|
||||
$this->logMsg("ERROR", $msg);
|
||||
$this->logMsg(LOG_ERR, $msg);
|
||||
}
|
||||
|
||||
public function w(string $msg) {
|
||||
$this->logMsg("WARN", $msg);
|
||||
$this->logMsg(LOG_WARN, $msg);
|
||||
}
|
||||
|
||||
public function n(string $msg) {
|
||||
$this->logMsg(LOG_NOTICE, $msg);
|
||||
}
|
||||
|
||||
public function i(string $msg) {
|
||||
$this->logMsg("INFO", $msg);
|
||||
$this->logMsg(LOG_INFO, $msg);
|
||||
}
|
||||
|
||||
public function d(string $msg) {
|
||||
$this->logMsg("DEBUG", $msg);
|
||||
$this->logMsg(LOG_DEBUG, $msg);
|
||||
}
|
||||
|
||||
public function setLogLevel(string $level) {
|
||||
if (array_key_exists($level, $this->levelnumbers) === true) {
|
||||
public function setLogLevel(int $level) {
|
||||
|
||||
/**
|
||||
* Funktion zum Setzen des Loglevels. Mögliche Werte sind
|
||||
* LOG_EMERG(0), LOG_ALERT(1), LOG_CRIT(2), LOG_ERR(3),
|
||||
* LOG_WARNING(4), LOG_NOTICE(5), LOG_INFO(6) oder LOG_DEBUG(7).
|
||||
* Es wird geprüft, ob das übergebene Level gültig ist.
|
||||
*/
|
||||
|
||||
if (in_array($level, array(0, 1, 2, 3, 4, 5, 6, 7)) === true) {
|
||||
$this->loglevel = $level;
|
||||
$this->writeLog("INFO", "Loglevel set to {$level}");
|
||||
$this->d("Loglevel set to {$this->loglevel}");
|
||||
} else {
|
||||
$this->writeLog("WARN", "{$level} is not a valid loglevel.");
|
||||
echo "{$level} is not a valid loglevel.";
|
||||
}
|
||||
}
|
||||
|
||||
private function logMsg(string $label, string $msg) {
|
||||
$msglevel = $this->levelnumbers[$label];
|
||||
$loglevel = $this->levelnumbers[$this->loglevel];
|
||||
if ($loglevel >= $msglevel) {
|
||||
$this->writeLog($label, $msg);
|
||||
}
|
||||
private function addLevel(int $level, string $msg): string {
|
||||
|
||||
/**
|
||||
* Stellt der Meldung das Loglevel voran.
|
||||
*/
|
||||
|
||||
$text = "[$level] ".$msg;
|
||||
return $text;
|
||||
}
|
||||
|
||||
private function writeLog(string $label, string $msg) {
|
||||
$app = $this->app;
|
||||
$file = $this->logfile;
|
||||
error_log(date("[Y-m-d H:i:s]")." [".$label."] [".$app."] ".$msg."\n", 3, $file);
|
||||
private function logMsg(string $msglevel, string $msg) {
|
||||
|
||||
/**
|
||||
* Übergibt die Meldung an die Funktion syslog. Vorher wird
|
||||
* entschieden, ob eine Meldung ausgegeben wird oder nicht. Dazu
|
||||
* wird geschaut, ob das Messagelevel kleiner oder gleich dem
|
||||
* Loglevel ist..
|
||||
*/
|
||||
|
||||
$msg = $this->addLevel($msglevel, $msg);
|
||||
if ($msglevel <= $this->loglevel) {
|
||||
syslog($msglevel, $msg);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -97,7 +97,7 @@ class Request extends BaseClass {
|
|||
$this->log->d("Try to send verification mail");
|
||||
|
||||
$link = $baseurl . $validator . $this->token . "\r\n\r\n";
|
||||
$mailbody = MAILTEXT1 . $mxdomain . MAILTEXT2 . "\r\n\r\n" . $link . $mailClosure;
|
||||
$mailbody = MAILTEXT1 . " {$mxdomain} " . MAILTEXT2 . "\r\n\r\n" . $link . $mailClosure;
|
||||
if (mail($mailTo, $mailSubject, $mailbody, $mailFrom))
|
||||
{
|
||||
$this->log->i("Validationmail successfull send");
|
||||
|
|
Loading…
Reference in a new issue