Hey, all.
I have a perl script which generates the html listed below. I cleaned it
up a bit since the perl CGI module creates some really ugly html code.
I've looked at this thing 8 ways to Sunday, but I can't see anything wrong.
When I hit the "Add" button, it immediately executes the action of the form
skipping the validate_form function completely.
I've tried the script section towards the top of the html as well as
just before the </body></html> without success.
I'm betting it's a simple mistake, but for the life of me, I can't find
it. Can someone tell me what I've screwed up?
Thanks for your time.
Doug O'Leary
HTML/javascript code:
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
<head><title>Ad d Nagios monitored host</title>
<link rev="made" href="mailto:dk oleary%40oleary computers.com"> </head>
<body>
<h1>Add Nagios Monitored Host</h1>
<p>Fields in <font color="red">red </font> are required</p>
<form method="post" action="/cgi-bin/run_this_comman d"
onsubmit="retur n validate_form(t his)">
<table><tbody >
<tr>
<td><button type="submit" onclick="return validate_form(t his)">
<big>Add</big></button></td>
<td><button
onclick="locati on.href='/nagios/cgi-bin/nadmin?func=dis play_hosts';
return false;">
<big>Reset</big></button></td>
</tr>
<tr>
<td> </td> <td> </td> <td> </td></tr>
<tr>
<th align="left">Fi eld</th>
<th align="left">Va lue</th>
<th align="left">De scription</th>
</tr>
<tr bgcolor="silver ">
<td><font color="red">hos t_name</font></td>
<td><input name="host_name " length="20" type="text"></td>
<td>Host name</td>
</tr>
<tr>
<td><font color="red">ali as</font></td>
<td><input name="host_name " length="20" type="text"></td>
<td>Nagios alias</td>
</tr>
<tr bgcolor="silver ">
<td><font color="red">add ress</font></td>
<td><input name="host_name " length="20" type="text"></td>
<td>IP address</td>
</tr>
<tr>
<td>parents</td>
<td><input name="parents" size="20" value="DEFAULT" type="text"></td>
<td>Hosts between Nagios server and host_name</td>
</tr>
<tr bgcolor="silver ">
<td>check_comma nd</td>
<td><select name="check_com mand">
<option selected="selec ted" value="" default="">DEFA ULT</option>
<option value="check-host-alive">check-host-alive </option>
<option value="check_dn s">check_dns </option>
<option value="check_ft p">check_ftp </option>
<option value="check_hp jd">check_hpj d </option>
<option value="check_ht tp">check_htt p </option>
<option value="check_ht tp_path">check_ http_path </option>
<option value="check_ht tp_port">check_ http_port </option>
<option value="check_im ap">check_ima p </option>
<option value="check_lo cal_disk">check _local_disk </option>
<option value="check_lo cal_load">check _local_load </option>
<option value="check_lo cal_procs">chec k_local_procs </option>
<option value="check_lo cal_users">chec k_local_users </option>
<option value="check_nn tp">check_nnt p </option>
<option value="check_nt _clientversion" >check_nt_clien tversion </option>
<option value="check_nt _cpuload">check _nt_cpuload </option>
<option value="check_nt _disk">check_nt _disk </option>
<option value="check_nt _fileage">check _nt_fileage </option>
<option value="check_nt _memuse">check_ nt_memuse </option>
<option value="check_nt _pagingfile">ch eck_nt_pagingfi le </option>
<option value="check_nt _process">check _nt_process </option>
<option value="check_nt _service">check _nt_service </option>
<option value="check_nt _service_nav">c heck_nt_service _nav </option>
<option value="check_nt _uptime">check_ nt_uptime </option>
<option value="check_nw stat_load15">ch eck_nwstat_load 15 </option>
<option value="check_nw stat_vkf">check _nwstat_vkf </option>
<option value="check_nw stat_vpf">check _nwstat_vpf </option>
<option value="check_pi ng">check_pin g </option>
<option value="check_po p">check_pop </option>
<option value="check_sm tp">check_smt p </option>
<option value="check_ss h">check_ssh </option>
<option value="check_tc p">check_tcp </option>
<option value="check_te lnet">check_tel net </option>
<option value="check_ud p">check_udp </option>
<option value="host-notify-by-email">host-notify-by-email </option>
<option value="host-notify-by-epager">host-notify-by-epager </option>
<option value="notify-by-email">notify-by-email </option>
<option value="notify-by-epager">notify-by-epager </option>
<option value="process-host-perfdata">proce ss-host-perfdata </option>
<option value="process-service-perfdata">
process-service-perfdata</option>
</select></td>
<td>Command used to verify host up/down.</td>
</tr>
<tr>
<td><font color="red">max _check_attempts </font></td>
<td><input name="max_check _attempts" value="10" type="text"></td>
<td>Max times to check host</td>
</tr>
<tr bgcolor="silver ">
<td>checks_enab led</td>
<td><select name="checks_en abled">
<option selected="selec ted" value="DEFAULT" >DEFAULT</option>
<option value="0">0</option>
<option value="1">1 </option>
</select></td>
<td>Whether or checks are enabled [0/1]</td>
</tr>
<tr>
<td>event_handl er</td>
<td><select name="event_han dler">
<option selected="selec ted" value="" default="">DEFA ULT</option>
<option value="check-host-alive">check-host-alive </option>
<option value="check_dn s">check_dns </option>
<option value="check_ft p">check_ftp </option>
<option value="check_hp jd">check_hpj d</option>
<option value="check_ht tp">check_htt p</option></option>
<option value="check_ht tp_port">check_ http_port </option>
<option value="check_im ap">check_ima p </option>
<option value="check_lo cal_disk">check _local_disk </option>
<option value="check_lo cal_load">check _local_load </option>
<option value="check_lo cal_procs">chec k_local_procs </option>
<option value="check_lo cal_users">chec k_local_users </option>
<option value="check_nn tp">check_nnt p </option>
<option value="check_nt _clientversion" >check_nt_clien tversion </option>
<option value="check_nt _cpuload">check _nt_cpuload </option>
<option value="check_nt _disk">check_nt _disk </option>
<option value="check_nt _fileage">check _nt_fileage </option>
<option value="check_nt _memuse">check_ nt_memuse </option>
<option value="check_nt _pagingfile">ch eck_nt_pagingfi le </option>
<option value="check_nt _process">check _nt_process </option>
<option value="check_nt _service">check _nt_service </option>
<option value="check_nt _service_nav">c heck_nt_service _nav </option>
<option value="check_nt _uptime">check_ nt_uptime </option>
<option value="check_nw stat_load15">ch eck_nwstat_load 15 </option>
<option value="check_nw stat_vkf">check _nwstat_vkf </option>
<option value="check_nw stat_vpf">check _nwstat_vpf </option>
<option value="check_pi ng">check_pin g </option>
<option value="check_po p">check_pop </option>
<option value="check_sm tp">check_smt p </option>
<option value="check_ss h">check_ssh </option>
<option value="check_tc p">check_tcp </option>
<option value="check_te lnet">check_tel net </option>
<option value="check_ud p">check_udp </option>
<option value="host-notify-by-email">host-notify-by-email </option>
<option value="host-notify-by-epager">host-notify-by-epager </option>
<option value="notify-by-email">notify-by-email </option>
<option value="notify-by-epager">notify-by-epager </option>
<option value="process-host-perfdata">proce ss-host-perfdata </option>
<option value="process-service-perfdata">proce ss-service-perfdata</option>
</select></td>
<td>Command to run when state changes.</td>
</tr>
<tr bgcolor="silver ">
<td>event_handl er_enabled</td>
<td><select name="event_han dler_enabled">
<option selected="selec ted" value="DEFAULT" >DEFAULT </option>
<option value="0">0 </option>
<option value="1">1</option>
</select></td>
<td>Whether or not event handlers work. [0/1]</td>
</tr>
<tr>
<td>low_flap_th reshold</td>
<td><input name="low_flap_ threshold"
size="20" value="DEFAULT" type="text"></td>
<td>IDs the low state change threshold for flap detection</td>
</tr>
<tr bgcolor="silver ">
<td>high_flap_t hreshold</td>
<td><input name="high_flap _threshold" size="20"
value="DEFAULT" type="text"></td>
<td>IDS the high state change threshold for flap detection. </td>
</tr>
<tr>
<td>flap_detect ion_enabled</td>
<td><select name="flap_dete ction_enabled">
<option selected="selec ted" value="DEFAULT" >DEFAULT </option>
<option value="0">0 </option>
<option value="1">1</option>
</select></td>
<td>IDs if flap detection is functional. [0/1]</td>
</tr>
<tr bgcolor="silver ">
<td>process_per f_data</td>
<td><select name="process_p erf_data">
<option selected="selec ted" value="DEFAULT" >DEFAULT </option>
<option value="0">0 </option>
<option value="1">1 </option>
</select></td>
<td>Whether or not to process perf data. [0/1]</td>
</tr>
<tr>
<td>retain_stat us_information</td>
<td><select name="retain_st atus_informatio n">
<option selected="selec ted" value="DEFAULT" >DEFAULT </option>
<option value="0">0 </option>
<option value="1">1</option>
</select></td>
<td>Whether or not to retain state information [0/1]</td>
</tr>
<tr bgcolor="silver ">
<td>retain_nons tatus_informati on</td>
<td><select name="retain_no nstatus_informa tion">
<option selected="selec ted" value="DEFAULT" >DEFAULT </option>
<option value="0">0 </option>
<option value="1">1</option>
</select></td>
<td>Whether or not to retain nonstatus information. [0/1]</td>
</tr>
<tr>
<td><font color="red">not ification_inter val</font></td>
<td><input name="notificat ion_interval" value="120" type="text"></td>
<td>Wait specified # of time units before renotification. </td>
</tr>
<tr bgcolor="silver ">
<td><font color="red">not ification_perio d</font></td>
<td><select name="notificat ion_period">
<option value="24x7">24 x7 </option>
<option selected="selec ted" value="none">no ne </option>
<option value="nonworkh ours">nonworkho urs </option>
<option value="workhour s">workhours </option>
</select></td>
<td>IDs timeperiod during which notifications can occur.</td>
</tr>
<tr>
<td><font color="red">not ification_optio ns</font></td>
<td><input name="notificat ion_options" value="d,u,r" type="text"></td>
<td>IDs upon which state notificatons should be sent. [d,u,r]</td>
</tr>
<tr bgcolor="silver ">
<td>notificatio ns_enabled</td>
<td><select name="notificat ions_enabled">
<option selected="selec ted" value="DEFAULT" >DEFAULT </option>
<option value="0">0 </option>
<option value="1">1</option>
</select></td>
<td>Whether or not notifications are enabled. [0/1] </td>
</tr>
<tr>
<td>stalking_op tions</td>
<td><input name="stalking_ options" size="20"
value="DEFAULT" type="text"></td>
<td>IDS for which host states stalking is enabled [o,d,u]</td>
</tr>
<tr bgcolor="silver ">
<td>register</td>
<td><select name="register" >
<option selected="selec ted" value="DEFAULT" >DEFAULT </option>
<option value="0">0 </option>
<option value="1">1</option>
</select></td>
<td>IDs if host_name should be registered. Defaults to 1</td>
</tr>
</tbody>
</table></form>
<script>
function isNotEmpty(elem )
{ var str = elem.value;
if (str == null || str.length == 0)
{ alert("Please fill in hostname");
return false;
}
return true;
}
function validate_form(f orm)
{ if (isNotEmpty(for m.host_name)
{ if (isNotEmpty(for m.alias)
{ if (isNotEmpty(for m.address)
{ return true;
}
}
}
return false;
}
function report_error(ms g, url, line)
{ alert("Msg: " + msg);
alert("Line: " + line);
}
window.onerror = report_error;
</script>
</body></html>
I have a perl script which generates the html listed below. I cleaned it
up a bit since the perl CGI module creates some really ugly html code.
I've looked at this thing 8 ways to Sunday, but I can't see anything wrong.
When I hit the "Add" button, it immediately executes the action of the form
skipping the validate_form function completely.
I've tried the script section towards the top of the html as well as
just before the </body></html> without success.
I'm betting it's a simple mistake, but for the life of me, I can't find
it. Can someone tell me what I've screwed up?
Thanks for your time.
Doug O'Leary
HTML/javascript code:
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
<head><title>Ad d Nagios monitored host</title>
<link rev="made" href="mailto:dk oleary%40oleary computers.com"> </head>
<body>
<h1>Add Nagios Monitored Host</h1>
<p>Fields in <font color="red">red </font> are required</p>
<form method="post" action="/cgi-bin/run_this_comman d"
onsubmit="retur n validate_form(t his)">
<table><tbody >
<tr>
<td><button type="submit" onclick="return validate_form(t his)">
<big>Add</big></button></td>
<td><button
onclick="locati on.href='/nagios/cgi-bin/nadmin?func=dis play_hosts';
return false;">
<big>Reset</big></button></td>
</tr>
<tr>
<td> </td> <td> </td> <td> </td></tr>
<tr>
<th align="left">Fi eld</th>
<th align="left">Va lue</th>
<th align="left">De scription</th>
</tr>
<tr bgcolor="silver ">
<td><font color="red">hos t_name</font></td>
<td><input name="host_name " length="20" type="text"></td>
<td>Host name</td>
</tr>
<tr>
<td><font color="red">ali as</font></td>
<td><input name="host_name " length="20" type="text"></td>
<td>Nagios alias</td>
</tr>
<tr bgcolor="silver ">
<td><font color="red">add ress</font></td>
<td><input name="host_name " length="20" type="text"></td>
<td>IP address</td>
</tr>
<tr>
<td>parents</td>
<td><input name="parents" size="20" value="DEFAULT" type="text"></td>
<td>Hosts between Nagios server and host_name</td>
</tr>
<tr bgcolor="silver ">
<td>check_comma nd</td>
<td><select name="check_com mand">
<option selected="selec ted" value="" default="">DEFA ULT</option>
<option value="check-host-alive">check-host-alive </option>
<option value="check_dn s">check_dns </option>
<option value="check_ft p">check_ftp </option>
<option value="check_hp jd">check_hpj d </option>
<option value="check_ht tp">check_htt p </option>
<option value="check_ht tp_path">check_ http_path </option>
<option value="check_ht tp_port">check_ http_port </option>
<option value="check_im ap">check_ima p </option>
<option value="check_lo cal_disk">check _local_disk </option>
<option value="check_lo cal_load">check _local_load </option>
<option value="check_lo cal_procs">chec k_local_procs </option>
<option value="check_lo cal_users">chec k_local_users </option>
<option value="check_nn tp">check_nnt p </option>
<option value="check_nt _clientversion" >check_nt_clien tversion </option>
<option value="check_nt _cpuload">check _nt_cpuload </option>
<option value="check_nt _disk">check_nt _disk </option>
<option value="check_nt _fileage">check _nt_fileage </option>
<option value="check_nt _memuse">check_ nt_memuse </option>
<option value="check_nt _pagingfile">ch eck_nt_pagingfi le </option>
<option value="check_nt _process">check _nt_process </option>
<option value="check_nt _service">check _nt_service </option>
<option value="check_nt _service_nav">c heck_nt_service _nav </option>
<option value="check_nt _uptime">check_ nt_uptime </option>
<option value="check_nw stat_load15">ch eck_nwstat_load 15 </option>
<option value="check_nw stat_vkf">check _nwstat_vkf </option>
<option value="check_nw stat_vpf">check _nwstat_vpf </option>
<option value="check_pi ng">check_pin g </option>
<option value="check_po p">check_pop </option>
<option value="check_sm tp">check_smt p </option>
<option value="check_ss h">check_ssh </option>
<option value="check_tc p">check_tcp </option>
<option value="check_te lnet">check_tel net </option>
<option value="check_ud p">check_udp </option>
<option value="host-notify-by-email">host-notify-by-email </option>
<option value="host-notify-by-epager">host-notify-by-epager </option>
<option value="notify-by-email">notify-by-email </option>
<option value="notify-by-epager">notify-by-epager </option>
<option value="process-host-perfdata">proce ss-host-perfdata </option>
<option value="process-service-perfdata">
process-service-perfdata</option>
</select></td>
<td>Command used to verify host up/down.</td>
</tr>
<tr>
<td><font color="red">max _check_attempts </font></td>
<td><input name="max_check _attempts" value="10" type="text"></td>
<td>Max times to check host</td>
</tr>
<tr bgcolor="silver ">
<td>checks_enab led</td>
<td><select name="checks_en abled">
<option selected="selec ted" value="DEFAULT" >DEFAULT</option>
<option value="0">0</option>
<option value="1">1 </option>
</select></td>
<td>Whether or checks are enabled [0/1]</td>
</tr>
<tr>
<td>event_handl er</td>
<td><select name="event_han dler">
<option selected="selec ted" value="" default="">DEFA ULT</option>
<option value="check-host-alive">check-host-alive </option>
<option value="check_dn s">check_dns </option>
<option value="check_ft p">check_ftp </option>
<option value="check_hp jd">check_hpj d</option>
<option value="check_ht tp">check_htt p</option></option>
<option value="check_ht tp_port">check_ http_port </option>
<option value="check_im ap">check_ima p </option>
<option value="check_lo cal_disk">check _local_disk </option>
<option value="check_lo cal_load">check _local_load </option>
<option value="check_lo cal_procs">chec k_local_procs </option>
<option value="check_lo cal_users">chec k_local_users </option>
<option value="check_nn tp">check_nnt p </option>
<option value="check_nt _clientversion" >check_nt_clien tversion </option>
<option value="check_nt _cpuload">check _nt_cpuload </option>
<option value="check_nt _disk">check_nt _disk </option>
<option value="check_nt _fileage">check _nt_fileage </option>
<option value="check_nt _memuse">check_ nt_memuse </option>
<option value="check_nt _pagingfile">ch eck_nt_pagingfi le </option>
<option value="check_nt _process">check _nt_process </option>
<option value="check_nt _service">check _nt_service </option>
<option value="check_nt _service_nav">c heck_nt_service _nav </option>
<option value="check_nt _uptime">check_ nt_uptime </option>
<option value="check_nw stat_load15">ch eck_nwstat_load 15 </option>
<option value="check_nw stat_vkf">check _nwstat_vkf </option>
<option value="check_nw stat_vpf">check _nwstat_vpf </option>
<option value="check_pi ng">check_pin g </option>
<option value="check_po p">check_pop </option>
<option value="check_sm tp">check_smt p </option>
<option value="check_ss h">check_ssh </option>
<option value="check_tc p">check_tcp </option>
<option value="check_te lnet">check_tel net </option>
<option value="check_ud p">check_udp </option>
<option value="host-notify-by-email">host-notify-by-email </option>
<option value="host-notify-by-epager">host-notify-by-epager </option>
<option value="notify-by-email">notify-by-email </option>
<option value="notify-by-epager">notify-by-epager </option>
<option value="process-host-perfdata">proce ss-host-perfdata </option>
<option value="process-service-perfdata">proce ss-service-perfdata</option>
</select></td>
<td>Command to run when state changes.</td>
</tr>
<tr bgcolor="silver ">
<td>event_handl er_enabled</td>
<td><select name="event_han dler_enabled">
<option selected="selec ted" value="DEFAULT" >DEFAULT </option>
<option value="0">0 </option>
<option value="1">1</option>
</select></td>
<td>Whether or not event handlers work. [0/1]</td>
</tr>
<tr>
<td>low_flap_th reshold</td>
<td><input name="low_flap_ threshold"
size="20" value="DEFAULT" type="text"></td>
<td>IDs the low state change threshold for flap detection</td>
</tr>
<tr bgcolor="silver ">
<td>high_flap_t hreshold</td>
<td><input name="high_flap _threshold" size="20"
value="DEFAULT" type="text"></td>
<td>IDS the high state change threshold for flap detection. </td>
</tr>
<tr>
<td>flap_detect ion_enabled</td>
<td><select name="flap_dete ction_enabled">
<option selected="selec ted" value="DEFAULT" >DEFAULT </option>
<option value="0">0 </option>
<option value="1">1</option>
</select></td>
<td>IDs if flap detection is functional. [0/1]</td>
</tr>
<tr bgcolor="silver ">
<td>process_per f_data</td>
<td><select name="process_p erf_data">
<option selected="selec ted" value="DEFAULT" >DEFAULT </option>
<option value="0">0 </option>
<option value="1">1 </option>
</select></td>
<td>Whether or not to process perf data. [0/1]</td>
</tr>
<tr>
<td>retain_stat us_information</td>
<td><select name="retain_st atus_informatio n">
<option selected="selec ted" value="DEFAULT" >DEFAULT </option>
<option value="0">0 </option>
<option value="1">1</option>
</select></td>
<td>Whether or not to retain state information [0/1]</td>
</tr>
<tr bgcolor="silver ">
<td>retain_nons tatus_informati on</td>
<td><select name="retain_no nstatus_informa tion">
<option selected="selec ted" value="DEFAULT" >DEFAULT </option>
<option value="0">0 </option>
<option value="1">1</option>
</select></td>
<td>Whether or not to retain nonstatus information. [0/1]</td>
</tr>
<tr>
<td><font color="red">not ification_inter val</font></td>
<td><input name="notificat ion_interval" value="120" type="text"></td>
<td>Wait specified # of time units before renotification. </td>
</tr>
<tr bgcolor="silver ">
<td><font color="red">not ification_perio d</font></td>
<td><select name="notificat ion_period">
<option value="24x7">24 x7 </option>
<option selected="selec ted" value="none">no ne </option>
<option value="nonworkh ours">nonworkho urs </option>
<option value="workhour s">workhours </option>
</select></td>
<td>IDs timeperiod during which notifications can occur.</td>
</tr>
<tr>
<td><font color="red">not ification_optio ns</font></td>
<td><input name="notificat ion_options" value="d,u,r" type="text"></td>
<td>IDs upon which state notificatons should be sent. [d,u,r]</td>
</tr>
<tr bgcolor="silver ">
<td>notificatio ns_enabled</td>
<td><select name="notificat ions_enabled">
<option selected="selec ted" value="DEFAULT" >DEFAULT </option>
<option value="0">0 </option>
<option value="1">1</option>
</select></td>
<td>Whether or not notifications are enabled. [0/1] </td>
</tr>
<tr>
<td>stalking_op tions</td>
<td><input name="stalking_ options" size="20"
value="DEFAULT" type="text"></td>
<td>IDS for which host states stalking is enabled [o,d,u]</td>
</tr>
<tr bgcolor="silver ">
<td>register</td>
<td><select name="register" >
<option selected="selec ted" value="DEFAULT" >DEFAULT </option>
<option value="0">0 </option>
<option value="1">1</option>
</select></td>
<td>IDs if host_name should be registered. Defaults to 1</td>
</tr>
</tbody>
</table></form>
<script>
function isNotEmpty(elem )
{ var str = elem.value;
if (str == null || str.length == 0)
{ alert("Please fill in hostname");
return false;
}
return true;
}
function validate_form(f orm)
{ if (isNotEmpty(for m.host_name)
{ if (isNotEmpty(for m.alias)
{ if (isNotEmpty(for m.address)
{ return true;
}
}
}
return false;
}
function report_error(ms g, url, line)
{ alert("Msg: " + msg);
alert("Line: " + line);
}
window.onerror = report_error;
</script>
</body></html>
Comment