]>
git.proxmox.com Git - pmg-gui.git/blob - js/mobile/utils.js
33ed019a1e77d8edca0c4779983165160b0515ea
4 let cookies
= document
.cookie
.split(/;\s*/);
5 for (let i
= 0; i
< cookies
.length
; i
++) {
6 let cookie
= cookies
[i
].split('=');
7 if (cookie
[0] === name
&& cookie
.length
> 1) {
13 setCookie(name
, value
, expires
) {
14 value
= encodeURIComponent(value
);
15 let cookie
= `${name}=${value}`;
17 cookie
+= `; expires=${expires}`;
19 document
.cookie
= cookie
;
22 PMG
.Utils
.setCookie(name
, "", "Thu, 01 Jan 1970 00:00:00 UTC");
25 var authCookie
= PMG
.Utils
.getCookie('PMGAuthCookie') || "";
26 return authCookie
.substr(0, 7) === 'PMGQUAR' && Proxmox
.UserName
!== '';
29 let fields
= iso
.split('-').map((field
) => parseInt(field
, 10));
30 // monthIndex starts at 0
31 let date
= new Date(fields
[0], fields
[1]-1, fields
[2]);
32 return Math
.round(date
.getTime()/1000);
35 let date
= new Date(unix
*1000);
36 let year
= date
.getFullYear().toString();
37 let month
= (date
.getMonth()+1).toString().padStart(2, "0");
38 let day
= date
.getDate().toString().padStart(2, "0");
39 return `${year}-${month}-${day}`;
42 let statusText
= "", errorText
= "";
43 if (xhr
instanceof Error
) {
44 statusText
= gettext("Error");
45 errorText
= xhr
.message
;
46 } else if (xhr
.error
instanceof Error
) {
47 statusText
= gettext("Error");
48 errorText
= xhr
.error
.message
;
50 statusText
= xhr
.status
.toString() + ' ' + xhr
.statusText
;
52 let errorObj
= JSON
.parse(xhr
.responseText
);
53 if (errorObj
.errors
) {
54 let errors
= Object
.keys(errorObj
.errors
).map((key
) => key
+ ": " + errorObj
.errors
[key
]);
55 errorText
= errors
.join('<br>');
58 statusText
= gettext("Error");
59 errorText
= e
.message
;
71 showSuccessToast(msg
) {
80 let queryObj
= app
.utils
.parseUrlQuery(location
.search
);
81 let mail
, action
, date
, username
, ticket
;
82 if (queryObj
.ticket
) {
83 let tocheck
= decodeURIComponent(queryObj
.ticket
);
84 let match
= tocheck
.match(/^PMGQUAR:([^\s:]+):/);
89 delete queryObj
.ticket
;
97 if (queryObj
.cselect
) {
98 mail
= queryObj
.cselect
;
99 action
= queryObj
.action
;
100 delete queryObj
.cselect
;
101 delete queryObj
.action
;
104 if (mail
|| action
|| date
|| ticket
) {
105 let queryString
= app
.utils
.serializeObject(queryObj
);
106 window
.history
.replaceState(
107 window
.history
.state
,
109 location
.pathname
+ (queryString
? "?" + queryString
: ''),
113 return { mail
, action
, date
, username
, ticket
};
115 setLoginInfo(result
) {
116 PMG
.Utils
.setCookie('PMGAuthCookie', result
.data
.ticket
);
117 Proxmox
.CSRFPreventionToken
= result
.data
.CSRFPreventionToken
;
119 getSubscriptionInfo() {
120 return new Promise(function(resolve
, reject
) {
122 url
: '/api2/json/nodes/localhost/subscription',
124 success
: (result
, status
, xhr
) => {
125 resolve(result
.data
);
127 error
: (xhr
, status
) => {
133 checkSubscription(data
, showPopup
) {
134 return new Promise(function(resolve
, reject
) {
135 if (data
.status
!== 'Active') {
136 let url
= data
.url
|| 'https://wwww.proxmox.com';
137 let err
= `You do not have a valid subscription for this server.
139 <a target="_blank" href="${url}">www.proxmox.com</a>
140 to get a list of available options.`;
141 app
.toolbar
.show('.toolbar.subscription');
142 $$('.button.subscription').on('click', () => {
145 gettext("No valid subscription"),
151 gettext("No valid subscription"),
160 $$('.toolbar.subscription').remove();