• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

NathanGibbs3 / BASE / 590

pending completion
590

push

travis-ci-com

NathanGibbs3
20230420 Fix CI build breakage. 2

2755 of 16977 relevant lines covered (16.23%)

21.61 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/base_stat_time.php
1
<?php
2
/*******************************************************************************
3
** Basic Analysis and Security Engine (BASE)
4
** Copyright (C) 2004 BASE Project Team
5
** Copyright (C) 2000 Carnegie Mellon University
6
**
7
** (see the file 'base_main.php' for license details)
8
**
9
** Project Leads: Kevin Johnson <kjohnson@secureideas.net>
10
**                Sean Muller <samwise_diver@users.sourceforge.net>
11
** Built upon work by Roman Danyliw <rdd@cert.org>, <roman@danyliw.com>
12
**
13
** Purpose: Input GET/POST variables
14
**   - submit:
15
**   - time:
16
**   - time_sep:
17
********************************************************************************
18
** Authors:
19
********************************************************************************
20
** Kevin Johnson <kjohnson@secureideas.net
21
**
22
********************************************************************************
23
*/
24

25
function StoreAlertNum($sql, $label, $time_sep, $i_year, $i_month, $i_day, $i_hour)
26
{  
27
  GLOBAL $db, $cnt, $label_lst, $value_lst, $value_POST_lst, $debug_mode;
28

29
  $label_lst [ $cnt ] = $label;
×
30

31
  if (sizeof($time_sep) == 0) {
×
32
      $time_sep = array(0 => '', 1 => '');
×
33
  }
34
  
35
  if ( $debug_mode > 0 )
×
36
     echo $sql."<BR>";
×
37

38
  $result = $db->baseExecute($sql);
×
39
  if ( $myrow = $result->baseFetchRow() )
×
40
  {
41
     $value_lst [ $cnt ] = $myrow[0];
×
42
     $result->baseFreeRows();
×
43

44
     $value_POST_lst[$cnt] = "base_qry_main.php?new=1&amp;submit="._QUERYDBP."&amp;num_result_rows=-1&amp;time_cnt=1".
×
45
                             "&amp;time%5B0%5D%5B0%5D=+&time%5B0%5D%5B1%5D=%3D";
46

47
     if ( $time_sep[0] == "hour" )
×
48
        $value_POST_lst[$cnt] = $value_POST_lst[$cnt].'&amp;time%5B0%5D%5B2%5D='.$i_month.
×
49
                                '&amp;time%5B0%5D%5B3%5D='.$i_day.
50
                                '&amp;time%5B0%5D%5B4%5D='.$i_year.
51
                                '&amp;time%5B0%5D%5B5%5D='.$i_hour;
52

53
     else if ( $time_sep[0] == "day" )
×
54
        $value_POST_lst[$cnt] = $value_POST_lst[$cnt].'&amp;time%5B0%5D%5B2%5D='.$i_month.
×
55
                                '&amp;time%5B0%5D%5B3%5D='.$i_day.
56
                                '&amp;time%5B0%5D%5B4%5D='.$i_year;
57

58
     else if ( $time_sep[0] == "month" )
×
59
        $value_POST_lst[$cnt] = $value_POST_lst[$cnt].'&amp;time%5B0%5D%5B2%5D='.$i_month.
×
60
                                '&amp;time%5B0%5D%5B4%5D='.$i_year;
61

62
     /* add no parentheses and no operator */
63
     $value_POST_lst[$cnt] = $value_POST_lst[$cnt].'&amp;time%5B0%5D%5B8%5D=+&amp;time%5B0%5D%5B9%5D=+';
×
64
 
65
                $cnt++;
×
66
        }else{
×
67
                $value_lst [ $cnt++ ] = 0;
×
68
        }
69
}
70

71
function PrintTimeProfile(){
72
        GLOBAL $cnt, $label_lst, $value_lst, $value_POST_lst;
73
        // Find max value.
74
        $max_cnt = $value_lst[0];
×
75
        for ( $i = 0; $i < $cnt; $i++ ){
×
76
                if ( $value_lst[$i] > $max_cnt ){
×
77
                        $max_cnt = $value_lst[$i];
×
78
                }
79
        }
80
        NLIO('<!-- TimeProfile -->', 2);
×
81
        $tmp ="<td class='plfieldhdr'";
×
82
        NLIO("<table border='1' width='100%'>", 2);
×
83
        NLIO('<tr>',3);
×
84
        NLIO($tmp." width='25%'>"._CHRTTIME.'</td>',4);
×
85
        NLIO($tmp." width='15%'># "._QSCOFALERTS.'</td>',4);
×
86
        NLIO($tmp.'>'._ALERT.'</td>',4);
×
87
        NLIO('</tr>',3);
×
88
        for ($i = 0; $i < $cnt; $i++ ){
×
89
                NLIO('<tr>',3);
×
90
                if ( $value_lst[$i] == 0 ){
×
91
                        $tmp = $label_lst[$i];
×
92
                        $idx = 4;
×
93
                }else{
×
94
                        $tmp = "<a href='$value_POST_lst[$i]'>$label_lst[$i]</a>";
×
95
                        $idx = 7;
×
96
                }
97
                NLIO("<td>$tmp</td>",4);
×
98
                NLIO("<td align='center'>$value_lst[$i]</td>",4);
×
99
                if ( $idx == 7 ){
×
100
                        NLIO('<td>',4);
×
101
                        NLIO("<table border='0' cellPadding='0' cellSpacing='0' width='100%'>",5);
×
102
                        NLIO('<tr>',6);
×
103
                }
104
                NLIO(HBarGraph($value_lst[$i],$max_cnt),$idx);
×
105
                if ( $idx == 7 ){
×
106
                        NLIO('</tr>',6);
×
107
                        NLIO('</table>',5);
×
108
                        NLIO('</td>',4);
×
109
                }
110
                NLIO('</tr>',3);
×
111
        }
112
        NLIO('</table>',2);
×
113
}
114

115
include ("base_conf.php");
×
116
include_once ("$BASE_path/includes/base_constants.inc.php");
×
117
include ("$BASE_path/includes/base_include.inc.php");
×
118
include_once ("$BASE_path/base_db_common.php");
×
119
include_once ("$BASE_path/base_stat_common.php");
×
120
include_once ("$BASE_path/base_qry_common.php");
×
121

122
AuthorizedRole(10000);
×
123
$et = new EventTiming($debug_time_mode);
×
124
$db = NewBASEDBConnection($DBlib_path, $DBtype); // Connect to DB.
×
125
$db->baseDBConnect(
×
126
        $db_connect_method, $alert_dbname, $alert_host, $alert_port, $alert_user,
127
        $alert_password
128
);
129
UpdateAlertCache($db);
×
130
$time_sep = ImportHTTPVar("time_sep", VAR_ALPHA);
×
131
$time = ImportHTTPVar("time", VAR_DIGIT);
×
132
$submit = ImportHTTPVar("submit", VAR_ALPHA | VAR_SPACE);
×
133
$cs = new CriteriaState("base_stat_alerts.php");
×
134
$cs->ReadState();
×
135
$page_title = _BSTTITLE;
×
136
PrintBASESubHeader($page_title, $page_title, $cs->GetBackLink(), 1);
×
137
$criteria_clauses = ProcessCriteria();
×
138
PrintCriteria('');
×
139
$from = " FROM acid_event ".$criteria_clauses[0];
×
140
$where = " WHERE ".$criteria_clauses[1];
×
141
UpdateAlertCache($db);
×
142
  if ( $submit == "" )
×
143
  {
144
   InitArray($time, $MAX_ROWS, TIME_CFCNT, "");
×
145
  }
146

147
  echo '<FORM ACTION="base_stat_time.php" METHOD="get">
×
148
        <TABLE WIDTH="100%" BORDER=0>
149
         <TR>
150
          <TD WIDTH="40%" CLASS="metatitle"><B><FONT COLOR="#FFFFFF">'._BSTTIMECRIT.'</FONT></B></TD>
151
          <TD></TD></TR>
152
        </TABLE>
153

154
        <TABLE WIDTH="100%" BORDER=2 class="query">
155
        <TR>
156
         <TD>';
157

158
  echo '<B>'._BSTPROFILEBY.' :</B> &nbsp;
×
159
        <INPUT NAME="time_sep[0]" TYPE="radio" VALUE="hour" '.@chk_check($time_sep[0],"hour").'> '._HOUR.'
×
160
        <INPUT NAME="time_sep[0]" TYPE="radio" VALUE="day" '.@chk_check($time_sep[0], "day").'> '._DAY.'
×
161
        <INPUT NAME="time_sep[0]" TYPE="radio" VALUE="month" '.@chk_check($time_sep[0], "month").'> '._MONTH.'
×
162
        <BR>';
163

164
  echo '<SELECT NAME="time_sep[1]">
×
165
         <OPTION VALUE=" "  '.@chk_select($time_sep[1], " ").'>'._DISPTIME.'
×
166
         <OPTION VALUE="on" '.@chk_select($time_sep[1], "on").'>'._TIMEON.'
×
167
         <OPTION VALUE="between"'.@chk_select($time_sep[1], "between").'>'._TIMEBETWEEN.'
×
168
        </SELECT>';
169
 
170
  for ( $i = 0; $i < 2; $i++ )
×
171
  {
172
      echo '<SELECT NAME="time['.$i.'][0]">
×
173
             <OPTION VALUE=" "  '.chk_select($time[$i][0]," " ).'>'._DISPMONTH.'
×
174
             <OPTION VALUE="01" '.chk_select($time[$i][0],"01").'>'._JANUARY.'
×
175
             <OPTION VALUE="02" '.chk_select($time[$i][0],"02").'>'._FEBRUARY.'
×
176
             <OPTION VALUE="03" '.chk_select($time[$i][0],"03").'>'._MARCH.'
×
177
             <OPTION VALUE="04" '.chk_select($time[$i][0],"04").'>'._APRIL.'
×
178
             <OPTION VALUE="05" '.chk_select($time[$i][0],"05").'>'._MAY.'
×
179
             <OPTION VALUE="06" '.chk_select($time[$i][0],"06").'>'._JUNE.'
×
180
             <OPTION VALUE="07" '.chk_select($time[$i][0],"07").'>'._JULY.'
×
181
             <OPTION VALUE="08" '.chk_select($time[$i][0],"08").'>'._AUGUST.'
×
182
             <OPTION VALUE="09" '.chk_select($time[$i][0],"09").'>'._SEPTEMBER.'
×
183
             <OPTION VALUE="10" '.chk_select($time[$i][0],"10").'>'._OCTOBER.'
×
184
             <OPTION VALUE="11" '.chk_select($time[$i][0],"11").'>'._NOVEMBER.'
×
185
             <OPTION VALUE="12" '.chk_select($time[$i][0],"12").'>'._DECEMBER.'
×
186
            </SELECT>';
187
      
188
      echo '<INPUT TYPE="text" NAME="time['.$i.'][1]" SIZE=2 VALUE="'.$time[$i][1].'"> &nbsp;'."\n";
×
189
      echo '<SELECT NAME="time['.$i.'][2]">'.
×
190
             dispYearOptions($time[$i][2])
×
191
            .'</SELECT>';
192

193
      if ( $i == 0 ) echo '&nbsp; -- &nbsp;&nbsp;';
×
194
  }
195

196
  echo '<INPUT TYPE="submit" NAME="submit" VALUE="'._PROFILEALERT.'">
×
197
        </TD></TR></TABLE>
198
        </FORM>
199

200
        <P><HR>';
201

202
  if ( $submit != "" && @$time_sep[0] == "" )
×
203
     echo _BSTERRPROFILECRIT;     
×
204
  else if ( $submit != "" && $time_sep[1] == " " )
×
205
     echo _BSTERRTIMETYPE;
×
206

207
  else if ( $submit != "" && $time_sep[0] != "" && $time_sep[1] == "on" &&
×
208
            $time[0][2] == " " )
×
209
     echo _BSTERRNOYEAR;
×
210

211
  else if ( $submit != "" && $time_sep[0] != "" && $time_sep[1] == "between" &&
×
212
            ($time[1][2] == " " || $time[0][2] == " ") )
×
213
     echo _BSTERRNOYEAR;
×
214

215
  else if ( $submit != "" && $time_sep[0] != "" && $time_sep[1] == "between" &&
×
216
            ($time[1][0] == " " || $time[0][0] == " ") )
×
217
     echo _BSTERRNOMONTH; 
×
218
 
219
  else if ( $submit != "" && ($time_sep[0] != "") 
×
220
            && $time_sep[1] == "between" && ($time[1][1] == "" || $time[0][1] == "") )
×
221
     echo _BSTERRNODAY;
×
222

223
  else if ($submit != "")
×
224
  {
225

226
  /* Dump the results of the above specified query */
227
           
228
  $year_start = $year_end = NULL;
×
229
  $month_start = $month_end = NULL;
×
230
  $day_start = $day_end = NULL;
×
231
  $hour_start = $hour_end = NULL;
×
232

233
  if ( $time_sep[1] == "between" )
×
234
  {
235
     if ($time_sep[0] == "hour")       
×
236
     { 
237
        $year_start = $time[0][2];  $year_end = $time[1][2];
×
238
        $month_start = $time[0][0]; $month_end = $time[1][0];
×
239
        $day_start = $time[0][1]; $day_end = $time[1][1];
×
240
        $hour_start = 0; $hour_end = 23; 
×
241
     }
242
     else if ($time_sep[0] == "day")          
×
243
     { 
244
        $year_start = $time[0][2];  $year_end = $time[1][2];
×
245
        $month_start = $time[0][0]; $month_end = $time[1][0];
×
246
        $day_start = $time[0][1]; $day_end = $time[1][1];
×
247
        $hour_start = -1; 
×
248
     }
249
     else if ($time_sep[0] == "month")           
×
250
     { 
251
        $year_start = $time[0][2];  $year_end = $time[1][2];
×
252
        $month_start = $time[0][0]; $month_end = $time[1][0];
×
253
        $day_start = -1;
×
254
        $hour_start = -1; 
×
255
     }
256
  }
257
  else if ( $time_sep[1] == "on" )
×
258
  {
259
     if ($time_sep[0] == "hour")       
×
260
     { 
261
        $year_start = $time[0][2];  $year_end = $time[0][2];
×
262
        if ( $time[0][0] != " " )
×
263
        {   $month_start = $time[0][0]; $month_end = $time[0][0];  }
×
264
        else
×
265
        {   $month_start = 1; $month_end = 12;  }
×
266

267
        if ( $time[0][1] != "" )
×
268
        {  $day_start = $time[0][1]; $day_end = $time[0][1];  }
×
269
        else
×
270
        {  $day_start = 1; $day_end = 31;  }
×
271
        $hour_start = 0; $hour_end = 23; 
×
272
     }
273
     else if ($time_sep[0] == "day")          
×
274
     { 
275
        $year_start = $time[0][2];  $year_end = $time[0][2];
×
276
        if ( $time[0][0] != " " )
×
277
        {   $month_start = $time[0][0]; $month_end = $time[0][0];  }
×
278
        else
×
279
        {   $month_start = 1; $month_end = 12;  }
×
280

281
        if ( $time[0][1] != "" )
×
282
        {  $day_start = $time[0][1]; $day_end = $time[0][1];  }
×
283
        else
×
284
        {  $day_start = 1; $day_end = 31;  }
×
285

286
        $hour_start = -1; 
×
287
     }
288
     else if ($time_sep[0] == "month")           
×
289
     { 
290
        $year_start = $time[0][2];  $year_end = $time[0][2];
×
291
        if ( $time[0][0] != " " )
×
292
        {   $month_start = $time[0][0]; $month_end = $time[0][0];  }
×
293
        else
×
294
        {   $month_start = 1; $month_end = 12;  }  
×
295
        $day_start = -1;
×
296
        $hour_start = -1; 
×
297
     }
298
  }
299

300
  if ( $debug_mode == 1 )
×
301
  {
302
     echo '<TABLE BORDER=1>
×
303
            <TR>
304
              <TD>year_start<TD>year_end<TD>month_start<TD>month_end
305
              <TD>day_start<TD>day_end<TD>hour_start<TD>hour_end
306
            <TR>
307
              <TD>'.$year_start.'<TD>'.$year_end.'<TD>'.$month_start.'<TD>'.$month_end.
308
              '<TD>'.$day_start.'<TD>'.$day_end.'<TD>'.$hour_start.'<TD>'.$hour_end.
309
           '</TABLE>';
310
  }
311

312
  $cnt = 0;
×
313
  $i_year = $i_month = $i_day = $i_hour = NULL;
×
314

315
  for ( $i_year = $year_start; $i_year <= $year_end; $i_year++ )
×
316
  {
317
      // !!! AVN !!!
318
      // to_date() must used!
319
      $sql = "SELECT count(*) ".$from.$where." AND ".
×
320
             $db->baseSQL_YEAR("timestamp", "=", $i_year);
×
321

322
      if ( $month_start != -1 )
×
323
      {
324
         if ($i_year == $year_start)  $month_start2 = $month_start;  else  $month_start2 = 1;
×
325
         if ($i_year == $year_end)    $month_end2 = $month_end;      else  $month_end2 = 12;
×
326

327
         for ( $i_month = $month_start2; $i_month <= $month_end2; $i_month++ )
×
328
         {
329
             $sql = "SELECT count(*) ".$from.$where." AND ".
×
330
                    $db->baseSQL_YEAR("timestamp", "=", $i_year)." AND ".
×
331
                    $db->baseSQL_MONTH("timestamp", "=", $i_month);
×
332

333
             if ( $day_start != -1 )
×
334
             {
335
                if ($i_month == $month_start)  $day_start2 = $day_start;  else  $day_start2 = 1;
×
336
                if ($i_month == $month_end)    $day_end2 = $day_end;      else  $day_end2 = 31;
×
337

338
                for ( $i_day = $day_start2; $i_day <= $day_end2; $i_day++ )
×
339
                {
340
                  if ( checkdate($i_month, $i_day, $i_year) )
×
341
                  {
342
                    $sql = "SELECT count(*) ".$from.$where." AND ".
×
343
                           $db->baseSQL_YEAR("timestamp", "=", $i_year)." AND ".
×
344
                           $db->baseSQL_MONTH("timestamp", "=",$i_month)." AND ".
×
345
                           $db->baseSQL_DAY("timestamp", "=", $i_day);
×
346

347
                    $i_hour = "";
×
348
                    if ( $hour_start != -1 )
×
349
                    {
350
                       for ( $i_hour = $hour_start; $i_hour <= $hour_end; $i_hour++ )
×
351
                       {
352
                           $sql = "SELECT count(*) ".$from.$where." AND ".
×
353
                                  $db->baseSQL_YEAR("timestamp", "=", $i_year)." AND ".
×
354
                                  $db->baseSQL_MONTH("timestamp", "=", $i_month)." AND ".
×
355
                                  $db->baseSQL_DAY("timestamp", "=", $i_day)." AND ".
×
356
                                  $db->baseSQL_HOUR("timestamp", "=", $i_hour);
×
357

358
                           StoreAlertNum($sql, $i_month."/".$i_day."/".$i_year." ".
×
359
                                               $i_hour.":00:00 - ".$i_hour.":59:59", 
360
                                         $time_sep, $i_year, $i_month, $i_day, $i_hour);
361
                       }  // end hour
362
                    }
363
                    else
×
364
                        StoreAlertNum($sql, $i_month."/".$i_day."/".$i_year,
×
365
                                      $time_sep, $i_year, $i_month, $i_day, $i_hour);
366
                  }
367
                }   // end day
368
             }
369
             else
×
370
               StoreAlertNum($sql, $i_month."/".$i_year, $time_sep, $i_year, $i_month, $i_day, $i_hour);
×
371
         }   // end month
372
      }
373
      else
×
374
        StoreAlertNum($sql, $i_year, $time_sep, $i_year, $i_month, $i_day, $i_hour);
×
375
  }   // end year
376

377
  echo '</TABLE>';
×
378
        PrintTimeProfile();
×
379
}
380
PrintBASESubFooter();
×
381
?>
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc