mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-31 20:43:41 +00:00
proxy -> tunnel, implement backend apis
This commit is contained in:
@@ -165,8 +165,8 @@ export default class ProxiesComponent {
|
||||
const loader = this.loader.open('Saving').subscribe()
|
||||
|
||||
try {
|
||||
await this.api.addProxy({
|
||||
label: input.label,
|
||||
await this.api.addTunnel({
|
||||
name: input.label,
|
||||
config: input.config.value.file as string, // @TODO alex this is the file represented as a string
|
||||
public: input.type === 'public',
|
||||
})
|
||||
|
||||
@@ -71,7 +71,7 @@ export class ProxiesTableComponent<T extends WireguardProxy> {
|
||||
const loader = this.loader.open('Deleting').subscribe()
|
||||
|
||||
try {
|
||||
await this.api.removeProxy({ id })
|
||||
await this.api.removeTunnel({ id })
|
||||
} catch (e: any) {
|
||||
this.errorService.handleError(e)
|
||||
} finally {
|
||||
@@ -108,7 +108,7 @@ export class ProxiesTableComponent<T extends WireguardProxy> {
|
||||
const loader = this.loader.open('Saving').subscribe()
|
||||
|
||||
try {
|
||||
await this.api.updateProxy({ id, label })
|
||||
await this.api.updateTunnel({ id, name: label })
|
||||
return true
|
||||
} catch (e: any) {
|
||||
this.errorService.handleError(e)
|
||||
|
||||
@@ -234,30 +234,25 @@ export namespace RR {
|
||||
}
|
||||
export type CreateBackupRes = null
|
||||
|
||||
// proxy
|
||||
// tunnel
|
||||
|
||||
export type AddProxyReq = {
|
||||
label: string
|
||||
config: string // hash of file
|
||||
export type AddTunnelReq = {
|
||||
name: string
|
||||
config: string // file contents
|
||||
public: boolean
|
||||
} // net.proxy.add
|
||||
export type AddProxyRes = {
|
||||
} // net.tunnel.add
|
||||
export type AddTunnelRes = {
|
||||
id: string
|
||||
}
|
||||
|
||||
export type UpdateProxyReq = {
|
||||
export type UpdateTunnelReq = {
|
||||
id: string
|
||||
label: string
|
||||
} // net.netwok-interface.set-label
|
||||
export type UpdateProxyRes = null
|
||||
name: string
|
||||
} // net.netwok-interface.set-name
|
||||
export type UpdateTunnelRes = null
|
||||
|
||||
export type RemoveProxyReq = { id: string } // net.proxy.remove
|
||||
export type RemoveProxyRes = null
|
||||
|
||||
// export type SetOutboundProxyReq = {
|
||||
// id: string | null
|
||||
// } // net.proxy.set-outbound
|
||||
// export type SetOutboundProxyRes = null
|
||||
export type RemoveTunnelReq = { id: string } // net.tunnel.remove
|
||||
export type RemoveTunnelRes = null
|
||||
|
||||
export type InitAcmeReq = {
|
||||
provider: 'letsencrypt' | 'letsencrypt-staging' | string
|
||||
|
||||
@@ -176,17 +176,17 @@ export abstract class ApiService {
|
||||
|
||||
// ** proxies **
|
||||
|
||||
abstract addProxy(params: RR.AddProxyReq): Promise<RR.AddProxyRes>
|
||||
abstract addTunnel(params: RR.AddTunnelReq): Promise<RR.AddTunnelRes>
|
||||
|
||||
abstract updateProxy(params: RR.UpdateProxyReq): Promise<RR.UpdateProxyRes>
|
||||
abstract updateTunnel(params: RR.UpdateTunnelReq): Promise<RR.UpdateTunnelRes>
|
||||
|
||||
abstract removeProxy(params: RR.RemoveProxyReq): Promise<RR.RemoveProxyRes>
|
||||
abstract removeTunnel(params: RR.RemoveTunnelReq): Promise<RR.RemoveTunnelRes>
|
||||
|
||||
// @TODO 041
|
||||
|
||||
// abstract setOutboundProxy(
|
||||
// params: RR.SetOutboundProxyReq,
|
||||
// ): Promise<RR.SetOutboundProxyRes>
|
||||
// params: RR.SetOutboundTunnelReq,
|
||||
// ): Promise<RR.SetOutboundTunnelRes>
|
||||
|
||||
// ** domains **
|
||||
|
||||
@@ -364,8 +364,8 @@ export abstract class ApiService {
|
||||
// ** service outbound proxy **
|
||||
|
||||
// abstract setServiceOutboundProxy(
|
||||
// params: RR.SetServiceOutboundProxyReq,
|
||||
// ): Promise<RR.SetServiceOutboundProxyRes>
|
||||
// params: RR.SetServiceOutboundTunnelReq,
|
||||
// ): Promise<RR.SetServiceOutboundTunnelRes>
|
||||
|
||||
abstract initAcme(params: RR.InitAcmeReq): Promise<RR.InitAcmeRes>
|
||||
|
||||
|
||||
@@ -346,21 +346,21 @@ export class LiveApiService extends ApiService {
|
||||
|
||||
// proxies
|
||||
|
||||
async addProxy(params: RR.AddProxyReq): Promise<RR.AddProxyRes> {
|
||||
return this.rpcRequest({ method: 'net.proxy.add', params })
|
||||
async addTunnel(params: RR.AddTunnelReq): Promise<RR.AddTunnelRes> {
|
||||
return this.rpcRequest({ method: 'net.tunnel.add', params })
|
||||
}
|
||||
|
||||
async updateProxy(params: RR.UpdateProxyReq): Promise<RR.UpdateProxyRes> {
|
||||
return this.rpcRequest({ method: 'net.netwok-interface.set-label', params })
|
||||
async updateTunnel(params: RR.UpdateTunnelReq): Promise<RR.UpdateTunnelRes> {
|
||||
return this.rpcRequest({ method: 'net.netwok-interface.set-name', params })
|
||||
}
|
||||
|
||||
async removeProxy(params: RR.RemoveProxyReq): Promise<RR.RemoveProxyRes> {
|
||||
return this.rpcRequest({ method: 'net.proxy.remove', params })
|
||||
async removeTunnel(params: RR.RemoveTunnelReq): Promise<RR.RemoveTunnelRes> {
|
||||
return this.rpcRequest({ method: 'net.tunnel.remove', params })
|
||||
}
|
||||
|
||||
// async setOutboundProxy(
|
||||
// params: RR.SetOutboundProxyReq,
|
||||
// ): Promise<RR.SetOutboundProxyRes> {
|
||||
// params: RR.SetOutboundTunnelReq,
|
||||
// ): Promise<RR.SetOutboundTunnelRes> {
|
||||
// return this.rpcRequest({ method: 'server.proxy.set-outbound', params })
|
||||
// }
|
||||
|
||||
@@ -627,8 +627,8 @@ export class LiveApiService extends ApiService {
|
||||
}
|
||||
|
||||
// async setServiceOutboundProxy(
|
||||
// params: RR.SetServiceOutboundProxyReq,
|
||||
// ): Promise<RR.SetServiceOutboundProxyRes> {
|
||||
// params: RR.SetServiceOutboundTunnelReq,
|
||||
// ): Promise<RR.SetServiceOutboundTunnelRes> {
|
||||
// return this.rpcRequest({ method: 'package.proxy.set-outbound', params })
|
||||
// }
|
||||
|
||||
|
||||
@@ -544,10 +544,11 @@ export class MockApiService extends ApiService {
|
||||
|
||||
// proxies
|
||||
|
||||
async addProxy(params: RR.AddProxyReq): Promise<RR.AddProxyRes> {
|
||||
private proxyId = 0
|
||||
async addTunnel(params: RR.AddTunnelReq): Promise<RR.AddTunnelRes> {
|
||||
await pauseFor(2000)
|
||||
|
||||
const id = `wga-${params.label}`
|
||||
const id = `wg${this.proxyId++}`
|
||||
|
||||
const patch: AddOperation<T.NetworkInterfaceInfo>[] = [
|
||||
{
|
||||
@@ -556,7 +557,7 @@ export class MockApiService extends ApiService {
|
||||
value: {
|
||||
public: params.public,
|
||||
ipInfo: {
|
||||
name: params.label,
|
||||
name: params.name,
|
||||
scopeId: 3,
|
||||
deviceType: 'wireguard',
|
||||
subnets: [],
|
||||
@@ -571,14 +572,14 @@ export class MockApiService extends ApiService {
|
||||
return { id }
|
||||
}
|
||||
|
||||
async updateProxy(params: RR.UpdateProxyReq): Promise<RR.UpdateProxyRes> {
|
||||
async updateTunnel(params: RR.UpdateTunnelReq): Promise<RR.UpdateTunnelRes> {
|
||||
await pauseFor(2000)
|
||||
|
||||
const patch: ReplaceOperation<string>[] = [
|
||||
{
|
||||
op: PatchOp.REPLACE,
|
||||
path: `/serverInfo/network/networkInterfaces/${params.id}/label`,
|
||||
value: params.label,
|
||||
value: params.name,
|
||||
},
|
||||
]
|
||||
this.mockRevision(patch)
|
||||
@@ -586,7 +587,7 @@ export class MockApiService extends ApiService {
|
||||
return null
|
||||
}
|
||||
|
||||
async removeProxy(params: RR.RemoveProxyReq): Promise<RR.RemoveProxyRes> {
|
||||
async removeTunnel(params: RR.RemoveTunnelReq): Promise<RR.RemoveTunnelRes> {
|
||||
await pauseFor(2000)
|
||||
const patch: RemoveOperation[] = [
|
||||
{
|
||||
@@ -600,8 +601,8 @@ export class MockApiService extends ApiService {
|
||||
}
|
||||
|
||||
// async setOutboundProxy(
|
||||
// params: RR.SetOutboundProxyReq,
|
||||
// ): Promise<RR.SetOutboundProxyRes> {
|
||||
// params: RR.SetOutboundTunnelReq,
|
||||
// ): Promise<RR.SetOutboundTunnelRes> {
|
||||
// await pauseFor(2000)
|
||||
|
||||
// const patch: ReplaceOperation<string | null>[] = [
|
||||
@@ -1372,8 +1373,8 @@ export class MockApiService extends ApiService {
|
||||
}
|
||||
|
||||
// async setServiceOutboundProxy(
|
||||
// params: RR.SetServiceOutboundProxyReq,
|
||||
// ): Promise<RR.SetServiceOutboundProxyRes> {
|
||||
// params: RR.SetServiceOutboundTunnelReq,
|
||||
// ): Promise<RR.SetServiceOutboundTunnelRes> {
|
||||
// await pauseFor(2000)
|
||||
// const patch = [
|
||||
// {
|
||||
|
||||
Reference in New Issue
Block a user