Skip to content
Snippets Groups Projects
Select Git revision
  • d2f37ebe4d4d87d1a8af30aa624f6134150e2360
  • master default protected
  • devel
  • hruska-feature-clients-api
  • malostik-#5066-deduplicate-idea-ids
  • warden-postgresql-port
  • hruska-feature-#6799-filter-keys
  • hruska-feature-5066-duplicateIdeaID
  • warden-client-3.0-beta3
  • warden-server-3.0-beta3
  • warden-client-2.2-final
  • warden-server-2.2-final
  • warden-client-3.0-beta2
  • warden-server-3.0-beta2
  • warden-client-2.2
  • warden-server-2.2-patch3
  • warden-client-3.0-beta1
  • warden-server-3.0-beta1
  • warden-server-2.2-patch1
  • warden-client-3.0-beta0
  • warden-server-3.0-beta0
  • warden-server-2.2
  • warden-server-2.1-patch1
  • warden-client-2.1
  • warden-server-2.1
  • warden-server-2.1-beta6
  • warden-server-2.1-beta5
  • warden-server-2.1-beta4
28 results

graph_TargetportActivity.php

Blame
  • graph_TargetportActivity.php 1.65 KiB
    <?
    include("db.php");
    
    
    if(!isset($_GET['per'])){$_GET['per']="hour";}
    switch( $_GET['per']) {
            case "hour":
    		$agg = 1;
                    break;
            case "day":
    		$agg = 24;
                    break;
            case "month":
    		$agg = 24*30; // -30.5 ?
                     break;
    }
    
    #sqli todo
    #selector
    
    $query_cols = "target_port";
    if(IsSet($_GET['port']) && is_numeric($_GET['port'])){
    	$where = "target_port=".$_GET['port'];
    } else {
    	die("pars");
    }
    
    
    
    #seznam sloupcu ve vysledku, todo dyn, coz je ovsem seznam sledovanych velicin
    $cols=array();
    $i=0;
    $cols["events"]=$i++;
    $cols["uniqueSources"]=$i++;
    $cols["uniqueSensors"]=$i++;
    $cols["totalScale"]=$i++;
    $count_cols=count($cols);
    
    
    #select data
    $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, 
    count(*) as events, 
    count(distinct source) as uniqueSources, 
    count(distinct concat_ws('-',hostname,service,type)) as uniqueSensors,
    sum(attack_scale) as totalScale 
    FROM events WHERE $where GROUP BY $query_cols, t;";
    
    #var_dump($q);
    $res = mysql_query($q, $db);
    while ($tmp = mysql_fetch_assoc($res)) { 
    	#var_dump($tmp);
            $d=array_fill(0, $count_cols, 0);
            $d[ $cols[ "events" ] ] = (int)$tmp["events"];
            $d[ $cols[ "uniqueSources" ] ] = (int)$tmp["uniqueSources"];
            $d[ $cols[ "uniqueSensors" ] ] = (int)$tmp["uniqueSensors"];
            $d[ $cols[ "totalScale" ] ] = (int)$tmp["totalScale"];
            array_unshift($d, (int)$tmp["t"]);
    	array_push($data, $d);
    }
    
    
    #print json_encode($d);
    print json_encode(array("cols"=>array_keys($cols), "data"=>$data));
    
    ?>