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

NathanGibbs3 / BASE / 631

pending completion
631

push

travis-ci-com

NathanGibbs3
20230524 Fix CI build breakage.
         Code Cleanup.

44 of 44 new or added lines in 1 file covered. (100.0%)

3273 of 17644 relevant lines covered (18.55%)

27.23 hits per line

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

25.37
/includes/base_state_citems.inc.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 Lead: Kevin Johnson <kjohnson@secureideas.net>
10
** Built upon work by Roman Danyliw <rdd@cert.org>, <roman@danyliw.com>
11
**
12
** Purpose: individual criteria classes
13
********************************************************************************
14
** Authors:
15
********************************************************************************
16
** Kevin Johnson <kjohnson@secureideas.net
17
**
18
********************************************************************************
19
*/
20
// Ensure the conf file has been loaded. Prevent direct access to this file.
21
defined('_BASE_INC') or die('Accessing this file directly is not allowed.');
22

23
class BaseCriteria {
24
        var $criteria;
25
        var $export_name;
26
        var $db;
27
        var $cs;
28
        // Placeholders to support function overrides.
29
        var $value;
30
        var $value1;
31
        var $value2;
32
        var $value3;
33

34
        function __construct( &$db, &$cs, $name ){ // PHP 5+ constructor Shim.
35
                // Class/Method agnostic shim code.
36
                $SCname = get_class();
88✔
37
                if( method_exists($this, $SCname) ){
88✔
38
                        $SCargs = func_get_args();
88✔
39
                        // Custom non agnostic shim line for pass by refs.
40
                        $SCargs = array(&$db, &$cs, $name);
88✔
41
                        call_user_func_array(array($this, $SCname), $SCargs);
88✔
42
                }else{
32✔
43
                        // @codeCoverageIgnoreStart
44
                        // Should never execute.
45
                        trigger_error( // Will need to add this message to the TD.
46
                                "Class: $SCname No Legacy Constructor.\n",
47
                                E_USER_ERROR
48
                        );
49
                        // @codeCoverageIgnoreEnd
50
                }
51
        }
64✔
52

53
        function BaseCriteria( &$db, &$cs, $name ){ // PHP 4x constructor.
54
                $this->db =& $db;
176✔
55
                $this->cs =& $cs;
176✔
56
                $this->export_name = $name;
176✔
57
                $this->criteria = NULL;
176✔
58
                // NULL Placeholders.
59
                $this->value = NULL;
176✔
60
                $this->value1 = NULL;
176✔
61
                $this->value2 = NULL;
176✔
62
                $this->value3 = NULL;
176✔
63
        }
128✔
64

65
        // These functions are NoOp placeholders in this class.
66

67
        function Init(){
68
                // Initilaize Class Data Structure(s).
69
        }
16✔
70

71
        function Import(){
72
                // Imports criteria from POST, GET, or the session.
73
        }
16✔
74

75
        function Clear(){
76
                // Clears the criteria.
77
        }
16✔
78

79
        function Sanitize(){
80
                // Clean/validate the criteria.
81
        }
16✔
82

83
        function SanitizeElement( $value ){
84
                // Clean/validate the criteria.
85
        }
32✔
86

87
        function PrintForm( $value1, $value2, $value3 ){
88
                // Prints the HTML form to input the criteria.
89
        }
16✔
90

91
        function AddFormItem( &$value1, $value2 ){
92
                // Adding another item to the HTML form.
93
        }
16✔
94

95
        function GetFormItemCnt(){
96
                // Returns the number of items in this form element.
97
        }
16✔
98

99
        function SetFormItemCnt( $value ){
100
                // Sets the number of items in this form element.
101
        }
16✔
102

103
        function Set( $value ){
104
                // Set the value of this criteria.
105
        }
16✔
106

107
        function Get(){
108
                // Returns the value of this criteria.
109
        }
16✔
110

111
        function ToSQL(){
112
                // Convert this criteria to SQL.
113
        }
16✔
114

115
        function Description( $value ){
116
                // Generate human-readable description of this criteria.
117
        }
16✔
118

119
        function isEmpty(){
120
                // Returns if the criteria is empty.
121
        }
16✔
122

123
        function CTIFD( $func = '', $SF = '' ){
124
                // CTIFD Clear To Import Function Data.
125
                // Prints debug info for Criteria Type Input/Import Functions.
126
                GLOBAL $debug_mode;
272✔
127
                if( !LoadedString($func) ){
374✔
128
                        $func = __CLASS__ . '::' . __FUNCTION__;
22✔
129
                }
8✔
130
                if( $debug_mode > 1 ){
374✔
131
                        $msg = "$func: $this->export_name ";
286✔
132
                        if( is_bool($SF) ){
286✔
133
                                if( $SF ){
264✔
134
                                        $msg .= 'Allowed';
132✔
135
                                }else{
48✔
136
                                        $msg .= 'Denied';
132✔
137
                                }
138
                        }
96✔
139
                        $msg .= ": Criteria Type: " . gettype($this->criteria);
286✔
140
                        ErrorMessage($msg, 'black', 1);
286✔
141
                }
104✔
142
        }
272✔
143
};
144

145
class SingleElementCriteria extends BaseCriteria{
146
        function Import(){ // Store ourselves in the session.
147
                $this->criteria = SetSessionVar($this->export_name);
88✔
148
                $_SESSION[$this->export_name] = &$this->criteria;
88✔
149
        }
64✔
150

151
        // NoOp placeholders in this class. Why is it even here?
152

153
        function Sanitize(){
154
                $this->SanitizeElement('');
22✔
155
        }
16✔
156

157
        function GetFormItemCnt(){
158
                return -1;
22✔
159
        }
160

161
        function Set( $value ){
162
                $this->criteria = $value;
22✔
163
        }
16✔
164

165
        function Get(){
166
                return $this->criteria;
22✔
167
        }
168

169
        function isEmpty(){
170
                if( is_null($this->criteria) || $this->criteria == '' ){
22✔
171
                        $Ret = true;
22✔
172
                }else{
8✔
173
                        $Ret = false;
22✔
174
                }
175
                return $Ret;
22✔
176
        }
177
};
178

179
class MultipleElementCriteria extends BaseCriteria {
180
        var $element_cnt;
181
        var $criteria_cnt;
182
        var $valid_field_list = array();
183

184
        function __construct(
185
                &$db, &$cs, $export_name, $element_cnt, $field_list = Array()
186
        ){ // PHP 5+ constructor Shim.
187
                // Class/Method agnostic shim code.
188
                $SCname = get_class();
44✔
189
                if( method_exists($this, $SCname) ){
44✔
190
                        $SCargs = func_get_args();
44✔
191
                        // Custom non agnostic shim lines for pass by refs.
192
                        $SCargs = array(
8✔
193
                                &$db, &$cs, $export_name, $element_cnt, $field_list = Array()
44✔
194
                        );
16✔
195
                        call_user_func_array(array($this, $SCname), $SCargs);
44✔
196
                }else{
16✔
197
                        // @codeCoverageIgnoreStart
198
                        // Should never execute.
199
                        trigger_error( // Will need to add this message to the TD.
200
                                "Class: $SCname No Legacy Constructor.\n",
201
                                E_USER_ERROR
202
                        );
203
                        // @codeCoverageIgnoreEnd
204
                }
205
        }
32✔
206

207
        function MultipleElementCriteria(
208
                &$db, &$cs, $export_name, $element_cnt, $field_list = Array()
209
        ){ // PHP 4x constructor.
210
                $tdb =& $db;
66✔
211
                $cs =& $cs;
66✔
212
                $this->BaseCriteria($tdb, $cs, $export_name);
66✔
213
                $this->element_cnt = $element_cnt;
66✔
214
                $this->criteria_cnt = 0;
66✔
215
                $this->valid_field_list = $field_list;
66✔
216
        }
48✔
217

218
        function Init(){
219
                GLOBAL $MAX_ROWS;
48✔
220
                if ( isset($MAX_ROWS) ){
66✔
221
                        $tmp = $MAX_ROWS;
22✔
222
                }else{
8✔
223
                        $tmp = 10;
44✔
224
                }
225
                InitArray($this->criteria, $tmp, $this->element_cnt, '');
66✔
226
                $this->criteria_cnt = 1;
66✔
227
                $_SESSION[$this->export_name."_cnt"] = &$this->criteria_cnt;
66✔
228
                $this->CTIFD(__CLASS__ . '::' . __FUNCTION__);
66✔
229
        }
48✔
230

231
        function Import(){
232
                $tmp = SetSessionVar($this->export_name);
44✔
233
                if ( is_array($tmp) ){ // Type Lock criteria import. Fixes Issue #10.
44✔
234
                        $SF = true;
22✔
235
                        $this->criteria = $tmp;
22✔
236
                }else{
8✔
237
                        $SF = false;
22✔
238
                }
239
                $this->criteria_cnt = intval(SetSessionVar($this->export_name."_cnt"));
44✔
240
                $_SESSION[$this->export_name] = &$this->criteria;
44✔
241
                $_SESSION[$this->export_name."_cnt"] = &$this->criteria_cnt;
44✔
242
                $this->CTIFD(__CLASS__ . '::' . __FUNCTION__, $SF);
44✔
243
        }
32✔
244

245
        function Sanitize(){
246
      if ( in_array("criteria", array_keys(get_object_vars($this))) )
×
247
      {
248
         for($i=0; $i < $this->element_cnt; $i++)
×
249
         {
250
            if ( isset($this->criteria[$i]) )
×
251
               $this->SanitizeElement($i);
×
252
         }
253
      }
254
        }
255

256
        // NoOp placeholders in this class. Why is it even here?
257

258
        function SanitizeElement($i){
259
        }
16✔
260

261
        function GetFormItemCnt(){
262
                return $this->criteria_cnt;
22✔
263
        }
264

265
        function SetFormItemCnt( $value ){
266
                $this->criteria_cnt = intval($value); // TypeLock this.
22✔
267
        }
16✔
268

269
        function AddFormItem( &$submit, $submit_value ){
270
        $this->criteria_cnt =& $this->criteria_cnt;
×
271
      AddCriteriaFormRow($submit, $submit_value, $this->criteria_cnt, $this->criteria, $this->element_cnt);
×
272
        }
273

274
        function Set( $value ){
275
                if( is_array($value) ){ // Type Lock criteria Set. Fixes Issue #10.
66✔
276
                        $SF = true;
44✔
277
                        $this->criteria = $value;
44✔
278
                }else{
16✔
279
                        $SF = false;
22✔
280
                }
281
                $this->CTIFD(__CLASS__ . '::' . __FUNCTION__, $SF);
66✔
282
        }
48✔
283

284
        function Get(){
285
                return $this->criteria;
22✔
286
        }
287

288
        function isEmpty(){
289
                if( is_null($this->criteria) || intval($this->criteria_cnt) == 0 ){
44✔
290
                        $Ret = true;
44✔
291
                }else{
16✔
292
                        $Ret = false;
44✔
293
                }
294
                return $Ret;
44✔
295
        }
296

297
        function PrintForm( $field_list, $blank_field_string, $add_button_string ){
298
                GLOBAL $debug_mode;
299
                if( $debug_mode > 0 ){
×
300
                        $this->CTIFD(__CLASS__ . '::' . __FUNCTION__);
×
301
                        print "Criteria Count: $this->criteria_cnt<br/>\n";
×
302
                }
303
                for( $i = 0; $i < $this->criteria_cnt; $i++ ){
×
304
                        if( !is_array($this->criteria[$i]) ){
×
305
                                if( $debug_mode > 0 ){
×
306
                                        print __FUNCTION__.": Criteria Data Error Detected<br/>\n";
×
307
                                        print "Re Initializing<br/>\n";
×
308
                                }
309
                                $this->Init();
×
310
                        }
311
         echo '    <SELECT NAME="'.htmlspecialchars($this->export_name).'['.$i.'][0]">';
×
312
         echo '      <OPTION VALUE=" " '.chk_select($this->criteria[$i][0]," ").'>__</OPTION>'; 
×
313
         echo '      <OPTION VALUE="(" '.chk_select($this->criteria[$i][0],"(").'>(</OPTION>';
×
314
         echo '    </SELECT>';
×
315

316
         echo '    <SELECT NAME="'.htmlspecialchars($this->export_name).'['.$i.'][1]">';
×
317
         echo '      <OPTION VALUE=" "      '.chk_select($this->criteria[$i][1]," ").'>'.$blank_field_string.'</OPTION>';
×
318
 
319
         foreach( $field_list as $field_name => $field_human_name )
×
320
         {
321
            echo '   <OPTION VALUE="'.$field_name.'" '.chk_select($this->criteria[$i][1],$field_name).'>'.$field_human_name.'</OPTION>';
×
322
         }
323
         echo '    </SELECT>';
×
324

325
         echo '    <SELECT NAME="'.htmlspecialchars($this->export_name).'['.$i.'][2]">';
×
326
         echo '      <OPTION VALUE="="  '.chk_select($this->criteria[$i][2],"="). '>=</OPTION>';
×
327
         echo '      <OPTION VALUE="!=" '.chk_select($this->criteria[$i][2],"!=").'>!=</OPTION>';
×
328
         echo '      <OPTION VALUE="<"  '.chk_select($this->criteria[$i][2],"<"). '><</OPTION>';
×
329
         echo '      <OPTION VALUE="<=" '.chk_select($this->criteria[$i][2],"<=").'><=</OPTION>';
×
330
         echo '      <OPTION VALUE=">"  '.chk_select($this->criteria[$i][2],">"). '>></OPTION>';
×
331
         echo '      <OPTION VALUE=">=" '.chk_select($this->criteria[$i][2],">=").'>>=</OPTION>';
×
332
         echo '    </SELECT>';
×
333

334
         echo '    <INPUT TYPE="text" NAME="'.htmlspecialchars($this->export_name).'['.$i.'][3]" SIZE=5 VALUE="'.htmlspecialchars($this->criteria[$i][3]).'">';
×
335

336
         echo '    <SELECT NAME="'.htmlspecialchars($this->export_name).'['.$i.'][4]">';
×
337
         echo '      <OPTION VALUE=" " '.chk_select($this->criteria[$i][4]," ").'>__</OPTION';
×
338
         echo '      <OPTION VALUE="(" '.chk_select($this->criteria[$i][4],"(").'>(</OPTION>';
×
339
         echo '      <OPTION VALUE=")" '.chk_select($this->criteria[$i][4],")").'>)</OPTION>';
×
340
         echo '    </SELECT>';
×
341

342
         echo '    <SELECT NAME="'.htmlspecialchars($this->export_name).'['.$i.'][5]">';
×
343
         echo '      <OPTION VALUE=" "   '.chk_select($this->criteria[$i][5]," ").  '>__</OPTION>';
×
344
         echo '      <OPTION VALUE="OR" '.chk_select($this->criteria[$i][5],"OR").  '>'._OR.'</OPTION>';
×
345
         echo '      <OPTION VALUE="AND" '.chk_select($this->criteria[$i][5],"AND").'>'._AND.'</OPTION>';
×
346
         echo '    </SELECT>';
×
347
         if ( $i == $this->criteria_cnt-1 )
×
348
            echo '    <INPUT TYPE="submit" NAME="submit" VALUE="'.htmlspecialchars($add_button_string).'">';
×
349
         echo '<BR>';
×
350
                }
351
        }
352

353
        function Compact(){ // Not Used in Code. Why is it even here?
354
                if( $this->isEmpty() ){ // Restore to newly constructed state.
22✔
355
                        $this->criteria = NULL;
22✔
356
                        $_SESSION[$this->export_name] = &$this->criteria;
22✔
357
                }
8✔
358
        }
16✔
359
};
360

361
class ProtocolFieldCriteria extends MultipleElementCriteria {
362
        function __construct(
363
                &$db, &$cs, $export_name, $element_cnt, $field_list = Array()
364
        ){ // PHP 5+ constructor Shim.
365
                // Class/Method agnostic shim code.
366
                $SCname = get_class();
22✔
367
                if( method_exists($this, $SCname) ){
22✔
368
                        $SCargs = func_get_args();
22✔
369
                        // Custom non agnostic shim lines for pass by refs.
370
                        $SCargs = array(
4✔
371
                                &$db, &$cs, $export_name, $element_cnt, $field_list = array()
22✔
372
                        );
8✔
373
                        call_user_func_array(array($this, $SCname), $SCargs);
22✔
374
                }else{
8✔
375
                        // @codeCoverageIgnoreStart
376
                        // Should never execute.
377
                        trigger_error( // Will need to add this message to the TD.
378
                                "Class: $SCname No Legacy Constructor.\n",
379
                                E_USER_ERROR
380
                        );
381
                        // @codeCoverageIgnoreEnd
382
                }
383
        }
16✔
384

385
        function ProtocolFieldCriteria(
386
                &$db, &$cs, $export_name, $element_cnt, $field_list = array()
387
        ){ // PHP 4x constructor.
388
                $tdb =& $db;
22✔
389
                $cs =& $cs;
22✔
390
                $this->MultipleElementCriteria(
22✔
391
                        $tdb, $cs, $export_name, $element_cnt, $field_list
16✔
392
                );
8✔
393
        }
16✔
394

395
        function SanitizeElement( $i ){
396
                // Make a copy of the element array -- Why?!
397
      $curArr = $this->criteria[$i];
×
398
      // Sanitize the element
399
      $this->criteria[$i][0] = @CleanVariable($curArr[0], VAR_OPAREN);
×
400
      $this->criteria[$i][1] = @CleanVariable($curArr[1], "", array_keys($this->valid_field_list));
×
401
      $this->criteria[$i][2] = @CleanVariable($curArr[2], "", array("=", "!=", "<", "<=", ">", ">="));
×
402
      $this->criteria[$i][3] = @CleanVariable($curArr[3], VAR_DIGIT);
×
403
      $this->criteria[$i][4] = @CleanVariable($curArr[4], VAR_OPAREN | VAR_CPAREN);
×
404
      $this->criteria[$i][5] = @CleanVariable($curArr[5], "", array("AND", "OR"));
×
405
      // Destroy the copy
406
      unset($curArr);
×
407
        }
408

409
        function Description( $human_fields ){
410
                $tmp = '';
×
411
      for ( $i = 0; $i < $this->criteria_cnt; $i++ )
×
412
      {
413
          if (is_array($this->criteria[$i]))
×
414
              if ($this->criteria[$i][1] != " " && $this->criteria[$i][3] != "" )
×
415
                  $tmp = $tmp.$this->criteria[$i][0].$human_fields[($this->criteria[$i][1])].' '.
×
416
                      $this->criteria[$i][2].' '.$this->criteria[$i][3].$this->criteria[$i][4].' '.$this->criteria[$i][5];
×
417
      }
418
      if ( $tmp != "" )
×
419
         $tmp = $tmp.$this->cs->GetClearCriteriaString($this->export_name); 
×
420

421
                return $tmp;
×
422
        }
423
}
424

425
class SignatureCriteria extends SingleElementCriteria {
426
// $sig[4]: stores signature
427
//   - [0] : exactly, roughly    [2] : =, !=
428
//   - [1] : signature           [3] : signature from signature list
429
        var $sig_type;
430
        var $criteria = array(0 => '', 1 => '');
431

432
        function __construct( &$db, &$cs, $export_name ){
433
                // PHP 5+ constructor Shim.
434
                // Class/Method agnostic shim code.
435
                $SCname = get_class();
62✔
436
                if( method_exists($this, $SCname) ){
62✔
437
                        $SCargs = func_get_args();
62✔
438
                        // Custom non agnostic shim line for pass by refs.
439
                        $SCargs = array(&$db, &$cs, $export_name);
62✔
440
                        call_user_func_array(array($this, $SCname), $SCargs);
62✔
441
                }else{
20✔
442
                        // @codeCoverageIgnoreStart
443
                        // Should never execute.
444
                        trigger_error( // Will need to add this message to the TD.
445
                                "Class: $SCname No Legacy Constructor.\n",
446
                                E_USER_ERROR
447
                        );
448
                        // @codeCoverageIgnoreEnd
449
                }
450
        }
44✔
451

452
        function SignatureCriteria( &$db, &$cs, $export_name ){
453
                // PHP 4x constructor.
454
                $tdb =& $db;
62✔
455
                $cs =& $cs;
62✔
456
                $this->BaseCriteria($tdb, $cs, $export_name);
62✔
457
                $this->sig_type = '';
62✔
458
        }
44✔
459

460
        function Init(){
461
                InitArray($this->criteria, 4, 0, '');
22✔
462
                $this->sig_type = '';
22✔
463
        }
16✔
464

465
        function Import(){
466
                $tmp = SetSessionVar($this->export_name);
44✔
467
                if( is_array($tmp) ){ // Type Lock criteria import. Fixes Issue #10.
44✔
468
                        parent::Import(); // Store ourselves in the session.
22✔
469
                        $SF = true;
22✔
470
                }else{
8✔
471
                        $SF = false;
22✔
472
                }
473
                $this->CTIFD(__CLASS__ . '::' . __FUNCTION__, $SF);
44✔
474
                $this->sig_type = SetSessionVar("sig_type");
44✔
475
                $_SESSION['sig_type'] = &$this->sig_type;
44✔
476
        }
32✔
477

478
        function Clear(){
479
        }
16✔
480

481
        function SanitizeElement( $value ){
482
      if (!isset($this->criteria[0]) || !isset($this->criteria[1])) {
×
483
          $this->criteria = array(0 => '', 1 => '');
×
484
      }
485

486
      $this->criteria[0] = CleanVariable(@$this->criteria[0], "", array(" ", "=", "LIKE"));
×
487
      $this->criteria[1] = filterSql(@$this->criteria[1]); /* signature name */
×
488
      $this->criteria[2] = CleanVariable(@$this->criteria[2], "", array("=", "!="));
×
489
      $this->criteria[3] = filterSql(@$this->criteria[3]); /* signature name from the signature list */
×
490
        }
491

492
        function PrintForm( $value1, $value2, $value3 ){
493
                GLOBAL $debug_mode;
494
                if( !is_array($this->criteria) ){
×
495
                        if( $debug_mode > 0 ){
×
496
                                $this->CTIFD(__CLASS__ . '::' . __FUNCTION__);
×
497
                                print __FUNCTION__.": Criteria Data Error Detected<br/>\n";
×
498
                                print "Re Initializing<br/>\n";
×
499
                        }
500
                        $this->Init();
×
501
                }
502
      echo '<SELECT NAME="sig[0]"><OPTION VALUE=" "  '.chk_select(@$this->criteria[0]," "). '>'._DISPSIG;    
×
503
      echo '                      <OPTION VALUE="="     '.chk_select(@$this->criteria[0],"="). '>'._SIGEXACTLY;
×
504
      echo '                      <OPTION VALUE="LIKE" '.chk_select(@$this->criteria[0],"LIKE").'>'._SIGROUGHLY.'</SELECT>';
×
505

506
      echo '<SELECT NAME="sig[2]"><OPTION VALUE="="  '.chk_select(@$this->criteria[2],"="). '>=';
×
507
      echo '                      <OPTION VALUE="!="     '.chk_select(@$this->criteria[2],"!="). '>!=';
×
508
      echo '</SELECT>';
×
509

510
      echo '<INPUT TYPE="text" NAME="sig[1]" SIZE=40 VALUE="'.htmlspecialchars(@$this->criteria[1]).'"><BR>';
×
511
                if( is_key('use_sig_list', $GLOBALS) ){ // Issue #44
×
512
      if ( $GLOBALS['use_sig_list'] > 0)
×
513
      {
514
         $temp_sql = "SELECT DISTINCT sig_name FROM signature";
×
515
         if ($GLOBALS['use_sig_list'] == 1)
×
516
         {
517
            $temp_sql = $temp_sql." WHERE sig_name NOT LIKE '%SPP\_%'";
×
518
         }
519

520
         $temp_sql = $temp_sql." ORDER BY sig_name";
×
521
         $tmp_result = $this->db->baseExecute($temp_sql);
×
522
         echo '<SELECT NAME="sig[3]"
523
                       onChange=\'PacketForm.elements[4].value =
524
                         this.options[this.selectedIndex].value;return true;\'>
525
                <OPTION VALUE="null" SELECTED>{ Select Signature from List }';
526

527
         if ($tmp_result)
528
         {
529
            while ( $myrow = $tmp_result->baseFetchRow() )
×
530
               echo '<OPTION VALUE="'.$myrow[0].'">'.$myrow[0];
×
531
            $tmp_result->baseFreeRows();
×
532
         }
533
         echo '</SELECT><BR>';
×
534
      }
535
                }
536
        }
537

538
        function ToSQL(){
539
        }
16✔
540

541
        function Description( $value ){
542
                $tmp = $tmp_human = "";
40✔
543
                if( isset($this->criteria[0]) && $this->criteria[0] != " " ){
40✔
544
                        // Common code for both scenarios.
545
                        if( $this->criteria[0] == '=' ){
40✔
546
                                if( $this->criteria[2] == '!=' ){
40✔
547
                                        $tmp_human = '!=';
20✔
548
                                }elseif( $this->criteria[2] == '=' ){
40✔
549
                                        $tmp_human = '=';
40✔
550
                                }
12✔
551
                        }elseif( $this->criteria[0] == 'LIKE' ){
26✔
552
                                if( $this->criteria[2] == '!=' ){
20✔
553
                                        $tmp_human = ' '._DOESNTCONTAIN.' ';
20✔
554
                                }elseif( $this->criteria[2] == '=' ){
20✔
555
                                        $tmp_human = ' '._CONTAINS.' ';
20✔
556
                                }
6✔
557
                        }
6✔
558
                        $SIdx = 0;
40✔
559
                        if(
560
                                (isset($this->criteria[3]))
40✔
561
                                && ($this->criteria[3] != "" )
40✔
562
                                && ($this->criteria[3] != "null")
40✔
563
                                && ($this->criteria[3] != "NULL")
40✔
564
                                && ($this->criteria[3] != NULL)
40✔
565
                        ){
12✔
566
                                // First scenario: Signature name is taken from the signature
567
                                // list. The user has clicked on a drop down menu for this.
568
                                $SIdx = 3;
×
569
                        }elseif(
570
                                (isset($this->criteria[1])) && ($this->criteria[1] != "")
40✔
571
                        ){
12✔
572
                                // Second scenario: Signature name is taken from a string that
573
                                // has been typed in manually by the user.
574
                                $SIdx = 1;
20✔
575
                        }
6✔
576
                        if( $SIdx != 0 ){
40✔
577
                                $tmp .= _SIGNATURE.' '.$tmp_human.' "';
20✔
578
                                if(
579
                                        ($this->db->baseGetDBversion() >= 100)
20✔
580
                                        && $this->sig_type == 1
20✔
581
                                ){
6✔
582
                                        $tmp .= BuildSigByID($this->criteria[$SIdx], $this->db).'" ';
×
583
                                }else{
584
                                        $tmp .= htmlentities($this->criteria[$SIdx]).'"';
20✔
585
                                }
586
                                $tmp .= $this->cs->GetClearCriteriaString($this->export_name);
20✔
587
                                $tmp .= '<br/>';
20✔
588
                        }
6✔
589
                }
12✔
590
                return $tmp;
40✔
591
        }
592
};  /* SignatureCriteria */
593

594
class SignatureClassificationCriteria extends SingleElementCriteria {
595
        function Init(){
596
                $this->criteria = '';
×
597
        }
598

599
        function Clear(){ // clears the criteria.
600
        }
601

602
        function SanitizeElement( $value ){
603
                $this->criteria = CleanVariable($this->criteria, VAR_DIGIT);
×
604
        }
605

606
        function PrintForm( $value1, $value2, $value3 ){
607
     if ( $this->db->baseGetDBversion() >= 103 )
×
608
     {
609

610
        echo '<SELECT NAME="sig_class">
611
              <OPTION VALUE=" " '.chk_select($this->criteria, " ").'>'._DISPANYCLASS.'
×
612
              <OPTION VALUE="null" '.chk_select($this->criteria, "null").'>-'._UNCLASS.'-';
×
613

614
        $temp_sql = "SELECT sig_class_id, sig_class_name FROM sig_class";
×
615
        $tmp_result = $this->db->baseExecute($temp_sql);
×
616
        if ( $tmp_result )
617
        {
618
           while ( $myrow = $tmp_result->baseFetchRow() )
×
619
            echo '<OPTION VALUE="'.$myrow[0].'" '.chk_select($this->criteria, $myrow[0]).'>'.
×
620
                  $myrow[1];
×
621

622
           $tmp_result->baseFreeRows();
×
623
        }
624
        echo '</SELECT>&nbsp;&nbsp';
×
625
     }
626
        }
627

628
        function ToSQL(){ // convert this criteria to SQL.
629
        }
630

631
        function Description( $value ){
632
                $tmp = '';
×
633
      if ( $this->db->baseGetDBversion() >= 103 )
×
634
      {
635
         if ( $this->criteria != " " && $this->criteria != "" )
×
636
         {
637
            if ( $this->criteria == "null")
×
638
               $tmp = $tmp._SIGCLASS.' = '.
×
639
                              '<I>'._UNCLASS.'</I><BR>';
640
            else
641
               $tmp = $tmp._SIGCLASS.' = '.
×
642
                              htmlentities(GetSigClassName($this->criteria, $this->db)).
×
643
                              $this->cs->GetClearCriteriaString($this->export_name).'<BR>';
×
644
         }
645
      }
646

647
                return $tmp;
×
648
        }
649

650
};  /* SignatureClassificationCriteria */
651

652
class SignaturePriorityCriteria extends SingleElementCriteria {
653
        var $criteria = array(0 => '', 1 => '');
654

655
        function Init(){
656
                InitArray($this->criteria, 2, 0, '');
22✔
657
        }
16✔
658

659
        function Import(){
660
                $tmp = SetSessionVar($this->export_name);
44✔
661
                if( is_array($tmp) ){ // Type Lock criteria import. Fixes Issue #10.
44✔
662
                        parent::Import(); // Store ourselves in the session.
22✔
663
                        $SF = true;
22✔
664
                }else{
8✔
665
                        $SF = false;
22✔
666
                }
667
                $this->CTIFD(__CLASS__ . '::' . __FUNCTION__, $SF);
44✔
668
        }
32✔
669

670
        function Clear(){ // Clears the criteria.
671
        }
16✔
672

673
        function SanitizeElement( $value ){
674
     if (!isset($this->criteria[0]) || !isset($this->criteria[1])) {
×
675
         $this->criteria = array(0 => '', 1 => '');
×
676
     }
677

678
      $this->criteria[0] = CleanVariable(@$this->criteria[0], "", array("=", "!=", "<", "<=", ">", ">="));
×
679
      $this->criteria[1] = CleanVariable(@$this->criteria[1], VAR_DIGIT);
×
680
        }
681

682
        function PrintForm( $value1, $value2, $value3 ){
683
                GLOBAL $debug_mode;
684
                if( $this->db->baseGetDBversion() >= 103 ){
×
685
                        if( !is_array($this->criteria) ){
×
686
                                if( $debug_mode > 0 ){
×
687
                                        $this->CTIFD(__CLASS__ . '::' . __FUNCTION__);
×
688
                                        print __FUNCTION__.": Criteria Data Error Detected<br/>\n";
×
689
                                        print "Re Initializing<br/>\n";
×
690
                                }
691
                                $this->Init();
×
692
                        }
693
        echo '<SELECT NAME="sig_priority[0]">
694
                <OPTION VALUE=" " '.@chk_select($this->criteria[0],"="). '>__</OPTION>
×
695
                <OPTION VALUE="=" '.@chk_select($this->criteria[0],"=").'>==</OPTION>
×
696
                <OPTION VALUE="!=" '.@chk_select($this->criteria[0],"!=").'>!=</OPTION>
×
697
                <OPTION VALUE="<"  '.@chk_select($this->criteria[0],"<"). '><</OPTION>
×
698
                <OPTION VALUE=">"  '.@chk_select($this->criteria[0],">").'>></OPTION>
×
699
                <OPTION VALUE="<=" '.@chk_select($this->criteria[0],"><="). '><=</OPTION>
×
700
                <OPTION VALUE=">=" '.@chk_select($this->criteria[0],">=").'>>=</SELECT>';
×
701
 
702
        echo '<SELECT NAME="sig_priority[1]">
703
                <OPTION VALUE="" '.@chk_select($this->criteria[1], " ").'>'._DISPANYPRIO.'</OPTION>
×
704
                 <OPTION VALUE="null" '.@chk_select($this->criteria[1], "null").'>-'._UNCLASS.'-</OPTION>';
×
705
        $temp_sql = "select DISTINCT sig_priority from signature ORDER BY sig_priority ASC ";
×
706
        $tmp_result = $this->db->baseExecute($temp_sql);
×
707
        if ( $tmp_result )
708
        {
709
           while ( $myrow = $tmp_result->baseFetchRow() )
×
710
             echo '<OPTION VALUE="'.$myrow[0].'" '.chk_select(@$this->criteria[1], $myrow[0]).'>'.
×
711
                   $myrow[0];
×
712
 
713
            $tmp_result->baseFreeRows();
×
714
        }
715
        echo '</SELECT>&nbsp;&nbsp';
×
716
      }
717
        }
718

719
        function ToSQL(){ // Convert this criteria to SQL.
720
        }
16✔
721

722
        function Description( $value ){
723
                $tmp = '';
×
724
       if (!isset($this->criteria[1])) {
×
725
           $this->criteria = array(0 => '', 1 => '');
×
726
       }
727
 
728
       if ( $this->db->baseGetDBversion() >= 103 )
×
729
       {
730
          if ( $this->criteria[1] != " " && $this->criteria[1] != "" )
×
731
          {
732
             if ( $this->criteria[1] == null)
×
733
                $tmp = $tmp._SIGPRIO.' = '.
×
734
                               '<I>'._NONE.'</I><BR>';
735
             else
736
                $tmp = $tmp._SIGPRIO.' '.htmlentities($this->criteria[0])." ".htmlentities($this->criteria[1]).
×
737
                       $this->cs->GetClearCriteriaString($this->export_name).'<BR>';
×
738
                        }
739
                }
740
                return $tmp;
×
741
        }
742

743
};  /* SignaturePriorityCriteria */
744

745
class AlertGroupCriteria extends SingleElementCriteria {
746

747
        function Init(){
748
                $this->criteria = '';
×
749
        }
750

751
        function Clear(){ // clears the criteria.
752
        }
753

754
        function SanitizeElement( $value ){
755
                $this->criteria = CleanVariable($this->criteria, VAR_DIGIT);
×
756
        }
757

758
        function PrintForm( $value1, $value2, $value3 ){
759
      echo '<SELECT NAME="ag">
760
             <OPTION VALUE=" " '.chk_select($this->criteria, " ").'>'._DISPANYAG;
×
761

762
      $temp_sql = "SELECT ag_id, ag_name FROM acid_ag";
×
763
      $tmp_result = $this->db->baseExecute($temp_sql);
×
764
      if ( $tmp_result )
765
      {
766
         while ( $myrow = $tmp_result->baseFetchRow() )
×
767
           echo '<OPTION VALUE="'.$myrow[0].'" '.chk_select($this->criteria, $myrow[0]).'>'.
×
768
                 '['.$myrow[0].'] '.htmlspecialchars($myrow[1]);
×
769

770
         $tmp_result->baseFreeRows();
×
771
      }
772
      echo '</SELECT>&nbsp;&nbsp;';
×
773
        }
774

775
        function ToSQL(){ // Convert this criteria to SQL.
776
        }
777

778
        function Description( $value ){
779
                $tmp = '';
×
780
      if ( $this->criteria != " " && $this->criteria != "" )
×
781
        $tmp = $tmp._ALERTGROUP.' = ['.htmlentities($this->criteria).'] '.GetAGNameByID($this->criteria, $this->db).
×
782
                    $this->cs->GetClearCriteriaString($this->export_name).'<BR>';
×
783

784
      return $tmp;
×
785
        }
786

787
};  /* AlertGroupCriteria */
788

789
class SensorCriteria extends SingleElementCriteria {
790

791
        function Init(){
792
                $this->criteria = '';
×
793
        }
794

795
        function Clear(){ // Clears the criteria.
796
        }
797

798
        function SanitizeElement( $value ){
799
                $this->criteria = CleanVariable($this->criteria, VAR_DIGIT);
×
800
        }
801

802
        function PrintForm( $value1, $value2, $value3 ){
803
                GLOBAL $debug_mode;
804
      // How many sensors do we have?
805
      $number_sensors = 0;
×
806
      $number_sensors_lst = $this->db->baseExecute("SELECT count(*) FROM sensor");
×
807
      $number_sensors_array = $number_sensors_lst->baseFetchRow();
×
808
      $number_sensors_lst->baseFreeRows();
×
809
      if (!isset($number_sensors_array))
×
810
      {
811
        $mystr = '<BR>' . __FILE__ . '' . __LINE__ . ": \$ERROR: number_sensors_array has not been set at all!<BR>";
×
812
        ErrorMessage($mystr);        
×
813
        $number_sensors = 0;
×
814
      }
815

816
      if ($number_sensors_array == NULL || $number_sensors_array == "")
×
817
      {
818
        $number_sensors = 0;
×
819
      }
820
      else
821
      {
822
        $number_sensors = $number_sensors_array[0];
×
823
      }
824
                if ($debug_mode > 1){
×
825
                        print '$number_sensors = ' . $number_sensors . '<BR><BR>';
×
826
                }
827
      echo '<SELECT NAME="sensor">
828
             <OPTION VALUE=" " '.chk_select($this->criteria, " ").'>'._DISPANYSENSOR;
×
829

830
      $temp_sql = "SELECT sid, hostname, interface, filter FROM sensor";
×
831
      $tmp_result = $this->db->baseExecute($temp_sql);      
×
832

833
      
834
      for ($n = 0; $n < $number_sensors; $n++)
×
835
      {
836
        $myrow = $tmp_result->baseFetchRow();
×
837

838
        if (!isset($myrow) || $myrow == "" || $myrow == NULL)
×
839
        {
840
          if ($n >= $number_sensors)
×
841
          {
842
            break;
×
843
          }
844
          else
845
          {
846
            next;
×
847
          }
848
        }
849

850
        echo '<OPTION VALUE="' . $myrow[0] . '" ' .
×
851
             chk_select($this->criteria, $myrow[0]) . '>' .
×
852
             '[' . $myrow[0] . '] ' .
×
853
             GetSensorName($myrow[0], $this->db);
×
854
      }
855
      $tmp_result->baseFreeRows();
×
856

857
      echo '</SELECT>&nbsp;&nbsp';
×
858
        }
859
   function ToSQL()
860
   {
861
     /* convert this criteria to SQL */
862
   }
863
        function Description($value) {
864
     $tmp = "";
×
865

866
     if ( $this->criteria != " " && $this->criteria != "" )
×
867
        $tmp = $tmp._SENSOR.' = ['.htmlentities($this->criteria).'] '.
×
868
               GetSensorName($this->criteria, $this->db).
×
869
               $this->cs->GetClearCriteriaString($this->export_name).'<BR>';
×
870

871
      return $tmp;
×
872
        }
873

874
}; // SensorCriteria
875

876
class TimeCriteria extends MultipleElementCriteria {
877
// $time[MAX][10]: stores the date/time of the packet detection
878
//  - [][0] : (                           [][5] : hour
879
//  - [][1] : =, !=, <, <=, >, >=         [][6] : minute
880
//  - [][2] : month                       [][7] : second
881
//  - [][3] : day                         [][8] : (, )
882
//  - [][4] : year                        [][9] : AND, OR
883
//
884
// $time_cnt : number of rows in the $time[][] structure
885

886
        function Clear(){ // Clears the criteria.
887
        }
16✔
888

889
        function SanitizeElement( $i ){
890
                // Make copy of element array. - Why?!
891
      $curArr = $this->criteria[$i];
×
892
      // Sanitize the element
893
      $this->criteria[$i][0] = @CleanVariable($curArr[0], VAR_OPAREN);
×
894
      $this->criteria[$i][1] = @CleanVariable($curArr[1], "", array("=", "!=", "<", "<=", ">", ">="));
×
895
      $this->criteria[$i][2] = @CleanVariable($curArr[2], VAR_DIGIT);
×
896
      $this->criteria[$i][3] = @CleanVariable($curArr[3], VAR_DIGIT);
×
897
      $this->criteria[$i][4] = @CleanVariable($curArr[4], VAR_DIGIT);
×
898
      $this->criteria[$i][5] = @CleanVariable($curArr[5], VAR_DIGIT);
×
899
      $this->criteria[$i][6] = @CleanVariable($curArr[6], VAR_DIGIT);
×
900
      $this->criteria[$i][7] = @CleanVariable($curArr[7], VAR_DIGIT);
×
901
      $this->criteria[$i][8] = @CleanVariable($curArr[8], VAR_OPAREN | VAR_CPAREN);
×
902
      $this->criteria[$i][9] = @CleanVariable($curArr[9], "", array("AND", "OR"));
×
903
      // Destroy the old copy
904
      unset($curArr);
×
905
        }
906

907
        function PrintForm( $value1, $value2, $value3 ){
908
                GLOBAL $debug_mode;
909
                for( $i = 0; $i < $this->criteria_cnt; $i++ ){
×
910
                        if( !is_array($this->criteria[$i]) ){
×
911
                                if( $debug_mode > 0 ){
×
912
                                        $this->CTIFD(__CLASS__ . '::' . __FUNCTION__);
×
913
                                        print __FUNCTION__.": Criteria Data Error Detected<br/>\n";
×
914
                                        print "Re Initializing<br/>\n";
×
915
                                }
916
                                $this->Init();
×
917
                        }
918
         echo '<SELECT NAME="time['.$i.'][0]"><OPTION VALUE=" " '.chk_select(@$this->criteria[$i][0]," ").'>__'; 
×
919
         echo '                               <OPTION VALUE="("  '.chk_select(@$this->criteria[$i][0],"(").'>(</SELECT>';
×
920
         echo '<SELECT NAME="time['.$i.'][1]"><OPTION VALUE=" "  '.chk_select(@$this->criteria[$i][1]," "). '>'._DISPTIME;    
×
921
         echo '                               <OPTION VALUE="="  '.chk_select(@$this->criteria[$i][1],"="). '>=';
×
922
         echo '                               <OPTION VALUE="!=" '.chk_select(@$this->criteria[$i][1],"!=").'>!=';
×
923
         echo '                               <OPTION VALUE="<"  '.chk_select(@$this->criteria[$i][1],"<"). '><';
×
924
         echo '                               <OPTION VALUE="<=" '.chk_select(@$this->criteria[$i][1],"<=").'><=';
×
925
         echo '                               <OPTION VALUE=">"  '.chk_select(@$this->criteria[$i][1],">"). '>>';
×
926
         echo '                               <OPTION VALUE=">=" '.chk_select(@$this->criteria[$i][1],">=").'>>=</SELECT>';
×
927

928
         echo '<SELECT NAME="time['.$i.'][2]"><OPTION VALUE=" "  '.chk_select(@$this->criteria[$i][2]," " ).'>'._DISPMONTH;
×
929
         echo '                               <OPTION VALUE="01" '.chk_select(@$this->criteria[$i][2],"01").'>'._SHORTJAN;
×
930
         echo '                               <OPTION VALUE="02" '.chk_select(@$this->criteria[$i][2],"02").'>'._SHORTFEB;
×
931
         echo '                               <OPTION VALUE="03" '.chk_select(@$this->criteria[$i][2],"03").'>'._SHORTMAR;
×
932
         echo '                               <OPTION VALUE="04" '.chk_select(@$this->criteria[$i][2],"04").'>'._SHORTAPR;
×
933
         echo '                               <OPTION VALUE="05" '.chk_select(@$this->criteria[$i][2],"05").'>'._SHORTMAY;
×
934
         echo '                               <OPTION VALUE="06" '.chk_select(@$this->criteria[$i][2],"06").'>'._SHORTJUN;
×
935
         echo '                               <OPTION VALUE="07" '.chk_select(@$this->criteria[$i][2],"07").'>'._SHORTJLY;
×
936
         echo '                               <OPTION VALUE="08" '.chk_select(@$this->criteria[$i][2],"08").'>'._SHORTAUG;
×
937
         echo '                               <OPTION VALUE="09" '.chk_select(@$this->criteria[$i][2],"09").'>'._SHORTSEP;
×
938
         echo '                               <OPTION VALUE="10" '.chk_select(@$this->criteria[$i][2],"10").'>'._SHORTOCT;
×
939
         echo '                               <OPTION VALUE="11" '.chk_select(@$this->criteria[$i][2],"11").'>'._SHORTNOV;
×
940
         echo '                               <OPTION VALUE="12" '.chk_select(@$this->criteria[$i][2],"12").'>'._SHORTDEC.'</SELECT>';
×
941
         echo '<INPUT TYPE="text" NAME="time['.$i.'][3]" SIZE=2 VALUE="'.htmlspecialchars(@$this->criteria[$i][3]).'">';
×
942
         echo '<SELECT NAME="time['.$i.'][4]">'.dispYearOptions(@$this->criteria[$i][4]).'</SELECT>';
×
943

944
         echo '<INPUT TYPE="text" NAME="time['.$i.'][5]" SIZE=2 VALUE="'.htmlspecialchars(@$this->criteria[$i][5]).'"><B>:</B>';
×
945
         echo '<INPUT TYPE="text" NAME="time['.$i.'][6]" SIZE=2 VALUE="'.htmlspecialchars(@$this->criteria[$i][6]).'"><B>:</B>';
×
946
         echo '<INPUT TYPE="text" NAME="time['.$i.'][7]" SIZE=2 VALUE="'.htmlspecialchars(@$this->criteria[$i][7]).'">';
×
947

948
         echo '<SELECT NAME="time['.$i.'][8]"><OPTION VALUE=" " '.chk_select(@$this->criteria[$i][8]," ").'>__';
×
949
         echo '                               <OPTION VALUE="(" '.chk_select(@$this->criteria[$i][8],"(").'>(';
×
950
         echo '                               <OPTION VALUE=")" '.chk_select(@$this->criteria[$i][8],")").'>)</SELECT>';
×
951
         echo '<SELECT NAME="time['.$i.'][9]"><OPTION VALUE=" "   '.chk_select(@$this->criteria[$i][9]," ").  '>__';
×
952
         echo '                               <OPTION VALUE="OR" '.chk_select(@$this->criteria[$i][9],"OR").  '>'._OR;
×
953
         echo '                               <OPTION VALUE="AND" '.chk_select(@$this->criteria[$i][9],"AND").'>'._AND.'</SELECT>';
×
954
       
955
         if ( $i == $this->criteria_cnt-1 )
×
956
            echo '    <INPUT TYPE="submit" NAME="submit" VALUE="'._ADDTIME.'">';
×
957
         echo '<BR>';
×
958
      }
959
        }
960

961
        function ToSQL(){ // Convert this criteria to SQL.
962
        }
16✔
963

964
        function Description( $value ){
965
                $tmp = '';
×
966
     for ($i = 0; $i < $this->criteria_cnt; $i++)
×
967
     {
968
         if ( isset($this->criteria[$i][1]) && $this->criteria[$i][1] != " " )
×
969
         { 
970
            $tmp = $tmp.'<CODE>'.htmlspecialchars($this->criteria[$i][0]).' time '.htmlspecialchars($this->criteria[$i][1]).' [ ';
×
971

972
            /* date */
973
            if ( $this->criteria[$i][2] == " " && $this->criteria[$i][3] == "" && $this->criteria[$i][4] == " " )
×
974
               $tmp = $tmp." </CODE><I>any date</I><CODE>";
×
975
            else
976
               $tmp = $tmp.(($this->criteria[$i][2] == " ") ? "* / " : $this->criteria[$i][2]." / ").
×
977
                           (($this->criteria[$i][3] == "" ) ? "* / " : $this->criteria[$i][3]." / ").
×
978
                           (($this->criteria[$i][4] == " ") ? "*  " : $this->criteria[$i][4]." "); 
×
979
            $tmp = $tmp.'] [ ';
×
980
            /* time */
981
            if ( $this->criteria[$i][5] == "" && $this->criteria[$i][6] == "" && $this->criteria[$i][7] == "" )
×
982
               $tmp = $tmp."</CODE><I>any time</I><CODE>";
×
983
            else
984
               $tmp = $tmp.(($this->criteria[$i][5] == "") ? "* : " : $this->criteria[$i][5]." : ").
×
985
                           (($this->criteria[$i][6] == "") ? "* : " : $this->criteria[$i][6]." : ").
×
986
                           (($this->criteria[$i][7] == "") ? "*  " : $this->criteria[$i][7]." "); 
×
987
            $tmp = $tmp.$this->criteria[$i][8].'] '.$this->criteria[$i][9];
×
988
            $tmp = $tmp.'</CODE><BR>';
×
989
         }             
990
     }
991
     if ( $tmp != "" )
×
992
       $tmp = $tmp.$this->cs->GetClearCriteriaString($this->export_name);
×
993

994
                return $tmp;
×
995
        }
996
}; // TimeCriteria
997

998
class IPAddressCriteria extends MultipleElementCriteria {
999
// * $ip_addr[MAX][10]: stores an ip address parameters/operators row
1000
//  - [][0] : (                          [][5] : octet3 of address
1001
//  - [][1] : source, dest               [][6] : octet4 of address
1002
//  - [][2] : =, !=                      [][7] : network mask
1003
//  - [][3] : octet1 of address          [][8] : (, )
1004
//  - [][4] : octet2 of address          [][9] : AND, OR
1005
//
1006
// $ip_addr_cnt: number of rows in the $ip_addr[][] structure
1007

1008
        function __construct(
1009
                &$db, &$cs, $export_name, $element_cnt
1010
        ){ // PHP 5+ constructor Shim.
1011
                // Class/Method agnostic shim code.
1012
                $SCname = get_class();
80✔
1013
                if( method_exists($this, $SCname) ){
80✔
1014
                        $SCargs = func_get_args();
80✔
1015
                        // Custom non agnostic shim line for pass by refs.
1016
                        $SCargs = array(&$db, &$cs, $export_name, $element_cnt);
80✔
1017
                        call_user_func_array(array($this, $SCname), $SCargs);
80✔
1018
                }else{
24✔
1019
                        // @codeCoverageIgnoreStart
1020
                        // Should never execute.
1021
                        trigger_error( // Will need to add this message to the TD.
1022
                                "Class: $SCname No Legacy Constructor.\n",
1023
                                E_USER_ERROR
1024
                        );
1025
                        // @codeCoverageIgnoreEnd
1026
                }
1027
        }
56✔
1028

1029
        function IPAddressCriteria(
1030
                &$db, &$cs, $export_name, $element_cnt
1031
        ){ // PHP 4x constructor.
1032
                $tdb =& $db;
80✔
1033
                $cs =& $cs;
80✔
1034
                parent::MultipleElementCriteria(
80✔
1035
                        $tdb, $cs, $export_name, $element_cnt,
56✔
1036
                        array(
1037
                                "ip_src" => _SOURCE,
80✔
1038
                                "ip_dst" => _DEST,
56✔
1039
                                "ip_both" => _SORD
32✔
1040
                        )
24✔
1041
                );
24✔
1042
        }
56✔
1043

1044
        function Import(){
1045
                parent::Import(); // Store ourselves in the session.
×
1046
                if ( is_array($this->criteria) ){
×
1047
                        // Expand IP into octets.
1048
                        for ( $i = 0; $i < $this->criteria_cnt; $i++ ){
×
1049
        if ( (isset ($this->criteria[$i][3])) &&
×
1050
                        (preg_match("/([0-9]*)\.([0-9]*)\.([0-9]*)\.([0-9]*)/", $this->criteria[$i][3])) )
×
1051
        {
1052
           $tmp_ip_str = $this->criteria[$i][7] = $this->criteria[$i][3];
×
1053
           $this->criteria[$i][3] = strtok($tmp_ip_str, ".");
×
1054
           $this->criteria[$i][4] = strtok(".");
×
1055
           $this->criteria[$i][5] = strtok(".");
×
1056
           $this->criteria[$i][6] = strtok("/");
×
1057
           $this->criteria[$i][10] = strtok("");
×
1058
        }
1059
                        }
1060
                }
1061
      $_SESSION['ip_addr'] = &$this->criteria;
×
1062
      $_SESSION['ip_addr_cnt'] = &$this->criteria_cnt;
×
1063
        }
1064
        function Clear(){
1065
                // Clears the criteria.
1066
        }
14✔
1067
        function SanitizeElement($value) {
1068
                $i = 0; // Why is this function hardwired to check only the first
×
1069
                // criteria instance? Leaving it for now, but need to investigate.
1070
                // 2019-07-12 Nathan
1071
      // Make copy of old element array
1072
      $curArr = $this->criteria[$i];
×
1073
      // Sanitize element
1074
      $this->criteria[$i][0] = @CleanVariable($curArr[0], VAR_OPAREN);
×
1075
      $this->criteria[$i][1] = @CleanVariable($curArr[1], "", array_keys($this->valid_field_list));
×
1076
      $this->criteria[$i][2] = @CleanVariable($curArr[2], "", array("=", "!=", "<", "<=", ">", ">="));
×
1077
      $this->criteria[$i][3] = @CleanVariable($curArr[3], VAR_DIGIT);
×
1078
      $this->criteria[$i][4] = @CleanVariable($curArr[4], VAR_DIGIT);
×
1079
      $this->criteria[$i][5] = @CleanVariable($curArr[5], VAR_DIGIT);
×
1080
      $this->criteria[$i][6] = @CleanVariable($curArr[6], VAR_DIGIT);
×
1081
      $this->criteria[$i][7] = @CleanVariable($curArr[7], VAR_DIGIT | VAR_PERIOD | VAR_FSLASH);
×
1082
      $this->criteria[$i][8] = @CleanVariable($curArr[8], VAR_OPAREN | VAR_CPAREN);
×
1083
      $this->criteria[$i][9] = @CleanVariable($curArr[9], "", array("AND", "OR"));
×
1084
      // Destroy copy
1085
      unset($curArr);
×
1086
        }
1087
        function PrintForm($value1, $value2, $value3) {
1088
                GLOBAL $debug_mode;
1089
                for ( $i = 0; $i < $this->criteria_cnt; $i++ ){
×
1090
                        if (!is_array($this->criteria[$i])){
×
1091
                                if ( $debug_mode > 0 ){
×
1092
                                        $this->CTIFD(__CLASS__ . '::' . __FUNCTION__);
×
1093
                                        print __FUNCTION__.": Criteria Data Error Detected<br/>\n";
×
1094
                                        print "Re Initializing<br/>\n";
×
1095
                                }
1096
                                $this->Init();
×
1097
                        }
1098
         echo '    <SELECT NAME="ip_addr['.$i.'][0]"><OPTION VALUE=" " '.chk_select(@$this->criteria[$i][0]," ").'>__'; 
×
1099
         echo '                                      <OPTION VALUE="(" '.chk_select(@$this->criteria[$i][0],"(").'>(</SELECT>';
×
1100
         echo '    <SELECT NAME="ip_addr['.$i.'][1]">
×
1101
                    <OPTION VALUE=" "      '.chk_select(@$this->criteria[$i][1]," "     ).'>'._DISPADDRESS.'
×
1102
                    <OPTION VALUE="ip_src" '.chk_select(@$this->criteria[$i][1],"ip_src").'>'._SHORTSOURCE.'
×
1103
                    <OPTION VALUE="ip_dst" '.chk_select(@$this->criteria[$i][1],"ip_dst").'>'._SHORTDEST.'
×
1104
                    <OPTION VALUE="ip_both" '.chk_select(@$this->criteria[$i][1],"ip_both").'>'._SHORTSOURCEORDEST.'
×
1105
                   </SELECT>'; 
1106
         echo '    <SELECT NAME="ip_addr['.$i.'][2]">
×
1107
                    <OPTION VALUE="="  '.chk_select(@$this->criteria[$i][2],"="). '>=
×
1108
                    <OPTION VALUE="!=" '.chk_select(@$this->criteria[$i][2],"!=").'>!=
×
1109
                   </SELECT>';
1110
                if( is_key('ip_address_input', $GLOBALS) ){ // Issue #53
×
1111
                        $tmp = $GLOBALS['ip_address_input'];
×
1112
                }else{
1113
                        $tmp = 2;
×
1114
                }
1115
                if ( $tmp == 2 ){
×
1116
           echo  '    <INPUT TYPE="text" NAME="ip_addr['.$i.'][3]" SIZE=16 VALUE="'.htmlspecialchars(@$this->criteria[$i][7]).'">';
×
1117
                }else{
1118
           echo '    <INPUT TYPE="text" NAME="ip_addr['.$i.'][3]" SIZE=3 VALUE="'.htmlspecialchars(@$this->criteria[$i][3]).'"><B>.</B>';
×
1119
           echo '    <INPUT TYPE="text" NAME="ip_addr['.$i.'][4]" SIZE=3 VALUE="'.htmlspecialchars(@$this->criteria[$i][4]).'"><B>.</B>';
×
1120
           echo '    <INPUT TYPE="text" NAME="ip_addr['.$i.'][5]" SIZE=3 VALUE="'.htmlspecialchars(@$this->criteria[$i][5]).'"><B>.</B>';
×
1121
           echo '    <INPUT TYPE="text" NAME="ip_addr['.$i.'][6]" SIZE=3 VALUE="'.htmlspecialchars(@$this->criteria[$i][6]).'"><!--<B>/</B>';
×
1122
           echo '    <INPUT TYPE="text" NAME="ip_addr['.$i.'][7]" SIZE=3 VALUE="'.htmlspecialchars(@$this->criteria[$i][7]).'">-->'; 
×
1123
                }
1124
        echo '    <SELECT NAME="ip_addr['.$i.'][8]"><OPTION VALUE=" " '.chk_select(@$this->criteria[$i][8]," ").'>__';
×
1125
        echo '                                      <OPTION VALUE="(" '.chk_select(@$this->criteria[$i][8],"(").'>(';
×
1126
        echo '                                      <OPTION VALUE=")" '.chk_select(@$this->criteria[$i][8],")").'>)</SELECT>';
×
1127
        echo '    <SELECT NAME="ip_addr['.$i.'][9]"><OPTION VALUE=" "   '.chk_select(@$this->criteria[$i][9]," ").  '>__';
×
1128
        echo '                                      <OPTION VALUE="OR" '.chk_select(@$this->criteria[$i][9],"OR").  '>'._OR;
×
1129
        echo '                                      <OPTION VALUE="AND" '.chk_select(@$this->criteria[$i][9],"AND").'>'._AND.'</SELECT>';
×
1130
        if ( $i == $this->criteria_cnt-1 )
×
1131
          echo '    <INPUT TYPE="submit" NAME="submit" VALUE="'._ADDADDRESS.'">';
×
1132
        echo '<BR>';
×
1133
      }
1134
        }
1135
        function ToSQL(){
1136
                // Convert this criteria to SQL.
1137
        }
14✔
1138
        function Description($value) {
1139
      $human_fields["ip_src"] = _SOURCE;
×
1140
      $human_fields["ip_dst"] = _DEST;
×
1141
      $human_fields["ip_both"] = _SORD;
×
1142
      $human_fields[""] = ""; 
×
1143
      $human_fields["LIKE"] = _CONTAINS;
×
1144
      $human_fields["="] = "=";  
×
1145

1146
      $tmp2 = "";
×
1147

1148
      for ( $i = 0; $i < $this->criteria_cnt; $i++ )
×
1149
      {
1150
         $tmp = "";
×
1151
         if ( isset($this->criteria[$i][3]) && $this->criteria[$i][3] != "" )
×
1152
         {
1153
            $tmp = $tmp.$this->criteria[$i][3];
×
1154
            if ( $this->criteria[$i][4] != "" )
×
1155
            {
1156
               $tmp = $tmp.".".$this->criteria[$i][4];
×
1157
               if ( $this->criteria[$i][5] != "" )
×
1158
               {
1159
                  $tmp = $tmp.".".$this->criteria[$i][5];
×
1160
                  if ( $this->criteria[$i][6] != "" )
×
1161
                  {
1162
                     if ( ($this->criteria[$i][3].".".$this->criteria[$i][4].".".
×
1163
                        $this->criteria[$i][5].".".$this->criteria[$i][6]) == NULL_IP)
×
1164
                        $tmp = " unknown ";
×
1165
                     else
1166
                        $tmp = $tmp.".".$this->criteria[$i][6];
×
1167
                  }
1168
                  else
1169
                     $tmp = $tmp.'.*';
×
1170
               }
1171
               else
1172
                  $tmp = $tmp.'.*.*';
×
1173
            }
1174
            else
1175
               $tmp = $tmp.'.*.*.*';
×
1176
         }
1177
         /* Make sure that the IP isn't blank */
1178
         if ( $tmp != "" )
×
1179
         {
1180
            $mask = "";
×
1181
            if ( $this->criteria[$i][10] != "" )
×
1182
               $mask = "/".$this->criteria[$i][10];
×
1183

1184
             $tmp2 = $tmp2.$this->criteria[$i][0].
×
1185
                     $human_fields[($this->criteria[$i][1])].' '.$this->criteria[$i][2].
×
1186
                     ' '.$tmp.' '.$this->criteria[$i][8].' '.$this->criteria[$i][9].$mask.
×
1187
                     $this->cs->GetClearCriteriaString($this->export_name)."<BR>";
×
1188
         }
1189
                }
1190
                return $tmp2;
×
1191
        }
1192
};  /* IPAddressCriteria */
1193

1194
class IPFieldCriteria extends ProtocolFieldCriteria {
1195
// $ip_field[MAX][6]: stores all other ip fields parameters/operators row
1196
//  - [][0] : (                            [][3] : field value
1197
//  - [][1] : TOS, TTL, ID, offset, length [][4] : (, )
1198
//  - [][2] : =, !=, <, <=, >, >=          [][5] : AND, OR
1199
//
1200
// $ip_field_cnt: number of rows in the $ip_field[][] structure
1201

1202
        function __construct(
1203
                &$db, &$cs, $export_name, $element_cnt
1204
        ) { // PHP 5+ constructor Shim.
1205
                // Class/Method agnostic shim code.
1206
                $SCname = get_class();
×
1207
                if ( method_exists($this, $SCname) ) {
×
1208
                        $SCargs = func_get_args();
×
1209
                        // Custom non agnostic shim line for pass by refs.
1210
                        $SCargs = array(&$db, &$cs, $export_name, $element_cnt);
×
1211
                        call_user_func_array(array($this, $SCname), $SCargs);
×
1212
                }else{
1213
                        // @codeCoverageIgnoreStart
1214
                        // Should never execute.
1215
                        trigger_error( // Will need to add this message to the TD.
1216
                                "Class: $SCname No Legacy Constructor.\n",
1217
                                E_USER_ERROR
1218
                        );
1219
                        // @codeCoverageIgnoreEnd
1220
                }
1221
        }
1222
        function IPFieldCriteria(
1223
                &$db, &$cs, $export_name, $element_cnt
1224
        ) { // PHP 4x constructor.
1225
                $tdb =& $db;
×
1226
                $cs =& $cs;
×
1227
                parent::ProtocolFieldCriteria(
×
1228
                        $tdb, $cs, $export_name, $element_cnt,
1229
                        array(
1230
                                "ip_tos"  => "TOS",
×
1231
                                "ip_ttl"  => "TTL",
1232
                                "ip_id"   => "ID",
1233
                                "ip_off"  => "offset",
1234
                                "ip_csum" => "chksum",
1235
                                "ip_len"  => "length"
1236
                        )
1237
                );
1238
        }
1239
        function PrintForm($value1, $value2, $value3) {
1240
                parent::PrintForm($this->valid_field_list, _DISPFIELD, _ADDIPFIELD);
×
1241
        }
1242
   function ToSQL()
1243
   {
1244
     /* convert this criteria to SQL */
1245
   }
1246
        function Description($value) {
1247
      return parent::Description( array_merge( array ( "" => "", 
×
1248
                                                       "LIKE" => _CONTAINS,
1249
                                                       "=" => "="), $this->valid_field_list ) );  
×
1250
        }
1251
};
1252

1253
class TCPPortCriteria extends ProtocolFieldCriteria {
1254
// $tcp_port[MAX][6]: stores all port parameters/operators row
1255
//  - [][0] : (                            [][3] : port value
1256
//  - [][1] : Source Port, Dest Port       [][4] : (, )
1257
//  - [][2] : =, !=, <, <=, >, >=          [][5] : AND, OR
1258
//
1259
// $tcp_port_cnt: number of rows in the $tcp_port[][] structure
1260

1261
        function __construct(
1262
                &$db, &$cs, $export_name, $element_cnt
1263
        ) { // PHP 5+ constructor Shim.
1264
                // Class/Method agnostic shim code.
1265
                $SCname = get_class();
×
1266
                if ( method_exists($this, $SCname) ) {
×
1267
                        $SCargs = func_get_args();
×
1268
                        // Custom non agnostic shim line for pass by refs.
1269
                        $SCargs = array(&$db, &$cs, $export_name, $element_cnt);
×
1270
                        call_user_func_array(array($this, $SCname), $SCargs);
×
1271
                }else{
1272
                        // @codeCoverageIgnoreStart
1273
                        // Should never execute.
1274
                        trigger_error( // Will need to add this message to the TD.
1275
                                "Class: $SCname No Legacy Constructor.\n",
1276
                                E_USER_ERROR
1277
                        );
1278
                        // @codeCoverageIgnoreEnd
1279
                }
1280
        }
1281
        function TCPPortCriteria(
1282
                &$db, &$cs, $export_name, $element_cnt
1283
        ) { // PHP 4x constructor.
1284
                $tdb =& $db;
×
1285
                $cs =& $cs;
×
1286
                parent::ProtocolFieldCriteria(
×
1287
                        $tdb, $cs, $export_name, $element_cnt,
1288
                        array (
1289
                                "layer4_sport" => _SOURCEPORT,
×
1290
                                "layer4_dport" => _DESTPORT
1291
                        )
1292
                );
1293
        }
1294
        function PrintForm($value1, $value2, $value3) {
1295
                parent::PrintForm($this->valid_field_list, _DISPPORT, _ADDTCPPORT);
×
1296
        }
1297
   function ToSQL()
1298
   {
1299
     /* convert this criteria to SQL */
1300
   }
1301
        function Description($value) {
1302
                return parent::Description(array_merge( array("" => "",  
×
1303
                                                    "=" => "="), $this->valid_field_list) );
×
1304
        }
1305
};  /* TCPPortCriteria */
1306

1307
class TCPFieldCriteria extends ProtocolFieldCriteria {
1308
// TCP Variables
1309
// =============
1310
// $tcp_field[MAX][6]: stores all other tcp fields parameters/operators row
1311
//  - [][0] : (                            [][3] : field value
1312
//  - [][1] : windows, URP                 [][4] : (, )
1313
//  - [][2] : =, !=, <, <=, >, >=          [][5] : AND, OR
1314
//
1315
// $tcp_field_cnt: number of rows in the $tcp_field[][] structure
1316

1317
        function __construct(
1318
                &$db, &$cs, $export_name, $element_cnt
1319
        ) { // PHP 5+ constructor Shim.
1320
                // Class/Method agnostic shim code.
1321
                $SCname = get_class();
×
1322
                if ( method_exists($this, $SCname) ) {
×
1323
                        $SCargs = func_get_args();
×
1324
                        // Custom non agnostic shim line for pass by refs.
1325
                        $SCargs = array(&$db, &$cs, $export_name, $element_cnt);
×
1326
                        call_user_func_array(array($this, $SCname), $SCargs);
×
1327
                }else{
1328
                        // @codeCoverageIgnoreStart
1329
                        // Should never execute.
1330
                        trigger_error( // Will need to add this message to the TD.
1331
                                "Class: $SCname No Legacy Constructor.\n",
1332
                                E_USER_ERROR
1333
                        );
1334
                        // @codeCoverageIgnoreEnd
1335
                }
1336
        }
1337
        function TCPFieldCriteria(
1338
                &$db, &$cs, $export_name, $element_cnt
1339
        ) { // PHP 4x constructor.
1340
                $tdb =& $db;
×
1341
                $cs =& $cs;
×
1342
                parent::ProtocolFieldCriteria(
×
1343
                        $tdb, $cs, $export_name, $element_cnt,
1344
                        array (
1345
                                "tcp_win" => "window",
×
1346
                                "tcp_urp" => "urp",
1347
                                "tcp_seq" => "seq #",
1348
                                "tcp_ack" => "ack",
1349
                                "tcp_off" => "offset",
1350
                                "tcp_res" => "res",
1351
                                "tcp_csum" => "chksum"
1352
                        )
1353
                );
1354
        }
1355
        function PrintForm($value1, $value2, $value3) {
1356
                parent::PrintForm($this->valid_field_list, _DISPFIELD, _ADDTCPFIELD);
×
1357
        }
1358
   function ToSQL()
1359
   {
1360
     /* convert this criteria to SQL */
1361
   }
1362
        function Description($value) {
1363
                return parent::Description(array_merge ( array("" => ""), $this->valid_field_list) );
×
1364
        }
1365
};  /* TCPFieldCriteria */
1366

1367
class TCPFlagsCriteria extends SingleElementCriteria{
1368
        // $tcp_flags[9]: stores all other tcp flags parameters/operators row
1369
        //  - [0] : is, contains                   [5] : 16    (ACK)
1370
        //  - [1] : 1   (FIN)                      [6] : 32    (URG)
1371
        //  - [2] : 2   (SYN)                      [7] : 64    (RSV0)
1372
        //  - [3] : 4   (PUSH)                     [8] : 128   (RSV1)
1373
        //  - [4] : 8   (RST)
1374

1375
        function Init(){
1376
                InitArray($this->criteria, TCPFLAGS_CFCNT, 0, '');
88✔
1377
        }
64✔
1378
        function Import(){
1379
                $tmp = SetSessionVar($this->export_name);
44✔
1380
                if ( is_array($tmp) ){ // Type Lock criteria import. Fixes Issue #10.
44✔
1381
                        parent::Import(); // Store ourselves in the session.
22✔
1382
                        $SF = true;
22✔
1383
                }else{
8✔
1384
                        $SF = false;
22✔
1385
                }
1386
                $this->CTIFD(__CLASS__ . '::' . __FUNCTION__,$SF);
44✔
1387
        }
32✔
1388
        function Clear(){
1389
                // Clears the criteria.
1390
        }
16✔
1391
        function SanitizeElement($value) {
1392
                $this->criteria = CleanVariable($this->criteria, VAR_DIGIT);
×
1393
        }
1394
        function PrintForm($value1, $value2, $value3) {
1395
                GLOBAL $debug_mode;
1396
                if (!is_array($this->criteria)){
×
1397
                        $this->CTIFD(__CLASS__ . '::' . __FUNCTION__);
×
1398
                        print __FUNCTION__.": Criteria Data Error Detected<br/>\n";
×
1399
                        print "Re Initializing<br/>\n";
×
1400
                        $this->Init();
×
1401
                }
1402
      echo '<TD><SELECT NAME="tcp_flags[0]"><OPTION VALUE=" " '.chk_select($this->criteria[0]," ").'>'._DISPFLAGS;
×
1403
      echo '                              <OPTION VALUE="is" '.chk_select($this->criteria[0],"is").'>'._IS;
×
1404
      echo '                              <OPTION VALUE="contains" '.chk_select($this->criteria[0],"contains").'>'._CONTAINS.'</SELECT>';
×
1405
      echo '   <FONT>';
×
1406
      echo '    <INPUT TYPE="checkbox" NAME="tcp_flags[8]" VALUE="128" '.chk_check($this->criteria[8],"128").'> [RSV1] &nbsp'; 
×
1407
      echo '    <INPUT TYPE="checkbox" NAME="tcp_flags[7]" VALUE="64"  '.chk_check($this->criteria[7],"64").'> [RSV0] &nbsp';
×
1408
      echo '    <INPUT TYPE="checkbox" NAME="tcp_flags[6]" VALUE="32"  '.chk_check($this->criteria[6],"32").'> [URG] &nbsp';
×
1409
      echo '    <INPUT TYPE="checkbox" NAME="tcp_flags[5]" VALUE="16"  '.chk_check($this->criteria[5],"16").'> [ACK] &nbsp';
×
1410
      echo '    <INPUT TYPE="checkbox" NAME="tcp_flags[3]" VALUE="8"   '.chk_check($this->criteria[4],"8").'> [PSH] &nbsp'; 
×
1411
      echo '    <INPUT TYPE="checkbox" NAME="tcp_flags[4]" VALUE="4"   '.chk_check($this->criteria[3],"4").'> [RST] &nbsp';
×
1412
      echo '    <INPUT TYPE="checkbox" NAME="tcp_flags[2]" VALUE="2"   '.chk_check($this->criteria[2],"2").'> [SYN] &nbsp';
×
1413
      echo '    <INPUT TYPE="checkbox" NAME="tcp_flags[1]" VALUE="1"   '.chk_check($this->criteria[1],"1").'> [FIN] &nbsp';
×
1414
      echo '  </FONT>';
×
1415
        }
1416
        function ToSQL(){
1417
                // Convert this criteria to SQL.
1418
        }
16✔
1419
        function Description($value) {
1420
      $human_fields["1"] = "F";
×
1421
      $human_fields["2"] = "S";
×
1422
      $human_fields["4"] = "R";
×
1423
      $human_fields["8"] = "P";
×
1424
      $human_fields["16"] = "A";
×
1425
      $human_fields["32"] = "U";
×
1426
      $human_fields["64"] = "[R0]";
×
1427
      $human_fields["128"] = "[R1]";
×
1428
      $human_fields["LIKE"] = _CONTAINS;
×
1429
      $human_fields["="] = "="; 
×
1430

1431
      $tmp = "";
×
1432

1433
      if ( isset($this->criteria[0]) && ($this->criteria[0] != " ") && ($this->criteria[0] != "") )
×
1434
      {
1435
         $tmp = $tmp.'flags '.$this->criteria[0].' ';
×
1436
         for ( $i = 8; $i >=1; $i-- )
×
1437
            if ( $this->criteria[$i] == "" )
×
1438
               $tmp = $tmp.'-';
×
1439
            else
1440
               $tmp = $tmp.$human_fields[($this->criteria[$i])];
×
1441

1442
         $tmp = $tmp.$this->cs->GetClearCriteriaString("tcp_flags").'<BR>';
×
1443
      }
1444
                return $tmp;
×
1445
        }
1446
        function isEmpty(){
1447
                $Ret = false;
88✔
1448
                $TD = array ('', ' '); // Test Values
88✔
1449
                if ( is_null($this->criteria) || in_array($this->criteria[0], $TD) ){
88✔
1450
                        $Ret = true;
66✔
1451
                }
24✔
1452
                return $Ret;
88✔
1453
        }
1454
};  /* TCPFlagCriteria */
1455

1456
class UDPPortCriteria extends ProtocolFieldCriteria {
1457
// $udp_port[MAX][6]: stores all port parameters/operators row
1458
//  - [][0] : (                            [][3] : port value
1459
//  - [][1] : Source Port, Dest Port       [][4] : (, )
1460
//  - [][2] : =, !=, <, <=, >, >=          [][5] : AND, OR
1461
//
1462
// $udp_port_cnt: number of rows in the $udp_port[][] structure
1463

1464
        function __construct(
1465
                &$db, &$cs, $export_name, $element_cnt
1466
        ) { // PHP 5+ constructor Shim.
1467
                // Class/Method agnostic shim code.
1468
                $SCname = get_class();
×
1469
                if ( method_exists($this, $SCname) ) {
×
1470
                        $SCargs = func_get_args();
×
1471
                        // Custom non agnostic shim line for pass by refs.
1472
                        $SCargs = array(&$db, &$cs, $export_name, $element_cnt);
×
1473
                        call_user_func_array(array($this, $SCname), $SCargs);
×
1474
                }else{
1475
                        // @codeCoverageIgnoreStart
1476
                        // Should never execute.
1477
                        trigger_error( // Will need to add this message to the TD.
1478
                                "Class: $SCname No Legacy Constructor.\n",
1479
                                E_USER_ERROR
1480
                        );
1481
                        // @codeCoverageIgnoreEnd
1482
                }
1483
        }
1484
        function UDPPortCriteria(
1485
                &$db, &$cs, $export_name, $element_cnt
1486
        ) { // PHP 4x constructor.
1487
                $tdb =& $db;
×
1488
                $cs =& $cs;
×
1489
                parent::ProtocolFieldCriteria(
×
1490
                        $tdb, $cs, $export_name, $element_cnt,
1491
                        array (
1492
                                "layer4_sport" => _SOURCEPORT,
×
1493
                                "layer4_dport" => _DESTPORT
1494
                        )
1495
                );
1496
        }
1497
        function PrintForm($value1, $value2, $value3) {
1498
                parent::PrintForm($this->valid_field_list, _DISPPORT, _ADDUDPPORT);
×
1499
        }
1500
   function ToSQL()
1501
   {
1502
     /* convert this criteria to SQL */
1503
   }
1504
        function Description($value) {
1505
                return parent::Description(array_merge( array("" => "",  
×
1506
                                                    "=" => "="), $this->valid_field_list) );
×
1507
        }
1508
};  /* UDPPortCriteria */
1509

1510
class UDPFieldCriteria extends ProtocolFieldCriteria {
1511
// $udp_field[MAX][6]: stores all other udp fields parameters/operators row
1512
//  - [][0] : (                            [][3] : field value
1513
//  - [][1] : length                       [][4] : (, )
1514
//  - [][2] : =, !=, <, <=, >, >=          [][5] : AND, OR
1515
//
1516
// $udp_field_cnt: number of rows in the $udp_field[][] structure
1517

1518
        function __construct(
1519
                &$db, &$cs, $export_name, $element_cnt
1520
        ) { // PHP 5+ constructor Shim.
1521
                // Class/Method agnostic shim code.
1522
                $SCname = get_class();
×
1523
                if ( method_exists($this, $SCname) ) {
×
1524
                        $SCargs = func_get_args();
×
1525
                        // Custom non agnostic shim line for pass by refs.
1526
                        $SCargs = array(&$db, &$cs, $export_name, $element_cnt);
×
1527
                        call_user_func_array(array($this, $SCname), $SCargs);
×
1528
                }else{
1529
                        // @codeCoverageIgnoreStart
1530
                        // Should never execute.
1531
                        trigger_error( // Will need to add this message to the TD.
1532
                                "Class: $SCname No Legacy Constructor.\n",
1533
                                E_USER_ERROR
1534
                        );
1535
                        // @codeCoverageIgnoreEnd
1536
                }
1537
        }
1538
        function UDPFieldCriteria(
1539
                &$db, &$cs, $export_name, $element_cnt
1540
        ) { // PHP 4x constructor.
1541
                $tdb =& $db;
×
1542
                $cs =& $cs;
×
1543
                parent::ProtocolFieldCriteria(
×
1544
                        $tdb, $cs, $export_name, $element_cnt,
1545
                        array (
1546
                                "udp_len" => "length",
×
1547
                                "udp_csum" => "chksum"
1548
                        )
1549
                );
1550
        }
1551
        function PrintForm($value1, $value2, $value3) {
1552
                parent::PrintForm($this->valid_field_list, _DISPFIELD, _ADDUDPFIELD);
×
1553
        }
1554
   function ToSQL()
1555
   {
1556
     /* convert this criteria to SQL */
1557
   }
1558
        function Description($value) {
1559
                return parent::Description(array_merge ( array("" => ""), $this->valid_field_list) );
×
1560
        }
1561
};  /* UDPFieldCriteria */
1562

1563
class ICMPFieldCriteria extends ProtocolFieldCriteria {
1564
// $icmp_field[MAX][6]: stores all other icmp fields parameters/operators row
1565
//  - [][0] : (                            [][3] : field value
1566
//  - [][1] : code, length                 [][4] : (, )
1567
//  - [][2] : =, !=, <, <=, >, >=          [][5] : AND, OR
1568
//
1569
// $icmp_field_cnt: number of rows in the $icmp_field[][] structure
1570

1571
        function __construct(
1572
                &$db, &$cs, $export_name, $element_cnt
1573
        ) { // PHP 5+ constructor Shim.
1574
                // Class/Method agnostic shim code.
1575
                $SCname = get_class();
×
1576
                if ( method_exists($this, $SCname) ) {
×
1577
                        $SCargs = func_get_args();
×
1578
                        // Custom non agnostic shim line for pass by refs.
1579
                        $SCargs = array(&$db, &$cs, $export_name, $element_cnt);
×
1580
                        call_user_func_array(array($this, $SCname), $SCargs);
×
1581
                }else{
1582
                        // @codeCoverageIgnoreStart
1583
                        // Should never execute.
1584
                        trigger_error( // Will need to add this message to the TD.
1585
                                "Class: $SCname No Legacy Constructor.\n",
1586
                                E_USER_ERROR
1587
                        );
1588
                        // @codeCoverageIgnoreEnd
1589
                }
1590
        }
1591
        function ICMPFieldCriteria(
1592
                &$db, &$cs, $export_name, $element_cnt
1593
        ) { // PHP 4x constructor.
1594
                $tdb =& $db;
×
1595
                $cs =& $cs;
×
1596
                parent::ProtocolFieldCriteria(
×
1597
                        $tdb, $cs, $export_name, $element_cnt,
1598
                        array (
1599
                                "icmp_type" => "type",
×
1600
                                "icmp_code" => "code",
1601
                                "icmp_id"   => "id",
1602
                                "icmp_seq"  => "seq #",
1603
                                "icmp_csum" => "chksum"
1604
                        )
1605
                );
1606
        }
1607
        function PrintForm($value1, $value2, $value3) {
1608
                parent::PrintForm($this->valid_field_list, _DISPFIELD, _ADDICMPFIELD);
×
1609
        }
1610
   function ToSQL()
1611
   {
1612
     /* convert this criteria to SQL */
1613
   }
1614
        function Description($value) {
1615
                return parent::Description(array_merge ( array("" => ""), $this->valid_field_list) );
×
1616
        }
1617
};  /* ICMPFieldCriteria */
1618

1619
class Layer4Criteria extends SingleElementCriteria
1620
{
1621
   function Init()
1622
   {
1623
      $this->criteria = "";
×
1624
   }
1625

1626
   function Clear()
1627
   {
1628
     /* clears the criteria */
1629
   }
1630
        function SanitizeElement($value) {
1631
                $this->criteria = CleanVariable($this->criteria, "", array("UDP", "TCP", "ICMP", "RawIP"));
×
1632
        }
1633
        function PrintForm($value1, $value2, $value3) {
1634
      if ( $this->criteria != "" )
×
1635
         echo '<INPUT TYPE="submit" NAME="submit" VALUE="'._NOLAYER4.'"> &nbsp';
×
1636
      if ( $this->criteria == "TCP" )
×
1637
         echo '  
×
1638
           <INPUT TYPE="submit" NAME="submit" VALUE="UDP"> &nbsp
1639
           <INPUT TYPE="submit" NAME="submit" VALUE="ICMP">';
1640
      else if ( $this->criteria == "UDP" )
×
1641
         echo '  
×
1642
           <INPUT TYPE="submit" NAME="submit" VALUE="TCP"> &nbsp
1643
           <INPUT TYPE="submit" NAME="submit" VALUE="ICMP">';
1644
      else if ( $this->criteria == "ICMP" )
×
1645
         echo '  
×
1646
           <INPUT TYPE="submit" NAME="submit" VALUE="TCP"> &nbsp
1647
           <INPUT TYPE="submit" NAME="submit" VALUE="UDP">';
1648
      else
1649
         echo '  
1650
           <INPUT TYPE="submit" NAME="submit" VALUE="TCP"> &nbsp
1651
           <INPUT TYPE="submit" NAME="submit" VALUE="UDP">
1652
           <INPUT TYPE="submit" NAME="submit" VALUE="ICMP">';
1653
        }
1654
   function ToSQL()
1655
   {
1656
     /* convert this criteria to SQL */
1657
   }
1658
        function Description($value) {
1659
      if ( $this->criteria == "TCP" )
×
1660
         return _QCTCPCRIT;
×
1661
      else if ( $this->criteria == "UDP" )
×
1662
         return _QCUDPCRIT;
×
1663
      else if ( $this->criteria == "ICMP" )
×
1664
         return _QCICMPCRIT ;
×
1665
      else
1666
         return _QCLAYER4CRIT;
×
1667
        }
1668
};  /* Layer4Criteria */
1669

1670
class DataCriteria extends MultipleElementCriteria {
1671
// $data_encode[2]: how the payload should be interpreted and converted
1672
//  - [0] : encoding type (hex, ascii)
1673
//  - [1] : conversion type (hex, ascii)
1674
//
1675
// $data[MAX][5]: stores all the payload related parameters/operators row
1676
//  - [][0] : (                            [][3] : (, )
1677
//  - [][1] : =, !=                        [][4] : AND, OR
1678
//  - [][2] : field value
1679
//
1680
// $data_cnt: number of rows in the $data[][] structure
1681
        var $data_encode = array();
1682

1683
        function __construct(
1684
                &$db, &$cs, $export_name, $element_cnt
1685
        ) { // PHP 5+ constructor Shim.
1686
                // Class/Method agnostic shim code.
1687
                $SCname = get_class();
160✔
1688
                if ( method_exists($this, $SCname) ) {
160✔
1689
                        $SCargs = func_get_args();
160✔
1690
                        // Custom non agnostic shim line for pass by refs.
1691
                        $SCargs = array(&$db, &$cs, $export_name, $element_cnt);
160✔
1692
                        call_user_func_array(array($this, $SCname), $SCargs);
160✔
1693
                }else{
48✔
1694
                        // @codeCoverageIgnoreStart
1695
                        // Should never execute.
1696
                        trigger_error( // Will need to add this message to the TD.
1697
                                "Class: $SCname No Legacy Constructor.\n",
1698
                                E_USER_ERROR
1699
                        );
1700
                        // @codeCoverageIgnoreEnd
1701
                }
1702
        }
112✔
1703
        function DataCriteria(
1704
                &$db, &$cs, $export_name, $element_cnt
1705
        ) { // PHP 4x constructor.
1706
                $tdb =& $db;
160✔
1707
                $cs =& $cs;
160✔
1708
                parent::MultipleElementCriteria(
160✔
1709
                        $tdb, $cs, $export_name, $element_cnt,
112✔
1710
                        array (
1711
                                "LIKE" => _HAS,
160✔
1712
                                "NOT LIKE" => _HASNOT
64✔
1713
                        )
48✔
1714
                );
48✔
1715
                InitArray($this->data_encode, 2, 0, '');
160✔
1716
        }
112✔
1717
        function Init(){
1718
                parent::Init();
20✔
1719
                InitArray($this->data_encode, 2, 0, '');
20✔
1720
        }
14✔
1721
        function Import(){
1722
                GLOBAL $debug_mode;
42✔
1723
                parent::Import(); // Store ourselves in the session.
60✔
1724
                $tmp = SetSessionVar("data_encode");
60✔
1725
                if ( is_array($tmp) ){ // Type Lock Property import. Fixes Issue #10.
60✔
1726
                        $this->data_encode = $tmp;
20✔
1727
                        $ISF = true;
20✔
1728
                }else{
6✔
1729
                        $ISF = false;
40✔
1730
                }
1731
                $_SESSION['data_encode'] = &$this->data_encode;
60✔
1732
                if ( $debug_mode > 1 ){
60✔
1733
                        $this->CTIFD(__CLASS__ . '::' . __FUNCTION__);
60✔
1734
                        ErrorMessage(
60✔
1735
                                "Property Type: " . gettype($tmp), 'black', 1
60✔
1736
                        );
18✔
1737
                        if ( is_bool($ISF) ){
60✔
1738
                                $msg = 'Property '.__FUNCTION__.': ';
60✔
1739
                                if ($ISF){
60✔
1740
                                        $msg .= 'Allowed';
20✔
1741
                                }else{
6✔
1742
                                        $msg .= 'Denied';
40✔
1743
                                }
1744
                                $msg .= '.';
60✔
1745
                                ErrorMessage($msg, 'black', 1);
60✔
1746
                        }
18✔
1747
                }
18✔
1748
        }
42✔
1749
        function Clear(){
1750
                // Clears the criteria.
1751
        }
14✔
1752
   function SanitizeElement($i)
1753
   {
1754
      $this->data_encode[0] = CleanVariable($this->data_encode[0], "", array("hex", "ascii"));
×
1755
      $this->data_encode[1] = CleanVariable($this->data_encode[1], "", array("hex", "ascii"));
×
1756
      // Make a copy of the element array
1757
      $curArr = $this->criteria[$i];
×
1758
      // Sanitize the array
1759
      $this->criteria[$i][0] = CleanVariable($curArr[0], VAR_OPAREN);
×
1760
      $this->criteria[$i][1] = CleanVariable($curArr[1], "", array_keys($this->valid_field_list));
×
1761
      $this->criteria[$i][2] = CleanVariable($curArr[2], VAR_FSLASH | VAR_PERIOD | VAR_DIGIT | VAR_PUNC | VAR_LETTER );
×
1762
      $this->criteria[$i][3] = CleanVariable($curArr[3], VAR_OPAREN | VAR_CPAREN);
×
1763
      $this->criteria[$i][4] = CleanVariable($curArr[4], "", array("AND", "OR"));
×
1764
      // Destroy the copy
1765
      unset($curArr);
×
1766
   }
1767
        function PrintForm($value1, $value2, $value3) {
1768
                GLOBAL $debug_mode;
1769
                if (!is_array($this->criteria[0])){
×
1770
                        if ( $debug_mode > 0 ){
×
1771
                                $this->CTIFD(__CLASS__ . '::' . __FUNCTION__);
×
1772
                                print __FUNCTION__.": Criteria Data Error Detected<br/>\n";
×
1773
                                print "Re Initializing<br/>\n";
×
1774
                        }
1775
                        $this->Init();
×
1776
                }
1777
      echo '<B>'._INPUTCRTENC.':</B>';
×
1778
      echo '<SELECT NAME="data_encode[0]"><OPTION VALUE=" "    '.chk_select($this->data_encode[0]," ").'>'._DISPENCODING; 
×
1779
      echo '                              <OPTION VALUE="hex"  '.chk_select($this->data_encode[0],"hex").'>hex';
×
1780
      echo '                              <OPTION VALUE="ascii"'.chk_select($this->data_encode[0],"ascii").'>ascii</SELECT>';
×
1781
      echo '<B>'._CONVERT2WS.':</B>';
×
1782
      echo '<SELECT NAME="data_encode[1]"><OPTION VALUE=" "    '.chk_select(@$this->data_encode[1]," ").'>'._DISPCONVERT2; 
×
1783
      echo '                              <OPTION VALUE="hex"  '.chk_select(@$this->data_encode[1],"hex").'>hex';
×
1784
      echo '                              <OPTION VALUE="ascii"'.chk_select(@$this->data_encode[1],"ascii").'>ascii</SELECT>';
×
1785
      echo '<BR>';
×
1786

1787
      for ( $i = 0; $i < $this->criteria_cnt; $i++ )
×
1788
      {
1789
         echo '<SELECT NAME="data['.$i.'][0]"><OPTION VALUE=" " '.chk_select(@$this->criteria[$i][0]," ").'>__'; 
×
1790
         echo '                               <OPTION VALUE="("  '.chk_select(@$this->criteria[$i][0],"(").'>(</SELECT>';
×
1791
         echo '<SELECT NAME="data['.$i.'][1]"><OPTION VALUE=" "  '.chk_select(@$this->criteria[$i][1]," "). '>'._DISPPAYLOAD;    
×
1792
         echo '                               <OPTION VALUE="LIKE"     '.chk_select(@$this->criteria[$i][1],"LIKE"). '>'._HAS;
×
1793
         echo '                               <OPTION VALUE="NOT LIKE" '.chk_select(@$this->criteria[$i][1],"NOT LIKE").'>'._HASNOT.'</SELECT>';
×
1794

1795
         echo '<INPUT TYPE="text" NAME="data['.$i.'][2]" SIZE=45 VALUE="'.htmlspecialchars(@$this->criteria[$i][2]).'">';
×
1796

1797
         echo '<SELECT NAME="data['.$i.'][3]"><OPTION VALUE=" " '.chk_select(@$this->criteria[$i][3]," ").'>__';
×
1798
         echo '                               <OPTION VALUE="(" '.chk_select(@$this->criteria[$i][3],"(").'>(';
×
1799
         echo '                               <OPTION VALUE=")" '.chk_select(@$this->criteria[$i][3],")").'>)</SELECT>';
×
1800
         echo '<SELECT NAME="data['.$i.'][4]"><OPTION VALUE=" "   '.chk_select(@$this->criteria[$i][4]," ").  '>__';
×
1801
         echo '                               <OPTION VALUE="OR" '.chk_select(@$this->criteria[$i][4],"OR").  '>'._OR;
×
1802
         echo '                               <OPTION VALUE="AND" '.chk_select(@$this->criteria[$i][4],"AND").'>'._AND.'</SELECT>';
×
1803

1804
         if ( $i == $this->criteria_cnt-1 )
×
1805
            echo '    <INPUT TYPE="submit" NAME="submit" VALUE="'._ADDPAYLOAD.'">';
×
1806
         echo '<BR>';
×
1807
      }
1808
        }
1809
        function ToSQL(){
1810
                // Convert this criteria to SQL.
1811
        }
14✔
1812
        function Description($value) {
1813
      $human_fields["LIKE"] = _CONTAINS;
×
1814
      $human_fields["NOT LIKE"] = _DOESNTCONTAIN;
×
1815
      $human_fields[""] = ""; 
×
1816

1817
      $tmp = "";
×
1818

1819
      if ( $this->data_encode[0] != " " && $this->data_encode[1] != " ")
×
1820
      {
1821
          $tmp = $tmp.' ('._DENCODED.' '.$this->data_encode[0];
×
1822
          $tmp = $tmp.' => '.$this->data_encode[1];
×
1823
          $tmp = $tmp.')<BR>';
×
1824
      }
1825
      else
1826
          $tmp = $tmp.' '._NODENCODED.'<BR>';
×
1827

1828
      for ( $i = 0; $i < $this->criteria_cnt; $i++ )
×
1829
      {
1830
         if ($this->criteria[$i][1] != " " && $this->criteria[$i][2] != "" )
×
1831
            $tmp = $tmp.$this->criteria[$i][0].$human_fields[$this->criteria[$i][1]].' "'.$this->criteria[$i][2].
×
1832
                             '" '.$this->criteria[$i][3].' '.$this->criteria[$i][4];
×
1833
      }
1834
       
1835
      if ( $tmp != "" )
×
1836
         $tmp = $tmp.$this->cs->GetClearCriteriaString($this->export_name);
×
1837

1838
                return $tmp;
×
1839
        }
1840
};
1841
?>
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