2014-08-15 19:18:46 +04:00
|
|
|
<?php
|
2014-08-27 18:28:51 +04:00
|
|
|
OCP\JSON::checkLoggedIn();
|
2014-08-15 19:18:46 +04:00
|
|
|
OCP\JSON::callCheck();
|
|
|
|
|
|
|
|
$l = new OC_L10N('core');
|
|
|
|
|
2014-08-18 15:57:38 +04:00
|
|
|
if (!isset($_FILES['rootcert_import'])) {
|
|
|
|
OCP\JSON::error(array('error' => 'No certificate uploaded'));
|
2014-08-15 19:18:46 +04:00
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
2014-08-18 15:57:38 +04:00
|
|
|
$data = file_get_contents($_FILES['rootcert_import']['tmp_name']);
|
|
|
|
$filename = basename($_FILES['rootcert_import']['name']);
|
2014-08-15 19:18:46 +04:00
|
|
|
|
|
|
|
$certificateManager = \OC::$server->getCertificateManager();
|
|
|
|
|
2014-08-27 18:28:51 +04:00
|
|
|
try {
|
|
|
|
$cert = $certificateManager->addCertificate($data, $filename);
|
2014-08-15 19:18:46 +04:00
|
|
|
OCP\JSON::success(array(
|
|
|
|
'name' => $cert->getName(),
|
|
|
|
'commonName' => $cert->getCommonName(),
|
|
|
|
'organization' => $cert->getOrganization(),
|
|
|
|
'validFrom' => $cert->getIssueDate()->getTimestamp(),
|
|
|
|
'validTill' => $cert->getExpireDate()->getTimestamp(),
|
|
|
|
'validFromString' => $l->l('date', $cert->getIssueDate()),
|
|
|
|
'validTillString' => $l->l('date', $cert->getExpireDate()),
|
|
|
|
'issuer' => $cert->getIssuerName(),
|
|
|
|
'issuerOrganization' => $cert->getIssuerOrganization()
|
|
|
|
));
|
2014-08-27 18:28:51 +04:00
|
|
|
} catch(\Exception $e) {
|
2014-08-15 19:18:46 +04:00
|
|
|
OCP\JSON::error(array('error' => 'Couldn\'t import SSL root certificate, allowed formats: PEM and DER'));
|
|
|
|
}
|