Browse Source

debug tab | encode/decode json

release/v0.1
mirrt 9 years ago
committed by vineetbhargav86
parent
commit
b4c5106e40
  1. 63
      iguana/index.html
  2. 115
      iguana/js/debugJson.js

63
iguana/index.html

@ -20,7 +20,6 @@
<body data-custom-load="true" data-name="iguana" data-tools="pnacl newlib glibc clang-newlib mac" data-configs="Debug Release"
data-path="{tc}/{config}">
<!-- <div class="jumbotron" style="height:100px;">
<h> Status: <code id="statusField">NO-STATUS</code></h>
<p>
@ -101,6 +100,9 @@ data-path="{tc}/{config}">
</div>
</div>
<div class="col-xs-8 col-sm-9 col-md-10">
<div class="panel-group">
<div class="panel panel-default api-call-All">
<div class="panel-heading">
@ -371,6 +373,64 @@ data-path="{tc}/{config}">
<div id="Debug_page" class="page">
<div class='panel panel-default'>
<div class='panel-heading'>
<h3><span>
Encrypt/decrypt JSON
</span></h3>
</div>
<div class='panel-body'>
<div class="row">
<div class="col-sm-8 col-md-8">
<form class="form-horizontal">
<div class="form-group">
<label for="debug_passphrase" class="control-label col-sm-3 col-md-3">
Passphrase
</label>
<div class="col-sm-7 col-md-7">
<input type="text" class="form-control" id='debug_passphrase'>
<span class='material-input'></span>
</div>
</div>
<div class="form-group">
<label for="debug_permanentfile" class="control-label col-sm-3 col-md-3">
Permanentfile
</label>
<div class="col-sm-7 col-md-7">
<input type="text" class="form-control" id='debug_permanentfile'>
<span class='material-input'></span>
</div>
</div>
<div class="form-group">
<label for="debug_json_src" class="control-label col-sm-3 col-md-3">
Json
</label>
<div class="col-sm-7 col-md-7">
<textarea name="" id="debug_json_src" cols="30" rows="5" class='form-control'></textarea>
<span class='material-input'></span>
</div>
</div>
<div class="form-group">
<button class="btn btn-primary" id="debug_json_encrypt">
Encrypt JSON
</button>
<button class="btn btn-primary" id="debug_json_decrypt">
Decrypt JSON
</button>
</div>
</form>
</div>
<div class="col-sm-4 col-md-4">
<h5 class="uri-link">Response</h5>
<pre class="hljs json coin_result" id="debug_json_result">JSON response</pre>
<button class="btn btn-default clear-response">Clear response</button>
</div>
</div>
</div>
</div>
<div class="jumbotron">
<table>
<tr >
@ -548,6 +608,7 @@ data-path="{tc}/{config}">
<script type="text/javascript " src="js/storage.js" ></script>
<script type="text/javascript " src="js/jquery.tablesort.js" ></script>
<script type="text/javascript " src="js/tradeintegration.js" ></script>
<script type="text/javascript " src="js/debugJson.js" ></script>
</body>
</html>

115
iguana/js/debugJson.js

@ -0,0 +1,115 @@
var dJson = {};
dJson.ENCRYPTED = false;
dJson.request = {};
dJson._init = function(credentials) {
for(var attr in this.request) {
if(this.request.hasOwnProperty(attr)) {
this.request[attr] = null;
};
};
this.request.passphrase = credentials.passphrase;
this.request.permanentfile = credentials.permanentfile;
this.request.agent = "SuperNET";
};
dJson._checkJson = function(json) {
try {
var obj = JSON.parse(json);
} catch(e) {
return false;
};
return ogj;
};
//{"agent":"SuperNET","method":"encryptjson","passphrase":"<passphrase>","permanentfile":"<filename>","fromform":"valuefromform","fromform2":"valuefromform2",...rest of form at top level}
dJson.encrypt = function(credentials, json, cb) {
this._init(credentials);
var jsonObj;
if(jsonObj = this._checkJson) {
this.ENCRYPTED = true;
this.request.method = "encryptjson";
for(var attr in jsonObj) {
if(jsonObj.hasOwnProperty(attr)) {
this.request[attr] = jsonObj[attr];
};
};
var request = JSON.stringify(this.request);
SPNAPI.makeRequest(
JSON.stringify(this.request),
function(request,response){
cb(response);
}
);
} else
cb(null);
};
//{"agent":"SuperNET","method":"encryptjson","passphrase":"<passphrase>","permanentfile":"<filename>"}
dJson.decrypt = function(credentials, cb) {
this._init(credentials);
this.ENCRYPTED = false;
this.request.method = "decryptjson";
SPNAPI.makeRequest(
JSON.stringify(this.request),
function(request,response){
cb(response);
}
);
};
$(document).ready(function() {
var encryptBtn = $('#debug_json_encrypt'),
decryptBtn = $('#debug_json_decrypt'),
debugJsonResult = $('#debug_json_result'),
pass = $('#debug_passphrase'),
permFile = $('#debug_permanentfile'),
jsonSrc = $('#debug_json_src');
$(encryptBtn).click(function(e) {
e.preventDefault();
debugJsonResult.text('');
dJson.encrypt({
passphrase: pass.val(),
permanentfile: permFile.val()
},
jsonSrc.val(),
function(response) {
debugJsonResult.text(response || 'wrong json');
}
);
});
$(decryptBtn).click(function(e) {
e.preventDefault();
if( !dJson.ENCRYPTED) {
debugJsonResult.text('Please call encryptjson first');
return;
};
dJson.decrypt({
passphrase: pass.val(),
permanentfile: permFile.val()
}, function(response) {
debugJsonResult.text(response);
});
});
});
Loading…
Cancel
Save