diff --git a/.gitignore b/.gitignore index 9ce3266..d9768fe 100644 --- a/.gitignore +++ b/.gitignore @@ -28,3 +28,9 @@ _testmain.go # TLS cert/key files *.pem + +node_modules/ + +**/bootstrap.min.css +**/site.css +**/jquery-2.2.2.min.js diff --git a/paranoid-gui/README.md b/paranoid-gui/README.md new file mode 100644 index 0000000..75b52a7 --- /dev/null +++ b/paranoid-gui/README.md @@ -0,0 +1,22 @@ +# Paranoid GUI # + +## Preconditions ## +You must have [Node Webkit](http://nwjs.io/) installed. + +You also must have [Nodejs](https://nodejs.org/en/) including npm installed + +paranoid-cli must be installed and within your $PATH + + +## Build Instructions ## +Navigate into this directory inside a terminal and run the following commands. +``` +npm install +sh init.sh +``` + +## Running the GUI ## +After following the build instructions make sure you are still in the directory and run the following command: +``` +nw . +``` diff --git a/paranoid-gui/css/master.css b/paranoid-gui/css/master.css new file mode 100644 index 0000000..b7f204a --- /dev/null +++ b/paranoid-gui/css/master.css @@ -0,0 +1,135 @@ +@import url("http://fonts.googleapis.com/css?family=Open+Sans:400,300,300italic,400italic,600"); + +* { + margin: 0; + padding: 0; + box-sizing: border-box; +} + +body { + font-family: 'Open Sans'; +} + +a { + text-decoration: none; +} + +div#header { + width: 100%; + height: 50px; + background-color: #2c3e50; + margin: 0 auto; +} + +.logo { + float: left; + margin-top: 8px; +} + +.logo a{ + font-size: 1.6em; + color: #fff; + margin-left: 10px; +} + +.logo a span { + font-weight: 300; +} + +div#container { + width: 100%; + margin: 0 auto; +} + +.sidebar { + width: 250px; + height: -webkit-calc(100% - 50px); /* Chrome, Safari */ + background-color: #171717; + float: left; +} + +.content { + width: auto; + height: -webkit-calc(100% - 50px); /* Chrome, Safari */ + background-color: #95a5a6; + margin-left: 250px; + padding: 15px; + overflow-y: scroll; +} + +.devs { + width: 100%; + display: flex; + flex-direction: column; +} + +.content p { + color: #424242; + font-size: 0.7em; +} + +#badge { + float: right; +} + +#refreshButton { + float: right; +} + +ul#nav li{ + list-style: none; +} + +ul#nav li a{ + color: #ccc; + display: block; + padding: 10px; + font-size: 0.8em; + border-bottom: 1px solid #0A0A0A; + -webkit-transition: 0.2s; +} + +ul#nav li a:hover { + background-color: #030303; + color: #fff; + padding-left: 20px; +} + +ul#nav li a.selected { + padding-left: 30px; + font-weight: bold; +} + +div#box { + margin-top: 15px; +} + +div#box .box-top { + color: #fff; + text-shadow: 0px 0px 1px #000; + background-color: #2980b9; + padding: 5px; + padding-left: 15px; + font-weight: 500; + +} + +div#box .box-panel { + padding: 15px; + background-color: #fff; +} + +div#buttons { + padding-top: 15px; + display: flex; + flex-direction: row; + width: 100%; +} + +div#buttons.btn { + width: 33%; +} + +#refresh_bt { + padding: 100px; +} diff --git a/paranoid-gui/html/filesystem.html b/paranoid-gui/html/filesystem.html new file mode 100644 index 0000000..c1c412f --- /dev/null +++ b/paranoid-gui/html/filesystem.html @@ -0,0 +1,72 @@ +
+

FileSystem

+
+
+ +
+

Status Mounted +

+ +
+
+
Mountpoint
+
    +
  • Must be mounted to get mountpoint
  • +
+ +
+ +
+
Detailed status
+
    +
  • Must be mounted to get detailed status
  • +
+
+ +
+
Nodes
+
    +
  • Must be mounted to get node list
  • +
+
+
+ + + +
+
+ +
+

Mount your FileSystem

+
+ + + + + + + + + +
+
+
+ +
+

Attributes

+ +
+
+ +
+

Delete FileSystem

+ + + +
diff --git a/paranoid-gui/html/home.html b/paranoid-gui/html/home.html new file mode 100644 index 0000000..4adb9de --- /dev/null +++ b/paranoid-gui/html/home.html @@ -0,0 +1,19 @@ +

PFSD Status

+

running

+
+ +
+

Credits

+

Co-Ordinator

+ Stehpen Blott +
+

Developers

+
+ Mladen Kajic
+ Terry Bolt
+ Conor Griffin
+ Wojtek Bednarzak
+ Sean Healy +
+
+
Icons made by Freepik from www.flaticon.com is licensed by CC 3.0 BY
diff --git a/paranoid-gui/html/newFs.html b/paranoid-gui/html/newFs.html new file mode 100644 index 0000000..cb7f587 --- /dev/null +++ b/paranoid-gui/html/newFs.html @@ -0,0 +1,30 @@ +

Create a new filesystem

+ +
+ + + + + + + +
+ +
+ +
+ +
+ +

Cert Generation (ignore if unsecured)

+ +
+ + +
+ + +
+ + +
diff --git a/paranoid-gui/images/Conor_Griffin.jpg b/paranoid-gui/images/Conor_Griffin.jpg new file mode 100644 index 0000000..d23eaef Binary files /dev/null and b/paranoid-gui/images/Conor_Griffin.jpg differ diff --git a/paranoid-gui/images/Mladen_Kajic.jpg b/paranoid-gui/images/Mladen_Kajic.jpg new file mode 100644 index 0000000..8ee8925 Binary files /dev/null and b/paranoid-gui/images/Mladen_Kajic.jpg differ diff --git a/paranoid-gui/images/Sean_Healy.jpg b/paranoid-gui/images/Sean_Healy.jpg new file mode 100644 index 0000000..d717a27 Binary files /dev/null and b/paranoid-gui/images/Sean_Healy.jpg differ diff --git a/paranoid-gui/images/Stephen_Blott.jpg b/paranoid-gui/images/Stephen_Blott.jpg new file mode 100644 index 0000000..88687eb Binary files /dev/null and b/paranoid-gui/images/Stephen_Blott.jpg differ diff --git a/paranoid-gui/images/Terry_Bolt.jpg b/paranoid-gui/images/Terry_Bolt.jpg new file mode 100644 index 0000000..95cb74e Binary files /dev/null and b/paranoid-gui/images/Terry_Bolt.jpg differ diff --git a/paranoid-gui/images/Wojtek_Bednarzak.jpg b/paranoid-gui/images/Wojtek_Bednarzak.jpg new file mode 100644 index 0000000..30d8748 Binary files /dev/null and b/paranoid-gui/images/Wojtek_Bednarzak.jpg differ diff --git a/paranoid-gui/images/buildings.png b/paranoid-gui/images/buildings.png new file mode 100644 index 0000000..8725ab8 Binary files /dev/null and b/paranoid-gui/images/buildings.png differ diff --git a/paranoid-gui/images/circle.png b/paranoid-gui/images/circle.png new file mode 100644 index 0000000..b24d932 Binary files /dev/null and b/paranoid-gui/images/circle.png differ diff --git a/paranoid-gui/images/interface.png b/paranoid-gui/images/interface.png new file mode 100644 index 0000000..150b7fa Binary files /dev/null and b/paranoid-gui/images/interface.png differ diff --git a/paranoid-gui/images/interface_green.png b/paranoid-gui/images/interface_green.png new file mode 100644 index 0000000..e06e319 Binary files /dev/null and b/paranoid-gui/images/interface_green.png differ diff --git a/paranoid-gui/index.html b/paranoid-gui/index.html new file mode 100644 index 0000000..29a22d8 --- /dev/null +++ b/paranoid-gui/index.html @@ -0,0 +1,42 @@ + + + Paranoid Filesystems + + + + + + + + + + + + + +
+ + +
+
+
+ + + diff --git a/paranoid-gui/init.sh b/paranoid-gui/init.sh new file mode 100644 index 0000000..c4d7342 --- /dev/null +++ b/paranoid-gui/init.sh @@ -0,0 +1,10 @@ +echo "downloading bootstrap" +wget --quiet -O ./css/bootstrap.min.css http://maxcdn.bootstrapcdn.com/bootstrap/3.3.0/css/bootstrap.min.css + +echo "downloading bootflat" +wget --quiet -O ./css/site.css http://bootflat.github.io/css/site.css + +echo "downloading jquery" +wget --quiet -O ./scripts/jquery-2.2.2.min.js https://code.jquery.com/jquery-2.2.2.min.js + +echo "done." diff --git a/paranoid-gui/package.json b/paranoid-gui/package.json new file mode 100644 index 0000000..aeac826 --- /dev/null +++ b/paranoid-gui/package.json @@ -0,0 +1,14 @@ +{ + "name": "paranoid-gui", + "description": "Paranoid GUI", + "version": "1.0.0", + "main": "index.html", + "window": { + "toolbar": false, + "width": 1000, + "height": 700 + }, + "dependencies": { + "open": "0.0.5" + } +} diff --git a/paranoid-gui/scripts/filesystems.js b/paranoid-gui/scripts/filesystems.js new file mode 100644 index 0000000..6e5f596 --- /dev/null +++ b/paranoid-gui/scripts/filesystems.js @@ -0,0 +1,358 @@ +var path = require("path"); +var fs = require("fs"); + +function getUserHome() { + return process.env.HOME || process.env.USERPROFILE; +} + +function getFilesystems() { + var fileSystemsDir = path.join(getUserHome(), ".pfs", "filesystems"); + var fileNames = fs.readdirSync(fileSystemsDir); + var filesystems = []; + for (var i=0; imounted'); + $(".content #fsStatus #fsMountedLabel").addClass("label label-success"); + $(".content #mountUnmountButton").html("Unmount"); + $(".content #mountUnmountButton").attr("class", "btn btn-warning"); + $(".content #mountUnmountButton").attr("onClick", "mountUnmountButtonClicked(" + i + ")"); + $(".content #autoMountButton").hide(); + $(".content .onlyForMountedSection").show(); + $(".content #refreshButton").show(); + + getFilesystemStatus(fileSystem.name, function(s) { + $(".content #fsStatus #mountpoint").html(getFilesystemMountpoint(fileSystem.path)); + $(".content #fsStatus #clistatus").html(s); + }); + getFilesystemNodes(fileSystem.name, function(s) { + $(".content #fsStatus #nodes").html(s); + }); + + } else { + $(".content #fsStatus #fsMountedLabel").html('not mounted'); + $(".content #fsStatus #fsMountedLabel").addClass("label label-warning"); + $(".content #mountUnmountButton").html("Mount"); + $(".content #mountUnmountButton").attr("class", "btn btn-success"); + $(".content #mountUnmountButton").attr("onClick", "mountUnmountButtonClicked(" + i + ")"); + $(".content #autoMountButton").show(); + $(".content .onlyForMountedSection").hide(); + $(".content #refreshButton").hide(); + } + + // mount section + $(".content #fsMountSection #fsMountForm").submit(mountFS); + + // attributes section + if (!fileSystem.attributes.encrypted) { + $(".content #fsAttributes #fsAttributeEncrypted #badge").html('NO'); + $(".content #fsAttributes #fsAttributeEncrypted #badge").addClass("label label-danger"); + } + + if (fileSystem.attributes.networkoff) { + $(".content #fsAttributes #fsAttributeNetwork #badge").html('NO'); + $(".content #fsAttributes #fsAttributeNetwork #badge").addClass("label label-danger"); + } + + if (!fileSystem.attributes.keygenerated) { + $(".content #fsAttributes #fsAttributeKeygen #badge").html('NO'); + $(".content #fsAttributes #fsAttributeKeygen #badge").addClass("label label-danger"); + } + + $(".content #fsAttributes #fsAttributePool #badge").html('' + fileSystem.pool + ''); + $(".content #fsAttributes #fsAttributeUuid #badge").html('' + fileSystem.uuid + ''); + + // delete section + $(".content #fsDeleteSection #deleteButton").attr("onClick", 'deleteClicked($(".content #fsDeleteSection #nameCheckText").val(), ' + i + ');'); +} + +function newfs(form) { + var exec = require('child_process').exec; + var cmd = "paranoid-cli init "; + if (!form.secure.checked) { + cmd += "-u "; + } + if (!form.network.checked) { + cmd += "--networkoff "; + } + if (!form.encrypted.checked) { + cmd += "--unencrypted "; + } + if (form.cert.value !== "") { + cmd += "--cert " + form.cert.value + " "; + } + if (form.key.value !== "") { + cmd += "--key " + form.key.value + " "; + } + if (form.pool.value !== "") { + cmd += "--pool " + form.pool.value + " "; + } + cmd += form.name.value; + + var input = ""; + if (form.numDays.value !== null) { + input += form.numDays.value.toString() + "\n"; + } else { + input += "100\n"; + } + + if (form.organisation.value !== null) { + input += form.organisation.value; + } + input += "\n"; + + if (form.hostnames.value !== null) { + input += form.hostnames.value; + } + input += "\n"; + + var child = exec(cmd, function(error, stdout, stderr) { + if (error !== null) { + alert(error); + return; + } + + if (stderr !== "") { + alert(stderr); + } + + fileSystems = getFilesystems(); + loadSideBar(); + rowClicked(-1); + }); + child.stdin.write(input); +} + +function deleteClicked(val, i) { + var fileSystem = fileSystems[i]; + if (val != fileSystem.name) { + alert("Incorrect FileSystem name"); + } else { + deleteFs(i); + } +} + +function deleteFs(i) { + var exec = require('child_process').exec; + var cmd = "paranoid-cli delete " + fileSystems[i].name; + exec(cmd, function(error, stdout, stderr) { + var e = false; + if (error !== null) { + alert(error); + e = true; + } + if (stdout !== "") { + alert(stdout); + e = true; + } + if (e) { + return; + } + + fileSystems = getFilesystems(); + loadSideBar(); + rowClicked(-1); + }); +} + +function pathExists(filePath) { + var fs = require("fs"); + try { + fs.accessSync(filePath, fs.F_OK); + return true; + } catch(e) { + return false; + } +} + +function readFile(filePath) { + var fs = require("fs"); + return fs.readFileSync(filePath, "utf8"); +} + +function loadJsonFile(filePath) { + return JSON.parse(readFile(filePath)); +} + +function fileSystemIsMounted(fsName) { + var pidFile = path.join(getUserHome(), ".pfs", "filesystems", fsName, "meta", "pfsd.pid"); + + if (!pathExists(pidFile)) { + return false; + } else { + var pid = readFile(pidFile); + var execSync = require('child_process').execSync; + var cmd = "ps " + pid; + try { + var code = execSync(cmd); + return true; + } catch (e) { + alert(e); + return false; + } + } +} + +function mountUnmountButtonClicked(i){ + var fileSystem = fileSystems[i]; + if (fileSystem.mounted) { + unMountFs(i); + } else { + if (!$(".content #fsMountSection").is(":visible")) { + $(".content #fsMountSection").slideDown(200); + } else { + $(".content #fsMountSection").slideUp(200); + } + } +} + +function automountButtonClicked() { + var fileSystem = fileSystems[selected]; + + var exec = require('child_process').exec; + var cmd = "paranoid-cli automount -n " + fileSystem.name; + + exec(cmd, function(error, stdout, stderr) { + var e = false; + if (error !== null) { + alert(error); + e = true; + } + + if (stdout !== "") { + alert(stdout); + e = true; + } + + if (e) { + return; + } + + fileSystems = getFilesystems(); + loadSideBar(); + rowClicked(selected); + }); +} + +function unMountFs(i) { + var execSync = require('child_process').execSync; + var cmd = "paranoid-cli unmount " + fileSystems[i].name; + try { + var code = execSync(cmd); + fileSystems[i].mounted = false; + loadSideBar(); + rowClicked(i); + } catch (e) { + alert(e); + return false; + } +} + +function mountFS() { + var exec = require('child_process').exec; + var cmd = "paranoid-cli mount -n "; + + if($("#fsMountSection #fsMountForm #interface").val() !== "") { + cmd += "-i " + $("#fsMountSection #fsMountForm #interface").val() + " "; + } + + if($("#fsMountSection #fsMountForm #discovery").val() !== "") { + cmd += "-d " + $("#fsMountSection #fsMountForm #discovery").val() + " "; + } + + if($("#fsMountSection #fsMountForm #password").val() !== "") { + cmd += "--pool-password " + $("#fsMountSection #fsMountForm #password").val() + " "; + } + + cmd += fileSystems[selected].name + " " + $("#fsMountSection #fsMountForm #location").val(); + + exec(cmd, function(error, stdout, stderr) { + var e = false; + if (error !== null) { + alert(error); + e = true; + } + + if (stdout !== "") { + alert(stdout); + e = true; + } + + if (e) { + return; + } + + fileSystems = getFilesystems(); + loadSideBar(); + rowClicked(selected); + }); +} + +function getFilesystemStatus(fsName, callback) { + var exec = require("child_process").exec; + var cmd = "paranoid-cli status " + fsName; + + exec(cmd, function(error, stdout, stderr) { + if (error !== null) { + alert(error); + return; + } + + callback(stdout.replace("/n", "
")); + }); +} + +function getFilesystemNodes(fsName, callback) { + var exec = require("child_process").exec; + var cmd = "paranoid-cli list-nodes " + fsName; + + exec(cmd, function(error, stdout, stderr) { + if (error !== null) { + alert(error); + return; + } + + callback(stdout.replace("/n", "
")); + }); +} + +function getFilesystemMountpoint(fsPath) { + var mpPath = path.join(fsPath, "meta", "mountpoint"); + return readFile(mpPath); +} + +function refreshButtonClicked() { + drawFileSystem(selected); +} + +function openButtonPressed() { + var path = getFilesystemMountpoint(fileSystems[selected].path); + var gui = require("nw.gui"); + gui.Shell.showItemInFolder(path + "/."); +} diff --git a/paranoid-gui/scripts/home.js b/paranoid-gui/scripts/home.js new file mode 100644 index 0000000..48c7212 --- /dev/null +++ b/paranoid-gui/scripts/home.js @@ -0,0 +1,24 @@ +function setupHome() { + $(".content").load("html/home.html"); + pfsdRunning(function(running) { + if (running) { + $(".content #runningLabel").attr("class", "label label-success"); + $(".content #runningLabel").html("running"); + } else { + $(".content #runningLabel").attr("class", "label label-warning"); + $(".content #runningLabel").html("not running"); + } + }); +} + +function pfsdRunning(callback) { + var exec = require("child_process").exec; + var cmd = "pidof pfsd"; + + exec(cmd, function(error, stdout, stderr) { + if (error !== null) { + return callback(false); + } + callback(true); + }); +} diff --git a/paranoid-gui/scripts/nav.js b/paranoid-gui/scripts/nav.js new file mode 100644 index 0000000..4fa0d5a --- /dev/null +++ b/paranoid-gui/scripts/nav.js @@ -0,0 +1,53 @@ +var selected = -1; + +function loadSideBar() { + $("#nav").empty(); + var items = [ + ]; + + var starter = '
  • '; + if (item.mounted) { + entry += ' '; + } else { + entry += ' '; + } + entry += item.name + '
  • '; + items.push(entry); + }); + + var newFsRow = '
  • = fileSystems.length +1) { + i = -1; + } + selected = i; + if (i == -1) { + setupHome(); + } else if (i == fileSystems.length){ + $(".content").load("html/newFs.html"); + } else { + drawFileSystem(i); + } + loadSideBar(); +}