]> git.proxmox.com Git - mirror_frr.git/blame - tools/zc.pl
bgpd: Refactor subgroup_announce_table() to reuse an existing helpers
[mirror_frr.git] / tools / zc.pl
CommitLineData
2e14a748 1#!/usr/bin/env perl
47a3a827 2# SPDX-License-Identifier: GPL-2.0-or-later
718e3744 3##
4## Zebra interactive console
5## Copyright (C) 2000 Vladimir B. Grebenschikov <vova@express.ru>
718e3744 6
7use Net::Telnet ();
8use Getopt::Std;
9
10#use strict;
11
12my $host = `hostname -s`; $host =~ s/\s//g;
13my $port = 'zebra';
14my $server = 'localhost';
15
16# Check arguments
17&getopts ('l:e:czborh');
18
19&usage () if $opt_h;
20
21# main
22{
23 my $login_pass = $opt_l || $ENV{ZEBRA_PASSWORD} || 'zebra';
24 my $enable_pass = $opt_e || $ENV{ZEBRA_ENABLE} || '';
25
26 my $port = ($opt_z ? 'zebra' : 0) ||
27 ($opt_b ? 'bgpd' : 0) ||
28 ($opt_o ? 'ospfd' : 0) ||
29 ($opt_r ? 'ripd' : 0) || 'zebra';
30
31 my $cmd = join (' ', @ARGV);
32
33 my $t = new Net::Telnet (Timeout => 10,
34 Prompt => '/[\>\#] $/',
35 Port => $port);
36
37 $t->open ($server);
38
39 $t->cmd ($login_pass);
40 if ($enable_pass) {
41 $t->cmd (String => 'en',
42 Prompt => '/Password: /');
43 $t->cmd ($enable_pass);
44 }
45 $t->cmd ('conf t') if "$opt_c";
46
47 if ($cmd)
48 {
49 docmd ($t, $cmd);
50 exit (0);
51 }
52
53 my $prompt = sprintf ("%s%s# ", $host,
54 ($port eq 'zebra') ? '' : "/$port");
55
56 print "\nZEBRA interactive console ($port)\n\n" if -t STDIN;
57
58 while (1)
59 {
60 $| = 1;
61 print $prompt if -t STDIN;
62 chomp ($cmd = <>);
63 if (!defined ($cmd))
64 {
65 print "\n" if -t STDIN;
66 exit(0);
67 }
68 exit (0) if ($cmd eq 'q' || $cmd eq 'quit');
69
70 docmd ($t, $cmd) if $cmd !~ /^\s*$/;
71 }
72
73 exit(0);
74}
75
76sub docmd
77{
78 my ($t, $cmd) = @_;
79 my @lines = $t->cmd ($cmd);
80 print join ('', grep (!/[\>\#] $/, @lines)), "\n";
81}
82
83sub usage
84{
85 print "USAGE: $0 [-l LOGIN_PASSWORD] [-e ENABLE_PASSWORD] [-z|-b|-o|-r|-h] [<cmd>]\n",
86 "\t-l - specify login password\n",
87 "\t-e - specify enable password\n",
88 "\t-c - execute command in configure mode\n",
89 "\t-z - connect to zebra daemon\n",
90 "\t-b - connect to bgpd daemon\n",
91 "\t-o - connect to ospfd daemon\n",
92 "\t-r - connect to ripd daemon\n",
93 "\t-h - help\n";
94 exit (1);
95}