api2/subscription.rs: add subscription api class
This commit is contained in:
parent
576e3bf252
commit
7e13b2d67f
@ -30,4 +30,5 @@ openssl = "0.10"
|
||||
siphasher = "0.3"
|
||||
endian_trait = "0.6"
|
||||
walkdir = "2"
|
||||
md5 = "0.6"
|
||||
|
||||
|
28
src/api2/subscription.rs
Normal file
28
src/api2/subscription.rs
Normal file
@ -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<Value, Error> {
|
||||
|
||||
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
|
||||
}
|
13
src/tools.rs
13
src/tools.rs
@ -355,3 +355,16 @@ pub fn scandir<P, F>(
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn get_hardware_address() -> Result<String, Error> {
|
||||
|
||||
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))
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user