Skip to content
This repository has been archived by the owner on Sep 13, 2019. It is now read-only.

Commit

Permalink
Merge pull request #3 from affenrakete/patch-4
Browse files Browse the repository at this point in the history
Verschönerungen
  • Loading branch information
affenrakete committed Nov 8, 2017
2 parents 54c4d92 + 5fcd582 commit 8a0e6bf
Showing 1 changed file with 63 additions and 65 deletions.
128 changes: 63 additions & 65 deletions mailias.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ private function checkConfig($config = null) {
private function checkEmail($email = null) {
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$this->addNotification('debug', 'system', __FUNCTION__, 'Email not valid -> ' . $email);
$this->addNotification('info', 'user', __FUNCTION__, 'Email ist nicht gültig.');
return false;
}
return true;
Expand All @@ -144,6 +145,7 @@ private function checkInput($input = null, $type = null) {
switch ($type) {
case 'alias':
$pattern = "/^(?=^.{5,30}$)([a-zA-Z0-9]+)(?:[\w]*[a-zA-Z0-9]+)$/";
$user_info = "Alias ist ungültig.";
/*
* Gesamt 5 - 30 Zeichen
* a-o A-Z 0-9
Expand All @@ -153,6 +155,7 @@ private function checkInput($input = null, $type = null) {

case 'description':
$pattern = "/^([\w\ \-\.]){0,250}$/";
$user_info = "Beschreibung ist nicht gültig.";
/*
* Gesamt 0 - 250 Zeichen
* a-z A-Z 0-9
Expand All @@ -162,6 +165,7 @@ private function checkInput($input = null, $type = null) {

case 'domain':
$pattern = "/(?=^.{4,253}$)(^((?!-)[a-zA-Z0-9-]{1,63}(?<!-)\.)+[a-zA-Z]{2,63}$)/";
$user_info = "Domain ist nmicht gültig.";
break;

default:
Expand All @@ -173,9 +177,20 @@ private function checkInput($input = null, $type = null) {
}

$this->addNotification('debug', 'system', __FUNCTION__, $type . ' not valid -> ' . $input);
$this->addNotification('info', 'user', __FUNCTION__, $user_info);
return false;
}

private function checkUnlock() {
if ($this->locked) {
$this->addNotification('error', 'system', __FUNCTION__, 'locked');
$this->addNotification('info', 'user', __FUNCTION__, 'System gesperrt.');

return false;
}
return true;
}

public function getList() {
return $this->data;
}
Expand Down Expand Up @@ -244,35 +259,18 @@ private function readUser() {

public function insertAlias($alias = null, $receive = null, $description = null) {

/*
* Pre Check
* Sind alle Informationen gegeben?
*/

if ($this->locked) {
$this->addNotification('error', 'system', __FUNCTION__, 'locked');
if (!$this->checkUnlock()) {
return false;
}

// Prüfen Nutzereingaben
if (!$this->checkInput($alias, 'alias')) {
$this->addNotification('info', 'user', __FUNCTION__, 'Alias ist ungültig.');
}

if (!$this->checkEmail($receive)) {
$this->addNotification('info', 'user', __FUNCTION__, 'Empfänger Email ist nicht gültig.');
}

if (!$this->checkInput($description, 'description')) {
$this->addNotification('info', 'user', __FUNCTION__, 'Beschreibung ist nicht gültig.');
}
$this->checkInput($alias, 'alias');
$this->checkEmail($receive);
$this->checkInput($description, 'description');

// Komplette Alias Adresse zusammensetzen
// Komplette Alias Adresse zusammensetzen und prüfen
$aliasEmail = \strtolower($this->user['short'] . "-" . $alias . "@" . $this->config['domain']);

// Komplette Alias Adresse checken
if (!$this->checkEmail($aliasEmail)) {
$this->addNotification('info', 'user', __FUNCTION__, 'Alias Email ist ungültig.');
}
$this->checkEmail($aliasEmail);

// Abbruch wenn Fehler aufgetreten sind.
if ($this->notificationID > 0) {
Expand All @@ -284,6 +282,7 @@ public function insertAlias($alias = null, $receive = null, $description = null)
$this->addNotification('info', 'user', __FUNCTION__, 'Email Adresse erfolgreich angelegt: ' . $alias);
return true;
}

return false;
}

Expand Down Expand Up @@ -335,18 +334,18 @@ private function insertAliasExe($alias = null, $receive = null, $description = n

public function delAlias($inputId = null) {

$listId = [];
$toDelete = [];

if ($this->locked) {
$this->addNotification('error', 'system', __FUNCTION__, 'locked');
if (!$this->checkUnlock()) {
return false;
}

$listId = [];
$toDelete = [];

foreach ($inputId as $id) {
$listId[] = (int) $id;
}

// Benötigte Daten zum löschen aus Datenbank ziehen
$sql = "SELECT id, alias FROM mailias WHERE id IN (" . implode(',', array_unique($listId)) . ") AND user_id = ? ORDER BY id ASC";

$statement = $this->mysqli->prepare($sql);
Expand All @@ -364,55 +363,54 @@ public function delAlias($inputId = null) {
/*
* Do the loop
*/
foreach ($toDelete as $delete) {

if (!$this->delAliasExe($delete)) {
break;
}
$this->deleted[] = $delete['alias'];
}

// Meldungen für User erzeugen
foreach ($this->deleted as $alias) {
$this->addNotification('info', 'user', __FUNCTION__, 'Email Adresse erfolgreich gelöscht: ' . $alias);
}
$this->delAliasExe($toDelete);

return true;
}

private function delAliasExe($delete = null) {
private function delAliasExe($toDelete = null) {

/*
* Delete .qmail
* Weiterleitung durch Löschung von .qmail Datei deaktivieren
*/
foreach ($toDelete as $delete) {

$deletePart = explode('@', $delete['alias']);
$deleteFile = \strtolower("/home/" . $this->config['user'] . "/.qmail-" . $deletePart[0]);
/*
* Delete .qmail
* Weiterleitung durch Löschung von .qmail Datei deaktivieren
*/

if (!\file_exists($deleteFile)) {
$this->addNotification('info', 'user', __FUNCTION__, 'Weiterleitung existiert nicht.');
} elseif (!\unlink($deleteFile)) {
$this->addNotification('info', 'user', __FUNCTION__, 'Weiterleitung konnte nicht gelöscht werden.');
}
$deletePart = explode('@', $delete['alias']);
$deleteFile = \strtolower("/home/" . $this->config['user'] . "/.qmail-" . $deletePart[0]);

/*
* Delete SQL
* Daten aus SQL löschen
*/
if (!\file_exists($deleteFile)) {
$this->addNotification('info', 'user', __FUNCTION__, 'Weiterleitung existiert nicht.');
} elseif (!\unlink($deleteFile)) {
$this->addNotification('info', 'user', __FUNCTION__, 'Weiterleitung konnte nicht gelöscht werden.');
}

$sql = "DELETE FROM mailias WHERE id = ?";
/*
* Delete SQL
* Daten aus SQL löschen
*/

$statement = $this->mysqli->prepare($sql);
$statement->bind_param('i', $delete['id']);
$sql = "DELETE FROM mailias WHERE id = ?";

if (!$statement->execute()) {
$this->addNotification('info', 'user', __FUNCTION__, 'Email Adresse konnte nicht gelöscht werden.');
$this->addNotification('debug', 'system', __FUNCTION__, '(' . $this->mysqli->errno . ') ' . $this->mysqli->error);
$statement = $this->mysqli->prepare($sql);
$statement->bind_param('i', $delete['id']);

if (!$statement->execute()) {
$this->addNotification('info', 'user', __FUNCTION__, 'Email Adresse konnte nicht gelöscht werden.');
$this->addNotification('debug', 'system', __FUNCTION__, '(' . $this->mysqli->errno . ') ' . $this->mysqli->error);
}

$this->deleted[] = $delete['alias'];

if ($this->notificationID > 0) {
return false;
}
}

if ($this->notificationID > 0) {
return false;
// Meldungen für User erzeugen
foreach ($this->deleted as $alias) {
$this->addNotification('info', 'user', __FUNCTION__, 'Email Adresse erfolgreich gelöscht: ' . $alias);
}

return true;
Expand Down

0 comments on commit 8a0e6bf

Please sign in to comment.