Advertisement
Guest User

proxmox node reboot/shutdown molly-guard

a guest
Dec 13th, 2019
258
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. diff -u /usr/share/pve-manager/js/pvemanagerlib.js.orig /usr/share/pve-manager/js/pvemanagerlib.js
  2. --- /usr/share/pve-manager/js/pvemanagerlib.js.orig     2019-12-04 13:57:35.147696162 +0100
  3. +++ /usr/share/pve-manager/js/pvemanagerlib.js  2019-12-13 18:04:18.429662045 +0100
  4. @@ -9669,6 +9669,173 @@
  5.         me.callParent();
  6.      }
  7.  });
  8. +
  9. +/* Popup a message window
  10. + * where the user has to manually enter the nodename
  11. + * to enable the reboot/shutdown button
  12. + */
  13. +Ext.define('PVE.window.SafeNodeCommand', {
  14. +    extend: 'Ext.window.Window',
  15. +    alias: 'widget.pveSafeNodeCommand',
  16. +
  17. +    title: gettext('Confirm'),
  18. +    modal: true,
  19. +    buttonAlign: 'center',
  20. +    bodyPadding: 10,
  21. +    width: 450,
  22. +    layout: { type:'hbox' },
  23. +    defaultFocus: 'confirmField',
  24. +    showProgress: false,
  25. +
  26. +    config: {
  27. +        item: {
  28. +            nodename: undefined,
  29. +            command: undefined
  30. +        },
  31. +        url: undefined,
  32. +        params: {}
  33. +    },
  34. +
  35. +       /*
  36. +    getParams: function() {
  37. +        var me = this;
  38. +        if (Ext.Object.isEmpty(me.params)) {
  39. +            return '';
  40. +        }
  41. +        return '?' + Ext.Object.toQueryString(me.params);
  42. +    },
  43. +    */
  44. +
  45. +    controller: {
  46. +
  47. +        xclass: 'Ext.app.ViewController',
  48. +
  49. +        control: {
  50. +            'field[name=confirm]': {
  51. +                change: function(f, value) {
  52. +                    var view = this.getView();
  53. +                    var commandButton = this.lookupReference('commandButton');
  54. +                    if (value === view.getItem().nodename.toString()) {
  55. +                        commandButton.enable();
  56. +                    } else {
  57. +                        commandButton.disable();
  58. +                    }
  59. +                },
  60. +                specialkey: function (field, event) {
  61. +                    var commandButton = this.lookupReference('commandButton');
  62. +                    if (!commandButton.isDisabled() && event.getKey() == event.ENTER) {
  63. +                        commandButton.fireEvent('click', commandButton, event);
  64. +                    }
  65. +                }
  66. +            },
  67. +           'button[reference=abortButton]': {
  68. +               click: function() {
  69. +                    var view = this.getView();
  70. +                   view.close();
  71. +               }
  72. +            },
  73. +            'button[reference=commandButton]': {
  74. +                click: function() {
  75. +                    var view = this.getView();
  76. +
  77. +                    Proxmox.Utils.API2Request({
  78. +                        params: { command: view.getItem().command },
  79. +                        url: '/nodes/' + view.getItem().nodename + '/status',
  80. +                        method: 'POST',
  81. +                        waitMsgTarget: view,
  82. +                        failure: function(response, opts) {
  83. +                            view.close();
  84. +                            Ext.Msg.alert('Error', response.htmlStatus);
  85. +                        },
  86. +                        success: function(response, options) {
  87. +                            view.close();
  88. +                        }
  89. +                    });
  90. +                }
  91. +            }
  92. +        }
  93. +    },
  94. +
  95. +    items: [
  96. +        {
  97. +            xtype: 'component',
  98. +            cls: [ Ext.baseCSSPrefix + 'message-box-icon',
  99. +                   Ext.baseCSSPrefix + 'message-box-warning',
  100. +                   Ext.baseCSSPrefix + 'dlg-icon']
  101. +        },
  102. +        {
  103. +            xtype: 'container',
  104. +            flex: 1,
  105. +            layout: {
  106. +                type: 'vbox',
  107. +                align: 'stretch'
  108. +            },
  109. +            items: [
  110. +                {
  111. +                    xtype: 'component',
  112. +                    reference: 'messageCmp'
  113. +                },
  114. +                {
  115. +                    itemId: 'confirmField',
  116. +                    reference: 'confirmField',
  117. +                    xtype: 'textfield',
  118. +                    name: 'confirm',
  119. +                    labelWidth: 300,
  120. +                    hideTrigger: true,
  121. +                    allowBlank: false
  122. +                }
  123. +            ]
  124. +        }
  125. +    ],
  126. +    buttons: [
  127. +        {
  128. +            reference: 'commandButton',
  129. +            text: gettext('Shutdown'),
  130. +            disabled: true
  131. +        },
  132. +        {
  133. +            reference: 'abortButton',
  134. +            text: gettext('Abort'),
  135. +            disabled: false
  136. +        }
  137. +    ],
  138. +
  139. +    initComponent : function() {
  140. +        var me = this;
  141. +
  142. +        me.callParent();
  143. +
  144. +        var item = me.getItem();
  145. +
  146. +        if (!Ext.isDefined(item.nodename)) {
  147. +            throw "no nodename specified";
  148. +        }
  149. +
  150. +        var messageCmp = me.lookupReference('messageCmp');
  151. +        var button_text, msg;
  152. +        if (item.command === 'reboot') {
  153. +            msg = Ext.String.format(gettext("Reboot node '{0}'?"), item.nodename);
  154. +            button_text = gettext('Reboot');
  155. +        }
  156. +        else if (item.command === 'shutdown') {
  157. +            msg = Ext.String.format(gettext("Shutdown node '{0}'?"), item.nodename);
  158. +            button_text = gettext('Shutdown');
  159. +        }
  160. +       else {
  161. +           throw "unknown item command specified";
  162. +       }
  163. +        messageCmp.setHtml(msg);
  164. +
  165. +        var confirmField = me.lookupReference('confirmField');
  166. +        msg = gettext('Please enter the node name to confirm') +
  167. +            ' (' + item.nodename + ')';
  168. +        confirmField.setFieldLabel(msg);
  169. +
  170. +        var commandButton = me.lookupReference('commandButton');
  171. +        commandButton.setText(button_text);
  172. +    }
  173. +});
  174. +
  175.  /* Popup a message window
  176.   * where the user has to manually enter the resource ID
  177.   * to enable the destroy button
  178. @@ -19913,6 +20080,7 @@
  179.             interval: 1000
  180.         });
  181.  
  182. +/* dead code */
  183.         var node_command = function(cmd) {
  184.             Proxmox.Utils.API2Request({
  185.                 params: { command: cmd },
  186. @@ -19979,9 +20147,11 @@
  187.             disabled: !caps.nodes['Sys.PowerMgmt'],
  188.             dangerous: true,
  189.             confirmMsg: Ext.String.format(gettext("Reboot node '{0}'?"), nodename),
  190. -           handler: function() {
  191. -               node_command('reboot');
  192. -           },
  193. +            handler: function() {
  194. +                Ext.create('PVE.window.SafeNodeCommand', {
  195. +                       item: { nodename: nodename, command: 'reboot' }
  196. +                }).show();
  197. +            },
  198.             iconCls: 'fa fa-undo'
  199.         });
  200.  
  201. @@ -19991,7 +20161,9 @@
  202.             dangerous: true,
  203.             confirmMsg: Ext.String.format(gettext("Shutdown node '{0}'?"), nodename),
  204.             handler: function() {
  205. -               node_command('shutdown');
  206. +                Ext.create('PVE.window.SafeNodeCommand', {
  207. +                        item: { nodename: nodename, command: 'shutdown' }
  208. +                }).show();
  209.             },
  210.             iconCls: 'fa fa-power-off'
  211.         });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement