luci-proto-ncm: add APN and PIN validation
authorNicholas Smith <nicholas@nbembedded.com>
Sun, 27 Jun 2021 05:43:13 +0000 (15:43 +1000)
committerJo-Philipp Wich <jo@mein.io>
Tue, 15 Feb 2022 23:34:16 +0000 (00:34 +0100)
Signed-off-by: Nicholas Smith <nicholas@nbembedded.com>
[squash commits, fix whitespace]
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
(cherry picked from commit 1661ac6bf888e4563546cc63fe0e228af8889bf0)

protocols/luci-proto-ncm/htdocs/luci-static/resources/protocol/ncm.js

index 0daa7c16c186592f5551fa6da98b0ecb0c55f41c..4d2f446793d9190e0e7c115e6fd7c1eaecfcacee 100644 (file)
@@ -84,8 +84,17 @@ return network.registerProtocol('ncm', {
                o.value('IPV4V6', _('IPv4+IPv6'));
                o.value('IPV6', _('IPv6'));
 
-               s.taboption('general', form.Value, 'apn', _('APN'));
-               s.taboption('general', form.Value, 'pincode', _('PIN'));
+               o = s.taboption('general', form.Value, 'apn', _('APN'));
+               o.validate = function(section_id, value) {
+                       if (!/^[a-zA-Z0-9\-.]*[a-zA-Z0-9]$/.test(value))
+                                       return _('Invalid APN provided');
+
+                       return true;
+               };
+
+               o = s.taboption('general', form.Value, 'pincode', _('PIN'));
+               o.datatype = 'and(uinteger,minlength(4),maxlength(8))';
+
                s.taboption('general', form.Value, 'username', _('PAP/CHAP username'));
 
                o = s.taboption('general', form.Value, 'password', _('PAP/CHAP password'));