Skip to content

Commit

Permalink
release 0.6.17
Browse files Browse the repository at this point in the history
  • Loading branch information
faulpeltz committed Oct 21, 2024
1 parent d7e1b28 commit fad8281
Show file tree
Hide file tree
Showing 9 changed files with 135 additions and 249 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# DerTunnel Changelog

## 0.6.17

- Fix Dockerfile build
- Upgrade deps

## 0.6.16

- Upgrade deps
Expand Down
1 change: 1 addition & 0 deletions docker/Dockerfile → Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ COPY ./dist/dertunnel-server.js .
EXPOSE 443/tcp
EXPOSE 53/udp

VOLUME [ "/dertunnel/data" ]
ENTRYPOINT ["node", "./dertunnel-server.js"]
331 changes: 95 additions & 236 deletions package-lock.json

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dertunnel",
"version": "0.6.16",
"version": "0.6.17",
"description": "A ngrok-style tunnel client/server",
"main": "index.js",
"scripts": {
Expand Down Expand Up @@ -29,13 +29,13 @@
"license": "MIT",
"devDependencies": {
"@types/dns2": "2.0.9",
"@types/express": "4.17.21",
"@types/express": "5.0.0",
"@types/jest": "29.5.13",
"@types/node": "20.16.13",
"@types/prompts": "~2.4.9",
"@typescript-eslint/eslint-plugin": "8.10.0",
"@typescript-eslint/parser": "8.10.0",
"@yao-pkg/pkg": "5.15.0",
"@yao-pkg/pkg": "5.16.1",
"esbuild": "0.24.0",
"esbuild-register": "3.6.0",
"eslint": "8.57.1",
Expand All @@ -54,6 +54,6 @@
"lru-cache": "11.0.1",
"nanoid": "5.0.7",
"prompts": "2.4.2",
"rate-limiter-flexible": "5.0.3"
"rate-limiter-flexible": "5.0.4"
}
}
12 changes: 11 additions & 1 deletion src/server/config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { existsSync } from "fs";
import fs from "fs/promises";

import { hashToken } from "../shared/hash";
import { assertArray, assertBool, assertHostname, assertNumber, assertString, assertUserName } from "../shared/validate";

Expand Down Expand Up @@ -138,4 +140,12 @@ export async function saveClientConfig(config: TunnelClientsConfig, configFile?:
await fs.rename(configFile, oldFile);
await fs.rename(tmpFile, configFile);
await fs.unlink(oldFile);
}
}

export async function createClientConfigIfNotExists(config: TunnelClientsConfig, configFile?: string): Promise<void> {
configFile ??= lastClientConfigFileName ?? DefaultClientConfigFileName;
if (!existsSync(configFile)) {
const text = JSON.stringify(config, undefined, 2);
await fs.writeFile(configFile, text);
}
}
8 changes: 7 additions & 1 deletion src/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import chalk from "chalk";
import { program } from "commander";
import { Version } from "../version";

import { isServerConfigAvailable, loadClientConfig, loadConfig, saveConfig } from "./config";
import {
createClientConfigIfNotExists, isServerConfigAvailable,
loadClientConfig, loadConfig, saveClientConfig, saveConfig
} from "./config";
import { startDnsServer } from "./dns-server";
import { startTunnelServer } from "./server";
import { performInitialSetup, resetAdminTokenAndPrint } from "./setup";
Expand All @@ -29,8 +32,11 @@ const log = console.log;

// initial setup only
if (cmdOpts.setup) {
// ask for server config
const conf = await performInitialSetup();
await saveConfig(conf, cmdOpts.serverconfig);
// init client config file if necessary
await createClientConfigIfNotExists({ clients: [] }, cmdOpts.clientconfig);
process.exit(0);
}

Expand Down
14 changes: 9 additions & 5 deletions src/server/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ export async function performInitialSetup(): Promise<TunnelServiceConfig> {
validate: v => HostnameValidator.test(v)
}, {
name: "port",
type: "number",
type: "text",
message: "TLS server listening port",
initial: 443,
initial: "443",
validate: isPortNumber
}, {
name: "enableLogging",
Expand All @@ -40,9 +40,9 @@ export async function performInitialSetup(): Promise<TunnelServiceConfig> {
initial: true
}, {
name: "dnsPort",
type: (_, values) => values.enableDns ? "number" : false,
type: (_, values) => values.enableDns ? "text" : false,
message: "DNS server listening port",
initial: 53,
initial: "53",
validate: isPortNumber
}, {
name: "dnsTargetHost",
Expand All @@ -62,9 +62,13 @@ export async function performInitialSetup(): Promise<TunnelServiceConfig> {
name: "acmeCertDir",
type: (_, values) => values.enableAcme && values.enableDns ? "text" : false,
message: "Local directory for caching ACME certificates (must be writable)",
initial: "./cert-data"
initial: "./data"
}], { onCancel: () => { cancelled = true; return false } }) as TunnelServiceConfig;

// HAXX prompts "nunber" type bug - no initial value
conf.dnsPort = Number.parseInt(conf.dnsPort as unknown as string);
conf.port = Number.parseInt(conf.port as unknown as string);

if (cancelled) {
throw new Error("Setup aborted by user");
}
Expand Down
3 changes: 2 additions & 1 deletion src/shared/validate.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
export const HostnameValidator = /^(([a-z0-9]|[a-z0-9][a-z0-9-]*[a-z0-9])\.)*([a-z0-9]|[a-z0-9][a-z0-9-]*[a-z0-9])$/i;
export const EndpointValidator = /^[a-z0-9][a-z0-9-]*[a-z0-9]$/i;

export const isPortNumber = function (v: unknown) { return typeof v === "number" && v > 0 && v < 0x10000 }
export const isPortNumber = function (v: unknown) { console.log("#PORT", v); return (typeof v === "number" && v > 0 && v < 0x10000) ||
typeof v === "string" && Number.parseInt(v) > 0 && Number.parseInt(v) < 0x10000 };

export function assertHostname(value: unknown, label: string): void {
if (typeof (value) !== "string" || !HostnameValidator.test(value)) {
Expand Down
2 changes: 1 addition & 1 deletion src/version.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// TODO get version from package json or git
export const Version = "0.6.16";
export const Version = "0.6.17";

0 comments on commit fad8281

Please sign in to comment.