2020-04-17 12:11:25 +00:00
|
|
|
use anyhow::{Error};
|
2019-01-22 11:50:19 +00:00
|
|
|
use serde_json::{json, Value};
|
|
|
|
|
2020-09-16 09:51:13 +00:00
|
|
|
use proxmox::api::{api, Router, RpcEnvironment, Permission};
|
2019-11-21 13:36:28 +00:00
|
|
|
|
|
|
|
use crate::tools;
|
2020-04-17 13:14:28 +00:00
|
|
|
use crate::config::acl::PRIV_SYS_AUDIT;
|
2020-09-16 09:51:13 +00:00
|
|
|
use crate::config::cached_user_info::CachedUserInfo;
|
|
|
|
use crate::api2::types::{NODE_SCHEMA, Userid};
|
2019-01-22 11:50:19 +00:00
|
|
|
|
2020-04-17 13:14:28 +00:00
|
|
|
#[api(
|
2020-07-21 11:41:06 +00:00
|
|
|
input: {
|
|
|
|
properties: {
|
|
|
|
node: {
|
|
|
|
schema: NODE_SCHEMA,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2020-04-17 13:14:28 +00:00
|
|
|
returns: {
|
|
|
|
description: "Subscription status.",
|
|
|
|
properties: {
|
|
|
|
status: {
|
|
|
|
type: String,
|
|
|
|
description: "'NotFound', 'active' or 'inactive'."
|
|
|
|
},
|
|
|
|
message: {
|
|
|
|
type: String,
|
|
|
|
description: "Human readable problem description.",
|
|
|
|
},
|
|
|
|
serverid: {
|
|
|
|
type: String,
|
2020-09-16 09:51:13 +00:00
|
|
|
description: "The unique server ID, if permitted to access.",
|
2020-04-17 13:14:28 +00:00
|
|
|
},
|
|
|
|
url: {
|
|
|
|
type: String,
|
|
|
|
description: "URL to Web Shop.",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
access: {
|
2020-09-16 09:51:13 +00:00
|
|
|
permission: &Permission::Anybody,
|
2020-04-17 13:14:28 +00:00
|
|
|
},
|
|
|
|
)]
|
|
|
|
/// Read subscription info.
|
2020-09-16 09:51:13 +00:00
|
|
|
fn get_subscription(
|
|
|
|
_param: Value,
|
|
|
|
rpcenv: &mut dyn RpcEnvironment,
|
|
|
|
) -> Result<Value, Error> {
|
|
|
|
let userid: Userid = rpcenv.get_user().unwrap().parse()?;
|
|
|
|
let user_info = CachedUserInfo::new()?;
|
|
|
|
let user_privs = user_info.lookup_privs(&userid, &[]);
|
|
|
|
let server_id = if (user_privs & PRIV_SYS_AUDIT) != 0 {
|
|
|
|
tools::get_hardware_address()?
|
|
|
|
} else {
|
|
|
|
"hidden".to_string()
|
|
|
|
};
|
2019-01-22 11:50:19 +00:00
|
|
|
|
|
|
|
let url = "https://www.proxmox.com/en/proxmox-backup-server/pricing";
|
|
|
|
Ok(json!({
|
|
|
|
"status": "NotFound",
|
2020-09-16 09:51:13 +00:00
|
|
|
"message": "There is no subscription key",
|
|
|
|
"serverid": server_id,
|
|
|
|
"url": url,
|
2019-01-22 11:50:19 +00:00
|
|
|
}))
|
|
|
|
}
|
|
|
|
|
2019-11-21 08:36:41 +00:00
|
|
|
pub const ROUTER: Router = Router::new()
|
2020-04-17 13:14:28 +00:00
|
|
|
.get(&API_METHOD_GET_SUBSCRIPTION);
|