Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/renderer/lib/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ export const DefaultCompose: ComposeConfig = {
cap_add: ["NET_ADMIN"],
privileged: true,
ports: [
"8006:8006", // VNC Web Interface
"7148:7148", // Winboat Guest Server API
"8149:7149", // QEMU QMP Port
"3389:3389/tcp", // RDP
"3389:3389/udp", // RDP
"127.0.0.1:8006:8006", // VNC Web Interface
"127.0.0.1:7148:7148", // WinBoat Guest Server API
"127.0.0.1:8149:7149", // QEMU QMP Port
"127.0.0.1:3389:3389/tcp", // RDP
"127.0.0.1:3389:3389/udp", // RDP
],
stop_grace_period: "120s",
restart: RESTART_ON_FAILURE,
Expand Down
36 changes: 26 additions & 10 deletions src/renderer/utils/port.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,34 @@ export class ComposePortEntry extends String {
guestPort: number;
protocol: PortEntryProtocol = undefined;

constructor(entry: string) {
super(entry);
constructor(entry: string) {
super(entry);

// Supports both <hostPort>:<guestPort> and 127.0.0.1:<hostPort>:<guestPort>
const parts = entry.split(":");
let hostIp: string | null = null;
let hostPort: string;
let guestPort: string;

if (parts.length === 2) {
[hostPort, guestPort] = parts;
} else if (parts.length === 3) {
[hostIp, hostPort, guestPort] = parts;
} else {
throw new Error(`Invalid port entry format: ${entry}`);
}

// Compose port entries map a host port to a guest port in the following format: <hostport>:<guestport>/<protocol(can be omitted)>
// To parse out the host and guest ports, we first split the entry up using ":" as a separator. Now we can parse the host port just fine.
// To parse the guest port as well, we need to remove the optional protocol from the entry. To do this, we map over our substrings, and split by "/".
const portEntry = entry.split(":").map(x => x.split("/")[0]);
hostPort = hostPort.split("/")[0];
guestPort = guestPort.split("/")[0];

this.hostPort = Number.parseInt(hostPort);
this.guestPort = Number.parseInt(guestPort);
this.protocol = ComposePortEntry.parseProtocol(entry);

// Store hostIp if you want it later
(this as any).hostIp = hostIp;
}

this.hostPort = Number.parseInt(portEntry[0]);
this.guestPort = Number.parseInt(portEntry[1]);
this.protocol = ComposePortEntry.parseProtocol(entry);
}

// TODO: change how ComposePortEntry is initialized
static fromPorts(hostPort: number, guestPort: number, protocol?: PortEntryProtocol) {
Expand Down