diff options
author | Björn Schießle <schiessle@owncloud.com> | 2012-09-18 17:04:22 +0200 |
---|---|---|
committer | Björn Schießle <schiessle@owncloud.com> | 2012-09-18 17:04:22 +0200 |
commit | 842cd57fa780029e60d0fb8094d4dd794bb33cb7 (patch) | |
tree | dc741bc4fbb39ab141e1af21662f51bf4282c698 | |
parent | 2570ea7114a1b6db76d3b1f1f9fce311cbece500 (diff) | |
download | nextcloud-server-842cd57fa780029e60d0fb8094d4dd794bb33cb7.tar.gz nextcloud-server-842cd57fa780029e60d0fb8094d4dd794bb33cb7.zip |
use more oc file operations instead of plain PHP functions
-rw-r--r-- | apps/files_external/ajax/addRootCertificate.php | 26 |
1 files changed, 11 insertions, 15 deletions
diff --git a/apps/files_external/ajax/addRootCertificate.php b/apps/files_external/ajax/addRootCertificate.php index a8719fc7a3d..8848f85cf9d 100644 --- a/apps/files_external/ajax/addRootCertificate.php +++ b/apps/files_external/ajax/addRootCertificate.php @@ -2,25 +2,21 @@ OCP\JSON::checkAppEnabled('files_external'); -$view = \OCP\Files::getStorage("files_external"); -$from = $_FILES['rootcert_import']['tmp_name']; -$path = \OCP\Config::getSystemValue('datadirectory').$view->getAbsolutePath("").'uploads/'; -if(!file_exists($path)) mkdir($path,0700,true); -$to = $path.$_FILES['rootcert_import']['name']; -move_uploaded_file($from, $to); +$fh = fopen($_FILES['rootcert_import']['tmp_name'], 'r');
+$data = fread($fh, filesize($_FILES['rootcert_import']['tmp_name']));
+fclose($fh); +
+$view = new \OC_FilesystemView('/'.\OCP\User::getUser().'/files_external/uploads');
+if (!$view->file_exists('')) $view->mkdir(''); //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); - fclose($fh); +if (!strpos($data, 'BEGIN CERTIFICATE')) {
+ $data = chunk_split(base64_encode($data), 64, "\n");
+ $data = "-----BEGIN CERTIFICATE-----\n".$data."-----END CERTIFICATE-----\n";
} +$view->file_put_contents($_FILES['rootcert_import']['name'], $data); + OC_Mount_Config::createCertificateBundle(); header("Location: settings/personal.php"); |