hasGlobalAdmin()) { include 'includes/html/error-no-perm.inc.php'; exit; } echo '
'; // first load enabled, after that check snmp variable $snmp_enabled = ! isset($_POST['hostname']) || isset($_POST['snmp']); if (! empty($_POST['hostname'])) { $hostname = strip_tags($_POST['hostname']); if (! \LibreNMS\Util\Validate::hostname($hostname) && ! IP::isValid($hostname)) { print_error("Invalid hostname or IP: $hostname"); } if (Auth::user()->hasGlobalRead()) { // Settings common to SNMPv2 & v3 if ($_POST['port']) { $port = strip_tags($_POST['port']); } else { $port = Config::get('snmp.port'); } if ($_POST['transport']) { $transport = strip_tags($_POST['transport']); } else { $transport = 'udp'; } $additional = []; if (! $snmp_enabled) { $snmpver = 'v2c'; $additional = [ 'snmp_disable' => 1, 'os' => $_POST['os'] ? strip_tags($_POST['os_id']) : 'ping', 'hardware' => strip_tags($_POST['hardware']), 'sysName' => strip_tags($_POST['sysName']), ]; } elseif ($_POST['snmpver'] === 'v2c' || $_POST['snmpver'] === 'v1') { if ($_POST['community']) { Config::set('snmp.community', [$_POST['community']]); } $snmpver = strip_tags($_POST['snmpver']); print_message("Adding host $hostname communit" . (count(Config::get('snmp.community')) == 1 ? 'y' : 'ies') . ' ' . implode(', ', Config::get('snmp.community')) . " port $port using $transport"); } elseif ($_POST['snmpver'] === 'v3') { $v3 = [ 'authlevel' => strip_tags($_POST['authlevel']), 'authname' => $_POST['authname'], 'authpass' => $_POST['authpass'], 'authalgo' => strip_tags($_POST['authalgo']), 'cryptopass' => $_POST['cryptopass'], 'cryptoalgo' => $_POST['cryptoalgo'], ]; $v3_config = Config::get('snmp.v3'); array_unshift($v3_config, $v3); Config::set('snmp.v3', $v3_config); $snmpver = 'v3'; print_message("Adding SNMPv3 host: $hostname port: $port"); } else { print_error('Unsupported SNMP Version. There was a dropdown menu, how did you reach this error ?'); }//end if $poller_group = strip_tags($_POST['poller_group']); $force_add = ($_POST['force_add'] == 'on'); $port_assoc_mode = strip_tags($_POST['port_assoc_mode']); try { $device_id = addHost($hostname, $snmpver, $port, $transport, $poller_group, $force_add, $port_assoc_mode, $additional); $link = \LibreNMS\Util\Url::deviceUrl($device_id); print_message("Device added $hostname ($device_id)"); } catch (HostUnreachableException $e) { print_error($e->getMessage()); foreach ($e->getReasons() as $reason) { print_error($reason); } } catch (Exception $e) { print_error($e->getMessage()); } } else { print_error("You don't have the necessary privileges to add hosts."); } } echo '
'; $pagetitle[] = 'Add host'; ?>

Add Device

Devices will be checked for Ping/SNMP reachability before being probed.
'; }//endif ?>