diff options
author | Martin Kosek <mkosek@redhat.com> | 2011-02-16 14:26:35 +0100 |
---|---|---|
committer | Adam Young <ayoung@redhat.com> | 2011-02-18 09:49:37 -0500 |
commit | b7700ea815222b4de80741ad77b31707051300bd (patch) | |
tree | 4c92ba518468af34f9587131c8f4de3bb13613e3 /install/ui/certificate.js | |
parent | 27532f54687297e5dfa7d66503f22186d7fc3237 (diff) | |
download | freeipa-b7700ea815222b4de80741ad77b31707051300bd.tar.gz freeipa-b7700ea815222b4de80741ad77b31707051300bd.tar.xz freeipa-b7700ea815222b4de80741ad77b31707051300bd.zip |
Remove WebUI identifiers from global namespace
Many WebUI identifiers were defined in a global namespace. This is
not a good programming practice and may result in name clashes,
for example with other libraries.
This patch moves these variables to IPA namespace or its
sub-namespaces, when meaningful.
https://fedorahosted.org/freeipa/ticket/212
Diffstat (limited to 'install/ui/certificate.js')
-rwxr-xr-x | install/ui/certificate.js | 710 |
1 files changed, 356 insertions, 354 deletions
diff --git a/install/ui/certificate.js b/install/ui/certificate.js index 3158d0488..56995282f 100755 --- a/install/ui/certificate.js +++ b/install/ui/certificate.js @@ -20,377 +20,379 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -var BEGIN_CERTIFICATE = '-----BEGIN CERTIFICATE-----'; -var END_CERTIFICATE = '-----END CERTIFICATE-----'; - -var BEGIN_CERTIFICATE_REQUEST = '-----BEGIN CERTIFICATE REQUEST-----'; -var END_CERTIFICATE_REQUEST = '-----END CERTIFICATE REQUEST-----'; - -var CRL_REASON = [ - 'Unspecified', - 'Key Compromise', - 'CA Compromise', - 'Affiliation Changed', - 'Superseded', - 'Cessation of Operation', - 'Certificate Hold', - null, - 'Remove from CRL', - 'Privilege Withdrawn', - 'AA Compromise' -]; - -var CERTIFICATE_STATUS_MISSING = 0; -var CERTIFICATE_STATUS_VALID = 1; -var CERTIFICATE_STATUS_REVOKED = 2; - -function certificate_parse_dn(dn) { - - var result = {}; - if (!dn) return result; - - // TODO: Use proper LDAP DN parser - var rdns = dn.split(','); - for (var i=0; i<rdns.length; i++) { - var rdn = rdns[i]; - if (!rdn) continue; - - var parts = rdn.split('='); - var name = $.trim(parts[0].toLowerCase()); - var value = $.trim(parts[1]); - - var old_value = result[name]; - if (!old_value) { - result[name] = value; - } else if (typeof old_value == "string") { - result[name] = [old_value, value]; - } else { - result[name].push(value); + +IPA.cert = { + BEGIN_CERTIFICATE : '-----BEGIN CERTIFICATE-----', + END_CERTIFICATE : '-----END CERTIFICATE-----', + BEGIN_CERTIFICATE_REQUEST : '-----BEGIN CERTIFICATE REQUEST-----', + END_CERTIFICATE_REQUEST : '-----END CERTIFICATE REQUEST-----', + CRL_REASON : [ + 'Unspecified', + 'Key Compromise', + 'CA Compromise', + 'Affiliation Changed', + 'Superseded', + 'Cessation of Operation', + 'Certificate Hold', + null, + 'Remove from CRL', + 'Privilege Withdrawn', + 'AA Compromise' + ], + CERTIFICATE_STATUS_MISSING : 0, + CERTIFICATE_STATUS_VALID : 1, + CERTIFICATE_STATUS_REVOKED : 2, + + parse_dn : function (dn) { + + var result = {}; + if (!dn) return result; + + // TODO: Use proper LDAP DN parser + var rdns = dn.split(','); + for (var i=0; i<rdns.length; i++) { + var rdn = rdns[i]; + if (!rdn) continue; + + var parts = rdn.split('='); + var name = $.trim(parts[0].toLowerCase()); + var value = $.trim(parts[1]); + + var old_value = result[name]; + if (!old_value) { + result[name] = value; + } else if (typeof old_value == "string") { + result[name] = [old_value, value]; + } else { + result[name].push(value); + } } - } - return result; -} + return result; + }, -function certificate_get_dialog(spec) { - var that = {}; - spec = spec || {}; - that.title = spec.title || ''; - that.usercertificate = spec.usercertificate || ''; - - var dialog = $('<div/>', { - 'title': that.title - }); - - var textarea = $('<textarea/>', { - readonly: 'yes', - style: 'width: 100%; height: 275px;' - }).appendTo(dialog); - - textarea.val( - BEGIN_CERTIFICATE+'\n'+ - that.usercertificate+'\n'+ - END_CERTIFICATE ); - - that.open = function() { - dialog.dialog({ - modal: true, - width: 500, - height: 400, - buttons: { - 'Close': function() { - dialog.dialog('destroy'); - } - } + get_dialog: function (spec) { + var that = {}; + spec = spec || {}; + + that.title = spec.title || ''; + that.usercertificate = spec.usercertificate || ''; + + var dialog = $('<div/>', { + 'title': that.title }); - }; - return that; -} + var textarea = $('<textarea/>', { + readonly: 'yes', + style: 'width: 100%; height: 275px;' + }).appendTo(dialog); + + textarea.val( + IPA.cert.BEGIN_CERTIFICATE+'\n'+ + that.usercertificate+'\n'+ + IPA.cert.END_CERTIFICATE ); + + that.open = function() { + dialog.dialog({ + modal: true, + width: 500, + height: 400, + buttons: { + 'Close': function() { + dialog.dialog('destroy'); + } + } + }); + }; + + return that; + }, -function certificate_revoke_dialog(spec) { - var that = {}; - spec = spec || {}; - that.title = spec.title || ''; - that.revoke = spec.revoke; + revoke_dialog: function (spec) { + var that = {}; + spec = spec || {}; - var dialog = $('<div/>', { - 'title': that.title - }); + that.title = spec.title || ''; + that.revoke = spec.revoke; - var table = $('<table/>').appendTo(dialog); + var dialog = $('<div/>', { + 'title': that.title + }); - var tr = $('<tr/>').appendTo(table); + var table = $('<table/>').appendTo(dialog); - var td = $('<td/>').appendTo(tr); - td.append('Note:'); + var tr = $('<tr/>').appendTo(table); - td = $('<td/>').appendTo(tr); - td.append( - 'To confirm your intention to revoke this certificate, '+ - 'select a reason from the pull-down list, and click '+ - 'the "Revoke" button.'); + var td = $('<td/>').appendTo(tr); + td.append('Note:'); - tr = $('<tr/>').appendTo(table); + td = $('<td/>').appendTo(tr); + td.append( + 'To confirm your intention to revoke this certificate, '+ + 'select a reason from the pull-down list, and click '+ + 'the "Revoke" button.'); - td = $('<td/>').appendTo(tr); - td.append('Reason for Revocation:'); + tr = $('<tr/>').appendTo(table); - td = $('<td/>').appendTo(tr); + td = $('<td/>').appendTo(tr); + td.append('Reason for Revocation:'); - var select = $('<select/>').appendTo(td); - for (var i=0; i<CRL_REASON.length; i++) { - if (!CRL_REASON[i]) continue; - $('<option/>', { - 'value': i, - 'html': CRL_REASON[i] - }).appendTo(select); - } + td = $('<td/>').appendTo(tr); - that.open = function() { - dialog.dialog({ - modal: true, - width: 500, - height: 300, - buttons: { - 'Revoke': function() { - var values = {}; - values['reason'] = select.val(); - if (that.revoke) { - that.revoke(values); + var select = $('<select/>').appendTo(td); + for (var i=0; i<IPA.cert.CRL_REASON.length; i++) { + if (!IPA.cert.CRL_REASON[i]) continue; + $('<option/>', { + 'value': i, + 'html': IPA.cert.CRL_REASON[i] + }).appendTo(select); + } + + that.open = function() { + dialog.dialog({ + modal: true, + width: 500, + height: 300, + buttons: { + 'Revoke': function() { + var values = {}; + values['reason'] = select.val(); + if (that.revoke) { + that.revoke(values); + } + dialog.dialog('destroy'); + }, + 'Cancel': function() { + dialog.dialog('destroy'); } - dialog.dialog('destroy'); - }, - 'Cancel': function() { - dialog.dialog('destroy'); } - } - }); - }; + }); + }; - return that; -} + return that; + }, -function certificate_restore_dialog(spec) { - var that = {}; - spec = spec || {}; + restore_dialog: function (spec) { + var that = {}; + spec = spec || {}; - that.title = spec.title || ''; - that.restore = spec.restore; - - var dialog = $('<div/>', { - 'title': that.title - }); - - dialog.append( - 'To confirm your intention to restore this certificate, '+ - 'click the "Restore" button.'); - - that.open = function() { - dialog.dialog({ - modal: true, - width: 400, - height: 200, - buttons: { - 'Restore': function() { - var values = {}; - if (that.restore) { - that.restore(values); + that.title = spec.title || ''; + that.restore = spec.restore; + + var dialog = $('<div/>', { + 'title': that.title + }); + + dialog.append( + 'To confirm your intention to restore this certificate, '+ + 'click the "Restore" button.'); + + that.open = function() { + dialog.dialog({ + modal: true, + width: 400, + height: 200, + buttons: { + 'Restore': function() { + var values = {}; + if (that.restore) { + that.restore(values); + } + dialog.dialog('destroy'); + }, + 'Cancel': function() { + dialog.dialog('destroy'); } - dialog.dialog('destroy'); - }, - 'Cancel': function() { - dialog.dialog('destroy'); } - } + }); + }; + + return that; + }, + + view_dialog: function (spec) { + var that = {}; + spec = spec || {}; + + that.title = spec.title || ''; + that.subject = IPA.cert.parse_dn(spec.subject); + that.serial_number = spec.serial_number || ''; + that.issuer = IPA.cert.parse_dn(spec.issuer); + that.issued_on = spec.issued_on || ''; + that.expires_on = spec.expires_on || ''; + that.md5_fingerprint = spec.md5_fingerprint || ''; + that.sha1_fingerprint = spec.sha1_fingerprint || ''; + + var dialog = $('<div/>', { + 'title': that.title }); - }; - return that; -} + var table = $('<table/>').appendTo(dialog); + + var tr = $('<tr/>').appendTo(table); + $('<td/>', { + 'colspan': 2, + 'html': '<h3>Issued To</h3>' + }).appendTo(tr); + + tr = $('<tr/>').appendTo(table); + $('<td>Common Name:</td>').appendTo(tr); + $('<td/>', { + 'html': that.subject.cn + }).appendTo(tr); + + tr = $('<tr/>').appendTo(table); + $('<td>Organization:</td>').appendTo(tr); + $('<td/>', { + 'html': that.subject.o + }).appendTo(tr); + + tr = $('<tr/>').appendTo(table); + $('<td>Organizational Unit:</td>').appendTo(tr); + $('<td/>', { + 'html': that.subject.ou + }).appendTo(tr); + + tr = $('<tr/>').appendTo(table); + $('<td>Serial Number:</td>').appendTo(tr); + $('<td/>', { + 'html': that.serial_number + }).appendTo(tr); + + tr = $('<tr/>').appendTo(table); + $('<td/>', { + 'colspan': 2, + 'html': '<h3>Issued By</h3>' + }).appendTo(tr); + + tr = $('<tr/>').appendTo(table); + $('<td>Common Name:</td>').appendTo(tr); + $('<td/>', { + 'html': that.issuer.cn + }).appendTo(tr); + + tr = $('<tr/>').appendTo(table); + $('<td>Organization:</td>').appendTo(tr); + $('<td/>', { + 'html': that.issuer.o + }).appendTo(tr); + + tr = $('<tr/>').appendTo(table); + $('<td>Organizational Unit:</td>').appendTo(tr); + $('<td/>', { + 'html': that.issuer.ou + }).appendTo(tr); + + tr = $('<tr/>').appendTo(table); + $('<td/>', { + 'colspan': 2, + 'html': '<h3>Validity</h3>' + }).appendTo(tr); + + tr = $('<tr/>').appendTo(table); + $('<td>Issued On:</td>').appendTo(tr); + $('<td/>', { + 'html': that.issued_on + }).appendTo(tr); + + tr = $('<tr/>').appendTo(table); + $('<td>Expires On:</td>').appendTo(tr); + $('<td/>', { + 'html': that.expires_on + }).appendTo(tr); + + tr = $('<tr/>').appendTo(table); + $('<td/>', { + 'colspan': 2, + 'html': '<h3>Fingerprints</h3>' + }).appendTo(tr); + + tr = $('<tr/>').appendTo(table); + $('<td>SHA1 Fingerprint:</td>').appendTo(tr); + $('<td/>', { + 'html': that.sha1_fingerprint + }).appendTo(tr); + + tr = $('<tr/>').appendTo(table); + $('<td>MD5 Fingerprint:</td>').appendTo(tr); + $('<td/>', { + 'html': that.md5_fingerprint + }).appendTo(tr); + + that.open = function() { + dialog.dialog({ + modal: true, + width: 600, + height: 500, + buttons: { + 'Close': function() { + dialog.dialog('destroy'); + } + } + }); + }; -function certificate_view_dialog(spec) { - var that = {}; - spec = spec || {}; + return that; + }, - that.title = spec.title || ''; - that.subject = certificate_parse_dn(spec.subject); - that.serial_number = spec.serial_number || ''; - that.issuer = certificate_parse_dn(spec.issuer); - that.issued_on = spec.issued_on || ''; - that.expires_on = spec.expires_on || ''; - that.md5_fingerprint = spec.md5_fingerprint || ''; - that.sha1_fingerprint = spec.sha1_fingerprint || ''; - - var dialog = $('<div/>', { - 'title': that.title - }); - - var table = $('<table/>').appendTo(dialog); - - var tr = $('<tr/>').appendTo(table); - $('<td/>', { - 'colspan': 2, - 'html': '<h3>Issued To</h3>' - }).appendTo(tr); - - tr = $('<tr/>').appendTo(table); - $('<td>Common Name:</td>').appendTo(tr); - $('<td/>', { - 'html': that.subject.cn - }).appendTo(tr); - - tr = $('<tr/>').appendTo(table); - $('<td>Organization:</td>').appendTo(tr); - $('<td/>', { - 'html': that.subject.o - }).appendTo(tr); - - tr = $('<tr/>').appendTo(table); - $('<td>Organizational Unit:</td>').appendTo(tr); - $('<td/>', { - 'html': that.subject.ou - }).appendTo(tr); - - tr = $('<tr/>').appendTo(table); - $('<td>Serial Number:</td>').appendTo(tr); - $('<td/>', { - 'html': that.serial_number - }).appendTo(tr); - - tr = $('<tr/>').appendTo(table); - $('<td/>', { - 'colspan': 2, - 'html': '<h3>Issued By</h3>' - }).appendTo(tr); - - tr = $('<tr/>').appendTo(table); - $('<td>Common Name:</td>').appendTo(tr); - $('<td/>', { - 'html': that.issuer.cn - }).appendTo(tr); - - tr = $('<tr/>').appendTo(table); - $('<td>Organization:</td>').appendTo(tr); - $('<td/>', { - 'html': that.issuer.o - }).appendTo(tr); - - tr = $('<tr/>').appendTo(table); - $('<td>Organizational Unit:</td>').appendTo(tr); - $('<td/>', { - 'html': that.issuer.ou - }).appendTo(tr); - - tr = $('<tr/>').appendTo(table); - $('<td/>', { - 'colspan': 2, - 'html': '<h3>Validity</h3>' - }).appendTo(tr); - - tr = $('<tr/>').appendTo(table); - $('<td>Issued On:</td>').appendTo(tr); - $('<td/>', { - 'html': that.issued_on - }).appendTo(tr); - - tr = $('<tr/>').appendTo(table); - $('<td>Expires On:</td>').appendTo(tr); - $('<td/>', { - 'html': that.expires_on - }).appendTo(tr); - - tr = $('<tr/>').appendTo(table); - $('<td/>', { - 'colspan': 2, - 'html': '<h3>Fingerprints</h3>' - }).appendTo(tr); - - tr = $('<tr/>').appendTo(table); - $('<td>SHA1 Fingerprint:</td>').appendTo(tr); - $('<td/>', { - 'html': that.sha1_fingerprint - }).appendTo(tr); - - tr = $('<tr/>').appendTo(table); - $('<td>MD5 Fingerprint:</td>').appendTo(tr); - $('<td/>', { - 'html': that.md5_fingerprint - }).appendTo(tr); - - that.open = function() { - dialog.dialog({ - modal: true, - width: 600, - height: 500, - buttons: { - 'Close': function() { - dialog.dialog('destroy'); - } - } - }); - }; + request_dialog: function (spec) { + var that = {}; + spec = spec || {}; - return that; -} + that.title = spec.title || ''; + that.request = spec.request; -function certificate_request_dialog(spec) { - var that = {}; - spec = spec || {}; + var dialog = $('<div/>', { + 'title': that.title + }); - that.title = spec.title || ''; - that.request = spec.request; - - var dialog = $('<div/>', { - 'title': that.title - }); - - dialog.append('Copy and paste the Base64-encoded CSR below:'); - dialog.append('<br/>'); - dialog.append('<br/>'); - - dialog.append(BEGIN_CERTIFICATE_REQUEST); - dialog.append('<br/>'); - - var textarea = $('<textarea/>', { - style: 'width: 100%; height: 225px;' - }).appendTo(dialog); - - dialog.append('<br/>'); - dialog.append(END_CERTIFICATE_REQUEST); - - that.open = function() { - dialog.dialog({ - modal: true, - width: 500, - height: 400, - buttons: { - 'Issue': function() { - var values = {}; - var request = textarea.val(); - request = - BEGIN_CERTIFICATE_REQUEST+'\n'+ - $.trim(request)+'\n'+ - END_CERTIFICATE_REQUEST+'\n'; - values['request'] = request; - if (that.request) { - that.request(values); + dialog.append('Copy and paste the Base64-encoded CSR below:'); + dialog.append('<br/>'); + dialog.append('<br/>'); + + dialog.append(IPA.cert.BEGIN_CERTIFICATE_REQUEST); + dialog.append('<br/>'); + + var textarea = $('<textarea/>', { + style: 'width: 100%; height: 225px;' + }).appendTo(dialog); + + dialog.append('<br/>'); + dialog.append(IPA.cert.END_CERTIFICATE_REQUEST); + + that.open = function() { + dialog.dialog({ + modal: true, + width: 500, + height: 400, + buttons: { + 'Issue': function() { + var values = {}; + var request = textarea.val(); + request = + IPA.cert.BEGIN_CERTIFICATE_REQUEST+'\n'+ + $.trim(request)+'\n'+ + IPA.cert.END_CERTIFICATE_REQUEST+'\n'; + values['request'] = request; + if (that.request) { + that.request(values); + } + dialog.dialog('destroy'); + }, + 'Cancel': function() { + dialog.dialog('destroy'); } - dialog.dialog('destroy'); - }, - 'Cancel': function() { - dialog.dialog('destroy'); } - } - }); - }; + }); + }; - return that; -} + return that; + } +}; -function certificate_status_widget(spec) { +IPA.certificate_status_widget = function(spec) { spec = spec || {}; @@ -614,18 +616,18 @@ function certificate_status_widget(spec) { if (entity_certificate) { check_status(that.result.serial_number); } else { - set_status(CERTIFICATE_STATUS_MISSING); + set_status(IPA.cert.CERTIFICATE_STATUS_MISSING); } }; function set_status(status, revocation_reason) { - that.status_valid.css('display', status == CERTIFICATE_STATUS_VALID ? 'inline' : 'none'); - that.status_missing.css('display', status == CERTIFICATE_STATUS_MISSING ? 'inline' : 'none'); + that.status_valid.css('display', status == IPA.cert.CERTIFICATE_STATUS_VALID ? 'inline' : 'none'); + that.status_missing.css('display', status == IPA.cert.CERTIFICATE_STATUS_MISSING ? 'inline' : 'none'); if (!that.is_selfsign()) { - that.status_revoked.css('display', status == CERTIFICATE_STATUS_REVOKED ? 'inline' : 'none'); - that.revoke_button.css('visibility', status == CERTIFICATE_STATUS_VALID ? 'visible' : 'hidden'); - that.revocation_reason.html(revocation_reason == undefined ? '' : CRL_REASON[revocation_reason]); + that.status_revoked.css('display', status == IPA.cert.CERTIFICATE_STATUS_REVOKED ? 'inline' : 'none'); + that.revoke_button.css('visibility', status == IPA.cert.CERTIFICATE_STATUS_VALID ? 'visible' : 'hidden'); + that.revocation_reason.html(revocation_reason == undefined ? '' : IPA.cert.CRL_REASON[revocation_reason]); that.restore_button.css('visibility', revocation_reason == 6 ? 'visible' : 'hidden'); } } @@ -633,7 +635,7 @@ function certificate_status_widget(spec) { function check_status(serial_number) { if (that.is_selfsign()) { - set_status(CERTIFICATE_STATUS_VALID); + set_status(IPA.cert.CERTIFICATE_STATUS_VALID); return; } @@ -644,9 +646,9 @@ function certificate_status_widget(spec) { function(data, text_status, xhr) { var revocation_reason = data.result.result.revocation_reason; if (revocation_reason == undefined) { - set_status(CERTIFICATE_STATUS_VALID); + set_status(IPA.cert.CERTIFICATE_STATUS_VALID); } else { - set_status(CERTIFICATE_STATUS_REVOKED, revocation_reason); + set_status(IPA.cert.CERTIFICATE_STATUS_REVOKED, revocation_reason); } } ); @@ -656,13 +658,13 @@ function certificate_status_widget(spec) { var entity_certificate = that.get_entity_certificate(result); if (!entity_certificate) { - set_status(CERTIFICATE_STATUS_MISSING); + set_status(IPA.cert.CERTIFICATE_STATUS_MISSING); return; } var entity_name = that.get_entity_name(result); - var dialog = certificate_view_dialog({ + var dialog = IPA.cert.view_dialog({ 'title': 'Certificate for '+that.entity_label+' '+entity_name, 'subject': result['subject'], 'serial_number': result['serial_number'], @@ -680,13 +682,13 @@ function certificate_status_widget(spec) { var entity_certificate = that.get_entity_certificate(result); if (!entity_certificate) { - set_status(CERTIFICATE_STATUS_MISSING); + set_status(IPA.cert.CERTIFICATE_STATUS_MISSING); return; } var entity_name = that.get_entity_name(result); - var dialog = certificate_get_dialog({ + var dialog = IPA.cert.get_dialog({ 'title': 'Certificate for '+that.entity_label+' '+entity_name, 'usercertificate': entity_certificate }); @@ -699,7 +701,7 @@ function certificate_status_widget(spec) { var entity_name = that.get_entity_name(result); var entity_principal = that.get_entity_principal(result); - var dialog = certificate_request_dialog({ + var dialog = IPA.cert.request_dialog({ 'title': 'Issue New Certificate for '+that.entity_label+' '+entity_name, 'request': function(values) { var request = values['request']; @@ -724,14 +726,14 @@ function certificate_status_widget(spec) { var entity_certificate = that.get_entity_certificate(result); if (!entity_certificate) { - set_status(CERTIFICATE_STATUS_MISSING); + set_status(IPA.cert.CERTIFICATE_STATUS_MISSING); return; } var entity_name = that.get_entity_name(result); var serial_number = result['serial_number']; - var dialog = certificate_revoke_dialog({ + var dialog = IPA.cert.revoke_dialog({ 'title': 'Revoke Certificate for '+that.entity_label+' '+entity_name, 'revoke': function(values) { var reason = values['reason']; @@ -756,14 +758,14 @@ function certificate_status_widget(spec) { var entity_certificate = that.get_entity_certificate(result); if (!entity_certificate) { - set_status(CERTIFICATE_STATUS_MISSING); + set_status(IPA.cert.CERTIFICATE_STATUS_MISSING); return; } var entity_name = that.get_entity_name(result); var serial_number = result['serial_number']; - var dialog = certificate_restore_dialog({ + var dialog = IPA.cert.restore_dialog({ 'title': 'Restore Certificate for '+that.entity_label+' '+entity_name, 'restore': function(values) { IPA.cmd( @@ -781,4 +783,4 @@ function certificate_status_widget(spec) { } return that; -} +}; |