feat: commit hash in banner, version command, file upload/download

This commit is contained in:
Helios Agent 2026-03-03 14:29:22 +01:00
parent cb86894369
commit f7d29a98d3
No known key found for this signature in database
GPG key ID: C8259547CD8309B5
8 changed files with 202 additions and 9 deletions

View file

@ -1,8 +1,11 @@
fn main() { fn main() {
#[cfg(target_os = "windows")] let hash = std::process::Command::new("git")
{ .args(["rev-parse", "--short", "HEAD"])
let mut res = winres::WindowsResource::new(); .output()
res.set_icon("../../assets/logo.ico"); .ok()
res.compile().expect("Failed to compile Windows resources"); .and_then(|o| String::from_utf8(o.stdout).ok())
} .unwrap_or_default();
let hash = hash.trim();
println!("cargo:rustc-env=GIT_COMMIT={}", if hash.is_empty() { "unknown" } else { hash });
println!("cargo:rerun-if-changed=.git/HEAD");
} }

View file

@ -9,6 +9,7 @@ use serde::{Deserialize, Serialize};
use tokio::sync::Mutex; use tokio::sync::Mutex;
use tokio_tungstenite::{connect_async_tls_with_config, tungstenite::Message, Connector}; use tokio_tungstenite::{connect_async_tls_with_config, tungstenite::Message, Connector};
use base64::Engine;
use helios_common::{ClientMessage, ServerMessage}; use helios_common::{ClientMessage, ServerMessage};
mod shell; mod shell;
@ -20,7 +21,7 @@ mod windows_mgmt;
fn banner() { fn banner() {
println!(); println!();
println!(" {} HELIOS REMOTE", "".yellow().bold()); println!(" {} HELIOS REMOTE v{} ({})", "".yellow().bold(), env!("CARGO_PKG_VERSION"), env!("GIT_COMMIT"));
println!(" {}", "".repeat(45).dimmed()); println!(" {}", "".repeat(45).dimmed());
} }
@ -431,6 +432,53 @@ async fn handle_message(
} }
} }
ServerMessage::VersionRequest { request_id } => {
ClientMessage::VersionResponse {
request_id,
version: env!("CARGO_PKG_VERSION").to_string(),
commit: env!("GIT_COMMIT").to_string(),
}
}
ServerMessage::UploadRequest { request_id, path, content_base64 } => {
log_cmd!("upload → {}", path);
match (|| -> Result<(), String> {
let bytes = base64::engine::general_purpose::STANDARD
.decode(&content_base64)
.map_err(|e| format!("base64 decode: {e}"))?;
if let Some(parent) = std::path::Path::new(&path).parent() {
std::fs::create_dir_all(parent).map_err(|e| e.to_string())?;
}
std::fs::write(&path, &bytes).map_err(|e| e.to_string())?;
Ok(())
})() {
Ok(()) => {
log_ok!("Saved {}", path);
ClientMessage::Ack { request_id }
}
Err(e) => {
log_err!("upload failed: {e}");
ClientMessage::Error { request_id, message: e }
}
}
}
ServerMessage::DownloadRequest { request_id, path } => {
log_cmd!("download ← {}", path);
match std::fs::read(&path) {
Ok(bytes) => {
let size = bytes.len() as u64;
let content_base64 = base64::engine::general_purpose::STANDARD.encode(&bytes);
log_ok!("Sent {} bytes", size);
ClientMessage::DownloadResponse { request_id, content_base64, size }
}
Err(e) => {
log_err!("download failed: {e}");
ClientMessage::Error { request_id, message: format!("Read failed: {e}") }
}
}
}
ServerMessage::Ack { request_id } => { ServerMessage::Ack { request_id } => {
ClientMessage::Ack { request_id } ClientMessage::Ack { request_id }
} }

View file

@ -47,6 +47,19 @@ pub enum ServerMessage {
FocusWindowRequest { request_id: Uuid, window_id: u64 }, FocusWindowRequest { request_id: Uuid, window_id: u64 },
/// Maximize a window and bring it to the foreground /// Maximize a window and bring it to the foreground
MaximizeAndFocusRequest { request_id: Uuid, window_id: u64 }, MaximizeAndFocusRequest { request_id: Uuid, window_id: u64 },
/// Request client version info
VersionRequest { request_id: Uuid },
/// Upload a file to the client
UploadRequest {
request_id: Uuid,
path: String,
content_base64: String,
},
/// Download a file from the client
DownloadRequest {
request_id: Uuid,
path: String,
},
} }
/// Messages sent from the client to the relay server /// Messages sent from the client to the relay server
@ -81,6 +94,18 @@ pub enum ClientMessage {
request_id: Uuid, request_id: Uuid,
windows: Vec<WindowInfo>, windows: Vec<WindowInfo>,
}, },
/// Response to a version request
VersionResponse {
request_id: Uuid,
version: String,
commit: String,
},
/// Response to a download request
DownloadResponse {
request_id: Uuid,
content_base64: String,
size: u64,
},
} }
/// Mouse button variants /// Mouse button variants

11
crates/server/build.rs Normal file
View file

@ -0,0 +1,11 @@
fn main() {
let hash = std::process::Command::new("git")
.args(["rev-parse", "--short", "HEAD"])
.output()
.ok()
.and_then(|o| String::from_utf8(o.stdout).ok())
.unwrap_or_default();
let hash = hash.trim();
println!("cargo:rustc-env=GIT_COMMIT={}", if hash.is_empty() { "unknown" } else { hash });
println!("cargo:rerun-if-changed=.git/HEAD");
}

View file

@ -1,6 +1,6 @@
use std::time::Duration; use std::time::Duration;
use axum::{ use axum::{
extract::{Path, State}, extract::{Path, Query, State},
http::StatusCode, http::StatusCode,
response::IntoResponse, response::IntoResponse,
Json, Json,
@ -307,6 +307,103 @@ pub async fn maximize_and_focus(
} }
} }
/// GET /version — server version (public, no auth)
pub async fn server_version() -> impl IntoResponse {
Json(serde_json::json!({
"version": env!("CARGO_PKG_VERSION"),
"commit": env!("GIT_COMMIT"),
}))
}
/// GET /sessions/:id/version — client version
pub async fn client_version(
Path(session_id): Path<String>,
State(state): State<AppState>,
) -> impl IntoResponse {
match dispatch(&state, &session_id, "version", |rid| {
ServerMessage::VersionRequest { request_id: rid }
})
.await
{
Ok(ClientMessage::VersionResponse { version, commit, .. }) => (
StatusCode::OK,
Json(serde_json::json!({ "version": version, "commit": commit })),
)
.into_response(),
Ok(ClientMessage::Error { message, .. }) => (
StatusCode::INTERNAL_SERVER_ERROR,
Json(serde_json::json!({ "error": message })),
)
.into_response(),
Ok(_) => (
StatusCode::BAD_GATEWAY,
Json(serde_json::json!({ "error": "Unexpected response from client" })),
)
.into_response(),
Err(e) => e.into_response(),
}
}
/// POST /sessions/:id/upload
#[derive(Deserialize)]
pub struct UploadBody {
pub path: String,
pub content_base64: String,
}
pub async fn upload_file(
Path(session_id): Path<String>,
State(state): State<AppState>,
Json(body): Json<UploadBody>,
) -> impl IntoResponse {
match dispatch(&state, &session_id, "upload", |rid| ServerMessage::UploadRequest {
request_id: rid,
path: body.path.clone(),
content_base64: body.content_base64.clone(),
})
.await
{
Ok(_) => (StatusCode::OK, Json(serde_json::json!({ "ok": true }))).into_response(),
Err(e) => e.into_response(),
}
}
/// GET /sessions/:id/download?path=...
#[derive(Deserialize)]
pub struct DownloadQuery {
pub path: String,
}
pub async fn download_file(
Path(session_id): Path<String>,
State(state): State<AppState>,
Query(query): Query<DownloadQuery>,
) -> impl IntoResponse {
match dispatch(&state, &session_id, "download", |rid| ServerMessage::DownloadRequest {
request_id: rid,
path: query.path.clone(),
})
.await
{
Ok(ClientMessage::DownloadResponse { content_base64, size, .. }) => (
StatusCode::OK,
Json(serde_json::json!({ "content_base64": content_base64, "size": size })),
)
.into_response(),
Ok(ClientMessage::Error { message, .. }) => (
StatusCode::INTERNAL_SERVER_ERROR,
Json(serde_json::json!({ "error": message })),
)
.into_response(),
Ok(_) => (
StatusCode::BAD_GATEWAY,
Json(serde_json::json!({ "error": "Unexpected response from client" })),
)
.into_response(),
Err(e) => e.into_response(),
}
}
/// POST /sessions/:id/label /// POST /sessions/:id/label
#[derive(Deserialize)] #[derive(Deserialize)]
pub struct LabelBody { pub struct LabelBody {

View file

@ -30,6 +30,9 @@ async fn main() -> anyhow::Result<()> {
.with(tracing_subscriber::fmt::layer()) .with(tracing_subscriber::fmt::layer())
.init(); .init();
const GIT_COMMIT: &str = env!("GIT_COMMIT");
info!("helios-server v{} ({})", env!("CARGO_PKG_VERSION"), GIT_COMMIT);
let api_key = std::env::var("HELIOS_API_KEY") let api_key = std::env::var("HELIOS_API_KEY")
.unwrap_or_else(|_| "dev-secret".to_string()); .unwrap_or_else(|_| "dev-secret".to_string());
@ -52,10 +55,14 @@ async fn main() -> anyhow::Result<()> {
.route("/sessions/:id/windows/minimize-all", post(api::minimize_all)) .route("/sessions/:id/windows/minimize-all", post(api::minimize_all))
.route("/sessions/:id/windows/:window_id/focus", post(api::focus_window)) .route("/sessions/:id/windows/:window_id/focus", post(api::focus_window))
.route("/sessions/:id/windows/:window_id/maximize", post(api::maximize_and_focus)) .route("/sessions/:id/windows/:window_id/maximize", post(api::maximize_and_focus))
.route("/sessions/:id/version", get(api::client_version))
.route("/sessions/:id/upload", post(api::upload_file))
.route("/sessions/:id/download", get(api::download_file))
.layer(middleware::from_fn_with_state(state.clone(), require_api_key)); .layer(middleware::from_fn_with_state(state.clone(), require_api_key));
let app = Router::new() let app = Router::new()
.route("/ws", get(ws_handler::ws_upgrade)) .route("/ws", get(ws_handler::ws_upgrade))
.route("/version", get(api::server_version))
.merge(protected) .merge(protected)
.with_state(state); .with_state(state);

View file

@ -89,6 +89,8 @@ async fn handle_client_message(session_id: Uuid, msg: ClientMessage, state: &App
ClientMessage::ScreenshotResponse { request_id, .. } ClientMessage::ScreenshotResponse { request_id, .. }
| ClientMessage::ExecResponse { request_id, .. } | ClientMessage::ExecResponse { request_id, .. }
| ClientMessage::ListWindowsResponse { request_id, .. } | ClientMessage::ListWindowsResponse { request_id, .. }
| ClientMessage::VersionResponse { request_id, .. }
| ClientMessage::DownloadResponse { request_id, .. }
| ClientMessage::Ack { request_id } | ClientMessage::Ack { request_id }
| ClientMessage::Error { request_id, .. } => { | ClientMessage::Error { request_id, .. } => {
let rid = *request_id; let rid = *request_id;

View file

@ -9,7 +9,7 @@
$ErrorActionPreference = "Stop" $ErrorActionPreference = "Stop"
$url = "https://github.com/agent-helios/helios-remote/releases/latest/download/helios-remote-client-windows.exe" $url = "https://agent-helios.me/downloads/helios-remote/helios-remote-client-windows.exe"
$dest = "$env:USERPROFILE\Desktop\Helios Remote.exe" $dest = "$env:USERPROFILE\Desktop\Helios Remote.exe"
Write-Host "Downloading helios-remote client..." Write-Host "Downloading helios-remote client..."