Skip to content

Commit

Permalink
allow users to upload ssl root certificates for the webdav client
Browse files Browse the repository at this point in the history
  • Loading branch information
Bjoern Schiessle committed Jul 4, 2012
1 parent b2eac08 commit 5d61b85
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 6 deletions.
12 changes: 12 additions & 0 deletions apps/files_external/ajax/addRootCertificate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

OCP\JSON::checkAppEnabled('files_external');

$view = \OCP\Files::getStorage("files_external");
$from = $_FILES['rootcert_import']['tmp_name'];
$to = \OCP\Config::getSystemValue('datadirectory').$view->getAbsolutePath("").$_FILES['rootcert_import']['name'];
move_uploaded_file($from, $to);

header("Location: settings/personal.php");
exit;
?>
9 changes: 9 additions & 0 deletions apps/files_external/ajax/removeRootCertificate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

OCP\JSON::checkAppEnabled('files_external');

$view = \OCP\Files::getStorage("files_external");
$cert = $_POST['cert'];
$file = \OCP\Config::getSystemValue('datadirectory').$view->getAbsolutePath("").$cert;
unlink($file);
?>
10 changes: 6 additions & 4 deletions apps/files_external/js/settings.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
OC.MountConfig={
OC.MountConfig={
saveStorage:function(tr) {
var mountPoint = $(tr).find('.mountPoint input').val();
if (mountPoint == '') {
Expand Down Expand Up @@ -68,7 +68,6 @@ OC.MountConfig={
}

$(document).ready(function() {

$('.chzn-select').chosen();

$('#selectBackend').live('change', function() {
Expand Down Expand Up @@ -116,8 +115,11 @@ $(document).ready(function() {
$('td.remove>img').live('click', function() {
var tr = $(this).parent().parent();
var mountPoint = $(tr).find('.mountPoint input').val();
if (mountPoint == '') {
return false;
if (!mountPoint) {
var row=this.parentNode.parentNode;
$.post(OC.filePath('files_external', 'ajax', 'removeRootCertificate.php'), { cert: row.id });
$(tr).remove();
return true;
}
if ($('#externalStorage').data('admin') === true) {
var isPersonal = false;
Expand Down
15 changes: 15 additions & 0 deletions apps/files_external/lib/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,21 @@ private static function writeData($isPersonal, $data) {
$content .= ");\n?>";
@file_put_contents($file, $content);
}

/**
* Returns all user uploaded ssl root certificates
* @return array
*/
public static function getCertificates() {
$view = \OCP\Files::getStorage('files_external');
$path=\OCP\Config::getSystemValue('datadirectory').$view->getAbsolutePath("");
$result = array();
$handle = opendir($path);
while (false !== ($file = readdir($handle))) {
if($file != '.' && $file != '..') $result[] = $file;
}
return $result;
}

}

Expand Down
1 change: 1 addition & 0 deletions apps/files_external/personal.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
$tmpl = new OCP\Template('files_external', 'settings');
$tmpl->assign('isAdminPage', false, false);
$tmpl->assign('mounts', OC_Mount_Config::getPersonalMountPoints());
$tmpl->assign('certs', OC_Mount_Config::getCertificates());
$tmpl->assign('backends', $backends);
return $tmpl->fetchPage();

Expand Down
25 changes: 23 additions & 2 deletions apps/files_external/templates/settings.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<form id="files_external">
<form id="files_external" method="post" enctype="multipart/form-data" action="/owncloud/?app=files_external&getfile=ajax%2FaddRootCertificate.php">
<fieldset class="personalblock">
<legend><strong><?php echo $l->t('External Storage'); ?></strong></legend>
<table id="externalStorage" data-admin='<?php echo json_encode($_['isAdminPage']); ?>'>
Expand Down Expand Up @@ -79,11 +79,32 @@
<?php endforeach; ?>
</tbody>
</table>
<br />

<table id="sslCertificate" data-admin='<?php echo json_encode($_['isAdminPage']); ?>'>
<thead>
<tr>
<th><?php echo $l->t('SSL root certificates'); ?></th>
<th>&nbsp;</th>
</tr>
</thead>
<tbody width="100%">
<?php foreach ($_['certs'] as $rootCert): ?>
<tr id="<?php echo $rootCert ?>">
<td class="rootCert"><?php echo $rootCert ?></td>
<td <?php echo ($rootCert != '') ? 'class="remove"' : 'style="visibility:hidden;"'; ?>><img alt="<?php echo $l->t('Delete'); ?>" title="<?php echo $l->t('Delete'); ?>" class="svg action" src="<?php echo image_path('core', 'actions/delete.svg'); ?>" /></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<input type="file" id="rootcert_import" name="rootcert_import" style="width:230px;">
<input type="submit" name="cert_import" value="<?php echo $l->t('Import Root Certificate'); ?>" />

<?php if ($_['isAdminPage']): ?>
<br />
<input type="checkbox" name="allowUserMounting" id="allowUserMounting" value="1" <?php if ($_['allowUserMounting'] == 'yes') echo ' checked="checked"'; ?> />
<label for="allowUserMounting"><?php echo $l->t('Enable User External Storage'); ?></label><br/>
<em><?php echo $l->t('Allow users to mount their own external storage'); ?></em>
<?php endif; ?>
</fieldset>
</form>
</form>

0 comments on commit 5d61b85

Please sign in to comment.