Comparing version 1.5.0 to 1.5.1
@@ -0,1 +1,4 @@ | ||
v1.5.1 | ||
-- Split code into files | ||
-- Added input validation | ||
v1.5.0 | ||
@@ -2,0 +5,0 @@ -- Optimise code |
@@ -0,61 +1,60 @@ | ||
const colors = require('colors/safe'); | ||
module.exports = { | ||
helpMessage: ` | ||
Holesail Help | ||
${colors.cyan.bold('Holesail Help')} | ||
Description: | ||
Holesail is a tool that allows you to expose your local server over P2P network or connect to a Holesail server. | ||
${colors.bold('Description:')} | ||
${colors.white('Holesail is a tool that allows you to expose your local server over P2P network or connect to a Holesail server.')} | ||
Usage: | ||
${colors.bold('Usage:')} | ||
- Start a Holesail server: | ||
holesail --live <port> [--host <host>] [--connector <connector>] | ||
${colors.yellow('- Start a Holesail server:')} | ||
${colors.white(' holesail --live <port> [--host <host>] [--connector <connector>]')} | ||
- Connect to a Holesail server: | ||
holesail --connect <key|connector> [--port <port>] [--host <host>] | ||
${colors.yellow('- Connect to a Holesail server:')} | ||
${colors.white(' holesail --connect <key|connector> [--port <port>] [--host <host>]')} | ||
Options: | ||
${colors.bold('Options:')} | ||
- --help | ||
Displays this help message and exits. | ||
${colors.yellow('- --help')} | ||
${colors.white(' Displays this help message and exits.')} | ||
- --version | ||
Displays the version of the Holesail package and exits. | ||
${colors.yellow('- --version')} | ||
${colors.white(' Displays the version of the Holesail package and exits.')} | ||
- --live <port> | ||
Starts a Holesail server on the specified <port>. | ||
${colors.yellow('- --live <port>')} | ||
${colors.white(' Starts a Holesail server on the specified <port>.')} | ||
- --connect <key|connector> | ||
Connects to a Holesail server using the specified <key> or <connector>. | ||
${colors.yellow('- --connect <key|connector>')} | ||
${colors.white(' Connects to a Holesail server using the specified <key> or <connector>.')} | ||
- --port <port> | ||
Specifies the port number for the server or client connection. | ||
Default: 8989. | ||
${colors.yellow('- --port <port>')} | ||
${colors.white(' Specifies the port number for the server or client connection.\n Default: 8989.')} | ||
- --host <host> | ||
Specifies the host address for the server or client connection. | ||
Default: 127.0.0.1. | ||
${colors.yellow('- --host <host>')} | ||
${colors.white(' Specifies the host address for the server or client connection.\n Default: 127.0.0.1.')} | ||
- --connector <connector> | ||
Provides a custom connector for the server or client connection. | ||
If the connector length is 64, it is treated as a key. Otherwise, a key is created from the connector. | ||
${colors.yellow('- --connector <connector>')} | ||
${colors.white(' Provides a custom connector for the server or client connection.\n If the connector length is 64, it is treated as a key. Otherwise, a key is created from the connector.')} | ||
Examples: | ||
${colors.bold('Examples:')} | ||
- Start a Holesail server on port 3000 with default host and no connector: | ||
holesail --live 3000 | ||
${colors.yellow('- Start a Holesail server on port 3000 with default host and no connector:')} | ||
${colors.white(' holesail --live 3000')} | ||
- Start a Holesail server on port 3000 with a custom host and connector: | ||
holesail --live 3000 --host 192.168.1.1 --connector myCustomConnector | ||
${colors.yellow('- Start a Holesail server on port 3000 with a custom host and connector:')} | ||
${colors.white(' holesail --live 3000 --host 192.168.1.1 --connector myCustomConnector')} | ||
- Connect to a Holesail server with a specified key and default port: | ||
holesail 651daf65e3892d9ca8caa3237194612f460843f522e9b505975e9c840d2158a2 | ||
${colors.yellow('- Connect to a Holesail server with a specified key and default port:')} | ||
${colors.white(' holesail 651daf65e3892d9ca8caa3237194612f460843f522e9b505975e9c840d2158a2')} | ||
- Connect to a Holesail server with a specified connector and custom port: | ||
holesail myCustomConnector --port 8080 | ||
${colors.yellow('- Connect to a Holesail server with a specified connector and custom port:')} | ||
${colors.white(' holesail myCustomConnector --port 8080')} | ||
Notes: | ||
${colors.bold('Notes:')} | ||
- Treat connectors like SSH keys. Do not share them with anyone you do not trust. | ||
- Public keys should be treated like domain names on public servers. If there is any private information, it is your responsibility to protect it using passwords or connectors. | ||
`, | ||
${colors.white('- Treat connectors like SSH keys. Do not share them with anyone you do not trust.')} | ||
${colors.white('- Public keys should be treated like domain names on public servers. If there is any private information, it is your responsibility to protect it using passwords or connectors.')} | ||
`, | ||
@@ -65,2 +64,2 @@ printHelp: function(helpMessage) { | ||
} | ||
} | ||
}; |
187
index.js
#!/usr/bin/env node | ||
const DHT = require('holesail-server') //require module to start server on local port | ||
const goodbye = require('graceful-goodbye') | ||
const HyperDHT = require('hyperdht') | ||
const argv = require('minimist')(process.argv.slice(2)) //required to parse cli arguments | ||
const b4a = require('b4a') | ||
const {createHash} = require('node:crypto'); //for connectors | ||
const argv = require('minimist')(process.argv.slice(2)); //required to parse cli arguments | ||
const goodbye = require('graceful-goodbye'); | ||
const pkg = require('./package.json'); //holds info about current package | ||
const boxConsole = require('cli-box'); | ||
const help = require('./includes/help.js'); | ||
const Client = require('./includes/client.js'); | ||
const Server = require('./includes/server.js'); | ||
const {ValidateInput} = require('./includes/validateInput.js'); | ||
var colors = require('colors/safe'); | ||
//validate every input and throw errors if incorrect input | ||
const validator = new ValidateInput(argv); | ||
//splitting into files | ||
const help = require('./includes/help.js'); | ||
@@ -23,3 +22,3 @@ //setting up the command hierarchy | ||
help.printHelp(help.helpMessage); | ||
process.exit(-1) | ||
process.exit(-1); | ||
} | ||
@@ -33,155 +32,25 @@ | ||
const localServer = new DHT(); | ||
if (argv.live) { | ||
// user sets the custom host address for the server or use 127.0.0.1 | ||
if (argv.host) { | ||
host = argv.host | ||
} else { | ||
host = '127.0.0.1' | ||
} | ||
//if the connector length is 64 consider it as a seed or else create a seed from the connector | ||
//this lets the user pair with strings instead of long seeds | ||
if (argv.connector) { | ||
if (argv.connector.length === 64) { | ||
connector = argv.connector; | ||
isConnectorSet = false; | ||
} else { | ||
connector = createHash('sha256').update(argv.connector.toString()).digest('hex'); | ||
isConnectorSet = true; | ||
} | ||
} else { | ||
connector = null; | ||
isConnectorSet = false; | ||
} | ||
localServer.serve({port: argv.live, address: host, buffSeed: connector, secure: isConnectorSet}, () => { | ||
if (isConnectorSet) { | ||
var box = boxConsole("100x10", { | ||
text: colors.cyan.underline.bold("Holesail Server Started") + " ⛵️" + "\n" + | ||
colors.magenta("Connection Mode: ") + colors.cyan("Super Secret connector") + "\n" + | ||
colors.magenta(`Holesail is now listening on `) + `${host}:` + argv.live + "\n" + | ||
"Connect with connector: " + colors.white(`${argv.connector}`) + "\n" + | ||
colors.gray(`Public key is: ${localServer.getPublicKey()}`) + "\n" + | ||
colors.gray(` NOTE: TREAT CONNECTORS HOW YOU WOULD TREAT SSH KEY, DO NOT SHARE IT WITH ANYONE YOU DO NOT TRUST `), | ||
autoEOL: true, | ||
vAlign: "middle", | ||
hAlign: "middle", | ||
stretch: true | ||
} | ||
); | ||
console.log(box) | ||
} else { | ||
var box = boxConsole("100x10", { | ||
text: colors.cyan.underline.bold("Holesail Server Started") + " ⛵️" + "\n" + | ||
colors.magenta("Connection Mode: ") + colors.yellow("Publicly Sharable Key \n") + | ||
colors.magenta(`Holesail is now listening on `) + `${host}:` + argv.live + "\n" + | ||
"Connect with key: " + colors.white(`${localServer.getPublicKey()}`) + "\n" + | ||
colors.gray(` NOTICE: TREAT PUBLIC KEYS LIKE YOU WOULD TREAT A DOMAIN NAME ON PUBLIC SERVER, IF THERE IS ANYTHING PRIVATE ON IT, IT IS YOUR RESPONSIBILITY TO PASSWORD PROTECT IT OR USE CONNECTORS \n`), | ||
autoEOL: true, | ||
vAlign: "middle", | ||
hAlign: "middle", | ||
stretch: true | ||
} | ||
); | ||
console.log(box) | ||
} | ||
const options = { | ||
port: argv.live, | ||
host: argv.host, | ||
connector: argv.connector | ||
}; | ||
const server = new Server(options); | ||
server.start(); | ||
goodbye(async () => { | ||
await server.destroy(); | ||
}); | ||
} else if (argv.connect || argv['_'][0]) { | ||
//logic for holesail --connect key|connector and holesail key|connector | ||
//key has priority over connector | ||
let keyInput; | ||
if (argv.connect) { | ||
keyInput = argv.connect; | ||
} else { | ||
keyInput = argv['_'][0]; | ||
} | ||
//64 char long is treated as key, avoid 64 char long connectors | ||
if (keyInput.length === 64) { | ||
connector = keyInput; | ||
isConnectorSet = false; | ||
} else { | ||
connector = createHash('sha256').update(keyInput.toString()).digest('hex'); | ||
const seed = Buffer.from(connector, 'hex'); | ||
//the keypair here is not a reference to the function above | ||
connector = b4a.toString(seed, 'hex'); | ||
isConnectorSet = true; | ||
} | ||
if (!argv.port) { | ||
port = 8989 | ||
} else { | ||
port = argv.port | ||
} | ||
//--host | ||
if (argv.host) { | ||
host = argv.host | ||
} else { | ||
host = '127.0.0.1' | ||
} | ||
const holesailClient = require('holesail-client') | ||
var pubClient; | ||
if (isConnectorSet) { | ||
pubClient = new holesailClient(connector, "secure"); | ||
} else { | ||
pubClient = new holesailClient(connector); | ||
} | ||
pubClient.connect({port: port, address: host}, () => { | ||
if (isConnectorSet) { | ||
var box = boxConsole("100x10", { | ||
text: colors.cyan.underline.bold("Holesail Client Started") + " ⛵️" + "\n" + | ||
colors.magenta("Connection Mode: ") + colors.green("Super Secret Connector") + "\n" + | ||
colors.magenta(`Access application on http://${host}:${port}/`) + "\n" + | ||
"Connected to Secret Connector: " + colors.white(keyInput) + "\n" + | ||
colors.gray(`Public key: ${connector}`) + "\n" + | ||
colors.gray(` NOTE: TREAT CONNECTORS HOW YOU WOULD TREAT SSH KEY, DO NOT SHARE IT WITH ANYONE YOU DO NOT TRUST `), | ||
autoEOL: true, | ||
vAlign: "middle", | ||
hAlign: "middle", | ||
stretch: true | ||
} | ||
); | ||
console.log(box) | ||
} else { | ||
var box = boxConsole("100x10", { | ||
text: colors.cyan.underline.bold("Holesail Client Started") + " ⛵️" + "\n" + | ||
colors.magenta("Connection Mode: ") + colors.yellow("Publicly Sharable Key") + "\n" + | ||
colors.magenta(`Access application on http://${host}:${port}/`) + "\n" + | ||
colors.gray(`Public key: ${connector}`) + "\n" + | ||
colors.gray(` NOTICE: TREAT PUBLIC KEYS LIKE YOU WOULD TREAT A DOMAIN NAME ON PUBLIC SERVER, IF THERE IS ANYTHING PRIVATE ON IT, IT IS YOUR RESPONSIBILITY TO PASSWORD PROTECT IT OR USE CONNECTORS `), | ||
autoEOL: true, | ||
vAlign: "middle", | ||
hAlign: "middle", | ||
stretch: true | ||
} | ||
); | ||
console.log(box) | ||
} | ||
} | ||
) | ||
const keyInput = argv.connect || argv['_'][0]; | ||
const options = { | ||
port: argv.port || 8989, | ||
host: argv.host || '127.0.0.1' | ||
}; | ||
const client = new Client(keyInput, options); | ||
client.start(); | ||
} else { | ||
help.printHelp(help.helpMessage); | ||
process.exit(-1) | ||
console.log(colors.red(`Error: Invalid or Incorrect arguments specified. See holesail --help for a list of all valid arguments`)); | ||
process.exit(2); | ||
} | ||
goodbye(async () => { | ||
await localServer.destroy() | ||
}) |
{ | ||
"name": "holesail", | ||
"version": "1.5.0", | ||
"version": "1.5.1", | ||
"description": "A P2P based node package to expose your local ports on the Holepunch protocol", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
18630
14
293
1