New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

buddy-tunnel

Package Overview
Dependencies
Maintainers
2
Versions
136
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

buddy-tunnel - npm Package Compare versions

Comparing version 1.0.8-dev to 1.0.9-dev

src/agent/manager.js

2

package.json
{
"name": "buddy-tunnel",
"preferGlobal": false,
"version": "1.0.8-dev",
"version": "1.0.9-dev",
"type": "module",

@@ -6,0 +6,0 @@ "license": "MIT",

@@ -1,103 +0,87 @@

import fetch from 'node-fetch';
import { Agent as HttpsAgent } from 'https';
import Cfg from '../cfg.js';
import Tunnel from '../tunnel.js';
import logger from '../logger.js';
import Agent from '../agent.js';
import { isService } from '../utils.js';
import {
ERR_FAILED_TO_CONNECT,
LOG_AGENT_REGISTERED,
LOG_GETTING_AGENT,
LOG_REGION_DETECTED,
LOG_REGISTERING_AGENT,
LOG_REGISTERING_TUNNEL,
LOG_REMOVING_TUNNEL,
LOG_TUNNEL_REGISTERED,
LOG_UNREGISTERING_AGENT
ERR_FAILED_TO_CONNECT_TO_AGENT,
ERR_NOT_FOUND,
ERR_SWW,
LOG_ERROR
} from '../texts.js';
import { WebSocket } from 'ws';
import AgentManager from '../agent/manager.js';
const TIMEOUT = 10000;
const makeRequest = async (host, path, body) => {
const openSocket = (path) => {
return new Promise((resolve, reject) => {
const config = AgentManager.getFileConfig();
if (!config || !config.port) {
reject(new Error(ERR_FAILED_TO_CONNECT_TO_AGENT));
return;
}
const ws = new WebSocket(`ws://localhost:${config.port}${path}`);
ws.on('error', () => {
reject(new Error(ERR_FAILED_TO_CONNECT_TO_AGENT));
});
ws.on('open', () => {
resolve(ws);
});
});
};
const makeRequest = async (path, body) => {
const config = AgentManager.getFileConfig();
if (!config || !config.port) {
throw new Error(ERR_FAILED_TO_CONNECT_TO_AGENT);
}
const c = new AbortController();
setTimeout(() => {
c.abort();
}, TIMEOUT);
const response = await fetch(`http://localhost:${config.port}${path}`, {
body: body ? JSON.stringify(body) : null,
headers: { 'Content-Type': 'application/json' },
method: 'POST',
signal: c.signal,
});
if (response.status === 404) {
throw new Error(ERR_NOT_FOUND);
}
if (response.status === 400) {
const data = await response.json();
throw new Error(data.message);
}
if (response.status !== 200) {
throw new Error(ERR_SWW);
}
let data;
try {
const c = new AbortController();
setTimeout(() => {
c.abort();
}, TIMEOUT);
if (isService() && /app\.local\.io/.test(host)) host = 'https://host.docker.internal';
const response = await fetch(`${host}${path}`, {
body: JSON.stringify(body),
headers: { 'Content-Type': 'application/json' },
method: 'POST',
signal: c.signal,
agent: new HttpsAgent({
rejectUnauthorized: false,
}),
});
data = await response.json();
} catch (err) {
throw new Error(ERR_FAILED_TO_CONNECT(host));
logger.error(LOG_ERROR);
logger.error(err);
throw new Error(ERR_FAILED_TO_CONNECT_TO_AGENT);
}
if (data.code !== 200) {
throw new Error(ERR_FAILED_TO_CONNECT(host));
}
return data.result;
return data;
};
class ApiAgentClass {
async register(service) {
const token = Cfg.getToken();
const host = Cfg.getTokenHost();
logger.info(LOG_REGISTERING_AGENT);
const r = await makeRequest(host, '/tunnel/agent/add', {
token,
service
});
logger.info(LOG_AGENT_REGISTERED(r.id));
logger.info(LOG_REGION_DETECTED(r.region));
Cfg.setRegionIfNotSet(r.region);
return new Agent(r.id, r.token, service);
async fetchStatus() {
return makeRequest('/status');
}
async unregister(id, token){
const host = Cfg.getTokenHost();
logger.info(LOG_UNREGISTERING_AGENT);
await makeRequest(host, '/tunnel/agent/remove', {
token,
id
});
return true;
async addTunnel(data){
return makeRequest('/tunnel/add', data);
}
async fetchAgent(id, token) {
const host = Cfg.getTokenHost();
logger.info(LOG_GETTING_AGENT);
const r = await makeRequest(host, '/tunnel/agent/fetch', {
token,
id
});
return new Agent(r.id, token, r.service);
async fetchTunnels() {
return makeRequest('/tunnels');
}
async addTunnel(agentId, token, prepared) {
logger.info(LOG_REGISTERING_TUNNEL);
const host = Cfg.getTokenHost();
const config = await makeRequest(host, '/tunnel/add', {
...prepared,
token,
agentId
async stopTunnel(nameId){
return makeRequest('/tunnel/stop', {
nameId
});
logger.info(LOG_TUNNEL_REGISTERED(config.id));
return new Tunnel(config);
}
async removeTunnel(id, token) {
logger.info(LOG_REMOVING_TUNNEL);
const host = Cfg.getTokenHost();
await makeRequest(host, '/tunnel/remove', {
id,
token
});
async socketTunnel(nameId) {
return openSocket(`/tunnel?nameId=${encodeURIComponent(nameId)}`);
}

@@ -104,0 +88,0 @@ }

@@ -6,3 +6,2 @@ import { Command } from 'commander';

import Cfg from '../cfg.js';
import ApiAgent from '../api/agent.js';
import Output from '../output.js';

@@ -30,2 +29,3 @@ import {

} from '../texts.js';
import ApiBuddy from '../api/buddy.js';

@@ -60,4 +60,4 @@ const getBasicCommandHttp = () => {

const prepared = Cfg.prepareTunnel(TUNNEL_HTTP, target, options, true);
const agent = await ApiAgent.register(false);
const tunnel = await ApiAgent.addTunnel(agent.id, agent.token, prepared);
const agent = await ApiBuddy.register(false);
const tunnel = await ApiBuddy.addTunnel(agent.id, agent.token, prepared);
agent.addTunnel(tunnel);

@@ -64,0 +64,0 @@ Output.tunnel(tunnel);

@@ -7,14 +7,14 @@ import {

import Docker from '../docker.js';
import Service from '../service.js';
import ApiService from '../api/service.js';
import AgentManager from '../agent/manager.js';
import ApiAgent from '../api/agent.js';
const commandPre = async (_, command) => {
command.hasDocker = await Docker.hasSupport();
command.serviceConfig = Service.getFileConfig();
command.isServiceRunning = false;
command.serviceStatus = null;
if (command.hasDocker && command.serviceConfig) {
command.isServiceRunning = await Docker.isRunning(command.serviceConfig.id);
command.agentConfig = AgentManager.getFileConfig();
command.isAgentRunning = false;
command.agentStatus = null;
if (command.hasDocker && command.agentConfig) {
command.isAgentRunning = await Docker.isRunning(command.agentConfig.id);
try {
command.serviceStatus = await ApiService.fetchStatus();
command.agentStatus = await ApiAgent.fetchStatus();
} catch {

@@ -35,9 +35,9 @@ // do nothing

const newCli = version !== command.latestVersion;
const newService = command.serviceStatus && command.serviceStatus.version !== command.latestVersion;
if (newCli && newService) {
Output.newCliServiceVersion(command.latestVersion);
const newAgent = command.agentStatus && command.agentStatus.version !== command.latestVersion;
if (newCli && newAgent) {
Output.newCliAgentVersion(command.latestVersion);
} else if (newCli) {
Output.newCliVersion(command.latestVersion);
} else if (newService) {
Output.newServiceVersion(command.latestVersion);
} else if (newAgent) {
Output.newAgentVersion(command.latestVersion);
}

@@ -44,0 +44,0 @@ };

import { Command } from 'commander';
import Cfg from '../cfg.js';
import Output from '../output.js';
import ApiAgent from '../api/agent.js';
import {

@@ -10,2 +9,3 @@ DESC_COMMAND_START,

} from '../texts.js';
import ApiBuddy from '../api/buddy.js';

@@ -20,4 +20,4 @@ const commandStart = new Command('start');

const prepared = Cfg.getTunnel(name);
const agent = await ApiAgent.register(false);
const tunnel = await ApiAgent.addTunnel(agent.id, agent.token, prepared);
const agent = await ApiBuddy.register(false);
const tunnel = await ApiBuddy.addTunnel(agent.id, agent.token, prepared);
agent.addTunnel(tunnel);

@@ -24,0 +24,0 @@ Output.tunnel(tunnel);

@@ -5,3 +5,2 @@ import { Command } from 'commander';

} from '../utils.js';
import ApiAgent from '../api/agent.js';
import Cfg from '../cfg.js';

@@ -18,2 +17,3 @@ import Output from '../output.js';

} from '../texts.js';
import ApiBuddy from '../api/buddy.js';

@@ -36,4 +36,4 @@ const getBasicCommandTcp = () => {

const prepared = Cfg.prepareTunnel(TUNNEL_TCP, target, options, true);
const agent = await ApiAgent.register(false);
const tunnel = await ApiAgent.addTunnel(agent.id, agent.token, prepared);
const agent = await ApiBuddy.register(false);
const tunnel = await ApiBuddy.addTunnel(agent.id, agent.token, prepared);
agent.addTunnel(tunnel);

@@ -40,0 +40,0 @@ Output.tunnel(tunnel);

@@ -5,3 +5,2 @@ import { Command } from 'commander';

} from '../utils.js';
import ApiAgent from '../api/agent.js';
import Cfg from '../cfg.js';

@@ -22,2 +21,3 @@ import Output from '../output.js';

} from '../texts.js';
import ApiBuddy from '../api/buddy.js';

@@ -44,4 +44,4 @@ const getBasicCommandTls = () => {

const prepared = Cfg.prepareTunnel(TUNNEL_TLS, target, options, true);
const agent = await ApiAgent.register(false);
const tunnel = await ApiAgent.addTunnel(agent.id, agent.token, prepared);
const agent = await ApiBuddy.register(false);
const tunnel = await ApiBuddy.addTunnel(agent.id, agent.token, prepared);
agent.addTunnel(tunnel);

@@ -48,0 +48,0 @@ Output.tunnel(tunnel);

import { exec } from 'child_process';
import Cfg from './cfg.js';
import os from 'os';
const NAME = 'buddy-tunnel-service';
const NAME = 'buddy-tunnel-agent';
const IMAGE = 'buddy/tunnel';

@@ -33,3 +34,3 @@

await this.stop(id);
await this.docker(`run -d --name="${this.getContainerName(id)}" --pull="always" --add-host="host.docker.internal:host-gateway" --restart="unless-stopped" -p "${port}:${port}" --volume="${Cfg.dir}:/root/.buddy-tunnel" "${IMAGE}:${version}"`);
await this.docker(`run -d --env="BUDDY_HOSTNAME=${os.hostname()}" --name="${this.getContainerName(id)}" --pull="always" --add-host="host.docker.internal:host-gateway" --restart="unless-stopped" -p "${port}:${port}" --volume="${Cfg.dir}:/root/.buddy-tunnel" "${IMAGE}:${version}"`);
return true;

@@ -36,0 +37,0 @@ } catch (err) {

import { Command } from 'commander';
import { isService } from './utils.js';
import { isInDocker } from './utils.js';
import commandConfig from './command/config.js';

@@ -9,7 +9,7 @@ import Output from './output.js';

import commandStart from './command/start.js';
import commandService from './command/service.js';
import commandAgent from './command/agent.js';
import logger from './logger.js';
import Service from './service.js';
import commandVersion from './command/version.js';
import commandPre from './command/pre.js';
import AgentManager from './agent/manager.js';

@@ -23,4 +23,4 @@ process.title = 'buddy-tunnel';

if (isService()) {
Service.start();
if (isInDocker()) {
AgentManager.start();
} else {

@@ -34,3 +34,3 @@ const program = new Command();

program.addCommand(commandStart);
program.addCommand(commandService);
program.addCommand(commandAgent);
program.addCommand(commandVersion);

@@ -37,0 +37,0 @@

@@ -6,3 +6,3 @@ import pino from 'pino';

getHomeDirectory,
isService
isInDocker
} from './utils.js';

@@ -16,3 +16,3 @@

const getDestination = () => {
if (isService()) return null;
if (isInDocker()) return null;
return pino.destination(logStream);

@@ -19,0 +19,0 @@ };

@@ -10,13 +10,13 @@ import TerminalKit from 'terminal-kit';

import { TUNNEL_IDENTIFIED_HTTP1 } from './tunnel/identification.js';
import ApiService from './api/service.js';
import OutputInteractiveTunnel from './output/interactive/tunnel.js';
import OutputNoninteractiveTunnel from './output/noninteractive/tunnel.js';
import OutputNoninteractiveServiceTunnels from './output/noninteractive/service/tunnels.js';
import OutputNoninteractiveConfigTunnel from './output/noninteractive/config/tunnel.js';
import OutputNoninteractiveConfigTunnels from './output/noninteractive/config/tunnels.js';
import {
TXT_NEW_CLI_SERVICE_VERSION,
TXT_NEW_CLI_VERSION,
TXT_NEW_SERVICE_VERSION
TXT_NEW_AGENT_VERSION,
TXT_NEW_CLI_AGENT_VERSION,
TXT_NEW_CLI_VERSION
} from './texts.js';
import ApiAgent from './api/agent.js';
import OutputNoninteractiveAgentTunnels from './output/noninteractive/agent/tunnels.js';

@@ -49,7 +49,7 @@ const terminal = TerminalKit.terminal;

static serviceTunnels() {
ApiService.fetchTunnels().catch((err) => {
static agentTunnels() {
ApiAgent.fetchTunnels().catch((err) => {
Output.exitError(err);
}).then((data) => {
const on = new OutputNoninteractiveServiceTunnels(terminal, data.tunnels);
const on = new OutputNoninteractiveAgentTunnels(terminal, data.tunnels);
on.start();

@@ -73,8 +73,8 @@ });

static newCliServiceVersion(version) {
terminal.gray(TXT_NEW_CLI_SERVICE_VERSION(version));
static newCliAgentVersion(version) {
terminal.gray(TXT_NEW_CLI_AGENT_VERSION(version));
}
static newServiceVersion(version) {
terminal.gray(TXT_NEW_SERVICE_VERSION(version));
static newAgentVersion(version) {
terminal.gray(TXT_NEW_AGENT_VERSION(version));
}

@@ -81,0 +81,0 @@

@@ -1,2 +0,2 @@

const ERR_SERVICE_NOT_REGISTERED = 'Service not registered. Exiting...';
const ERR_AGENT_NOT_REGISTERED = 'Agent not registered. Exiting...';
const ERR_TARGET_IS_NOT_VALID = (target) => `Target '${target}' is not a valid value`;

@@ -26,12 +26,12 @@ const ERR_TYPE_IS_NOT_VALID = (type) => `Type '${type}' is not a valid value`;

const ERR_TUNNEL_NOT_FOUND = (name) => `Tunnel '${name}' not found`;
const ERR_SERVICE_NOT_RUNNING = 'Service is not running';
const ERR_SERVICE_DOCKER_NOT_FOUND = 'Can\'t manage service. First install Docker and enable it for current user';
const ERR_SWW_SERVICE_STOPPING = 'Something went wrong while stopping service';
const ERR_SWW_SERVICE_STARTING = 'Something went wrong while starting service';
const ERR_SWW_SERVICE_ENABLING = 'Something went wrong while enabling service';
const ERR_SWW_SERVICE_DISABLING = 'Something went wrong while disabling service';
const ERR_SERVICE_ENABLE = 'Can\'t start service. Enable it first';
const ERR_AGENT_NOT_RUNNING = 'Agent is not running';
const ERR_AGENT_DOCKER_NOT_FOUND = 'Can\'t manage agent. First install Docker and enable it for current user';
const ERR_SWW_AGENT_STOPPING = 'Something went wrong while stopping agent';
const ERR_SWW_AGENT_STARTING = 'Something went wrong while starting agent';
const ERR_SWW_AGENT_ENABLING = 'Something went wrong while enabling agent';
const ERR_SWW_AGENT_DISABLING = 'Something went wrong while disabling agent';
const ERR_AGENT_ENABLE = 'Can\'t start agent. Enable it first';
const ERR_TUNNEL_ALREADY_EXISTS = 'Tunnel with that name already exists. Change name or use -f flag to overwrite it';
const ERR_FAILED_TO_CONNECT = (host) => `Failed to connect to '${host}'`;
const ERR_FAILED_TO_CONNECT_TO_SERVICE = 'Failed to connect to service';
const ERR_FAILED_TO_CONNECT_TO_AGENT = 'Failed to connect to agent';
const ERR_NOT_FOUND = 'Not found';

@@ -48,13 +48,13 @@ const ERR_SWW = 'Something went wrong';

const ERR_CONFIG_CORRUPTED = 'Config file is corrupted';
const ERR_SERVICE_STOPPED = 'Service is stopped';
const ERR_AGENT_STOPPED = 'Agent is stopped';
const SUC_SERVICE_STOPPED = 'Service stopped';
const SUC_SERVICE_STARTED = 'Service started';
const SUC_SERVICE_ALREADY_STOPPED = 'Service is already stopped';
const SUC_SERVICE_IS_RUNNING = 'Service is running';
const SUC_SERVICE_ALREADY_RUNNING = 'Service is already running';
const SUC_SERVICE_ENABLED = 'Service enabled';
const SUC_SERVICE_ALREADY_ENABLED = 'Service already enabled';
const SUC_SERVICE_DISABLED = 'Service disabled';
const SUC_SERVICE_ALREADY_DISABLED = 'Service already disabled';
const SUC_AGENT_STOPPED = 'Agent stopped';
const SUC_AGENT_STARTED = 'Agent started';
const SUC_AGENT_ALREADY_STOPPED = 'Agent is already stopped';
const SUC_AGENT_IS_RUNNING = 'Agent is running';
const SUC_AGENT_ALREADY_RUNNING = 'Agent is already running';
const SUC_AGENT_ENABLED = 'Agent enabled';
const SUC_AGENT_ALREADY_ENABLED = 'Agent already enabled';
const SUC_AGENT_DISABLED = 'Agent disabled';
const SUC_AGENT_ALREADY_DISABLED = 'Agent already disabled';
const SUC_TUNNEL_STARTED = (type, name) => `${type} tunnel '${name}' started`;

@@ -90,20 +90,20 @@ const SUC_TUNNEL_STOPPED = 'Tunnel stopped';

const DESC_COMMAND_CONFIG_SET = 'set configuration';
const DESC_COMMAND_SERVICE_TUNNEL_HTTP = 'start HTTP tunnel in service';
const DESC_COMMAND_SERVICE_TUNNEL_LIST = 'list tunnels in service';
const DESC_COMMAND_SERVICE_TUNNEL_START = 'start tunnel in service from config';
const DESC_COMMAND_SERVICE_TUNNEL_STATUS = 'status of tunnel in service';
const DESC_COMMAND_SERVICE_TUNNEL_STOP = 'stop tunnel in service';
const DESC_COMMAND_SERVICE_TUNNEL_TCP = 'start TCP tunnel in service';
const DESC_COMMAND_SERVICE_TUNNEL_TLS = 'start TLS tunnel in service';
const DESC_COMMAND_SERVICE_DISABLE = 'disable service';
const DESC_COMMAND_SERVICE_ENABLE = 'enable service';
const DESC_COMMAND_SERVICE_START = 'start service';
const DESC_COMMAND_SERVICE_STATUS = 'service status';
const DESC_COMMAND_SERVICE_STOP = 'stop service';
const DESC_COMMAND_SERVICE_TUNNEL = 'manage service tunnels';
const DESC_COMMAND_SERVICE_UPDATE = 'update service version';
const DESC_COMMAND_SERVICE_VERSION = 'service version';
const DESC_COMMAND_AGENT_TUNNEL_HTTP = 'start HTTP tunnel in agent';
const DESC_COMMAND_AGENT_TUNNEL_LIST = 'list tunnels in agent';
const DESC_COMMAND_AGENT_TUNNEL_START = 'start tunnel in agent from config';
const DESC_COMMAND_AGENT_TUNNEL_STATUS = 'status of tunnel in agent';
const DESC_COMMAND_AGENT_TUNNEL_STOP = 'stop tunnel in agent';
const DESC_COMMAND_AGENT_TUNNEL_TCP = 'start TCP tunnel in agent';
const DESC_COMMAND_AGENT_TUNNEL_TLS = 'start TLS tunnel in agent';
const DESC_COMMAND_AGENT_DISABLE = 'disable agent';
const DESC_COMMAND_AGENT_ENABLE = 'enable agent';
const DESC_COMMAND_AGENT_START = 'start agent';
const DESC_COMMAND_AGENT_STATUS = 'agent status';
const DESC_COMMAND_AGENT_STOP = 'stop agent';
const DESC_COMMAND_AGENT_TUNNEL = 'manage agent tunnels';
const DESC_COMMAND_AGENT_UPDATE = 'update agent version';
const DESC_COMMAND_AGENT_VERSION = 'agent version';
const DESC_COMMAND_CONFIG = 'manage configuration';
const DESC_COMMAND_HTTP = 'start HTTP tunnel';
const DESC_COMMAND_SERVICE = 'manage service';
const DESC_COMMAND_AGENT = 'manage agent';
const DESC_COMMAND_START = 'start tunnel from config';

@@ -114,6 +114,6 @@ const DESC_COMMAND_TCP = 'start TCP tunnel';

const TXT_NEW_CLI_VERSION = (version) => `There is a new CLI version (${version}). To update run:\n\`sudo npm i -g buddy-tunnel@${version}\`\n\n`;
const TXT_NEW_SERVICE_VERSION = (version) => `There is a new Service version (${version}). To update run:\n\`buddy-tunnel service update\`\n\n`;
const TXT_NEW_CLI_SERVICE_VERSION = (version) => `There is a new version (${version}). To update run:\n\`sudo npm i -g buddy-tunnel@${version}\`\n\nAfter that update the service:\n\`buddy-tunnel service update\`\n\n`;
const TXT_STOPPING_SERVICE = 'Stopping service...';
const TXT_STARTING_SERVICE = 'Starting service...';
const TXT_NEW_AGENT_VERSION = (version) => `There is a new agent version (${version}). To update run:\n\`buddy-tunnel agent update\`\n\n`;
const TXT_NEW_CLI_AGENT_VERSION = (version) => `There is a new version (${version}). To update run:\n\`sudo npm i -g buddy-tunnel@${version}\`\n\nAfter that update the agent:\n\`buddy-tunnel agent update\`\n\n`;
const TXT_STOPPING_AGENT = 'Stopping agent...';
const TXT_STARTING_AGENT = 'Starting agent...';

@@ -146,7 +146,7 @@ const OPTION_REGION = 'override default region ("eu", "us")';

const OPTION_NAME_ID = 'name or id of the tunnel';
const OPTION_VERSION = 'force service version';
const OPTION_SERVICE_ID = 'start existing agent service';
const OPTION_SERVICE_START = 'start service right away';
const OPTION_SERVICE_TOKEN = 'token to authorize existing agent service or token to add a new agent';
const OPTION_SERVICE_PORT = 'service api port';
const OPTION_AGENT_VERSION = 'force agent version';
const OPTION_AGENT_ID = 'start existing agent agent';
const OPTION_AGENT_START = 'start agent right away';
const OPTION_AGENT_TOKEN = 'token to authorize existing agent agent or token to add a new agent';
const OPTION_AGENT_PORT = 'agent api port';

@@ -172,5 +172,5 @@ const LOG_REGISTERING_AGENT = 'Registering agent...';

const LOG_REQUEST = (url) => `request: ${url}`;
const LOG_ERROR_STARTING_SERVICE_SERVER = 'Error while starting service server';
const LOG_SERVICE_SERVER_STARTED = 'Service server started';
const LOG_SERVICE_STARTED = 'Service started';
const LOG_ERROR_STARTING_AGENT_SERVER = 'Error while starting agent server';
const LOG_AGENT_SERVER_STARTED = 'Agent server started';
const LOG_AGENT_STARTED = 'Agent started';
const LOG_TUNNEL_CONNECTED = (id, port) => `Tunnel '${id}' connected. Forwarding port '${port}'`;

@@ -208,5 +208,5 @@ const LOG_TUNNEL_FAILED = (id) => `Tunnel '${id}' forwarding failed`;

LOG_TUNNEL_CONNECTED,
LOG_SERVICE_STARTED,
LOG_SERVICE_SERVER_STARTED,
LOG_ERROR_STARTING_SERVICE_SERVER,
LOG_AGENT_STARTED,
LOG_AGENT_SERVER_STARTED,
LOG_ERROR_STARTING_AGENT_SERVER,
LOG_REQUEST,

@@ -229,7 +229,7 @@ LOG_SSH_CONNECTION,

LOG_REGISTERING_AGENT,
OPTION_SERVICE_PORT,
OPTION_SERVICE_TOKEN,
OPTION_SERVICE_ID,
OPTION_SERVICE_START,
OPTION_VERSION,
OPTION_AGENT_PORT,
OPTION_AGENT_TOKEN,
OPTION_AGENT_ID,
OPTION_AGENT_START,
OPTION_AGENT_VERSION,
OPTION_NAME_ID,

@@ -264,20 +264,20 @@ OPTION_NAME,

DESC_COMMAND_START,
DESC_COMMAND_SERVICE,
DESC_COMMAND_AGENT,
DESC_COMMAND_HTTP,
DESC_COMMAND_CONFIG,
DESC_COMMAND_SERVICE_VERSION,
DESC_COMMAND_SERVICE_UPDATE,
DESC_COMMAND_SERVICE_TUNNEL,
DESC_COMMAND_SERVICE_STOP,
DESC_COMMAND_SERVICE_STATUS,
DESC_COMMAND_SERVICE_START,
DESC_COMMAND_SERVICE_ENABLE,
DESC_COMMAND_SERVICE_DISABLE,
DESC_COMMAND_SERVICE_TUNNEL_TLS,
DESC_COMMAND_SERVICE_TUNNEL_TCP,
DESC_COMMAND_SERVICE_TUNNEL_STOP,
DESC_COMMAND_SERVICE_TUNNEL_STATUS,
DESC_COMMAND_SERVICE_TUNNEL_START,
DESC_COMMAND_SERVICE_TUNNEL_LIST,
DESC_COMMAND_SERVICE_TUNNEL_HTTP,
DESC_COMMAND_AGENT_VERSION,
DESC_COMMAND_AGENT_UPDATE,
DESC_COMMAND_AGENT_TUNNEL,
DESC_COMMAND_AGENT_STOP,
DESC_COMMAND_AGENT_STATUS,
DESC_COMMAND_AGENT_START,
DESC_COMMAND_AGENT_ENABLE,
DESC_COMMAND_AGENT_DISABLE,
DESC_COMMAND_AGENT_TUNNEL_TLS,
DESC_COMMAND_AGENT_TUNNEL_TCP,
DESC_COMMAND_AGENT_TUNNEL_STOP,
DESC_COMMAND_AGENT_TUNNEL_STATUS,
DESC_COMMAND_AGENT_TUNNEL_START,
DESC_COMMAND_AGENT_TUNNEL_LIST,
DESC_COMMAND_AGENT_TUNNEL_HTTP,
DESC_COMMAND_CONFIG_SET,

@@ -305,3 +305,3 @@ DESC_COMMAND_CONFIG_REMOVE,

ERR_CANT_CREATE_DIR_IN_HOME,
ERR_SERVICE_STOPPED,
ERR_AGENT_STOPPED,
ERR_CONNECTION_ERROR,

@@ -313,3 +313,3 @@ ERR_CONNECTION_TIMEOUT,

ERR_NOT_FOUND,
ERR_FAILED_TO_CONNECT_TO_SERVICE,
ERR_FAILED_TO_CONNECT_TO_AGENT,
ERR_FAILED_TO_CONNECT,

@@ -326,20 +326,20 @@ AGENT_FETCH_RETRY,

SUC_TUNNEL_STARTED,
SUC_SERVICE_ENABLED,
SUC_SERVICE_ALREADY_ENABLED,
SUC_SERVICE_DISABLED,
SUC_SERVICE_ALREADY_DISABLED,
SUC_SERVICE_STARTED,
SUC_SERVICE_ALREADY_RUNNING,
SUC_SERVICE_IS_RUNNING,
SUC_SERVICE_STOPPED,
SUC_SERVICE_ALREADY_STOPPED,
SUC_AGENT_ENABLED,
SUC_AGENT_ALREADY_ENABLED,
SUC_AGENT_DISABLED,
SUC_AGENT_ALREADY_DISABLED,
SUC_AGENT_STARTED,
SUC_AGENT_ALREADY_RUNNING,
SUC_AGENT_IS_RUNNING,
SUC_AGENT_STOPPED,
SUC_AGENT_ALREADY_STOPPED,
ERR_TUNNEL_ALREADY_EXISTS,
ERR_SERVICE_NOT_REGISTERED,
ERR_AGENT_NOT_REGISTERED,
ERR_WRONG_KEY_CERT,
ERR_SWW_SERVICE_STOPPING,
ERR_SWW_SERVICE_STARTING,
ERR_SERVICE_ENABLE,
ERR_SWW_SERVICE_ENABLING,
ERR_SWW_SERVICE_DISABLING,
ERR_SERVICE_NOT_RUNNING,
ERR_SWW_AGENT_STOPPING,
ERR_SWW_AGENT_STARTING,
ERR_AGENT_ENABLE,
ERR_SWW_AGENT_ENABLING,
ERR_SWW_AGENT_DISABLING,
ERR_AGENT_NOT_RUNNING,
ERR_SUBDOMAIN_IS_NOT_VALID,

@@ -359,9 +359,9 @@ ERR_TUNNEL_NOT_FOUND,

ERR_BA_LOGIN_NOT_PROVIDED,
ERR_SERVICE_DOCKER_NOT_FOUND,
ERR_AGENT_DOCKER_NOT_FOUND,
ERR_FETCH_VERSION,
TXT_STOPPING_SERVICE,
TXT_STARTING_SERVICE,
TXT_STOPPING_AGENT,
TXT_STARTING_AGENT,
TXT_NEW_CLI_VERSION,
TXT_NEW_SERVICE_VERSION,
TXT_NEW_CLI_SERVICE_VERSION,
TXT_NEW_AGENT_VERSION,
TXT_NEW_CLI_AGENT_VERSION,
ERR_WHITELIST_IS_NOT_VALID,

@@ -368,0 +368,0 @@ ERR_USER_AGENT_IS_NOT_VALID,

import path, { resolve } from 'path';
import { fileURLToPath } from 'url';
import { readFileSync } from 'fs';
import { homedir } from 'os';
import os, { homedir } from 'os';
import { ERR_FETCH_VERSION } from './texts.js';

@@ -23,5 +23,5 @@

const SERVICE_STATUS_INITIALIZING = 'initializing';
const SERVICE_STATUS_FETCH_FAILED = 'fetch agent failed, retrying';
const SERVICE_STATUS_RUNNING = 'running';
const AGENT_STATUS_INITIALIZING = 'initializing';
const AGENT_STATUS_FETCH_FAILED = 'fetch agent failed, retrying';
const AGENT_STATUS_RUNNING = 'running';

@@ -39,7 +39,12 @@ let cachedVersion;

const isService = () => process.env.BUDDY_TUNNEL_SERVICE === '1';
const isInDocker = () => process.env.BUDDY_TUNNEL_DOCKER === '1';
const getHostname = () => {
if (isInDocker()) return process.env.BUDDY_HOSTNAME;
return os.hostname();
};
const getHomeDirectory = () => {
let r;
if (isService()) r = '/root';
if (isInDocker()) r = '/root';
else r = homedir();

@@ -93,3 +98,3 @@ return path.join(r, '.buddy-tunnel');

const getRealTargetHost = (target) => {
if (!isService()) return target;
if (!isInDocker()) return target;
switch (target) {

@@ -107,2 +112,3 @@ case '127.0.0.1':

getRootDir,
getHostname,
getVersion,

@@ -121,9 +127,9 @@ REGION_EU,

getLatestVersion,
isService,
isInDocker,
getHomeDirectory,
sleep,
getRealTargetHost,
SERVICE_STATUS_INITIALIZING,
SERVICE_STATUS_FETCH_FAILED,
SERVICE_STATUS_RUNNING
AGENT_STATUS_INITIALIZING,
AGENT_STATUS_FETCH_FAILED,
AGENT_STATUS_RUNNING
};

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc