2007-04-03 14:10:23 +00:00
<? php
2019-06-23 00:29:12 -05:00
use LibreNMS\Config ;
2016-08-21 08:07:14 -05:00
use LibreNMS\Exceptions\HostUnreachableException ;
2017-11-01 17:06:39 +01:00
use LibreNMS\Util\IP ;
2016-08-21 08:07:14 -05:00
2015-07-13 20:10:26 +02:00
$no_refresh = true ;
2015-03-21 21:30:55 +00:00
2020-09-21 15:40:17 +02:00
if ( ! Auth :: user () -> hasGlobalAdmin ()) {
2019-04-11 23:26:42 -05:00
include 'includes/html/error-no-perm.inc.php' ;
2012-04-06 13:56:23 +00:00
2015-07-13 20:10:26 +02:00
exit ;
2007-06-24 14:56:47 +00:00
}
2018-02-09 01:55:18 -06:00
echo '<div class="row">
<div class="col-sm-3">
</div>
<div class="col-sm-6">' ;
// first load enabled, after that check snmp variable
2020-09-21 15:40:17 +02:00
$snmp_enabled = ! isset ( $_POST [ 'hostname' ]) || isset ( $_POST [ 'snmp' ]);
2018-02-09 01:55:18 -06:00
2020-09-21 15:40:17 +02:00
if ( ! empty ( $_POST [ 'hostname' ])) {
2017-11-01 17:06:39 +01:00
$hostname = clean ( $_POST [ 'hostname' ]);
2020-09-21 15:40:17 +02:00
if ( ! is_valid_hostname ( $hostname ) && ! IP :: isValid ( $hostname )) {
2018-02-09 01:55:18 -06:00
print_error ( "Invalid hostname or IP: $hostname " );
2017-11-01 17:06:39 +01:00
}
2019-08-05 14:16:05 -05:00
if ( Auth :: user () -> hasGlobalRead ()) {
2015-07-13 20:10:26 +02:00
// Settings common to SNMPv2 & v3
if ( $_POST [ 'port' ]) {
2017-10-28 05:59:25 +02:00
$port = clean ( $_POST [ 'port' ]);
2016-08-18 20:28:22 -05:00
} else {
2019-06-23 00:29:12 -05:00
$port = Config :: get ( 'snmp.port' );
2015-07-13 20:10:26 +02:00
}
if ( $_POST [ 'transport' ]) {
2017-10-28 05:59:25 +02:00
$transport = clean ( $_POST [ 'transport' ]);
2016-08-18 20:28:22 -05:00
} else {
2015-07-13 20:10:26 +02:00
$transport = 'udp' ;
}
2020-09-21 15:40:17 +02:00
$additional = [];
if ( ! $snmp_enabled ) {
2017-10-28 05:59:25 +02:00
$snmpver = 'v2c' ;
2020-09-21 15:40:17 +02:00
$additional = [
2017-10-28 05:59:25 +02:00
'snmp_disable' => 1 ,
2020-09-21 15:59:34 +02:00
'os' => $_POST [ 'os' ] ? mres ( $_POST [ 'os_id' ]) : 'ping' ,
2017-10-28 05:59:25 +02:00
'hardware' => mres ( $_POST [ 'hardware' ]),
2020-09-21 15:40:17 +02:00
'sysName' => mres ( $_POST [ 'sysName' ]),
];
2017-10-28 05:59:25 +02:00
} elseif ( $_POST [ 'snmpver' ] === 'v2c' || $_POST [ 'snmpver' ] === 'v1' ) {
2015-07-13 20:10:26 +02:00
if ( $_POST [ 'community' ]) {
2019-06-23 00:29:12 -05:00
Config :: set ( 'snmp.community' , [ clean ( $_POST [ 'community' ], false )]);
2015-07-13 20:10:26 +02:00
}
2017-10-28 05:59:25 +02:00
$snmpver = clean ( $_POST [ 'snmpver' ]);
2019-06-23 00:29:12 -05:00
print_message ( "Adding host $hostname communit" . ( count ( Config :: get ( 'snmp.community' )) == 1 ? 'y' : 'ies' ) . ' ' . implode ( ', ' , Config :: get ( 'snmp.community' )) . " port $port using $transport " );
2016-08-18 20:28:22 -05:00
} elseif ( $_POST [ 'snmpver' ] === 'v3' ) {
2020-09-21 15:40:17 +02:00
$v3 = [
'authlevel' => clean ( $_POST [ 'authlevel' ]),
'authname' => clean ( $_POST [ 'authname' ], false ),
'authpass' => clean ( $_POST [ 'authpass' ], false ),
'authalgo' => clean ( $_POST [ 'authalgo' ]),
'cryptopass' => clean ( $_POST [ 'cryptopass' ], false ),
'cryptoalgo' => clean ( $_POST [ 'cryptoalgo' ], false ),
];
2015-07-13 20:10:26 +02:00
2019-06-23 00:29:12 -05:00
$v3_config = Config :: get ( 'snmp.v3' );
2020-05-12 22:49:39 +02:00
array_unshift ( $v3_config , $v3 );
2019-06-23 00:29:12 -05:00
Config :: set ( 'snmp.v3' , $v3_config );
2015-07-13 20:10:26 +02:00
$snmpver = 'v3' ;
2020-05-12 22:49:39 +02:00
print_message ( "Adding SNMPv3 host: $hostname port: $port " );
2016-08-18 20:28:22 -05:00
} else {
2015-07-13 20:10:26 +02:00
print_error ( 'Unsupported SNMP Version. There was a dropdown menu, how did you reach this error ?' );
} //end if
2020-01-30 13:20:30 +01:00
2017-10-28 05:59:25 +02:00
$poller_group = clean ( $_POST [ 'poller_group' ]);
2020-09-21 15:40:17 +02:00
$force_add = ( $_POST [ 'force_add' ] == 'on' );
2015-07-13 20:10:26 +02:00
2017-10-28 05:59:25 +02:00
$port_assoc_mode = clean ( $_POST [ 'port_assoc_mode' ]);
2016-08-07 12:16:40 -05:00
try {
2017-10-28 05:59:25 +02:00
$device_id = addHost ( $hostname , $snmpver , $port , $transport , $poller_group , $force_add , $port_assoc_mode , $additional );
2020-09-21 15:40:17 +02:00
$link = generate_device_url ([ 'device_id' => $device_id ]);
2016-11-21 12:12:10 -06:00
print_message ( "Device added <a href=' $link '> $hostname ( $device_id )</a>" );
2016-08-07 12:16:40 -05:00
} catch ( HostUnreachableException $e ) {
print_error ( $e -> getMessage ());
foreach ( $e -> getReasons () as $reason ) {
print_error ( $reason );
}
2016-08-18 20:28:22 -05:00
} catch ( Exception $e ) {
2016-08-07 12:16:40 -05:00
print_error ( $e -> getMessage ());
2015-07-13 20:10:26 +02:00
}
2016-08-18 20:28:22 -05:00
} else {
2015-07-13 20:10:26 +02:00
print_error ( "You don't have the necessary privileges to add hosts." );
2018-02-09 01:55:18 -06:00
}
}
echo ' </div>
<div class="col-sm-3">
</div>
</div>' ;
2007-04-03 14:10:23 +00:00
2015-07-13 20:10:26 +02:00
$pagetitle [] = 'Add host' ;
2011-10-18 14:41:19 +00:00
2007-04-03 14:10:23 +00:00
?>
2014-10-02 23:14:45 +01:00
<div class="row">
<div class="col-sm-3">
</div>
<div class="col-sm-6">
2014-01-13 10:05:19 +00:00
<form name="form1" method="post" action="" class="form-horizontal" role="form">
2019-07-17 07:20:26 -05:00
<?php echo csrf_field() ?>
2014-10-02 23:14:45 +01:00
<div><h2>Add Device</h2></div>
2017-10-28 05:59:25 +02:00
<div class="alert alert-info">Devices will be checked for Ping/SNMP reachability before being probed.</div>
2014-01-13 10:05:19 +00:00
<div class="well well-lg">
2018-01-04 16:08:42 -06:00
<div class="form-group">
2020-04-09 16:39:37 -05:00
<label for="hostname" class="col-sm-3 control-label">Hostname or IP</label>
2018-01-04 16:08:42 -06:00
<div class="col-sm-9">
<input type="text" id="hostname" name="hostname" class="form-control input-sm" placeholder="Hostname">
</div>
</div>
<div class='form-group'>
2017-10-28 05:59:25 +02:00
<label for='hardware' class='col-sm-3 control-label'>SNMP</label>
<div class='col-sm-4'>
<input type="checkbox" id="snmp" name="snmp" data-size="small" onChange="disableSnmp(this);" checked>
</div>
</div>
<div id='snmp_override' style="display: none;">
2018-02-07 06:35:00 +01:00
<div class='form-group'>
<label for='sysName' class='col-sm-3 control-label'>sysName (optional)</label>
<div class='col-sm-9'>
<input id='sysName' class='form-control' name='sysName' placeholder="sysName (optional)"/>
</div>
</div>
2017-10-28 05:59:25 +02:00
<div class='form-group'>
<label for='hardware' class='col-sm-3 control-label'>Hardware (optional)</label>
<div class='col-sm-9'>
<input id='hardware' class='form-control' name='hardware' placeholder="Hardware (optional)"/>
</div>
</div>
<div class='form-group'>
<label for='os' class='col-sm-3 control-label'>OS (optional)</label>
<div class='col-sm-9'>
<input id='os' class='form-control' name='os' placeholder="OS (optional)"/>
<input type='hidden' id='os_id' class='form-control' name='os_id' />
</div>
</div>
</div>
<div id="snmp_conf" style="display: block;">
<div class="form-group">
<label for="snmpver" class="col-sm-3 control-label">SNMP Version</label>
<div class="col-sm-3">
<select name="snmpver" id="snmpver" class="form-control input-sm" onChange="changeForm();">
<option value="v1">v1</option>
<option value="v2c" selected>v2c</option>
<option value="v3">v3</option>
</select>
</div>
<div class="col-sm-3">
<input type="text" name="port" placeholder="port" class="form-control input-sm">
</div>
<div class="col-sm-3">
<select name="transport" id="transport" class="form-control input-sm">
2014-10-11 16:55:32 +00:00
<?php
2019-06-23 00:29:12 -05:00
foreach (Config::get('snmp.transports') as $transport) {
2020-09-21 15:40:17 +02:00
echo "<option value='" . $transport . "'";
2014-10-11 16:55:32 +00:00
if ($transport == $device['transport']) {
2015-07-13 20:10:26 +02:00
echo " selected='selected'";
2014-10-11 16:55:32 +00:00
}
2015-07-13 20:10:26 +02:00
2020-09-21 15:40:17 +02:00
echo '>' . $transport . '</option>';
2014-10-11 16:55:32 +00:00
}
2016-01-21 22:04:52 +01:00
?>
2017-10-28 05:59:25 +02:00
</select>
</div>
</div>
<div class="form-group">
<label for="port_association_mode" class="col-sm-3 control-label">Port Association Mode</label>
<div class="col-sm-3">
<select name="port_assoc_mode" id="port_assoc_mode" class="form-control input-sm">
2016-01-21 22:04:52 +01:00
<?php
foreach (get_port_assoc_modes() as $mode) {
2020-09-21 15:59:34 +02:00
$selected = '';
2019-06-23 00:29:12 -05:00
if ($mode == Config::get('default_port_association_mode')) {
2020-09-21 15:59:34 +02:00
$selected = 'selected';
2016-08-18 20:28:22 -05:00
}
2016-01-21 22:04:52 +01:00
2017-10-28 05:59:25 +02:00
echo " <option value=\"$mode\" $selected>$mode</option>\n";
2016-01-21 22:04:52 +01:00
}
2020-10-29 20:02:26 +02:00
$snmpv3_sha2_capable = snmpv3_sha2_capable();
2014-10-11 16:55:32 +00:00
?>
2017-10-28 05:59:25 +02:00
</select>
</div>
2014-10-02 23:14:45 +01:00
</div>
2017-10-28 05:59:25 +02:00
<div id="snmpv1_2">
<div class="form-group">
<div class="col-sm-12 alert alert-info">
<label class="control-label text-left input-sm">SNMPv1/2c Configuration</label>
</div>
</div>
<div class="form-group">
<label for="community" class="col-sm-3 control-label">Community</label>
<div class="col-sm-9">
<input type="text" name="community" id="community" placeholder="Community" class="form-control input-sm">
</div>
</div>
2014-10-02 23:14:45 +01:00
</div>
2017-10-28 05:59:25 +02:00
<div id="snmpv3">
<div class="form-group">
<div class="col-sm-12 alert alert-info">
<label class="control-label text-left input-sm">SNMPv3 Configuration</label>
</div>
</div>
<div class="form-group">
<label for="authlevel" class="col-sm-3 control-label">Auth Level</label>
<div class="col-sm-3">
<select name="authlevel" id="authlevel" class="form-control input-sm">
<option value="noAuthNoPriv" selected>noAuthNoPriv</option>
<option value="authNoPriv">authNoPriv</option>
<option value="authPriv">authPriv</option>
</select>
</div>
</div>
<div class="form-group">
<label for="authname" class="col-sm-3 control-label">Auth User Name</label>
<div class="col-sm-9">
2018-06-23 21:48:03 +02:00
<input type="text" name="authname" id="authname" class="form-control input-sm" autocomplete="off">
2017-10-28 05:59:25 +02:00
</div>
</div>
<div class="form-group">
<label for="authpass" class="col-sm-3 control-label">Auth Password</label>
<div class="col-sm-9">
2018-06-23 21:48:03 +02:00
<input type="text" name="authpass" id="authpass" placeholder="AuthPass" class="form-control input-sm" autocomplete="off">
2017-10-28 05:59:25 +02:00
</div>
</div>
<div class="form-group">
<label for="authalgo" class="col-sm-3 control-label">Auth Algorithm</label>
<div class="col-sm-9">
<select name="authalgo" id="authalgo" class="form-control input-sm">
<option value="MD5" selected>MD5</option>
<option value="SHA">SHA</option>
2020-10-29 20:02:26 +02:00
<option value="SHA-224"<?= $snmpv3_sha2_capable ?: ' disabled'?>>SHA-224</option>
<option value="SHA-256"<?= $snmpv3_sha2_capable ?: ' disabled'?>>SHA-256</option>
<option value="SHA-384"<?= $snmpv3_sha2_capable ?: ' disabled'?>>SHA-384</option>
<option value="SHA-512"<?= $snmpv3_sha2_capable ?: ' disabled'?>>SHA-512</option>
2017-10-28 05:59:25 +02:00
</select>
2020-10-29 20:02:26 +02:00
<?php if (! $snmpv3_sha2_capable) {?>
<label class="text-left"><small>Optional requirements not resolved so some options are disabled</small></label>
<?php } ?>
2017-10-28 05:59:25 +02:00
</div>
</div>
<div class="form-group">
<label for="cryptopass" class="col-sm-3 control-label">Crypto Password</label>
<div class="col-sm-9">
2018-06-23 21:48:03 +02:00
<input type="text" name="cryptopass" id="cryptopass" placeholder="Crypto Password" class="form-control input-sm" autocomplete="off">
2017-10-28 05:59:25 +02:00
</div>
</div>
<div class="form-group">
<label for="cryptoalgo" class="col-sm-3 control-label">Crypto Algorithm</label>
<div class="col-sm-9">
<select name="cryptoalgo" id="cryptoalgo" class="form-control input-sm">
<option value="AES" selected>AES</option>
2020-10-29 20:02:26 +02:00
<option value="AES-192"<?= $snmpv3_sha2_capable ?: ' disabled'?>>AES-192</option>
<option value="AES-256"<?= $snmpv3_sha2_capable ?: ' disabled'?>>AES-256</option>
2017-10-28 05:59:25 +02:00
<option value="DES">DES</option>
</select>
2020-10-29 20:02:26 +02:00
<?php if (! $snmpv3_sha2_capable) {?>
<label class="text-left"><small>Optional requirements not resolved so some options are disabled</small></label>
<?php } ?>
2017-10-28 05:59:25 +02:00
</div>
</div>
2014-10-02 23:14:45 +01:00
</div>
</div>
2015-03-15 21:44:35 +00:00
<?php
2019-06-23 00:29:12 -05:00
if (Config::get('distributed_poller') === true) {
2015-07-13 20:10:26 +02:00
echo '
2017-10-28 05:59:25 +02:00
<div class="form-group">
<label for="poller_group" class="col-sm-3 control-label">Poller Group</label>
<div class="col-sm-9">
<select name="poller_group" id="poller_group" class="form-control input-sm">
<option value="0"> Default poller group</option>
2015-07-13 20:10:26 +02:00
';
2015-03-15 21:44:35 +00:00
2020-01-27 13:18:31 +01:00
foreach (dbFetchRows('SELECT `id`,`group_name` FROM `poller_groups` ORDER BY `group_name`') as $group) {
2020-09-21 15:40:17 +02:00
echo '<option value="' . $group['id'] . '">' . $group['group_name'] . '</option>';
2015-03-15 21:44:35 +00:00
}
2015-07-13 20:10:26 +02:00
echo '
2017-10-28 05:59:25 +02:00
</select>
</div>
2015-03-15 21:44:35 +00:00
</div>
2016-09-14 02:32:45 +01:00
';
}//endif
?>
2015-03-19 22:06:13 +00:00
<div class="form-group">
2019-11-05 23:26:11 +01:00
<label for="force_add" class="col-sm-3 control-label">Force add<br><small>(No ICMP or SNMP checks performed)</small></label>
<div class="col-sm-9">
<input type="checkbox" name="force_add" id="force_add" data-size="small">
2015-03-19 22:06:13 +00:00
</div>
</div>
2015-08-29 18:50:57 +05:30
<hr>
<center><button type="submit" class="btn btn-default" name="Submit">Add Device</button></center>
2011-03-27 10:21:19 +00:00
</div>
2007-04-03 14:10:23 +00:00
</form>
2014-10-02 23:14:45 +01:00
</div>
<div class="col-sm-3">
</div>
</div>
<script>
function changeForm() {
snmpVersion = $("#snmpver").val();
if(snmpVersion == 'v1' || snmpVersion == 'v2c') {
$('#snmpv1_2').show();
$('#snmpv3').hide();
2015-07-13 20:10:26 +02:00
}
else if(snmpVersion == 'v3') {
2014-10-02 23:14:45 +01:00
$('#snmpv1_2').hide();
$('#snmpv3').show();
}
}
$('#snmpv3').toggle();
2017-10-28 05:59:25 +02:00
function disableSnmp(e) {
if(e.checked) {
$('#snmp_conf').show();
$('#snmp_override').hide();
} else {
$('#snmp_conf').hide();
$('#snmp_override').show();
}
}
var os_suggestions = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('text'),
queryTokenizer: Bloodhound.tokenizers.whitespace,
remote: {
url: "ajax_ossuggest.php?term=%QUERY",
filter: function (output) {
return $.map(output, function (item) {
return {
text: item.text,
os: item.os,
};
});
},
wildcard: "%QUERY"
}
});
os_suggestions.initialize();
$('#os').typeahead({
hint: true,
highlight: true,
minLength: 1,
classNames: {
menu: 'typeahead-left'
}
},
{
source: os_suggestions.ttAdapter(),
async: true,
displayKey: 'text',
valueKey: 'os',
templates: {
suggestion: Handlebars.compile('<p> {{text}}</p>')
},
limit: 20
});
$("#os").on("typeahead:selected typeahead:autocompleted", function(e,datum) {
$("#os_id").val(datum.os);
$("#os").html('<mark>' + datum.text + '</mark>');
});
$("[name='snmp']").bootstrapSwitch('offColor','danger');
2019-11-05 23:26:11 +01:00
$("[name='force_add']").bootstrapSwitch();
2017-10-28 05:59:25 +02:00
<?php
2020-09-21 15:40:17 +02:00
if (! $snmp_enabled) {
2017-10-28 05:59:25 +02:00
echo ' $("[name=\'snmp\']").trigger(\'click\');';
}
?>
2014-10-02 23:14:45 +01:00
</script>