Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change addIPAllocation () #174

Open
wants to merge 2 commits into
base: maintenance-0.20.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 32 additions & 0 deletions wwwroot/inc/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -5117,6 +5117,38 @@ function showNotice ($message, $option = '')
setMessage ('neutral', $message, $option == 'inline');
}

// asks ok/cancel question
// 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'] === 'true' ? TRUE : FALSE);

$form = "<form id=choice method=post action='?{$_SERVER['QUERY_STRING']}'>";
foreach ($_POST as $name => $value)
$form .= "<input type=hidden name='$name' value='$value'>";
$form .= "<input type=hidden id=answer name=answer value='false'>";
$form .= '</form>';

$msg = $question;
$question = str_replace ('<br>', '\n', $question);
$question = str_replace ("'", "\'", $question);
$msg .= <<<ENDMSG
$form
<script type="text/javascript">
answer = confirm('$question');
$('input#answer').val(answer);
$('form#choice').submit();
</script>
ENDMSG;

setMessage ('warning', $msg, FALSE);

return NULL;
}

// 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)
Expand Down
37 changes: 34 additions & 3 deletions wwwroot/inc/ophandlers.php
Original file line number Diff line number Diff line change
Expand Up @@ -1010,11 +1010,42 @@ 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)
{
$choice = showChoice ('Assign IP '.ip_format ($ip_bin).' Name: "'.$address['name'].'"?<br>'.
($reserved ? 'IP reservation will be removed!<br>' : '').
($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).' Name: "'.$address['name'].'" NOT assigned<br>'.
($reserved ? 'IP is still reserved!<br>' : '').
($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).' Name: "'.$address['name'].'" assigned<br>'.
($reserved ? 'IP is NO longer reserved!<br>' : '').
($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
(
Expand Down