mirror of
https://codeberg.org/YGGverse/psocks.git
synced 2026-03-31 16:35:28 +00:00
create namespace for json api; make temporarily index page reference to api/totals
This commit is contained in:
parent
24cbc3012e
commit
06228c577f
2 changed files with 15 additions and 7 deletions
|
|
@ -26,8 +26,8 @@ RUST_LOG=trace cargo run -- --allow=http://localhost/allow.txt \
|
||||||
```
|
```
|
||||||
* set `socks5://127.0.0.1:1080` proxy in your application
|
* set `socks5://127.0.0.1:1080` proxy in your application
|
||||||
* open http://127.0.0.1:8010 in browser for stats:
|
* open http://127.0.0.1:8010 in browser for stats:
|
||||||
* `/allow/domain.com` - add rule to the current session (and `--cache` if defined)
|
* `/api/allow/domain.com` - add rule to the current session (and `--cache` if defined)
|
||||||
* `/block/domain.com` - delete rule from the current session (and `--cache` if defined)
|
* `/api/block/domain.com` - delete rule from the current session (and `--cache` if defined)
|
||||||
|
|
||||||
### Allow list example
|
### Allow list example
|
||||||
|
|
||||||
|
|
|
||||||
18
src/main.rs
18
src/main.rs
|
|
@ -18,11 +18,16 @@ use tokio::{net::TcpListener, task};
|
||||||
|
|
||||||
#[rocket::get("/")]
|
#[rocket::get("/")]
|
||||||
async fn index(totals: &State<Arc<Total>>, startup_time: &State<Instant>) -> Json<Snap> {
|
async fn index(totals: &State<Arc<Total>>, startup_time: &State<Instant>) -> Json<Snap> {
|
||||||
|
Json(totals.inner().snap(startup_time.elapsed().as_secs())) // @TODO implement Web UI
|
||||||
|
}
|
||||||
|
|
||||||
|
#[rocket::get("/api/totals")]
|
||||||
|
async fn api_totals(totals: &State<Arc<Total>>, startup_time: &State<Instant>) -> Json<Snap> {
|
||||||
Json(totals.inner().snap(startup_time.elapsed().as_secs()))
|
Json(totals.inner().snap(startup_time.elapsed().as_secs()))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[rocket::get("/allow/<rule>")]
|
#[rocket::get("/api/allow/<rule>")]
|
||||||
async fn allow(
|
async fn api_allow(
|
||||||
rule: &str,
|
rule: &str,
|
||||||
list: &State<Arc<List>>,
|
list: &State<Arc<List>>,
|
||||||
totals: &State<Arc<Total>>,
|
totals: &State<Arc<Total>>,
|
||||||
|
|
@ -36,8 +41,8 @@ async fn allow(
|
||||||
})?))
|
})?))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[rocket::get("/block/<rule>")]
|
#[rocket::get("/api/block/<rule>")]
|
||||||
async fn block(
|
async fn api_block(
|
||||||
rule: &str,
|
rule: &str,
|
||||||
list: &State<Arc<List>>,
|
list: &State<Arc<List>>,
|
||||||
totals: &State<Arc<Total>>,
|
totals: &State<Arc<Total>>,
|
||||||
|
|
@ -84,7 +89,10 @@ async fn rocket() -> _ {
|
||||||
.manage(list)
|
.manage(list)
|
||||||
.manage(totals)
|
.manage(totals)
|
||||||
.manage(Instant::now())
|
.manage(Instant::now())
|
||||||
.mount("/", rocket::routes![index, allow, block])
|
.mount(
|
||||||
|
"/",
|
||||||
|
rocket::routes![index, api_totals, api_allow, api_block],
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn spawn_socks_server(opt: &'static Opt, list: Arc<List>, totals: Arc<Total>) -> Result<()> {
|
async fn spawn_socks_server(opt: &'static Opt, list: Arc<List>, totals: Arc<Total>) -> Result<()> {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue