79 Commits
v1.2 ... master

Author SHA1 Message Date
xfy
c0a7a1661f chore(api): change backend address 2025-04-01 11:01:19 +08:00
xfy
07f40c5edb chore(rust): update rust 1.8.0 support 2025-04-01 10:57:18 +08:00
19c83b02da Merge branch 'ci/gitlab' 2023-05-12 14:41:54 +08:00
52f00ac563 Merge branch 'ci/gitlab' 2023-05-12 14:41:06 +08:00
c1899bcbdd Update .gitlab-ci.yml file 2023-05-12 06:40:55 +00:00
baabfadda5 Update .gitlab-ci.yml file 2023-05-12 06:39:20 +00:00
bdafa0d086 Merge from ci 2023-05-12 14:38:22 +08:00
0de4fe7a67 Update .gitlab-ci.yml file 2023-05-12 03:51:31 +00:00
1e1c5e6e83 Update .gitlab-ci.yml file 2023-05-12 03:51:16 +00:00
df5ac42963 Update .gitlab-ci.yml file 2023-05-12 02:13:23 +00:00
0c2ef39aca Update .gitlab-ci.yml file 2023-05-12 01:15:46 +00:00
4ad81b4aff Update .gitlab-ci.yml file 2023-05-11 09:34:52 +00:00
91c4328b7d Update .gitlab-ci.yml file
Update .gitlab-ci.yml file

Update .gitlab-ci.yml file

Update .gitlab-ci.yml file
2023-05-11 09:10:51 +08:00
05f4f669a9 update git ignore
Update .gitlab-ci.yml file

Update .gitlab-ci.yml file

Update .gitlab-ci.yml file

Update .gitlab-ci.yml file

Update .gitlab-ci.yml file

Update .gitlab-ci.yml file

Update .gitlab-ci.yml file

Update .gitlab-ci.yml file

Update .gitlab-ci.yml file

Update .gitlab-ci.yml file

Update .gitlab-ci.yml file

Update .gitlab-ci.yml file
2023-05-11 09:10:50 +08:00
af55be9eca update ci image
Update .gitlab-ci.yml file

Update .gitlab-ci.yml file

Update .gitlab-ci.yml file

Update .gitlab-ci.yml file
2023-05-11 09:10:49 +08:00
507e392f69 update mingw builder 2023-05-11 09:10:48 +08:00
6d139f30d7 Add docker build file 2023-05-11 09:10:48 +08:00
021e90af62 Remove todos
Update .gitlab-ci.yml file

Update .gitlab-ci.yml file

Update .gitlab-ci.yml file
2023-05-11 09:10:48 +08:00
336f090a49 Merge branch 'ci/gitlab' of git.rua.plus:xfy/rua-list into ci/gitlab 2023-05-11 09:10:47 +08:00
a6b327c97f Remove todos 2023-05-11 09:10:47 +08:00
18753b6679 Add do not handle non-utf8 headers
Update .gitlab-ci.yml file
2023-05-11 09:10:47 +08:00
1108d92d78 Add do not handle non-utf8 headers 2023-05-11 09:10:47 +08:00
4c802ba781 Update error handle 2023-05-11 09:10:47 +08:00
f2288667d1 Fix linker
Update .gitlab-ci.yml file

Update .gitlab-ci.yml file
2023-05-11 09:10:47 +08:00
9a648cf408 Update linker 2023-05-11 09:10:46 +08:00
66a2efa9e4 Update cross-platform linker
Update .gitlab-ci.yml file
2023-05-11 09:10:46 +08:00
896d439728 Update .gitlab-ci.yml file
Update .gitlab-ci.yml file
2023-05-11 09:10:46 +08:00
bd60a2b7f9 Update .gitlab-ci.yml file 2023-05-11 01:09:17 +00:00
a0df34128d Update .gitlab-ci.yml file 2023-05-10 07:38:32 +00:00
e9033358fa Update .gitlab-ci.yml file 2023-05-10 03:27:44 +00:00
ed06d0becc Update .gitlab-ci.yml file 2023-05-10 03:14:25 +00:00
a350bee7a6 Update .gitlab-ci.yml file 2023-05-10 03:10:31 +00:00
6ceb03d674 Update .gitlab-ci.yml file 2023-05-09 09:56:09 +00:00
54e53782aa Update .gitlab-ci.yml file 2023-05-09 09:45:43 +00:00
dd2158ab46 Update .gitlab-ci.yml file 2023-05-09 09:38:31 +00:00
9863348b8a Update .gitlab-ci.yml file 2023-05-09 09:30:20 +00:00
6a248c51ad Update .gitlab-ci.yml file 2023-05-09 09:29:53 +00:00
ae1ca2bf44 Update .gitlab-ci.yml file 2023-05-09 09:28:31 +00:00
3e2b2b006c Update .gitlab-ci.yml file 2023-05-09 09:19:54 +00:00
83f47e223d Update .gitlab-ci.yml file 2023-05-09 09:18:08 +00:00
7ca9b02370 Update .gitlab-ci.yml file 2023-05-09 09:17:39 +00:00
e4f2216d23 Update .gitlab-ci.yml file 2023-05-09 09:15:34 +00:00
d48dbcb230 Update .gitlab-ci.yml file 2023-05-09 08:11:26 +00:00
c66137f842 update git ignore 2023-05-09 16:09:21 +08:00
e1ebde7e50 Update .gitlab-ci.yml file 2023-05-09 07:51:42 +00:00
2703d44125 Update .gitlab-ci.yml file 2023-05-09 07:47:30 +00:00
68fd726068 Update .gitlab-ci.yml file 2023-05-09 07:28:11 +00:00
2564a2e565 Update .gitlab-ci.yml file 2023-05-09 07:24:24 +00:00
4520f5cc66 update ci image 2023-05-09 15:19:17 +08:00
88dccb53a2 update mingw builder 2023-05-09 14:41:59 +08:00
2db53cd98e Add docker build file 2023-05-08 14:06:07 +08:00
df0f87a034 Update .gitlab-ci.yml file 2023-05-08 05:42:40 +00:00
c97a46e1c3 Update .gitlab-ci.yml file 2023-05-08 05:42:18 +00:00
17531118b3 Update .gitlab-ci.yml file 2023-05-06 09:49:38 +00:00
f536b0e8c1 Remove todos 2023-05-06 17:48:59 +08:00
dcc5d43604 Merge branch 'ci/gitlab' of git.rua.plus:xfy/rua-list into ci/gitlab 2023-05-06 17:48:50 +08:00
18f2766805 Remove todos 2023-05-06 17:48:35 +08:00
478c99d949 Update .gitlab-ci.yml file 2023-05-06 09:47:04 +00:00
3d67b404a5 Add do not handle non-utf8 headers 2023-05-06 17:40:13 +08:00
75ea312c92 Update error handle 2023-05-06 17:37:16 +08:00
916c539900 Update .gitlab-ci.yml file 2023-05-06 09:26:03 +00:00
ffaacc7851 Update .gitlab-ci.yml file 2023-05-06 09:12:46 +00:00
e2bab674e7 Fix linker 2023-05-06 15:56:49 +08:00
4e2d699a00 Update linker 2023-05-06 15:29:51 +08:00
2251fc57ca Update .gitlab-ci.yml file 2023-05-06 07:25:49 +00:00
65332d953d Update cross-platform linker 2023-05-06 15:16:48 +08:00
b1474f7125 Update .gitlab-ci.yml file 2023-05-06 06:17:42 +00:00
78a47c3cf6 Update .gitlab-ci.yml file 2023-05-06 06:16:34 +00:00
4638df0bab Add gitlab ci 2023-05-06 14:04:45 +08:00
2215402860 Refactor tests 2023-05-06 13:55:58 +08:00
79e204d80d Add cargo config file 2023-05-04 17:57:55 +08:00
f1d8deaaf2 Add todo 2023-05-04 15:27:57 +08:00
29bb64cf70 Fix dependencies 2023-05-04 14:26:03 +08:00
a1c1f0bc1e Fix debug error 2023-05-04 14:18:57 +08:00
a49cabe829 Fix header parse 2023-05-04 14:17:27 +08:00
72657d6312 Update tcp connection 2023-05-04 13:59:06 +08:00
54ed3f9320 Use original server 2023-05-04 12:33:04 +08:00
13f9c04fc3 Fix start queue 2023-05-04 11:44:21 +08:00
8d07f6dcfc Add openssl 2023-05-04 11:19:42 +08:00
10 changed files with 1032 additions and 584 deletions

View File

@ -1,2 +1,5 @@
target/
.git/
.git/
config.json
logs/
.DS_Store

4
.gitignore vendored
View File

@ -1,3 +1,5 @@
/target
config.json
logs/
logs/
.DS_Store
.cargo

86
.gitlab-ci.yml Normal file
View File

@ -0,0 +1,86 @@
stages:
- build
build:linux-gnu-amd64:
stage: build
image: rust:latest
rules:
- if: $CI_COMMIT_TAG
script:
- mkdir $HOME/.cargo
- echo "[source.crates-io]" >> $HOME/.cargo/config
- echo "replace-with = 'ustc'" >> $HOME/.cargo/config
- echo "" >> $HOME/.cargo/config
- echo "[source.ustc]" >> $HOME/.cargo/config
- echo "registry = \"sparse+https://mirrors.ustc.edu.cn/crates.io-index/\"" >> $HOME/.cargo/config
- mkdir public
- cargo build --release
- "mv target/release/rua-list target/release/rua-list-x86_64-unknown-linux-gnu-$CI_COMMIT_TAG"
- "mv target/release/rua-list-x86_64-unknown-linux-gnu-$CI_COMMIT_TAG public/"
artifacts:
paths:
- "public/rua-list-x86_64-unknown-linux-gnu-$CI_COMMIT_TAG"
build:linux-musl-amd64:
stage: build
image: rust:latest
rules:
- if: $CI_COMMIT_TAG
script:
- apt update
- apt install -y musl-tools
- rustup target add x86_64-unknown-linux-musl
- cargo build --release --target x86_64-unknown-linux-musl
- mkdir public
- "mv target/x86_64-unknown-linux-musl/release/rua-list target/x86_64-unknown-linux-musl/release/rua-list-x86_64-unknown-linux-musl-$CI_COMMIT_TAG"
- "mv target/x86_64-unknown-linux-musl/release/rua-list-x86_64-unknown-linux-musl-$CI_COMMIT_TAG public/"
artifacts:
paths:
- public/rua-list-x86_64-unknown-linux-musl-$CI_COMMIT_TAG
build:windows-amd64:
stage: build
image: rust:latest
rules:
- if: $CI_COMMIT_TAG
script:
- apt update
- apt install -y g++-mingw-w64-x86-64
- rustup target add x86_64-pc-windows-gnu
- rustup toolchain install stable-x86_64-pc-windows-gnu
- cargo build --release --target x86_64-pc-windows-gnu
- mkdir public
- "mv target/x86_64-pc-windows-gnu/release/rua-list.exe target/x86_64-pc-windows-gnu/release/rua-list-x86_64-pc-windows-gnu-$CI_COMMIT_TAG.exe"
- "mv target/x86_64-pc-windows-gnu/release/rua-list-x86_64-pc-windows-gnu-$CI_COMMIT_TAG.exe public/"
artifacts:
paths:
- public/rua-list-x86_64-pc-windows-gnu-$CI_COMMIT_TAG.exe
rustdoc:
stage: build
image: rust
rules:
- if: $CI_COMMIT_TAG
script:
- cargo doc
artifacts:
paths:
- target/doc
#release_job:
# stage: release
# image: registry.gitlab.com/gitlab-org/release-cli:latest
# rules:
# - if: $CI_COMMIT_TAG # Run this job when a tag is created
# script:
# - echo "running release_job"
# release: # See https://docs.gitlab.com/ee/ci/yaml/#release for available properties
# tag_name: "$CI_COMMIT_TAG"
# description: "$CI_COMMIT_TAG"
# assets:
# links:
# - name: "rua-list-x86_64-unknown-linux-gnu-$CI_COMMIT_TAG"
# url: "https://git.rua.plus/${CI_PROJECT_NAMESPACE}/${CI_PROJECT_NAME}/cw/-/jobs/${CI_JOB_ID}/artifacts/file/public/rua-list-x86_64-unknown-linux-gnu-$CI_COMMIT_TAG"
# - name: "rua-list-x86_64-unknown-linux-musl-$CI_COMMIT_TAG"
# url: "https://git.rua.plus/${CI_PROJECT_NAMESPACE}/${CI_PROJECT_NAME}/cw/-/jobs/${CI_JOB_ID}/artifacts/file/public/rua-list-x86_64-unknown-linux-musl-$CI_COMMIT_TAG"
# - name: "ua-list-x86_64-pc-windows-gnu-$CI_COMMIT_TAG.exe"
# url: "https://git.rua.plus/${CI_PROJECT_NAMESPACE}/${CI_PROJECT_NAME}/cw/-/jobs/${CI_JOB_ID}/artifacts/file/public/ua-list-x86_64-pc-windows-gnu-$CI_COMMIT_TAG.exe"

1346
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -24,3 +24,6 @@ tracing-subscriber = "0.3.17"
tracing-appender = "0.2.2"
tracing-error = "0.2.0"
color-eyre = "0.6.2"
[target.'cfg(unix)'.dependencies]
openssl = { version = "=0.10.52", features = ["vendored"] }

View File

@ -0,0 +1,29 @@
FROM rust:latest as builder
WORKDIR /app
# Create appuser
ENV USER=xfy
ENV UID=10001
RUN adduser \
--disabled-password \
--gecos "" \
--home "/nonexistent" \
--shell "/sbin/nologin" \
--no-create-home \
--uid "${UID}" \
"${USER}" \
&& mkdir $HOME/.cargo \
&& echo "[source.crates-io]" >> $HOME/.cargo/config \
&& echo "replace-with = 'ustc'" >> $HOME/.cargo/config \
&& echo "" >> $HOME/.cargo/config \
&& echo "[source.ustc]" >> $HOME/.cargo/config \
&& echo "registry = \"sparse+https://mirrors.ustc.edu.cn/crates.io-index/\"" >> $HOME/.cargo/config \
&& apt update \
&& apt install -y g++-mingw-w64-x86-64 \
&& rustup target add x86_64-unknown-linux-musl \
&& rustup target add x86_64-pc-windows-gnu \
&& rustup toolchain install stable-x86_64-pc-windows-gnu
ENTRYPOINT [ "/bin/bash" ]

View File

@ -1,2 +1,4 @@
// Target address
pub static MSG_URL: &str = "https://swdx.kdah.cn:8011";
// pub static MSG_URL: &str = "https://swdx.kdah.cn:8011";
pub static MSG_URL: &str = "http://58.242.187.12:8011";

View File

@ -1,9 +1,10 @@
use anyhow::Result;
use log::{debug, error, info};
use std::{net::SocketAddr, process::exit, sync::Arc};
use std::{net::SocketAddr, process::exit};
use tokio::{
io::{AsyncBufReadExt, AsyncReadExt, AsyncWriteExt, BufReader},
net::{TcpListener, TcpStream},
sync::{mpsc, oneshot, Mutex},
sync::{mpsc, oneshot},
};
type Responder = oneshot::Sender<String>;
@ -31,22 +32,21 @@ pub async fn headers_parser(port: usize) {
let (tx, mut rx) = mpsc::channel::<Frame>(128);
tokio::spawn(async move {
let connector = match TcpStream::connect("127.0.0.1:3001").await {
Ok(stream) => stream,
Err(err) => {
error!("Can not request to server {}", err);
return;
}
};
let connector = Arc::new(Mutex::new(connector));
while let Some(frame) = rx.recv().await {
let connector = connector.clone();
let mut connector = connector.lock().await;
let mut connector = match TcpStream::connect("127.0.0.1:3001").await {
Ok(stream) => stream,
Err(err) => {
error!("Can not request to server {}", err);
break;
}
};
// let connector = connector.clone();
// let mut connector = connector.lock().await;
let (reader, mut writer) = connector.split();
// Forward all request without illegal headers
if let Err(err) = writer.write_all(frame.request.as_bytes()).await {
error!("Can not write to server {}", err);
return;
break;
}
let mut reader = BufReader::new(reader);
let mut res_header = String::new();
@ -88,7 +88,13 @@ pub async fn headers_parser(port: usize) {
tokio::spawn(async move {
let mut buf = BufReader::new(&mut stream);
let header = read_to_end(&mut buf).await;
let header = match read_to_end(&mut buf).await {
Ok(c) => c,
Err(err) => {
error!("Failed to read headers {}", err);
return;
}
};
let header: Vec<_> = header.split("\r\n").collect();
let first_line = header.first().unwrap();
let header = &header[1..header.len() - 2];
@ -97,7 +103,7 @@ pub async fn headers_parser(port: usize) {
// Remove all illegal headers
let header: Vec<_> = header
.iter()
.filter(|head| head.contains(':'))
.filter(|head| head.contains(':') && !head.contains(';'))
.map(|head| head.to_string())
.map(|h| {
if h.to_lowercase().starts_with("content-length") {
@ -107,6 +113,7 @@ pub async fn headers_parser(port: usize) {
h
})
.collect();
debug!("{:?}", &header);
let headers = format!("{first_line}\r\n{}\r\n\r\n", header.join("\r\n"));
// If has content-length, read request body
let request = if content_len > 0 {
@ -145,13 +152,13 @@ pub async fn headers_parser(port: usize) {
}
}
async fn read_to_end(buf: &mut BufReader<&mut TcpStream>) -> String {
async fn read_to_end(buf: &mut BufReader<&mut TcpStream>) -> Result<String> {
let mut target = String::new();
loop {
let count = buf.read_line(&mut target).await.unwrap();
let count = buf.read_line(&mut target).await?;
if count < 3 {
break;
}
}
target
Ok(target)
}

View File

@ -56,32 +56,32 @@ async fn main() -> Result<()> {
.layer(TimeoutLayer::new(Duration::from_secs(10))),
);
// Parse illegal headers
tokio::spawn(async move {
headers_parser(port).await;
});
let addr: SocketAddr = match format!("127.0.0.1:{:?}", port + 1).parse() {
let addr: SocketAddr = match format!("0.0.0.0:{:?}", port + 1).parse() {
Ok(addr) => addr,
Err(err) => {
error!("Failed to parse address {}", err);
exit(1);
}
};
match Server::bind(&addr)
.serve(app.into_make_service())
.with_graceful_shutdown(shutdown_signal())
.await
{
Ok(()) => {
info!("Server shutdown");
}
Err(err) => {
error!("Can not start server {}", err);
exit(1);
}
}
// info!("Server listening on {}", &addr);
tokio::spawn(async move {
match Server::bind(&addr)
.serve(app.into_make_service())
.with_graceful_shutdown(shutdown_signal())
.await
{
Ok(()) => {
info!("Server shutdown");
}
Err(err) => {
error!("Can not start server {}", err);
exit(1);
}
}
});
headers_parser(port).await;
Ok(())
}
@ -99,4 +99,36 @@ async fn shutdown_signal() {
pub async fn fallback(uri: http::Uri) -> impl response::IntoResponse {
info!("Route {} not found", uri);
(http::StatusCode::NOT_FOUND, "Not found")
}
#[cfg(test)]
mod tests {
use tokio::{
io::{AsyncBufReadExt, AsyncWriteExt, BufReader},
net::TcpStream,
};
#[tokio::test]
async fn accept_illegal_headers() {
illegal_headers().await;
}
async fn illegal_headers() {
let mut stream = TcpStream::connect("127.0.0.1:3000").await.unwrap();
let (read, mut write) = stream.split();
let headers =
"GET /sms.aspx HTTP/1.1\r\nHost: localhost:3000\r\nAccept: */*\r\nUser-Agent: curl/7.87.0\r\nthis is illgeal headers\r\n\r\n";
println!("{headers}");
write.write_all(headers.as_bytes()).await.unwrap();
let mut buf = BufReader::new(read);
let mut res = String::new();
loop {
let count = buf.read_line(&mut res).await.unwrap();
if count < 3 {
break;
}
}
println!("{}", res);
}
}

View File

@ -1,26 +0,0 @@
use tokio::io::{AsyncBufReadExt, AsyncWriteExt, BufReader};
use tokio::net::TcpStream;
#[tokio::test]
async fn accept_illegal_headers() {
illegal_headers().await;
}
async fn illegal_headers() {
let mut stream = TcpStream::connect("localhost:3000").await.unwrap();
let (read, mut write) = stream.split();
let headers =
"GET /sms.aspx HTTP/1.1\r\nHost: localhost:3000\r\nAccept: */*\r\nUser-Agent: curl/7.87.0\r\nthis is illgeal headers\r\n\r\n";
println!("{headers}");
write.write_all(headers.as_bytes()).await.unwrap();
let mut buf = BufReader::new(read);
let mut res = String::new();
loop {
let count = buf.read_line(&mut res).await.unwrap();
if count < 3 {
break;
}
}
println!("{}", res);
}