Skip to content

Commit

Permalink
debug tab | encode/decode json
Browse files Browse the repository at this point in the history
  • Loading branch information
mirrt authored and vineetbhargav86 committed Feb 27, 2016
1 parent 3a7001c commit b4c5106
Show file tree
Hide file tree
Showing 2 changed files with 177 additions and 1 deletion.
63 changes: 62 additions & 1 deletion iguana/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -101,6 +100,9 @@ <h2>iguana</h2>
</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">
Expand Down Expand Up @@ -371,6 +373,64 @@ <h3 class="panel-title">Settings</h3>


<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 >
Expand Down Expand Up @@ -548,6 +608,7 @@ <h3>Instandex tab</h3>
<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 changes: 115 additions & 0 deletions iguana/js/debugJson.js
Original file line number Diff line number Diff line change
@@ -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);
});
});
});



0 comments on commit b4c5106

Please sign in to comment.