panel added

4-update-check
plazmoid 4 years ago
parent 57ae564fd7
commit 8c5e048b7c
  1. 7
      bin/u_agent/Cargo.toml
  2. 10
      bin/u_agent/src/main.rs
  3. 15
      bin/u_panel/Cargo.toml
  4. 27
      bin/u_panel/src/main.rs
  5. 2
      bin/u_run/Cargo.toml
  6. 2
      bin/u_run/src/main.rs
  7. 2
      bin/u_server/Cargo.toml
  8. 19
      bin/u_server/src/main.rs
  9. 2
      lib/u_lib/Cargo.toml
  10. 14
      lib/u_lib/src/client/client.rs
  11. 4
      lib/u_lib/src/client/mod.rs
  12. 5
      lib/u_lib/src/client/network.rs
  13. 15
      lib/u_lib/src/contracts/datatypes.rs
  14. 59
      lib/u_lib/src/contracts/jobs.rs
  15. 17
      lib/u_lib/src/contracts/messaging.rs
  16. 7
      lib/u_lib/src/contracts/mod.rs
  17. 7
      lib/u_lib/src/lib.rs

@ -1,5 +1,5 @@
[package] [package]
name = "u-agent" name = "u_agent"
version = "0.1.0" version = "0.1.0"
authors = ["plazmoid <kronos44@mail.ru>"] authors = ["plazmoid <kronos44@mail.ru>"]
edition = "2018" edition = "2018"
@ -7,13 +7,10 @@ edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
tokio = { version = "*", features = ["macros"] } tokio = { version = "*", features = ["macros", "rt-core", "process", "blocking"] }
sysinfo = "0.10.5" sysinfo = "0.10.5"
#lazy_static = "1.4.0"
log = "^0.4" log = "^0.4"
env_logger = "0.7.1" env_logger = "0.7.1"
cron = "0.6.0"
uuid = "0.8.1" uuid = "0.8.1"
reqwest = { version = "0.10.7", features = ["json"] } reqwest = { version = "0.10.7", features = ["json"] }
u_lib = { version = "*", path = "../../lib/u_lib" } u_lib = { version = "*", path = "../../lib/u_lib" }

@ -9,10 +9,14 @@
//mod jobs; //mod jobs;
use std::thread::sleep; use {
use std::time::Duration; std::thread::sleep,
std::time::Duration,
u_lib::client::*
};
mod executor;
mod network;
use network::ClientHandler; use network::ClientHandler;
#[tokio::main] #[tokio::main]

@ -0,0 +1,15 @@
[package]
name = "u_panel"
version = "0.1.0"
authors = ["plazmoid <kronos44@mail.ru>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
tokio = { version = "*", features = ["macros", "rt-core", "process", "blocking"] }
log = "^0.4"
env_logger = "0.7.1"
uuid = "0.8.1"
reqwest = { version = "0.10.7", features = ["json"] }
u_lib = { version = "*", path = "../../lib/u_lib" }

@ -0,0 +1,27 @@
use std::env::args;
use std::future::Future;
use u_lib::client::network::ClientHandler;
fn get_cmd_handler(cli_handler: &ClientHandler, method: &str) -> Option<fn()> {
match method {
"ls" => Some(cli_handler.list()),
_ => None
}
}
#[tokio::main]
async fn main() -> Result<(), &'static str> {
//daemonize();
let mut raw_args = args();
let method = match raw_args.nth(1) {
Some(m) => m,
None => return Err("Method required")
};
let instance = ClientHandler::new();
let future = match get_cmd_handler(&instance, &method) {
Some(c) => c,
None => return Err("Unknown method")
};
future.await;
Ok(())
}

@ -1,5 +1,5 @@
[package] [package]
name = "u-run" name = "u_run"
version = "0.1.0" version = "0.1.0"
authors = ["plazmoid <kronos44@mail.ru>"] authors = ["plazmoid <kronos44@mail.ru>"]
edition = "2018" edition = "2018"

@ -19,7 +19,7 @@ fn get_uagent_data() -> Option<Vec<u8>> {
let ls = read_dir("./").unwrap(); let ls = read_dir("./").unwrap();
for dirfile in ls { for dirfile in ls {
let filename = dirfile.unwrap().path(); let filename = dirfile.unwrap().path();
if filename.to_str().unwrap() == "u-agent" { if filename.to_str().unwrap() == "u_agent" {
let mut file = File::open(filename).unwrap(); let mut file = File::open(filename).unwrap();
let mut data: Vec<u8> = vec![]; let mut data: Vec<u8> = vec![];
file.read_to_end(&mut data).unwrap(); file.read_to_end(&mut data).unwrap();

@ -1,5 +1,5 @@
[package] [package]
name = "u-server" name = "u_server"
version = "0.1.0" version = "0.1.0"
authors = ["plazmoid <kronos44@mail.ru>"] authors = ["plazmoid <kronos44@mail.ru>"]
edition = "2018" edition = "2018"

@ -11,25 +11,21 @@ use std::{
use env_logger; use env_logger;
use tokio::sync::Mutex; use tokio::sync::Mutex;
use uuid::Uuid; use uuid::Uuid;
use tokio::join;
use u_lib::{ use u_lib::{
MASTER_SERVER,
MASTER_PORT, MASTER_PORT,
contracts::*, contracts::*,
Job client::*
}; };
type SharedStorage = Arc<Mutex<CliStorage>>;
fn get_content() -> impl Filter< fn get_content() -> impl Filter<Extract = (Message<'static, ClientInfo>,),
Extract = (Message<'static, ClientInfo>,), Error = Rejection> + Clone {
Error = Rejection
> + Clone {
body::content_length_limit(1024*64).and(body::json::<Message<ClientInfo>>()) body::content_length_limit(1024*64).and(body::json::<Message<ClientInfo>>())
} }
async fn add_client(msg: Message<'_, ClientInfo>, db: SharedStorage) -> async fn add_client(msg: Message<'_, ClientInfo>,
Result<impl Reply, Rejection> { db: SharedStorage) -> Result<impl Reply, Rejection> {
let new_cli = msg.item; let new_cli = msg.item;
let mut clients = db.lock().await; let mut clients = db.lock().await;
if clients.contains_key(&new_cli.id) { if clients.contains_key(&new_cli.id) {
@ -47,8 +43,7 @@ Result<impl Reply, Rejection> {
} }
} }
async fn listing(db: SharedStorage) -> async fn listing(db: SharedStorage) -> Result<impl Reply, Rejection> {
Result<impl Reply, Rejection> {
let clients = db.lock().await; let clients = db.lock().await;
let mut result: Vec<ClientInfo> = Vec::with_capacity(clients.len()); let mut result: Vec<ClientInfo> = Vec::with_capacity(clients.len());
for cli in clients.values() { for cli in clients.values() {

@ -12,3 +12,5 @@ uuid = { version = "^0.8.1", features = ["serde", "v4"] }
nix = "0.17" nix = "0.17"
libc = "^0.2" libc = "^0.2"
lazy_static = "1.4.0" lazy_static = "1.4.0"
tokio = { version = "*", features = ["macros", "process"] }
reqwest = { version = "0.10.7", features = ["json"] }

@ -6,24 +6,24 @@ use std::{
collections::HashMap collections::HashMap
}; };
use uuid::Uuid; use uuid::Uuid;
use super::{ use crate::{
ToMsg, contracts::*,
Job UID
}; };
use crate::UID;
pub type CliStorage = HashMap<Uuid, UClient>;
pub struct UClient { pub struct UClient {
pub client_info: ClientInfo, pub client_info: ClientInfo,
pub jobs: Vec<Box<Jobs>> // TODO: to futures pub jobs: JobPool, // TODO: to futures
pub is_admin: bool,
} }
impl UClient { impl UClient {
pub fn new(client_info: ClientInfo) -> Self { pub fn new(client_info: ClientInfo) -> Self {
Self { Self {
client_info, client_info,
jobs: Vec::new() jobs: Vec::new(),
is_admin: false
} }
} }
} }

@ -0,0 +1,4 @@
pub mod network;
pub mod client;
pub use client::*;

@ -1,7 +1,8 @@
use u_lib::{ use crate::{
MASTER_SERVER, MASTER_SERVER,
MASTER_PORT, MASTER_PORT,
contracts::* contracts::*,
client::*
}; };
use reqwest::{ use reqwest::{
Client, Client,

@ -0,0 +1,15 @@
use {
super::*,
tokio::sync::Mutex,
std::sync::Arc,
std::collections::HashMap,
uuid::Uuid,
crate::client::*
};
pub type JobPool = Vec<Box<dyn Job>>;
pub type JobResult = Result<Vec<u8>, Vec<u8>>;
pub type CliStorage = HashMap<Uuid, UClient>;
pub type SharedStorage = Arc<Mutex<CliStorage>>;

@ -1,55 +1,58 @@
use std::process::{ use std::{
Command, process::Command
Output
}; };
//use tokio::process::Command;
pub type JobResult<'res> = Result<&'res [u8], &'res [u8]>; use super::*;
pub trait Job { pub trait Job {
async fn run(&mut self); fn run(&mut self);
fn result(&self) -> JobResult; fn get_result(&self) -> &JobResult;
} }
pub struct ShellJob<'cmd> { pub struct ShellJob {
pub result: JobResult<'cmd>, pub result: JobResult,
pub cmd: &'cmd str, pub cmd: String,
pub args: Vec<&'cmd str> pub args: Vec<String>
} }
impl ShellJob { impl ShellJob {
pub fn from_raw(raw_cmd: &str) -> Self { pub fn from_raw(raw_cmd: String) -> Self {
let cmd_parts = raw_cmd.split(" "); let mut cmd_parts = raw_cmd
.split(" ")
.map(String::from)
.collect::<Vec<String>>();
let args: Vec<_> = cmd_parts.drain(1..).collect();
Self { Self {
cmd: cmd_parts[0], cmd: cmd_parts.into_iter().nth(1).unwrap(),
args: cmd_parts[1..], args,
result: Err("Did not run".as_bytes()) result: Err(b"Did not run".to_vec())
} }
} }
} }
impl Job for ShellJob { impl Job for ShellJob{
async fn run(&mut self) { fn run(&mut self) {
let result = Command::new(self.cmd) let result = Command::new(&self.cmd)
.args(&self.args) .args(&self.args)
.output(); .output();
self.result = match result { self.result = match result {
Ok(output) => { Ok(output) => {
if output.status != 0 { if output.status.success() {
Err(&output.stderr) Ok(output.stdout.to_vec())
} else { } else {
Ok(&output.stdout) Err(output.stderr.to_vec())
} }
} }
Err(e) => e.to_string().as_bytes() Err(e) => Err(e.to_string().into_bytes())
} }
} }
fn result(&self) -> JobResult { fn get_result(&self) -> &JobResult {
self.result &self.result
} }
} }
/*
pub struct PyJob {
}*/ /* pub struct PyJob {
} */

@ -51,3 +51,20 @@ where I: Clone {
pub struct RawMsg(pub String); pub struct RawMsg(pub String);
impl ToMsg for RawMsg {} impl ToMsg for RawMsg {}
/*
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_create_message_owned() {
let item = String::from("QWEDSA");
let msg_raw = Message {
id: *UID,
item: Cow::Owned(item.clone())
};
let msg = Message::new(item);
assert_eq!(msg_raw.item, msg.item);
}
}*/

@ -1,11 +1,12 @@
pub mod jobs; pub mod jobs;
pub mod client;
pub mod messaging; pub mod messaging;
pub mod datatypes;
pub use { pub use {
client::*, crate::client::client::*,
messaging::*, messaging::*,
jobs::* jobs::*,
datatypes::*
}; };
use std::{ use std::{

@ -1,9 +1,12 @@
pub mod config; pub mod config;
pub mod contracts; pub mod contracts;
pub mod utils; pub mod utils;
pub mod client;
pub use utils::*; pub use {
pub use config::*; utils::*,
config::*,
};
#[macro_use] #[macro_use]
extern crate lazy_static; extern crate lazy_static;

Loading…
Cancel
Save