mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-26 10:21:52 +00:00
* add support for idmapped mounts to start-sdk * misc fixes * misc fixes * add default to textarea * fix iptables masquerade rule * fix textarea types * more fixes * better logging for rsync * fix tty size * fix wg conf generation for android * disable file mounts on dependencies * mostly there, some styling issues (#3069) * mostly there, some styling issues * fix: address comments (#3070) * fix: address comments * fix: fix * show SSL for any address with secure protocol and ssl added * better sorting and messaging --------- Co-authored-by: Alex Inkin <alexander@inkin.ru> * fixes for nextcloud * allow sidebar navigation during service state traansitions * wip: x-forwarded headers * implement x-forwarded-for proxy * lowercase domain names and fix warning popover bug * fix http2 websockets * fix websocket retry behavior * add arch filters to s9pk pack * use docker for start-cli install * add version range to package signer on registry * fix rcs < 0 * fix user information parsing * refactor service interface getters * disable idmaps * build fixes * update docker login action * streamline build * add start-cli workflow * rename * riscv64gc * fix ui packing * no default features on cli * make cli depend on GIT_HASH * more build fixes * more build fixes * interpolate arch within dockerfile * fix tests * add launch ui to service page plus other small improvements (#3075) * add launch ui to service page plus other small improvements * revert translation disable * add spinner to service list if service is health and loading * chore: some visual tune up * chore: update Taiga UI --------- Co-authored-by: waterplea <alexander@inkin.ru> * fix backups * feat: use arm hosted runners and don't fail when apt package does not exist (#3076) --------- Co-authored-by: Matt Hill <mattnine@protonmail.com> Co-authored-by: Shadowy Super Coder <musashidisciple@proton.me> Co-authored-by: Matt Hill <MattDHill@users.noreply.github.com> Co-authored-by: Alex Inkin <alexander@inkin.ru> Co-authored-by: Remco Ros <remcoros@live.nl>
185 lines
4.7 KiB
TypeScript
185 lines
4.7 KiB
TypeScript
import { object, string } from "ts-matches"
|
|
import { Effects } from "../Effects"
|
|
import { Origin } from "./Origin"
|
|
import { AddSslOptions, BindParams } from "../osBindings"
|
|
import { Security } from "../osBindings"
|
|
import { BindOptions } from "../osBindings"
|
|
import { AlpnInfo } from "../osBindings"
|
|
|
|
export { AddSslOptions, Security, BindOptions }
|
|
|
|
export const knownProtocols = {
|
|
http: {
|
|
secure: null,
|
|
defaultPort: 80,
|
|
withSsl: "https",
|
|
alpn: { specified: ["http/1.1"] } as AlpnInfo,
|
|
},
|
|
https: {
|
|
secure: { ssl: true },
|
|
defaultPort: 443,
|
|
},
|
|
ws: {
|
|
secure: null,
|
|
defaultPort: 80,
|
|
withSsl: "wss",
|
|
alpn: { specified: ["http/1.1"] } as AlpnInfo,
|
|
},
|
|
wss: {
|
|
secure: { ssl: true },
|
|
defaultPort: 443,
|
|
},
|
|
ssh: {
|
|
secure: { ssl: false },
|
|
defaultPort: 22,
|
|
},
|
|
dns: {
|
|
secure: { ssl: false },
|
|
defaultPort: 53,
|
|
},
|
|
} as const
|
|
|
|
export type Scheme = string | null
|
|
|
|
type KnownProtocols = typeof knownProtocols
|
|
type ProtocolsWithSslVariants = {
|
|
[K in keyof KnownProtocols]: KnownProtocols[K] extends {
|
|
withSsl: string
|
|
}
|
|
? K
|
|
: never
|
|
}[keyof KnownProtocols]
|
|
type NotProtocolsWithSslVariants = Exclude<
|
|
keyof KnownProtocols,
|
|
ProtocolsWithSslVariants
|
|
>
|
|
|
|
type BindOptionsByKnownProtocol =
|
|
| {
|
|
protocol: ProtocolsWithSslVariants
|
|
preferredExternalPort?: number
|
|
addSsl?: Partial<AddSslOptions>
|
|
}
|
|
| {
|
|
protocol: NotProtocolsWithSslVariants
|
|
preferredExternalPort?: number
|
|
addSsl?: AddSslOptions
|
|
}
|
|
export type BindOptionsByProtocol =
|
|
| BindOptionsByKnownProtocol
|
|
| (BindOptions & { protocol: null })
|
|
|
|
const hasStringProtocol = object({
|
|
protocol: string,
|
|
}).test
|
|
|
|
export class MultiHost {
|
|
constructor(
|
|
readonly options: {
|
|
effects: Effects
|
|
id: string
|
|
},
|
|
) {}
|
|
|
|
/**
|
|
* @description Use this function to bind the host to an internal port and configured options for protocol, security, and external port.
|
|
*
|
|
* @param internalPort - The internal port to be bound.
|
|
* @param options - The protocol options for this binding.
|
|
* @returns A multi-origin that is capable of exporting one or more service interfaces.
|
|
* @example
|
|
* In this example, we bind a previously created multi-host to port 80, then select the http protocol and request an external port of 8332.
|
|
*
|
|
* ```
|
|
const uiMultiOrigin = await uiMulti.bindPort(80, {
|
|
protocol: 'http',
|
|
preferredExternalPort: 8332,
|
|
})
|
|
* ```
|
|
*/
|
|
async bindPort(
|
|
internalPort: number,
|
|
options: BindOptionsByProtocol,
|
|
): Promise<Origin> {
|
|
if (hasStringProtocol(options)) {
|
|
return await this.bindPortForKnown(options, internalPort)
|
|
} else {
|
|
return await this.bindPortForUnknown(internalPort, options)
|
|
}
|
|
}
|
|
|
|
private async bindPortForUnknown(
|
|
internalPort: number,
|
|
options: {
|
|
preferredExternalPort: number
|
|
addSsl: AddSslOptions | null
|
|
secure: { ssl: boolean } | null
|
|
},
|
|
) {
|
|
const binderOptions = {
|
|
id: this.options.id,
|
|
internalPort,
|
|
...options,
|
|
}
|
|
await this.options.effects.bind(binderOptions)
|
|
|
|
return new Origin(this, internalPort, null, null)
|
|
}
|
|
|
|
private async bindPortForKnown(
|
|
options: BindOptionsByKnownProtocol,
|
|
internalPort: number,
|
|
) {
|
|
const protoInfo = knownProtocols[options.protocol]
|
|
const preferredExternalPort =
|
|
options.preferredExternalPort ||
|
|
knownProtocols[options.protocol].defaultPort
|
|
const sslProto = this.getSslProto(options)
|
|
const addSsl = sslProto
|
|
? {
|
|
addXForwardedHeaders: false,
|
|
preferredExternalPort: knownProtocols[sslProto].defaultPort,
|
|
scheme: sslProto,
|
|
alpn: "alpn" in protoInfo ? protoInfo.alpn : null,
|
|
...("addSsl" in options ? options.addSsl : null),
|
|
}
|
|
: options.addSsl
|
|
? {
|
|
addXForwardedHeaders: false,
|
|
preferredExternalPort: 443,
|
|
scheme: sslProto,
|
|
alpn: null,
|
|
...("addSsl" in options ? options.addSsl : null),
|
|
}
|
|
: null
|
|
|
|
const secure: Security | null = protoInfo.secure ?? null
|
|
|
|
await this.options.effects.bind({
|
|
id: this.options.id,
|
|
internalPort,
|
|
preferredExternalPort,
|
|
addSsl,
|
|
secure,
|
|
})
|
|
|
|
return new Origin(this, internalPort, options.protocol, sslProto)
|
|
}
|
|
|
|
private getSslProto(options: BindOptionsByKnownProtocol) {
|
|
const proto = options.protocol
|
|
const protoInfo = knownProtocols[proto]
|
|
if (inObject("noAddSsl", options) && options.noAddSsl) return null
|
|
if ("withSsl" in protoInfo && protoInfo.withSsl) return protoInfo.withSsl
|
|
if (protoInfo.secure?.ssl) return proto
|
|
return null
|
|
}
|
|
}
|
|
|
|
function inObject<Key extends string>(
|
|
key: Key,
|
|
obj: any,
|
|
): obj is { [K in Key]: unknown } {
|
|
return key in obj
|
|
}
|