CH-J Toolsspráva serverů přes SSH
Menu
Vydané zdroje

CH-J Tools

Procházejte adresáře a soubory konkrétního vydání aplikace.

Stáhnout zdroje ZIP
CH-J / Server Manager 872 souborů
core-20261030T220507Z-61e4558d889f Přidáno: · Sestaveno:
mod.rs Přidáno: Datum není evidováno 3,6 KB · 97 řádků
Kód Stáhnout soubor
1//! Tauri command layer: thin adapters between the CH-J API (`src/api`) and the Rust Core.
2//! Every command first resolves the calling window (security layer) and only then touches
3//! a service. Core commands accept only the main window; module commands only registered
4//! module windows with the required manifest permission; license commands only the
5//! license window.
7pub mod app;
8pub mod availability;
9pub mod diagnostics;
10pub mod license;
11pub mod module_api;
12pub mod modules;
13pub mod profiles;
14#[cfg(feature = "smoke")]
15pub mod smoke;
16pub mod ssh;
17pub mod updates;
18pub mod vault;
20use crate::core::app::{Core, CoreSlot};
21use crate::core::error::{CoreError, CoreResult};
22use crate::security::caller::{require_main, require_module, ModuleContext};
23use serde_json::{json, Value};
24use std::sync::Arc;
25use tauri::Webview;
27pub type CommandResult = Result<Value, CoreError>;
29pub fn payload(value: Option<Value>) -> Value {
30 match value {
31 Some(Value::Object(map)) => Value::Object(map),
32 _ => json!({}),
33 }
36pub fn text<'a>(payload: &'a Value, key: &str) -> &'a str {
37 payload.get(key).and_then(Value::as_str).unwrap_or("")
40/// Core command guard (Electron `assertTrustedSender`).
41pub fn main_core(webview: &Webview, slot: &CoreSlot) -> CoreResult<Arc<Core>> {
42 require_main(webview.label(), webview.url().ok())?;
43 slot.get()
46/// Wraps a core command result: failures are logged like `registerCoreIpc.handle`.
47pub fn logged(core: &Core, channel: &str, result: CoreResult<Value>) -> CommandResult {
48 if let Err(error) = &result {
49 core.log_ipc_failure(channel, error);
50 }
51 result
54/// `{ok, value}` / `{ok:false, error}` envelope (SSH, biometrics, diagnostics).
55pub fn envelope(result: CoreResult<Value>, default_code: &str, limit: Option<usize>) -> Value {
56 match result {
57 Ok(value) => json!({ "ok": true, "value": value }),
58 Err(error) => {
59 let mut body = serde_json::to_value(&error).unwrap_or_else(|_| json!({}));
60 if body["code"].as_str().map(str::is_empty).unwrap_or(true) {
61 body["code"] = json!(default_code);
62 }
63 if let Some(limit) = limit {
64 body = json!({ "code": body["code"], "message": error.message.chars().take(limit).collect::<String>() });
65 }
66 json!({ "ok": false, "error": body })
67 }
68 }
71/// Module command guard: registered module window + manifest permission.
72pub fn module_call(webview: &Webview, slot: &CoreSlot, permission: Option<&str>) -> CoreResult<(Arc<Core>, Arc<ModuleContext>)> {
73 let core = slot.get()?;
74 let context = require_module(&core.windows, webview.label(), webview.url().ok())?;
75 if let Some(permission) = permission {
76 context.require(permission)?;
77 }
78 Ok((core, context))
81/// The 0.1.0 plugin runtime exposed error codes inside the message for these channels,
82/// because Electron dropped custom error properties.
83pub fn module_error(channel: &str, error: CoreError) -> CoreError {
84 let valid_code = error.code.len() >= 3 && error.code.len() <= 64 && error.code.chars().next().map(|c| c.is_ascii_uppercase()).unwrap_or(false) && error.code.chars().all(|c| c.is_ascii_uppercase() || c.is_ascii_digit() || c == '_');
85 let expose = error.code.starts_with("HASH_")
86 || (["plugin:users:", "plugin:system:", "plugin:files:", "plugin:disks:"].iter().any(|p| channel.starts_with(p)) && valid_code);
87 if expose {
88 let message = error.prefixed_message();
89 CoreError { message, ..error }
90 } else {
91 error
92 }
95pub fn module_result(channel: &str, result: CoreResult<Value>) -> CommandResult {
96 result.map_err(|e| module_error(channel, e))
SHA-2563aed28ff4eab9c9ee9e3b9cfd279ba651c96662e814d1d4cc577994e1595dd30

CH-J Proprietary Software License 1.14 · Zdroje jsou zveřejněny pod CH-J Proprietary Software License 1.14. Jejich dostupnost nemění licenční podmínky ani neposkytuje další oprávnění.

SHA-256 archivu77380d4805485ffa4027fbe7858b5836f197a4aa9d52358a43e2d12d018744df
Soubory