Upload via GUI (267 Dateien)
This commit is contained in:
@@ -22,6 +22,16 @@ if ($departmentIds !== null) {
|
||||
}
|
||||
}
|
||||
|
||||
// Optional: nur Textbausteine für die Abteilung eines Tickets (diese Abteilung plus die für alle Abteilungen)
|
||||
$onlyDept = isset($_GET['departmentId']) && ctype_digit((string) $_GET['departmentId']) ? (int) $_GET['departmentId'] : null;
|
||||
if ($onlyDept !== null) {
|
||||
if ($departmentIds !== null && !in_array($onlyDept, $departmentIds, true)) {
|
||||
api_error(403, 'FORBIDDEN', 'Kein Zugriff auf diese Abteilung.');
|
||||
}
|
||||
$deptFilter = ' AND (cr.department_id IS NULL OR cr.department_id = ?)';
|
||||
$deptParams = [$onlyDept];
|
||||
}
|
||||
|
||||
$stmt = $pdo->prepare(
|
||||
"SELECT cr.id, cr.title, cr.body, cr.department_id
|
||||
FROM canned_responses cr
|
||||
|
||||
@@ -66,14 +66,20 @@ function api_require_https(): void
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Liest die Anmeldung der Apps. Viele Hoster (Apache mit PHP-FPM/FastCGI, z. B. Plesk) reichen den Header "Authorization" nicht an PHP weiter.
|
||||
* Deshalb senden die Apps denselben Wert zusätzlich als "X-DeskHub-Authorization", der überall ankommt; hier gilt der erste vorhandene.
|
||||
*/
|
||||
function api_authorization_header(): string
|
||||
{
|
||||
$header = $_SERVER['HTTP_AUTHORIZATION'] ?? $_SERVER['REDIRECT_HTTP_AUTHORIZATION'] ?? '';
|
||||
if ($header === '' && function_exists('getallheaders')) {
|
||||
$headers = getallheaders();
|
||||
$header = $headers['Authorization'] ?? $headers['authorization'] ?? '';
|
||||
if (trim((string) $header) === '') $header = $_SERVER['HTTP_X_DESKHUB_AUTHORIZATION'] ?? '';
|
||||
if (trim((string) $header) === '' && function_exists('getallheaders')) {
|
||||
foreach (getallheaders() as $name => $value) {
|
||||
if (in_array(strtolower((string) $name), ['authorization', 'x-deskhub-authorization'], true) && trim((string) $value) !== '') { $header = $value; break; }
|
||||
}
|
||||
}
|
||||
return trim($header);
|
||||
return trim((string) $header);
|
||||
}
|
||||
|
||||
function api_bearer_token(): ?string
|
||||
@@ -204,11 +210,27 @@ function api_find_ticket(PDO $pdo, array $staff, string $number): array
|
||||
return $ticket;
|
||||
}
|
||||
|
||||
/** Adresse des ersten Bildes in einem HTML-Text (absolut, nur http/https); leer, wenn keines vorhanden ist. */
|
||||
function api_first_image_url(?string $html): string
|
||||
{
|
||||
if (!preg_match('/<img\b[^>]*\bsrc\s*=\s*(["\'])(.*?)\1/is', (string) $html, $m)) return '';
|
||||
$src = trim(html_entity_decode($m[2], ENT_QUOTES | ENT_HTML5, 'UTF-8'));
|
||||
if (str_starts_with($src, '//')) $src = 'https:' . $src;
|
||||
elseif (str_starts_with($src, '/')) $src = base_url() . $src;
|
||||
return preg_match('#^https?://#i', $src) ? $src : '';
|
||||
}
|
||||
|
||||
function api_plain_text(?string $html): string
|
||||
{
|
||||
$text = preg_replace('/<br\s*\/?>/i', "\n", (string) $html);
|
||||
$text = preg_replace('/<\/p\s*>/i', "\n\n", $text);
|
||||
return trim(html_entity_decode(strip_tags($text), ENT_QUOTES | ENT_HTML5, 'UTF-8'));
|
||||
// Weitere Blöcke (div, Listen, Tabellenzeilen, Überschriften …) enden ebenfalls mit einem Zeilenumbruch, Listenpunkte bekommen einen Punkt
|
||||
$text = preg_replace('/<li\b[^>]*>/i', '• ', $text);
|
||||
$text = preg_replace('/<\/(div|li|tr|h[1-6]|blockquote|pre|ul|ol|table)\s*>/i', "\n", $text);
|
||||
$text = html_entity_decode(strip_tags($text), ENT_QUOTES | ENT_HTML5, 'UTF-8');
|
||||
$text = preg_replace('/[ \t]+\n/', "\n", $text); // Leerzeichen am Zeilenende
|
||||
$text = preg_replace('/\n{3,}/', "\n\n", $text); // höchstens eine Leerzeile
|
||||
return trim($text);
|
||||
}
|
||||
|
||||
function api_ticket_summary(array $ticket): array
|
||||
@@ -247,7 +269,7 @@ function api_ticket_summary(array $ticket): array
|
||||
];
|
||||
}
|
||||
|
||||
function api_add_ticket_message(PDO $pdo, array $staff, array $ticket, string $type, string $rawMessage, ?string $setStatus): int
|
||||
function api_add_ticket_message(PDO $pdo, array $staff, array $ticket, string $type, string $rawMessage, ?string $setStatus, ?string $signatureChoice = null): int
|
||||
{
|
||||
$permission = $type === 'note' ? 'post_note' : 'reply_ticket';
|
||||
api_require_permission($staff, $permission, (int) $ticket['department_id']);
|
||||
@@ -331,12 +353,8 @@ function api_add_ticket_message(PDO $pdo, array $staff, array $ticket, string $t
|
||||
}
|
||||
|
||||
if (!$isNote) {
|
||||
$signature = trim((string) ($staff['signature'] ?? ''));
|
||||
if ($signature === '') {
|
||||
$signatureStmt = $pdo->prepare('SELECT signature FROM departments WHERE id = ?');
|
||||
$signatureStmt->execute([$ticket['department_id']]);
|
||||
$signature = (string) $signatureStmt->fetchColumn();
|
||||
}
|
||||
// Signatur: optional vom Aufrufer gewählt (own, dept, none), sonst eigene, ersatzweise die der Abteilung
|
||||
$signature = resolve_reply_signature($pdo, $staff, (int) $ticket['department_id'], $signatureChoice);
|
||||
$collabStmt = $pdo->prepare('SELECT email FROM ticket_collaborators WHERE ticket_id = ?');
|
||||
$collabStmt->execute([$ticket['id']]);
|
||||
notify_customer_new_reply($ticket, $message, $signature, $collabStmt->fetchAll(PDO::FETCH_COLUMN));
|
||||
|
||||
@@ -1,44 +1,44 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
require_once __DIR__ . '/common.php';
|
||||
|
||||
api_require_method('POST');
|
||||
api_require_https();
|
||||
$body = api_request_body();
|
||||
$email = mb_strtolower(trim((string) ($body['email'] ?? '')));
|
||||
$password = (string) ($body['password'] ?? '');
|
||||
$totpCode = trim((string) ($body['totpCode'] ?? ''));
|
||||
|
||||
if (!filter_var($email, FILTER_VALIDATE_EMAIL) || $password === '') {
|
||||
api_error(422, 'CREDENTIALS_REQUIRED', 'E-Mail-Adresse und Passwort sind erforderlich.');
|
||||
}
|
||||
if (!rate_limit_check('mobile_staff_login_ip', client_ip(), 10, 15)
|
||||
|| !rate_limit_check('mobile_staff_login_email', $email, 5, 15)) {
|
||||
api_error(429, 'RATE_LIMITED', 'Zu viele Anmeldeversuche. Bitte versuchen Sie es später erneut.');
|
||||
}
|
||||
|
||||
$pdo = get_db();
|
||||
$stmt = $pdo->prepare('SELECT * FROM staff WHERE email = ? AND is_active = 1');
|
||||
$stmt->execute([$email]);
|
||||
$staff = $stmt->fetch();
|
||||
if (!$staff || !password_verify($password, $staff['password_hash'])) {
|
||||
api_error(401, 'INVALID_CREDENTIALS', 'E-Mail-Adresse oder Passwort ist falsch.');
|
||||
}
|
||||
if (!empty($staff['totp_enabled'])) {
|
||||
if ($totpCode === '') {
|
||||
api_json(['requiresTotp' => true], 202);
|
||||
}
|
||||
if (!preg_match('/^\d{6}$/', $totpCode) || !totp_verify($staff['totp_secret'], $totpCode)) {
|
||||
api_error(401, 'INVALID_TOTP', 'Der Authenticator-Code ist ungültig.');
|
||||
}
|
||||
}
|
||||
|
||||
rate_limit_reset('mobile_staff_login_email', $email);
|
||||
rate_limit_reset('mobile_staff_login_ip', client_ip());
|
||||
$issued = api_issue_token($pdo, (int) $staff['id'], isset($body['deviceName']) ? (string) $body['deviceName'] : null);
|
||||
audit_log((int) $staff['id'], 'Mobile App: Anmeldung');
|
||||
api_json([
|
||||
'token' => $issued['token'],
|
||||
'expiresAt' => $issued['expires_at'],
|
||||
'staff' => api_staff_payload($staff),
|
||||
]);
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
require_once __DIR__ . '/common.php';
|
||||
|
||||
api_require_method('POST');
|
||||
api_require_https();
|
||||
$body = api_request_body();
|
||||
$email = mb_strtolower(trim((string) ($body['email'] ?? '')));
|
||||
$password = (string) ($body['password'] ?? '');
|
||||
$totpCode = trim((string) ($body['totpCode'] ?? ''));
|
||||
|
||||
if (!filter_var($email, FILTER_VALIDATE_EMAIL) || $password === '') {
|
||||
api_error(422, 'CREDENTIALS_REQUIRED', 'E-Mail-Adresse und Passwort sind erforderlich.');
|
||||
}
|
||||
if (!rate_limit_check('mobile_staff_login_ip', client_ip(), 10, 15)
|
||||
|| !rate_limit_check('mobile_staff_login_email', strtolower($email), 5, 15)) {
|
||||
api_error(429, 'RATE_LIMITED', 'Zu viele Anmeldeversuche. Bitte versuchen Sie es später erneut.');
|
||||
}
|
||||
|
||||
$pdo = get_db();
|
||||
$stmt = $pdo->prepare('SELECT * FROM staff WHERE LOWER(email) = LOWER(?) AND is_active = 1');
|
||||
$stmt->execute([$email]);
|
||||
$staff = $stmt->fetch();
|
||||
if (!$staff || !password_verify($password, $staff['password_hash'])) {
|
||||
api_error(401, 'INVALID_CREDENTIALS', 'E-Mail-Adresse oder Passwort ist falsch.');
|
||||
}
|
||||
if (!empty($staff['totp_enabled'])) {
|
||||
if ($totpCode === '') {
|
||||
api_json(['requiresTotp' => true], 202);
|
||||
}
|
||||
if (!preg_match('/^\d{6}$/', $totpCode) || !totp_verify($staff['totp_secret'], $totpCode)) {
|
||||
api_error(401, 'INVALID_TOTP', 'Der Authenticator-Code ist ungültig.');
|
||||
}
|
||||
}
|
||||
|
||||
rate_limit_reset('mobile_staff_login_email', strtolower($email));
|
||||
rate_limit_reset('mobile_staff_login_ip', client_ip());
|
||||
$issued = api_issue_token($pdo, (int) $staff['id'], isset($body['deviceName']) ? (string) $body['deviceName'] : null);
|
||||
audit_log((int) $staff['id'], 'Mobile App: Anmeldung');
|
||||
api_json([
|
||||
'token' => $issued['token'],
|
||||
'expiresAt' => $issued['expires_at'],
|
||||
'staff' => api_staff_payload($staff),
|
||||
]);
|
||||
|
||||
Reference in New Issue
Block a user