CH-J Toolsserverihaldus üle SSH
Menüü
Avaldatud allikas

CH-J Tools

Vaata katalooge ja faile konkreetse rakenduse vabastamiseks.

Laadi alla allikas ZIP
CH-J / Server Manager 1704 failid
0.1.2-beta Lisatud: · Ehitatud:
service.rs Lisatud: Kuupäeva ei registreerita 3,9 KB · 90 read
Kood Faili allalaadimine
1//! Users facade: chooses the Linux or Windows backend from system facts of the remote host
2//! (uname / Win32_OperatingSystem) and returns only IPC-safe data.
4use super::common::fail;
5use super::linux::LinuxUsers;
6use super::windows::WindowsUsers;
7use crate::core::error::CoreResult;
8use crate::core::ssh::platform::detect_platform;
9use crate::core::ssh::session::SessionManager;
10use serde_json::Value;
11use std::sync::Arc;
13pub struct UserAdmin {
14 pub sessions: Arc<SessionManager>,
15 pub linux: LinuxUsers,
16 pub windows: WindowsUsers,
19impl UserAdmin {
20 /// `Some(platform)` for Windows servers, `None` for Linux/POSIX.
21 async fn windows(&self, session_id: &str) -> CoreResult<Option<Value>> {
22 let record = self.sessions.require_connected(session_id)?;
23 let platform = detect_platform(&self.sessions, &record, false).await?;
24 match platform["os"].as_str() {
25 Some("windows") => Ok(Some(platform)),
26 Some("unknown") => Err(fail(
27 "USERS_PLATFORM_UNSUPPORTED",
28 &format!("The remote operating system could not be identified: {}.", platform["reason"].as_str().filter(|s| !s.is_empty()).unwrap_or("no POSIX shell and no Windows PowerShell")),
29 )),
30 _ => Ok(None),
31 }
32 }
34 pub async fn privileges(&self, session_id: &str, refresh: bool) -> CoreResult<Value> {
35 if self.windows(session_id).await?.is_some() {
36 return self.windows.privileges(session_id).await;
37 }
38 self.linux.privileges(session_id, refresh).await
39 }
41 pub async fn inventory(&self, session_id: &str, options: &Value) -> CoreResult<Value> {
42 if let Some(platform) = self.windows(session_id).await? {
43 return self.windows.inventory(session_id, &platform).await;
44 }
45 Ok(self.linux.inventory(session_id, options).await?.public)
46 }
48 pub async fn list(&self, session_id: &str) -> CoreResult<Value> {
49 if let Some(platform) = self.windows(session_id).await? {
50 let inventory = self.windows.inventory(session_id, &platform).await?;
51 return Ok(Value::Array(inventory["users"].as_array().cloned().unwrap_or_default().into_iter().filter(|u| u["system"] != true).collect()));
52 }
53 self.linux.list_compat(session_id).await
54 }
56 pub async fn detail(&self, session_id: &str, options: &Value) -> CoreResult<Value> {
57 if let Some(platform) = self.windows(session_id).await? {
58 return Ok(self.windows.detail(session_id, options, &platform).await?.public);
59 }
60 self.linux.detail_public(session_id, options).await
61 }
63 pub async fn manage(&self, session_id: &str, payload: &Value) -> CoreResult<Value> {
64 if let Some(platform) = self.windows(session_id).await? {
65 return self.windows.manage(session_id, payload, &platform).await;
66 }
67 self.linux.manage(session_id, payload).await
68 }
70 pub async fn keys(&self, session_id: &str, payload: &Value) -> CoreResult<Value> {
71 if let Some(platform) = self.windows(session_id).await? {
72 return self.windows.keys(session_id, payload, &platform).await;
73 }
74 self.linux.keys(session_id, payload).await
75 }
77 pub async fn ssh_password_off_all(&self, session_id: &str, payload: &Value) -> CoreResult<Value> {
78 if self.windows(session_id).await?.is_some() {
79 return Err(crate::core::error::CoreError::new("USERS_NOT_SUPPORTED", "Turning SSH password login off for all accounts works on Linux servers."));
80 }
81 self.linux.ssh_password_off_all(session_id, payload).await
82 }
84 pub async fn ssh_policy(&self, session_id: &str, payload: &Value) -> CoreResult<Value> {
85 if let Some(platform) = self.windows(session_id).await? {
86 return self.windows.ssh_policy(session_id, payload, &platform).await;
87 }
88 self.linux.ssh_policy(session_id, payload).await
89 }
SHA-256f70e661c2adb1077aadb967e2ae23eff8da637ba6d419a361ff94fd9fc7b7ef0

CH-J Proprietary Software License 1.14 · Allikas on esitatud CH-J Proprietary Software License 1.14 all. Selle kättesaadavus ei muuda litsentsitingimusi ega anna täiendavaid õigusi.

Arhiiv SHA-256ac8fe790f4ba60fc098f8c985fc2656cfcc6cdc21fb34b30e308a2b54e62258f
Failid