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

Adding invalid hostnames is no longer fatal. #8233

Merged
merged 2 commits into from Feb 9, 2018
Merged
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
37 changes: 17 additions & 20 deletions html/pages/addhost.inc.php
Expand Up @@ -11,23 +11,20 @@
exit;
}

if (isset($_POST['hostname'])) {
echo '<div class="row">
<div class="col-sm-3">
</div>
<div class="col-sm-6">';

// first load enabled, after that check snmp variable
$snmp_enabled = !isset($_POST['hostname']) || isset($_POST['snmp']);

if (!empty($_POST['hostname'])) {
$hostname = clean($_POST['hostname']);
if (!is_valid_hostname($hostname) && !IP::isValid($hostname)) {
print_error('Invalid hostname or IP.');
$hostname = false;
print_error("Invalid hostname or IP: $hostname");
}
} else {
$hostname = false;
}

$snmp_enabled = isset($_POST['snmp']);

if ($hostname !== false) {
echo '<div class="row">
<div class="col-sm-3">
</div>
<div class="col-sm-6">';
if ($_SESSION['userlevel'] > '5') {
// Settings common to SNMPv2 & v3
if ($_POST['port']) {
Expand Down Expand Up @@ -93,12 +90,12 @@
}
} else {
print_error("You don't have the necessary privileges to add hosts.");
}//end if
echo ' </div>
<div class="col-sm-3">
</div>
</div>';
}//end if
}
}
echo ' </div>
<div class="col-sm-3">
</div>
</div>';

$pagetitle[] = 'Add host';

Expand Down Expand Up @@ -364,7 +361,7 @@ classNames: {

$("[name='snmp']").bootstrapSwitch('offColor','danger');
<?php
if ($hostname !== false && !$snmp_enabled) {
if (!$snmp_enabled) {
echo ' $("[name=\'snmp\']").trigger(\'click\');';
}
?>
Expand Down