use more oc file operations instead of plain PHP functions

This commit is contained in:
Björn Schießle 2012-09-18 17:04:22 +02:00
parent 2570ea7114
commit 842cd57fa7
1 changed files with 11 additions and 15 deletions

View File

@ -2,25 +2,21 @@
OCP\JSON::checkAppEnabled('files_external'); OCP\JSON::checkAppEnabled('files_external');
$view = \OCP\Files::getStorage("files_external"); $fh = fopen($_FILES['rootcert_import']['tmp_name'], 'r');
$from = $_FILES['rootcert_import']['tmp_name']; $data = fread($fh, filesize($_FILES['rootcert_import']['tmp_name']));
$path = \OCP\Config::getSystemValue('datadirectory').$view->getAbsolutePath("").'uploads/'; fclose($fh);
if(!file_exists($path)) mkdir($path,0700,true);
$to = $path.$_FILES['rootcert_import']['name']; $view = new \OC_FilesystemView('/'.\OCP\User::getUser().'/files_external/uploads');
move_uploaded_file($from, $to); if (!$view->file_exists('')) $view->mkdir('');
//check if it is a PEM certificate, otherwise convert it if possible //check if it is a PEM certificate, otherwise convert it if possible
$fh = fopen($to, 'r'); if (!strpos($data, 'BEGIN CERTIFICATE')) {
$data = fread($fh, filesize($to)); $data = chunk_split(base64_encode($data), 64, "\n");
fclose($fh); $data = "-----BEGIN CERTIFICATE-----\n".$data."-----END CERTIFICATE-----\n";
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);
} }
$view->file_put_contents($_FILES['rootcert_import']['name'], $data);
OC_Mount_Config::createCertificateBundle(); OC_Mount_Config::createCertificateBundle();
header("Location: settings/personal.php"); header("Location: settings/personal.php");