mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-30 12:11:56 +00:00
proxy -> tunnel, implement backend apis
This commit is contained in:
@@ -12,6 +12,7 @@ pub mod service_interface;
|
|||||||
pub mod ssl;
|
pub mod ssl;
|
||||||
pub mod static_server;
|
pub mod static_server;
|
||||||
pub mod tor;
|
pub mod tor;
|
||||||
|
pub mod tunnel;
|
||||||
pub mod utils;
|
pub mod utils;
|
||||||
pub mod vhost;
|
pub mod vhost;
|
||||||
pub mod web_server;
|
pub mod web_server;
|
||||||
@@ -32,6 +33,10 @@ pub fn net<C: Context>() -> ParentHandler<C> {
|
|||||||
network_interface::network_interface_api::<C>()
|
network_interface::network_interface_api::<C>()
|
||||||
.with_about("View and edit network interface configurations"),
|
.with_about("View and edit network interface configurations"),
|
||||||
)
|
)
|
||||||
|
.subcommand(
|
||||||
|
"tunnel",
|
||||||
|
tunnel::tunnel_api::<C>().with_about("Manage tunnels"),
|
||||||
|
)
|
||||||
.subcommand(
|
.subcommand(
|
||||||
"vhost",
|
"vhost",
|
||||||
vhost::vhost_api::<C>().with_about("Manage ssl virtual host proxy"),
|
vhost::vhost_api::<C>().with_about("Manage ssl virtual host proxy"),
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
use std::collections::{BTreeMap, BTreeSet};
|
use std::collections::{BTreeMap, BTreeSet, HashMap};
|
||||||
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV6};
|
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV6};
|
||||||
use std::sync::{Arc, Weak};
|
use std::sync::{Arc, Weak};
|
||||||
use std::task::Poll;
|
use std::task::Poll;
|
||||||
@@ -28,6 +28,7 @@ use crate::context::{CliContext, RpcContext};
|
|||||||
use crate::db::model::public::{IpInfo, NetworkInterfaceInfo, NetworkInterfaceType};
|
use crate::db::model::public::{IpInfo, NetworkInterfaceInfo, NetworkInterfaceType};
|
||||||
use crate::db::model::Database;
|
use crate::db::model::Database;
|
||||||
use crate::net::forward::START9_BRIDGE_IFACE;
|
use crate::net::forward::START9_BRIDGE_IFACE;
|
||||||
|
use crate::net::network_interface::device::DeviceProxy;
|
||||||
use crate::net::utils::{ipv6_is_link_local, ipv6_is_local};
|
use crate::net::utils::{ipv6_is_link_local, ipv6_is_local};
|
||||||
use crate::net::web_server::Accept;
|
use crate::net::web_server::Accept;
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
@@ -86,15 +87,15 @@ pub fn network_interface_api<C: Context>() -> ParentHandler<C> {
|
|||||||
.with_call_remote::<CliContext>(),
|
.with_call_remote::<CliContext>(),
|
||||||
)
|
)
|
||||||
.subcommand(
|
.subcommand(
|
||||||
"set-inbound",
|
"set-public",
|
||||||
from_fn_async(set_inbound)
|
from_fn_async(set_public)
|
||||||
.with_metadata("sync_db", Value::Bool(true))
|
.with_metadata("sync_db", Value::Bool(true))
|
||||||
.no_display()
|
.no_display()
|
||||||
.with_about("Indicate whether this interface has inbound access from the WAN")
|
.with_about("Indicate whether this interface has inbound access from the WAN")
|
||||||
.with_call_remote::<CliContext>(),
|
.with_call_remote::<CliContext>(),
|
||||||
).subcommand(
|
).subcommand(
|
||||||
"unset-inbound",
|
"unset-inbound",
|
||||||
from_fn_async(unset_inbound)
|
from_fn_async(unset_public)
|
||||||
.with_metadata("sync_db", Value::Bool(true))
|
.with_metadata("sync_db", Value::Bool(true))
|
||||||
.no_display()
|
.no_display()
|
||||||
.with_about("Allow this interface to infer whether it has inbound access from the WAN based on its IPv4 address")
|
.with_about("Allow this interface to infer whether it has inbound access from the WAN based on its IPv4 address")
|
||||||
@@ -105,7 +106,13 @@ pub fn network_interface_api<C: Context>() -> ParentHandler<C> {
|
|||||||
.no_display()
|
.no_display()
|
||||||
.with_about("Forget a disconnected interface")
|
.with_about("Forget a disconnected interface")
|
||||||
.with_call_remote::<CliContext>()
|
.with_call_remote::<CliContext>()
|
||||||
)
|
).subcommand("set-name",
|
||||||
|
from_fn_async(set_name)
|
||||||
|
.with_metadata("sync_db", Value::Bool(true))
|
||||||
|
.no_display()
|
||||||
|
.with_about("Rename an interface")
|
||||||
|
.with_call_remote::<CliContext>()
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn list_interfaces(
|
async fn list_interfaces(
|
||||||
@@ -116,19 +123,19 @@ async fn list_interfaces(
|
|||||||
|
|
||||||
#[derive(Debug, Clone, Deserialize, Serialize, Parser, TS)]
|
#[derive(Debug, Clone, Deserialize, Serialize, Parser, TS)]
|
||||||
#[ts(export)]
|
#[ts(export)]
|
||||||
struct NetworkInterfaceSetInboundParams {
|
struct NetworkInterfaceSetPublicParams {
|
||||||
#[ts(type = "string")]
|
#[ts(type = "string")]
|
||||||
interface: InternedString,
|
interface: InternedString,
|
||||||
inbound: Option<bool>,
|
public: Option<bool>,
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn set_inbound(
|
async fn set_public(
|
||||||
ctx: RpcContext,
|
ctx: RpcContext,
|
||||||
NetworkInterfaceSetInboundParams { interface, inbound }: NetworkInterfaceSetInboundParams,
|
NetworkInterfaceSetPublicParams { interface, public }: NetworkInterfaceSetPublicParams,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
ctx.net_controller
|
ctx.net_controller
|
||||||
.net_iface
|
.net_iface
|
||||||
.set_inbound(&interface, Some(inbound.unwrap_or(true)))
|
.set_public(&interface, Some(public.unwrap_or(true)))
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -139,13 +146,13 @@ struct UnsetInboundParams {
|
|||||||
interface: InternedString,
|
interface: InternedString,
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn unset_inbound(
|
async fn unset_public(
|
||||||
ctx: RpcContext,
|
ctx: RpcContext,
|
||||||
UnsetInboundParams { interface }: UnsetInboundParams,
|
UnsetInboundParams { interface }: UnsetInboundParams,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
ctx.net_controller
|
ctx.net_controller
|
||||||
.net_iface
|
.net_iface
|
||||||
.set_inbound(&interface, None)
|
.set_public(&interface, None)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -163,12 +170,32 @@ async fn forget_iface(
|
|||||||
ctx.net_controller.net_iface.forget(&interface).await
|
ctx.net_controller.net_iface.forget(&interface).await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Deserialize, Serialize, Parser, TS)]
|
||||||
|
#[ts(export)]
|
||||||
|
struct RenameInterfaceParams {
|
||||||
|
#[ts(type = "string")]
|
||||||
|
interface: InternedString,
|
||||||
|
name: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn set_name(
|
||||||
|
ctx: RpcContext,
|
||||||
|
RenameInterfaceParams { interface, name }: RenameInterfaceParams,
|
||||||
|
) -> Result<(), Error> {
|
||||||
|
ctx.net_controller
|
||||||
|
.net_iface
|
||||||
|
.set_name(&interface, &name)
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
#[proxy(
|
#[proxy(
|
||||||
interface = "org.freedesktop.NetworkManager",
|
interface = "org.freedesktop.NetworkManager",
|
||||||
default_service = "org.freedesktop.NetworkManager",
|
default_service = "org.freedesktop.NetworkManager",
|
||||||
default_path = "/org/freedesktop/NetworkManager"
|
default_path = "/org/freedesktop/NetworkManager"
|
||||||
)]
|
)]
|
||||||
trait NetworkManager {
|
trait NetworkManager {
|
||||||
|
fn get_device_by_ip_iface(&self, iface: &str) -> Result<OwnedObjectPath, Error>;
|
||||||
|
|
||||||
#[zbus(property)]
|
#[zbus(property)]
|
||||||
fn all_devices(&self) -> Result<Vec<OwnedObjectPath>, Error>;
|
fn all_devices(&self) -> Result<Vec<OwnedObjectPath>, Error>;
|
||||||
|
|
||||||
@@ -193,6 +220,9 @@ mod active_connection {
|
|||||||
default_service = "org.freedesktop.NetworkManager"
|
default_service = "org.freedesktop.NetworkManager"
|
||||||
)]
|
)]
|
||||||
pub trait ActiveConnection {
|
pub trait ActiveConnection {
|
||||||
|
#[zbus(property)]
|
||||||
|
fn connection(&self) -> Result<OwnedObjectPath, Error>;
|
||||||
|
|
||||||
#[zbus(property)]
|
#[zbus(property)]
|
||||||
fn id(&self) -> Result<String, Error>;
|
fn id(&self) -> Result<String, Error>;
|
||||||
|
|
||||||
@@ -210,6 +240,19 @@ mod active_connection {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[proxy(
|
||||||
|
interface = "org.freedesktop.NetworkManager.Settings.Connection",
|
||||||
|
default_service = "org.freedesktop.NetworkManager"
|
||||||
|
)]
|
||||||
|
trait ConnectionSettings {
|
||||||
|
fn update2(
|
||||||
|
&self,
|
||||||
|
settings: HashMap<String, HashMap<String, ZValue<'_>>>,
|
||||||
|
flags: u32,
|
||||||
|
args: HashMap<String, ZValue<'_>>,
|
||||||
|
) -> Result<(), Error>;
|
||||||
|
}
|
||||||
|
|
||||||
#[proxy(
|
#[proxy(
|
||||||
interface = "org.freedesktop.NetworkManager.IP4Config",
|
interface = "org.freedesktop.NetworkManager.IP4Config",
|
||||||
default_service = "org.freedesktop.NetworkManager"
|
default_service = "org.freedesktop.NetworkManager"
|
||||||
@@ -276,6 +319,8 @@ mod device {
|
|||||||
default_service = "org.freedesktop.NetworkManager"
|
default_service = "org.freedesktop.NetworkManager"
|
||||||
)]
|
)]
|
||||||
pub trait Device {
|
pub trait Device {
|
||||||
|
fn delete(&self) -> Result<(), Error>;
|
||||||
|
|
||||||
#[zbus(property)]
|
#[zbus(property)]
|
||||||
fn ip_interface(&self) -> Result<String, Error>;
|
fn ip_interface(&self) -> Result<String, Error>;
|
||||||
|
|
||||||
@@ -836,7 +881,7 @@ impl NetworkInterfaceController {
|
|||||||
Ok(listener)
|
Ok(listener)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn set_inbound(
|
pub async fn set_public(
|
||||||
&self,
|
&self,
|
||||||
interface: &InternedString,
|
interface: &InternedString,
|
||||||
public: Option<bool>,
|
public: Option<bool>,
|
||||||
@@ -904,6 +949,96 @@ impl NetworkInterfaceController {
|
|||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn delete_iface(&self, interface: &InternedString) -> Result<(), Error> {
|
||||||
|
let Some(has_ip_info) = self
|
||||||
|
.ip_info
|
||||||
|
.peek(|ifaces| ifaces.get(interface).map(|i| i.ip_info.is_some()))
|
||||||
|
else {
|
||||||
|
return Ok(());
|
||||||
|
};
|
||||||
|
|
||||||
|
if has_ip_info {
|
||||||
|
let mut ip_info = self.ip_info.clone_unseen();
|
||||||
|
|
||||||
|
let connection = Connection::system().await?;
|
||||||
|
|
||||||
|
let netman_proxy = NetworkManagerProxy::new(&connection).await?;
|
||||||
|
|
||||||
|
let device = Some(netman_proxy.get_device_by_ip_iface(&**interface).await?)
|
||||||
|
.filter(|o| &**o != "/")
|
||||||
|
.or_not_found(lazy_format!("{interface} in NetworkManager"))?;
|
||||||
|
|
||||||
|
let device_proxy = DeviceProxy::new(&connection, device).await?;
|
||||||
|
|
||||||
|
device_proxy.delete().await?;
|
||||||
|
|
||||||
|
ip_info
|
||||||
|
.wait_for(|ifaces| ifaces.get(interface).map_or(true, |i| i.ip_info.is_none()))
|
||||||
|
.await;
|
||||||
|
}
|
||||||
|
|
||||||
|
self.forget(interface).await?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn set_name(&self, interface: &InternedString, name: &str) -> Result<(), Error> {
|
||||||
|
let (dump, mut sub) = self
|
||||||
|
.db
|
||||||
|
.dump_and_sub(
|
||||||
|
"/public/serverInfo/network/networkInterfaces"
|
||||||
|
.parse::<JsonPointer<_, _>>()
|
||||||
|
.with_kind(ErrorKind::Database)?
|
||||||
|
.join_end(&**interface)
|
||||||
|
.join_end("ipInfo")
|
||||||
|
.join_end("name"),
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
let change = dump.value.as_str().or_not_found(interface)? != name;
|
||||||
|
|
||||||
|
if !change {
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
|
||||||
|
let connection = Connection::system().await?;
|
||||||
|
|
||||||
|
let netman_proxy = NetworkManagerProxy::new(&connection).await?;
|
||||||
|
|
||||||
|
let device = Some(netman_proxy.get_device_by_ip_iface(&**interface).await?)
|
||||||
|
.filter(|o| &**o != "/")
|
||||||
|
.or_not_found(lazy_format!("{interface} in NetworkManager"))?;
|
||||||
|
|
||||||
|
let device_proxy = DeviceProxy::new(&connection, device).await?;
|
||||||
|
|
||||||
|
let dac = Some(device_proxy.active_connection().await?)
|
||||||
|
.filter(|o| &**o != "/")
|
||||||
|
.or_not_found(lazy_format!("ActiveConnection for {interface}"))?;
|
||||||
|
|
||||||
|
let dac_proxy = active_connection::ActiveConnectionProxy::new(&connection, dac).await?;
|
||||||
|
|
||||||
|
let settings = Some(dac_proxy.connection().await?)
|
||||||
|
.filter(|o| &**o != "/")
|
||||||
|
.or_not_found(lazy_format!("ConnectionSettings for {interface}"))?;
|
||||||
|
|
||||||
|
let settings_proxy = ConnectionSettingsProxy::new(&connection, settings).await?;
|
||||||
|
|
||||||
|
settings_proxy.update2(
|
||||||
|
[(
|
||||||
|
"connection".into(),
|
||||||
|
[("id".into(), zbus::zvariant::Value::Str(name.into()))]
|
||||||
|
.into_iter()
|
||||||
|
.collect(),
|
||||||
|
)]
|
||||||
|
.into_iter()
|
||||||
|
.collect(),
|
||||||
|
0x1,
|
||||||
|
HashMap::new(),
|
||||||
|
);
|
||||||
|
|
||||||
|
sub.recv().await;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ListenerMap {
|
struct ListenerMap {
|
||||||
|
|||||||
125
core/startos/src/net/tunnel.rs
Normal file
125
core/startos/src/net/tunnel.rs
Normal file
@@ -0,0 +1,125 @@
|
|||||||
|
use clap::Parser;
|
||||||
|
use imbl_value::InternedString;
|
||||||
|
use rpc_toolkit::{from_fn_async, Context, HandlerExt, ParentHandler};
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
use tokio::process::Command;
|
||||||
|
use ts_rs::TS;
|
||||||
|
|
||||||
|
use crate::context::{CliContext, RpcContext};
|
||||||
|
use crate::db::model::public::NetworkInterfaceType;
|
||||||
|
use crate::prelude::*;
|
||||||
|
use crate::util::io::{write_file_atomic, TmpDir};
|
||||||
|
use crate::util::Invoke;
|
||||||
|
|
||||||
|
pub fn tunnel_api<C: Context>() -> ParentHandler<C> {
|
||||||
|
ParentHandler::new()
|
||||||
|
.subcommand(
|
||||||
|
"add",
|
||||||
|
from_fn_async(add_tunnel)
|
||||||
|
.with_about("Add a new tunnel")
|
||||||
|
.with_call_remote::<CliContext>(),
|
||||||
|
)
|
||||||
|
.subcommand(
|
||||||
|
"remove",
|
||||||
|
from_fn_async(remove_tunnel)
|
||||||
|
.no_display()
|
||||||
|
.with_about("Remove a tunnel")
|
||||||
|
.with_call_remote::<CliContext>(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Deserialize, Serialize, Parser, TS)]
|
||||||
|
#[ts(export)]
|
||||||
|
pub struct AddTunnelParams {
|
||||||
|
#[ts(type = "string")]
|
||||||
|
name: InternedString,
|
||||||
|
config: String,
|
||||||
|
public: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn add_tunnel(
|
||||||
|
ctx: RpcContext,
|
||||||
|
AddTunnelParams {
|
||||||
|
name,
|
||||||
|
config,
|
||||||
|
public,
|
||||||
|
}: AddTunnelParams,
|
||||||
|
) -> Result<InternedString, Error> {
|
||||||
|
let existing = ctx
|
||||||
|
.db
|
||||||
|
.peek()
|
||||||
|
.await
|
||||||
|
.into_public()
|
||||||
|
.into_server_info()
|
||||||
|
.into_network()
|
||||||
|
.into_network_interfaces()
|
||||||
|
.keys()?;
|
||||||
|
let mut iface = InternedString::intern("wg0");
|
||||||
|
for id in 1.. {
|
||||||
|
if !existing.contains(&iface) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
iface = InternedString::from_display(&lazy_format!("wg{id}"));
|
||||||
|
}
|
||||||
|
let tmpdir = TmpDir::new().await?;
|
||||||
|
let conf = tmpdir.join(&*iface).with_extension("conf");
|
||||||
|
write_file_atomic(&conf, &config).await?;
|
||||||
|
let mut ifaces = ctx.net_controller.net_iface.subscribe();
|
||||||
|
Command::new("nmcli")
|
||||||
|
.arg("connection")
|
||||||
|
.arg("import")
|
||||||
|
.arg("type")
|
||||||
|
.arg("wireguard")
|
||||||
|
.arg("file")
|
||||||
|
.arg(&conf)
|
||||||
|
.invoke(ErrorKind::Network)
|
||||||
|
.await?;
|
||||||
|
tmpdir.delete().await?;
|
||||||
|
|
||||||
|
ifaces.wait_for(|ifaces| ifaces.contains_key(&iface)).await;
|
||||||
|
|
||||||
|
ctx.net_controller
|
||||||
|
.net_iface
|
||||||
|
.set_public(&iface, Some(public))
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
ctx.net_controller.net_iface.set_name(&iface, &name).await?;
|
||||||
|
|
||||||
|
Ok(iface)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Deserialize, Serialize, Parser, TS)]
|
||||||
|
#[ts(export)]
|
||||||
|
pub struct RemoveTunnelParams {
|
||||||
|
#[ts(type = "string")]
|
||||||
|
id: InternedString,
|
||||||
|
}
|
||||||
|
pub async fn remove_tunnel(
|
||||||
|
ctx: RpcContext,
|
||||||
|
RemoveTunnelParams { id }: RemoveTunnelParams,
|
||||||
|
) -> Result<(), Error> {
|
||||||
|
let Some(existing) = ctx
|
||||||
|
.db
|
||||||
|
.peek()
|
||||||
|
.await
|
||||||
|
.into_public()
|
||||||
|
.into_server_info()
|
||||||
|
.into_network()
|
||||||
|
.into_network_interfaces()
|
||||||
|
.into_idx(&id)
|
||||||
|
.and_then(|e| e.into_ip_info().transpose())
|
||||||
|
else {
|
||||||
|
return Ok(());
|
||||||
|
};
|
||||||
|
|
||||||
|
if existing.as_device_type().de()? != Some(NetworkInterfaceType::Wireguard) {
|
||||||
|
return Err(Error::new(
|
||||||
|
eyre!("network interface {id} is not a proxy"),
|
||||||
|
ErrorKind::InvalidRequest,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx.net_controller.net_iface.delete_iface(&id).await?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
3
sdk/base/lib/osBindings/AddTunnelParams.ts
Normal file
3
sdk/base/lib/osBindings/AddTunnelParams.ts
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
|
||||||
|
|
||||||
|
export type AddTunnelParams = { name: string; config: string; public: boolean }
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
|
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
|
||||||
|
|
||||||
export type NetworkInterfaceSetInboundParams = {
|
export type NetworkInterfaceSetPublicParams = {
|
||||||
interface: string
|
interface: string
|
||||||
inbound: boolean | null
|
public: boolean | null
|
||||||
}
|
}
|
||||||
3
sdk/base/lib/osBindings/RemoveTunnelParams.ts
Normal file
3
sdk/base/lib/osBindings/RemoveTunnelParams.ts
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
|
||||||
|
|
||||||
|
export type RemoveTunnelParams = { id: string }
|
||||||
3
sdk/base/lib/osBindings/RenameInterfaceParams.ts
Normal file
3
sdk/base/lib/osBindings/RenameInterfaceParams.ts
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
|
||||||
|
|
||||||
|
export type RenameInterfaceParams = { interface: string; name: string }
|
||||||
@@ -17,6 +17,7 @@ export { AddPackageParams } from "./AddPackageParams"
|
|||||||
export { AddPackageToCategoryParams } from "./AddPackageToCategoryParams"
|
export { AddPackageToCategoryParams } from "./AddPackageToCategoryParams"
|
||||||
export { AddressInfo } from "./AddressInfo"
|
export { AddressInfo } from "./AddressInfo"
|
||||||
export { AddSslOptions } from "./AddSslOptions"
|
export { AddSslOptions } from "./AddSslOptions"
|
||||||
|
export { AddTunnelParams } from "./AddTunnelParams"
|
||||||
export { AddVersionParams } from "./AddVersionParams"
|
export { AddVersionParams } from "./AddVersionParams"
|
||||||
export { Alerts } from "./Alerts"
|
export { Alerts } from "./Alerts"
|
||||||
export { Algorithm } from "./Algorithm"
|
export { Algorithm } from "./Algorithm"
|
||||||
@@ -138,7 +139,7 @@ export { NamedProgress } from "./NamedProgress"
|
|||||||
export { NetInfo } from "./NetInfo"
|
export { NetInfo } from "./NetInfo"
|
||||||
export { NetworkInfo } from "./NetworkInfo"
|
export { NetworkInfo } from "./NetworkInfo"
|
||||||
export { NetworkInterfaceInfo } from "./NetworkInterfaceInfo"
|
export { NetworkInterfaceInfo } from "./NetworkInterfaceInfo"
|
||||||
export { NetworkInterfaceSetInboundParams } from "./NetworkInterfaceSetInboundParams"
|
export { NetworkInterfaceSetPublicParams } from "./NetworkInterfaceSetPublicParams"
|
||||||
export { NetworkInterfaceType } from "./NetworkInterfaceType"
|
export { NetworkInterfaceType } from "./NetworkInterfaceType"
|
||||||
export { OnionHostname } from "./OnionHostname"
|
export { OnionHostname } from "./OnionHostname"
|
||||||
export { OsIndex } from "./OsIndex"
|
export { OsIndex } from "./OsIndex"
|
||||||
@@ -167,7 +168,9 @@ export { RemoveAssetParams } from "./RemoveAssetParams"
|
|||||||
export { RemoveCategoryParams } from "./RemoveCategoryParams"
|
export { RemoveCategoryParams } from "./RemoveCategoryParams"
|
||||||
export { RemovePackageFromCategoryParams } from "./RemovePackageFromCategoryParams"
|
export { RemovePackageFromCategoryParams } from "./RemovePackageFromCategoryParams"
|
||||||
export { RemovePackageParams } from "./RemovePackageParams"
|
export { RemovePackageParams } from "./RemovePackageParams"
|
||||||
|
export { RemoveTunnelParams } from "./RemoveTunnelParams"
|
||||||
export { RemoveVersionParams } from "./RemoveVersionParams"
|
export { RemoveVersionParams } from "./RemoveVersionParams"
|
||||||
|
export { RenameInterfaceParams } from "./RenameInterfaceParams"
|
||||||
export { ReplayId } from "./ReplayId"
|
export { ReplayId } from "./ReplayId"
|
||||||
export { RequestCommitment } from "./RequestCommitment"
|
export { RequestCommitment } from "./RequestCommitment"
|
||||||
export { RunActionParams } from "./RunActionParams"
|
export { RunActionParams } from "./RunActionParams"
|
||||||
|
|||||||
@@ -165,8 +165,8 @@ export default class ProxiesComponent {
|
|||||||
const loader = this.loader.open('Saving').subscribe()
|
const loader = this.loader.open('Saving').subscribe()
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await this.api.addProxy({
|
await this.api.addTunnel({
|
||||||
label: input.label,
|
name: input.label,
|
||||||
config: input.config.value.file as string, // @TODO alex this is the file represented as a string
|
config: input.config.value.file as string, // @TODO alex this is the file represented as a string
|
||||||
public: input.type === 'public',
|
public: input.type === 'public',
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ export class ProxiesTableComponent<T extends WireguardProxy> {
|
|||||||
const loader = this.loader.open('Deleting').subscribe()
|
const loader = this.loader.open('Deleting').subscribe()
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await this.api.removeProxy({ id })
|
await this.api.removeTunnel({ id })
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
this.errorService.handleError(e)
|
this.errorService.handleError(e)
|
||||||
} finally {
|
} finally {
|
||||||
@@ -108,7 +108,7 @@ export class ProxiesTableComponent<T extends WireguardProxy> {
|
|||||||
const loader = this.loader.open('Saving').subscribe()
|
const loader = this.loader.open('Saving').subscribe()
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await this.api.updateProxy({ id, label })
|
await this.api.updateTunnel({ id, name: label })
|
||||||
return true
|
return true
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
this.errorService.handleError(e)
|
this.errorService.handleError(e)
|
||||||
|
|||||||
@@ -234,30 +234,25 @@ export namespace RR {
|
|||||||
}
|
}
|
||||||
export type CreateBackupRes = null
|
export type CreateBackupRes = null
|
||||||
|
|
||||||
// proxy
|
// tunnel
|
||||||
|
|
||||||
export type AddProxyReq = {
|
export type AddTunnelReq = {
|
||||||
label: string
|
name: string
|
||||||
config: string // hash of file
|
config: string // file contents
|
||||||
public: boolean
|
public: boolean
|
||||||
} // net.proxy.add
|
} // net.tunnel.add
|
||||||
export type AddProxyRes = {
|
export type AddTunnelRes = {
|
||||||
id: string
|
id: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export type UpdateProxyReq = {
|
export type UpdateTunnelReq = {
|
||||||
id: string
|
id: string
|
||||||
label: string
|
name: string
|
||||||
} // net.netwok-interface.set-label
|
} // net.netwok-interface.set-name
|
||||||
export type UpdateProxyRes = null
|
export type UpdateTunnelRes = null
|
||||||
|
|
||||||
export type RemoveProxyReq = { id: string } // net.proxy.remove
|
export type RemoveTunnelReq = { id: string } // net.tunnel.remove
|
||||||
export type RemoveProxyRes = null
|
export type RemoveTunnelRes = null
|
||||||
|
|
||||||
// export type SetOutboundProxyReq = {
|
|
||||||
// id: string | null
|
|
||||||
// } // net.proxy.set-outbound
|
|
||||||
// export type SetOutboundProxyRes = null
|
|
||||||
|
|
||||||
export type InitAcmeReq = {
|
export type InitAcmeReq = {
|
||||||
provider: 'letsencrypt' | 'letsencrypt-staging' | string
|
provider: 'letsencrypt' | 'letsencrypt-staging' | string
|
||||||
|
|||||||
@@ -176,17 +176,17 @@ export abstract class ApiService {
|
|||||||
|
|
||||||
// ** proxies **
|
// ** 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
|
// @TODO 041
|
||||||
|
|
||||||
// abstract setOutboundProxy(
|
// abstract setOutboundProxy(
|
||||||
// params: RR.SetOutboundProxyReq,
|
// params: RR.SetOutboundTunnelReq,
|
||||||
// ): Promise<RR.SetOutboundProxyRes>
|
// ): Promise<RR.SetOutboundTunnelRes>
|
||||||
|
|
||||||
// ** domains **
|
// ** domains **
|
||||||
|
|
||||||
@@ -364,8 +364,8 @@ export abstract class ApiService {
|
|||||||
// ** service outbound proxy **
|
// ** service outbound proxy **
|
||||||
|
|
||||||
// abstract setServiceOutboundProxy(
|
// abstract setServiceOutboundProxy(
|
||||||
// params: RR.SetServiceOutboundProxyReq,
|
// params: RR.SetServiceOutboundTunnelReq,
|
||||||
// ): Promise<RR.SetServiceOutboundProxyRes>
|
// ): Promise<RR.SetServiceOutboundTunnelRes>
|
||||||
|
|
||||||
abstract initAcme(params: RR.InitAcmeReq): Promise<RR.InitAcmeRes>
|
abstract initAcme(params: RR.InitAcmeReq): Promise<RR.InitAcmeRes>
|
||||||
|
|
||||||
|
|||||||
@@ -346,21 +346,21 @@ export class LiveApiService extends ApiService {
|
|||||||
|
|
||||||
// proxies
|
// proxies
|
||||||
|
|
||||||
async addProxy(params: RR.AddProxyReq): Promise<RR.AddProxyRes> {
|
async addTunnel(params: RR.AddTunnelReq): Promise<RR.AddTunnelRes> {
|
||||||
return this.rpcRequest({ method: 'net.proxy.add', params })
|
return this.rpcRequest({ method: 'net.tunnel.add', params })
|
||||||
}
|
}
|
||||||
|
|
||||||
async updateProxy(params: RR.UpdateProxyReq): Promise<RR.UpdateProxyRes> {
|
async updateTunnel(params: RR.UpdateTunnelReq): Promise<RR.UpdateTunnelRes> {
|
||||||
return this.rpcRequest({ method: 'net.netwok-interface.set-label', params })
|
return this.rpcRequest({ method: 'net.netwok-interface.set-name', params })
|
||||||
}
|
}
|
||||||
|
|
||||||
async removeProxy(params: RR.RemoveProxyReq): Promise<RR.RemoveProxyRes> {
|
async removeTunnel(params: RR.RemoveTunnelReq): Promise<RR.RemoveTunnelRes> {
|
||||||
return this.rpcRequest({ method: 'net.proxy.remove', params })
|
return this.rpcRequest({ method: 'net.tunnel.remove', params })
|
||||||
}
|
}
|
||||||
|
|
||||||
// async setOutboundProxy(
|
// async setOutboundProxy(
|
||||||
// params: RR.SetOutboundProxyReq,
|
// params: RR.SetOutboundTunnelReq,
|
||||||
// ): Promise<RR.SetOutboundProxyRes> {
|
// ): Promise<RR.SetOutboundTunnelRes> {
|
||||||
// return this.rpcRequest({ method: 'server.proxy.set-outbound', params })
|
// return this.rpcRequest({ method: 'server.proxy.set-outbound', params })
|
||||||
// }
|
// }
|
||||||
|
|
||||||
@@ -627,8 +627,8 @@ export class LiveApiService extends ApiService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// async setServiceOutboundProxy(
|
// async setServiceOutboundProxy(
|
||||||
// params: RR.SetServiceOutboundProxyReq,
|
// params: RR.SetServiceOutboundTunnelReq,
|
||||||
// ): Promise<RR.SetServiceOutboundProxyRes> {
|
// ): Promise<RR.SetServiceOutboundTunnelRes> {
|
||||||
// return this.rpcRequest({ method: 'package.proxy.set-outbound', params })
|
// return this.rpcRequest({ method: 'package.proxy.set-outbound', params })
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
|||||||
@@ -544,10 +544,11 @@ export class MockApiService extends ApiService {
|
|||||||
|
|
||||||
// proxies
|
// proxies
|
||||||
|
|
||||||
async addProxy(params: RR.AddProxyReq): Promise<RR.AddProxyRes> {
|
private proxyId = 0
|
||||||
|
async addTunnel(params: RR.AddTunnelReq): Promise<RR.AddTunnelRes> {
|
||||||
await pauseFor(2000)
|
await pauseFor(2000)
|
||||||
|
|
||||||
const id = `wga-${params.label}`
|
const id = `wg${this.proxyId++}`
|
||||||
|
|
||||||
const patch: AddOperation<T.NetworkInterfaceInfo>[] = [
|
const patch: AddOperation<T.NetworkInterfaceInfo>[] = [
|
||||||
{
|
{
|
||||||
@@ -556,7 +557,7 @@ export class MockApiService extends ApiService {
|
|||||||
value: {
|
value: {
|
||||||
public: params.public,
|
public: params.public,
|
||||||
ipInfo: {
|
ipInfo: {
|
||||||
name: params.label,
|
name: params.name,
|
||||||
scopeId: 3,
|
scopeId: 3,
|
||||||
deviceType: 'wireguard',
|
deviceType: 'wireguard',
|
||||||
subnets: [],
|
subnets: [],
|
||||||
@@ -571,14 +572,14 @@ export class MockApiService extends ApiService {
|
|||||||
return { id }
|
return { id }
|
||||||
}
|
}
|
||||||
|
|
||||||
async updateProxy(params: RR.UpdateProxyReq): Promise<RR.UpdateProxyRes> {
|
async updateTunnel(params: RR.UpdateTunnelReq): Promise<RR.UpdateTunnelRes> {
|
||||||
await pauseFor(2000)
|
await pauseFor(2000)
|
||||||
|
|
||||||
const patch: ReplaceOperation<string>[] = [
|
const patch: ReplaceOperation<string>[] = [
|
||||||
{
|
{
|
||||||
op: PatchOp.REPLACE,
|
op: PatchOp.REPLACE,
|
||||||
path: `/serverInfo/network/networkInterfaces/${params.id}/label`,
|
path: `/serverInfo/network/networkInterfaces/${params.id}/label`,
|
||||||
value: params.label,
|
value: params.name,
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
this.mockRevision(patch)
|
this.mockRevision(patch)
|
||||||
@@ -586,7 +587,7 @@ export class MockApiService extends ApiService {
|
|||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
async removeProxy(params: RR.RemoveProxyReq): Promise<RR.RemoveProxyRes> {
|
async removeTunnel(params: RR.RemoveTunnelReq): Promise<RR.RemoveTunnelRes> {
|
||||||
await pauseFor(2000)
|
await pauseFor(2000)
|
||||||
const patch: RemoveOperation[] = [
|
const patch: RemoveOperation[] = [
|
||||||
{
|
{
|
||||||
@@ -600,8 +601,8 @@ export class MockApiService extends ApiService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// async setOutboundProxy(
|
// async setOutboundProxy(
|
||||||
// params: RR.SetOutboundProxyReq,
|
// params: RR.SetOutboundTunnelReq,
|
||||||
// ): Promise<RR.SetOutboundProxyRes> {
|
// ): Promise<RR.SetOutboundTunnelRes> {
|
||||||
// await pauseFor(2000)
|
// await pauseFor(2000)
|
||||||
|
|
||||||
// const patch: ReplaceOperation<string | null>[] = [
|
// const patch: ReplaceOperation<string | null>[] = [
|
||||||
@@ -1372,8 +1373,8 @@ export class MockApiService extends ApiService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// async setServiceOutboundProxy(
|
// async setServiceOutboundProxy(
|
||||||
// params: RR.SetServiceOutboundProxyReq,
|
// params: RR.SetServiceOutboundTunnelReq,
|
||||||
// ): Promise<RR.SetServiceOutboundProxyRes> {
|
// ): Promise<RR.SetServiceOutboundTunnelRes> {
|
||||||
// await pauseFor(2000)
|
// await pauseFor(2000)
|
||||||
// const patch = [
|
// const patch = [
|
||||||
// {
|
// {
|
||||||
|
|||||||
Reference in New Issue
Block a user