certificates.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. $(document).ready(function () {
  2. var type = $('#sslCertificate').data('type');
  3. $('#sslCertificate').on('click', 'td.remove', function () {
  4. var row = $(this).parent();
  5. $.ajax(OC.generateUrl('settings/' + type + '/certificate/{certificate}', {certificate: row.data('name')}), {
  6. type: 'DELETE'
  7. });
  8. row.remove();
  9. if ($('#sslCertificate > tbody > tr').length === 0) {
  10. $('#sslCertificate').hide();
  11. }
  12. return true;
  13. });
  14. $('#sslCertificate tr > td').tooltip({placement: 'bottom', container: 'body'});
  15. $('#rootcert_import').fileupload({
  16. pasteZone: null,
  17. submit: function (e, data) {
  18. data.formData = _.extend(data.formData || {}, {
  19. requesttoken: OC.requestToken
  20. });
  21. },
  22. success: function (data) {
  23. if (typeof data === 'string') {
  24. data = JSON.parse(data);
  25. } else if (data && data.length) {
  26. // fetch response from iframe
  27. data = JSON.parse(data[0].body.innerText);
  28. }
  29. if (!data || typeof(data) === 'string') {
  30. // IE8 iframe workaround comes here instead of fail()
  31. OC.Notification.showTemporary(
  32. t('settings', 'An error occurred. Please upload an ASCII-encoded PEM certificate.'));
  33. return;
  34. }
  35. var issueDate = new Date(data.validFrom * 1000);
  36. var expireDate = new Date(data.validTill * 1000);
  37. var now = new Date();
  38. var isExpired = !(issueDate <= now && now <= expireDate);
  39. var row = $('<tr/>');
  40. row.data('name', data.name);
  41. row.addClass(isExpired ? 'expired' : 'valid');
  42. row.append($('<td/>').attr('title', data.organization).text(data.commonName));
  43. row.append($('<td/>').attr('title', t('core,', 'Valid until {date}', {date: data.validTillString}))
  44. .text(data.validTillString));
  45. row.append($('<td/>').attr('title', data.issuerOrganization).text(data.issuer));
  46. row.append($('<td/>').addClass('remove').append(
  47. $('<img/>').attr({
  48. alt: t('core', 'Delete'),
  49. title: t('core', 'Delete'),
  50. src: OC.imagePath('core', 'actions/delete.svg')
  51. }).addClass('action')
  52. ));
  53. $('#sslCertificate tbody').append(row);
  54. $('#sslCertificate').show();
  55. },
  56. fail: function () {
  57. OC.Notification.showTemporary(
  58. t('settings', 'An error occurred. Please upload an ASCII-encoded PEM certificate.'));
  59. }
  60. });
  61. if ($('#sslCertificate > tbody > tr').length === 0) {
  62. $('#sslCertificate').hide();
  63. }
  64. });