2011-03-09 Miguel de Dios <miguel.dedios@artica.es>

* install.php, operation/incidents/incident.php,
	operation/agentes/status_monitor.php, operation/agentes/datos_agente.php,
	operation/servers/view_server.php, operation/snmpconsole/snmp_view.php,
	operation/events/events_rss.php, operation/events/events_list.php,
	operation/events/events_marquee.php, operation/search_users.php,
	mobile/operation/agents/monitor_status.php,
	mobile/operation/agents/view_agents.php,
	mobile/operation/agents/view_alerts.php, mobile/operation/events/events.php,
	mobile/include/functions_web.php, godmode/admin_access_logs.php,
	godmode/agentes/modificar_agente.php, godmode/alerts/alert_actions.php,
	godmode/reporting/reporting_builder.list_items.php: changed and addded in
	the source, the SQL queries for the "LIMIT x, x" to "LIMIT x OFFSET x", that
	it is standard for PostgreSQL.



git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@4080 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
mdtrooper 2011-03-09 17:55:37 +00:00
parent 3356b90afd
commit 2b23573f9a
20 changed files with 275 additions and 111 deletions

View File

@ -1,3 +1,19 @@
2011-03-09 Miguel de Dios <miguel.dedios@artica.es>
* install.php, operation/incidents/incident.php,
operation/agentes/status_monitor.php, operation/agentes/datos_agente.php,
operation/servers/view_server.php, operation/snmpconsole/snmp_view.php,
operation/events/events_rss.php, operation/events/events_list.php,
operation/events/events_marquee.php, operation/search_users.php,
mobile/operation/agents/monitor_status.php,
mobile/operation/agents/view_agents.php,
mobile/operation/agents/view_alerts.php, mobile/operation/events/events.php,
mobile/include/functions_web.php, godmode/admin_access_logs.php,
godmode/agentes/modificar_agente.php, godmode/alerts/alert_actions.php,
godmode/reporting/reporting_builder.list_items.php: changed and addded in
the source, the SQL queries for the "LIMIT x, x" to "LIMIT x OFFSET x", that
it is standard for PostgreSQL.
2011-03-09 Miguel de Dios <miguel.dedios@artica.es>
* include/functions_reporting.php, include/functions.php,

View File

@ -119,7 +119,14 @@ $url = "index.php?sec=godmode&sec2=godmode/admin_access_logs&tipo_log=".$tipo_lo
pagination ($count, $url);
$sql = sprintf ("SELECT * FROM tsesion %s ORDER BY fecha DESC LIMIT %d, %d", $filter, $offset, $config["block_size"]);
switch ($config["dbtype"]) {
case "mysql":
$sql = sprintf ("SELECT * FROM tsesion %s ORDER BY fecha DESC LIMIT %d, %d", $filter, $offset, $config["block_size"]);
break;
case "postgresql":
$sql = sprintf ("SELECT * FROM tsesion %s ORDER BY fecha DESC LIMIT %d OFFSET %d", $filter, $config["block_size"], $offset);
break;
}
$result = get_db_all_rows_sql ($sql);
if (empty ($result)) {

View File

@ -182,20 +182,45 @@ if ($ag_group > 0) {
$ag_group, $search_sql);
$total_agents = get_db_sql ($sql);
$sql = sprintf ('SELECT *
FROM tagente
WHERE id_grupo = %d
%s
ORDER BY %s %s LIMIT %d, %d',
$ag_group, $search_sql, $order['field'], $order['order'], $offset, $config["block_size"]);
} else {
switch ($config["dbtype"]) {
case "mysql":
$sql = sprintf ('SELECT *
FROM tagente
WHERE id_grupo = %d
%s
ORDER BY %s %s LIMIT %d, %d',
$ag_group, $search_sql, $order['field'], $order['order'], $offset, $config["block_size"]);
break;
case "postgresql":
$sql = sprintf ('SELECT *
FROM tagente
WHERE id_grupo = %d
%s
ORDER BY %s %s LIMIT %d OFFSET %d',
$ag_group, $search_sql, $order['field'], $order['order'], $config["block_size"], $offset);
break;
}
}
else {
// Admin user get ANY group, even if they doesnt exist
if (check_acl ($config['id_user'], 0, "PM")){
$sql = sprintf ('SELECT COUNT(*) FROM tagente WHERE 1=1 %s', $search_sql);
$total_agents = get_db_sql ($sql);
$sql = sprintf ('SELECT * FROM tagente WHERE 1=1 %s ORDER BY %s %s LIMIT %d, %d', $search_sql, $order['field'], $order['order'], $offset, $config["block_size"]);
} else {
switch ($config["dbtype"]) {
case "mysql":
$sql = sprintf ('SELECT *
FROM tagente WHERE 1=1 %s
ORDER BY %s %s LIMIT %d, %d', $search_sql, $order['field'], $order['order'], $offset, $config["block_size"]);
break;
case "postgresql":
$sql = sprintf ('SELECT *
FROM tagente WHERE 1=1 %s
ORDER BY %s %s LIMIT %d OFFSET %d', $search_sql, $order['field'], $order['order'], $config["block_size"], $offset);
break;
}
}
else {
$sql = sprintf ('SELECT COUNT(*)
FROM tagente
@ -205,13 +230,26 @@ if ($ag_group > 0) {
$search_sql);
$total_agents = get_db_sql ($sql);
$sql = sprintf ('SELECT *
FROM tagente
WHERE id_grupo IN (%s)
%s
ORDER BY %s %s LIMIT %d, %d',
implode (',', array_keys (get_user_groups ())),
$search_sql, $order['field'], $order['order'], $offset, $config["block_size"]);
switch ($config["dbtype"]) {
case "mysql":
$sql = sprintf ('SELECT *
FROM tagente
WHERE id_grupo IN (%s)
%s
ORDER BY %s %s LIMIT %d, %d',
implode (',', array_keys (get_user_groups ())),
$search_sql, $order['field'], $order['order'], $offset, $config["block_size"]);
break;
case "postgresql":
$sql = sprintf ('SELECT *
FROM tagente
WHERE id_grupo IN (%s)
%s
ORDER BY %s %s LIMIT %d OFFSET %d',
implode (',', array_keys (get_user_groups ())),
$search_sql, $order['field'], $order['order'], $config["block_size"], $offset);
break;
}
}
}

View File

@ -209,7 +209,8 @@ if ($delete_action) {
// Header
print_page_header (__('Alerts').' &raquo; '.__('Alert actions'), "images/god2.png", false, "", true);
// If user tries to delete an action of others groups
}else{
}
else{
$own_info = get_user_info ($config['id_user']);
if ($own_info['is_admin'] || check_acl ($config['id_user'], 0, "PM"))
$own_groups = array_keys(get_user_groups($config['id_user'], "LM"));
@ -227,7 +228,8 @@ if ($delete_action) {
exit;
}
}
}else
}
else
// Header
print_page_header (__('Alerts').' &raquo; '.__('Alert actions'), "images/god2.png", false, "", true);

View File

@ -133,7 +133,7 @@ switch ($config["dbtype"]) {
FROM treport_content
WHERE ' . $where . ' AND id_report = ' . $idReport . '
ORDER BY "order"
LIMIT ' . $offset . ', ' . $config["block_size"]);
LIMIT ' . $config["block_size"] . ' OFFSET ' . $offset);
break;
}
$countItems = get_db_sql('SELECT COUNT(id_rc) FROM treport_content WHERE ' . $where . ' AND id_report = ' . $idReport);

View File

@ -312,16 +312,15 @@ function install_step1_licence() {
if (!file_exists("COPYING")){
echo "<div class='warn'><b>Licence file 'COPYING' is not present in your distribution. This means you have some 'partial' Pandora FMS distribution. We cannot continue without accepting the licence file.</b>";
echo "</div>";
} else {
}
else {
echo "<form method=post action='install.php?step=2'>";
echo "<textarea name='gpl2' cols=50 rows=17>";
echo file_get_contents ("COPYING");
echo "</textarea>";
echo "<p>";
echo "<input type=submit value='Yes, I accept licence terms'>";
}
}
echo "</div>";
print_logo_status (2, 5);

View File

@ -71,7 +71,8 @@ function footer() {
if (isset($_SERVER['REQUEST_TIME'])) {
$time = $_SERVER['REQUEST_TIME'];
} else {
}
else {
$time = get_system_time ();
}
?>

View File

@ -144,7 +144,14 @@ class MonitorStatus {
$total = get_db_value_sql('SELECT COUNT(*) ' . $sql);
$rows = get_db_all_rows_sql($selectSQL . $sql . ' LIMIT ' . $this->offset . ', ' . $this->system->getPageSize());
switch ($config["dbtype"]) {
case "mysql":
$rows = get_db_all_rows_sql($selectSQL . $sql . ' LIMIT ' . $this->offset . ', ' . $this->system->getPageSize());
break;
case "postgresql":
$rows = get_db_all_rows_sql($selectSQL . $sql . ' LIMIT ' . $this->system->getPageSize() . ' OFFSET ' . $this->offset);
break;
}
if ($rows === false) $rows = array();

View File

@ -351,24 +351,6 @@ class ViewAgent {
$template = safe_output(get_alert_template ($alert['id_alert_template']));
$data[] = printTruncateText(safe_output($template['name']), 20, true, true);
// $actions = get_alert_agent_module_actions ($alert['id'], false, false);
// if (!empty($actions)){
// $actionText = '<ul class="action_list">';
// foreach ($actions as $action) {
// $actionText .= '<li><div><span class="action_name">' . $action['name'];
// if ($action["fires_min"] != $action["fires_max"]){
// $actionText .= " (".$action["fires_min"] . " / ". $action["fires_max"] . ")";
// }
// $actionText .= '</li></span><br></div>';
// }
// $actionText .= '</div></ul>';
// }
// else {
// if ($actionDefault != "")
// $actionText = get_db_sql ("SELECT name FROM talert_actions WHERE id = $actionDefault"). " <i>(".__("Default") . ")</i>";
// }
//
// $data[] = $actionText;
$data[] = print_timestamp ($alert["last_fired"], true, array('units' => 'tiny'));
$status = STATUS_ALERT_NOT_FIRED;
@ -377,10 +359,12 @@ class ViewAgent {
if ($alert["times_fired"] > 0) {
$status = STATUS_ALERT_FIRED;
$title = __('Alert fired').' '.$alert["times_fired"].' '.__('times');
} elseif ($alert["disabled"] > 0) {
}
elseif ($alert["disabled"] > 0) {
$status = STATUS_ALERT_DISABLED;
$title = __('Alert disabled');
} else {
}
else {
$status = STATUS_ALERT_NOT_FIRED;
$title = __('Alert not fired');
}
@ -391,17 +375,6 @@ class ViewAgent {
$table->data[] = $data;
}
print_table($table);
// echo "<h3 class='title_h3'>" . __('Alerts compound') . "</h3>";
//
// $alertsCombined = get_agent_alerts_compound(array($this->idAgent));
//
// $table->data = array();
// foreach ($alertsCombined as $alert) {
// $data = array();
//
// $table->data[] = $data;
// }
}
}
@ -415,7 +388,7 @@ class viewGraph {
$this->system = $system;
$this->idAgentModule = $idAgentModule;
$this->agentModule = get_db_row_filter('tagente_modulo', array('id_agente_modulo' => $this->idAgentModule));
//$this->system->debug($this->agentModule);
$this->period = $this->system->getRequest('period', 86400);
$this->offset = $this->system->getRequest("offset", 0);
@ -493,7 +466,14 @@ class viewGraph {
$count = get_db_value_sql($sql_count);
$sql = 'SELECT * ' . $sql_body . ' LIMIT ' . $this->offset . ',' . $this->system->getPageSize();
switch ($config["dbtype"]) {
case "mysql":
$sql = 'SELECT * ' . $sql_body . ' LIMIT ' . $this->offset . ',' . $this->system->getPageSize();
break;
case "postgresql":
$sql = 'SELECT * ' . $sql_body . ' LIMIT ' . $this->system->getPageSize() . ' OFFSET ' . $this->offset;
break;
}
$result = get_db_all_rows_sql ($sql);

View File

@ -69,10 +69,12 @@ class ViewAlerts {
if ($alert["times_fired"] > 0) {
$status = STATUS_ALERT_FIRED;
$title = __('Alert fired').' '.$alert["times_fired"].' '.__('times');
} elseif ($alert["disabled"] > 0) {
}
elseif ($alert["disabled"] > 0) {
$status = STATUS_ALERT_DISABLED;
$title = __('Alert disabled');
} else {
}
else {
$status = STATUS_ALERT_NOT_FIRED;
$title = __('Alert not fired');
}

View File

@ -25,6 +25,7 @@ class EventsView {
function show() {
global $config;
$config['text_char_long'] = 12;
$offset = $this->system->getRequest("offset", 0);
@ -119,7 +120,14 @@ class EventsView {
$sql_count = str_replace('*', 'COUNT(*)', $sql);
$sql = $sql . sprintf(' LIMIT %d,%d', $offset, $this->system->getPageSize());
switch ($config["dbtype"]) {
case "mysql":
$sql = $sql . sprintf(' LIMIT %d,%d', $offset, $this->system->getPageSize());
break;
case "postgresql":
$sql = $sql . sprintf(' LIMIT %d OFFSET %d', $this->system->getPageSize(), $offset);
break;
}
$count = get_db_value_sql($sql_count);

View File

@ -98,7 +98,14 @@ $sql_count = "SELECT count(*) " . $sql_body;
$count = get_db_value_sql($sql_count);
$sql .= " LIMIT " . $offset . "," . $block_size;
switch ($config["dbtype"]) {
case "mysql":
$sql .= " LIMIT " . $offset . "," . $block_size;
break;
case "postgresql":
$sql .= " LIMIT " . $block_size . " OFFSET " . $offset;
break;
}
$result = get_db_all_rows_sql ($sql);
if ($result === false) {

View File

@ -216,20 +216,40 @@ $sql .= " ORDER BY tagente.id_grupo, tagente.nombre";
// Build final SQL sentences
$count = get_db_sql ("SELECT COUNT(tagente_modulo.id_agente_modulo)".$sql);
$sql = "SELECT tagente_modulo.id_agente_modulo,
tagente.intervalo AS agent_interval,
tagente.nombre AS agent_name,
tagente_modulo.nombre AS module_name,
tagente_modulo.id_agente_modulo,
tagente_modulo.history_data,
tagente_modulo.flag AS flag,
tagente.id_grupo AS id_group,
tagente.id_agente AS id_agent,
tagente_modulo.id_tipo_modulo AS module_type,
tagente_modulo.module_interval,
tagente_estado.datos,
tagente_estado.estado,
tagente_estado.utimestamp AS utimestamp".$sql." LIMIT ".$offset.",".$config["block_size"];
switch ($config["dbtype"]) {
case "mysql":
$sql = "SELECT tagente_modulo.id_agente_modulo,
tagente.intervalo AS agent_interval,
tagente.nombre AS agent_name,
tagente_modulo.nombre AS module_name,
tagente_modulo.id_agente_modulo,
tagente_modulo.history_data,
tagente_modulo.flag AS flag,
tagente.id_grupo AS id_group,
tagente.id_agente AS id_agent,
tagente_modulo.id_tipo_modulo AS module_type,
tagente_modulo.module_interval,
tagente_estado.datos,
tagente_estado.estado,
tagente_estado.utimestamp AS utimestamp".$sql." LIMIT ".$offset.",".$config["block_size"];
break;
case "postgresql":
$sql = "SELECT tagente_modulo.id_agente_modulo,
tagente.intervalo AS agent_interval,
tagente.nombre AS agent_name,
tagente_modulo.nombre AS module_name,
tagente_modulo.id_agente_modulo,
tagente_modulo.history_data,
tagente_modulo.flag AS flag,
tagente.id_grupo AS id_group,
tagente.id_agente AS id_agent,
tagente_modulo.id_tipo_modulo AS module_type,
tagente_modulo.module_interval,
tagente_estado.datos,
tagente_estado.estado,
tagente_estado.utimestamp AS utimestamp".$sql." LIMIT " . $config["block_size"] . " OFFSET " . $offset;
break;
}
$result = get_db_all_rows_sql ($sql);
if ($count > $config["block_size"]) {

View File

@ -244,16 +244,37 @@ echo '<div id="steps_clean">&nbsp;</div>';
echo '</div>';
if ($group_rep == 0) {
$sql = "SELECT *
FROM tevento
WHERE 1=1 ".$sql_post." ORDER BY utimestamp DESC LIMIT ".$offset.",".$pagination;
switch ($config["dbtype"]) {
case "mysql":
$sql = "SELECT *
FROM tevento
WHERE 1=1 ".$sql_post." ORDER BY utimestamp DESC LIMIT ".$offset.",".$pagination;
break;
case "postgresql":
$sql = "SELECT *
FROM tevento
WHERE 1=1 ".$sql_post." ORDER BY utimestamp DESC LIMIT ".$pagination." OFFSET ".$offset;
break;
}
}
else {
$sql = "SELECT *, COUNT(*) AS event_rep, MAX(utimestamp) AS timestamp_rep
FROM tevento
WHERE 1=1 ".$sql_post."
GROUP BY evento, id_agentmodule
ORDER BY timestamp_rep DESC LIMIT ".$offset.",".$pagination;
switch ($config["dbtype"]) {
case "mysql":
$sql = "SELECT *, COUNT(*) AS event_rep, MAX(utimestamp) AS timestamp_rep
FROM tevento
WHERE 1=1 ".$sql_post."
GROUP BY evento, id_agentmodule
ORDER BY timestamp_rep DESC LIMIT ".$offset.",".$pagination;
break;
case "postgresql":
$sql = "SELECT *, COUNT(*) AS event_rep, MAX(utimestamp) AS timestamp_rep
FROM tevento
WHERE 1=1 ".$sql_post."
GROUP BY evento, id_agentmodule
ORDER BY timestamp_rep DESC LIMIT ".$pagination." OFFSET ".$offset;
break;
}
}
//Extract the events by filter (or not) from db

View File

@ -57,8 +57,14 @@ if (!check_acl ($config["id_user"], 0, "PM")) {
$sql_group_filter .= " AND id_grupo != 0";
}
$sql = "SELECT evento, timestamp, id_agente FROM tevento WHERE 1=1 $sql_group_filter ORDER BY utimestamp DESC LIMIT 0 , $MAX_MARQUEE_EVENTS";
switch ($config["dbtype"]) {
case "mysql":
$sql = "SELECT evento, timestamp, id_agente FROM tevento WHERE 1=1 $sql_group_filter ORDER BY utimestamp DESC LIMIT 0 , $MAX_MARQUEE_EVENTS";
break;
case "postgresql":
$sql = "SELECT evento, timestamp, id_agente FROM tevento WHERE 1=1 $sql_group_filter ORDER BY utimestamp DESC LIMIT $MAX_MARQUEE_EVENTS OFFSET 0";
break;
}
$result = get_db_all_rows_sql ($sql);
foreach ($result as $row) {

View File

@ -157,17 +157,34 @@ if ($id_event != -1)
if(!check_acl($user, 0, "PM"))
$sql_post .= " AND tevento.event_type <> 'system'";
$sql="SELECT tevento.id_evento AS event_id,
tevento.id_agente AS id_agent,
tevento.id_usuario AS validated_by,
tevento.id_grupo AS id_group,
tevento.estado AS validated,
tevento.evento AS event_descr,
tevento.utimestamp AS unix_timestamp,
tevento.event_type AS event_type
FROM tevento
WHERE 1 = 1" . $sql_post . "
ORDER BY utimestamp DESC LIMIT 0 , 30";
switch ($config["dbtype"]) {
case "mysql":
$sql="SELECT tevento.id_evento AS event_id,
tevento.id_agente AS id_agent,
tevento.id_usuario AS validated_by,
tevento.id_grupo AS id_group,
tevento.estado AS validated,
tevento.evento AS event_descr,
tevento.utimestamp AS unix_timestamp,
tevento.event_type AS event_type
FROM tevento
WHERE 1 = 1" . $sql_post . "
ORDER BY utimestamp DESC LIMIT 0 , 30";
break;
case "postgresql":
$sql="SELECT tevento.id_evento AS event_id,
tevento.id_agente AS id_agent,
tevento.id_usuario AS validated_by,
tevento.id_grupo AS id_group,
tevento.estado AS validated,
tevento.evento AS event_descr,
tevento.utimestamp AS unix_timestamp,
tevento.event_type AS event_type
FROM tevento
WHERE 1 = 1" . $sql_post . "
ORDER BY utimestamp DESC LIMIT 30 OFFSET 0";
break;
}
$result= get_db_all_rows_sql ($sql);

View File

@ -181,9 +181,18 @@ $groups = get_user_groups ($config["id_user"], "IR");
//Select incidencts where the user has access to ($groups from
//get_user_groups), array_keys for the id, implode to pass to SQL
$sql = "SELECT * FROM tincidencia
WHERE id_grupo IN (".implode (",",array_keys ($groups)).")" . $filter . "
ORDER BY actualizacion DESC LIMIT ".$offset.",".$config["block_size"];
switch ($config["dbtype"]) {
case "mysql":
$sql = "SELECT * FROM tincidencia
WHERE id_grupo IN (".implode (",",array_keys ($groups)).")" . $filter . "
ORDER BY actualizacion DESC LIMIT ".$offset.",".$config["block_size"];
break;
case "postgresql":
$sql = "SELECT * FROM tincidencia
WHERE id_grupo IN (".implode (",",array_keys ($groups)).")" . $filter . "
ORDER BY actualizacion DESC LIMIT ".$config["block_size"]." OFFSET ".$offset;
break;
}
$result = get_db_all_rows_sql ($sql);
if (empty ($result)) {

View File

@ -143,7 +143,8 @@ if ($searchUsers) {
if(!$users_id) {
$user_condition = "";
}else {
}
else {
// Condition with the visible agents
$user_condition = " AND id_user IN (\"".implode('","',$users_id)."\")";
}
@ -200,7 +201,8 @@ else {
$profileCell = print_image ("images/user_suit.png", true,
array ("alt" => __('Admin'),
"title" => __('Administrator'))).'&nbsp;';
} else {
}
else {
$profileCell = print_image ("images/user_green.png", true,
array ("alt" => __('User'),
"title" => __('Standard User'))).'&nbsp;';
@ -214,7 +216,8 @@ else {
$profileCell .= get_group_name ($row["id_grupo"]);
$profileCell .= "<br />";
}
} else {
}
else {
$profileCell .= __('The user doesn\'t have any assigned profile/group');
}
$profileCell .= "</span></a>";

View File

@ -65,7 +65,8 @@ foreach ($servers as $server) {
if ($server['status'] == 0) {
$data[1] = print_status_image (STATUS_SERVER_DOWN, '', true);
} else {
}
else {
$data[1] = print_status_image (STATUS_SERVER_OK, '', true);
}

View File

@ -116,7 +116,14 @@ if (isset ($_POST["updatebt"])) {
}
}
$sql = sprintf ("SELECT * FROM ttrap ORDER BY timestamp DESC LIMIT %d,%d",$offset,$pagination);
switch ($config["dbtype"]) {
case "mysql":
$sql = sprintf ("SELECT * FROM ttrap ORDER BY timestamp DESC LIMIT %d,%d",$offset,$pagination);
break;
case "postgresql":
$sql = sprintf ("SELECT * FROM ttrap ORDER BY timestamp DESC LIMIT %d OFFSET %d", $pagination, $offset);
break;
}
$traps = get_db_all_rows_sql ($sql);
// No traps
@ -150,7 +157,14 @@ foreach ($traps as $trap) {
}
//Make query to extract traps of DB.
$sql = "SELECT * FROM ttrap %s ORDER BY timestamp DESC LIMIT %d,%d";
switch ($config["dbtype"]) {
case "mysql":
$sql = "SELECT * FROM ttrap %s ORDER BY timestamp DESC LIMIT %d,%d";
break;
case "postgresql":
$sql = "SELECT * FROM ttrap %s ORDER BY timestamp DESC LIMIT %d OFFSET %d";
break;
}
$whereSubquery = 'WHERE 1=1';
if ($filter_agent != '') {
@ -214,8 +228,14 @@ if ($filter_severity != -1) {
if ($filter_status != -1)
$whereSubquery .= ' AND status = ' . $filter_status;
$sql = sprintf($sql, $whereSubquery, $offset, $pagination);
switch ($config["dbtype"]) {
case "mysql":
$sql = sprintf($sql, $whereSubquery, $offset, $pagination);
break;
case "postgresql":
$sql = sprintf($sql, $whereSubquery, $pagination, $offset);
break;
}
$traps = get_db_all_rows_sql($sql);