f8ae1bb36e
jquery.fileupload offers the [`pastezone`](https://github.com/blueimp/jQuery-File-Upload/wiki/Options#pastezone) functionality. This functionality is enabled by default and if somebody copy-pastes something into Chrome it will automatically trigger an upload of the content to any configured jquery.fileupload element embedded in the JS. This implementation triggers some problems: 1. The pastezone is defined globally by default (🙈). So if there are multiple fileupload's on a page (such as in the personal settings) then stuff is going to be uploaded to all embedded uploads. 2. Our server code is not able to parse the data. For example for uploads in the files app we expect a file name which is not specified => Just an error is thrown. You can reproduce this by taking a file into your clipboard and in Chrome then pressing <kbd>CTRL + V</kbd>. 3. When copy-pasting some string from MS Office on the personal page a temporary avatar with said content is created. Considering that this is anyways was never working at all and causes bugs I've set the `pastezone` to `null`. This mens that upload via copy and paste will be disabled. Lesson learned: Third-party JS libraries can have some weird details.
70 lines
2.3 KiB
JavaScript
70 lines
2.3 KiB
JavaScript
$(document).ready(function () {
|
|
var type = $('#sslCertificate').data('type');
|
|
$('#sslCertificate').on('click', 'td.remove', function () {
|
|
var row = $(this).parent();
|
|
$.ajax(OC.generateUrl('settings/' + type + '/certificate/{certificate}', {certificate: row.data('name')}), {
|
|
type: 'DELETE'
|
|
});
|
|
row.remove();
|
|
|
|
if ($('#sslCertificate > tbody > tr').length === 0) {
|
|
$('#sslCertificate').hide();
|
|
}
|
|
return true;
|
|
});
|
|
|
|
$('#sslCertificate tr > td').tipsy({gravity: 'n', live: true});
|
|
|
|
$('#rootcert_import').fileupload({
|
|
pasteZone: null,
|
|
submit: function (e, data) {
|
|
data.formData = _.extend(data.formData || {}, {
|
|
requesttoken: OC.requestToken
|
|
});
|
|
},
|
|
success: function (data) {
|
|
if (typeof data === 'string') {
|
|
data = $.parseJSON(data);
|
|
} else if (data && data.length) {
|
|
// fetch response from iframe
|
|
data = $.parseJSON(data[0].body.innerText);
|
|
}
|
|
if (!data || typeof(data) === 'string') {
|
|
// IE8 iframe workaround comes here instead of fail()
|
|
OC.Notification.showTemporary(
|
|
t('settings', 'An error occurred. Please upload an ASCII-encoded PEM certificate.'));
|
|
return;
|
|
}
|
|
var issueDate = new Date(data.validFrom * 1000);
|
|
var expireDate = new Date(data.validTill * 1000);
|
|
var now = new Date();
|
|
var isExpired = !(issueDate <= now && now <= expireDate);
|
|
|
|
var row = $('<tr/>');
|
|
row.data('name', data.name);
|
|
row.addClass(isExpired ? 'expired' : 'valid');
|
|
row.append($('<td/>').attr('title', data.organization).text(data.commonName));
|
|
row.append($('<td/>').attr('title', t('core,', 'Valid until {date}', {date: data.validTillString}))
|
|
.text(data.validTillString));
|
|
row.append($('<td/>').attr('title', data.issuerOrganization).text(data.issuer));
|
|
row.append($('<td/>').addClass('remove').append(
|
|
$('<img/>').attr({
|
|
alt: t('core', 'Delete'),
|
|
title: t('core', 'Delete'),
|
|
src: OC.imagePath('core', 'actions/delete.svg')
|
|
}).addClass('action')
|
|
));
|
|
|
|
$('#sslCertificate tbody').append(row);
|
|
$('#sslCertificate').show();
|
|
},
|
|
fail: function () {
|
|
OC.Notification.showTemporary(
|
|
t('settings', 'An error occurred. Please upload an ASCII-encoded PEM certificate.'));
|
|
}
|
|
});
|
|
|
|
if ($('#sslCertificate > tbody > tr').length === 0) {
|
|
$('#sslCertificate').hide();
|
|
}
|
|
});
|