]> git.proxmox.com Git - proxmox-backup.git/blob - src/api2/node/subscription.rs
always allow retrieving (censored) subscription info
[proxmox-backup.git] / src / api2 / node / subscription.rs
1 use anyhow::{Error};
2 use serde_json::{json, Value};
3
4 use proxmox::api::{api, Router, RpcEnvironment, Permission};
5
6 use crate::tools;
7 use crate::config::acl::PRIV_SYS_AUDIT;
8 use crate::config::cached_user_info::CachedUserInfo;
9 use crate::api2::types::{NODE_SCHEMA, Userid};
10
11 #[api(
12 input: {
13 properties: {
14 node: {
15 schema: NODE_SCHEMA,
16 },
17 },
18 },
19 returns: {
20 description: "Subscription status.",
21 properties: {
22 status: {
23 type: String,
24 description: "'NotFound', 'active' or 'inactive'."
25 },
26 message: {
27 type: String,
28 description: "Human readable problem description.",
29 },
30 serverid: {
31 type: String,
32 description: "The unique server ID, if permitted to access.",
33 },
34 url: {
35 type: String,
36 description: "URL to Web Shop.",
37 },
38 },
39 },
40 access: {
41 permission: &Permission::Anybody,
42 },
43 )]
44 /// Read subscription info.
45 fn get_subscription(
46 _param: Value,
47 rpcenv: &mut dyn RpcEnvironment,
48 ) -> Result<Value, Error> {
49 let userid: Userid = rpcenv.get_user().unwrap().parse()?;
50 let user_info = CachedUserInfo::new()?;
51 let user_privs = user_info.lookup_privs(&userid, &[]);
52 let server_id = if (user_privs & PRIV_SYS_AUDIT) != 0 {
53 tools::get_hardware_address()?
54 } else {
55 "hidden".to_string()
56 };
57
58 let url = "https://www.proxmox.com/en/proxmox-backup-server/pricing";
59 Ok(json!({
60 "status": "NotFound",
61 "message": "There is no subscription key",
62 "serverid": server_id,
63 "url": url,
64 }))
65 }
66
67 pub const ROUTER: Router = Router::new()
68 .get(&API_METHOD_GET_SUBSCRIPTION);