From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 1345E9D33B for ; Thu, 23 Nov 2023 17:10:20 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id EDBFCDF3 for ; Thu, 23 Nov 2023 17:09:49 +0100 (CET) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS for ; Thu, 23 Nov 2023 17:09:48 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 662514343C for ; Thu, 23 Nov 2023 17:09:48 +0100 (CET) From: Stefan Sterz To: pve-devel@lists.proxmox.com Date: Thu, 23 Nov 2023 17:09:37 +0100 Message-Id: <20231123160937.439019-1-s.sterz@proxmox.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.085 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record T_SCC_BODY_TEXT_LINE -0.01 - URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [item.data] Subject: [pve-devel] [PATCH manager] sdn: add model based validation to dhcp ranges X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 23 Nov 2023 16:10:20 -0000 this patch re-works the validation the in the subnit edit panel to also validate whether the ip address version in a range match each other. Signed-off-by: Stefan Sterz --- not super proud of this, but couldn't really find another way to properly validate accross two columns and also have the panel still work as intended. www/manager6/sdn/SubnetEdit.js | 85 ++++++++++++++++++++++++++++++---- 1 file changed, 76 insertions(+), 9 deletions(-) diff --git a/www/manager6/sdn/SubnetEdit.js b/www/manager6/sdn/SubnetEdit.js index 8fc3f52b..cba80d8f 100644 --- a/www/manager6/sdn/SubnetEdit.js +++ b/www/manager6/sdn/SubnetEdit.js @@ -59,6 +59,49 @@ Ext.define('PVE.sdn.SubnetInputPanel', { ], }); +Ext.define('PVE.sdn.model.DhcpRange', { + extend: 'Ext.data.Model', + fields: [ + { name: 'startAddress' }, + { name: 'endAddress' }, + { + name: 'rangeErrors', + depends: ['startAddress', 'endAddress'], + calculate: (data) => { + let errors = []; + let sV4 = Proxmox.Utils.IP4_match.test(data.startAddress); + let sV6 = Proxmox.Utils.IP6_match.test(data.startAddress); + let eV4 = Proxmox.Utils.IP4_match.test(data.endAddress); + let eV6 = Proxmox.Utils.IP6_match.test(data.endAddress); + + if (!((sV4 && eV4) || (sV6 && eV6))) { + errors.push("IP address versions do not match."); + } + + return errors; + }, + }, + { + name: 'rangeErrorsClass', + depends: ['rangeErrors'], + calculate: (data) => { + if (data.rangeErrors.length !== 0) { + return ['x-form-trigger-wrap-default', 'x-form-trigger-wrap-invalid']; + } + + return []; + } + } + ], + + validators: { + startAddress: (value, record) => + Ext.form.VTypes.IP64Address(value) || gettext("Not a valid IP address."), + endAddress: (value, record) => + Ext.form.VTypes.IP64Address(value) || gettext("Not a valid IP address."), + }, +}); + Ext.define('PVE.sdn.SubnetDhcpRangePanel', { extend: 'Ext.form.FieldContainer', mixins: ['Ext.form.field.Field'], @@ -86,8 +129,8 @@ Ext.define('PVE.sdn.SubnetDhcpRangePanel', { // needs a deep copy otherwise we run in to ExtJS reference // shenaningans value.push({ - 'start-address': item.data['start-address'], - 'end-address': item.data['end-address'], + 'start-address': item.data.startAddress, + 'end-address': item.data.endAddress, }); }); @@ -121,8 +164,10 @@ Ext.define('PVE.sdn.SubnetDhcpRangePanel', { // needs a deep copy otherwise we run in to ExtJS reference // shenaningans data.push({ - 'start-address': item['start-address'], - 'end-address': item['end-address'], + startAddress: item['start-address'], + endAddress: item['end-address'], + rangeErrors: [], + rangeErrorsClass: [], }); }); @@ -133,6 +178,18 @@ Ext.define('PVE.sdn.SubnetDhcpRangePanel', { let me = this; let errors = []; + let grid = me.lookup('grid'); + + grid.getStore().data.each((row, index) => { + if (!row.isValid()) { + errors.push(gettext("An entry in the DHCP Range is not a valid IP address!")); + } + + if (row.data.rangeErrors.length !== 0) { + row.data.rangeErrors.forEach((error) => errors.push(error)); + } + }); + return errors; }, @@ -182,27 +239,37 @@ Ext.define('PVE.sdn.SubnetDhcpRangePanel', { reference: 'grid', scrollable: true, store: { - fields: ['start-address', 'end-address'], + model: 'PVE.sdn.model.DhcpRange', + }, + itemConfig: { + viewModel: true, }, + modelValidation: true, columns: [ { text: gettext('Start Address'), xtype: 'widgetcolumn', - dataIndex: 'start-address', flex: 1, widget: { xtype: 'textfield', - vtype: 'IP64Address', + bind: { + value: '{record.startAddress}', + error: '{record.rangeErrors}', + userCls: '{record.rangeErrorsClass}', + }, }, }, { text: gettext('End Address'), xtype: 'widgetcolumn', - dataIndex: 'end-address', flex: 1, widget: { xtype: 'textfield', - vtype: 'IP64Address', + bind: { + value: '{record.endAddress}', + error: '{record.rangeErrors}', + userCls: '{record.rangeErrorsClass}', + }, }, }, { -- 2.39.2