mirror of
https://github.com/euzu/tuliprox.git
synced 2026-10-07 08:22:05 +02:00
Merge branch 'develop' into fix/web_ui_direct_login_when_auth_disabled
This commit is contained in:
Generated
+8
-15
@@ -1108,7 +1108,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "frontend"
|
||||
version = "3.1.7"
|
||||
version = "3.1.8"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"base64",
|
||||
@@ -1120,9 +1120,9 @@ dependencies = [
|
||||
"futures-signals",
|
||||
"gloo-render 0.2.0",
|
||||
"gloo-storage 0.3.0",
|
||||
"gloo-timers 0.3.0",
|
||||
"gloo-timers 0.2.6",
|
||||
"gloo-utils 0.2.0",
|
||||
"implicit-clone 0.6.0",
|
||||
"implicit-clone",
|
||||
"js-sys",
|
||||
"log",
|
||||
"prost",
|
||||
@@ -1633,6 +1633,8 @@ version = "0.2.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9b995a66bb87bebce9a0f4a95aed01daca4872c050bfcb21653361c03bc35e5c"
|
||||
dependencies = [
|
||||
"futures-channel",
|
||||
"futures-core",
|
||||
"js-sys",
|
||||
"wasm-bindgen",
|
||||
]
|
||||
@@ -2169,15 +2171,6 @@ dependencies = [
|
||||
"indexmap",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "implicit-clone"
|
||||
version = "0.6.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1689b939ee35e3a075b0834b5672efd43aec8a6e81a1c6002b76a5ca2f211ae0"
|
||||
dependencies = [
|
||||
"implicit-clone-derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "implicit-clone-derive"
|
||||
version = "0.1.2"
|
||||
@@ -3801,7 +3794,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "shared"
|
||||
version = "3.1.7"
|
||||
version = "3.1.8"
|
||||
dependencies = [
|
||||
"base64",
|
||||
"bitflags 2.9.4",
|
||||
@@ -4350,7 +4343,7 @@ checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b"
|
||||
|
||||
[[package]]
|
||||
name = "tuliprox"
|
||||
version = "3.1.7"
|
||||
version = "3.1.8"
|
||||
dependencies = [
|
||||
"arc-swap",
|
||||
"async-compression",
|
||||
@@ -5076,7 +5069,7 @@ dependencies = [
|
||||
"console_error_panic_hook",
|
||||
"futures",
|
||||
"gloo 0.10.0",
|
||||
"implicit-clone 0.4.9",
|
||||
"implicit-clone",
|
||||
"indexmap",
|
||||
"js-sys",
|
||||
"prokio",
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "tuliprox"
|
||||
version = "3.1.7"
|
||||
version = "3.1.8"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
@@ -3,7 +3,7 @@ use crate::api::api_utils::try_unwrap_body;
|
||||
use crate::api::model::AppState;
|
||||
use crate::auth::{create_jwt_admin, create_jwt_user, is_admin, verify_password, verify_token, AuthBearer};
|
||||
use axum::response::IntoResponse;
|
||||
use log::error;
|
||||
use log::{debug, error};
|
||||
use serde_json::json;
|
||||
use shared::model::{TokenResponse, UserCredential, TOKEN_NO_AUTH};
|
||||
use shared::utils::{concat_path_leading_slash, CONSTANTS};
|
||||
|
||||
@@ -125,7 +125,7 @@ pub fn parse_xtream(input: &ConfigInput,
|
||||
streams: &Value) -> Result<Option<Vec<PlaylistGroup>>, TuliproxError> {
|
||||
match map_to_xtream_category(categories) {
|
||||
Ok(xtream_categories) => {
|
||||
let input_name = Arc::new(input.name.clone());
|
||||
let input_name = input.name.clone();
|
||||
let url = input.url.as_str();
|
||||
let username = input.username.as_ref().map_or("", |v| v);
|
||||
let password = input.password.as_ref().map_or("", |v| v);
|
||||
@@ -173,7 +173,7 @@ pub fn parse_xtream(input: &ConfigInput,
|
||||
xtream_cluster,
|
||||
additional_properties: stream.get_additional_properties(),
|
||||
category_id: 0,
|
||||
input_name: input_name.to_string(),
|
||||
input_name: input_name.clone(),
|
||||
..Default::default()
|
||||
},
|
||||
};
|
||||
|
||||
+2
-2
@@ -1,10 +1,10 @@
|
||||
[package]
|
||||
name = "frontend"
|
||||
version = "3.1.7"
|
||||
version = "3.1.8"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
shared = { version = "3.1.7", path = "../shared" }
|
||||
shared = { version = "3.1.8", path = "../shared" }
|
||||
chrono = "0"
|
||||
yew = "0.21"
|
||||
yew-router = "0.18"
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
use std::cell::RefCell;
|
||||
use super::{get_base_href, request_post};
|
||||
use crate::services::requests::set_token;
|
||||
use super::{check_dummy_token, get_base_href, get_token, request_post, set_token};
|
||||
use futures_signals::signal::Mutable;
|
||||
use futures_signals::signal::SignalExt;
|
||||
use shared::model::{Claims, TokenResponse, UserCredential, ROLE_ADMIN, ROLE_USER, TOKEN_NO_AUTH};
|
||||
use std::future::Future;
|
||||
use shared::utils::{concat_path, concat_path_leading_slash};
|
||||
use base64::{engine::general_purpose, Engine as _};
|
||||
use log::warn;
|
||||
use crate::error::{Error, Error::BadRequest, Error::NotFound};
|
||||
use log::{debug, warn};
|
||||
use crate::error::{Error, Error::Unauthorized, Error::NotFound};
|
||||
|
||||
fn decode_jwt_payload(token: &str) -> Option<Claims> {
|
||||
let payload_enc = token.split('.').nth(1)?;
|
||||
@@ -65,7 +64,7 @@ impl AuthService {
|
||||
}
|
||||
|
||||
fn no_auth(&self, err: Error) -> Result<TokenResponse, Error> {
|
||||
if matches!(err, BadRequest(_)) {
|
||||
if matches!(err, Unauthorized) {
|
||||
self.username.replace("admin".to_string());
|
||||
self.auth_channel.set(true);
|
||||
set_token(Some(TOKEN_NO_AUTH));
|
||||
@@ -100,6 +99,7 @@ impl AuthService {
|
||||
}
|
||||
|
||||
pub async fn refresh(&self) -> Result<TokenResponse, Error> {
|
||||
check_dummy_token();
|
||||
match request_post::<(), TokenResponse>(&concat_path(&self.auth_path, "refresh"), (), None, None).await {
|
||||
Ok(Some(token)) => {
|
||||
self.username.replace(token.username.to_string());
|
||||
@@ -120,7 +120,7 @@ impl AuthService {
|
||||
if token == TOKEN_NO_AUTH {
|
||||
roles.push(ROLE_ADMIN.to_string());
|
||||
}
|
||||
|
||||
|
||||
if let Some(claims) = decode_jwt_payload(token) {
|
||||
for role in claims.roles.iter() {
|
||||
roles.push(role.clone());
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
use crate::error::{Error, ErrorInfo, ErrorSetInfo};
|
||||
use gloo_storage::{LocalStorage, Storage};
|
||||
use log::{error};
|
||||
use log::error;
|
||||
use reqwasm::http::Request;
|
||||
use serde::{de::DeserializeOwned, Serialize};
|
||||
use serde_json::Value;
|
||||
use web_sys::window;
|
||||
use shared::utils::bin_deserialize;
|
||||
use web_sys::window;
|
||||
|
||||
const CONTENT_TYPE_BIN: &str = "application/cbor";
|
||||
const CONTENT_TYPE_JSON: &str = "application/json";
|
||||
@@ -32,6 +32,14 @@ pub fn set_token(token: Option<&str>) {
|
||||
}
|
||||
}
|
||||
|
||||
// The Authorization header is for the Backend Authenticator mandatory.
|
||||
// If we dont set a dummy token the backend api cant be called.
|
||||
pub fn check_dummy_token() {
|
||||
if get_token().is_none() {
|
||||
set_token(Some("eyJraWQiOiJkZWZhdWx0IiwiYWxnIjoiUlMyNTYifQ.eyJsb2dpbiI6ImR1bW15In0.WWzZP0hICmJeIgMLVYNOpayriEC08J_lYssk9z8GglHXfZ6oJUDv3svlJDA8sQG025VA_LR5UzyyiWeQDCdpWyrCI_nI2Xd-3ga3JwWtxHE9NWFalgq0Q9jjxoB4LYWCXsAkqoZqk6s7b3F5Fi_h5oYHfwM4h8hXEbrgnJ_Z1wpSc7HNh6SUnOllxcaJOxYlRrlUn3XulSSf2NhHe3XotvFguiIV1-RIns3cSIL29bvMUEFw84w7BfJn-joynZsWlfJBvzyOiuDqduXa0deH7b962unM2wPpbvTgliJhFFOUBHClRhBOmoo0cijuMZB4K7NjgjGmU5eVfHG6pVWs_b0ikS4V_P6RJcNS6Alcc_HB_YXv0yCD3pjcBbuRXAskivEhgXuecdRMGQgohAhXplLuu5SR0K6Bcrt7UFFnBi2qN6fbw1i4s8PDXqiTu4rIg9agCkVNfplRvj8Szl6egF0Vd1TN1WGEarkdINEUyfNQkAihFY5BKxfaPun1-a0VydRMZElu6VzrrUMxXt4T7zybuJZI63C3mKLEHZixdSC76c9AE-zGom5LZYE4mqwd4dW3QHtWFZgGZiL9C_VBIf63WzjTYhWVuO2U8O9bsKkSEl5L-Ww9j8ccDHp5nc7y6yUgSYd600TBRI7WblFovLsl2tjElvUqfJZhj6JmX_Q"));
|
||||
}
|
||||
}
|
||||
|
||||
/// build all kinds of http request: post/get/delete etc.
|
||||
async fn request<B, T>(method: RequestMethod, url: &str, body: B, content_type: Option<String>,
|
||||
response_type: Option<String>) -> Result<Option<T>, Error>
|
||||
@@ -43,14 +51,14 @@ where
|
||||
let r_type = response_type.as_ref().map_or(CONTENT_TYPE_JSON, |c| c.as_str());
|
||||
let mut request = match method {
|
||||
RequestMethod::Get => Request::get(url),
|
||||
RequestMethod::Post => {
|
||||
RequestMethod::Post => {
|
||||
let json = serde_json::to_string(&body).map_err(|_| Error::RequestError)?;
|
||||
Request::post(url).body(json).header("Content-Type", c_type)
|
||||
},
|
||||
}
|
||||
RequestMethod::Put => {
|
||||
let json = serde_json::to_string(&body).map_err(|_| Error::RequestError)?;
|
||||
Request::put(url).body(json).header("Content-Type", c_type)
|
||||
},
|
||||
}
|
||||
// RequestMethod::PATCH => Request::patch(&url).body(serde_json::to_string(&body).unwrap()),
|
||||
RequestMethod::Delete => Request::delete(url),
|
||||
};
|
||||
@@ -85,7 +93,7 @@ where
|
||||
Err(err) => {
|
||||
error!("Failed to deserialize {err}");
|
||||
Err(Error::DeserializeError)
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(err) => {
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "shared"
|
||||
version = "3.1.7"
|
||||
version = "3.1.8"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
|
||||
Reference in New Issue
Block a user