CH-J ToolsPalvelimen hallinta yli SSH
Valikko
Julkaistu lähde

CH-J Tools

Selaile hakemistoja ja tiedostoja tietyn sovelluksen julkaisua varten.

Lataa lähde ZIP
CH-J / Server Manager 1704 tiedostot
0.1.2-beta Lisätty: · Rakennettu:
mod.rs Lisätty: Kirjaamaton päivä 3,7 KB · 101 rivit
Koodi Lataa tiedosto
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;
14pub mod quick;
15pub mod standby;
16#[cfg(feature = "smoke")]
17pub mod smoke;
18pub mod ssh;
19pub mod updates;
20pub mod vault;
22use crate::core::app::{Core, CoreSlot};
23use crate::core::error::{CoreError, CoreResult};
24use crate::security::caller::{require_main, require_module, ModuleContext};
25use serde_json::{json, Value};
26use std::sync::Arc;
27use tauri::Webview;
29pub type CommandResult = Result<Value, CoreError>;
31pub fn payload(value: Option<Value>) -> Value {
32 match value {
33 Some(Value::Object(map)) => Value::Object(map),
34 _ => json!({}),
35 }
38pub fn text<'a>(payload: &'a Value, key: &str) -> &'a str {
39 payload.get(key).and_then(Value::as_str).unwrap_or("")
42/// Core command guard (Electron `assertTrustedSender`).
43pub fn main_core(webview: &Webview, slot: &CoreSlot) -> CoreResult<Arc<Core>> {
44 require_main(webview.label(), webview.url().ok())?;
45 slot.get()
48/// Wraps a core command result: failures are logged like `registerCoreIpc.handle`.
49pub fn logged(core: &Core, channel: &str, result: CoreResult<Value>) -> CommandResult {
50 if let Err(error) = &result {
51 core.log_ipc_failure(channel, error);
52 }
53 result
56/// `{ok, value}` / `{ok:false, error}` envelope (SSH, biometrics, diagnostics).
57pub fn envelope(result: CoreResult<Value>, default_code: &str, limit: Option<usize>) -> Value {
58 match result {
59 Ok(value) => json!({ "ok": true, "value": value }),
60 Err(error) => {
61 let mut body = serde_json::to_value(&error).unwrap_or_else(|_| json!({}));
62 if body["code"].as_str().map(str::is_empty).unwrap_or(true) {
63 body["code"] = json!(default_code);
64 }
65 if let Some(limit) = limit {
66 body = json!({ "code": body["code"], "message": error.message.chars().take(limit).collect::<String>() });
67 }
68 json!({ "ok": false, "error": body })
69 }
70 }
73/// Module command guard: registered module window + manifest permission.
74pub fn module_call(webview: &Webview, slot: &CoreSlot, permission: Option<&str>) -> CoreResult<(Arc<Core>, Arc<ModuleContext>)> {
75 let core = slot.get()?;
76 let context = require_module(&core.windows, webview.label(), webview.url().ok())?;
77 if let Some(permission) = permission {
78 context.require(permission)?;
79 }
80 Ok((core, context))
83/// The 0.1.0 plugin runtime exposed error codes inside the message for these channels,
84/// because Electron dropped custom error properties.
85pub fn module_error(channel: &str, error: CoreError) -> CoreError {
86 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 == '_');
87 let expose = error.code.starts_with("HASH_")
88 || (["plugin:users:", "plugin:system:", "plugin:files:", "plugin:disks:", "plugin:rsync:"].iter().any(|p| channel.starts_with(p)) && valid_code);
89 if expose {
90 let message = error.prefixed_message();
91 CoreError { message, ..error }
92 } else {
93 error
94 }
97pub fn module_result(channel: &str, result: CoreResult<Value>) -> CommandResult {
98 result.map_err(|e| module_error(channel, e))
101pub mod keychain;
SHA-25678d28676e6c09824e3ab2bc012059e902ede432ae4484f82c70965c0b560fa0a

CH-J Proprietary Software License 1.14 · Lähde ilmoitetaan CH-J Proprietary Software License 1.14-koodilla. Sen saatavuus ei muuta lisenssiehtoja eikä myönnä lisäoikeuksia.

Arkisto SHA-256ac8fe790f4ba60fc098f8c985fc2656cfcc6cdc21fb34b30e308a2b54e62258f
Tiedostot