Initial commit
This commit is contained in:
commit
d41ecd9fd2
12 changed files with 175 additions and 0 deletions
1
.envrc
Normal file
1
.envrc
Normal file
|
|
@ -0,0 +1 @@
|
|||
use nix
|
||||
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
/target
|
||||
.direnv/
|
||||
7
Cargo.lock
generated
Normal file
7
Cargo.lock
generated
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 4
|
||||
|
||||
[[package]]
|
||||
name = "poxy"
|
||||
version = "0.1.0"
|
||||
6
Cargo.toml
Normal file
6
Cargo.toml
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
[package]
|
||||
name = "poxy"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
41
README.md
Normal file
41
README.md
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
# poxy: Proxy Epoxy
|
||||
|
||||
Poxy is networking epoxy using proxies: A multitool to glue real-world devices together.
|
||||
Redirect connections, bypass NAT, and much more.
|
||||
|
||||
## Easy and unified config format
|
||||
|
||||
Config is done using a simple format:
|
||||
|
||||
```
|
||||
tudbutde @ tudbut.de:
|
||||
!LISTEN ::0:80/tcp -> #mainhttp
|
||||
!LISTEN ::0:55699/udp -> #wgexit
|
||||
|
||||
tudbut-wgexit @ s2.tudbut.de:
|
||||
#wgexit -> !OUT localhost:55699/udp
|
||||
|
||||
tud-pi-purple:
|
||||
#mainhttp -> NAT -> !OUT localhost:80/tcp
|
||||
|
||||
computer:
|
||||
!LISTEN localhost:7022/tcp -> #sshproxy
|
||||
|
||||
friendscomputer:
|
||||
#sshproxy -> NAT via tudbutde -> !OUT localhost:22/tcp
|
||||
```
|
||||
|
||||
This can also be written as:
|
||||
|
||||
```
|
||||
tudbutde @ tudbut.de:
|
||||
!LISTEN ::0:80/tcp -> NAT -> !OUT +tud-pi-purple:80/tcp
|
||||
!LISTEN ::0:55699/udp -> !OUT +tudbut-wgexit:55699/udp
|
||||
|
||||
tudbut-wgexit @ s2.tudbut.de:
|
||||
|
||||
computer:
|
||||
!LISTEN localhost:7022/tcp -> NAT via +tudbutde -> !OUT +friendscomputer:22/tcp
|
||||
```
|
||||
|
||||
!LISTEN is equivalent to !INPUT.
|
||||
9
shell.nix
Normal file
9
shell.nix
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
{ pkgs ? import <nixpkgs> {} }:
|
||||
pkgs.mkShell {
|
||||
nativeBuildInputs = with pkgs; [
|
||||
cargo
|
||||
helix
|
||||
rust-analyzer
|
||||
cargo-watch
|
||||
];
|
||||
}
|
||||
18
src/directive.rs
Normal file
18
src/directive.rs
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
use crate::*;
|
||||
|
||||
impl Directive {
|
||||
pub(crate) fn populate(&mut self, host: &PoxyHost) {
|
||||
match self {
|
||||
Directive::Input(_netif, _protocol) => (),
|
||||
Directive::Output(poxy_output, _protocol) => {
|
||||
poxy_output.populate(host);
|
||||
}
|
||||
Directive::Label(_) => (),
|
||||
Directive::NatTraversal(poxy_host) => {
|
||||
if poxy_host.is_some_and(|x| x == "localhost") {
|
||||
*poxy_host = Some(host.hostname);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
50
src/lib.rs
Normal file
50
src/lib.rs
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
mod directive;
|
||||
mod network;
|
||||
mod path;
|
||||
mod poxy_output;
|
||||
use std::sync::Arc;
|
||||
|
||||
#[derive(Clone, PartialEq, Eq)]
|
||||
pub enum PoxyOutput {
|
||||
Realworld(Option<String>, String),
|
||||
OtherPoxy(String),
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq, Eq)]
|
||||
pub struct PoxyHost {
|
||||
hostname: String,
|
||||
www_address: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, PartialEq, Eq)]
|
||||
pub enum Protocol {
|
||||
Tcp,
|
||||
Udp,
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq, Eq)]
|
||||
pub enum Directive {
|
||||
Input(String, Protocol),
|
||||
Output(PoxyOutput, Protocol),
|
||||
Label(String),
|
||||
NatTraversal(Option<String>),
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq, Eq)]
|
||||
pub struct PathElement {
|
||||
pub previous: Option<OtherPathElement>,
|
||||
pub next: Option<OtherPathElement>,
|
||||
pub inner: Directive,
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq, Eq)]
|
||||
pub struct OtherPathElement {
|
||||
network: Arc<Network>,
|
||||
path: usize,
|
||||
index: usize,
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq, Eq)]
|
||||
pub struct Network {
|
||||
paths: Vec<(PoxyHost, Vec<PathElement>)>,
|
||||
}
|
||||
3
src/main.rs
Normal file
3
src/main.rs
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
fn main() {
|
||||
println!("Hello, world!");
|
||||
}
|
||||
23
src/network.rs
Normal file
23
src/network.rs
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
use std::collections::HashMap;
|
||||
|
||||
use crate::*;
|
||||
|
||||
impl Network {
|
||||
pub fn clean(&self) -> Network {
|
||||
let mut label_map = HashMap::new();
|
||||
for (host, path) in &self.paths {
|
||||
match path[0].inner {
|
||||
Directive::Label(ref label) => {
|
||||
label_map.insert(label.to_owned(), (host.clone(), path.clone()));
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
for (_k, v) in &mut label_map {
|
||||
for node in &mut v.1 {
|
||||
node.inner.populate(&v.0);
|
||||
}
|
||||
}
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
3
src/path.rs
Normal file
3
src/path.rs
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
use crate::*;
|
||||
|
||||
impl PathElement {}
|
||||
12
src/poxy_output.rs
Normal file
12
src/poxy_output.rs
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
use crate::*;
|
||||
|
||||
impl PoxyOutput {
|
||||
pub(crate) fn populate(&mut self, host: &PoxyHost) {
|
||||
match self {
|
||||
PoxyOutput::Realworld(x @ None, _) => {
|
||||
*x = Some(host.hostname.clone());
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue