From e3d7e5c6d568d135e18c8a8889993c01af2c31bc Mon Sep 17 00:00:00 2001 From: github138 Date: Wed, 10 Aug 2016 16:52:39 +0200 Subject: [PATCH 1/2] add showChoice () fix addIPAllocation () show warnings * showChoice(): new function * addIPAllocation (): add showChoice fix warning messages use IPV4_AUTO_RELEASE config var --- wwwroot/inc/functions.php | 29 +++++++++++++++++++++++++++++ wwwroot/inc/ophandlers.php | 29 ++++++++++++++++++++++++++--- 2 files changed, 55 insertions(+), 3 deletions(-) diff --git a/wwwroot/inc/functions.php b/wwwroot/inc/functions.php index 26691b8a0..6d957a808 100644 --- a/wwwroot/inc/functions.php +++ b/wwwroot/inc/functions.php @@ -5117,6 +5117,35 @@ function showNotice ($message, $option = '') setMessage ('neutral', $message, $option == 'inline'); } +// asks ok/cancel question +// return string 'true' or 'false' +// adds 'answer' to request post data and repeats request +function showChoice ($question) +{ + if (isset ($_POST['answer'])) + return $_POST['answer']; + + $form = "
"; + foreach ($_POST as $name => $value) + $form .= ""; + $form .= ""; + $form .= '
'; + + $msg = $question; + $question = str_replace ('
', '\n', $question); + $question = str_replace ("'", "\'", $question); + $msg .= << + answer = confirm('$question'); + $('input#answer').val(answer); + $('form#choice').submit(); + +ENDMSG; + + setMessage ('warning', $msg, FALSE); +} + // do not call this directly, use showError and its siblings instead // $type could be 'error', 'warning', 'success' or 'neutral' function setMessage ($type, $message, $direct_rendering) diff --git a/wwwroot/inc/ophandlers.php b/wwwroot/inc/ophandlers.php index 2e43b7a32..e6e07cd89 100644 --- a/wwwroot/inc/ophandlers.php +++ b/wwwroot/inc/ophandlers.php @@ -1010,10 +1010,33 @@ function addIPAllocation () return; } - if($address['reserved'] && $address['name'] != '') + $autorelease = getConfigVar ('IPV4_AUTO_RELEASE'); + if ($autorelease > 0) { - showWarning("IP ".ip_format($ip_bin)." reservation \"".$address['name']."\" is removed"); - //TODO ask to take reserved IP or not ! + $reserved = $ipname = FALSE; + if ($autorelease >= 1 && $address['reserved'] == 'yes') + $reserved = TRUE; + if ($autorelease >= 2 && $address['name'] != '') + $ipname = TRUE; + + if ($reserved || $ipname) + { + if (showChoice ('Assign IP '.ip_format ($ip_bin).'?
'. + ($reserved ? 'IP reservation will be removed!
' : ''). + ($ipname ? 'IP name "'.$address['name'].'" will be removed!' : '') + ) != 'true') + { + showWarning ('IP '.ip_format ($ip_bin).' NOT assigned
'. + ($reserved ? 'IP is still reserved!
' : ''). + ($ipname ? 'IP name "'.$address['name'].'" unchanged' : '')); + + return buildRedirectURL (NULL, NULL, array ('hl_ip' => ip_format ($ip_bin))); + } + + showWarning ('IP '.ip_format ($ip_bin).' assigned
'. + ($reserved ? 'IP is NO longer reserved!
' : ''). + ($ipname ? 'IP name "'.$address['name'].'" removed!' : '')); + } } bindIPToObject From dfd54ce6e467a6e0fb67e23182a3a4ccecfa1468 Mon Sep 17 00:00:00 2001 From: Charlie Root Date: Sat, 13 Aug 2016 13:31:45 +0200 Subject: [PATCH 2/2] refine showChoice() --- wwwroot/inc/functions.php | 7 +++++-- wwwroot/inc/ophandlers.php | 24 ++++++++++++++++-------- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/wwwroot/inc/functions.php b/wwwroot/inc/functions.php index 6d957a808..f922c1a50 100644 --- a/wwwroot/inc/functions.php +++ b/wwwroot/inc/functions.php @@ -5118,12 +5118,13 @@ function showNotice ($message, $option = '') } // asks ok/cancel question -// return string 'true' or 'false' +// return TRUE/FALSE/NULL +// NULL = waiting for choice // adds 'answer' to request post data and repeats request function showChoice ($question) { if (isset ($_POST['answer'])) - return $_POST['answer']; + return ($_POST['answer'] === 'true' ? TRUE : FALSE); $form = "
"; foreach ($_POST as $name => $value) @@ -5144,6 +5145,8 @@ function showChoice ($question) ENDMSG; setMessage ('warning', $msg, FALSE); + + return NULL; } // do not call this directly, use showError and its siblings instead diff --git a/wwwroot/inc/ophandlers.php b/wwwroot/inc/ophandlers.php index e6e07cd89..736eeae61 100644 --- a/wwwroot/inc/ophandlers.php +++ b/wwwroot/inc/ophandlers.php @@ -1021,23 +1021,31 @@ function addIPAllocation () if ($reserved || $ipname) { - if (showChoice ('Assign IP '.ip_format ($ip_bin).'?
'. - ($reserved ? 'IP reservation will be removed!
' : ''). - ($ipname ? 'IP name "'.$address['name'].'" will be removed!' : '') - ) != 'true') + $choice = showChoice ('Assign IP '.ip_format ($ip_bin).' Name: "'.$address['name'].'"?
'. + ($reserved ? 'IP reservation will be removed!
' : ''). + ($ipname ? 'IP name "'.$address['name'].'" and comment will be removed!' : '') + ); + + if ($choice === NULL) // waiting for choice + return; + + if($choice !== TRUE) { - showWarning ('IP '.ip_format ($ip_bin).' NOT assigned
'. + showWarning ('IP '.ip_format ($ip_bin).' Name: "'.$address['name'].'" NOT assigned
'. ($reserved ? 'IP is still reserved!
' : ''). - ($ipname ? 'IP name "'.$address['name'].'" unchanged' : '')); + ($ipname ? 'IP name "'.$address['name'].'" and comment unchanged' : '')); return buildRedirectURL (NULL, NULL, array ('hl_ip' => ip_format ($ip_bin))); } - showWarning ('IP '.ip_format ($ip_bin).' assigned
'. + showWarning ('IP '.ip_format ($ip_bin).' Name: "'.$address['name'].'" assigned
'. ($reserved ? 'IP is NO longer reserved!
' : ''). - ($ipname ? 'IP name "'.$address['name'].'" removed!' : '')); + ($ipname ? 'IP name "'.$address['name'].'" and comment removed!' : '')); } } + else + if ($address['reserved'] == 'yes' && $address['name'] != '') + showWarning ('IP '.ip_format ($ip_bin).' Name: "'.$address['name'].'" is already reserved!'); bindIPToObject (