From 7e13b2d67ff6d9d765c55ed1571f53c24d4b6f12 Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Tue, 22 Jan 2019 12:50:19 +0100 Subject: [PATCH] api2/subscription.rs: add subscription api class --- Cargo.toml | 1 + src/api2/subscription.rs | 28 ++++++++++++++++++++++++++++ src/tools.rs | 13 +++++++++++++ 3 files changed, 42 insertions(+) create mode 100644 src/api2/subscription.rs diff --git a/Cargo.toml b/Cargo.toml index 763bacdd..c72d0ef7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -30,4 +30,5 @@ openssl = "0.10" siphasher = "0.3" endian_trait = "0.6" walkdir = "2" +md5 = "0.6" diff --git a/src/api2/subscription.rs b/src/api2/subscription.rs new file mode 100644 index 00000000..5bc0bc55 --- /dev/null +++ b/src/api2/subscription.rs @@ -0,0 +1,28 @@ +use failure::*; + +use crate::tools; +use crate::api::schema::*; +use crate::api::router::*; +use serde_json::{json, Value}; + + +fn get_subscription(_param: Value, _info: &ApiMethod) -> Result { + + let url = "https://www.proxmox.com/en/proxmox-backup-server/pricing"; + Ok(json!({ + "status": "NotFound", + "message": "There is no subscription key", + "serverid": tools::get_hardware_address()?, + "url": url, + })) +} + +pub fn router() -> Router { + + let route = Router::new() + .get(ApiMethod::new( + get_subscription, + ObjectSchema::new("Read subscription info."))); + + route +} diff --git a/src/tools.rs b/src/tools.rs index da512aa8..3c3fe2ec 100644 --- a/src/tools.rs +++ b/src/tools.rs @@ -355,3 +355,16 @@ pub fn scandir( } Ok(()) } + +pub fn get_hardware_address() -> Result { + + static FILENAME: &str = "/etc/ssh/assh_host_rsa_key.pub"; + + let mut file = File::open(FILENAME)?; + let mut contents = Vec::new(); + file.read_to_end(&mut contents)?; + + let digest = md5::compute(contents); + + Ok(format!("{:0x}", digest)) +}