$view = \OCP\Files::getStorage("files_external");
$from = $_FILES['rootcert_import']['tmp_name'];
-$to = \OCP\Config::getSystemValue('datadirectory').$view->getAbsolutePath("").$_FILES['rootcert_import']['name'];
+$path = \OCP\Config::getSystemValue('datadirectory').$view->getAbsolutePath("").'uploads/';
+$to = $path.$_FILES['rootcert_import']['name'];
move_uploaded_file($from, $to);
+//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");\r
+ $pem = "-----BEGIN CERTIFICATE-----\n".$pem."-----END CERTIFICATE-----\n";
+ $fh = fopen($to, 'w');
+ fwrite($fh, $pem);
+}
+
+OC_Mount_Config::createCertificateBundle();
+
header("Location: settings/personal.php");
exit;
?>
\ No newline at end of file
$view = \OCP\Files::getStorage("files_external");
$cert = $_POST['cert'];
-$file = \OCP\Config::getSystemValue('datadirectory').$view->getAbsolutePath("").$cert;
+$file = \OCP\Config::getSystemValue('datadirectory').$view->getAbsolutePath("").'uploads/'.$cert;
unlink($file);
+OC_Mount_Config::createCertificateBundle();
?>
\ No newline at end of file
*/\r
public static function getCertificates() {
$view = \OCP\Files::getStorage('files_external');
- $path=\OCP\Config::getSystemValue('datadirectory').$view->getAbsolutePath("");
+ $path=\OCP\Config::getSystemValue('datadirectory').$view->getAbsolutePath("").'uploads/';
+ if (!is_dir($path)) mkdir($path);
$result = array();
$handle = opendir($path);
while (false !== ($file = readdir($handle))) {
}
return $result;
}
+
+ /**
+ * creates certificate bundle
+ */
+ public static function createCertificateBundle() {
+ $view = \OCP\Files::getStorage("files_external");\r
+ $path = \OCP\Config::getSystemValue('datadirectory').$view->getAbsolutePath("");\r
+ \r
+ $certs = OC_Mount_Config::getCertificates();\r
+ $fh_certs = fopen($path."/rootcerts.crt", 'w');\r
+ foreach ($certs as $cert) {\r
+ $file=$path.'/uploads/'.$cert;\r
+ $fh = fopen($file, "r");\r
+ $data = fread($fh, filesize($file));\r
+ fclose($fh);
+ if (strpos($data, 'BEGIN CERTIFICATE')) {\r
+ fwrite($fh_certs, $data);
+ }\r
+ }\r
+ \r
+ fclose($fh_certs);
+
+ return true;
+ }
}
$this->client = new OC_Connector_Sabre_Client($settings);
if($caview = \OCP\Files::getStorage('files_external')) {
- $this->client->setCurlSettings(array(CURLOPT_CAPATH => \OCP\Config::getSystemValue('datadirectory').$caview->getAbsolutePath("")));
+ $this->client->setCurlSettings(array(CURLOPT_CAINFO => \OCP\Config::getSystemValue('datadirectory').$caview->getAbsolutePath("").'rootcerts.crt'));
}
//create the root folder if necesary
$this->mkdir('');
</table>
<br />
- <?php if (!$_['isAdminPage'] && false): // disabled until sabredav can handle uploaded ca certs ?>
+ <?php if (!$_['isAdminPage']): ?>
<table id="sslCertificate" data-admin='<?php echo json_encode($_['isAdminPage']); ?>'>
<thead>
<tr>
* @return array\r
*/\r
public function request($method, $url = '', $body = null, $headers = array()) {\r
- \r
+\r
$this->curlSettings[CURLOPT_POSTFIELDS] = $body; \r
$url = $this->getAbsoluteUrl($url);\r
\r