2012-07-04 19:16:02 +04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
OCP\JSON::checkAppEnabled('files_external');
|
|
|
|
|
|
|
|
$view = \OCP\Files::getStorage("files_external");
|
|
|
|
$from = $_FILES['rootcert_import']['tmp_name'];
|
2012-07-06 17:58:38 +04:00
|
|
|
$path = \OCP\Config::getSystemValue('datadirectory').$view->getAbsolutePath("").'uploads/';
|
2012-07-09 20:11:29 +04:00
|
|
|
if(!file_exists($path)) mkdir($path,0700,true);
|
2012-07-06 17:58:38 +04:00
|
|
|
$to = $path.$_FILES['rootcert_import']['name'];
|
2012-07-04 19:16:02 +04:00
|
|
|
move_uploaded_file($from, $to);
|
|
|
|
|
2012-07-06 17:58:38 +04:00
|
|
|
//check if it is a PEM certificate, otherwise convert it if possible
|
|
|
|
$fh = fopen($to, 'r');
|
|
|
|
$data = fread($fh, filesize($to));
|
|
|
|
fclose($fh);
|
|
|
|
if (!strpos($data, 'BEGIN CERTIFICATE')) {
|
|
|
|
$pem = chunk_split(base64_encode($data), 64, "\n");
|
|
|
|
$pem = "-----BEGIN CERTIFICATE-----\n".$pem."-----END CERTIFICATE-----\n";
|
|
|
|
$fh = fopen($to, 'w');
|
|
|
|
fwrite($fh, $pem);
|
2012-07-06 19:09:20 +04:00
|
|
|
fclose($fh);
|
2012-07-06 17:58:38 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
OC_Mount_Config::createCertificateBundle();
|
|
|
|
|
2012-07-04 19:16:02 +04:00
|
|
|
header("Location: settings/personal.php");
|
|
|
|
exit;
|
|
|
|
?>
|