Start of the native Windows port. windows/ holds a Rust workspace; this first piece is ps-core's model of the services.proxy-suite option tree, with upstream's names and defaults, Windows-only additions documented, validation ported from the module's assertions, and the derived tags and loopback ports the tunnels add. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
480 lines
14 KiB
Rust
480 lines
14 KiB
Rust
//! `inbounds`: server listeners for remote clients, their users, share links,
|
|
//! subscriptions, and the manager that keeps the users' policies.
|
|
//!
|
|
//! Left out from upstream: `runtime` (everything here is runtime-editable), `serverSource`
|
|
//! (a Linux dummy interface), `manager.speedLimits` (nftables policing) and the web server
|
|
//! groups; the service serves subscriptions itself on `subscriptions.listen`.
|
|
|
|
use std::collections::BTreeMap;
|
|
|
|
use serde::{Deserialize, Serialize};
|
|
use serde_json::{Map, Value};
|
|
|
|
use super::{AwgObfuscation, RouteMatch};
|
|
|
|
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
|
#[serde(rename_all = "camelCase", default, deny_unknown_fields)]
|
|
pub struct Inbounds {
|
|
pub enable: bool,
|
|
pub server_address: Option<String>,
|
|
pub server_aliases: Vec<String>,
|
|
pub server_ports: Vec<Value>,
|
|
pub access_log: bool,
|
|
/// Add Windows Firewall rules for every listener not on loopback.
|
|
pub open_firewall: bool,
|
|
pub share_links: bool,
|
|
pub subscriptions: InboundSubscriptions,
|
|
pub routing: InboundRouting,
|
|
pub users: BTreeMap<String, InboundUser>,
|
|
pub listeners: BTreeMap<String, InboundListener>,
|
|
pub manager: Manager,
|
|
}
|
|
|
|
impl Default for Inbounds {
|
|
fn default() -> Self {
|
|
Self {
|
|
enable: false,
|
|
server_address: None,
|
|
server_aliases: Vec::new(),
|
|
server_ports: Vec::new(),
|
|
access_log: false,
|
|
open_firewall: true,
|
|
share_links: true,
|
|
subscriptions: InboundSubscriptions::default(),
|
|
routing: InboundRouting::default(),
|
|
users: BTreeMap::new(),
|
|
listeners: BTreeMap::new(),
|
|
manager: Manager::default(),
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
|
|
#[serde(rename_all = "camelCase", default, deny_unknown_fields)]
|
|
pub struct InboundSubscriptions {
|
|
pub enable: bool,
|
|
pub base_url: Option<String>,
|
|
/// `null`: a key generated on first start and kept in the state directory. `false`: no
|
|
/// key (tokens are a hash of the user alone). A string: a file with the key.
|
|
pub key_file: Option<Value>,
|
|
/// Windows only: address and port the service serves the subscription files on
|
|
/// (`host:port`), since there is no web server to hand a directory to. `null`: not
|
|
/// served; `proxy-ctl inbounds sub` still prints them.
|
|
pub listen: Option<String>,
|
|
}
|
|
|
|
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
|
#[serde(rename_all = "camelCase", default, deny_unknown_fields)]
|
|
pub struct InboundRouting {
|
|
pub via: String,
|
|
pub proxy: RouteMatch,
|
|
pub block_ru: bool,
|
|
pub block_private: bool,
|
|
pub block_torrent: bool,
|
|
pub block_ports: Vec<Value>,
|
|
pub zapret_direct: bool,
|
|
}
|
|
|
|
impl Default for InboundRouting {
|
|
fn default() -> Self {
|
|
Self {
|
|
via: "proxy".into(),
|
|
proxy: RouteMatch::default(),
|
|
block_ru: true,
|
|
block_private: true,
|
|
block_torrent: true,
|
|
block_ports: vec![Value::from(25)],
|
|
zapret_direct: true,
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
|
|
#[serde(rename_all = "camelCase", default, deny_unknown_fields)]
|
|
pub struct InboundUser {
|
|
pub order: Option<u32>,
|
|
pub uuid: Option<String>,
|
|
pub uuid_file: Option<String>,
|
|
pub password: Option<String>,
|
|
pub password_file: Option<String>,
|
|
pub public_key: Option<String>,
|
|
pub private_key_file: Option<String>,
|
|
pub preshared_key_file: Option<String>,
|
|
pub address: Option<String>,
|
|
pub policy: UserPolicy,
|
|
}
|
|
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
|
|
#[serde(rename_all = "lowercase")]
|
|
pub enum TrafficPeriod {
|
|
Daily,
|
|
Weekly,
|
|
Monthly,
|
|
}
|
|
|
|
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
|
#[serde(rename_all = "camelCase", default, deny_unknown_fields)]
|
|
pub struct UserPolicy {
|
|
pub enabled: bool,
|
|
/// A date, an ISO time, or a Unix time.
|
|
pub expires_at: Option<Value>,
|
|
/// Seconds, or a number with m, h, d or w.
|
|
pub expires_after: Option<Value>,
|
|
/// Bytes, or a number with K, M, G, T.
|
|
pub traffic_limit: Option<Value>,
|
|
pub traffic_period: Option<TrafficPeriod>,
|
|
pub ip_limit: Option<u32>,
|
|
}
|
|
|
|
impl Default for UserPolicy {
|
|
fn default() -> Self {
|
|
Self {
|
|
enabled: true,
|
|
expires_at: None,
|
|
expires_after: None,
|
|
traffic_limit: None,
|
|
traffic_period: None,
|
|
ip_limit: None,
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
|
|
#[serde(rename_all = "lowercase")]
|
|
pub enum InboundType {
|
|
Vless,
|
|
Vmess,
|
|
Trojan,
|
|
Hysteria2,
|
|
Shadowsocks,
|
|
Socks,
|
|
Http,
|
|
Amneziawg,
|
|
}
|
|
|
|
impl InboundType {
|
|
pub fn as_str(self) -> &'static str {
|
|
match self {
|
|
Self::Vless => "vless",
|
|
Self::Vmess => "vmess",
|
|
Self::Trojan => "trojan",
|
|
Self::Hysteria2 => "hysteria2",
|
|
Self::Shadowsocks => "shadowsocks",
|
|
Self::Socks => "socks",
|
|
Self::Http => "http",
|
|
Self::Amneziawg => "amneziawg",
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
|
#[serde(rename_all = "camelCase", default, deny_unknown_fields)]
|
|
pub struct InboundListener {
|
|
#[serde(rename = "type")]
|
|
pub kind: Option<InboundType>,
|
|
pub port: u16,
|
|
pub share_port: Option<u16>,
|
|
pub share_address: Option<String>,
|
|
pub address: String,
|
|
pub accept_proxy_protocol: bool,
|
|
pub share_fingerprint: Option<String>,
|
|
pub share_variants: Vec<ShareVariant>,
|
|
pub via: Option<String>,
|
|
pub order: i64,
|
|
pub users: Vec<String>,
|
|
pub flow: Option<String>,
|
|
pub method: String,
|
|
pub server_password: Option<String>,
|
|
pub server_password_file: Option<String>,
|
|
pub transport: InboundTransport,
|
|
pub tls: InboundTls,
|
|
pub reality: Reality,
|
|
pub fallbacks: Vec<Fallback>,
|
|
pub xray_json: Option<Map<String, Value>>,
|
|
pub json_file: Option<String>,
|
|
pub hysteria: Hysteria,
|
|
pub amnezia_wg: AwgServer,
|
|
}
|
|
|
|
impl Default for InboundListener {
|
|
fn default() -> Self {
|
|
Self {
|
|
kind: None,
|
|
port: 443,
|
|
share_port: None,
|
|
share_address: None,
|
|
address: "::".into(),
|
|
accept_proxy_protocol: false,
|
|
share_fingerprint: Some("chrome".into()),
|
|
share_variants: Vec::new(),
|
|
via: None,
|
|
order: 1000,
|
|
users: Vec::new(),
|
|
flow: None,
|
|
method: "2022-blake3-aes-128-gcm".into(),
|
|
server_password: None,
|
|
server_password_file: None,
|
|
transport: InboundTransport::default(),
|
|
tls: InboundTls::default(),
|
|
reality: Reality::default(),
|
|
fallbacks: Vec::new(),
|
|
xray_json: None,
|
|
json_file: None,
|
|
hysteria: Hysteria::default(),
|
|
amnezia_wg: AwgServer::default(),
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
|
|
#[serde(rename_all = "camelCase", default, deny_unknown_fields)]
|
|
pub struct ShareVariant {
|
|
pub name: String,
|
|
pub fingerprint: Option<String>,
|
|
pub alpn: Option<Vec<String>>,
|
|
pub mode: Option<String>,
|
|
pub address: Option<String>,
|
|
pub server_name: Option<String>,
|
|
pub port_hopping: Option<bool>,
|
|
}
|
|
|
|
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
|
#[serde(rename_all = "camelCase", default, deny_unknown_fields)]
|
|
pub struct InboundTransport {
|
|
#[serde(rename = "type")]
|
|
pub kind: String,
|
|
pub path: String,
|
|
pub host: Option<String>,
|
|
pub mode: Option<String>,
|
|
pub service_name: String,
|
|
pub trusted_x_forwarded_for: Vec<String>,
|
|
}
|
|
|
|
impl Default for InboundTransport {
|
|
fn default() -> Self {
|
|
Self {
|
|
kind: "raw".into(),
|
|
path: "/".into(),
|
|
host: None,
|
|
mode: None,
|
|
service_name: String::new(),
|
|
trusted_x_forwarded_for: Vec::new(),
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
|
|
#[serde(rename_all = "camelCase", default, deny_unknown_fields)]
|
|
pub struct InboundTls {
|
|
pub enable: bool,
|
|
pub certificate_file: Option<String>,
|
|
pub key_file: Option<String>,
|
|
pub server_name: Option<String>,
|
|
pub alpn: Option<Vec<String>>,
|
|
}
|
|
|
|
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
|
#[serde(rename_all = "camelCase", default, deny_unknown_fields)]
|
|
pub struct Reality {
|
|
pub enable: bool,
|
|
pub dest: String,
|
|
pub server_names: Vec<String>,
|
|
pub private_key_file: Option<String>,
|
|
pub private_key: Option<String>,
|
|
pub public_key: Option<String>,
|
|
pub short_ids: Vec<String>,
|
|
pub xver: u8,
|
|
}
|
|
|
|
impl Default for Reality {
|
|
fn default() -> Self {
|
|
Self {
|
|
enable: false,
|
|
dest: "www.microsoft.com:443".into(),
|
|
server_names: Vec::new(),
|
|
private_key_file: None,
|
|
private_key: None,
|
|
public_key: None,
|
|
short_ids: vec![String::new()],
|
|
xver: 0,
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
|
|
#[serde(rename_all = "camelCase", default, deny_unknown_fields)]
|
|
pub struct Fallback {
|
|
pub name: Option<String>,
|
|
pub alpn: Option<String>,
|
|
pub path: Option<String>,
|
|
pub dest: Option<Value>,
|
|
pub listener: Option<String>,
|
|
pub xver: u8,
|
|
}
|
|
|
|
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
|
#[serde(rename_all = "camelCase", default, deny_unknown_fields)]
|
|
pub struct Hysteria {
|
|
pub masquerade: Option<String>,
|
|
pub rewrite_host: bool,
|
|
pub x_forwarded: bool,
|
|
pub salamander: Salamander,
|
|
/// Upstream redirects the range with nftables; Windows has no such redirect, so here it
|
|
/// only goes into share links for a front that does it.
|
|
pub port_hopping: Option<String>,
|
|
}
|
|
|
|
impl Default for Hysteria {
|
|
fn default() -> Self {
|
|
Self {
|
|
masquerade: None,
|
|
rewrite_host: true,
|
|
x_forwarded: false,
|
|
salamander: Salamander::default(),
|
|
port_hopping: None,
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
|
|
#[serde(rename_all = "camelCase", default, deny_unknown_fields)]
|
|
pub struct Salamander {
|
|
pub enable: bool,
|
|
pub password: Option<String>,
|
|
pub password_file: Option<String>,
|
|
}
|
|
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Serialize, Deserialize)]
|
|
#[serde(rename_all = "lowercase")]
|
|
pub enum AwgServerMode {
|
|
#[default]
|
|
Proxy,
|
|
Lan,
|
|
}
|
|
|
|
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
|
#[serde(rename_all = "camelCase", default, deny_unknown_fields)]
|
|
pub struct AwgServer {
|
|
pub mode: AwgServerMode,
|
|
/// `null`: `awgi-<tag>`.
|
|
pub interface_name: Option<String>,
|
|
pub subnet: String,
|
|
pub subnet6: Option<String>,
|
|
pub private_key_file: Option<String>,
|
|
pub obfuscation: AwgObfuscation,
|
|
pub dns: Vec<String>,
|
|
pub mtu: Option<u32>,
|
|
pub persistent_keepalive: Option<u32>,
|
|
#[serde(rename = "clientAllowedIPs")]
|
|
pub client_allowed_ips: Vec<String>,
|
|
}
|
|
|
|
impl Default for AwgServer {
|
|
fn default() -> Self {
|
|
Self {
|
|
mode: AwgServerMode::Proxy,
|
|
interface_name: None,
|
|
subnet: "10.66.0.0/24".into(),
|
|
subnet6: None,
|
|
private_key_file: None,
|
|
obfuscation: AwgObfuscation::default(),
|
|
dns: vec!["1.1.1.1".into(), "1.0.0.1".into()],
|
|
mtu: None,
|
|
persistent_keepalive: Some(25),
|
|
client_allowed_ips: vec!["0.0.0.0/0".into(), "::/0".into()],
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
|
#[serde(rename_all = "camelCase", default, deny_unknown_fields)]
|
|
pub struct Manager {
|
|
pub enable: bool,
|
|
pub interval: u32,
|
|
pub api: ManagerApi,
|
|
pub subscriptions: ManagerSubscriptions,
|
|
pub delete_expired_after: Option<String>,
|
|
pub ip_limit: IpLimit,
|
|
pub notify: Notify,
|
|
pub webhooks: Vec<Webhook>,
|
|
}
|
|
|
|
impl Default for Manager {
|
|
fn default() -> Self {
|
|
Self {
|
|
enable: false,
|
|
interval: 30,
|
|
api: ManagerApi::default(),
|
|
subscriptions: ManagerSubscriptions::default(),
|
|
delete_expired_after: None,
|
|
ip_limit: IpLimit::default(),
|
|
notify: Notify::default(),
|
|
webhooks: Vec::new(),
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
|
|
#[serde(rename_all = "camelCase", default, deny_unknown_fields)]
|
|
pub struct ManagerApi {
|
|
pub listen: Option<String>,
|
|
pub tokens_file: Option<String>,
|
|
}
|
|
|
|
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
|
#[serde(rename_all = "camelCase", default, deny_unknown_fields)]
|
|
pub struct ManagerSubscriptions {
|
|
pub enable: bool,
|
|
pub listen: Option<String>,
|
|
pub profile_title: String,
|
|
pub update_interval: Option<u32>,
|
|
pub support_url: Option<String>,
|
|
pub web_page_url: Option<String>,
|
|
}
|
|
|
|
impl Default for ManagerSubscriptions {
|
|
fn default() -> Self {
|
|
Self {
|
|
enable: true,
|
|
listen: None,
|
|
profile_title: "{user}".into(),
|
|
update_interval: Some(12),
|
|
support_url: None,
|
|
web_page_url: None,
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
|
#[serde(rename_all = "camelCase", default, deny_unknown_fields)]
|
|
pub struct IpLimit {
|
|
pub ban_time: u32,
|
|
}
|
|
|
|
impl Default for IpLimit {
|
|
fn default() -> Self {
|
|
Self { ban_time: 600 }
|
|
}
|
|
}
|
|
|
|
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
|
#[serde(rename_all = "camelCase", default, deny_unknown_fields)]
|
|
pub struct Notify {
|
|
pub traffic_percent: Vec<u32>,
|
|
pub expiry_days: Vec<u32>,
|
|
}
|
|
|
|
impl Default for Notify {
|
|
fn default() -> Self {
|
|
Self { traffic_percent: vec![80, 100], expiry_days: vec![3, 1] }
|
|
}
|
|
}
|
|
|
|
#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
|
|
#[serde(rename_all = "camelCase", default, deny_unknown_fields)]
|
|
pub struct Webhook {
|
|
pub url: String,
|
|
pub events: Vec<String>,
|
|
pub secret_file: Option<String>,
|
|
}
|