diff --git a/client/chrome/content/options.js b/client/chrome/content/options.js index f20baad..97852ec 100644 --- a/client/chrome/content/options.js +++ b/client/chrome/content/options.js @@ -25,6 +25,224 @@ function getNotaryTree() { return document.getElementById('notaryTree'); } +function getWscriptPath() { + + if(Services.appinfo.OS == 'WINNT') { + var wscript_path = false; + + wscript_path = Components.classes['@mozilla.org/file/directory_service;1'].getService(Components.interfaces.nsIProperties).get("SysD", Components.interfaces.nsILocalFile); + wscript_path.append("wscript.exe"); + + return wscript_path.clone(); + } + + return false; +} + +function getDaemonsDirectory() { + var daemons = Components.classes['@mozilla.org/file/directory_service;1'].getService(Components.interfaces.nsIProperties).get("ProfD", Components.interfaces.nsILocalFile); + daemons.append("extensions"); + daemons.append("convergence@dot-bit.org"); // guid of extension + + daemons.append("daemons"); + + return daemons.clone(); +} + +function getNamecoindPath() { + var namecoind_path = getDaemonsDirectory(); + + namecoind_path.append("namecoind"); + + if (Services.appinfo.OS != 'WINNT') { + dump("Linux in use\n"); + namecoind_path.append("linux"); + namecoind_path.append("x64"); + namecoind_path.append("namecoind"); + } + else { + dump("Windows in use\n"); + namecoind_path.append("windows"); + namecoind_path.append("x64"); + namecoind_path.append("namecoind.exe"); + } + + if(! namecoind_path.exists()) { + dump("namecoind is missing!\n"); + } + + return namecoind_path.clone(); +} + +function getInvisibleNamecoindPath() { + var invisible_namecoind_path = getDaemonsDirectory(); + + invisible_namecoind_path.append("namecoind"); + + if (Services.appinfo.OS == 'WINNT') { + invisible_namecoind_path.append("windows"); + invisible_namecoind_path.append("x64"); + invisible_namecoind_path.append("invisible_namecoind.vbs"); + + return invisible_namecoind_path.clone(); + } + + return false; +} + +function getNmcontrolPath() { + var nmcontrol_path = getDaemonsDirectory(); + + nmcontrol_path.append("nmcontrol"); + + if (Services.appinfo.OS != 'WINNT') { + dump("Linux in use\n"); + nmcontrol_path.append("python"); + nmcontrol_path.append("cd_launcher.sh"); + } + else { + dump("Windows in use\n"); + nmcontrol_path.append("windows"); + nmcontrol_path.append("cd_launcher.bat"); + } + + if(! nmcontrol_path.exists()) { + dump("nmcontrol launch script is missing!\n"); + } + + return nmcontrol_path.clone(); +} + +function getInvisibleNmcontrolPath() { + var invisible_nmcontrol_path = getDaemonsDirectory(); + + invisible_nmcontrol_path.append("nmcontrol"); + + if (Services.appinfo.OS == 'WINNT') { + invisible_nmcontrol_path.append("windows"); + invisible_nmcontrol_path.append("invisible_nmcontrol.vbs"); + + return invisible_nmcontrol_path.clone(); + } + + return false; +} + +function getNamecoinConfStr() { + var namecoin_conf = getNmcontrolPath().parent.parent.clone().path; + + if (Services.appinfo.OS != 'WINNT') { + dump("Linux in use\n"); + namecoin_conf = namecoin_conf + '/namecoin.conf'; + } + else { + dump("Windows in use\n"); + namecoin_conf = namecoin_conf + '\\namecoin.conf'; + } + + return namecoin_conf; +} + +function getNamecoindProfileDirectoryStr() { + // Create the namecoind profile directory if it's not already there + Components.utils.import("resource://gre/modules/FileUtils.jsm"); + var namecoind_profile_dir = FileUtils.getDir("Home", [".convergence-namecoin"], true).path; + + return namecoind_profile_dir; +} + +function setNamecoindState(enabled) { + + var namecoind_path = getNamecoindPath(); + var namecoind_profile_dir = getNamecoindProfileDirectoryStr(); + + var process = Components.classes['@mozilla.org/process/util;1'].createInstance(Components.interfaces.nsIProcess); + + var proc_arguments = []; + + if (Services.appinfo.OS != 'WINNT') { + dump("Linux in use\n"); + + dump("namecoind path: " + namecoind_path.path + "\n"); + process.init(namecoind_path); + + proc_arguments= ['-datadir=' + namecoind_profile_dir + '/', '-server', '-rpcuser=convergence', '-rpcpassword=convergence', '-port=18834', '-rpcport=18835'] ; // command line arguments array + if(!enabled) { + proc_arguments.push('stop'); + } + } + else { + dump("Windows in use\n"); + + var wscript_path = getWscriptPath(); + var invisible_namecoind_path = getInvisibleNamecoindPath(); + + dump("namecoind path: " + wscript_path.path + "\n"); + process.init(wscript_path); + + proc_arguments= [invisible_namecoind_path.path, '\'' + namecoind_path.path + '\'' + ' -datadir=\'' + namecoind_profile_dir + '/\' -server -rpcuser=convergence -rpcpassword=convergence -port=18834 -rpcport=18835'] ; // command line arguments array + if(!enabled) { + proc_arguments[1] = proc_arguments[1] + ' stop'; + } + } + + dump("namecoind args: " + proc_arguments.join(" ") + "\n"); + process.run(false, proc_arguments, proc_arguments.length); + + if(enabled) { + dump("namecoind started.\n"); + } + else { + dump("namecoind stopped.\n"); + } +} + +function setNmcontrolState(enabled) { + + var nmcontrol_path = getNmcontrolPath(); + var namecoin_conf = getNamecoinConfStr(); + + var process = Components.classes['@mozilla.org/process/util;1'].createInstance(Components.interfaces.nsIProcess); + + var proc_arguments = []; + + if (Services.appinfo.OS != 'WINNT') { + dump("Linux in use\n"); + + dump("nmcontrol path: " + nmcontrol_path.path + "\n"); + process.init(nmcontrol_path); + + proc_arguments= [nmcontrol_path.parent.clone().path, 'python2 nmcontrol.py --daemon=0 --data.update.namecoin="' + namecoin_conf + '" --rpc.port=18836 --dns.port=18837 --http.port=18838'] ; // command line arguments array + if(!enabled) { + proc_arguments[1] = proc_arguments[1] + ' stop'; + } + } + else { + dump("Windows in use\n"); + + var wscript_path = getWscriptPath(); + var invisible_nmcontrol_path = getInvisibleNmcontrolPath(); + + dump("nmcontrol path: " + wscript_path.path + "\n"); + process.init(wscript_path); + + proc_arguments= [invisible_nmcontrol_path.path, '\'' + nmcontrol_path.path + '\' \'' + nmcontrol_path.parent.clone().path + '\' nmcontrol.exe --daemon=0 \'--data.update.namecoin=' + namecoin_conf + '\' \'--rpc.port=18836\' \'--dns.port=18837\' \'--http.port=18838\''] ; // command line arguments array + if(!enabled) { + proc_arguments[1] = proc_arguments[1] + ' stop'; + } + } + + dump("nmcontrol args: " + proc_arguments.join(" ") + "\n"); + process.run(false, proc_arguments, proc_arguments.length); + + if(enabled) { + dump("nmcontrol started.\n"); + } + else { + dump("nmcontrol stopped.\n"); + } +} + function onOptionsLoad() { convergence = Components.classes['@fraggod.net/convergence;1'].getService().wrappedJSObject; settingsManager = convergence.getSettingsManager(); @@ -64,220 +282,6 @@ function onOptionsSave() { settingsManager.setDaemonMode(document.getElementById('daemon-mode').selectedItem.value); settingsManager.setDaemonStop(document.getElementById("daemon-stop").checked); - // Start or stop the daemons according to user settings - if(settingsManager.getDaemonMode() == "namecoind-nmcontrol") { - - //var namecoind_path = __LOCATION__.parent.parent.clone(); - - var namecoind_path = Components.classes['@mozilla.org/file/directory_service;1'].getService(Components.interfaces.nsIProperties).get("ProfD", Components.interfaces.nsILocalFile); - namecoind_path.append("extensions"); - namecoind_path.append("convergence@dot-bit.org"); // guid of extension - - namecoind_path.append("daemons"); - namecoind_path.append("namecoind"); - - if (Services.appinfo.OS != 'WINNT') { - dump("Linux in use\n"); - namecoind_path.append("linux"); - namecoind_path.append("x64"); - namecoind_path.append("namecoind"); - } - else { - dump("Windows in use\n"); - namecoind_path.append("windows"); - namecoind_path.append("x64"); - namecoind_path.append("namecoind.exe"); - } - - dump("namecoind path: " + namecoind_path.path + "\n"); - dump("namecoind exists: " + namecoind_path.exists() + "\n"); - - if(namecoind_path.exists()) { - - // Create the namecoind profile directory if it's not already there - Components.utils.import("resource://gre/modules/FileUtils.jsm"); - var namecoind_profile_dir = FileUtils.getDir("Home", [".convergence-namecoin"], true).path; - - dump("namecoind profile dir: " + namecoind_profile_dir + "\n"); - - // Start namecoind - var process = Components.classes['@mozilla.org/process/util;1'].createInstance(Components.interfaces.nsIProcess); - process.init(namecoind_path); - if (Services.appinfo.OS != 'WINNT') { - dump("Linux in use\n"); - var arguments= ['-datadir=' + namecoind_profile_dir + '/', '-server', '-rpcuser=convergence', '-rpcpassword=convergence', '-rpcport=18835'] ; // command line arguments array - } - else { - dump("Windows in use\n"); - var arguments= ['-datadir=' + namecoind_profile_dir + '\\', '-server', '-rpcuser=convergence', '-rpcpassword=convergence', '-rpcport=18835'] ; // command line arguments array - } - process.run(false, arguments, arguments.length); - dump("namecoind started.\n"); - } - else { - dump("namecoind not found.\n"); - } - - var nmcontrol_path = Components.classes['@mozilla.org/file/directory_service;1'].getService(Components.interfaces.nsIProperties).get("ProfD", Components.interfaces.nsILocalFile); - nmcontrol_path.append("extensions"); - nmcontrol_path.append("convergence@dot-bit.org"); // guid of extension - - nmcontrol_path.append("daemons"); - nmcontrol_path.append("nmcontrol"); - - if (Services.appinfo.OS != 'WINNT') { - dump("Linux in use"); - nmcontrol_path.append("python"); - nmcontrol_path.append("cd_launcher.sh"); - } - else { - dump("Windows in use"); - nmcontrol_path.append("windows"); - nmcontrol_path.append("cd_launcher.bat"); - } - - dump("nmcontrol path: " + nmcontrol_path.path + "\n"); - dump("nmcontrol exists: " + nmcontrol_path.exists() + "\n"); - - if(nmcontrol_path.exists()) { - - // Create the namecoind profile directory if it's not already there - Components.utils.import("resource://gre/modules/FileUtils.jsm"); - var namecoin_conf = nmcontrol_path.parent.parent.clone().path; - if (Services.appinfo.OS != 'WINNT') { - dump("Linux in use\n"); - namecoin_conf = namecoin_conf + '/namecoin.conf'; - } - else { - dump("Windows in use\n"); - namecoin_conf = namecoin_conf + '\\namecoin.conf'; - } - - // Start nmcontrol - var process = Components.classes['@mozilla.org/process/util;1'].createInstance(Components.interfaces.nsIProcess); - process.init(nmcontrol_path); - if (Services.appinfo.OS != 'WINNT') { - dump("Linux in use\n"); - var arguments= [nmcontrol_path.parent.clone().path, './nmcontrol.py --daemon=0 --data.update.namecoin=' + namecoin_conf + ' --rpc.port=18836'] ; // command line arguments array - } - else { - dump("Windows in use\n"); - var arguments= [nmcontrol_path.parent.clone().path, 'nmcontrol.exe --daemon=0 --data.update.namecoin=' + namecoin_conf + ' --rpc.port=18836'] ; // command line arguments array - } - process.run(false, arguments, arguments.length); - dump("nmcontrol started.\n"); - } - else { - dump("nmcontrol not found.\n"); - } - - } - else { - //var namecoind_path = __LOCATION__.parent.parent.clone(); - - var namecoind_path = Components.classes['@mozilla.org/file/directory_service;1'].getService(Components.interfaces.nsIProperties).get("ProfD", Components.interfaces.nsILocalFile); - namecoind_path.append("extensions"); - namecoind_path.append("convergence@dot-bit.org"); // guid of extension - - namecoind_path.append("daemons"); - namecoind_path.append("namecoind"); - - if (Services.appinfo.OS != 'WINNT') { - dump("Linux in use\n"); - namecoind_path.append("linux"); - namecoind_path.append("x64"); - namecoind_path.append("namecoind"); - } - else { - dump("Windows in use\n"); - namecoind_path.append("windows"); - namecoind_path.append("x64"); - namecoind_path.append("namecoind.exe"); - } - - dump("namecoind path: " + namecoind_path.path + "\n"); - dump("namecoind exists: " + namecoind_path.exists() + "\n"); - - if(namecoind_path.exists()) { - - // Create the namecoind profile directory if it's not already there - Components.utils.import("resource://gre/modules/FileUtils.jsm"); - var namecoind_profile_dir = FileUtils.getDir("Home", [".convergence-namecoin"], true).path; - - dump("namecoind profile dir: " + namecoind_profile_dir + "\n"); - - // Stop namecoind - var process = Components.classes['@mozilla.org/process/util;1'].createInstance(Components.interfaces.nsIProcess); - process.init(namecoind_path); - if (Services.appinfo.OS != 'WINNT') { - dump("Linux in use\n"); - var arguments= ['-datadir=' + namecoind_profile_dir + '/', '-server', '-rpcuser=convergence', '-rpcpassword=convergence', '-rpcport=18835', 'stop'] ; // command line arguments array - } - else { - dump("Windows in use\n"); - var arguments= ['-datadir=' + namecoind_profile_dir + '\\', '-server', '-rpcuser=convergence', '-rpcpassword=convergence', '-rpcport=18835', 'stop'] ; // command line arguments array - } - process.run(false, arguments, arguments.length); - dump("namecoind stopped.\n"); - } - else { - dump("namecoind not found.\n"); - } - - var nmcontrol_path = Components.classes['@mozilla.org/file/directory_service;1'].getService(Components.interfaces.nsIProperties).get("ProfD", Components.interfaces.nsILocalFile); - nmcontrol_path.append("extensions"); - nmcontrol_path.append("convergence@dot-bit.org"); // guid of extension - - nmcontrol_path.append("daemons"); - nmcontrol_path.append("nmcontrol"); - - if (Services.appinfo.OS != 'WINNT') { - dump("Linux in use"); - nmcontrol_path.append("python"); - nmcontrol_path.append("cd_launcher.sh"); - } - else { - dump("Windows in use"); - nmcontrol_path.append("windows"); - nmcontrol_path.append("cd_launcher.bat"); - } - - dump("nmcontrol path: " + nmcontrol_path.path + "\n"); - dump("nmcontrol exists: " + nmcontrol_path.exists() + "\n"); - - if(nmcontrol_path.exists()) { - - // Create the namecoind profile directory if it's not already there - Components.utils.import("resource://gre/modules/FileUtils.jsm"); - var namecoin_conf = nmcontrol_path.parent.parent.clone().path; - if (Services.appinfo.OS != 'WINNT') { - dump("Linux in use\n"); - namecoin_conf = namecoin_conf + '/namecoin.conf'; - } - else { - dump("Windows in use\n"); - namecoin_conf = namecoin_conf + '\\namecoin.conf'; - } - - // Stop nmcontrol - var process = Components.classes['@mozilla.org/process/util;1'].createInstance(Components.interfaces.nsIProcess); - process.init(nmcontrol_path); - if (Services.appinfo.OS != 'WINNT') { - dump("Linux in use\n"); - var arguments= [nmcontrol_path.parent.clone().path, './nmcontrol.py --daemon=0 --data.update.namecoin=' + namecoin_conf + ' --rpc.port=18836 stop'] ; // command line arguments array - } - else { - dump("Windows in use\n"); - var arguments= [nmcontrol_path.parent.clone().path, 'nmcontrol.exe --daemon=0 --data.update.namecoin=' + namecoin_conf + ' --rpc.port=18836 stop'] ; // command line arguments array - } - process.run(false, arguments, arguments.length); - dump("nmcontrol stopped.\n"); - } - else { - dump("nmcontrol not found.\n"); - } - } - settingsManager.setNotaryList(notaries); settingsManager.savePreferences(); issuePreferencesChangedNotification(); @@ -750,6 +754,25 @@ function daemonModeCommand() { } +function applyDaemonsNow() { + var value = document.getElementById('daemon-mode').selectedItem.value; + + if(value == "namecoind-nmcontrol") { + //window.setTimeout(function() {setNamecoindState(true);}, 500); + //window.setTimeout(function() {setNmcontrolState(true);}, 5000); + + setNamecoindState(true); + setNmcontrolState(true); + } + else { + //window.setTimeout(function() {setNamecoindState(false);}, 500); + //window.setTimeout(function() {setNmcontrolState(false);}, 5000); + + setNamecoindState(false); + setNmcontrolState(false); + } +} + function updateNamecoindStatus(jsonData) { document.getElementById('namecoind-output').value = JSON.stringify(jsonData["result"]); @@ -758,8 +781,10 @@ function updateNamecoindStatus(jsonData) { function checkNamecoind() { - if(settingsManager.getDaemonMode() == "namecoind-nmcontrol") { + //if(settingsManager.getDaemonMode() == "namecoind-nmcontrol") { + if(document.getElementById('daemon-mode').selectedIndex == 1) { + document.getElementById('namecoind-output').value = "Loading..."; sendRequest('getinfo', [], null, updateNamecoindStatus); } diff --git a/client/chrome/content/options.xul b/client/chrome/content/options.xul index 8b4e9a5..3ca865a 100644 --- a/client/chrome/content/options.xul +++ b/client/chrome/content/options.xul @@ -5,7 +5,7 @@ title="FreeSpeechMe Preferences" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" xmlns:html="http://www.w3.org/1999/xhtml" - width="620" height="450" buttons="accept,cancel" onload="onOptionsLoad();" + width="620" height="600" buttons="accept,cancel" onload="onOptionsLoad();" ondialogaccept="return onOptionsSave();">