]>
git.proxmox.com Git - pmg-gui.git/blob - js/mobile/utils.js
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
;
72 let queryObj
= app
.utils
.parseUrlQuery(location
.search
);
73 let mail
, action
, date
, username
, ticket
;
74 if (queryObj
.ticket
) {
75 let tocheck
= decodeURIComponent(queryObj
.ticket
);
76 let match
= tocheck
.match(/^PMGQUAR:([^\s:]+):/);
81 delete queryObj
.ticket
;
89 if (queryObj
.cselect
) {
90 mail
= queryObj
.cselect
;
91 action
= queryObj
.action
;
92 delete queryObj
.cselect
;
93 delete queryObj
.action
;
96 if (mail
|| action
|| date
|| ticket
) {
97 let queryString
= app
.utils
.serializeObject(queryObj
);
98 window
.history
.replaceState(
101 location
.pathname
+ (queryString
? "?" + queryString
: ''),
105 return { mail
, action
, date
, username
, ticket
};
107 setLoginInfo(result
) {
108 PMG
.Utils
.setCookie('PMGAuthCookie', result
.data
.ticket
);
109 Proxmox
.CSRFPreventionToken
= result
.data
.CSRFPreventionToken
;
111 getSubscriptionInfo() {
112 return new Promise(function(resolve
, reject
) {
114 url
: '/api2/json/nodes/localhost/subscription',
116 success
: (result
, status
, xhr
) => {
117 resolve(result
.data
);
119 error
: (xhr
, status
) => {
125 checkSubscription(data
, showPopup
) {
126 return new Promise(function(resolve
, reject
) {
127 if (data
.status
!== 'Active') {
128 let url
= data
.url
|| 'https://wwww.proxmox.com';
129 let err
= `You do not have a valid subscription for this server.
131 <a target="_blank" href="${url}">www.proxmox.com</a>
132 to get a list of available options.`;
133 app
.toolbar
.show('.toolbar.subscription');
134 $$('.button.subscription').on('click', () => {
137 gettext("No valid subscription"),
143 gettext("No valid subscription"),
152 $$('.toolbar.subscription').remove();