From d95cc86e826887528926b71f55d114bdbe9b2ad5 Mon Sep 17 00:00:00 2001
From: guruevi <noreply@pandorafms.org>
Date: Wed, 7 Jan 2009 15:57:33 +0000
Subject: [PATCH] 2009-01-07  Evi Vanoost  <vanooste@rcbi.rochester.edu>

	* include/functions.php: Removed safe_sql_string. Cleaned documenation so
	it would be parsed without errors by phpdoc

	* include/functions_exportserver.php: Aggregate all exportserver functions
	here.

	* include/functions_db.php: Cleaned up documentation. Added
	get_modulegroups and get_modulegroup_name.

	* godmode/db/db_refine.php: Fixed the selection box.

	* godmode/agentes/agent_disk_conf_editor.php: Added todo. Don't handle
	the footer anymore

	* godmode/agentes/agent_template.php,
	godmode/agentes/module_manager_editor_plugin.php,
	godmode/agentes/module_manager_editor_wmi.php,
	godmode/agentes/module_manager_editor.php,
	godmode/agentes/module_manager_editor_data.php,
	godmode/agentes/alert_manager_editor.php,
	godmode/agentes/module_manager_editor_network.php,
	godmode/agentes/module_manager.php, godmode/agentes/agent_manager.php,
	godmode/agentes/alert_manager.php:
	Removed the ACL part since it was redundant due to the inclusion.
	Just made sure that it was included (checking on $id_agente)

	* godmode/agentes/manage_config.php,
	godmode/agentes/manage_config_remote.php,
	godmode/agentes/planned_downtime.php: Style fix

	* godmode/agentes/configurar_agente.php
	godmode/agentes/module_manager_editor_prediction.php: Fixed prediction
	module creation/update bugs

	* godmode/setup/links.php: No more relying on antique (PHP4) functions

git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1321 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
---
 pandora_console/ChangeLog                     |  38 +++++
 .../agentes/agent_disk_conf_editor.php        |  11 +-
 .../godmode/agentes/agent_manager.php         |  21 +--
 .../godmode/agentes/agent_template.php        |  12 +-
 .../godmode/agentes/alert_manager.php         |  15 +-
 .../godmode/agentes/alert_manager_editor.php  |   4 +-
 .../godmode/agentes/configurar_agente.php     |  14 +-
 .../godmode/agentes/manage_config.php         |   4 +-
 .../godmode/agentes/manage_config_remote.php  |   4 +-
 .../godmode/agentes/modificar_agente.php      |  12 +-
 .../godmode/agentes/module_manager.php        |  12 +-
 .../godmode/agentes/module_manager_editor.php |  14 +-
 .../agentes/module_manager_editor_data.php    |   4 +-
 .../agentes/module_manager_editor_network.php |   6 +-
 .../agentes/module_manager_editor_plugin.php  |   5 +-
 .../module_manager_editor_prediction.php      | 141 ++++++++----------
 .../agentes/module_manager_editor_wmi.php     |   7 +-
 .../godmode/agentes/planned_downtime.php      |   8 +-
 pandora_console/godmode/db/db_refine.php      |   4 +-
 pandora_console/godmode/setup/links.php       |   5 +-
 pandora_console/include/functions.php         |  71 ++++-----
 pandora_console/include/functions_db.php      |  90 +++++++----
 .../include/functions_exportserver.php        |  68 +++++++++
 23 files changed, 312 insertions(+), 258 deletions(-)
 create mode 100644 pandora_console/include/functions_exportserver.php

diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog
index 144e518c54..bf2ab805e9 100644
--- a/pandora_console/ChangeLog
+++ b/pandora_console/ChangeLog
@@ -1,3 +1,41 @@
+2009-01-07  Evi Vanoost  <vanooste@rcbi.rochester.edu>
+
+	* include/functions.php: Removed safe_sql_string. Cleaned documenation so
+	it would be parsed without errors by phpdoc
+	
+	* include/functions_exportserver.php: Aggregate all exportserver functions
+	here.
+	
+	* include/functions_db.php: Cleaned up documentation. Added 
+	get_modulegroups and get_modulegroup_name.
+	
+	* godmode/db/db_refine.php: Fixed the selection box.
+
+	* godmode/agentes/agent_disk_conf_editor.php: Added todo. Don't handle 
+	the footer anymore
+	
+	* godmode/agentes/agent_template.php, 
+	godmode/agentes/module_manager_editor_plugin.php,
+	godmode/agentes/module_manager_editor_wmi.php, 
+	godmode/agentes/module_manager_editor.php,
+	godmode/agentes/module_manager_editor_data.php,
+	godmode/agentes/alert_manager_editor.php,
+	godmode/agentes/module_manager_editor_network.php, 
+	godmode/agentes/module_manager.php, godmode/agentes/agent_manager.php,
+	godmode/agentes/alert_manager.php: 
+	Removed the ACL part since it was redundant due to the inclusion. 
+	Just made sure that it was included (checking on $id_agente)
+	
+	* godmode/agentes/manage_config.php,
+	godmode/agentes/manage_config_remote.php,
+	godmode/agentes/planned_downtime.php: Style fix
+	
+	* godmode/agentes/configurar_agente.php
+	godmode/agentes/module_manager_editor_prediction.php: Fixed prediction 
+	module creation/update bugs
+	
+	* godmode/setup/links.php: No more relying on antique (PHP4) functions
+	
 2009-01-07  Esteban Sanchez  <estebans@artica.es>
 
 	* godmode/agentes/modificar_agente.php: Old functions replace with new
diff --git a/pandora_console/godmode/agentes/agent_disk_conf_editor.php b/pandora_console/godmode/agentes/agent_disk_conf_editor.php
index 0c41384001..040d96e1d5 100644
--- a/pandora_console/godmode/agentes/agent_disk_conf_editor.php
+++ b/pandora_console/godmode/agentes/agent_disk_conf_editor.php
@@ -1,11 +1,6 @@
-<?PHP
-
+<?php
+//TODO: Implement an open source version
 if (enterprise_include ("godmode/agentes/agent_disk_conf_editor.php") === ENTERPRISE_NOT_HOOK) {
-	echo "<h3>This feature is not included on OpenSource version. Please visit our website to learn more about the advanced features of <a href='http://pandorafms.com'>Pandora FMS Enterprise edition</a></h3>";
-	// Footer
-	echo "</div><div id='foot'>";
-	include ("general/footer.php");
-	echo "</div>";
+	echo "<h3>This feature is not included on the Open Source version. Please visit our website to learn more about the advanced features of <a href='http://pandorafms.com'>Pandora FMS Enterprise edition</a></h3>";
 }
-
 ?>
diff --git a/pandora_console/godmode/agentes/agent_manager.php b/pandora_console/godmode/agentes/agent_manager.php
index f386ec6b23..13d7cb8e16 100644
--- a/pandora_console/godmode/agentes/agent_manager.php
+++ b/pandora_console/godmode/agentes/agent_manager.php
@@ -16,24 +16,17 @@
 // along with this program; if not, write to the Free Software
 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
+// Load global vars
+enterprise_include ('godmode/agentes/agent_manager.php');
+
+if (!isset ($id_agente)) {
+	die ("Not Authorized");
+}
+
 // ========================
 // AGENT GENERAL DATA FORM 
 // ========================
 
-// Load global vars
-require_once ('include/config.php');
-
-enterprise_include ('godmode/agentes/agent_manager.php');
-
-check_login ();
-
-if (! give_acl ($config['id_user'], 0, "AW")) {
-	audit_db ($config['id_user'], $REMOTE_ADDR, "ACL Violation",
-		"Trying to access agent manager");
-	require ("general/noaccess.php");
-	exit;
-}
-
 echo "<h2>".__('Agent configuration');
 if (isset($_GET["create_agent"])) {
 	$create_agent = 1;
diff --git a/pandora_console/godmode/agentes/agent_template.php b/pandora_console/godmode/agentes/agent_template.php
index 1a80f9c323..1441e6b58c 100644
--- a/pandora_console/godmode/agentes/agent_template.php
+++ b/pandora_console/godmode/agentes/agent_template.php
@@ -17,16 +17,8 @@
 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
 // Load global vars
-require_once ("include/config.php");
-
-check_login ();
-
-// Access control
-if (! give_acl ($config['id_user'], 0, "AW") || !isset ($id_agente)) {
-	audit_db ($config['id_user'], $REMOTE_ADDR, "ACL Violation",
-		"Trying to access agent manager");
-	require ("general/noaccess.php");
-	exit;
+if (!isset ($id_agente)) {
+	die ("Not Authorized");
 }
 
 // ==========================
diff --git a/pandora_console/godmode/agentes/alert_manager.php b/pandora_console/godmode/agentes/alert_manager.php
index c5fbeaee47..84f2a44a08 100644
--- a/pandora_console/godmode/agentes/alert_manager.php
+++ b/pandora_console/godmode/agentes/alert_manager.php
@@ -16,19 +16,10 @@
 // along with this program; if not, write to the Free Software
 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
-
-
 // Load global vars
-require("include/config.php");
-
-check_login();
-
-if (! give_acl ($config["id_user"], 0, "AW")) {
-	audit_db ($config["id_user"], $REMOTE_ADDR, "ACL Violation",
-		"Trying to access agent manager");
-	require ($config["homedir"]."/general/noaccess.php");
-	return;
-};
+if (!isset ($id_agente)) {
+	die ("Not Authorized");
+}
 
 echo "<h2>".__('Agent configuration')." &gt; ".__('Alerts')."</h2>";
 // ==========================
diff --git a/pandora_console/godmode/agentes/alert_manager_editor.php b/pandora_console/godmode/agentes/alert_manager_editor.php
index 040f2c8f92..8655c1fc78 100644
--- a/pandora_console/godmode/agentes/alert_manager_editor.php
+++ b/pandora_console/godmode/agentes/alert_manager_editor.php
@@ -16,7 +16,9 @@
 // along with this program; if not, write to the Free Software
 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
-
+if (!isset ($id_agente)) {
+	die ("Not Authorized");
+}
 
 $add_component = get_parameter ("add_component",0);
 echo "<h3>".__('Alert association form');
diff --git a/pandora_console/godmode/agentes/configurar_agente.php b/pandora_console/godmode/agentes/configurar_agente.php
index bf20472b36..6ce35d9083 100644
--- a/pandora_console/godmode/agentes/configurar_agente.php
+++ b/pandora_console/godmode/agentes/configurar_agente.php
@@ -16,17 +16,16 @@
 // along with this program; if not, write to the Free Software
 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
-
 // Load global vars
-require("include/config.php");
-enterprise_include('godmode/agentes/configurar_agente.php');
+require_once ("include/config.php");
+enterprise_include ('godmode/agentes/configurar_agente.php');
 
 check_login ();
 
 //See if id_agente is set (either POST or GET, otherwise -1
-$id_agente = get_parameter ("id_agente", -1);
+$id_agente = (int) get_parameter ("id_agente", -1);
 
-$group = dame_id_grupo ($id_agente); //Will return 0 or an int
+$group = get_agent_group ($id_agente);
 
 if (! give_acl($config["id_user"], $group, "AW")) {
 	audit_db ($config['id_user'], $REMOTE_ADDR, "ACL Violation",
@@ -35,7 +34,6 @@ if (! give_acl($config["id_user"], $group, "AW")) {
 	exit;
 }
 
-
 // Get passed variables
 $tab = get_parameter_get ("tab", "main");
 $form_moduletype = get_parameter_post ("form_moduletype");
@@ -699,7 +697,6 @@ if ((isset ($_POST["update_module"])) || (isset ($_POST["insert_module"]))) {
 	$form_minvalue = (int) get_parameter_post ("form_minvalue",0);
 	$form_maxvalue = (int) get_parameter ("form_maxvalue",0);
 	$form_interval = (int) get_parameter ("form_interval",300);
-	$form_id_prediction_module = (int) get_parameter ("form_id_prediction_module",0);
 	$form_id_plugin = (int) get_parameter ("form_id_plugin",0);
 	$form_id_export = (int) get_parameter ("form_id_export",0);
 	$form_disabled = (bool) get_parameter ("form_disabled",0);
@@ -725,6 +722,7 @@ if ((isset ($_POST["update_module"])) && (!isset ($_POST["oid"]))) { // if modif
 			$snmp_oid = $form_combo_snmp_oid;
 		}
 	}
+	
 	$sql = sprintf ("UPDATE tagente_modulo SET 
 			descripcion = '%s', 
 			id_module_group = %d,
@@ -801,7 +799,7 @@ if (((!isset ($_POST["nc"]) OR ($_POST["nc"] == -1))) && (!isset ($_POST["oid"])
 		VALUES (%d,%d,'%s','%s',%d,%d,'%s','%s',%d,%d,'%s',%d,'%s','%s',%d,'%s','%s','%s',%d,%d,%d,%d,%d,%d,'%s')",
 			$id_agente, $form_id_tipo_modulo, $form_name, $form_description, $form_maxvalue, $form_minvalue, $form_snmp_oid, $form_snmp_community, 
 			$form_id_module_group, $form_interval, $form_ip_target, $form_tcp_port, $form_tcp_rcv, $form_tcp_send, $form_id_export, $form_plugin_user, $form_plugin_pass, 
-			$form_plugin_parameter, $form_id_plugin, $form_post_process, $form_id_prediction_module, $form_max_timeout, $form_disabled, $form_id_modulo, $form_custom_id);
+			$form_plugin_parameter, $form_id_plugin, $form_post_process, $form_prediction_module, $form_max_timeout, $form_disabled, $form_id_modulo, $form_custom_id);
 	$id_agente_modulo = process_sql ($sql, 'insert_id');
 
 	if ($id_agente_modulo === false){
diff --git a/pandora_console/godmode/agentes/manage_config.php b/pandora_console/godmode/agentes/manage_config.php
index 665cbb9483..ceb71096cd 100644
--- a/pandora_console/godmode/agentes/manage_config.php
+++ b/pandora_console/godmode/agentes/manage_config.php
@@ -16,10 +16,8 @@
 // along with this program; if not, write to the Free Software
 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
-
-
 // Load global vars
-require ("include/config.php");
+require_once ("include/config.php");
 
 check_login ();
 
diff --git a/pandora_console/godmode/agentes/manage_config_remote.php b/pandora_console/godmode/agentes/manage_config_remote.php
index 6271396949..256dec62af 100644
--- a/pandora_console/godmode/agentes/manage_config_remote.php
+++ b/pandora_console/godmode/agentes/manage_config_remote.php
@@ -16,10 +16,8 @@
 // along with this program; if not, write to the Free Software
 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
-
-
 // Load global vars
-require ("include/config.php");
+require_once ("include/config.php");
 
 check_login();
 
diff --git a/pandora_console/godmode/agentes/modificar_agente.php b/pandora_console/godmode/agentes/modificar_agente.php
index f16bca0cd4..386700875b 100644
--- a/pandora_console/godmode/agentes/modificar_agente.php
+++ b/pandora_console/godmode/agentes/modificar_agente.php
@@ -16,24 +16,20 @@
 // along with this program; if not, write to the Free Software
 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
-
 // Load global vars
 require_once ("include/config.php");
-
-if (give_acl($config["id_user"], 0, "AW") != 1) {
-	audit_db($config["id_user"],$REMOTE_ADDR, "ACL Violation",
-	"Trying to access Agent Management");
-	require ("general/noaccess.php");
-	exit;
-}
+	
+check_login ();
 
 // Take some parameters (GET)
 $offset = get_parameter ("offset", 0);
 $group_id = get_parameter ("group_id", 0);
 $ag_group = get_parameter ("ag_group", -1);
+
 if (($ag_group == -1) && ($group_id != 0)) {
 	$ag_group = $group_id;
 }
+
 if (isset ($_GET["ag_group_refresh"])){
 	$ag_group = get_parameter_get ("ag_group_refresh", -1);
 }
diff --git a/pandora_console/godmode/agentes/module_manager.php b/pandora_console/godmode/agentes/module_manager.php
index 3c35586099..e57d87e875 100644
--- a/pandora_console/godmode/agentes/module_manager.php
+++ b/pandora_console/godmode/agentes/module_manager.php
@@ -18,15 +18,9 @@
 
 
 // Load global vars
-require("include/config.php");
-check_login();
-
-if (give_acl($config["id_user"], 0, "AW")!=1) {
-    audit_db($config["id_user"], $REMOTE_ADDR, "ACL Violation","Trying to access agent manager");
-    require ($config["homedir"]."/general/noaccess.php");
-    exit;
-};
-
+if (!isset ($id_agente)) {
+	die ("Not Authorized");
+}
 
 echo "<h2>".__('Agent configuration')." &gt; ".__('Modules')."</h2>"; 
 
diff --git a/pandora_console/godmode/agentes/module_manager_editor.php b/pandora_console/godmode/agentes/module_manager_editor.php
index 37ef332121..6c7eed47bc 100644
--- a/pandora_console/godmode/agentes/module_manager_editor.php
+++ b/pandora_console/godmode/agentes/module_manager_editor.php
@@ -16,18 +16,12 @@
 // along with this program; if not, write to the Free Software
 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
-
-
-// General startup for established session
-check_login();
-
-// Specific ACL check
-if (give_acl ($config["id_user"], 0, "AW") != 1) {
-	audit_db($config["id_user"], $REMOTE_ADDR, "ACL Violation","Trying to access agent manager");
-	require ($config["homedir"]."/general/noaccess.php");
-	exit;
+if (!isset ($id_agente)) {
+	die ("Not Authorized");
 }
 
+require_once ("include/functions_exportserver.php");
+
 // Following variables come from module_manager.php -> configurar_agente.php :
 //
 // $form_moduletype: could be [1] Agent module/Data server, [2] network server, [4] plugin server, [6] wmiserver, or [5] predictionserver
diff --git a/pandora_console/godmode/agentes/module_manager_editor_data.php b/pandora_console/godmode/agentes/module_manager_editor_data.php
index 7ef78a1b00..1d49f61274 100644
--- a/pandora_console/godmode/agentes/module_manager_editor_data.php
+++ b/pandora_console/godmode/agentes/module_manager_editor_data.php
@@ -17,7 +17,9 @@
 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
 // General startup for established session
-check_login();
+if (!isset ($id_agente)) {
+	die ("Not Authorized");
+}
 
 // get the variable form_moduletype
 $form_moduletype = get_parameter_post ("form_moduletype");
diff --git a/pandora_console/godmode/agentes/module_manager_editor_network.php b/pandora_console/godmode/agentes/module_manager_editor_network.php
index 930f72d98c..7573e971cb 100644
--- a/pandora_console/godmode/agentes/module_manager_editor_network.php
+++ b/pandora_console/godmode/agentes/module_manager_editor_network.php
@@ -18,9 +18,9 @@
 
 
 // General startup for established session
-global $config;
-check_login();
-global $form_snmp_community;
+if (!isset ($id_agente)) {
+	die ("Not Authorized");
+}
 
 // get the variable form_moduletype
 $form_moduletype = get_parameter_post ("form_moduletype");
diff --git a/pandora_console/godmode/agentes/module_manager_editor_plugin.php b/pandora_console/godmode/agentes/module_manager_editor_plugin.php
index 121ffd9780..632add5334 100644
--- a/pandora_console/godmode/agentes/module_manager_editor_plugin.php
+++ b/pandora_console/godmode/agentes/module_manager_editor_plugin.php
@@ -18,8 +18,9 @@
 
 
 // General startup for established session
-global $config;
-check_login();
+if (!isset ($id_agente)) {
+	die ("Not Authorized");
+}
 
 // get the variable form_moduletype
 $form_moduletype = get_parameter_post ("form_moduletype");
diff --git a/pandora_console/godmode/agentes/module_manager_editor_prediction.php b/pandora_console/godmode/agentes/module_manager_editor_prediction.php
index c943e557af..9dc4f47871 100644
--- a/pandora_console/godmode/agentes/module_manager_editor_prediction.php
+++ b/pandora_console/godmode/agentes/module_manager_editor_prediction.php
@@ -16,11 +16,10 @@
 // along with this program; if not, write to the Free Software
 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
-
-
 // General startup for established session
-global $config;
-check_login();
+if (!isset ($id_agente)) {
+	die ("Not Authorized");
+}
 
 // get the variable form_moduletype
 $form_moduletype = get_parameter_post ("form_moduletype");
@@ -30,7 +29,7 @@ $update_module_id = get_parameter_get ("update_module");
 $disabled_status = NULL;
 
 // Specific ACL check
-if (give_acl($config["id_user"], 0, "AW")!=1) {
+if (give_acl($config["id_user"], 0, "AW") != 1) {
     audit_db($config["id_user"], $REMOTE_ADDR, "ACL Violation","Trying to access agent manager");
     require ($config["homedir"]."/general/noaccess.php");
     exit;
@@ -82,112 +81,102 @@ echo "<h3>".__('Module assignment')." - ".__('Prediction server module')."</h3>"
 echo '<form name="modulo" method="post" action="index.php?sec=gagente&sec2=godmode/agentes/configurar_agente&tab=module&id_agente='.$id_agente.'">';
 // Whether in update or insert mode
 if ($update_module_id == NULL){
-	echo "<input type='hidden' name='insert_module' value='1'>";
+	print_input_hidden ("insert_module", 1);
 } else {
-	echo "<input type='hidden' name='update_module' value='1'>";
+	print_input_hidden ("update_module", 1);
 }
 
 //id_agente_module
-echo "<input type='hidden' name='id_agente_modulo'' value='".$update_module_id."'>";
+print_input_hidden ("id_agente_modulo", $update_module_id);
 
 // id_modulo 5 - Prediction
-echo "<input type='hidden' name='form_id_modulo' value='5'>";
+print_input_hidden ("form_id_modulo", 5);
 
 // name / disabled
 echo '<table width="600" cellpadding="4" cellspacing="4" class="databox_color">';
 echo '<tr>';
-echo '<td class="datos2">'.__('Module name')."</td>";
-echo '<td class="datos2"><input type="text" name="form_name" size="35" value="'.$form_name.'"></td>';
-echo '<td class="datos2">'.__('Disabled')."</td>";
-echo '<td class="datos2"><input type="checkbox" name="form_disabled" value="1" "'.$disabled_status.'"></td>';
-echo '</tr>';
-
+echo '<td class="datos2">'.__('Module name').'</td>';
+echo '<td class="datos2">';
+print_input_text ("form_name", $form_name, '', 35);
+echo '<td class="datos2">'.__('Disabled').'</td>';
+echo '<td class="datos2">';
+print_checkbox ("form_disabled", 1, $disabled_status);
+echo '</td></tr>';
 
+//Source module
 echo '<tr>';
 echo '<td class="datos">'.__('Source module');
 pandora_help ("prediction_source_module");
 echo '</td>';
 echo '<td class="datos" colspan="3">';
-echo '<select name="form_id_prediction_module">';
-$sql1='SELECT id_agente_modulo, tagente_modulo.nombre, tagente.id_agente, tagente.id_grupo, tagente.nombre FROM tagente_modulo, tagente WHERE id_tipo_modulo NOT IN (100,24,19,20,21,22,23,17,10,2) AND tagente.id_agente = tagente_modulo.id_agente ORDER BY tagente.nombre';
-$result=mysql_query($sql1);
-while ($row=mysql_fetch_array($result)){
-	if (give_acl($config["id_user"], $row[3], "AR"))
-    	echo "<option value='".$row[0]."'>".$row[1]. " / ". $row[4];
-}
-echo "</select>";
-echo "</tr>";
 
-// module type
-echo '</tr><tr>';
-echo '<td class="datos2">'. __('Module type') .'</td>';
-echo '<td class="datos2">';
-if ($update_module_id != NULL){
-	echo "<span class='redi'>Not available in edition mode</span>";
-	echo "<input type='hidden' name='form_id_tipo_modulo' value='".$form_id_tipo_modulo."'>";
-} else {
-	echo '<select name="form_id_tipo_modulo">';
-	$sql1='SELECT id_tipo, nombre FROM ttipo_modulo WHERE id_tipo IN (1,2) ORDER BY nombre';
-	$result=mysql_query($sql1);
-	while ($row=mysql_fetch_array($result)){
-		echo "<option value='".$row["id_tipo"]."'>".$row["nombre"]."</option>";
+$agents = get_group_agents (array_keys (get_user_groups ($config["id_user"], "AW")));
+$fields = array ();
+
+foreach ($agents as $agent_id => $agent_name) {
+	$modules = get_agent_modules ($agent_id);
+	foreach ($modules as $module_id => $module_name) {
+		$fields[$module_id] = $agent_name.' / '.$module_name;
 	}
-	echo '</select>';
 }
 
-echo '<td class="datos2">'.__('Interval')."</td>";
-echo '<td class="datos2"><input type="text" name="form_interval" size="5" value="'.$form_interval.'"></td></tr>';
+print_select ($fields, "form_prediction_module", $form_prediction_module);
+echo '</td></tr>';
+
+// module type / interval
+echo '<tr><td class="datos2">'. __('Module type') .'</td><td class="datos2">';
+if (!empty ($update_module_id)) {
+	echo '<span class="redi">Not available in edition mode</span>';
+	print_input_hidden ("form_id_tipo_modulo", $form_id_tipo_modulo);
+} else {
+	$fields = array ();
+	$fields[1] = get_moduletype_name (1);
+	$fields[2] = get_moduletype_name (2);
+	print_select ($fields, "form_id_tipo_modulo");
+}
+
+echo '<td class="datos2">'.__('Interval').'</td><td class="datos2">';
+print_input_text ("form_interval", $form_interval, '', 5);
+echo '</td></tr>';
 
 // Post process / Export server
-echo '<tr>';
-echo '<td class="datos">'.__('Module group')."</td>";
-echo '<td class="datos"><select name="form_id_module_group">';
-if ($form_id_module_group != 0){
-    echo "<option value='".$form_id_module_group."'>".dame_nombre_grupomodulo($form_id_module_group)."</option>";
-}
-$sql1='SELECT * FROM tmodule_group';
-$result=mysql_query($sql1);
-while ($row=mysql_fetch_array($result)){
-    echo "<option value='".$row["id_mg"]."'>".$row["name"]."</option>";
-}
-echo '</select>';
+echo '<tr><td class="datos">'.__('Module group').'</td><td class="datos">';
+$fields = get_modulegroups ();
+print_select ($fields, "form_id_module_group", $form_id_module_group);
+
 // Export target is a server where the data will be sent
-echo '<td class="datos">'.__('Export target')."</td>";
-echo '<td class="datos"><select name="form_id_export">';
-if ($form_id_export != 0){
-    echo "<option value='".$form_id_export."'>".dame_nombre_servidorexportacion($form_id_export)."</option>";
-}
-echo "<option value='0'>".__('None')."</option>";
-$sql1='SELECT id, name FROM tserver_export ORDER BY name;';
-$result=mysql_query($sql1);
-while ($row=mysql_fetch_array($result)){
-    echo "<option value='".$row["id"]."'>".$row["name"]."</option>";
-}
-echo '</select>';
-echo '</tr>';
+echo '<td class="datos">'.__('Export target').'</td>';
+echo '<td class="datos">';
+
+$fields = get_exportservers_info ();
+$fields[0] = __('None');
+
+print_select ($fields, "form_id_export", $form_id_export);
+echo '</td></tr>';
 
 // Description
 echo '<tr>';
-echo '<td valign="top" class="datos2">'.__('Description')."</td>";
-echo '<td valign="top" class="datos2" colspan="3"><textarea name="form_description" cols="65" rows="2">'.$form_description.'</textarea>';
-echo '</tr>';
+echo '<td valign="top" class="datos2">'.__('Description').'</td>';
+echo '<td valign="top" class="datos2" colspan="3">';
+print_textarea ("form_description", 2, 65, $form_description);
+echo '</td></tr>';
 
 // Custom ID
 echo '<tr>';
-echo '<td class="datos">'.__('Custom ID')."</td>";
-echo '<td class="datos" colspan="3"><input type="text" name="form_custom_id" size="20" value="'.$form_custom_id.'"></td>';
-echo '</tr>';
+echo '<td class="datos">'.__('Custom ID').'</td>';
+echo '<td class="datos" colspan="3">';
+print_input_text ("form_custom_id", $form_custom_id, '', 20);
+echo '</td></tr>';
 
 echo '</table>';
 
 // Submit
-echo '<table width="680" cellpadding="4" cellspacing="4">';
-echo '<td valign="top" align="right">';
+echo '<div style="width:680px; text-align: right">';
 if ($update_module_id == NULL){
-	echo '<input name="crtbutton" type="submit" class="sub wand" value="'.__('Create').'">';
+	print_submit_button (__('Create'), 'crtbutton', false, 'class="sub wand"');
 } else {
-	echo '<input name="updbutton" type="submit" class="sub wand" value="'.__('Update').'">';
+	print_submit_button (__('Update'), 'updbutton', false, 'class="sub upd"');
 }
-echo '</table>';
+echo '</div>';
 
 ?>
diff --git a/pandora_console/godmode/agentes/module_manager_editor_wmi.php b/pandora_console/godmode/agentes/module_manager_editor_wmi.php
index bb96e73c4a..d3a1f57d37 100644
--- a/pandora_console/godmode/agentes/module_manager_editor_wmi.php
+++ b/pandora_console/godmode/agentes/module_manager_editor_wmi.php
@@ -16,11 +16,10 @@
 // along with this program; if not, write to the Free Software
 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
-
-
 // General startup for established session
-global $config;
-check_login();
+if (!isset ($id_agente)) {
+	die ("Not Authorized");
+}
 
 // get the variable form_moduletype
 $form_moduletype = get_parameter_post ("form_moduletype");
diff --git a/pandora_console/godmode/agentes/planned_downtime.php b/pandora_console/godmode/agentes/planned_downtime.php
index 1b3deac086..c1e2d41787 100644
--- a/pandora_console/godmode/agentes/planned_downtime.php
+++ b/pandora_console/godmode/agentes/planned_downtime.php
@@ -3,6 +3,7 @@
 // Pandora FMS - the Flexible Monitoring System
 // ============================================
 // Copyright (c) 2008 Artica Soluciones Tecnologicas, http://www.artica.es
+// Copyright (c) 2008-2009 Evi Vanoost <vanooste@rcbi.rochester.edu>
 // Please see http://pandora.sourceforge.net for full contribution list
 
 // This program is free software; you can redistribute it and/or
@@ -16,13 +17,8 @@
 // along with this program; if not, write to the Free Software
 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
-
-// Copyright (c) 2008 Evi Vanoost <vanooste@rcbi.rochester.edu>
-// Please see http://pandora.sourceforge.net for full contribution list
-
-
 // Load global vars
-require("include/config.php");
+require_once ("include/config.php");
 
 check_login();
 
diff --git a/pandora_console/godmode/db/db_refine.php b/pandora_console/godmode/db/db_refine.php
index b7575aae47..5ea42c5018 100644
--- a/pandora_console/godmode/db/db_refine.php
+++ b/pandora_console/godmode/db/db_refine.php
@@ -64,13 +64,13 @@ echo '<div style="float:left; width: 250px;">';
 echo '<b>'.__('Source agent').'</b><br />';
 
 $agent_selected = get_parameter_post ("origen", 0);
-$agents = get_group_agents (get_user_groups ($config["id_user"], "AW"));
+$agents = get_group_agents (array_keys (get_user_groups ($config["id_user"], "AW")));
 
 print_select ($agents, "origen", $agent_selected, 'javascript:this.form.update_agent.click();', __('No agent selected'), '0', false, false, false, 'w130');
 
 echo '&nbsp;&nbsp;';
 
-print_submit_button (__('Get Info'), 'update_agent', false, 'class="sub upd"');
+print_submit_button (__('Get Info'), 'update_agent', false, 'style="display:none;"');
 
 echo '<br /><br />';
 echo '<b>'.__('Modules').'</b><br /><br />';
diff --git a/pandora_console/godmode/setup/links.php b/pandora_console/godmode/setup/links.php
index 1f4417b363..47fb95a2ef 100644
--- a/pandora_console/godmode/setup/links.php
+++ b/pandora_console/godmode/setup/links.php
@@ -29,9 +29,8 @@ if (! give_acl ($config['id_user'], 0, "PM") || ! dame_admin ($config['id_user']
 
 
 	if (isset($_POST["create"])){ // If create
-		$name = entrada_limpia($_POST["name"]);
-		$link = entrada_limpia($_POST["link"]);
-		$link = safe_sql_string ($link);
+		$name = get_parameter_post ("name");
+		$link = get_parameter_post ("link");
 		$sql_insert = "INSERT INTO tlink (name,link) VALUES ('$name','$link')";
 		$result=mysql_query($sql_insert);	
 		if (! $result)
diff --git a/pandora_console/include/functions.php b/pandora_console/include/functions.php
index 778f623723..daa560cda4 100644
--- a/pandora_console/include/functions.php
+++ b/pandora_console/include/functions.php
@@ -43,9 +43,9 @@ function pandora_help ($help_id, $return = false) {
  * entities. UTF-8 is necessary for foreign chars like asian 
  * and our databases are (or should be) UTF-8
  * 
- * @param mixed String or array of strings to be cleaned.
+ * @param (mixed) String or array of strings to be cleaned.
  * 
- * @return The cleaned string.
+ * @return (mixed) The cleaned string or array.
  */
 function safe_input ($value) {
 	if (is_numeric ($value))
@@ -135,21 +135,21 @@ function output_clean_strict ($string) {
 
 
 /** 
- * WARNING: Deprecated function, use safe_input. Keep from compatibility.
+ * DEPRECATED use safe_input. Keep for compatibility.
  */
 function entrada_limpia ($string) {
 	return safe_input ($string);
 }
 
 /** 
- * Performs an extra clean to a string.
+ * Performs an extra clean to a string. Makes it usable in an URL
  *
  * It's useful on sec and sec2 index parameters, to avoid the use of
  * malicious parameters. The string is also stripped to 125 charactes.
  * 
- * @param string String to clean
+ * @param (string) String to clean
  * 
- * @return 
+ * @return (string) Cleaned string
  */
 function safe_url_extraclean ($string) {
 	/* Clean "://" from the strings
@@ -371,10 +371,10 @@ function pagination ($count, $url, $offset, $pagination = 0) {
  * If the number is zero or it's integer value, no decimals are
  * shown. Otherwise, the number of decimals are given in the call.
  * 
- * @param number Number to be rendered
- * @param decimals Number of decimals to be shown. Default value: 1
+ * @param (float) Number to be rendered
+ * @param (int) Number of decimals to be shown. Default value: 1
  * 
- * @return 
+ * @return (string) A formatted number for use in output
  */
 function format_numeric ($number, $decimals = 1) {
 	//Translate to float in case there are characters in the string so
@@ -442,9 +442,9 @@ function human_time_comparation ($timestamp) {
 }
 
 /**
- *   @function	 get_system_time
- *   @abstract   This function gets the time from either system or sql based on preference and returns it
- *   @result     Unix timestamp
+ * This function gets the time from either system or sql based on preference and returns it
+ *
+ * @return (int) Unix timestamp
 **/
 function get_system_time () {
 	global $config;
@@ -525,11 +525,7 @@ function human_date_relative ($seconds) {
 }
 
 /** 
- * 
- * 
- * @param lapse 
- * 
- * @return 
+ * DEPRECATED: Use print_timestamp instead
  */
 function render_time ($lapse) {
 	$myhour = intval (($lapse*30) / 60);
@@ -547,15 +543,15 @@ function render_time ($lapse) {
 }
 
 /** 
- * Get a paramter from a request.
+ * Get a parameter from a request.
  *
  * It checks first on post request, if there were nothing defined, it
  * would return get request
  * 
- * @param name 
- * @param default 
+ * @param (string) name of the parameter in the $_POST or $_GET array
+ * @param (mixed) default value if it wasn't found
  * 
- * @return 
+ * @return (mixed) Whatever was in that parameter, cleaned however 
  */
 function get_parameter ($name, $default = '') {
 	// POST has precedence
@@ -628,11 +624,11 @@ function get_alert_priority ($priority = 0) {
 }
 
 /** 
+ * Gets a translated string of names of days based on the boolean properties of it's input ($row["monday"] = (bool) 1 will output Mon) 
  * 
+ * @param (array) The array of boolean values to check. They should have monday -> sunday in boolean
  * 
- * @param row 
- * 
- * @return 
+ * @return (string) Translated names of days
  */
 function get_alert_days ($row) {
 	global $config;
@@ -669,11 +665,11 @@ function get_alert_days ($row) {
 }
 
 /** 
+ * Gets the alert times values and returns them as string
  * 
+ * @param (array) Array with time_from and time_to in it's keys
  * 
- * @param row2 
- * 
- * @return 
+ * @return (string) A string with the concatenated values
  */
 function get_alert_times ($row2) {
 	if ($row2["time_from"]){
@@ -693,14 +689,14 @@ function get_alert_times ($row2) {
 }
 
 /** 
- * 
+ * DEPRECATED: This has been replaced with print_table or format_alert_row
  * 
  * @param row2 
  * @param tdcolor 
  * @param id_tipo_modulo 
  * @param combined 
  * 
- * @return 
+ * @return (string) HTML code
  */
 function show_alert_row_edit ($row2, $tdcolor = "datos", $id_tipo_modulo = 1, $combined = 0){
 	global $config;
@@ -805,9 +801,9 @@ function show_alert_row_edit ($row2, $tdcolor = "datos", $id_tipo_modulo = 1, $c
 /** 
  * Formats a row from the alert table and returns an array usable in the table function
  * 
- * @param $alert (array) A valid (non empty) row from the alert table
- * @param $agent (bool) Whether to print the agent information with the module information
- * @param $combined (bool) Whether or not this is a combined alert
+ * @param (array) $alert A valid (non empty) row from the alert table
+ * @param (bool) $combined Whether or not this is a combined alert
+ * @param (bool) $agent Whether to print the agent information with the module information
  * 
  * @return (array) A formatted array with proper html for use in $table -> 7 columns
  */
@@ -1110,17 +1106,6 @@ function unsafe_string ($string) {
 	return $string;
 }
 
-/**
- * Deprecated by get_parameter functions and safe_input funcitons
- * Magic Quotes are deprecated in PHP5 and will be removed in PHP6
- */
-
-function safe_sql_string ($string) {
-	if (get_magic_quotes_gpc () == 0) 
-		$string = mysql_escape_string ($string);
-	return $string;
-}
-
 /**
  * enterprise functions
  */
diff --git a/pandora_console/include/functions_db.php b/pandora_console/include/functions_db.php
index 400b5d511c..9cf0ff53b1 100644
--- a/pandora_console/include/functions_db.php
+++ b/pandora_console/include/functions_db.php
@@ -192,8 +192,7 @@ function give_disabled_group ($id_group) {
 /**
  * Get all the agents within a group(s).
  *
- * @param id_group Group id or a comma delimited list of id_groups or an array
- * of ID's
+ * @param id_group Group id or an array of ID's
  * 
  * @param disabled Add disabled agents to agents. Default: False.
  * 
@@ -202,17 +201,15 @@ function give_disabled_group ($id_group) {
  * @return An array with all agents in the group or an empty array
  */
 function get_group_agents ($id_group, $disabled = false, $case = "lower") {
-	$id_group = safe_int ($id_group, 1);
+	$id_group = (array) safe_int ($id_group, 1);
 	
-	if (is_array ($id_group)) {
-		//If id_group is an array, then 
-		if (in_array (1, $id_group)) {
-			//If All is included in the group list, just select All
-			$id_group = 1;
-		} else {
-			//If All is not included, select what we need
-			$id_group = implode (",", $id_group);
-		}
+	//If id_group is an array, then 
+	if (in_array (1, $id_group)) {
+		//If All is included in the group list, just select All
+		$id_group = 1;
+	} else {
+		//If All is not included, select what we need
+		$id_group = implode (",", $id_group);
 	}
 	
 	/* 'All' group must return all agents */
@@ -808,7 +805,7 @@ function get_server_name ($id_server) {
 }
 
 /** 
- * Get the module type name.
+ * Get the module type name (type = generic_data, remote_snmp, ...)
  * 
  * @param id_type Type id
  * 
@@ -828,9 +825,9 @@ function dame_id_grupo ($id_agent) {
 /** 
  * Get the number of pandora data in the database.
  * 
- * @param id_agent Agent id or 0 for all
+ * @param (int) $id_agent Agent id or 0 for all
  *
- * @return 
+ * @return (int) The number of data in the database
  */
 function dame_numero_datos ($id_agent = 0) {
 	if ($id_agent < 1) {
@@ -950,12 +947,12 @@ function existe ($id_user) {
  *
  * If the module interval is not set, the agent interval is returned
  * 
- * @param id_agent_module Id agent module to get the interval value.
+ * @param (int) $id_agent_module Id agent module to get the interval value.
  * 
- * @return 
+ * @return (int) Module interval or agent interval if no module interval
  */
 function get_module_interval ($id_agent_module) {
-	$interval = (int) get_db_value ('module_interval', 'tagente_modulo', 'id_agente_modulo', $id_agent_module);
+	$interval = (int) get_db_value ('module_interval', 'tagente_modulo', 'id_agente_modulo', (int) $id_agent_module);
 	if ($interval > 0)
 		return $interval;
 		
@@ -1530,7 +1527,7 @@ function get_db_all_rows_field_filter ($table, $field, $condition, $order_field
  *
  * @return A matrix with all the values in the table that matches the condition in the field
  */
-function get_db_all_fields_in_table ($table, $field, $condition = '', $order_field = '') {
+function get_db_all_fields_in_table ($table, $field = '', $condition = '', $order_field = '') {
 	$sql = sprintf ("SELECT * FROM `%s`", $table);
 	if ($condition != '') {
 		$sql .= sprintf (" WHERE `%s` = '%s'", $field, $condition);
@@ -1861,11 +1858,11 @@ function check_server_status () {
 }
 
 /** 
+ * DEPRECATED or MOVE: Will show a small HTML table with some compound alert information
  * 
+ * @param (int) id_combined_alert 
  * 
- * @param id_combined_alert 
- * 
- * @return 
+ * @return (string) HTML block
  */
 function show_alert_row_mini ($id_combined_alert) {
 	$color=1;
@@ -2183,9 +2180,9 @@ function get_server_info ($id_server = -1) {
 /**
  * This function will return the number of all agent modules in the database
  *
- * @param integer or array of integers with agent(s). Leave empty to select everything
+ * @param (int) or (array) of integers with agent(s). Leave empty to select everything
  *
- * @return integer with the number of agent modules
+ * @return (int) The number of agent modules
  *
  **/
 function get_agent_modules_count ($id_agent = 0) {
@@ -2235,19 +2232,17 @@ function get_group_name ($id_group) {
 }
 
 /**
- *   @function	 process_alerts_validate
- *   @abstract   Validates an alert id or an array of alert id's
- *   @param      $alert_id Array of or single id
- *   @result     True if it was successful, false if it doesn't
+ * Validates an alert id or an array of alert id's
+ *
+ * @param $alert_id (array) Array of or a single id
+ *
+ * @return (bool) True if it was successful, false if it doesn't
  **/
 function process_alerts_validate ($id_alert) {
 	global $config;
 	require_once ("include/functions_events.php");
 	
-	if (!is_array ($id_alert)) {
-		$id_alert = (array) $id_alert;
-	}
-	$id_alert = safe_int ($id_alert, 1);
+	$id_alert = (array) safe_int ($id_alert, 1);
 	
 	if (empty ($id_alert)) {
 		return false;
@@ -2280,4 +2275,35 @@ function process_alerts_validate ($id_alert) {
 	}
 	return true;
 }
+
+/**
+ * Gets all module groups. (General, Networking, System). Module groups are merely for sorting frontend
+ *
+ * @return (array) All module groups
+**/
+function get_modulegroups () {
+	$result = get_db_all_fields_in_table ("tmodule_group");
+	$return = array ();
+	
+	if (empty ($result)) {
+		return $return;
+	}
+	
+	foreach ($result as $modulegroup) {
+		$return[$modulegroup["id_mg"]] = $modulegroup["name"];
+	}
+	
+	return $return;
+}
+
+/**
+ * Gets a modulegroup name based on the id
+ *
+ * @param (int) $modulegroup_id The id of the modulegroup
+ *
+ * @return (string) The modulegroup name
+**/	
+function get_modulegroup_name ($modulegroup_id) {
+	return (string) get_db_value ('name', 'tmodule_group', 'id_mg', (int) $modulegroup_id);
+}
 ?>
\ No newline at end of file
diff --git a/pandora_console/include/functions_exportserver.php b/pandora_console/include/functions_exportserver.php
new file mode 100644
index 0000000000..f08be737d0
--- /dev/null
+++ b/pandora_console/include/functions_exportserver.php
@@ -0,0 +1,68 @@
+<?php
+// Pandora FMS - the Flexible Monitoring System
+// ============================================
+// Copyright (c) 2009 Evi Vanoost, <vanooste@rcbi.rochester.edu>
+// Please see http://pandora.sourceforge.net for full contribution list
+//
+// This file is part of Pandora FMS.
+//
+// Pandora FMS is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 2 of the License, or
+// (at your option) any later version.
+//
+// Pandora FMS is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Pandora FMS. If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * Gets all export servers out of the database
+ *   
+ * @param (bool) $active Whether or not to exclude inactive servers (defaults to 1 => no inactive servers)
+ *
+ * @return (array) An array of server information (similar to server_info) but without the other servers
+**/
+function get_exportservers ($active = 1) {
+	$query = "SELECT * FROM tserver WHERE export_server = 1";
+	$return = array ();
+		
+	if ($active == 1) {
+		$servers = get_db_all_rows_sql ($query.' AND status = 1');
+	} else {
+		$servers = get_db_all_rows_sql ($query);
+	}
+	
+	if (empty ($servers)) {
+		return $return;
+	}
+	
+	foreach ($servers as $server) {
+		$return[$server["id_server"]] = $server;
+	}
+	
+	return $return;
+}
+
+/**
+ * Gets a specific piece of info on the export servers table (defaults to name)
+ *
+ * @param (bool) $active (bool) Whether or not to exclude inactive servers (defaults to 1 => no inactive servers)
+ * @param (string) $row What row to select from the server info table
+ *
+ * @return (array) An array of server information (similar to get_exportservers) but without the extra data
+ **/
+function get_exportservers_info ($active = 1, $row = "name") {
+	$exportservers = get_exportservers ();
+	$return = array ();
+	
+	foreach ($exportservers as $server_id => $server_info) {
+		$return[$server_id] = $server_info[$row];
+	}
+	
+	return $return;
+}
+?>
\ No newline at end of file