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

add SSH PTY for NOKIA SROS (fix for #86) #107

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions auth/ssh.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function __construct($config, $debug) {
$this->port = isset($this->config['port']) ? (int) $this->config['port'] : 22;

if ($this->debug) {
define('NET_SSH2_LOGGING', NET_SSH2_LOG_COMPLEX);
define('NET_SSH2_LOGGING', SSH2::LOG_COMPLEX);
}
}

Expand Down Expand Up @@ -94,7 +94,21 @@ public function connect() {
public function send_command($command) {
vitalisator marked this conversation as resolved.
Show resolved Hide resolved
$this->connect();

$data = $this->connection->exec($command);
if ($this->config['type'] == 'nokia') {
$this->connection->enablePTY();
// read and ignore the first response prompt to get clear output if the router is sending MOTD
$this->connection->read('/.*:.*# /', SSH2::READ_REGEX);

// disable paging
$this->connection->write("environment no more\n");
$this->connection->read('/.*:.*# /', SSH2::READ_REGEX);

$this->connection->write($command . "\n");
$data = $this->connection->read('/.*:.*# /', SSH2::READ_REGEX);
} else {
$data = $this->connection->exec($command);
}

if ($this->debug) {
log_to_file($this->connection->getLog());
}
Expand Down
26 changes: 20 additions & 6 deletions routers/nokia.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,21 @@
require_once('includes/utils.php');

final class Nokia extends Router {
public function __construct($global_config, $config, $id, $requester) {
parent::__construct($global_config, $config, $id, $requester);
if (isset($this->config['vrf'])) {
$this->vrf_cmd = 'router ' . $this->config['vrf'];
}
}
protected function build_bgp($parameter) {
$cmd = new CommandBuilder();
$cmd->add('show router bgp routes');
if (isset($this->vrf_cmd)) {
$cmd->add('show', $this->vrf_cmd, 'bgp routes');
} else {
$cmd->add('show router bgp routes');
}

$cmd->add($parameter);

if (match_ipv6($parameter, false)) {
$cmd->add('ipv6');
Expand All @@ -35,8 +47,6 @@ protected function build_bgp($parameter) {
$cmd->add('ipv4');
}

$cmd->add($parameter);

if ($this->config['bgp_detail']) {
$cmd->add('detail');
}
Expand All @@ -48,7 +58,11 @@ protected function build_aspath_regexp($parameter) {
$parameter = quote($parameter);
$commands = array();
$cmd = new CommandBuilder();
$cmd->add('show router bgp routes');
if (isset($this->vrf_cmd)) {
$cmd->add('show', $this->vrf_cmd, 'bgp routes');
} else {
$cmd->add('show router bgp routes');
}

if (!$this->config['disable_ipv6']) {
$cmd6 = clone $cmd;
Expand Down Expand Up @@ -83,7 +97,7 @@ protected function build_ping($parameter) {
}

$cmd = new CommandBuilder();
$cmd->add('ping count 10', $parameter);
$cmd->add('ping count 10', $parameter, $this->vrf_cmd);

if ($this->has_source_interface_id()) {
$cmd->add('source', $this->get_source_interface_id());
Expand All @@ -98,7 +112,7 @@ protected function build_traceroute($parameter) {
}

$cmd = new CommandBuilder();
$cmd->add('traceroute', $parameter);
$cmd->add('traceroute no-dns', $parameter, $this->vrf_cmd);

if ($this->has_source_interface_id()) {
$cmd->add('source', $this->get_source_interface_id());
Expand Down
1 change: 1 addition & 0 deletions routers/router.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ abstract class Router {
protected $config;
protected $id;
protected $requester;
protected $vrf_cmd;
vitalisator marked this conversation as resolved.
Show resolved Hide resolved

public function __construct($global_config, $config, $id, $requester) {
$this->global_config = $global_config;
Expand Down