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

@ -9,10 +9,14 @@
//mod jobs;
use std::thread::sleep;
use std::time::Duration;
use {
std::thread::sleep,
std::time::Duration,
u_lib::client::*
};
mod executor;
mod network;
use network::ClientHandler;
#[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]
name = "u-run"
name = "u_run"
version = "0.1.0"
authors = ["plazmoid <kronos44@mail.ru>"]
edition = "2018"

@ -19,7 +19,7 @@ fn get_uagent_data() -> Option<Vec<u8>> {
let ls = read_dir("./").unwrap();
for dirfile in ls {
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 data: Vec<u8> = vec![];
file.read_to_end(&mut data).unwrap();

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

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

@ -12,3 +12,5 @@ uuid = { version = "^0.8.1", features = ["serde", "v4"] }
nix = "0.17"
libc = "^0.2"
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
};
use uuid::Uuid;
use super::{
ToMsg,
Job
use crate::{
contracts::*,
UID
};
use crate::UID;
pub type CliStorage = HashMap<Uuid, UClient>;
pub struct UClient {
pub client_info: ClientInfo,
pub jobs: Vec<Box<Jobs>> // TODO: to futures
pub jobs: JobPool, // TODO: to futures
pub is_admin: bool,
}
impl UClient {
pub fn new(client_info: ClientInfo) -> Self {
Self {
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_PORT,
contracts::*
contracts::*,
client::*
};
use reqwest::{
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::{
Command,
Output
use std::{
process::Command
};
pub type JobResult<'res> = Result<&'res [u8], &'res [u8]>;
//use tokio::process::Command;
use super::*;
pub trait Job {
async fn run(&mut self);
fn result(&self) -> JobResult;
fn run(&mut self);
fn get_result(&self) -> &JobResult;
}
pub struct ShellJob<'cmd> {
pub result: JobResult<'cmd>,
pub cmd: &'cmd str,
pub args: Vec<&'cmd str>
pub struct ShellJob {
pub result: JobResult,
pub cmd: String,
pub args: Vec<String>
}
impl ShellJob {
pub fn from_raw(raw_cmd: &str) -> Self {
let cmd_parts = raw_cmd.split(" ");
pub fn from_raw(raw_cmd: String) -> Self {
let mut cmd_parts = raw_cmd
.split(" ")
.map(String::from)
.collect::<Vec<String>>();
let args: Vec<_> = cmd_parts.drain(1..).collect();
Self {
cmd: cmd_parts[0],
args: cmd_parts[1..],
result: Err("Did not run".as_bytes())
cmd: cmd_parts.into_iter().nth(1).unwrap(),
args,
result: Err(b"Did not run".to_vec())
}
}
}
impl Job for ShellJob{
async fn run(&mut self) {
let result = Command::new(self.cmd)
fn run(&mut self) {
let result = Command::new(&self.cmd)
.args(&self.args)
.output();
self.result = match result {
Ok(output) => {
if output.status != 0 {
Err(&output.stderr)
if output.status.success() {
Ok(output.stdout.to_vec())
} 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 {
self.result
fn get_result(&self) -> &JobResult {
&self.result
}
}
/*
pub struct PyJob {
/* pub struct PyJob {
} */

@ -51,3 +51,20 @@ where I: Clone {
pub struct RawMsg(pub String);
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 client;
pub mod messaging;
pub mod datatypes;
pub use {
client::*,
crate::client::client::*,
messaging::*,
jobs::*
jobs::*,
datatypes::*
};
use std::{

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

Loading…
Cancel
Save