Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 71 additions & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

61 changes: 61 additions & 0 deletions anet-server/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{
"version": "0.2.0",
"configurations": [
{
"type": "lldb",
"request": "launch",
"name": "Debug anet-server",
"cargo": {
"args": [
"build",
"--bin",
"anet-server"
],
"filter": {
"name": "anet-server",
"kind": "bin"
}
},
"args": [
"-c",
"/home/lis/Documents/coded/anet-fork/contrib/dev/server.toml"
],
"cwd": "${workspaceFolder}"
},
{
"name": "Attach anet-server",
"type": "lldb",
"request": "attach",
"program": "${workspaceFolder}/target/debug/anet-server",
"pid": "${command:pickProcess}"
},
{
"name": "Debug anet-server (sudo)",
"type": "lldb",
"request": "launch",

"program": "/home/lis/Documents/coded/anet-fork/target/debug/anet-server",

"args": [
"-c",
"/home/lis/Documents/coded/anet-fork/contrib/dev/server.toml"
],

"cwd": "/home/lis/Documents/coded/anet-fork",

"preLaunchTask": "cargo build",

"initCommands": [
"platform select remote-linux"
],

"pipeTransport": {
"pipeProgram": "sudo",
"pipeArgs": [
"-E"
],
"debuggerPath": "/usr/bin/lldb-server"
}
}
]
}
5 changes: 5 additions & 0 deletions anet-server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ ed25519-dalek = {workspace = true}
async-trait = { workspace = true }
futures = { workspace = true }

sea-orm = { version = "1", features = ["sqlx-postgres", "sqlx-sqlite", "runtime-tokio-rustls"] }

directories = "5"

russh = "0.45"
russh-keys = "0.45"

Expand All @@ -33,6 +37,7 @@ arc-swap = "1.6"
reqwest = { version = "0.12", default-features = false, features = ["json", "rustls-tls"] }

anet-common = { path = "../anet-common" }
sea-orm-migration = "1.1.20"

[[bin]]
name = "anet-server"
Expand Down
2 changes: 1 addition & 1 deletion anet-server/src/auth_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ impl ServerAuthHandler {
};
if req.client_id != temp_info.client_fingerprint { return Err(anyhow::anyhow!("Client ID mismatch")); }

let assigned_ip = self.registry.allocate_ip().context("IP POOL FOOL")?.to_string();
let assigned_ip = self.registry.allocate_ip(temp_info.client_fingerprint.clone()).await.context("IP POOL FOOL")?.to_string();
let session_id = generate_seid();
let nonce_prefix = generate_unique_nonce_prefix(self.registry.clone());

Expand Down
9 changes: 2 additions & 7 deletions anet-server/src/client_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,9 @@ impl ClientRegistry {
let client_ip = &client_info.assigned_ip;
let remote_addr = **client_info.remote_addr.load();

self.quic_router.remove(client_ip);
self.clients_by_prefix.remove(&client_info.nonce_prefix);
self.clients_by_addr.remove(&remote_addr);

if let Ok(ip_addr) = client_ip.parse::<Ipv4Addr>() {
self.ip_pool.release(ip_addr);
}

// dec sessions
let ap = self.auth_provider.clone();
let fp = client_info.fingerprint.clone();
Expand All @@ -92,8 +87,8 @@ impl ClientRegistry {
info!("[Registry] Client {} removed.", client_ip);
}

pub fn allocate_ip(&self) -> Option<Ipv4Addr> {
self.ip_pool.allocate()
pub async fn allocate_ip(&self, fingerprint: String) -> Result<Ipv4Addr, anyhow::Error> {
self.ip_pool.allocate(fingerprint).await
}

pub fn get_by_addr(&self, remote_addr: &SocketAddr) -> Option<Arc<ClientTransportInfo>> {
Expand Down
3 changes: 3 additions & 0 deletions anet-server/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ pub struct ServerCoreConfig {
pub ssh_bind_to: String,
pub vnc_bind_to: String,
pub ssh_host_key: String,
pub db_url: Option<String>,
}

impl Default for ServerCoreConfig {
Expand All @@ -106,6 +107,7 @@ impl Default for ServerCoreConfig {
ssh_bind_to: "0.0.0.0:822".to_string(),
vnc_bind_to: "0.0.0.0:5900".to_string(),
ssh_host_key: "/etc/ssh/ssh_host_rsa_key".to_string(),
db_url: None,
}
}
}
Expand All @@ -129,6 +131,7 @@ pub struct Config {

#[serde(default)]
pub stealth: StealthConfig,

}

#[derive(Debug, Parser)]
Expand Down
43 changes: 43 additions & 0 deletions anet-server/src/db.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
use anyhow::Result;
use directories::ProjectDirs;
use sea_orm::{Database, DatabaseConnection};
use std::fs;
use sea_orm_migration::MigratorTrait;

use crate::migration;

#[derive(Clone)]
pub struct AnetDB {
}

impl AnetDB {

pub async fn connect_db(url : Option<String>) -> Result<DatabaseConnection, sea_orm::DbErr> {
let db_url = match url{
Some(url) => url,
None => {
// ~/.local/share/myapp/
let proj_dirs = ProjectDirs::from("org", "alco","anet")
.expect("failed to get project dirs");

let data_dir = proj_dirs.data_dir();

fs::create_dir_all(data_dir).expect("failed to create data dir");

let db_path = data_dir.join("db.sqlite");

format!("sqlite://{}?mode=rwc", db_path.display())
}
};

println!("DB: {}", db_url);


let db: DatabaseConnection =
Database::connect(db_url)
.await?;

migration::Migrator::up(&db, None).await?;
Ok(db)
}
}
17 changes: 17 additions & 0 deletions anet-server/src/entities/clients.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};

#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Serialize, Deserialize)]
#[sea_orm(table_name = "clients")]
pub struct Model {
#[sea_orm(primary_key, column_type = "Text")]
pub fingerprint: String,
pub ip: i64,

pub created_at: DateTime,
pub updated_at: DateTime,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {}

impl ActiveModelBehavior for ActiveModel {}
1 change: 1 addition & 0 deletions anet-server/src/entities/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod clients;
Loading