Skip to content

Commit

Permalink
Merge pull request #115 from kralverde/ip_scrub
Browse files Browse the repository at this point in the history
Add config option to scrub ips from logs
  • Loading branch information
Snowiiii authored Oct 14, 2024
2 parents 68b0a49 + 47208e9 commit ee4db10
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
8 changes: 8 additions & 0 deletions docs/config/basic.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,11 @@ Creative
Adventure
Spectator
```

### IP Scrubbing

Whether to scrub player IPs from logs

```toml
scrub_ips=true
```
4 changes: 4 additions & 0 deletions pumpkin-config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ pub struct BasicConfiguration {
/// The default game mode for players.
#[serde_inline_default(GameMode::Survival)]
pub default_gamemode: GameMode,
/// Whether to remove IPs from logs or not
#[serde_inline_default(true)]
pub scrub_ips: bool,
}

fn default_server_address() -> SocketAddr {
Expand All @@ -115,6 +118,7 @@ impl Default for BasicConfiguration {
encryption: true,
motd: "A Blazing fast Pumpkin Server!".to_string(),
default_gamemode: GameMode::Survival,
scrub_ips: true,
}
}
}
Expand Down
16 changes: 15 additions & 1 deletion pumpkin/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,17 @@ pub mod rcon;
pub mod server;
pub mod world;

fn scrub_address(ip: &str) -> String {
use pumpkin_config::BASIC_CONFIG;
if BASIC_CONFIG.scrub_ips {
ip.chars()
.map(|ch| if ch == '.' || ch == ':' { ch } else { 'x' })
.collect()
} else {
ip.to_string()
}
}

fn init_logger() {
use pumpkin_config::ADVANCED_CONFIG;
if ADVANCED_CONFIG.logging.enabled {
Expand Down Expand Up @@ -196,7 +207,10 @@ fn main() -> io::Result<()> {
log::warn!("failed to set TCP_NODELAY {e}");
}

log::info!("Accepted connection from: {}", address);
log::info!(
"Accepted connection from: {}",
scrub_address(&format!("{}", address))
);

let token = next(&mut unique_token);
poll.registry().register(
Expand Down

0 comments on commit ee4db10

Please sign in to comment.