Cisco-Conf
view release on metacpan or search on metacpan
if (length($ref->{'description'}) > $dLength) {
$dLength = length($ref->{'description'});
}
}
my $format = sprintf(" %%-%ds %%%ds\n", $nLength, $dLength);
printf("You have access to the following routers:\n\n$format\n",
'Name', 'Description');
foreach $ref (sort { $a->{'name'} cmp $b->{'name'} } @$list) {
printf($format, $ref->{'name'}, $ref->{'description'});
}
}
}
############################################################################
#
# Name: Add
#
# Purpose: Add a new configuration to the config file.
#
# Input: Routers name
#
# Returns: Nothing, exits in case of trouble.
#
############################################################################
sub _Load {
my($config, $conf, $name) = @_;
my $tftpFile = $conf->TftpFile($config);
if (-f $tftpFile && ! -z _) {
print "\nWarning: A file $tftpFile already exists!";
print "\nOverwrite it? [y]";
my $reply = <STDIN>;
$reply =~ s/\s+//;
if ($reply ne '' && $reply !~ /y/i) {
exit 0;
}
}
$conf->Load($tftpFile);
$tftpFile;
}
sub Add ($) {
my $name = shift;
my $config = Cisco::Conf->_ReadConfigFile($CONFIG_FILE);
if (!$name) {
print STDERR "Must have a valid router name.\n";
exit 1;
}
if (exists($config->{'hosts'}->{$name})) {
die "A router $name already exists.";
}
print "\nEnter a description of the router $name (one line):\n";
my $description = <STDIN>;
$description =~ s/^\s+//;
$description =~ s/\s+$//;
my $user = ((getpwuid($>))[0]);
if ($< != $>) {
$user .= " " . ((getpwuid($<))[0]);
}
if ($< != 0 && $> != 0) {
$user .= " " . ((getpwuid(0))[0]);
}
print "\nEnter blank separated list of users that may configure the";
print "\n router: [$user] ";
my $reply = <STDIN>;
$reply =~ s/^\s+//;
$reply =~ s/\s+$//;
$user = $reply ? $reply : $user;
my $peer_address;
if ($peer_address = Socket::inet_aton($name)) {
$peer_address = Socket::inet_ntoa($peer_address);
} else {
$peer_address = $name;
}
print "\nEnter IP address of the router [$peer_address] ";
$reply = <STDIN>;
$reply =~ s/^\s+//;
$reply =~ s/\s+$//;
$peer_address = $reply ? $reply : $peer_address;
my $local_address = $config->{'local_addr'};
print "\nEnter the local hosts IP address that the router will use";
print "\nfor accessing the TFTP server: [$local_address] ";
$reply = <STDIN>;
$reply =~ s/^\s+//;
$reply =~ s/\s+$//;
$local_address = $reply ? $reply : $local_address;
print "\nDepending on your routers configuration, a username might";
print "\nbe required. If so, you may make it part of the cisconf";
print "\nconfiguration by entering it now. If you don't, or if your";
print "\nrouter doesn't require a username, enter the word 'undef'.";
print "\nIn the latter case you will be queried whenever a username";
print "\nis required. Username: [undef] ";
$reply = <STDIN>;
$reply =~ s/^\s+//;
$reply =~ s/\s+$//;
my $login_username = $reply;
if ($login_username eq 'undef') {
$login_username = undef;
}
print "\nEnter the routers login password or the word 'undef', if you";
print "\ndon't want to configure a fixed password. If you don't enter a";
print "\npassword, you will be queried for the password each time you";
print "\nare accessing the router: [undef] ";
$reply = <STDIN>;
$reply =~ s/^\s+//;
$reply =~ s/\s+$//;
my $login_password = $reply ? $reply : undef;
print "\nEnter the routers enable password. If you don't enter a";
print "\npassword, but an empty string, you will be queried for";
print "\nthe password each time you are accessing the router: [undef] ";
$reply = <STDIN>;
$reply =~ s/^\s+//;
$reply =~ s/\s+$//;
my $enable_password = $reply ? $reply : undef;
print "\nEnter the file name of the routers configuration [$name.conf] ";
( run in 0.446 second using v1.01-cache-2.11-cpan-6aa56a78535 )