-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
88 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
FROM rust:1.71 as build | ||
WORKDIR /ipmon | ||
COPY . . | ||
RUN cargo build --bin ipmon-server --release | ||
|
||
FROM debian:bullseye-slim | ||
WORKDIR /app | ||
COPY --from=build /ipmon/target/release/ipmon-server ./ | ||
ENTRYPOINT ["/app/ipmon-server"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
use std::net::SocketAddr; | ||
|
||
use axum::{extract::ConnectInfo, http::header::HeaderMap, routing::get, Router}; | ||
|
||
#[tokio::main] | ||
async fn main() { | ||
simple_logger::init_with_level(log::Level::Info).unwrap(); | ||
|
||
// build our application with a route | ||
let app = Router::new().route("/", get(handler)); | ||
|
||
axum::Server::bind(&"127.0.0.1:8080".parse().unwrap()) | ||
.serve(app.into_make_service_with_connect_info::<SocketAddr>()) | ||
.await | ||
.unwrap(); | ||
} | ||
|
||
async fn handler(headers: HeaderMap, ConnectInfo(addr): ConnectInfo<SocketAddr>) -> String { | ||
let client_ip; | ||
if headers.contains_key("X-Real-Ip") { | ||
client_ip = headers["X-Real-Ip"].to_str().unwrap().to_owned(); | ||
} else if headers.contains_key("X-Forwarded-For") { | ||
client_ip = headers["X-Forwarded-For"].to_str().unwrap().to_owned(); | ||
} else { | ||
client_ip = addr.to_string(); | ||
} | ||
client_ip | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
pub mod platform; | ||
pub mod twilio; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
pub fn is_debug() -> bool { | ||
cfg!(debug_assertions) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters