Cisco::Conf - Perl module for configuring Cisco routers via TFTP
use Cisco::Conf; # Set the path of the main configuration file $configFile = '/usr/local/cisco/etc/config'; # Add a new machine to the configuration file Cisco::Conf->Add($configFile, {'name' => 'myrouter', 'description' => 'My Internet gateway', 'users' => ['root', 'joe'], 'host' => '192.168.1.1', 'username' => 'itsme', 'password' => 'secret', 'enable_password' => undef # Prompt password }); # Remove a machine from the configuration file Cisco::Conf->Remove($configFile, 'myrouter'); # Create a configuration object by reading it from the # configuration file $conf = Cisco::Conf->Read($configFile, 'myrouter'); # Edit a machine's configuration (uses $ENV{'EDITOR'}) $conf->Edit($editor, $file, $tmpDir); # Feed a machine's configuration into RCS $conf->RCS($file, "in"); # Load a machine's configuration and save it in 'myfile' $conf->Load('myfile'); # Strip comments from a machine configuration in $configuration $stripped = Cisco::Conf->Strip($configuration); # Read a configuration from 'myfile' and save it into the router $conf->Save('myfile', $write); # Return a list of all configurations that the current user may # access @list = Cisco::Conf->Info($configFile);
This module offers a set of methods for creating and managing Cisco configurations. Configurations are stored as plain text files, including comments. Comments are indicated by an exclamation mark and may terminate any line. Example:
! Here come the interfaces interface Ethernet 0 ! Local LAN ...
All methods throw a Perl exception in case of errors, thus you should encapsulate them with an eval, like this:
eval
$@ = ''; eval { Cisco::Conf->Add('/usr/local/cisco/etc/configurations', {'name' => 'myrouter', ... }); }; if ($@) { print STDERR "An error occurred: $@\n"; exit 1; }
The following methods are offered by the module:
(Class method) Adds a new configuration to the list of configurations in the file $configFile. A configuration is represented by the hash ref \%attr with a number of attributes, including
$configFile
\%attr
A symbolic and short name for the configuration, unique in the list of configurations.
A textual description of the configuration.
The routers host name or IP address
The routers username, login and enable passwords. If these attributes are not present or have a value of undef, the methods will prompt for passwords.
File name where the machine configuration is stored, for example /usr/local/cisco/etc/mycisco.conf.
/usr/local/cisco/etc/mycisco.conf
Only root may add or remove configurations.
(Class method) Removes configuration $name from the list of configurations in the file $configFile.
$name
(Class method) Reads the configuration of the host $name from the configuration file $configFile and returns a Cisco::Conf instance representing the host.
(Instance method) Invoke the editor $editor to edit the configuration file. If $editor is not defined, use $ENV{'EDITOR'} or the first editor from the list of editors in the configuration file. (The editors attribute.)
$editor
For security reasons valid editors are restricted to those from the configuration file. Editing takes place in the directory $tmpDir, so that we can change the EUID to the users.
Example:
$self->Edit('emacs', 'myrouter.conf', '/tmp');
(Instance method) Invoke the revision control system (RCS) by using the ci attribute from the config file
$self->RCS($file, "in");
(Class method) Strips comments and empty lines from the machine configuration in the string $configuration and returns the resulting string.
$configuration
Comments may appear on any line, beginning with an exclamation mark. Example:
! This is a comment interface Ethernet 0 ! Another comment
(Instance method) Loads the current configuration from the host and saves it into the file $file. If such a file already exists, it will be overwritten silently: It is the calling functions task to emit a warning or do whatever appropriate.
$file
You cannot choose arbitrary file names for $file: The location depends on the settings of your local TFTP server. In particular you have to *have* a local TFTP server running. :-) See tftpd(1) for details.
Note that the file mode of $file will be 0666, on other words, the file is readable and writeable for the world! You should change this as soon as possible.
(Instance method) Reads a machines configuration from $file and save it into the router. Like with the Load method, possible locations of $file depend on your TFTP servers settings.
Note that the file mode of $file will be changed to 0444, on other words, the file is readable for the world! You should change this as soon as possible.
If the argument $write is TRUE, the configuration will be saved into the non-volatile memory by executing the command
write memory
(Class method) Read a list of all configurations in $configFile and return those configurations that are accessible by the current user.
(Instance method) Returns a routers config file name.
(Instance method) Returns a routers TFTP file name.
for giving me the contract that included the cisconf script. :-)
for fixing the nasty open file bug ...
for adding the username and supporting the Rcs module.
This module is
Copyright (C) 1998 Jochen Wiedmann Am Eisteich 9 72555 Metzingen Germany Phone: +49 7123 14887 Email: joe@ispsoft.de
All rights reserved.
You may distribute this module under the terms of either the GNU General Public License or the Artistic License, as specified in the Perl README file.
cisconf(1)
To install Cisco::Conf, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Cisco::Conf
CPAN shell
perl -MCPAN -e shell install Cisco::Conf
For more information on module installation, please visit the detailed CPAN module installation guide.