blob: 0b4fabdb8ad0b66970d7b9862694f0713f991b3c (
plain) (
tree)
|
|
<?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;
|