github.com/slspeek/camlistore_namedsearch@v0.0.0-20140519202248-ed6f70f7721a/server/camlistored/ui/sigdebug.js (about) 1 /* 2 Copyright 2011 Google Inc. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 goog.provide('cam.DebugPage'); 18 19 goog.require('goog.dom'); 20 goog.require('goog.events.EventType'); 21 goog.require('goog.ui.Component'); 22 23 goog.require('cam.ServerConnection'); 24 25 // TODO(mpl): add button on index page (toolbar?) to come here. 26 // @param {cam.ServerType.DiscoveryDocument} config Global config of the current server this page is being rendered for. 27 // @param {goog.dom.DomHelper=} opt_domHelper DOM helper to use. 28 cam.DebugPage = function(config, opt_domHelper) { 29 goog.base(this, opt_domHelper); 30 31 this.config_ = config; 32 this.sigdisco_ = null; 33 this.connection_ = new cam.ServerConnection(config); 34 35 }; 36 goog.inherits(cam.DebugPage, goog.ui.Component); 37 38 cam.DebugPage.prototype.enterDocument = function() { 39 cam.DebugPage.superClass_.enterDocument.call(this); 40 41 // set up listeners 42 goog.events.listen(goog.dom.getElement('discobtn'), 43 goog.events.EventType.CLICK, 44 this.discoRoot_, 45 false, this); 46 goog.events.listen(goog.dom.getElement('sigdiscobtn'), 47 goog.events.EventType.CLICK, 48 this.discoJsonSignRoot_, 49 false, this); 50 goog.events.listen(goog.dom.getElement('addkeyref'), 51 goog.events.EventType.CLICK, 52 this.addKeyRef_, 53 false, this); 54 goog.events.listen(goog.dom.getElement('sign'), 55 goog.events.EventType.CLICK, 56 this.doSign_, 57 false, this); 58 goog.events.listen(goog.dom.getElement('verify'), 59 goog.events.EventType.CLICK, 60 this.doVerify_, 61 false, this); 62 }; 63 64 cam.DebugPage.prototype.exitDocument = function() { 65 cam.DebugPage.superClass_.exitDocument.call(this); 66 }; 67 68 cam.DebugPage.prototype.discoRoot_ = function(e) { 69 var disco = "<pre>" + JSON.stringify(this.config_, null, 2) + "</pre>"; 70 goog.dom.getElement("discores").innerHTML = disco; 71 }; 72 73 cam.DebugPage.prototype.discoJsonSignRoot_ = function() { 74 this.connection_.discoSignRoot( 75 goog.bind(function(sigdisco) { 76 this.sigdisco_ = sigdisco; 77 var disco = "<pre>" + JSON.stringify(sigdisco, null, 2) + "</pre>"; 78 goog.dom.getElement("sigdiscores").innerHTML = disco; 79 }, this) 80 ) 81 }; 82 83 cam.DebugPage.prototype.addKeyRef_ = function() { 84 if (!this.sigdisco_) { 85 alert("must do jsonsign discovery first"); 86 return; 87 } 88 var clearta = goog.dom.getElement("clearjson"); 89 var j; 90 try { 91 j = JSON.parse(clearta.value); 92 } catch (x) { 93 alert(x); 94 return 95 } 96 j.camliSigner = this.sigdisco_.publicKeyBlobRef; 97 clearta.value = JSON.stringify(j, null, 2); 98 } 99 100 cam.DebugPage.prototype.doSign_ = function() { 101 // We actually do not need sigdisco since sign_ will pull all the needed info from the config_ instead. But I'm leaving the check as the debug check is also a sort of demo. 102 if (!this.sigdisco_) { 103 alert("must do jsonsign discovery first"); 104 return; 105 } 106 var clearta = goog.dom.getElement("clearjson"); 107 var clearObj = JSON.parse(clearta.value); 108 this.connection_.sign_(clearObj, 109 function(response) { 110 goog.dom.getElement("signedjson").value = response; 111 } 112 ) 113 } 114 115 cam.DebugPage.prototype.doVerify_ = function() { 116 // We actually do not need sigdisco since sign_ will pull all the needed info from the config_ instead. But I'm leaving the check as the debug check is also a sort of demo. 117 if (!this.sigdisco_) { 118 alert("must do jsonsign discovery first"); 119 return; 120 } 121 var signedta = goog.dom.getElement("signedjson"); 122 this.connection_.verify_(signedta.value, 123 function(response) { 124 var text = "<pre>" + response + "</pre>"; 125 goog.dom.getElement("verifyinfo").innerHTML = text; 126 } 127 ) 128 }