|
|
|
@ -9,8 +9,8 @@ const express = require("express"); // could be good to replace with c |
|
|
|
|
|
|
|
|
|
// Get port or default to 8082
|
|
|
|
|
const port = process.env.PORT || 8082; |
|
|
|
|
const protocol = 'https' |
|
|
|
|
const subclass = '192.168.4.' |
|
|
|
|
const protocol = process.env.PROTOCOL || 'https' |
|
|
|
|
const subclass = process.env.SUBCLASS || '192.168.4.' |
|
|
|
|
|
|
|
|
|
const publicKeyPath = path.resolve(process.env.HOME,'.ssh','id_rsa_offlineoctopus.pub') |
|
|
|
|
const publicKey = fs.readFileSync(publicKeyPath).toString().split(' ')[1] |
|
|
|
@ -251,7 +251,7 @@ app.get('/scan', (req, res) => { |
|
|
|
|
|
|
|
|
|
function scanpeers(){ |
|
|
|
|
foundPeers = [] |
|
|
|
|
for (let i=1;i<25;i++){ // async so blasting, gives very quick result for positives
|
|
|
|
|
for (let i=1;i<254;i++){ // async so blasting, gives very quick result for positives
|
|
|
|
|
let url=protocol+'://'+subclass+i+':'+port+'/available' |
|
|
|
|
let opt={rejectUnauthorized: false} |
|
|
|
|
https.get(url, opt, res => { |
|
|
|
@ -277,6 +277,7 @@ app.get('/sshconfig', (req, res) => { |
|
|
|
|
|
|
|
|
|
// note that stopping this process removes the mounts
|
|
|
|
|
function mountAll(){ |
|
|
|
|
// might have to scanpeers() first
|
|
|
|
|
getSshConfig().map( l => { |
|
|
|
|
let cs = 'sshfs ' + l.name + ':' |
|
|
|
|
if (l.custom) |
|
|
|
@ -285,7 +286,9 @@ function mountAll(){ |
|
|
|
|
cs+='/home/'+l.user |
|
|
|
|
return cs + ' ' + path.resolve(__dirname, "sshfsmounts", l.name) |
|
|
|
|
} ) |
|
|
|
|
.map( l => execSync(l)) |
|
|
|
|
//.map( l => execSync(l))
|
|
|
|
|
.map( l => console.log(l)) |
|
|
|
|
// will error out on non existing directories
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function getSshConfig(){ |
|
|
|
@ -381,3 +384,38 @@ const webServer = https.createServer(credentials, app); |
|
|
|
|
webServer.listen(port, () => { |
|
|
|
|
console.log("listening on "+protocol+"://localhost:" + port); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
// REPL testing
|
|
|
|
|
const readline = require("readline"); |
|
|
|
|
const rl = readline.createInterface({ |
|
|
|
|
input: process.stdin, |
|
|
|
|
output: process.stdout |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
let command = '' |
|
|
|
|
function getCommand(){ |
|
|
|
|
rl.question("REPL: ", function(command) { |
|
|
|
|
if (command == "close") { |
|
|
|
|
rl.close(); |
|
|
|
|
} else { |
|
|
|
|
console.log(command, eval(command) ) |
|
|
|
|
getCommand() |
|
|
|
|
// somehow switch to node REPL proper after?!
|
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
getCommand() |
|
|
|
|
|
|
|
|
|
function help(){ |
|
|
|
|
return ` |
|
|
|
|
help() |
|
|
|
|
execConfiguredCommand(cmdName) |
|
|
|
|
getSshConfig() |
|
|
|
|
mountAll() |
|
|
|
|
scanpeers()` |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
rl.on("close", function() { |
|
|
|
|
console.log("\ndone"); |
|
|
|
|
process.exit(0); |
|
|
|
|
}); |
|
|
|
|