initial commit
Some checks failed
continuous-integration/drone Build is failing

Signed-off-by: Jochen Maes <jochen@sejo-it.be>
This commit is contained in:
Jochen Maes 2023-10-24 08:29:31 +02:00
commit 35d5369c76
6 changed files with 61 additions and 0 deletions

20
.drone.yml Normal file
View File

@ -0,0 +1,20 @@
kind: pipeline
type: docker
name: "Wimi builder"
platform:
arch: arm64
steps:
- name: build
image: rust:1.73
commands:
- cargo build --target aarch64-unknown-linux-gnu
- name: publish image
image: plugins/docker
settings:
username: builder
password:
from_secret: builder_password
repo: https://gitea.sejo-it.be/v2/SeJo-IT/wimi
tags:
- latest

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/target

7
Cargo.lock generated Normal file
View File

@ -0,0 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "wimi"
version = "0.1.0"

8
Cargo.toml Normal file
View File

@ -0,0 +1,8 @@
[package]
name = "wimi"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]

3
Dockerfile Normal file
View File

@ -0,0 +1,3 @@
FROM scratch
COPY target/aarch64-unknown-linux-gnu/release/wimi /wimi
CMD ["/wimi"]

22
src/main.rs Normal file
View File

@ -0,0 +1,22 @@
use std::{net::{TcpListener, TcpStream}, io::{Write}};
fn main() {
let listener = TcpListener::bind("[::]:4242").unwrap();
for stream in listener.incoming() {
let stream = stream.unwrap();
throw_ip_back(stream);
}
}
fn throw_ip_back(mut stream: TcpStream) {
let status_line = "HTTP/1.1 200 OK";
let raw_addr = stream.peer_addr().unwrap().ip().to_string();
println!("{}", raw_addr);
let content = format!("HTTP/1.1 200 OK {}",raw_addr.replace("::ffff:", ""));
let length = content.len();
let response = format!("{status_line}\r\nContent-Length: {length}\r\n\r\n{content}");
stream.write_all(response.as_bytes()).unwrap();
}