From ab4685087545374f8733c65298f908b51d6e3556 Mon Sep 17 00:00:00 2001
From: root <root@orion.zcu.cz>
Date: Thu, 6 Sep 2012 22:34:26 +0200
Subject: [PATCH] ui bugfix: do generovanych grafu muze prijit velke mnozstvi
 dat, pri defaultnich zobrazenich oriznu na 1000 radek. ostatni maji zatim
 alertuji pres js

---
 .../wardenweb/graph_HostnameServiceTypeActivity.php      | 9 +++++++--
 .../wardenweb/graph_HostnameServiceTypeActivityScale.php | 9 +++++++--
 .../contrib/wardenweb/graph_TypeActivity.php             | 5 +++--
 .../contrib/wardenweb/graph_TypeActivityScale.php        | 5 +++--
 4 files changed, 20 insertions(+), 8 deletions(-)

diff --git a/src/warden-server/contrib/wardenweb/graph_HostnameServiceTypeActivity.php b/src/warden-server/contrib/wardenweb/graph_HostnameServiceTypeActivity.php
index d9686f5..c17600e 100644
--- a/src/warden-server/contrib/wardenweb/graph_HostnameServiceTypeActivity.php
+++ b/src/warden-server/contrib/wardenweb/graph_HostnameServiceTypeActivity.php
@@ -16,9 +16,14 @@ switch( $_GET['per']) {
 }
 
 #sqli todo
+
+#limits
+$limit="";
+
 #selector
 if(!IsSet($_GET['where'])) {
-	$where="detected>from_unixtime(0)";
+	$where="1=1";
+	$limit="order by detected desc limit 1000";
 } else {
 	$where = base64_decode($_GET['where']);
 }
@@ -51,7 +56,7 @@ $count_cols=count($cols);
 $data=array();
 #casova posloupnost
 # premapuju podle staticky alokovanych sloupcu, posilam to rovnou do grafu
-$q = "SELECT unix_timestamp(detected)-(unix_timestamp(detected)%(3600*$agg)) as t, concat_ws('-',$query_cols) as col, count(*) as count FROM events WHERE $where GROUP BY $query_cols, t;";
+$q = "SELECT unix_timestamp(detected)-(unix_timestamp(detected)%(3600*$agg)) as t, concat_ws('-',$query_cols) as col, count(*) as count FROM events WHERE $where GROUP BY $query_cols, t $limit";
 #var_dump($q);
 $res = mysql_query($q, $db);
 while ($tmp = mysql_fetch_assoc($res)) { 
diff --git a/src/warden-server/contrib/wardenweb/graph_HostnameServiceTypeActivityScale.php b/src/warden-server/contrib/wardenweb/graph_HostnameServiceTypeActivityScale.php
index b89d6e2..1b3ad51 100644
--- a/src/warden-server/contrib/wardenweb/graph_HostnameServiceTypeActivityScale.php
+++ b/src/warden-server/contrib/wardenweb/graph_HostnameServiceTypeActivityScale.php
@@ -16,9 +16,14 @@ switch( $_GET['per']) {
 }
 
 #sqli todo
+
+#limits
+$limit="";
+
 #selector
 if(!IsSet($_GET['where'])) {
-	$where="detected>from_unixtime(0)";
+	$where="1=1";
+	$limit="order by detected desc limit 1000";
 } else {
 	$where = base64_decode($_GET['where']);
 }
@@ -51,7 +56,7 @@ $count_cols=count($cols);
 $data=array();
 #casova posloupnost
 # premapuju podle staticky alokovanych sloupcu, posilam to rovnou do grafu
-$q = "SELECT unix_timestamp(detected)-(unix_timestamp(detected)%(3600*$agg)) as t, concat_ws('-',$query_cols) as col, sum(attack_scale) as totalScale FROM events WHERE $where GROUP BY $query_cols, t;";
+$q = "SELECT unix_timestamp(detected)-(unix_timestamp(detected)%(3600*$agg)) as t, concat_ws('-',$query_cols) as col, sum(attack_scale) as totalScale FROM events WHERE $where GROUP BY $query_cols, t $limit";
 #var_dump($q);
 $res = mysql_query($q, $db);
 while ($tmp = mysql_fetch_assoc($res)) { 
diff --git a/src/warden-server/contrib/wardenweb/graph_TypeActivity.php b/src/warden-server/contrib/wardenweb/graph_TypeActivity.php
index 5008777..6be4a4d 100644
--- a/src/warden-server/contrib/wardenweb/graph_TypeActivity.php
+++ b/src/warden-server/contrib/wardenweb/graph_TypeActivity.php
@@ -17,7 +17,8 @@ switch( $_GET['per']) {
 
 #sqli todo
 #selector
-$where="detected>from_unixtime(0)";
+$where="1=1";
+$limit="order by detected desc limit 1004";
 $query_cols = "type";
 
 
@@ -46,7 +47,7 @@ $count_cols=count($cols);
 $data=array();
 #casova posloupnost
 # premapuju podle staticky alokovanych sloupcu, posilam to rovnou do grafu
-$q = "SELECT unix_timestamp(detected)-(unix_timestamp(detected)%(3600*$agg)) as t, concat_ws('-',$query_cols) as col, count(*) as count FROM events WHERE $where GROUP BY $query_cols, t;";
+$q = "SELECT unix_timestamp(detected)-(unix_timestamp(detected)%(3600*$agg)) as t, concat_ws('-',$query_cols) as col, count(*) as count FROM events WHERE $where GROUP BY $query_cols, t $limit";
 #var_dump($q);
 $res = mysql_query($q, $db);
 while ($tmp = mysql_fetch_assoc($res)) { 
diff --git a/src/warden-server/contrib/wardenweb/graph_TypeActivityScale.php b/src/warden-server/contrib/wardenweb/graph_TypeActivityScale.php
index c189c0f..5f627a0 100644
--- a/src/warden-server/contrib/wardenweb/graph_TypeActivityScale.php
+++ b/src/warden-server/contrib/wardenweb/graph_TypeActivityScale.php
@@ -17,7 +17,8 @@ switch( $_GET['per']) {
 
 #sqli todo
 #selector
-$where="detected>from_unixtime(0)";
+$where="1=1";
+$limit="order by detected desc limit 1003";
 $query_cols = "type";
 
 
@@ -46,7 +47,7 @@ $count_cols=count($cols);
 $data=array();
 #casova posloupnost
 # premapuju podle staticky alokovanych sloupcu, posilam to rovnou do grafu
-$q = "SELECT unix_timestamp(detected)-(unix_timestamp(detected)%(3600*$agg)) as t, concat_ws('-',$query_cols) as col, sum(attack_scale) as totalScale FROM events WHERE $where GROUP BY $query_cols, t;";
+$q = "SELECT unix_timestamp(detected)-(unix_timestamp(detected)%(3600*$agg)) as t, concat_ws('-',$query_cols) as col, sum(attack_scale) as totalScale FROM events WHERE $where GROUP BY $query_cols, t $limit";
 #var_dump($q);
 $res = mysql_query($q, $db);
 while ($tmp = mysql_fetch_assoc($res)) { 
-- 
GitLab