]>
git.proxmox.com Git - proxmox-backup.git/blob - www/window/AddTfaRecovery.js
1 Ext
.define('PBS.window.AddTfaRecovery', {
2 extend
: 'Proxmox.window.Edit',
3 alias
: 'widget.pbsAddTfaRecovery',
4 mixins
: ['Proxmox.Mixin.CBind'],
6 onlineHelp
: 'user_mgmt',
9 subject
: gettext('TFA recovery keys'),
15 url
: '/api2/extjs/access/tfa',
16 submitUrl: function(url
, values
) {
17 let userid
= values
.userid
;
19 return `${url}/${userid}`;
22 apiCallDone: function(success
, response
) {
31 .map((v
, i
) => `${i}: ${v}`)
33 Ext
.create('PBS.window.TfaRecoveryShow', {
35 userid
: this.getViewModel().get('userid'),
46 passwordConfirmText
: (get) => {
47 let id
= get('userid');
48 return Ext
.String
.format(gettext("Confirm password of '{0}'"), id
);
54 xclass
: 'Ext.app.ViewController',
55 hasEntry
: async
function(userid
) {
57 let view
= me
.getView();
60 await PBS
.Async
.api2({
61 url
: `${view.url}/${userid}/recovery`,
70 init: function(view
) {
71 this.onUseridChange(null, Proxmox
.UserName
);
74 onUseridChange
: async
function(field
, userid
) {
76 let vm
= me
.getViewModel();
79 vm
.set('userid', userid
);
81 let has_entry
= await me
.hasEntry(userid
);
82 vm
.set('has_entry', has_entry
);
88 xtype
: 'pmxDisplayEditField',
91 editable
: (get) => !get('fixedUser'),
92 value
: () => Proxmox
.UserName
,
94 fieldLabel
: gettext('User'),
96 xtype
: 'pbsUserSelector',
98 validator: function(_value
) {
99 return !this.up('window').getViewModel().get('has_entry');
102 renderer
: Ext
.String
.htmlEncode
,
104 change
: 'onUseridChange',
108 xtype
: 'hiddenfield',
113 xtype
: 'displayfield',
115 hidden
: '{!has_entry}',
119 value
: gettext('User already has recovery keys.'),
124 reference
: 'password',
125 fieldLabel
: gettext('Verify Password'),
126 inputType
: 'password',
131 hidden
: () => Proxmox
.UserName
=== 'root@pam',
132 disabled
: () => Proxmox
.UserName
=== 'root@pam',
135 emptyText
: '{passwordConfirmText}',
141 Ext
.define('PBS.window.TfaRecoveryShow', {
142 extend
: 'Ext.window.Window',
143 alias
: ['widget.pbsTfaRecoveryShow'],
144 mixins
: ['Proxmox.Mixin.CBind'],
149 title
: gettext('Recovery Keys'),
165 inputId
: 'token-secret-value',
170 'fontFamily': 'monospace',
175 xtype
: 'displayfield',
179 value
: gettext('Please record recovery keys - they will only be displayed now'),
186 handler: function(b
) {
187 document
.getElementById('token-secret-value').select();
188 document
.execCommand("copy");
190 iconCls
: 'fa fa-clipboard',
191 text
: gettext('Copy Recovery Keys'),
194 handler: function(b
) {
195 let win
= this.up('window');
196 win
.paperkeys(win
.values
, win
.userid
);
198 iconCls
: 'fa fa-print',
199 text
: gettext('Print Recovery Keys'),
202 paperkeys: function(keyString
, userid
) {
205 let printFrame
= document
.createElement("iframe");
206 Object
.assign(printFrame
.style
, {
214 const host
= document
.location
.host
;
215 const title
= document
.title
;
216 const html
= `<html><head><script>
217 window.addEventListener('DOMContentLoaded', (ev) => window.print());
218 </script><style>@media print and (max-height: 150mm) {
219 h4, p { margin: 0; font-size: 1em; }
220 }</style></head><body style="padding: 5px;">
221 <h4>Recovery Keys for '${userid}' - ${title} (${host})</h4>
222 <p style="font-size:1.5em;line-height:1.5em;font-family:monospace;
223 white-space:pre-wrap;overflow-wrap:break-word;">
228 printFrame
.src
= "data:text/html;base64," + btoa(html
);
229 document
.body
.appendChild(printFrame
);