Fix launcher verification session check and socket IP resolution
This commit is contained in:
1 parent
522e3a5717
commit
c7aa563dac
6 files changed
+185
-29
No files matched your search
@@ -259,9 +259,16 @@ pub fn panel_token(state: &AppState) -> Option<String> {
|
||||
let panel = state.panel_url()?;
|
||||
let accounts = state.accounts.read().unwrap();
|
||||
let active = accounts.active()?;
|
||||
if active.kind != "panel" || active.panel_url.as_deref() != Some(panel.as_str()) {
|
||||
if active.kind != "panel" {
|
||||
return None;
|
||||
}
|
||||
if let Some(active_url) = &active.panel_url {
|
||||
let a = active_url.trim_end_matches('/');
|
||||
let p = panel.trim_end_matches('/');
|
||||
if !a.eq_ignore_ascii_case(p) {
|
||||
return None;
|
||||
}
|
||||
}
|
||||
state.secrets.get(&active.id).panel_token
|
||||
}
|
||||
|
||||
|
||||
@@ -9,23 +9,40 @@ use std::time::Duration;
|
||||
pub struct Recorder {
|
||||
http: reqwest::Client,
|
||||
panel: String,
|
||||
token: String,
|
||||
token: Option<String>,
|
||||
username: Option<String>,
|
||||
}
|
||||
|
||||
pub fn capture(state: &AppState) -> Option<Recorder> {
|
||||
Some(Recorder { http: state.http.clone(), panel: state.panel_url()?, token: accounts::panel_token(state)? })
|
||||
let panel = state.panel_url()?;
|
||||
let accounts = state.accounts.read().unwrap();
|
||||
let active = accounts.active()?;
|
||||
let token = accounts::panel_token(state);
|
||||
Some(Recorder {
|
||||
http: state.http.clone(),
|
||||
panel,
|
||||
token,
|
||||
username: Some(active.username.clone()),
|
||||
})
|
||||
}
|
||||
|
||||
impl Recorder {
|
||||
pub async fn send(&self, kind: &str, instance: &str) -> anyhow::Result<()> {
|
||||
self.http
|
||||
let mut req = self
|
||||
.http
|
||||
.post(format!("{}/api/v1/launcher/events", self.panel))
|
||||
.bearer_auth(&self.token)
|
||||
.timeout(Duration::from_secs(5))
|
||||
.json(&LaunchEvent { kind: kind.into(), instance_id: instance.into(), username: None })
|
||||
.send()
|
||||
.await?
|
||||
.error_for_status()?;
|
||||
.timeout(Duration::from_secs(5));
|
||||
if let Some(token) = &self.token {
|
||||
req = req.bearer_auth(token);
|
||||
}
|
||||
req.json(&LaunchEvent {
|
||||
kind: kind.into(),
|
||||
instance_id: instance.into(),
|
||||
username: self.username.clone(),
|
||||
})
|
||||
.send()
|
||||
.await?
|
||||
.error_for_status()?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user