luci-proto-3g: add APN and PIN validation
authorNicholas Smith <nicholas@nbembedded.com>
Fri, 11 Jun 2021 12:40:30 +0000 (22:40 +1000)
committerJo-Philipp Wich <jo@mein.io>
Tue, 13 Jul 2021 18:10:04 +0000 (20:10 +0200)
Signed-off-by: Nicholas Smith <nicholas@nbembedded.com>
[squash commits, fix whitespace]
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
protocols/luci-proto-3g/htdocs/luci-static/resources/protocol/3g.js

index ee4927a02761989f842baea16142036dee58e3b9..d0d8b4a677bc767418e763b73c994f3225520179 100644 (file)
@@ -92,8 +92,17 @@ return network.registerProtocol('3g', {
                o.value('gprs_only', _('GPRS only'));
                o.value('evdo', 'CDMA/EV-DO');
 
-               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'));