Index: html/pages/device/edit/rancid.inc.php
===================================================================
--- html/pages/device/edit/rancid.inc.php (nonexistent)
+++ html/pages/device/edit/rancid.inc.php (working copy)
@@ -0,0 +1,122 @@
+
+ * @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2016 Observium Limited
+ *
+ */
+
+if ($vars["editing"]) {
+ if ($readonly) {
+ print_error_permission(
+ "You have insufficient permissions to edit settings."
+ );
+ } else {
+ $port = $_POST["port"];
+ if (!is_numeric($port)) {
+ $update_message = "Port must be numeric!";
+ $updated = 0;
+ } else {
+ $update = [
+ "device_id" => $device["device_id"],
+ "port" => $_POST["port"],
+ "connection_type" => $_POST["connection_type"],
+ "user" => $_POST["user"],
+ "pass" => $_POST["pass"],
+ "enable" => $_POST["enable"],
+ ];
+ $rows_updated = dbUpdateMulti($update, 'rancidlogin');
+
+ if ($rows_updated > 0) {
+ $update_message = "Device record updated.";
+ $updated = 1;
+ } elseif ($rows_updated = "-1") {
+ $update_message =
+ "Device record unchanged. No update necessary.";
+ $updated = -1;
+ } else {
+ $update_message = "Device record update error.";
+ $updated = 0;
+ }
+ }
+ }
+}
+$device = dbFetchRow("SELECT * FROM `rancidlogin` WHERE `device_id` = ?", [
+ $device["device_id"],
+]);
+if ($updated && $update_message) {
+ print_message($update_message);
+} elseif ($update_message) {
+ print_error($update_message);
+}
+$types = ["ssh", "telnet", "rsh"];
+$form = [
+ "type" => "horizontal",
+ "id" => "edit",
+ //'space' => '20px',
+ "title" => "Rancid Login Settings",
+ //'icon' => 'oicon-gear',
+ //'class' => 'box box-solid',
+ "fieldset" => ["edit" => ""],
+];
+
+$form["row"][0]["editing"] = [
+ "type" => "hidden",
+ "value" => "yes",
+];
+$form["row"][1]["port"] = [
+ "type" => "text",
+ "name" => "SSH Port",
+ "width" => "250px",
+ "readonly" => $readonly,
+ "value" => escape_html($device["port"]),
+];
+$form["row"][2]["connection_type"] = [
+ "type" => "select",
+ "name" => "Connection Type",
+ "width" => "250px",
+ "readonly" => $readonly,
+ "name" => "Connection Type",
+ "width" => "250px",
+ "readonly" => $readonly,
+ "values" => $types,
+ "value" => $device["connection_type"],
+];
+$form["row"][3]["user"] = [
+ "type" => "text",
+ "name" => "Username",
+ "width" => "250px",
+ "readonly" => $readonly,
+ "value" => escape_html($device["user"]),
+];
+$form["row"][4]["pass"] = [
+ "type" => "password",
+ "name" => "Password",
+ "width" => "250px",
+ "readonly" => $readonly,
+ "show_password" => !$readonly,
+ "value" => escape_html($device["pass"]),
+];
+$form["row"][5]["enable"] = [
+ "type" => "password",
+ "name" => "Enable Password",
+ "width" => "250px",
+ "readonly" => $readonly,
+ "show_password" => !$readonly,
+ "value" => escape_html($device["enable"]),
+];
+$form["row"][6]["submit"] = [
+ "type" => "submit",
+ "name" => "Save Changes",
+ "icon" => "icon-ok icon-white",
+ "class" => "btn-primary",
+ "readonly" => $readonly,
+ "value" => "save",
+];
+print_form($form);
+unset($form);
+
+// EOF
Property changes on: html/pages/device/edit/rancid.inc.php
___________________________________________________________________
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: html/pages/device/edit.inc.php
===================================================================
--- html/pages/device/edit.inc.php (revision 15443)
+++ html/pages/device/edit.inc.php (working copy)
@@ -84,6 +84,10 @@
}
if ($_SESSION['userlevel'] >= 9) {
+ $panes['rancid'] = 'Rancid';
+}
+
+if ($_SESSION['userlevel'] >= 9) {
// Detect (possible) duplicates
$duplicates = [];
get_device_duplicated($device, $duplicates);
Index: scripts/generate-rancid-login.php
===================================================================
--- scripts/generate-rancid-login.php (nonexistent)
+++ scripts/generate-rancid-login.php (working copy)
@@ -0,0 +1,112 @@
+#!/usr/bin/env php
+ $name) {
+ $os_maps[$os][] = [ 'name' => $name ];
+ }
+}
+
+// OS maps from definitions
+foreach ($config['os'] as $os => $entry) {
+ if (!isset($entry['rancid'])) {
+ continue;
+ }
+
+ $os_maps[$os] = $entry['rancid'];
+}
+print_debug_vars($os_maps, 1);
+
+// Limit devices with rancid supported os
+$where_array = [];
+if (!isset($options['a'])) {
+ $where_array[] = generate_query_values($config['poller_id'], 'poller_id');
+}
+$where_array[] = generate_query_values(array_keys($os_maps), 'os');
+$sql = "SELECT `hostname`, `os`, `version`, `hardware`, `disabled`, `status`, `port`, `connection_type`, `user`, `pass`, `enable` FROM `devices` LEFT JOIN `rancidlogin` on `devices`.`device_id` = `rancidlogin`.`device_id` " . generate_where_clause($where_array) . " ORDER BY `hostname`";
+foreach (dbFetchRows($sql) as $device) {
+ // blacklisted hosts
+ if (isset($config['rancid_host_blacklist']) &&
+ (in_array($device['hostname'], (array)$config['rancid_host_blacklist'], TRUE) ||
+ in_array($device['ip'], (array)$config['rancid_host_blacklist'], TRUE))) {
+ continue;
+ }
+
+ // Up for not disabled and available devices
+ $rancid_status = ($device['disabled'] || !$device['status']) ? "down" : "up";
+ //print_vars($device);
+
+ // New defs
+ foreach ($os_maps[$device['os']] as $rancid_map) {
+ // Need check hardware for map
+ if (isset($rancid_map['hardware']) &&
+ !preg_match($rancid_map['hardware'], $device['hardware'])) {
+ continue;
+ }
+
+ // Need check min os version
+ if (isset($rancid_map['version_min']) &&
+ version_compare($rancid_map['version_min'], $device['version'], '>')) {
+ continue;
+ }
+
+ // Need check min rancid version
+ if (isset($rancid_map['rancid_min']) &&
+ version_compare(trim_number($rancid_map['rancid_min']), $rancid_version, '>')) {
+ continue;
+ }
+
+ if (isset($device['user']) && isset($device['pass']) && isset($device['connection_type']) ) {
+ if ($device['connection_type'] == 2) {
+ $type = "rsh";
+ if (isset($device['user'])) {
+ $port = $device['port'];
+ } else {
+ $port = "514";
+ };
+ } elseif ($device['connection_type'] == 1) {
+ $type = "telnet";
+ if (isset($device['user'])) { $port = $device['port']; } else { $port = "21"; };
+ } elseif ($device['connection_type'] == 0) {
+ $type = "ssh";
+ if (isset($device['user'])) { $port = $device['port']; } else { $port = "22"; };
+ }
+ // All checks complete, write rancid entry and break loop
+ echo("add user {" . $device['hostname'] . "} {" . $device['user'] . "}" . PHP_EOL);
+ if ($device['enable'] == "") {
+ echo("add password {" . $device['hostname'] . "} {" . $device['pass'] . "}" . PHP_EOL);
+ echo("add autoenable {" . $device['hostname'] . "} {1}" . PHP_EOL);
+ } else {
+ echo("add password {" . $device['hostname'] . "} {" . $device['pass'] . "} {" . $device['enable'] . "}" . PHP_EOL);
+ }
+ echo("add method {" . $device['hostname'] . "} {" . $type . ":" . $port . "}" . PHP_EOL);
+ break;
+ }
+ }
+}
+
+// EOF
Property changes on: scripts/generate-rancid-login.php
___________________________________________________________________
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property