From d6cfa86978ee75a7df4660a6e0b13b3414eb071e Mon Sep 17 00:00:00 2001 From: steve-lad <72376554+steve-lad@users.noreply.github.com> Date: Fri, 18 Jun 2021 16:50:15 +0200 Subject: [PATCH] Control MAC address entry Warning and refocus if not conform to indicated requirements --- assets/js/sccp_manager.js | 9 +++++++++ sccpManTraits/ajaxHelper.php | 8 ++++++++ sccpManTraits/bmoFunctions.php | 3 ++- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/assets/js/sccp_manager.js b/assets/js/sccp_manager.js index f74f278..d2d3aa1 100644 --- a/assets/js/sccp_manager.js +++ b/assets/js/sccp_manager.js @@ -212,6 +212,15 @@ $(document).ready(function () { e.preventDefault(); }); + $('#sccp_hw_mac').change(function() { + var value = $(this).val(); + const regex = new RegExp('^([0-9A-Fa-f]{2}[:.-]?){5}([0-9A-Fa-f]{2})$'); + if ( regex.test(value) === false ) { + fpbxToast(_('Invalid Mac Address'),_('Invalid Mac Address'), 'warning'); + setTimeout(function(){document.getElementById("sccp_hw_mac").focus();},2000); + }; + }); + // Form.buttons - Form.adddevice $('.futuretype').change(function (e) { var kid = $(this).data('id'); diff --git a/sccpManTraits/ajaxHelper.php b/sccpManTraits/ajaxHelper.php index fc9b004..8864f36 100644 --- a/sccpManTraits/ajaxHelper.php +++ b/sccpManTraits/ajaxHelper.php @@ -35,6 +35,9 @@ trait ajaxHelper { case 'delete_dialplan': return true; break; + case 'validateMac': + return true; + break; default: return false; } @@ -49,6 +52,8 @@ trait ajaxHelper { case 'savesettings': // Consolidate this into a separate method to improve legibility $this->handleSubmit($request); + + // TODO: Need to be more specific on reload and only reload if critical settings changed. $res = $this->aminterface->core_sccp_reload(); $msg [] = array ("Config Saved: {$res['Response']}", "Info : {$res['data']}"); @@ -376,6 +381,9 @@ trait ajaxHelper { // return array('status' => false, 'message' => $result); return $result; break; + case 'validateMac': + dbug('Request', $_REQUEST); + break; } } diff --git a/sccpManTraits/bmoFunctions.php b/sccpManTraits/bmoFunctions.php index 1bd6817..d6adee0 100644 --- a/sccpManTraits/bmoFunctions.php +++ b/sccpManTraits/bmoFunctions.php @@ -32,7 +32,7 @@ trait bmoFunctions { Below adds redirect URL, but it is not followed $cc->setRedirectURL("config.php?display=sccp_phone"); so force redirect at end of addDevice in SccpClass - */ + */ } } } @@ -115,6 +115,7 @@ trait bmoFunctions { ); break; case 'sccpsettings': + // TODO: Need to change to have save and save and continue $buttons = array( 'submit' => array( 'name' => 'ajaxsubmit',