Config manager plugin:
creator: Jean-Michel Ppin (pepj in http://forums.cacti.net or http://cactiusers.org/)


Description:
------------
Here is an plugin to download or upload the configurations files 
from of router or switches ("TFTP" method) or do what you want of any devices type
with the method "multi".
+ The method "TFTP":
  - You can use TFTP based on "Pancho" (www.pancho.org)
  - or use the TFTP pure PHP (don't need to install Pancho, but at this time only 
  tested for Foundry, Cisco, ...)

+ The method "multi" uses your scripts or script-template SCP, SFTP, FTP, ...
I've inserted for example "secure download of the config for Cisco IOS" in template.txt.
and some other new template for the method "multi".

A snmp trap or Syslog can start/active the configuration of "TFTP" or "multi" method.

Method TFTP:
------------
 This plugin method has been created in order to be easily adapted to any 
download/upload config manager, but I develop it with "pancho" (www.pancho.org)
a very good and efficient tool which work with almost all types
of router and switches (cisco,foundry,avaya, Nortel, acelar, and much more).
With this pugin you can easily schedule severall download or upload of 
configuration of your switches. If severall configuration are schedule
for the same time, only one will be immediatly executed, the other have
 to wait the next polling of cacti (5 Minutes). I choose this option
 because I don't want to overload the server. For the upload I fixed a
max value (see in setting) because it could be very dangerous. But you 
can change the default.
You can use only one SNMP parameter set for one download/upload configuration.
 But you can create a lot of download/upload confiurations.
You have the possibility to choose to insert the routers or switches with the device
 list of mac_trac if this plugin is activated (click on "hostid?" or "mactracid?"
checkbox). It appear only if you have mactrac plugin.
The advantage you don't need to group the devices by constructor. Pancho know it via SNMP
The disadvantage you have to active SNMP.
You can change the format of the uploaded/downloaded file.
You can choose for each config a post or pre command executed by pancho.
You can reset the "last run" time direct from the first configmanager view in order to force 
to restart the download/upload in 5 minutes.

Method "multi":
---------------
With this method you can insert any command to execute on the selected devices.
This method seems easy but it very powerful because you can now:
    - download / upload on a device with Telnet, SCP, SSH, SFTP or your scripts or FTP ....
You can define your own functions template in the file "template.txt" (no reboot, only click again).
Some template are defined in template.txt. The help text of your template will be 
shown when you select your option and click on the help button.
The disavantage of this method is you have to group the devices because this function and
 this cannot detect automatically the constructor or model of the device.
The advantage is you don't need SNMP and can do what you want.

You can select a template or direct type your command in the parameter of the config.

Some parameters will be exchange during the execution.
%i% will be replaced by the ip addresse of the device. %n% = name of the device listed in a configuration.
%d% = day, %y% = year %m% = month. %f% = name of the config. %l% = log file name %s% = full log file name.
%p% = path. %u% = user. %w%= password. %g% = path to configmanager plugins directory.

Comparaison tool :
-----------------
You can compare what you want its a diff. I tested only under windows
at this time but it should also function under linux. For the Windows users 
I have put a diff.exe in the configmanager plugins which has the same parameters
as under linux. For the compare (diff) function check it you have the following temporary folder 
'./plugins/configmanager/temp'


security:
---------
1/ I 've add a feature for security reason in order accept that only 
some IP addresses have the right to manage this plugin (the cacti
server is also automatically allowed). The allowed IP 
addresses have to be inserted in the file "secure.cfg", but you
can see these from the setting tab.
2/ For the comparaison of the file I want to use the same idea in order
to avoid the access above the specified directory. I use the file
"securecompare.cfg"

Installation:
-------------
For now I choose the user_auth_realms 60 but it could be changed in the
 future.
0/ You will need the plugin-architectur of Jimmy http://cactiusers.org
1a/ Only If you want to use the "TFTP" method with Pancho
   Install "pancho" www.pancho.org (with perl!!).
   For the lazy people I put my installed pancho directory in the forum. So
   you will need only copy-paste
1b/ If you want to use the "TFTP" method with pure PHP you have to install (copy)
   the sharednetwork class (for example under plugins\sharednetworkclass). If you don't
   copy it into plugins\sharednetworkclass you have to change the path in config.php.
2/ copy the plugin under "your_cacti/plugins/configmanager"
   - !!! if you have some scripts under "your_cacti/plugins/configmanager/scripts" don't forget
   to copy them again.
3/ Step NO MORE NEEDED if you can wait 5 minutes (you can look at the configmanager-logfile if the databases has been created)
   create the sql database
   - "mysql --user=root --password cacti < your_cacti/plugins/configmanager/configmanager.sql"
4/ put in the "your_cacti/include/config.php" file
   "$plugins[] = 'configmanager';" like described in plugin architectur.
5/ put the right to use this plugin for your special user. (In the cacti user administration tab)
6/ give the right to access to this plugin only for the managers workstations in plugins/configmanager/secure.cfg.
   From the cacti server you have always the right to use it.
7/ insert in the settings tab: Only If you want to use the "TFTP" method
 - TFTP server (name or IP)     
 - TFTP root data path          
 - program (please with the full name if cactid and if you prefer the pancho library use the "-Id:/programme/pancho/lib" parameter like me)
   (for me I have put D:/Programme/perl/bin/perl.exe -Id:/programme/pancho/lib d:/programme/pancho/pancho.pl)
8/ insert in the settings tab: 
 - "file to start before" and "file to start after" only if you want to start a
      programm before or after the download/upload.
8/ create your configuration to schedule
9/ For the compare (diff) function check it you have the following temporary folder 
'./plugins/configmanager/temp'
10/ For the windows users without "diff" and "gzip" check if these programs are under
"plugins/configmanager/" or installed with the environement variable path.
If not download it from http://forums.cacti.net/about12406.html or 
or the http://cactiusers.org/forums/topic257.html
11/ For the Unix users you can remove "diff.exe" and "gzip.exe" under "plugins/configmanager/"
if you want.
12/ For the "multi" method check if the file template.txt covers your needs.
     (please if you have good ideas, new templates tell us that)

upgrade of the data:
--------------------
NO MORE NEEDED if you can wait 5 minutes until the config manager setup do it.
you can look at the configmanager-logfile if the databases has been created.

If you prefer manually :
start on the command line 'php ...plugins\configmanager\database_upgrade.php'

FAQ
----
1/ How functions the scheduler periodically?
First the scheduler starts the configuration at the date you
have insert. Then will start on the period you ve given (ie:
monthly at this time and day).
If you have severall configuration at the same time only one will
be executed, the next will wait 5 minutes or the next poller-time
of cacti. 

2/ What is the difference between the two debug mode ?
"debug mode" is when you want to see more information in cactilog
"debug mode for SNMP upload/download request" is for the activation
 of pancho debug (SNMP debug).

3/ How to use an another download/upload program?
You have to change all the function in "configmanager_gatewaytoprogram.php".

4/ How to test from the command line
with "php configmanager_poller.php -d"
but you have first to reset the start time of your config in checking the desired 
config and doing a reset "last run time" from first view.

6/ How to test the produced configfile directly with pancho from the shell?
From command: [...] --> means optional
.../perl [-IdirectoryOfpancho\lib ] directoryOfpancho\pancho.pl --upload --filename fileToBeUploaded --post --config  configurationFileProducedFromConfigmanager
.../perl [-IdirectoryOfpancho\lib ] directoryOfpancho\pancho.pl --download --post --config configurationFileProducedFromConfigmanager

7/ how to restart the config (in 5 minutes):
the desired config must be checked and do a reset "last run time" from first view.

8/ (Pancho method) Why my downloaded file is under the Tftproot and not in mydirectory
   mydirectory have to be under the Tftproot path and mydirectory have to be given relative
   to this Tftproot path
9/ (Pancho method) How to download directly in a subdirectory like 20060502
   put in the parameter "path for data" '%y%%m%%d%'. If you Tftproot path is /data
   the file will be copied under /data/20060502 if the date is 2. Mai 2006

10/ Under Unix. With the method multi the scp (or ssh) command don't run automatically but scp want
 a password and certificate ?
  - You can use the BSD scp with the option -1 and/or first generate a certificate/key, because scp and ssh by unix
  do not accept a interactive password.
  - or create first generate the certificates/keys both machine with null password or use ssh-agent

11/ How to active snmp trap or Syslog capabilities ?
  0/ You need Syslog plugin
  a/ insert your traps and exception in the view "trap events"
  b/ Active the global option in the settings.
  c/ active "trap events" in each config you want.

12/ How can I see which configmanager config have an active "trap events" ?
  - look at the view "trap events"

history:
--------
11.11.2007 correction because cacti 0.8.7 and syslog-plugin changes files and variables.
11.11.2007 correction bug for "multi" method when path empty
02.08.2007 version 0.72 correction for downloading TFTP pure PHP with NET-SNMP
25.07.2007 version 0.71 add of binary upload/download param for Nortel+Passport
20.07.2007 version 0.7 with integration of TFTP method pure PHP
20.07.2007 correction for downloading(starting script) after a trap for the method
           TFTP because TFTP make the device is sending a trap.
20.03.2007 add some template for cisco and Foundry scp download
11.02.2007 add of traps events starting the download of configuration
11.02.2007 change of format of dates in the logs to "Y-m-d H:i:s"
11.02.2007 keep the rigth snmp version by editing
25.01.2007 new release 0.5f Bug by removing hosts. It removed the host in each config
24.01.2007 released 0.5e
24.01.2007 hardening for some version of PHP and MySQL which are controlling more the variables types
           in configmanager.php and configmanager_edit.php
19.01.2007 <?php in top_headertable.php
19.01.2007 some PHP version do not recognize the value false as 0. (configmanager.php)
16.01.2007 correction in version 0.5e showing the pancho configuration when you click on the icon like a text
           in the view configmanager_edit (view for inserting the hosts
04.01.2007 correction in version0.5c the lost of the SQL autoincrement for the upgrades
01.01.2007 correction of "warnesj" if download/upload of devices needs more than 5 minutes
14.12.2006 don't use any more the "save_sql" of cacti because they remove the ;
13.12.2006 correction for cacti older as 0.8i and configmanager0.5a (function tail_file )
26.11.2006 add warning before deleting
26.11.2006 some minor changes in compare
26.11.2006 add possibility to change the TFTP server in each config (in order to allow NAT)
26.11.2006 add new logfile
26.11.2006 show in red the devices that are no more in cacti and mac_trac
26.11.2006 correction for removing devices
04.08.2006 method TFTP: add some function like commit and download of startup
03.08.2006 method TFTP: some change for uploading a file
13.07.2006 correct the Unix error "Running PHP5 / PHP Warning: Call-time pass-by-reference has been deprecated"
05.02.2006 correct bugs : add $config['url_path'] in inc_device_filter_table.php
05.02.2006 correct Unix bugs with pictures ex: comparaison.GIF -> comparaison.gif
12.05.2006 correct bugs for people which have not a cacti with a direct http alias. Like http://serverx/mycactideveloppement
03.05.2006 add template for the multi method (download with telnet on cisco,
           download with scp
03.05.2006 add example for PRE and POST command of pancho
03.05.2006 correction of start of process for method multi
03.05.2006 correction of ispre ispost parameter error message
17.04.2006 You can change the format of the uploaded/downloaded file.
17.04.2006 You can choose for each config a post or pre command to be executed by pancho.
17.04.2006 reset the "last run" time direct from the first configmanager view in order to force 
           to restart the download/upload in 5 minutes.
06.04.2006 dynamic help: show help of the template by clicking on "? icon"
04.04.2006 remove the "move" after the download in TFTP method
02.04.2006 new version with SCP, SFTP, SSH
31.03.2006 comparaison of two files with same name
26.03.2006 solve some bug in compare for unix
26.03.2006 add compare of gz or zip
25.03.2006 create "scandir" function also for PHP4 in compare.php 
24.03.2006 I have change "up/down" to "active/paused" in order to avoid 
	confusion with "upload" and "download configuration.
24.03.2006 add the compare "diff" function
16.03.2006 add show "last log file"
16.03.2006 problem with select all solved
14.03.2006 possibility to use mactrac devices 
14.03.2006 no more problem with the drop list 
13.03.2006 the filter look now only at the name not the description 
12.03.2006 correction bug with any. 
12.03.2006 correction bug switch up/down. 
12.03.2006 correction bug filter 
13.03.2006 the filter look now only at the name not the description
12.03.2006 correction bug with any.
12.03.2006 correction bug switch up/down.
12.03.2006 correction bug filter