Browse Source

pexe enable/disable button in satting tab,working manifest.json, saving peers and hdrs file in conf automatically

release/v0.1
vineetbhargav86 9 years ago
parent
commit
e09c5370de
  1. 14
      iguana/app/coin_mgmt.js
  2. 103
      iguana/example.js
  3. 11
      iguana/index.html
  4. 8
      iguana/js/api.js
  5. 35
      iguana/js/imgAPI.js
  6. 311
      iguana/js/peerlist.js
  7. 78
      iguana/js/settings.js
  8. 24
      iguana/js/storage.js
  9. 35
      iguana/manifest.json

14
iguana/app/coin_mgmt.js

@ -1,6 +1,4 @@
var coinManagement = {};
// Classes
coinManagement.Coin = function (_id, _symbol, _description, _statusId) {
@ -38,6 +36,18 @@ coinManagement.Initialize = function () {
];
};
coinManagement.getCoinSymbols=function(){
var coins=[];
if (coinManagement.Coins === null || coinManagement.Coins === undefined) {
return [];
}
for (var index = 0; index < coinManagement.Coins.length; index++) {
coins.push(coinManagement.Coins[index].Symbol);
}
return coins;
};
coinManagement.GetCoinIndex = function (id) {
if (coinManagement.Coins == null || coinManagement.Coins == undefined) {

103
iguana/example.js

@ -16,7 +16,7 @@ function $(id) {
*/
window.requestFileSystem = window.requestFileSystem || window.webkitRequestFileSystem;
function errorHandler(e) {
function errorHandler(e,callback,name) {
var msg = '';
switch (e.code) {
@ -25,6 +25,7 @@ function errorHandler(e) {
break;
case FileError.NOT_FOUND_ERR:
msg = 'NOT_FOUND_ERR';
callback(name);
break;
case FileError.SECURITY_ERR:
msg = 'SECURITY_ERR';
@ -42,9 +43,8 @@ function errorHandler(e) {
console.log('Error: ' + msg);
}
var fileSystem;
var fileSystem=null;
var files={};
function onInitFs(fs) {
console.log('Opened file system: ' + fs.name);
fileSystem = fs;
@ -52,17 +52,7 @@ function onInitFs(fs) {
// Called by the common.js module.
function domContentLoaded(name, tc, config, width, height) {
/* navigator.webkitPersistentStorage.requestQuota(10000000000,
function(bytes) {
common.updateStatus(
'Allocated ' + bytes + ' bytes of persistent storage. Running the first time will take 17 seconds to load');
common.attachDefaultListeners();
common.createNaClModule(name, tc, config, width, height);
},
function(e) { alert('Failed to allocate space') });
*/
navigator.webkitPersistentStorage.requestQuota(10000000000,
navigator.webkitPersistentStorage.requestQuota(10000000000,
function(bytes){
window.requestFileSystem(PERSISTENT, bytes, onInitFs, errorHandler);
common.updateStatus(
@ -75,6 +65,89 @@ function domContentLoaded(name, tc, config, width, height) {
}
var check_files=function(){
var coins= coinManagement.getCoinSymbols();
var files=["_hdrs.txt","_peers.txt"];
for(var i=0;i<coins.length;i++){
for(var j=0;j<files.length;j++){
var name="confs/"+coins[i]+files[j];
console.log("checking file "+name);
files[name]=null;
check_if_file_present(name);
}
}
};
var check_if_file_present=function(filename,callback){
fileSystem.root.getFile(filename, {}, function(fileEntry) {
//console.log("entered file fu");
// Get a File object representing the file,
// then use FileReader to read its contents.
fileEntry.file(function(file) {
var reader = new FileReader();
reader.onloadend = function(e) {
//var txtArea = document.createElement('textarea');
//console.log("Configuration file text: "+this.result.toString());
console.log("File already present in HTML5 system:"+fileEntry.fullPath);
//SPNAPI.conf_files[filename]=this.result.toString();
};
reader.readAsText(file);
}, function(e){
errorHandler(e,access_and_save_conf_file,filename);
});
}, function(e){
errorHandler(e,access_and_save_conf_file,filename);
});
};
var access_and_save_conf_file=function(name){
console.log("access file called for "+name);
$.ajax({
type: "GET",
url: name,
//async: false,
success: function (data){
save_contents(data,name);
}
});
};
var save_contents=function(contents,name){
fileSystem.root.getFile(name, {create: true}, function(fileEntry) {
// Create a FileWriter object for our FileEntry (log.txt).
fileEntry.createWriter(function(fileWriter) {
fileWriter.onwriteend = function(e) {
console.log('Write completed.');
};
fileWriter.onerror = function(e) {
console.log('Write failed: ' + e.toString());
};
// Create a new Blob and write it to log.txt.
var blob = new Blob([contents], {type: 'text/plain'});
fileWriter.write(blob);
}, errorHandler);
}, errorHandler);
};
// Called by the common.js module.
function attachListeners() {
var radioEls = document.querySelectorAll('input[type="radio"]');

11
iguana/index.html

@ -291,7 +291,7 @@ data-path="{tc}/{config}">
<div class="row">
<div class="col-xs-6 col-md-6 col-lg-6">
<div id="agent_settings"></div>
</div>
</div>
<div class="col-xs-6 col-md-6 col-lg-6">
<div id="config_settings"></div>
<div class="function" id="fread" hidden>
@ -480,22 +480,23 @@ data-path="{tc}/{config}">
<script type="text/javascript" src='js/jquery.dropdown.js'></script>
<!--Iguana genric code-->
<script type="text/javascript" src="js/api.js" " charset="utf-8 "></script>
<script type="text/javascript" src="js/api.js" " charset="utf-8 "></script>
<script src="app/coin_mgmt.js "></script>
<script type="text/javascript " src="js/util.js "></script>
<script type="text/javascript " src="js/sites.js " charset="utf-8 "></script>
<script type="text/javascript " src="app/common.js "></script>
<script type="text/javascript " src="app/startup.js " ></script>
<script type="text/javascript " src="js/settings.js " charset="utf-8 "></script>
<!--Iguana tabs-->
<script src='js/form.js'></script>
<script src="app/coin_mgmt.js "></script>
<script type="text/javascript " src='js/peerlist.js'></script>
<script type="text/javascript " src="js/methods.js " charset="utf-8 "></script>
<script type="text/javascript " src="js/settings.js " charset="utf-8 "></script>
<script type="text/javascript " src="js/imgAPI.js " ></script>
<script type="text/javascript " src="js/pangea.js" ></script>
<script type="text/javascript " src="js/blockexplorer.js" ></script>
<script type="text/javascript " src="js/instantdex.js" ></script>
<script type="text/javascript " src="js/storage.js" ></script>
</body>
</html>

8
iguana/js/api.js

@ -11,7 +11,7 @@ function tagGen(len)
var SPNAPI = (function(SPNAPI, $, undefined) {
SPNAPI.methods = {};
SPNAPI.pages = ["Instandex", "Pangea", "Peers","Debug", "Coins", "Blockexplorer"];
SPNAPI.pages = ["Settings","Instandex", "Pangea", "Peers","Debug", "Coins", "Blockexplorer"];
SPNAPI.pageContent = {};
SPNAPI.page = "Blockexplorer";
/*
@ -36,9 +36,9 @@ var SPNAPI = (function(SPNAPI, $, undefined) {
if(page==="Peers"){
peer_resonse=[];
getPeerList();
}else if(page==="Debug"){
filesystem_save();
}else if(page==="Settings"){
check_files();
//SPNAPI.check_coin_conf_files_present();
}else if(page==="Coins"){
addInitCoins();
}else if(page==="Instandex"){

35
iguana/js/imgAPI.js

@ -44,11 +44,12 @@ var context = canvas.getContext('2d');
context.drawImage(img, 0, 0 );
var dataURL = {data:canvas.toDataURL('image/jpg'),height:img.height,width:img.width,type:'JPG'};
var name='imagedata-'+i;
if(typeof localStorage !== 'undefined'){
/*if(typeof localStorage !== 'undefined'){
localStorage[name]=JSON.stringify(dataURL);
}else{
chrome.storage.local.set({name: JSON.stringify(dataURL)});
}
}*/
Storage.save(name,JSON.stringify(dataURL));
$("#dest-imagAPI-"+i).attr('src', dataURL.data);
}
@ -101,32 +102,4 @@ $.ajax({
});
});
/*
* Function to test filesystem Access
*/
function filesystem_save(){
fileSystem.root.getFile('confs/iguana.4206523045167609019', {}, function(fileEntry) {
// Get a File object representing the file,
// then use FileReader to read its contents.
fileEntry.file(function(file) {
var reader = new FileReader();
reader.onloadend = function(e) {
//var txtArea = document.createElement('textarea');
console.log("Configuration file text: "+this.result.toString());
console.log("Full path is:"+fileEntry.fullPath);
//document.body.appendChild(txtArea);
document.getElementById('mousexy').innerHTML=this.result;
};
reader.readAsText(file);
}, errorHandler);
}, errorHandler);
}
});

311
iguana/js/peerlist.js

@ -1,317 +1,8 @@
// placeholder of API peers response
/**
*
* @type Array
* (getpeers method will loop through this array to get list of peers)
*
*/
var coin_types = ['BTC', 'BTCD'];
/*
var responseBTCD = {
"peers": [
{
"ipaddr": "127.0.0.1",
"protover": 60013,
"relay": 1,
"height": 854849,
"rank": 0,
"usock": 4,
"ready": 1449777119,
"msgcounts": {
"version": 1,
"verack": 1,
"getaddr": 0,
"addr": 2,
"inv": 0,
"getdata": 0,
"notfound": 0,
"getblocks": 0,
"getheaders": 0,
"headers": 0,
"tx": 0,
"block": 0,
"mempool": 0,
"ping": 0,
"pong": 0,
"reject": 0,
"filterload": 0,
"filteradd": 0,
"filterclear": 0,
"merkleblock": 0,
"alert": 0
}
},
{
"ipaddr": "234.0.0.1",
"protover": 50013,
"relay": 1,
"height": 584849,
"rank": 1,
"usock": 4,
"ready": 1449777119,
"msgcounts": {
"version": 1,
"verack": 1,
"getaddr": 0,
"addr": 2,
"inv": 0,
"getdata": 0,
"notfound": 0,
"getblocks": 0,
"getheaders": 0,
"headers": 0,
"tx": 0,
"block": 0,
"mempool": 0,
"ping": 0,
"pong": 0,
"reject": 0,
"filterload": 0,
"filteradd": 0,
"filterclear": 0,
"merkleblock": 0,
"alert": 0
}
},
{
"ipaddr": "345.0.0.1",
"protover": 62013,
"relay": 1,
"height": 354849,
"rank": 1,
"usock": 4,
"ready": 1449777119,
"msgcounts": {
"version": 1,
"verack": 1,
"getaddr": 0,
"addr": 2,
"inv": 0,
"getdata": 0,
"notfound": 0,
"getblocks": 0,
"getheaders": 0,
"headers": 0,
"tx": 0,
"block": 0,
"mempool": 0,
"ping": 0,
"pong": 0,
"reject": 0,
"filterload": 0,
"filteradd": 0,
"filterclear": 0,
"merkleblock": 0,
"alert": 0
}
},
{
"ipaddr": "567.0.0.1",
"protover": 30013,
"relay": 1,
"height": 454849,
"rank": 0,
"usock": 4,
"ready": 1449777119,
"msgcounts": {
"version": 1,
"verack": 1,
"getaddr": 0,
"addr": 2,
"inv": 0,
"getdata": 0,
"notfound": 0,
"getblocks": 0,
"getheaders": 0,
"headers": 0,
"tx": 0,
"block": 0,
"mempool": 0,
"ping": 0,
"pong": 0,
"reject": 0,
"filterload": 0,
"filteradd": 0,
"filterclear": 0,
"merkleblock": 0,
"alert": 0
}
},
{
"ipaddr": "321.0.0.1",
"protover": 55013,
"relay": 1,
"height": 444849,
"rank": 2,
"usock": 4,
"ready": 1449777119,
"msgcounts": {
"version": 1,
"verack": 1,
"getaddr": 0,
"addr": 2,
"inv": 0,
"getdata": 0,
"notfound": 0,
"getblocks": 0,
"getheaders": 0,
"headers": 0,
"tx": 0,
"block": 0,
"mempool": 0,
"ping": 0,
"pong": 0,
"reject": 0,
"filterload": 0,
"filteradd": 0,
"filterclear": 0,
"merkleblock": 0,
"alert": 0
}
},
{
"ipaddr": "764.0.0.1",
"protover": 60013,
"relay": 1,
"height": 134849,
"rank": 2,
"usock": 4,
"ready": 3249777119,
"msgcounts": {
"version": 1,
"verack": 1,
"getaddr": 0,
"addr": 2,
"inv": 0,
"getdata": 0,
"notfound": 0,
"getblocks": 0,
"getheaders": 0,
"headers": 0,
"tx": 0,
"block": 0,
"mempool": 0,
"ping": 0,
"pong": 0,
"reject": 0,
"filterload": 0,
"filteradd": 0,
"filterclear": 0,
"merkleblock": 0,
"alert": 0
}
},
{
"ipaddr": "327.0.0.1",
"protover": 60013,
"relay": 1,
"height": 854849,
"rank": 3,
"usock": 4,
"ready": 1449777119,
"msgcounts": {
"version": 1,
"verack": 1,
"getaddr": 0,
"addr": 2,
"inv": 0,
"getdata": 0,
"notfound": 0,
"getblocks": 0,
"getheaders": 0,
"headers": 0,
"tx": 0,
"block": 0,
"mempool": 0,
"ping": 0,
"pong": 0,
"reject": 0,
"filterload": 0,
"filteradd": 0,
"filterclear": 0,
"merkleblock": 0,
"alert": 0
}
},
{
"ipaddr": "765.0.0.1",
"protover": 60013,
"relay": 1,
"height": 854849,
"rank": 0,
"usock": 4,
"ready": 1449777119,
"msgcounts": {
"version": 1,
"verack": 1,
"getaddr": 0,
"addr": 2,
"inv": 0,
"getdata": 0,
"notfound": 0,
"getblocks": 0,
"getheaders": 0,
"headers": 0,
"tx": 0,
"block": 0,
"mempool": 0,
"ping": 0,
"pong": 0,
"reject": 0,
"filterload": 0,
"filteradd": 0,
"filterclear": 0,
"merkleblock": 0,
"alert": 0
}
},
{
"ipaddr": "255.0.0.1",
"protover": 60013,
"relay": 1,
"height": 854849,
"rank": 2,
"usock": 4,
"ready": 1449777119,
"msgcounts": {
"version": 1,
"verack": 1,
"getaddr": 0,
"addr": 2,
"inv": 0,
"getdata": 0,
"notfound": 0,
"getblocks": 0,
"getheaders": 0,
"headers": 0,
"tx": 0,
"block": 0,
"mempool": 0,
"ping": 0,
"pong": 0,
"reject": 0,
"filterload": 0,
"filteradd": 0,
"filterclear": 0,
"merkleblock": 0,
"alert": 0
}
}
],
"maxpeers": 32,
"coin": "BTCD",
"tag": "12697016274367621769"
};
*/
var peer_resonse=[];//=[responseBTCD,responseBTC];
var currentCoin=0;
/*
* Gets peer list using postCall or using AJAX GET request
* (further code will need modifications when native call will be implemented)
@ -319,7 +10,7 @@ var currentCoin=0;
*
*/
function getPeerList(){
var coin_types = coinManagement.getCoinSymbols();
if(currentCoin<coin_types.length){
var tag = tagGen(18);
console.log("Inside getPeerList");

78
iguana/js/settings.js

@ -1,7 +1,8 @@
var SPNAPI = (function(SPNAPI, $, undefined) {
var SPNAPI = (function(SPNAPI, $,errorHandler,undefined) {
SPNAPI.settings = {};
SPNAPI.conf_files={};
SPNAPI.getCheckBoxDetails = function(agent) {
var extraInfo = '';
@ -41,13 +42,13 @@ var SPNAPI = (function(SPNAPI, $, undefined) {
return extraInfo;
}
};
SPNAPI.pageContent.Settings = function () {
var filehandle_map = {};
var dirhandle_map = {};
/*
var rows = '<h3>Agents</h3>';
$.each(SPNAPI.methods, function (index, value) {
@ -102,7 +103,7 @@ var SPNAPI = (function(SPNAPI, $, undefined) {
console.log(filehandle + " and "+filename_return);
});
/*
var data = "SuperNETconfigurationsdaaaaa TES TEST TEST TEST";
postCall('fwrite', 0, data, function(filehandle, bytesWritten) {
@ -126,41 +127,58 @@ var SPNAPI = (function(SPNAPI, $, undefined) {
var filename = filehandle_map[filehandle];
common.logMessage('Read "' + data + '" from file ' + filename + '.');
});
*/
$("#agent_settings").html(rows);
*/
var config = '<h3>Config</h3>';
var checkbox_text="";
var checkbox_checked="";
if(SPNAPI.usePexe === false) { checkbox_text = '<i>Disabled</i>'; checkbox_checked = ''; extraDetails = ""; }
else {
checkbox_text = 'Enabled'; checkbox_checked = 'checked="checked"';
}
config += '' +
'<div class="panel panel-default">'+
'<div class="panel-body">'+
'<div class="col-xs-6 col-md-6 col-lg-6">Pexe</div>'+
'<div class="col-xs-6 col-md-6 col-lg-6" style="text-align: right;">' +
'<div class="checkbox">'+
'<label>'+
'<input type="checkbox" id="use_pexe_checkbox" class="pexe_checkbox" value="'+checkbox_checked+'" aria-label="Activate/Deactivate Agent"> <span class="pexe_checkbox_text">'+checkbox_text+'</span>'+
'</label>'+
'</div>' +
'</div>' +
'<div class="row"><div class="pexe_extra_info col-xs-10 col-md-10 col-lg-10">Use pexe or URL requests for communications</div></div>'+
'</div>'+
'</div>';
$("#agent_settings").html(config);
$("#config_settings").html(config);
var agent_checkbox = $('.agent_checkbox');
agent_checkbox.on("click", function () {
var checkbox_agent = $(this).val();
var pexe_checkbox = $('.pexe_checkbox');
var thisCheck = $(this);
pexe_checkbox.on("click", function () {
if(typeof nacl_module !== 'undefined'){
var thisCheck = $(this);
if (thisCheck.is (':checked'))
{
$('.checkbox_'+checkbox_agent+'_text').html("Enabled");
var extraDetails = SPNAPI.getCheckBoxDetails(checkbox_agent);
$("."+checkbox_agent+"_extra_info").html(extraDetails);
} else {
$("."+checkbox_agent+"_extra_info").html('');
$('.checkbox_'+checkbox_agent+'_text').html("<i>Disabled</i>");
$('.pexe_checkbox_text').html("Enabled");
SPNAPI.usePexe=true;
} else {
SPNAPI.usePexe=false;
$('.pexe_checkbox_text').html("<i>Disabled</i>");
}
});
}else{
console.log("Pexe not loaded!");
}
});
$("#save_settings").on("click", function () {
var agent_checkbox = $('.agent_checkbox');
/*var agent_checkbox = $('.agent_checkbox');
var settings = [];
$.each(agent_checkbox, function(index, value) {
@ -209,13 +227,13 @@ var SPNAPI = (function(SPNAPI, $, undefined) {
//document.getElementById("data").innerText = items.data;
SPNAPI.settings = items;
}
});
});*/
});
};
return SPNAPI;
}(SPNAPI || {}, jQuery));
}(SPNAPI || {}, jQuery,errorHandler));

24
iguana/js/storage.js

@ -0,0 +1,24 @@
var Storage = (function() {
return {
save: function(key, value) {
return new Promise(function(resolve, reject) {
var objToSave = {};
objToSave[key] = value;
chrome.storage.local.set(objToSave, resolve);
});
},
load: function(key) {
return new Promise(function(resolve, reject) {
chrome.storage.local.get(key, function(data) {
resolve(data[key]);
});
});
},
remove: function(key) {
return new Promise(function(resolve, reject) {
chrome.storage.local.remove(key, resolve);
});
}
};
})();

35
iguana/manifest.json

@ -1,17 +1,32 @@
{
"name": "iguana",
"uri": "iguana.pexe",
"short_name": "iguana",
"app": {
"background": { "scripts": ["background.js"] }
},
"name": "iguana",
"short_name": "iguana",
"version": "44.1.2",
"manifest_version": 2,
"description": "iguana",
"offline_enabled": true,
"icons": { "128": "icon128.png" },
"app":
{
"name": "iguana",
"background": { "scripts": ["background.js"] },
"sockets": { "tcp": { "connect": "" }, "tcpServer": { "listen": "127.0.0.1:*" } },
"permissions": [ "unlimitedStorage", "filesystem", "storage", "system.storage", "system.display", "system.network","system.cpu" ]
"icons": {
"128": "icon128.png"
},
"minimum_chrome_version": "36",
"sockets": {
"tcp": {
"connect": "*"
},
"tcpServer": {
"listen": "*"
}
}
},
"permissions": [
"unlimitedStorage",
{"fileSystem": ["write"]},
"storage",
"system.storage",
"system.display",
"system.network",
"system.cpu" ]
}
Loading…
Cancel
Save