-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsave_emailadress.php
More file actions
49 lines (39 loc) · 1.44 KB
/
save_emailadress.php
File metadata and controls
49 lines (39 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
require_once 'inc/config.php';
header('Content-Type: text/plain; charset=utf-8');
$secretToken = 'serverintern';
$ct = $_SERVER['CONTENT_TYPE'] ?? $_SERVER['HTTP_CONTENT_TYPE'] ?? '';
if (stripos($ct, 'application/json') !== false) {
$raw = file_get_contents('php://input');
$input = json_decode($raw, true);
if (!is_array($input)) $input = [];
} else {
$input = $_POST;
}
if (!isset($input['token']) || $input['token'] !== $secretToken) {
http_response_code(403);
exit('Forbidden');
}
$uploadId = trim($input['uploadId'] ?? '');
$uploader = trim($input['uploader_email'] ?? '');
$recipientRaw = trim($input['recipient_email'] ?? '');
$recipients = preg_split('/[\s,;]+/', $recipientRaw);
$recipients = array_unique(array_filter(array_map('trim', $recipients), function ($email) {
return filter_var($email, FILTER_VALIDATE_EMAIL);
}));
$fileData = file_exists($dataFile) ? json_decode(file_get_contents($dataFile), true) : [];
if (!isset($fileData[$uploadId])) {
$fileData[$uploadId] = [
'uploader_email' => $uploader,
'recipient_email' => $recipients,
'keys' => []
];
}
if (!isset($fileData[$uploadId]['keys']) || !is_array($fileData[$uploadId]['keys'])) {
$fileData[$uploadId]['keys'] = [];
}
if (!in_array($key, $fileData[$uploadId]['keys'])) {
$fileData[$uploadId]['keys'][] = $key;
}
file_put_contents($dataFile, json_encode($fileData, JSON_PRETTY_PRINT));
http_response_code(200);