plugin for download/upload routers switches configuration

General discussion about Plugins for Cacti

Moderators: Developers, Moderators

Post Reply
kos
Posts: 25
Joined: Wed Nov 01, 2006 2:29 am
Location: Singapore

Post by kos »

Hi pepj,

first of all, thank you for your strong support :D

I removed line 253 but received the following failure message:
Notice: Undefined variable: id2 in c:\Inetpub\wwwroot\cacti\plugins\configmanager\configmanager.php on line 254

Warning: Cannot modify header information - headers already sent by (output started at c:\Inetpub\wwwroot\cacti\plugins\configmanager\configmanager.php:254) in c:\Inetpub\wwwroot\cacti\plugins\configmanager\configmanager.php on line 269
I added line 253 again and as well I added the lines in 254. Based on the log I noticed that I could only save it, if all fields with "monthly, daily" are activated", otherwise I got the failure message (see in the log file).

After saving it (with all fields activated), I could see the list of devices, but it fails to add them into the config.

Likely the same issue with "non integer values" ?!?! Any idea?

Thanks again.

Kai
Attachments
cfgmng_logfile.txt
(2.59 KiB) Downloaded 344 times
pepj
Cacti User
Posts: 324
Joined: Thu Sep 29, 2005 5:03 am
Location: switzerland

Post by pepj »

kos wrote: I noticed that I could only save it, if all fields with "monthly, daily" are activated", otherwise I got the failure message (see in the log file).
OK I think we got it .... the false value in your PHP is not interpreted as 0 !!!

Can you try this ?
replace in configmanager.php the following lines (after line228)

Code: Select all

		$save["monthly"] = isset($_POST['chk_monthly']) ? ($_POST['chk_monthly']=="on"): false;	
		/* info of Checkboxes are only set if "on" */
		$save["mon"] = isset($_POST['chk_mon']) ? ($_POST['chk_mon']=="on"): false;
		$save["tue"] = isset($_POST['chk_tue']) ? ($_POST['chk_tue']=="on"): false;
		$save["wed"] = isset($_POST['chk_wed']) ? ($_POST['chk_wed']=="on"): false;
		$save["thu"] = isset($_POST['chk_thu']) ? ($_POST['chk_thu']=="on"): false;
		$save["fri"] = isset($_POST['chk_fri']) ? ($_POST['chk_fri']=="on"): false;
		$save["sat"] = isset($_POST['chk_sat']) ? ($_POST['chk_sat']=="on"): false;
		$save["sun"] = isset($_POST['chk_sun']) ? ($_POST['chk_sun']=="on"): false;
with

Code: Select all

		$save["monthly"] = isset($_POST['chk_monthly']) ? (($_POST['chk_monthly']=="on")?1:0): 0;	
		/* info of Checkboxes are only set if "on" */
		$save["mon"] = isset($_POST['chk_mon']) ? (($_POST['chk_mon']=="on")?1:0): 0;
		$save["tue"] = isset($_POST['chk_tue']) ? (($_POST['chk_tue']=="on")?1:0): 0;
		$save["wed"] = isset($_POST['chk_wed']) ? (($_POST['chk_wed']=="on")?1:0): 0;
		$save["thu"] = isset($_POST['chk_thu']) ? (($_POST['chk_thu']=="on")?1:0): 0;
		$save["fri"] = isset($_POST['chk_fri']) ? (($_POST['chk_fri']=="on")?1:0): 0;
		$save["sat"] = isset($_POST['chk_sat']) ? (($_POST['chk_sat']=="on")?1:0): 0;
		$save["sun"] = isset($_POST['chk_sun']) ? (($_POST['chk_sun']=="on")?1:0): 0;
If it works I will release this plugin into 0.5e.

I have also find an other bug for showing the pancho configuration when you click on the icon like a text in the view configmanager_edit (view for inserting the hosts)
In configmanager_edit.php the line 30

Code: Select all

include("./include/auth.php");
must be move in line 34 direct behind

Code: Select all

include("./plugins/configmanager/config.php");
include("./plugins/configmanager/debug.php");
include("./plugins/configmanager/functions.php");
Jean-Michel
cacti 0.8.7e | cmd & cactid (cactid 0.8.x) | Linux | MySQL Ver 14.7 Distrib 4.1.12, for Win32 | PHP v5.2.6 | Apache v2.x | Thold | Plugin Architecture | plugin "configuration manager" http://cactiusers.org/forums/topic257.html | plugin "IP subnet calculator IPv4 / IPV6" http://forums.cacti.net/viewtopic.php?t=15428 | plugin banner http://docs.cacti.net/userplugin:banner | Net-SNMP 5.5.2 | cygwin 1.5.18 of 02.07.2005
kos
Posts: 25
Joined: Wed Nov 01, 2006 2:29 am
Location: Singapore

Post by kos »

Hi pepj,

the creation of a config file works fine with the changes in configmanager.php.

The other change, related to pancho I can't check.

But I can still not add any hosts to the configs in a second step. Do you have any idea why?

Thanks

kai
pepj
Cacti User
Posts: 324
Joined: Thu Sep 29, 2005 5:03 am
Location: switzerland

Post by pepj »

kos wrote:But I can still not add any hosts to the configs in a second step.
1/ Did you see a value for configid in the url ?
like

http://cacti/plugins/configmanager/conf ... onfigid=15[/b]&name=configmanagerTESTX

2/ in order to be sure ... you checked the desired hosts and click on the butto 'GO' of "Choose an action: Add into config" on the rigtht ?

3/ could you insert between line 242 and 243 in the file configmanager_edit.php.

Code: Select all

$message=date("d/m/Y H:i:s ")."SQL Save configuration's hosts in tables ".$cfgmngtable_data.". -> id result=$gid, code=".mysql_errno()
." errortext=".mysql_error()."\ndata to save are :".print_r($save,true)."\n";
cfgmng_log($message);
Same principle as before Each time you will do a insert/remove/move a hosts of the config your parameters and the SQL code will be inserted in the logfile of configmanager (either select Console/config updown-load/logfile or look at the file ...plugins/configmanager/cfgmng_logfile.txt)
what can you see ?
Jean-Michel
cacti 0.8.7e | cmd & cactid (cactid 0.8.x) | Linux | MySQL Ver 14.7 Distrib 4.1.12, for Win32 | PHP v5.2.6 | Apache v2.x | Thold | Plugin Architecture | plugin "configuration manager" http://cactiusers.org/forums/topic257.html | plugin "IP subnet calculator IPv4 / IPV6" http://forums.cacti.net/viewtopic.php?t=15428 | plugin banner http://docs.cacti.net/userplugin:banner | Net-SNMP 5.5.2 | cygwin 1.5.18 of 02.07.2005
kos
Posts: 25
Joined: Wed Nov 01, 2006 2:29 am
Location: Singapore

Post by kos »

Hi Pepj,

1) I assume, the end of the url is not visible due to the size of the statusline of the explorer

2. yes

3) I added the code and got a failure message via the WEB (see attachment). Additionally I added the log which shows some errors with the "configid".

ciao

kos
kos
Posts: 25
Joined: Wed Nov 01, 2006 2:29 am
Location: Singapore

Post by kos »

and here is the attachment
Attachments
configmanager3.doc
(28.5 KiB) Downloaded 346 times
pepj
Cacti User
Posts: 324
Joined: Thu Sep 29, 2005 5:03 am
Location: switzerland

Post by pepj »

kos wrote:and here is the attachment

1/ I think it is the wrong attachement !!???

2/ What do you mind with 1)... the end of the url is not visible due to the size of the statusline of the explorer ?
You normally should see the view where you have to enter the hosts with a url like

Code: Select all

http://cacti/plugins/configmanager/configmanager_edit.php?action=edit&configid=15&name=configmanagerTESTX 
Jean-Michel
cacti 0.8.7e | cmd & cactid (cactid 0.8.x) | Linux | MySQL Ver 14.7 Distrib 4.1.12, for Win32 | PHP v5.2.6 | Apache v2.x | Thold | Plugin Architecture | plugin "configuration manager" http://cactiusers.org/forums/topic257.html | plugin "IP subnet calculator IPv4 / IPV6" http://forums.cacti.net/viewtopic.php?t=15428 | plugin banner http://docs.cacti.net/userplugin:banner | Net-SNMP 5.5.2 | cygwin 1.5.18 of 02.07.2005
kos
Posts: 25
Joined: Wed Nov 01, 2006 2:29 am
Location: Singapore

Post by kos »

Pepj,

1) you are right, below is the correct attachment.

2) I see the url with an id and name
Attachments
configmanager4.doc
(1.7 KiB) Downloaded 360 times
pepj
Cacti User
Posts: 324
Joined: Thu Sep 29, 2005 5:03 am
Location: switzerland

Post by pepj »

kos wrote: Undefined variable: gid in .... line 243 from configmanager_edit.php
a $ should be before the variable gid in line inserted for debuging (Posted: Thu Jan 18, 2007 8:20 am) like

Code: Select all

result=$gid, code=".mysql_errno()
do you have from line 242 to line246 something like this ?

Code: Select all

		$gid = sql_save2($save, $cfgmngtable_data);
$message=date("d/m/Y H:i:s ")."SQL Save configuration's hosts in tables ".$cfgmngtable_data.". -> id result=$gid, code=".mysql_errno()
." errortext=".mysql_error()."\ndata to save are :".print_r($save,true)."\n";
cfgmng_log($message);
		if (!$gid) $failed = true;

You have also to remove the wrong datas from plugin_cfgmng_data ...
I see your configmanagerid => 2
1/ to see the data

Code: Select all

select * from plugin_cfgmng_data;
2/ to delete the wrong data of configmanagerid=2

Code: Select all

delete from plugin_cfgmng_data where configmanagerid=2;
I say you have to remove the wrong data because I 've seen in your logfile:
[gorder] => 1
[state] => enable
.......
[hostid] => 20
[configmanagerid] => 2
[id] =>
(
data to save are :Array
22/01/2007 06:47:40 SQL Save configuration's hosts in tables plugin_cfgmng_data. -> id result=0, code=1054 errortext=Unknown column 'configid' in 'where clause'
)
Jean-Michel
cacti 0.8.7e | cmd & cactid (cactid 0.8.x) | Linux | MySQL Ver 14.7 Distrib 4.1.12, for Win32 | PHP v5.2.6 | Apache v2.x | Thold | Plugin Architecture | plugin "configuration manager" http://cactiusers.org/forums/topic257.html | plugin "IP subnet calculator IPv4 / IPV6" http://forums.cacti.net/viewtopic.php?t=15428 | plugin banner http://docs.cacti.net/userplugin:banner | Net-SNMP 5.5.2 | cygwin 1.5.18 of 02.07.2005
kos
Posts: 25
Joined: Wed Nov 01, 2006 2:29 am
Location: Singapore

Post by kos »

Hi Pepj,

the $ was in front of the gid ...

I added the missing line
$gid = sql_save2($save, $cfgmngtable_data);
and the failure message does not appear anymore

But I can still not save hosts. The failure message (please find in the log) refers to a wrong value:
errortext=Incorrect integer value: '' for column 'snmp_version' at row 1
May be its again a problem with my php version [5.1.4]
Attachments
configmanager5.doc
(1.03 KiB) Downloaded 280 times
pepj
Cacti User
Posts: 324
Joined: Thu Sep 29, 2005 5:03 am
Location: switzerland

Post by pepj »

kos wrote: May be its again a problem with my php version [5.1.4]
May be this version PHP or SQL has some default to improve the control of the variable types. But it should function with any function. Therefore I have to do hardening too.
kos wrote: Incorrect integer value: '' for column 'snmp_version'
I want to force the snmp_version field when not used ... do to 2 things
1/ in "configmanager_edit.php" replace line 224

Code: Select all

		$save["snmp_version"] = $tempconfig[0]['snmp_version'];
with

Code: Select all

		$ver = $tempconfig[0]['snmp_version'];
		if ($tempconfig[0]['configtype']!="tftp") $ver = 1;
		$save["snmp_version"] = $ver;
you should have from line 223 to 227

Code: Select all

		$save["hostip"] = GetHostByName($hostname);
		$ver = $tempconfig[0]['snmp_version'];
		if ($tempconfig[0]['configtype']!="tftp") $ver = 1;
		$save["snmp_version"] = $ver;
		$save["hostuser"] = $tempconfig[0]['snmp_username'];
2/ in "configmanager.php" insert line between 567 and 568

Code: Select all

	    if (!is_int($valuesnmp_version)) $valuesnmp_version=1;
You should have between 567 and 569

Code: Select all

	    if (isset($_POST['snmp_version'])) {$valuesnmp_version=$_POST['snmp_version'];} else {$valuesnmp_version=$snmp_versiondef;};
	    if (!is_int($valuesnmp_version)) $valuesnmp_version=1;
	    $valuesnmp_version=(($valuesnmp_version>0)&&($valuesnmp_version<4))?$valuesnmp_version:1;
Thanks a lot for your patience
Jean-Michel
cacti 0.8.7e | cmd & cactid (cactid 0.8.x) | Linux | MySQL Ver 14.7 Distrib 4.1.12, for Win32 | PHP v5.2.6 | Apache v2.x | Thold | Plugin Architecture | plugin "configuration manager" http://cactiusers.org/forums/topic257.html | plugin "IP subnet calculator IPv4 / IPV6" http://forums.cacti.net/viewtopic.php?t=15428 | plugin banner http://docs.cacti.net/userplugin:banner | Net-SNMP 5.5.2 | cygwin 1.5.18 of 02.07.2005
kos
Posts: 25
Joined: Wed Nov 01, 2006 2:29 am
Location: Singapore

Post by kos »

Hi Pepj,

I changed the code according to your input and now

!!! I T W O R K S !!!!!!!!

even if the hosts are stored twice :lol: I can easily remove them manually.

Thanks for your support and your energy to get it running :D

regards from Singapore

kos
kos
Posts: 25
Joined: Wed Nov 01, 2006 2:29 am
Location: Singapore

Post by kos »

hmmm I was too optimistic,

trying to remove one of the doubled entries, removes both entries.

regards

kos
pepj
Cacti User
Posts: 324
Joined: Thu Sep 29, 2005 5:03 am
Location: switzerland

Post by pepj »


but it functions now, doesn't it ? .... do you have problem to insert and remove hosts ?


I have posted the new release 0.5e with all the changes.

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
Jean-Michel
cacti 0.8.7e | cmd & cactid (cactid 0.8.x) | Linux | MySQL Ver 14.7 Distrib 4.1.12, for Win32 | PHP v5.2.6 | Apache v2.x | Thold | Plugin Architecture | plugin "configuration manager" http://cactiusers.org/forums/topic257.html | plugin "IP subnet calculator IPv4 / IPV6" http://forums.cacti.net/viewtopic.php?t=15428 | plugin banner http://docs.cacti.net/userplugin:banner | Net-SNMP 5.5.2 | cygwin 1.5.18 of 02.07.2005
kos
Posts: 25
Joined: Wed Nov 01, 2006 2:29 am
Location: Singapore

Post by kos »

Yes I have problems in adding and removing hosts to/from the different configs.

Adding a host to a config results in 2 entries (see attachment)
Removing a host of a config results in eliminating both hosts entries

Additionally I recognised another topic:

Assume, you added a single device to several configs. If you remove such host in ONE dedicated config, the host gets removed in ALL configs

Details I have shown in the attachment

ciao

kos
Attachments
configmanager6.doc
(93 KiB) Downloaded 356 times
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest