blob: 0b4fabdb8ad0b66970d7b9862694f0713f991b3c (
plain) (
blame)
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
|
<?php
Header('Content-Type: application/json; charset=utf-8');
$apikey = WebInterface::getApiKey();
if (empty($apikey) || $apikey !== Request::post('token', null, 'string')) {
http_response_code(403);
die('{"error":"Unauthorized"}');
}
$newKey = Request::post('privkey', null, 'string');
if (empty($newKey)) {
http_response_code(400);
die('{"error":"privkey missing"}');
}
$newCert = Request::post('cert', null, 'string');
if (empty($newCert)) {
http_response_code(400);
die('{"error":"cert missing"}');
}
// Import will try to validate the certificate too
$task = WebInterface::tmImportCustomCert($newKey, $newCert, 'api',
'New HTTPS certificate uploaded via API from ' . $_SERVER['REMOTE_ADDR']);
$task = Taskmanager::waitComplete($task, 10000);
if (!Taskmanager::isTask($task)) {
http_send_status(500);
die('{"error":"error communicating with task manager"}');
}
if (Taskmanager::isFailed($task)) {
// Send task data back to user, might contain more information
http_send_status(400);
die(json_encode([
'error' => 'import failed',
'data' => $task['data'] ?? [],
]));
}
echo '{"message":"OK"}';
Trigger::checkCallbacks();
exit;
|