hand

finger proxy server
Log | Files | Refs | README

commit 1204988bbe282683d6d159fb9e09c92f817af4a8
parent cabf3698b95b22ca73ac726d90dca782ce956c1d
Author: alex wennerberg <alex@alexwennerberg.com>
Date:   Thu,  2 Dec 2021 00:08:10 -0800

Very simple working proxy

Diffstat:
Msrc/main.rs | 41++++++++++++++++++++++++++++++-----------
1 file changed, 30 insertions(+), 11 deletions(-)

diff --git a/src/main.rs b/src/main.rs @@ -1,22 +1,41 @@ +use fingers; use vial::prelude::*; routes! { - GET "/echo" => echo; - POST "/echo" => post; + GET "/" => index; + POST "/" => post; } -fn echo(_: Request) -> &'static str { - "<form method='POST'> - <input type='text' name='echo'/> - <input type='submit'/> - </form>" +const form: &str = "<style> +</style> +<h1>👉</h1> +<form method='POST'> +<input type='text' placeholder='e.g. alex@flounder.online' name='query'/> +<input type='submit'/> +</form>"; + +fn index(_: Request) -> &'static str { + form } fn post(req: Request) -> String { - format!( - "<h1>You said: {}</h1>", - req.form("echo").unwrap_or("You didn't say anything!") - ) + let query = req.form("query").unwrap(); + let user: &str; + let host: &str; + let params: Vec<&str> = query.split("@").collect(); + if params.len() == 1 { + host = params[0]; + user = ""; + } else { + user = params[0]; + host = params[1]; + } + let response = fingers::finger(user, host) + .timeout(10) + .max_response_len(1024 * 10) + .send() + .unwrap(); + format!("{}\n<pre class='response'>{}</pre>", form, response) } fn main() {