]>
git.proxmox.com Git - pmg-gui.git/blob - js/mobile/utils.js
1 Template7
.registerHelper('gettext', function(value
) {
8 let cookies
= document
.cookie
.split(/;\s*/);
9 for (let i
= 0; i
< cookies
.length
; i
++) {
10 let cookie
= cookies
[i
].split('=');
11 if (cookie
[0] === name
&& cookie
.length
> 1) {
17 setCookie(name
, value
, expires
) {
18 value
= encodeURIComponent(value
);
19 let cookie
= `${name}=${value}`;
21 cookie
+= `; expires=${expires}`;
23 document
.cookie
= cookie
;
26 PMG
.Utils
.setCookie(name
, "", "Thu, 01 Jan 1970 00:00:00 UTC");
29 var authCookie
= PMG
.Utils
.getCookie('PMGAuthCookie') || "";
30 return (authCookie
.substr(0,7) === 'PMGQUAR' && Proxmox
.UserName
!== '');
33 let fields
= iso
.split('-').map((field
) => parseInt(field
, 10));
34 // monthIndex starts at 0
35 let date
= new Date(fields
[0],fields
[1]-1, fields
[2]);
36 return Math
.round(date
.getTime()/1000);
39 let date
= new Date(unix
*1000);
40 let year
= date
.getFullYear().toString();
41 let month
= (date
.getMonth()+1).toString().padStart(2, "0");
42 let day
= date
.getDate().toString().padStart(2, "0");
43 return `${year}-${month}-${day}`;
46 let statusText
= "", errorText
= "";
47 if (xhr
instanceof Error
) {
48 statusText
= gettext("Error");
49 errorText
= xhr
.message
;
50 } else if (xhr
.error
instanceof Error
) {
51 statusText
= gettext("Error");
52 errorText
= xhr
.error
.message
;
54 statusText
= xhr
.status
.toString() + ' ' + xhr
.statusText
;
56 let errorObj
= JSON
.parse(xhr
.responseText
);
57 if (errorObj
.errors
) {
58 let errors
= Object
.keys(errorObj
.errors
).map((key
) => key
+ ": " + errorObj
.errors
[key
]);
59 errorText
= errors
.join('<br>');
62 statusText
= gettext("Error");
63 errorText
= e
.message
;
76 let queryObj
= app
.utils
.parseUrlQuery(location
.search
);
77 let mail
, action
, date
, username
, ticket
;
78 if (queryObj
.ticket
) {
79 let tocheck
= decodeURIComponent(queryObj
.ticket
);
80 let match
= tocheck
.match(/^PMGQUAR:([^\s\:]+):/);
85 delete queryObj
.ticket
;
93 if (queryObj
.cselect
) {
94 mail
= queryObj
.cselect
;
95 action
= queryObj
.action
;
96 delete queryObj
.cselect
;
97 delete queryObj
.action
;
100 if (mail
|| action
|| date
|| ticket
) {
101 let queryString
= app
.utils
.serializeObject(queryObj
);
102 window
.history
.replaceState(
103 window
.history
.state
,
105 location
.pathname
+ (queryString
? "?" + queryString
: '')
109 return { mail
, action
, date
, username
, ticket
};
111 setLoginInfo(result
) {
112 PMG
.Utils
.setCookie('PMGAuthCookie', result
.data
.ticket
);
113 Proxmox
.CSRFPreventionToken
= result
.data
.CSRFPreventionToken
;
115 getSubscriptionInfo() {
116 return new Promise(function(resolve
, reject
) {
118 url
: '/api2/json/nodes/localhost/subscription',
120 success
: (result
, status
, xhr
) => {
121 resolve(result
.data
);
123 error
: (xhr
, status
) => {
129 checkSubscription(data
, showPopup
) {
130 return new Promise(function(resolve
, reject
) {
131 if (data
.status
!== 'Active') {
132 let url
= data
.url
|| 'https://wwww.proxmox.com';
133 let err
= `You do not have a valid subscription for this server.
135 <a target="_blank" href="${url}">www.proxmox.com</a>
136 to get a list of available options.`;
137 app
.toolbar
.show('.toolbar.subscription');
138 $$('.button.subscription').on('click', () => {
141 gettext("No valid subscription"),
147 gettext("No valid subscription"),
156 $$('.toolbar.subscription').remove();