2013-06-11 09:50:56 +00:00
/ *
Copyright 2011 Google Inc .
Licensed under the Apache License , Version 2.0 ( the "License" ) ;
you may not use this file except in compliance with the License .
You may obtain a copy of the License at
2014-01-08 03:41:58 +00:00
http : //www.apache.org/licenses/LICENSE-2.0
2013-06-11 09:50:56 +00:00
Unless required by applicable law or agreed to in writing , software
distributed under the License is distributed on an "AS IS" BASIS ,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND , either express or implied .
See the License for the specific language governing permissions and
limitations under the License .
* /
goog . provide ( 'camlistore.DebugPage' ) ;
goog . require ( 'goog.dom' ) ;
goog . require ( 'goog.events.EventType' ) ;
goog . require ( 'goog.ui.Component' ) ;
goog . require ( 'camlistore.ServerConnection' ) ;
// TODO(mpl): add button on index page (toolbar?) to come here.
2014-01-08 03:41:58 +00:00
// @param {camlistore.ServerType.DiscoveryDocument} config Global config of the current server this page is being rendered for.
// @param {goog.dom.DomHelper=} opt_domHelper DOM helper to use.
2013-06-11 09:50:56 +00:00
camlistore . DebugPage = function ( config , opt _domHelper ) {
goog . base ( this , opt _domHelper ) ;
this . config _ = config ;
this . sigdisco _ = null ;
this . connection _ = new camlistore . ServerConnection ( config ) ;
} ;
goog . inherits ( camlistore . DebugPage , goog . ui . Component ) ;
camlistore . DebugPage . prototype . enterDocument = function ( ) {
camlistore . DebugPage . superClass _ . enterDocument . call ( this ) ;
// set up listeners
goog . events . listen ( goog . dom . getElement ( 'discobtn' ) ,
goog . events . EventType . CLICK ,
this . discoRoot _ ,
false , this ) ;
goog . events . listen ( goog . dom . getElement ( 'sigdiscobtn' ) ,
goog . events . EventType . CLICK ,
this . discoJsonSignRoot _ ,
false , this ) ;
goog . events . listen ( goog . dom . getElement ( 'addkeyref' ) ,
goog . events . EventType . CLICK ,
this . addKeyRef _ ,
false , this ) ;
goog . events . listen ( goog . dom . getElement ( 'sign' ) ,
goog . events . EventType . CLICK ,
this . doSign _ ,
false , this ) ;
goog . events . listen ( goog . dom . getElement ( 'verify' ) ,
goog . events . EventType . CLICK ,
this . doVerify _ ,
false , this ) ;
} ;
camlistore . DebugPage . prototype . exitDocument = function ( ) {
camlistore . DebugPage . superClass _ . exitDocument . call ( this ) ;
} ;
camlistore . DebugPage . prototype . discoRoot _ = function ( e ) {
var disco = "<pre>" + JSON . stringify ( this . config _ , null , 2 ) + "</pre>" ;
goog . dom . getElement ( "discores" ) . innerHTML = disco ;
} ;
camlistore . DebugPage . prototype . discoJsonSignRoot _ = function ( ) {
this . connection _ . discoSignRoot (
goog . bind ( function ( sigdisco ) {
this . sigdisco _ = sigdisco ;
var disco = "<pre>" + JSON . stringify ( sigdisco , null , 2 ) + "</pre>" ;
goog . dom . getElement ( "sigdiscores" ) . innerHTML = disco ;
} , this )
)
} ;
camlistore . DebugPage . prototype . addKeyRef _ = function ( ) {
if ( ! this . sigdisco _ ) {
alert ( "must do jsonsign discovery first" ) ;
return ;
}
var clearta = goog . dom . getElement ( "clearjson" ) ;
var j ;
try {
j = JSON . parse ( clearta . value ) ;
} catch ( x ) {
alert ( x ) ;
return
}
j . camliSigner = this . sigdisco _ . publicKeyBlobRef ;
clearta . value = JSON . stringify ( j , null , 2 ) ;
2011-05-30 03:22:24 +00:00
}
2013-06-11 09:50:56 +00:00
camlistore . DebugPage . prototype . doSign _ = function ( ) {
2014-01-08 03:41:58 +00:00
// 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.
2013-06-11 09:50:56 +00:00
if ( ! this . sigdisco _ ) {
alert ( "must do jsonsign discovery first" ) ;
return ;
}
var clearta = goog . dom . getElement ( "clearjson" ) ;
var clearObj = JSON . parse ( clearta . value ) ;
this . connection _ . sign _ ( clearObj ,
function ( response ) {
goog . dom . getElement ( "signedjson" ) . value = response ;
}
)
2011-05-30 03:22:24 +00:00
}
2013-06-11 09:50:56 +00:00
camlistore . DebugPage . prototype . doVerify _ = function ( ) {
2014-01-08 03:41:58 +00:00
// 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.
2013-06-11 09:50:56 +00:00
if ( ! this . sigdisco _ ) {
alert ( "must do jsonsign discovery first" ) ;
return ;
}
var signedta = goog . dom . getElement ( "signedjson" ) ;
2013-06-26 18:15:17 +00:00
this . connection _ . verify _ ( signedta . value ,
2013-06-11 09:50:56 +00:00
function ( response ) {
var text = "<pre>" + response + "</pre>" ;
goog . dom . getElement ( "verifyinfo" ) . innerHTML = text ;
}
)
2011-05-30 03:22:24 +00:00
}