saving current changes
This commit is contained in:
@@ -88,19 +88,28 @@ async fn main() {
|
|||||||
|
|
||||||
// Test map port output
|
// Test map port output
|
||||||
println!("{:#?}", p2prc_map_port_command("3000","test.akilan.io",""));
|
println!("{:#?}", p2prc_map_port_command("3000","test.akilan.io",""));
|
||||||
|
|
||||||
let mut config = p2prc_read_config();
|
let mut config = p2prc_read_config();
|
||||||
|
|
||||||
// Change server port
|
// Change server port
|
||||||
config.server_port = "1233".parse().unwrap();
|
config.server_port = "1233".parse().unwrap();
|
||||||
|
|
||||||
p2prc_write_config(config);
|
p2prc_write_config(config);
|
||||||
|
|
||||||
println!("{:#?}", p2prc_read_config());
|
println!("{:#?}", p2prc_read_config());
|
||||||
|
|
||||||
|
// p2prc_default_config();
|
||||||
|
|
||||||
|
// println!("{:#?}", p2prc_read_config());
|
||||||
|
|
||||||
|
println!("{:#?}", p2prc_get_specs("217.76.63.222:32921".to_string()));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// println!("{}", p2prc_map_port_command("3000", "0.0.0.0",""));
|
// println!("{}", p2prc_map_port_command("3000", "0.0.0.0",""));
|
||||||
// println!("Starting SpinProcess...");
|
// println!("Starting SpinProcess...");
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
use std::fs;
|
use std::fs;
|
||||||
use std::io::Error;
|
use std::io::Error;
|
||||||
|
use std::net::IpAddr;
|
||||||
use std::process::{Command, Output};
|
use std::process::{Command, Output};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use serde::de::DeserializeOwned;
|
use serde::de::DeserializeOwned;
|
||||||
@@ -90,6 +91,20 @@ pub struct MapPort {
|
|||||||
pub entire_address: String,
|
pub entire_address: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
|
pub struct Specs {
|
||||||
|
#[serde(rename = "Hostname")]
|
||||||
|
pub hostname: String,
|
||||||
|
#[serde(rename = "Platform")]
|
||||||
|
pub platform: String,
|
||||||
|
#[serde(rename = "CPU")]
|
||||||
|
pub cpu: String,
|
||||||
|
#[serde(rename = "RAM")]
|
||||||
|
pub ram: i64,
|
||||||
|
#[serde(rename = "Disk")]
|
||||||
|
pub disk: i64,
|
||||||
|
}
|
||||||
|
|
||||||
// Runs p2prc with custom arguments called.
|
// Runs p2prc with custom arguments called.
|
||||||
// Function implemented as an identity function
|
// Function implemented as an identity function
|
||||||
pub fn run_p2prc_command<T>(arguments: &str) -> T
|
pub fn run_p2prc_command<T>(arguments: &str) -> T
|
||||||
@@ -103,7 +118,7 @@ where
|
|||||||
.arg(&command_str)
|
.arg(&command_str)
|
||||||
.output()
|
.output()
|
||||||
.expect("Failed to execute command");
|
.expect("Failed to execute command");
|
||||||
|
|
||||||
let stdout = String::from_utf8_lossy(&output.stdout);
|
let stdout = String::from_utf8_lossy(&output.stdout);
|
||||||
serde_json::from_str(&stdout).expect("Failed to deserialize JSON output")
|
serde_json::from_str(&stdout).expect("Failed to deserialize JSON output")
|
||||||
}
|
}
|
||||||
@@ -160,3 +175,17 @@ pub fn p2prc_write_config(config: Config) {
|
|||||||
fs::write(config.config_path, json).expect("Panic message: ");
|
fs::write(config.config_path, json).expect("Panic message: ");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set default config (--dc command)
|
||||||
|
pub fn p2prc_default_config() {
|
||||||
|
let _: Option<bool> = run_p2prc_command(&*"--dc".to_string());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get hardware information of a remote server
|
||||||
|
pub fn p2prc_get_specs(ip_addr: String) -> Specs {
|
||||||
|
let command: String = format!("--specs {}", ip_addr);
|
||||||
|
let specs: Specs = run_p2prc_command(&*command);
|
||||||
|
specs
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user