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

NathanGibbs3 / BASE / 584

pending completion
584

push

travis-ci-com

NathanGibbs3
20230412 Fix CI build breakage.
         Related Issue(s) #158

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

2594 of 16816 relevant lines covered (15.43%)

20.97 hits per line

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

25.27
/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
/** The below check is to make sure that the conf file has been loaded before this one....
21
 **  This should prevent someone from accessing the page directly. -- Kevin
22
 **/
23
defined( '_BASE_INC' ) or die( 'Accessing this file directly is not allowed.' );
24

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

36
        function __construct(&$db, &$cs, $name) { // PHP 5+ constructor Shim.
37
                // Class/Method agnostic shim code.
38
                $SCname = get_class();
484✔
39
                if ( method_exists($this, $SCname) ) {
484✔
40
                        $SCargs = func_get_args();
484✔
41
                        // Custom non agnostic shim line for pass by refs.
42
                        $SCargs = array(&$db, &$cs, $name);
484✔
43
                        call_user_func_array(array($this, $SCname), $SCargs);
484✔
44
                }else{
176✔
45
                        // @codeCoverageIgnoreStart
46
                        // Should never execute.
47
                        trigger_error( // Will need to add this message to the TD.
48
                                "Class: $SCname No Legacy Constructor.\n",
49
                                E_USER_ERROR
50
                        );
51
                        // @codeCoverageIgnoreEnd
52
                }
53
        }
352✔
54
        function BaseCriteria(&$db, &$cs, $name) { // PHP 4x constructor.
55
                $this->db =& $db;
880✔
56
                $this->cs =& $cs;
880✔
57
                $this->export_name = $name;
880✔
58
                $this->criteria = NULL;
880✔
59
                // NULL Placeholders.
60
                $this->value = NULL;
880✔
61
                $this->value1 = NULL;
880✔
62
                $this->value2 = NULL;
880✔
63
                $this->value3 = NULL;
880✔
64
        }
640✔
65
        // These functions are NoOp placeholders in this class.
66
        function Init(){
67
                // Initilaize Class Data Structure(s).
68
        }
16✔
69
        function Import(){
70
                // Imports criteria from POST, GET, or the session.
71
        }
16✔
72
        function Clear(){
73
                // Clears the criteria.
74
        }
16✔
75
        function Sanitize(){
76
                // Clean/validate the criteria.
77
        }
16✔
78
        function SanitizeElement($value){
79
                // Clean/validate the criteria.
80
        }
32✔
81
        function PrintForm($value1, $value2, $value3){
82
                // Prints the HTML form to input the criteria.
83
        }
16✔
84
        function AddFormItem(&$value1, $value2){
85
                // Adding another item to the HTML form.
86
        }
16✔
87
        function GetFormItemCnt(){
88
                // Returns the number of items in this form element.
89
        }
16✔
90
        function SetFormItemCnt($value){
91
                // Sets the number of items in this form element.
92
        }
16✔
93
        function Set($value){
94
                // Set the value of this criteria.
95
        }
16✔
96
        function Get(){
97
                // Returns the value of this criteria.
98
        }
16✔
99
        function ToSQL(){
100
                // Convert this criteria to SQL.
101
        }
16✔
102
        function Description($value){
103
                // Generate human-readable description of this criteria.
104
        }
16✔
105
        function isEmpty(){
106
                // Returns if the criteria is empty.
107
        }
16✔
108
        function CTIFD( $func = __FUNCTION__, $SF = '' ){
109
                // Prints debuging info regarding Criteria Type Input/Import Functions.
110
                GLOBAL $debug_mode;
272✔
111
                if ( $debug_mode > 1 ){
374✔
112
                        print "$func: $this->export_name<br/>\n";
286✔
113
                        print "Criteria Type: ".gettype($this->criteria)."<br/>\n";
286✔
114
                        if ( is_bool($SF) ){
286✔
115
                                $msg = "Criteria $func: ";
264✔
116
                                if ($SF){
264✔
117
                                        $msg .= 'Allowed';
132✔
118
                                }else{
48✔
119
                                        $msg .= 'Denied';
132✔
120
                                }
121
                                $msg .= ".<br/>\n";
264✔
122
                                print $msg;
264✔
123
                        }
96✔
124
                }
104✔
125
        }
272✔
126
};
127

128
class SingleElementCriteria extends BaseCriteria{
129
        function Import(){
130
                $this->criteria = SetSessionVar($this->export_name);
88✔
131
                $_SESSION[$this->export_name] = &$this->criteria;
88✔
132
        }
64✔
133
        // NoOp placeholders in this class. Why is it even here?
134
        function Sanitize() {
135
                $this->SanitizeElement('');
22✔
136
        }
16✔
137
        function GetFormItemCnt(){
138
                return -1;
22✔
139
        }
140
        function Set($value){
141
                $this->criteria = $value;
22✔
142
        }
16✔
143
        function Get(){
144
                return $this->criteria;
22✔
145
        }
146
        function isEmpty(){
147
                if ( is_null($this->criteria) || $this->criteria == '' ){
22✔
148
                        $Ret = true;
22✔
149
                }else{
8✔
150
                        $Ret = false;
22✔
151
                }
152
                return $Ret;
22✔
153
        }
154
};
155

156
class MultipleElementCriteria extends BaseCriteria {
157
        var $element_cnt;
158
        var $criteria_cnt;
159
        var $valid_field_list = Array();
160

161
        function __construct(
162
                &$db, &$cs, $export_name, $element_cnt, $field_list = Array()
163
        ) { // PHP 5+ constructor Shim.
164
                // Class/Method agnostic shim code.
165
                $SCname = get_class();
264✔
166
                if ( method_exists($this, $SCname) ) {
264✔
167
                        $SCargs = func_get_args();
264✔
168
                        // Custom non agnostic shim lines for pass by refs.
169
                        $SCargs = array(
48✔
170
                                &$db, &$cs, $export_name, $element_cnt, $field_list = Array()
264✔
171
                        );
96✔
172
                        call_user_func_array(array($this, $SCname), $SCargs);
264✔
173
                }else{
96✔
174
                        // @codeCoverageIgnoreStart
175
                        // Should never execute.
176
                        trigger_error( // Will need to add this message to the TD.
177
                                "Class: $SCname No Legacy Constructor.\n",
178
                                E_USER_ERROR
179
                        );
180
                        // @codeCoverageIgnoreEnd
181
                }
182
        }
192✔
183
        function MultipleElementCriteria(
184
                &$db, &$cs, $export_name, $element_cnt, $field_list = Array()
185
        ) { // PHP 4x constructor.
186
                $tdb =& $db;
286✔
187
                $cs =& $cs;
286✔
188
                $this->BaseCriteria($tdb, $cs, $export_name);
286✔
189
                $this->element_cnt = $element_cnt;
286✔
190
                $this->criteria_cnt = 0;
286✔
191
                $this->valid_field_list = $field_list;
286✔
192
        }
208✔
193
        function Init(){
194
                GLOBAL $MAX_ROWS;
48✔
195
                if ( isset($MAX_ROWS) ){
66✔
196
                        $tmp = $MAX_ROWS;
22✔
197
                }else{
8✔
198
                        $tmp = 10;
44✔
199
                }
200
                InitArray($this->criteria, $tmp, $this->element_cnt, '');
66✔
201
                $this->criteria_cnt = 1;
66✔
202
                $_SESSION[$this->export_name."_cnt"] = &$this->criteria_cnt;
66✔
203
                $this->CTIFD(__FUNCTION__);
66✔
204
        }
48✔
205
        function Import(){
206
                $tmp = SetSessionVar($this->export_name);
44✔
207
                if ( is_array($tmp) ){ // Type Lock criteria import. Fixes Issue #10.
44✔
208
                        $SF = true;
22✔
209
                        $this->criteria = $tmp;
22✔
210
                }else{
8✔
211
                        $SF = false;
22✔
212
                }
213
                $this->criteria_cnt = SetSessionVar($this->export_name."_cnt");
44✔
214
                $_SESSION[$this->export_name] = &$this->criteria;
44✔
215
                $_SESSION[$this->export_name."_cnt"] = &$this->criteria_cnt;
44✔
216
                $this->CTIFD(__FUNCTION__,$SF);
44✔
217
        }
32✔
218
   function Sanitize()
219
   { 
220
      if ( in_array("criteria", array_keys(get_object_vars($this))) )
×
221
      {
222
         for($i=0; $i < $this->element_cnt; $i++)
×
223
         {
224
            if ( isset($this->criteria[$i]) )
×
225
               $this->SanitizeElement($i);
×
226
         }
227
      }
228
   }
229
        // NoOp placeholders in this class. Why is it even here?
230
        function SanitizeElement($i){
231
        }
16✔
232
        function GetFormItemCnt(){
233
                return $this->criteria_cnt;
22✔
234
        }
235
        function SetFormItemCnt($value){
236
                $this->criteria_cnt = $value;
22✔
237
        }
16✔
238
   function AddFormItem(&$submit, $submit_value)
239
   {
240
        $this->criteria_cnt =& $this->criteria_cnt;
×
241
      AddCriteriaFormRow($submit, $submit_value, $this->criteria_cnt, $this->criteria, $this->element_cnt);
×
242
   }
243
        function Set($value){
244
                if ( is_array($value) ){ // Type Lock criteria Set. Fixes Issue #10.
66✔
245
                        $SF = true;
44✔
246
                        $this->criteria = $value;
44✔
247
                }else{
16✔
248
                        $SF = false;
22✔
249
                }
250
                $this->CTIFD(__FUNCTION__,$SF);
66✔
251
        }
48✔
252
        function Get(){
253
                return $this->criteria;
22✔
254
        }
255
        function isEmpty(){
256
                if ( is_null($this->criteria) || $this->criteria_cnt == 0 ){
44✔
257
                        $Ret = true;
44✔
258
                }else{
16✔
259
                        $Ret = false;
44✔
260
                }
261
                return $Ret;
44✔
262
        }
263
        function PrintForm($field_list, $blank_field_string, $add_button_string){
264
                GLOBAL $debug_mode;
265
                if ( $debug_mode > 0 ){
×
266
                        $this->CTIFD(__FUNCTION__);
×
267
                        print "Criteria Count: $this->criteria_cnt<br/>\n";
×
268
                }
269
                for ( $i = 0; $i < $this->criteria_cnt; $i++ ){
×
270
                        if (!is_array($this->criteria[$i])){
×
271
                                if ( $debug_mode > 0 ){
×
272
                                        print __FUNCTION__.": Criteria Data Error Detected<br/>\n";
×
273
                                        print "Re Initializing<br/>\n";
×
274
                                }
275
                                $this->Init();
×
276
                        }
277
         echo '    <SELECT NAME="'.htmlspecialchars($this->export_name).'['.$i.'][0]">';
×
278
         echo '      <OPTION VALUE=" " '.chk_select($this->criteria[$i][0]," ").'>__</OPTION>'; 
×
279
         echo '      <OPTION VALUE="(" '.chk_select($this->criteria[$i][0],"(").'>(</OPTION>';
×
280
         echo '    </SELECT>';
×
281

282
         echo '    <SELECT NAME="'.htmlspecialchars($this->export_name).'['.$i.'][1]">';
×
283
         echo '      <OPTION VALUE=" "      '.chk_select($this->criteria[$i][1]," ").'>'.$blank_field_string.'</OPTION>';
×
284
 
285
         foreach( $field_list as $field_name => $field_human_name )
×
286
         {
287
            echo '   <OPTION VALUE="'.$field_name.'" '.chk_select($this->criteria[$i][1],$field_name).'>'.$field_human_name.'</OPTION>';
×
288
         }
289
         echo '    </SELECT>';
×
290

291
         echo '    <SELECT NAME="'.htmlspecialchars($this->export_name).'['.$i.'][2]">';
×
292
         echo '      <OPTION VALUE="="  '.chk_select($this->criteria[$i][2],"="). '>=</OPTION>';
×
293
         echo '      <OPTION VALUE="!=" '.chk_select($this->criteria[$i][2],"!=").'>!=</OPTION>';
×
294
         echo '      <OPTION VALUE="<"  '.chk_select($this->criteria[$i][2],"<"). '><</OPTION>';
×
295
         echo '      <OPTION VALUE="<=" '.chk_select($this->criteria[$i][2],"<=").'><=</OPTION>';
×
296
         echo '      <OPTION VALUE=">"  '.chk_select($this->criteria[$i][2],">"). '>></OPTION>';
×
297
         echo '      <OPTION VALUE=">=" '.chk_select($this->criteria[$i][2],">=").'>>=</OPTION>';
×
298
         echo '    </SELECT>';
×
299

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

302
         echo '    <SELECT NAME="'.htmlspecialchars($this->export_name).'['.$i.'][4]">';
×
303
         echo '      <OPTION VALUE=" " '.chk_select($this->criteria[$i][4]," ").'>__</OPTION';
×
304
         echo '      <OPTION VALUE="(" '.chk_select($this->criteria[$i][4],"(").'>(</OPTION>';
×
305
         echo '      <OPTION VALUE=")" '.chk_select($this->criteria[$i][4],")").'>)</OPTION>';
×
306
         echo '    </SELECT>';
×
307

308
         echo '    <SELECT NAME="'.htmlspecialchars($this->export_name).'['.$i.'][5]">';
×
309
         echo '      <OPTION VALUE=" "   '.chk_select($this->criteria[$i][5]," ").  '>__</OPTION>';
×
310
         echo '      <OPTION VALUE="OR" '.chk_select($this->criteria[$i][5],"OR").  '>'._OR.'</OPTION>';
×
311
         echo '      <OPTION VALUE="AND" '.chk_select($this->criteria[$i][5],"AND").'>'._AND.'</OPTION>';
×
312
         echo '    </SELECT>';
×
313
         if ( $i == $this->criteria_cnt-1 )
×
314
            echo '    <INPUT TYPE="submit" NAME="submit" VALUE="'.htmlspecialchars($add_button_string).'">';
×
315
         echo '<BR>';
×
316
                }
317
        }
318
        // Not Used in Code. Why is it even here?
319
        function Compact(){
320
                if ( $this->isEmpty() ){
22✔
321
                        // Restore to newly constructed state.
322
                        $this->criteria = NULL;
22✔
323
                        $_SESSION[$this->export_name] = &$this->criteria;
22✔
324
                }
8✔
325
        }
16✔
326
};
327

328
class ProtocolFieldCriteria extends MultipleElementCriteria {
329
        function __construct(
330
                &$db, &$cs, $export_name, $element_cnt, $field_list = Array()
331
        ) { // PHP 5+ constructor Shim.
332
                // Class/Method agnostic shim code.
333
                $SCname = get_class();
22✔
334
                if ( method_exists($this, $SCname) ) {
22✔
335
                        $SCargs = func_get_args();
22✔
336
                        // Custom non agnostic shim lines for pass by refs.
337
                        $SCargs = array(
4✔
338
                                &$db, &$cs, $export_name, $element_cnt, $field_list = Array()
22✔
339
                        );
8✔
340
                        call_user_func_array(array($this, $SCname), $SCargs);
22✔
341
                }else{
8✔
342
                        // @codeCoverageIgnoreStart
343
                        // Should never execute.
344
                        trigger_error( // Will need to add this message to the TD.
345
                                "Class: $SCname No Legacy Constructor.\n",
346
                                E_USER_ERROR
347
                        );
348
                        // @codeCoverageIgnoreEnd
349
                }
350
        }
16✔
351
        function ProtocolFieldCriteria(
352
                &$db, &$cs, $export_name, $element_cnt, $field_list = Array()
353
        ) { // PHP 4x constructor.
354
                $tdb =& $db;
22✔
355
                $cs =& $cs;
22✔
356
                $this->MultipleElementCriteria(
22✔
357
                        $tdb, $cs, $export_name, $element_cnt, $field_list
16✔
358
                );
8✔
359
        }
16✔
360
        function SanitizeElement($i){
361
      // Make a copy of the element array
362
      $curArr = $this->criteria[$i];
×
363
      // Sanitize the element
364
      $this->criteria[$i][0] = @CleanVariable($curArr[0], VAR_OPAREN);
×
365
      $this->criteria[$i][1] = @CleanVariable($curArr[1], "", array_keys($this->valid_field_list));
×
366
      $this->criteria[$i][2] = @CleanVariable($curArr[2], "", array("=", "!=", "<", "<=", ">", ">="));
×
367
      $this->criteria[$i][3] = @CleanVariable($curArr[3], VAR_DIGIT);
×
368
      $this->criteria[$i][4] = @CleanVariable($curArr[4], VAR_OPAREN | VAR_CPAREN);
×
369
      $this->criteria[$i][5] = @CleanVariable($curArr[5], "", array("AND", "OR"));
×
370
      // Destroy the copy
371
      unset($curArr);
×
372
        }
373
        function Description($human_fields){
374
      $tmp = "";
×
375
      for ( $i = 0; $i < $this->criteria_cnt; $i++ )
×
376
      {
377
          if (is_array($this->criteria[$i]))
×
378
              if ($this->criteria[$i][1] != " " && $this->criteria[$i][3] != "" )
×
379
                  $tmp = $tmp.$this->criteria[$i][0].$human_fields[($this->criteria[$i][1])].' '.
×
380
                      $this->criteria[$i][2].' '.$this->criteria[$i][3].$this->criteria[$i][4].' '.$this->criteria[$i][5];
×
381
      }
382
      if ( $tmp != "" )
×
383
         $tmp = $tmp.$this->cs->GetClearCriteriaString($this->export_name); 
×
384

385
                return $tmp;
×
386
        }
387
}
388

389
class SignatureCriteria extends SingleElementCriteria {
390
// $sig[4]: stores signature
391
//   - [0] : exactly, roughly    [2] : =, !=
392
//   - [1] : signature           [3] : signature from signature list
393
        var $sig_type;
394
        var $criteria = array(0 => '', 1 => '');
395

396
        function __construct(&$db, &$cs, $export_name) { // PHP 5+ constructor Shim.
397
                // Class/Method agnostic shim code.
398
                $SCname = get_class();
150✔
399
                if ( method_exists($this, $SCname) ) {
150✔
400
                        $SCargs = func_get_args();
150✔
401
                        // Custom non agnostic shim line for pass by refs.
402
                        $SCargs = array(&$db, &$cs, $export_name);
150✔
403
                        call_user_func_array(array($this, $SCname), $SCargs);
150✔
404
                }else{
52✔
405
                        // @codeCoverageIgnoreStart
406
                        // Should never execute.
407
                        trigger_error( // Will need to add this message to the TD.
408
                                "Class: $SCname No Legacy Constructor.\n",
409
                                E_USER_ERROR
410
                        );
411
                        // @codeCoverageIgnoreEnd
412
                }
413
        }
108✔
414
        function SignatureCriteria(&$db, &$cs, $export_name) { // PHP 4x constructor.
415
                $tdb =& $db;
150✔
416
                $cs =& $cs;
150✔
417
                $this->BaseCriteria($tdb, $cs, $export_name);
150✔
418
                $this->sig_type = '';
150✔
419
        }
108✔
420
        function Init(){
421
                InitArray($this->criteria, 4, 0, '');
22✔
422
                $this->sig_type = '';
22✔
423
        }
16✔
424
        function Import(){
425
                $tmp = SetSessionVar($this->export_name);
44✔
426
                if ( is_array($tmp) ){ // Type Lock criteria import. Fixes Issue #10.
44✔
427
                        parent::Import();
22✔
428
                        $SF = true;
22✔
429
                }else{
8✔
430
                        $SF = false;
22✔
431
                }
432
                $this->CTIFD(__FUNCTION__,$SF);
44✔
433
                $this->sig_type = SetSessionVar("sig_type");
44✔
434
                $_SESSION['sig_type'] = &$this->sig_type;
44✔
435
        }
32✔
436
        function Clear(){
437
        }
16✔
438
        function SanitizeElement($value) {
439
      if (!isset($this->criteria[0]) || !isset($this->criteria[1])) {
×
440
          $this->criteria = array(0 => '', 1 => '');
×
441
      }
442

443
      $this->criteria[0] = CleanVariable(@$this->criteria[0], "", array(" ", "=", "LIKE"));
×
444
      $this->criteria[1] = filterSql(@$this->criteria[1]); /* signature name */
×
445
      $this->criteria[2] = CleanVariable(@$this->criteria[2], "", array("=", "!="));
×
446
      $this->criteria[3] = filterSql(@$this->criteria[3]); /* signature name from the signature list */
×
447
        }
448
        function PrintForm($value1, $value2, $value3) {
449
                GLOBAL $debug_mode;
450
                if ( !is_array($this->criteria) ){
×
451
                        if ( $debug_mode > 0 ){
×
452
                                $this->CTIFD(__FUNCTION__);
×
453
                                print __FUNCTION__.": Criteria Data Error Detected<br/>\n";
×
454
                                print "Re Initializing<br/>\n";
×
455
                        }
456
                        $this->Init();
×
457
                }
458
      echo '<SELECT NAME="sig[0]"><OPTION VALUE=" "  '.chk_select(@$this->criteria[0]," "). '>'._DISPSIG;    
×
459
      echo '                      <OPTION VALUE="="     '.chk_select(@$this->criteria[0],"="). '>'._SIGEXACTLY;
×
460
      echo '                      <OPTION VALUE="LIKE" '.chk_select(@$this->criteria[0],"LIKE").'>'._SIGROUGHLY.'</SELECT>';
×
461

462
      echo '<SELECT NAME="sig[2]"><OPTION VALUE="="  '.chk_select(@$this->criteria[2],"="). '>=';
×
463
      echo '                      <OPTION VALUE="!="     '.chk_select(@$this->criteria[2],"!="). '>!=';
×
464
      echo '</SELECT>';
×
465

466
      echo '<INPUT TYPE="text" NAME="sig[1]" SIZE=40 VALUE="'.htmlspecialchars(@$this->criteria[1]).'"><BR>';
×
467
                if ( base_array_key_exists('use_sig_list',$GLOBALS) ){ // Issue #44
×
468
      if ( $GLOBALS['use_sig_list'] > 0)
×
469
      {
470
         $temp_sql = "SELECT DISTINCT sig_name FROM signature";
×
471
         if ($GLOBALS['use_sig_list'] == 1)
×
472
         {
473
            $temp_sql = $temp_sql." WHERE sig_name NOT LIKE '%SPP\_%'";
×
474
         }
475

476
         $temp_sql = $temp_sql." ORDER BY sig_name";
×
477
         $tmp_result = $this->db->baseExecute($temp_sql);
×
478
         echo '<SELECT NAME="sig[3]"
479
                       onChange=\'PacketForm.elements[4].value =
480
                         this.options[this.selectedIndex].value;return true;\'>
481
                <OPTION VALUE="null" SELECTED>{ Select Signature from List }';
482

483
         if ($tmp_result)
484
         {
485
            while ( $myrow = $tmp_result->baseFetchRow() )
×
486
               echo '<OPTION VALUE="'.$myrow[0].'">'.$myrow[0];
×
487
            $tmp_result->baseFreeRows();
×
488
         }
489
         echo '</SELECT><BR>';
×
490
      }
491
                }
492
        }
493
        function ToSQL(){
494
        }
16✔
495
        function Description($value) {
496
                $tmp = $tmp_human = "";
40✔
497
                if ( isset($this->criteria[0]) && $this->criteria[0] != " " ){
40✔
498
                        // Common code for both scenarios.
499
                        if ( $this->criteria[0] == '=' ){
40✔
500
                                if ( $this->criteria[2] == '!=' ){
40✔
501
                                        $tmp_human = '!=';
20✔
502
                                }elseif ( $this->criteria[2] == '=' ){
40✔
503
                                        $tmp_human = '=';
40✔
504
                                }
12✔
505
                        }elseif ( $this->criteria[0] == 'LIKE' ){
26✔
506
                                if ( $this->criteria[2] == '!=' ){
20✔
507
                                        $tmp_human = ' '._DOESNTCONTAIN.' ';
20✔
508
                                }elseif ( $this->criteria[2] == '=' ){
20✔
509
                                        $tmp_human = ' '._CONTAINS.' ';
20✔
510
                                }
6✔
511
                        }
6✔
512
                        $SIdx = 0;
40✔
513
                        if (
514
                                (isset($this->criteria[3]))
40✔
515
                                && ($this->criteria[3] != "" )
40✔
516
                                && ($this->criteria[3] != "null")
40✔
517
                                && ($this->criteria[3] != "NULL")
40✔
518
                                && ($this->criteria[3] != NULL)
40✔
519
                        ){
12✔
520
                                // First scenario: Signature name is taken from the signature
521
                                // list. The user has clicked at a drop down menu for this.
522
                                $SIdx = 3;
×
523
                        }elseif (
524
                                (isset($this->criteria[1])) && ($this->criteria[1] != "")
40✔
525
                        ){
12✔
526
                                // Second scenario: Signature name is taken from a string that
527
                                // has been typed in manually by the user.
528
                                $SIdx = 1;
20✔
529
                        }
6✔
530
                        if ( $SIdx != 0 ){
40✔
531
                                $tmp .= _SIGNATURE.' '.$tmp_human.' "';
20✔
532
                                if (
533
                                        ($this->db->baseGetDBversion() >= 100)
20✔
534
                                        && $this->sig_type == 1
20✔
535
                                ){
6✔
536
                                        $tmp .= BuildSigByID($this->criteria[$SIdx], $this->db).'" ';
×
537
                                }else{
538
                                        $tmp .= htmlentities($this->criteria[$SIdx]).'"';
20✔
539
                                }
540
                                $tmp .= $this->cs->GetClearCriteriaString($this->export_name);
20✔
541
                                $tmp .= '<br/>';
20✔
542
                        }
6✔
543
                }
12✔
544
                return $tmp;
40✔
545
        }
546
};  /* SignatureCriteria */
547

548
class SignatureClassificationCriteria extends SingleElementCriteria
549
{
550
   function Init()
551
   {
552
     $this->criteria = "";
×
553
   }
554

555
   function Clear()
556
   {
557
    /* clears the criteria */
558
   }
559
        function SanitizeElement($value) {
560
                $this->criteria = CleanVariable($this->criteria, VAR_DIGIT);
×
561
        }
562
        function PrintForm($value1, $value2, $value3) {
563
     if ( $this->db->baseGetDBversion() >= 103 )
×
564
     {
565

566
        echo '<SELECT NAME="sig_class">
567
              <OPTION VALUE=" " '.chk_select($this->criteria, " ").'>'._DISPANYCLASS.'
×
568
              <OPTION VALUE="null" '.chk_select($this->criteria, "null").'>-'._UNCLASS.'-';
×
569

570
        $temp_sql = "SELECT sig_class_id, sig_class_name FROM sig_class";
×
571
        $tmp_result = $this->db->baseExecute($temp_sql);
×
572
        if ( $tmp_result )
573
        {
574
           while ( $myrow = $tmp_result->baseFetchRow() )
×
575
            echo '<OPTION VALUE="'.$myrow[0].'" '.chk_select($this->criteria, $myrow[0]).'>'.
×
576
                  $myrow[1];
×
577

578
           $tmp_result->baseFreeRows();
×
579
        }
580
        echo '</SELECT>&nbsp;&nbsp';
×
581
     }
582
        }
583
   function ToSQL()
584
   {
585
    /* convert this criteria to SQL */
586
   }
587
        function Description($value) {
588
      $tmp = "";
×
589

590
      if ( $this->db->baseGetDBversion() >= 103 )
×
591
      {
592
         if ( $this->criteria != " " && $this->criteria != "" )
×
593
         {
594
            if ( $this->criteria == "null")
×
595
               $tmp = $tmp._SIGCLASS.' = '.
×
596
                              '<I>'._UNCLASS.'</I><BR>';
597
            else
598
               $tmp = $tmp._SIGCLASS.' = '.
×
599
                              htmlentities(GetSigClassName($this->criteria, $this->db)).
×
600
                              $this->cs->GetClearCriteriaString($this->export_name).'<BR>';
×
601
         }
602
      }
603

604
      return $tmp;
×
605
        }
606
};  /* SignatureClassificationCriteria */
607

608
class SignaturePriorityCriteria extends SingleElementCriteria {
609
        var $criteria = array(0 => '', 1 => '');
610

611
        function Init(){
612
                InitArray($this->criteria, 2, 0, '');
22✔
613
        }
16✔
614
        function Import(){
615
                $tmp = SetSessionVar($this->export_name);
44✔
616
                if ( is_array($tmp) ){ // Type Lock criteria import. Fixes Issue #10.
44✔
617
                        parent::Import();
22✔
618
                        $SF = true;
22✔
619
                }else{
8✔
620
                        $SF = false;
22✔
621
                }
622
                $this->CTIFD(__FUNCTION__,$SF);
44✔
623
        }
32✔
624
        function Clear(){
625
                // Clears the criteria.
626
        }
16✔
627
        function SanitizeElement($value) {
628
     if (!isset($this->criteria[0]) || !isset($this->criteria[1])) {
×
629
         $this->criteria = array(0 => '', 1 => '');
×
630
     }
631

632
      $this->criteria[0] = CleanVariable(@$this->criteria[0], "", array("=", "!=", "<", "<=", ">", ">="));
×
633
      $this->criteria[1] = CleanVariable(@$this->criteria[1], VAR_DIGIT);
×
634
        }
635
        function PrintForm($value1, $value2, $value3) {
636
                GLOBAL $debug_mode;
637
                if ( $this->db->baseGetDBversion() >= 103 ){
×
638
                        if ( !is_array($this->criteria) ){
×
639
                                if ( $debug_mode > 0 ){
×
640
                                        $this->CTIFD(__FUNCTION__);
×
641
                                        print __FUNCTION__.": Criteria Data Error Detected<br/>\n";
×
642
                                        print "Re Initializing<br/>\n";
×
643
                                }
644
                                $this->Init();
×
645
                        }
646
        echo '<SELECT NAME="sig_priority[0]">
647
                <OPTION VALUE=" " '.@chk_select($this->criteria[0],"="). '>__</OPTION>
×
648
                <OPTION VALUE="=" '.@chk_select($this->criteria[0],"=").'>==</OPTION>
×
649
                <OPTION VALUE="!=" '.@chk_select($this->criteria[0],"!=").'>!=</OPTION>
×
650
                <OPTION VALUE="<"  '.@chk_select($this->criteria[0],"<"). '><</OPTION>
×
651
                <OPTION VALUE=">"  '.@chk_select($this->criteria[0],">").'>></OPTION>
×
652
                <OPTION VALUE="<=" '.@chk_select($this->criteria[0],"><="). '><=</OPTION>
×
653
                <OPTION VALUE=">=" '.@chk_select($this->criteria[0],">=").'>>=</SELECT>';
×
654
 
655
        echo '<SELECT NAME="sig_priority[1]">
656
                <OPTION VALUE="" '.@chk_select($this->criteria[1], " ").'>'._DISPANYPRIO.'</OPTION>
×
657
                 <OPTION VALUE="null" '.@chk_select($this->criteria[1], "null").'>-'._UNCLASS.'-</OPTION>';
×
658
        $temp_sql = "select DISTINCT sig_priority from signature ORDER BY sig_priority ASC ";
×
659
        $tmp_result = $this->db->baseExecute($temp_sql);
×
660
        if ( $tmp_result )
661
        {
662
           while ( $myrow = $tmp_result->baseFetchRow() )
×
663
             echo '<OPTION VALUE="'.$myrow[0].'" '.chk_select(@$this->criteria[1], $myrow[0]).'>'.
×
664
                   $myrow[0];
×
665
 
666
            $tmp_result->baseFreeRows();
×
667
        }
668
        echo '</SELECT>&nbsp;&nbsp';
×
669
      }
670
        }
671
        function ToSQL(){
672
                // Convert this criteria to SQL.
673
        }
16✔
674
        function Description($value) {
675
       $tmp = "";
×
676
       if (!isset($this->criteria[1])) {
×
677
           $this->criteria = array(0 => '', 1 => '');
×
678
       }
679
 
680
       if ( $this->db->baseGetDBversion() >= 103 )
×
681
       {
682
          if ( $this->criteria[1] != " " && $this->criteria[1] != "" )
×
683
          {
684
             if ( $this->criteria[1] == null)
×
685
                $tmp = $tmp._SIGPRIO.' = '.
×
686
                               '<I>'._NONE.'</I><BR>';
687
             else
688
                $tmp = $tmp._SIGPRIO.' '.htmlentities($this->criteria[0])." ".htmlentities($this->criteria[1]).
×
689
                       $this->cs->GetClearCriteriaString($this->export_name).'<BR>';
×
690
                        }
691
                }
692
                return $tmp;
×
693
        }
694
};  /* SignaturePriorityCriteria */
695

696
class AlertGroupCriteria extends SingleElementCriteria
697
{
698
   function Init()
699
   {
700
      $this->criteria = "";
×
701
   }
702

703
   function Clear()
704
   {
705
    /* clears the criteria */
706
   }
707
        function SanitizeElement($value) {
708
                $this->criteria = CleanVariable($this->criteria, VAR_DIGIT);
×
709
        }
710
        function PrintForm($value1, $value2, $value3) {
711
      echo '<SELECT NAME="ag">
712
             <OPTION VALUE=" " '.chk_select($this->criteria, " ").'>'._DISPANYAG;
×
713

714
      $temp_sql = "SELECT ag_id, ag_name FROM acid_ag";
×
715
      $tmp_result = $this->db->baseExecute($temp_sql);
×
716
      if ( $tmp_result )
717
      {
718
         while ( $myrow = $tmp_result->baseFetchRow() )
×
719
           echo '<OPTION VALUE="'.$myrow[0].'" '.chk_select($this->criteria, $myrow[0]).'>'.
×
720
                 '['.$myrow[0].'] '.htmlspecialchars($myrow[1]);
×
721

722
         $tmp_result->baseFreeRows();
×
723
      }
724
      echo '</SELECT>&nbsp;&nbsp;';
×
725
        }
726
   function ToSQL()
727
   {
728
    /* convert this criteria to SQL */
729
   }
730
        function Description($value) {
731
      $tmp = "";
×
732

733
      if ( $this->criteria != " " && $this->criteria != "" )
×
734
        $tmp = $tmp._ALERTGROUP.' = ['.htmlentities($this->criteria).'] '.GetAGNameByID($this->criteria, $this->db).
×
735
                    $this->cs->GetClearCriteriaString($this->export_name).'<BR>';
×
736

737
      return $tmp;
×
738
        }
739
};  /* AlertGroupCriteria */
740

741
class SensorCriteria extends SingleElementCriteria
742
{
743
   function Init()
744
   {
745
     $this->criteria = "";
×
746
   }
747

748
   function Clear()
749
   {
750
     /* clears the criteria */
751
   }
752
        function SanitizeElement($value) {
753
                $this->criteria = CleanVariable($this->criteria, VAR_DIGIT);
×
754
        }
755
        function PrintForm($value1, $value2, $value3) {
756
                GLOBAL $debug_mode;
757
      // How many sensors do we have?
758
      $number_sensors = 0;
×
759
      $number_sensors_lst = $this->db->baseExecute("SELECT count(*) FROM sensor");
×
760
      $number_sensors_array = $number_sensors_lst->baseFetchRow();
×
761
      $number_sensors_lst->baseFreeRows();
×
762
      if (!isset($number_sensors_array))
×
763
      {
764
        $mystr = '<BR>' . __FILE__ . '' . __LINE__ . ": \$ERROR: number_sensors_array has not been set at all!<BR>";
×
765
        ErrorMessage($mystr);        
×
766
        $number_sensors = 0;
×
767
      }
768

769
      if ($number_sensors_array == NULL || $number_sensors_array == "")
×
770
      {
771
        $number_sensors = 0;
×
772
      }
773
      else
774
      {
775
        $number_sensors = $number_sensors_array[0];
×
776
      }
777
                if ($debug_mode > 1){
×
778
                        print '$number_sensors = ' . $number_sensors . '<BR><BR>';
×
779
                }
780
      echo '<SELECT NAME="sensor">
781
             <OPTION VALUE=" " '.chk_select($this->criteria, " ").'>'._DISPANYSENSOR;
×
782

783
      $temp_sql = "SELECT sid, hostname, interface, filter FROM sensor";
×
784
      $tmp_result = $this->db->baseExecute($temp_sql);      
×
785

786
      
787
      for ($n = 0; $n < $number_sensors; $n++)
×
788
      {
789
        $myrow = $tmp_result->baseFetchRow();
×
790

791
        if (!isset($myrow) || $myrow == "" || $myrow == NULL)
×
792
        {
793
          if ($n >= $number_sensors)
×
794
          {
795
            break;
×
796
          }
797
          else
798
          {
799
            next;
×
800
          }
801
        }
802

803
        echo '<OPTION VALUE="' . $myrow[0] . '" ' .
×
804
             chk_select($this->criteria, $myrow[0]) . '>' .
×
805
             '[' . $myrow[0] . '] ' .
×
806
             GetSensorName($myrow[0], $this->db);
×
807
      }
808
      $tmp_result->baseFreeRows();
×
809

810
      echo '</SELECT>&nbsp;&nbsp';
×
811
        }
812
   function ToSQL()
813
   {
814
     /* convert this criteria to SQL */
815
   }
816
        function Description($value) {
817
     $tmp = "";
×
818

819
     if ( $this->criteria != " " && $this->criteria != "" )
×
820
        $tmp = $tmp._SENSOR.' = ['.htmlentities($this->criteria).'] '.
×
821
               GetSensorName($this->criteria, $this->db).
×
822
               $this->cs->GetClearCriteriaString($this->export_name).'<BR>';
×
823

824
      return $tmp;
×
825
        }
826
};  /* SensorCriteria */
827

828
class TimeCriteria extends MultipleElementCriteria {
829
// $time[MAX][10]: stores the date/time of the packet detection
830
//  - [][0] : (                           [][5] : hour
831
//  - [][1] : =, !=, <, <=, >, >=         [][6] : minute
832
//  - [][2] : month                       [][7] : second
833
//  - [][3] : day                         [][8] : (, )
834
//  - [][4] : year                        [][9] : AND, OR
835
//
836
// $time_cnt : number of rows in the $time[][] structure
837

838
        function Clear(){
839
                // Clears the criteria.
840
        }
16✔
841
        function SanitizeElement($i){
842
                // Make copy of element array.
843
      $curArr = $this->criteria[$i];
×
844
      // Sanitize the element
845
      $this->criteria[$i][0] = @CleanVariable($curArr[0], VAR_OPAREN);
×
846
      $this->criteria[$i][1] = @CleanVariable($curArr[1], "", array("=", "!=", "<", "<=", ">", ">="));
×
847
      $this->criteria[$i][2] = @CleanVariable($curArr[2], VAR_DIGIT);
×
848
      $this->criteria[$i][3] = @CleanVariable($curArr[3], VAR_DIGIT);
×
849
      $this->criteria[$i][4] = @CleanVariable($curArr[4], VAR_DIGIT);
×
850
      $this->criteria[$i][5] = @CleanVariable($curArr[5], VAR_DIGIT);
×
851
      $this->criteria[$i][6] = @CleanVariable($curArr[6], VAR_DIGIT);
×
852
      $this->criteria[$i][7] = @CleanVariable($curArr[7], VAR_DIGIT);
×
853
      $this->criteria[$i][8] = @CleanVariable($curArr[8], VAR_OPAREN | VAR_CPAREN);
×
854
      $this->criteria[$i][9] = @CleanVariable($curArr[9], "", array("AND", "OR"));
×
855
      // Destroy the old copy
856
      unset($curArr);
×
857
   }
858
        function PrintForm($value1, $value2, $value3) {
859
                GLOBAL $debug_mode;
860
                for ( $i = 0; $i < $this->criteria_cnt; $i++ ){
×
861
                        if (!is_array($this->criteria[$i])){
×
862
                                if ( $debug_mode > 0 ){
×
863
                                        $this->CTIFD(__FUNCTION__);
×
864
                                        print __FUNCTION__.": Criteria Data Error Detected<br/>\n";
×
865
                                        print "Re Initializing<br/>\n";
×
866
                                }
867
                                $this->Init();
×
868
                        }
869
         echo '<SELECT NAME="time['.$i.'][0]"><OPTION VALUE=" " '.chk_select(@$this->criteria[$i][0]," ").'>__'; 
×
870
         echo '                               <OPTION VALUE="("  '.chk_select(@$this->criteria[$i][0],"(").'>(</SELECT>';
×
871
         echo '<SELECT NAME="time['.$i.'][1]"><OPTION VALUE=" "  '.chk_select(@$this->criteria[$i][1]," "). '>'._DISPTIME;    
×
872
         echo '                               <OPTION VALUE="="  '.chk_select(@$this->criteria[$i][1],"="). '>=';
×
873
         echo '                               <OPTION VALUE="!=" '.chk_select(@$this->criteria[$i][1],"!=").'>!=';
×
874
         echo '                               <OPTION VALUE="<"  '.chk_select(@$this->criteria[$i][1],"<"). '><';
×
875
         echo '                               <OPTION VALUE="<=" '.chk_select(@$this->criteria[$i][1],"<=").'><=';
×
876
         echo '                               <OPTION VALUE=">"  '.chk_select(@$this->criteria[$i][1],">"). '>>';
×
877
         echo '                               <OPTION VALUE=">=" '.chk_select(@$this->criteria[$i][1],">=").'>>=</SELECT>';
×
878

879
         echo '<SELECT NAME="time['.$i.'][2]"><OPTION VALUE=" "  '.chk_select(@$this->criteria[$i][2]," " ).'>'._DISPMONTH;
×
880
         echo '                               <OPTION VALUE="01" '.chk_select(@$this->criteria[$i][2],"01").'>'._SHORTJAN;
×
881
         echo '                               <OPTION VALUE="02" '.chk_select(@$this->criteria[$i][2],"02").'>'._SHORTFEB;
×
882
         echo '                               <OPTION VALUE="03" '.chk_select(@$this->criteria[$i][2],"03").'>'._SHORTMAR;
×
883
         echo '                               <OPTION VALUE="04" '.chk_select(@$this->criteria[$i][2],"04").'>'._SHORTAPR;
×
884
         echo '                               <OPTION VALUE="05" '.chk_select(@$this->criteria[$i][2],"05").'>'._SHORTMAY;
×
885
         echo '                               <OPTION VALUE="06" '.chk_select(@$this->criteria[$i][2],"06").'>'._SHORTJUN;
×
886
         echo '                               <OPTION VALUE="07" '.chk_select(@$this->criteria[$i][2],"07").'>'._SHORTJLY;
×
887
         echo '                               <OPTION VALUE="08" '.chk_select(@$this->criteria[$i][2],"08").'>'._SHORTAUG;
×
888
         echo '                               <OPTION VALUE="09" '.chk_select(@$this->criteria[$i][2],"09").'>'._SHORTSEP;
×
889
         echo '                               <OPTION VALUE="10" '.chk_select(@$this->criteria[$i][2],"10").'>'._SHORTOCT;
×
890
         echo '                               <OPTION VALUE="11" '.chk_select(@$this->criteria[$i][2],"11").'>'._SHORTNOV;
×
891
         echo '                               <OPTION VALUE="12" '.chk_select(@$this->criteria[$i][2],"12").'>'._SHORTDEC.'</SELECT>';
×
892
         echo '<INPUT TYPE="text" NAME="time['.$i.'][3]" SIZE=2 VALUE="'.htmlspecialchars(@$this->criteria[$i][3]).'">';
×
893
         echo '<SELECT NAME="time['.$i.'][4]">'.dispYearOptions(@$this->criteria[$i][4]).'</SELECT>';
×
894

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

899
         echo '<SELECT NAME="time['.$i.'][8]"><OPTION VALUE=" " '.chk_select(@$this->criteria[$i][8]," ").'>__';
×
900
         echo '                               <OPTION VALUE="(" '.chk_select(@$this->criteria[$i][8],"(").'>(';
×
901
         echo '                               <OPTION VALUE=")" '.chk_select(@$this->criteria[$i][8],")").'>)</SELECT>';
×
902
         echo '<SELECT NAME="time['.$i.'][9]"><OPTION VALUE=" "   '.chk_select(@$this->criteria[$i][9]," ").  '>__';
×
903
         echo '                               <OPTION VALUE="OR" '.chk_select(@$this->criteria[$i][9],"OR").  '>'._OR;
×
904
         echo '                               <OPTION VALUE="AND" '.chk_select(@$this->criteria[$i][9],"AND").'>'._AND.'</SELECT>';
×
905
       
906
         if ( $i == $this->criteria_cnt-1 )
×
907
            echo '    <INPUT TYPE="submit" NAME="submit" VALUE="'._ADDTIME.'">';
×
908
         echo '<BR>';
×
909
      }
910
        }
911
        function ToSQL(){
912
                // Convert this criteria to SQL.
913
        }
16✔
914
        function Description($value) {
915
     $tmp = "";
×
916
     for ($i = 0; $i < $this->criteria_cnt; $i++)
×
917
     {
918
         if ( isset($this->criteria[$i][1]) && $this->criteria[$i][1] != " " )
×
919
         { 
920
            $tmp = $tmp.'<CODE>'.htmlspecialchars($this->criteria[$i][0]).' time '.htmlspecialchars($this->criteria[$i][1]).' [ ';
×
921

922
            /* date */
923
            if ( $this->criteria[$i][2] == " " && $this->criteria[$i][3] == "" && $this->criteria[$i][4] == " " )
×
924
               $tmp = $tmp." </CODE><I>any date</I><CODE>";
×
925
            else
926
               $tmp = $tmp.(($this->criteria[$i][2] == " ") ? "* / " : $this->criteria[$i][2]." / ").
×
927
                           (($this->criteria[$i][3] == "" ) ? "* / " : $this->criteria[$i][3]." / ").
×
928
                           (($this->criteria[$i][4] == " ") ? "*  " : $this->criteria[$i][4]." "); 
×
929
            $tmp = $tmp.'] [ ';
×
930
            /* time */
931
            if ( $this->criteria[$i][5] == "" && $this->criteria[$i][6] == "" && $this->criteria[$i][7] == "" )
×
932
               $tmp = $tmp."</CODE><I>any time</I><CODE>";
×
933
            else
934
               $tmp = $tmp.(($this->criteria[$i][5] == "") ? "* : " : $this->criteria[$i][5]." : ").
×
935
                           (($this->criteria[$i][6] == "") ? "* : " : $this->criteria[$i][6]." : ").
×
936
                           (($this->criteria[$i][7] == "") ? "*  " : $this->criteria[$i][7]." "); 
×
937
            $tmp = $tmp.$this->criteria[$i][8].'] '.$this->criteria[$i][9];
×
938
            $tmp = $tmp.'</CODE><BR>';
×
939
         }             
940
     }
941
     if ( $tmp != "" )
×
942
       $tmp = $tmp.$this->cs->GetClearCriteriaString($this->export_name);
×
943

944
                return $tmp;
×
945
        }
946
};  /* TimeCriteria */
947

948
class IPAddressCriteria extends MultipleElementCriteria {
949
// * $ip_addr[MAX][10]: stores an ip address parameters/operators row
950
//  - [][0] : (                          [][5] : octet3 of address
951
//  - [][1] : source, dest               [][6] : octet4 of address
952
//  - [][2] : =, !=                      [][7] : network mask
953
//  - [][3] : octet1 of address          [][8] : (, )
954
//  - [][4] : octet2 of address          [][9] : AND, OR
955
//
956
// $ip_addr_cnt: number of rows in the $ip_addr[][] structure
957

958
        function __construct(
959
                &$db, &$cs, $export_name, $element_cnt
960
        ) { // PHP 5+ constructor Shim.
961
                // Class/Method agnostic shim code.
962
                $SCname = get_class();
80✔
963
                if ( method_exists($this, $SCname) ) {
80✔
964
                        $SCargs = func_get_args();
80✔
965
                        // Custom non agnostic shim line for pass by refs.
966
                        $SCargs = array(&$db, &$cs, $export_name, $element_cnt);
80✔
967
                        call_user_func_array(array($this, $SCname), $SCargs);
80✔
968
                }else{
24✔
969
                        // @codeCoverageIgnoreStart
970
                        // Should never execute.
971
                        trigger_error( // Will need to add this message to the TD.
972
                                "Class: $SCname No Legacy Constructor.\n",
973
                                E_USER_ERROR
974
                        );
975
                        // @codeCoverageIgnoreEnd
976
                }
977
        }
56✔
978
        function IPAddressCriteria(
979
                &$db, &$cs, $export_name, $element_cnt
980
        ) { // PHP 4x constructor.
981
                $tdb =& $db;
80✔
982
                $cs =& $cs;
80✔
983
                parent::MultipleElementCriteria(
80✔
984
                        $tdb, $cs, $export_name, $element_cnt,
56✔
985
                        array (
986
                                "ip_src" => _SOURCE,
80✔
987
                                "ip_dst" => _DEST,
56✔
988
                                "ip_both" => _SORD
32✔
989
                        )
24✔
990
                );
24✔
991
        }
56✔
992
        function Import(){
993
                parent::Import();
×
994
                if ( is_array($this->criteria) ){
×
995
                        // Expand IP into octets.
996
                        for ( $i = 0; $i < $this->criteria_cnt; $i++ ){
×
997
        if ( (isset ($this->criteria[$i][3])) &&
×
998
                        (preg_match("/([0-9]*)\.([0-9]*)\.([0-9]*)\.([0-9]*)/", $this->criteria[$i][3])) )
×
999
        {
1000
           $tmp_ip_str = $this->criteria[$i][7] = $this->criteria[$i][3];
×
1001
           $this->criteria[$i][3] = strtok($tmp_ip_str, ".");
×
1002
           $this->criteria[$i][4] = strtok(".");
×
1003
           $this->criteria[$i][5] = strtok(".");
×
1004
           $this->criteria[$i][6] = strtok("/");
×
1005
           $this->criteria[$i][10] = strtok("");
×
1006
        }
1007
                        }
1008
                }
1009
      $_SESSION['ip_addr'] = &$this->criteria;
×
1010
      $_SESSION['ip_addr_cnt'] = &$this->criteria_cnt;
×
1011
        }
1012
        function Clear(){
1013
                // Clears the criteria.
1014
        }
14✔
1015
        function SanitizeElement($value) {
1016
                $i = 0; // Why is this function hardwired to check only the first
×
1017
                // criteria instance? Leaving it for now, but need to investigate.
1018
                // 2019-07-12 Nathan
1019
      // Make copy of old element array
1020
      $curArr = $this->criteria[$i];
×
1021
      // Sanitize element
1022
      $this->criteria[$i][0] = @CleanVariable($curArr[0], VAR_OPAREN);
×
1023
      $this->criteria[$i][1] = @CleanVariable($curArr[1], "", array_keys($this->valid_field_list));
×
1024
      $this->criteria[$i][2] = @CleanVariable($curArr[2], "", array("=", "!=", "<", "<=", ">", ">="));
×
1025
      $this->criteria[$i][3] = @CleanVariable($curArr[3], VAR_DIGIT);
×
1026
      $this->criteria[$i][4] = @CleanVariable($curArr[4], VAR_DIGIT);
×
1027
      $this->criteria[$i][5] = @CleanVariable($curArr[5], VAR_DIGIT);
×
1028
      $this->criteria[$i][6] = @CleanVariable($curArr[6], VAR_DIGIT);
×
1029
      $this->criteria[$i][7] = @CleanVariable($curArr[7], VAR_DIGIT | VAR_PERIOD | VAR_FSLASH);
×
1030
      $this->criteria[$i][8] = @CleanVariable($curArr[8], VAR_OPAREN | VAR_CPAREN);
×
1031
      $this->criteria[$i][9] = @CleanVariable($curArr[9], "", array("AND", "OR"));
×
1032
      // Destroy copy
1033
      unset($curArr);
×
1034
        }
1035
        function PrintForm($value1, $value2, $value3) {
1036
                GLOBAL $debug_mode;
1037
                for ( $i = 0; $i < $this->criteria_cnt; $i++ ){
×
1038
                        if (!is_array($this->criteria[$i])){
×
1039
                                if ( $debug_mode > 0 ){
×
1040
                                        $this->CTIFD(__FUNCTION__);
×
1041
                                        print __FUNCTION__.": Criteria Data Error Detected<br/>\n";
×
1042
                                        print "Re Initializing<br/>\n";
×
1043
                                }
1044
                                $this->Init();
×
1045
                        }
1046
         echo '    <SELECT NAME="ip_addr['.$i.'][0]"><OPTION VALUE=" " '.chk_select(@$this->criteria[$i][0]," ").'>__'; 
×
1047
         echo '                                      <OPTION VALUE="(" '.chk_select(@$this->criteria[$i][0],"(").'>(</SELECT>';
×
1048
         echo '    <SELECT NAME="ip_addr['.$i.'][1]">
×
1049
                    <OPTION VALUE=" "      '.chk_select(@$this->criteria[$i][1]," "     ).'>'._DISPADDRESS.'
×
1050
                    <OPTION VALUE="ip_src" '.chk_select(@$this->criteria[$i][1],"ip_src").'>'._SHORTSOURCE.'
×
1051
                    <OPTION VALUE="ip_dst" '.chk_select(@$this->criteria[$i][1],"ip_dst").'>'._SHORTDEST.'
×
1052
                    <OPTION VALUE="ip_both" '.chk_select(@$this->criteria[$i][1],"ip_both").'>'._SHORTSOURCEORDEST.'
×
1053
                   </SELECT>'; 
1054
         echo '    <SELECT NAME="ip_addr['.$i.'][2]">
×
1055
                    <OPTION VALUE="="  '.chk_select(@$this->criteria[$i][2],"="). '>=
×
1056
                    <OPTION VALUE="!=" '.chk_select(@$this->criteria[$i][2],"!=").'>!=
×
1057
                   </SELECT>';
1058
                if ( base_array_key_exists('ip_address_input',$GLOBALS) ){ // Issue #53
×
1059
                        $tmp = $GLOBALS['ip_address_input'];
×
1060
                }else{
1061
                        $tmp = 2;
×
1062
                }
1063
                if ( $tmp == 2 ){
×
1064
           echo  '    <INPUT TYPE="text" NAME="ip_addr['.$i.'][3]" SIZE=16 VALUE="'.htmlspecialchars(@$this->criteria[$i][7]).'">';
×
1065
                }else{
1066
           echo '    <INPUT TYPE="text" NAME="ip_addr['.$i.'][3]" SIZE=3 VALUE="'.htmlspecialchars(@$this->criteria[$i][3]).'"><B>.</B>';
×
1067
           echo '    <INPUT TYPE="text" NAME="ip_addr['.$i.'][4]" SIZE=3 VALUE="'.htmlspecialchars(@$this->criteria[$i][4]).'"><B>.</B>';
×
1068
           echo '    <INPUT TYPE="text" NAME="ip_addr['.$i.'][5]" SIZE=3 VALUE="'.htmlspecialchars(@$this->criteria[$i][5]).'"><B>.</B>';
×
1069
           echo '    <INPUT TYPE="text" NAME="ip_addr['.$i.'][6]" SIZE=3 VALUE="'.htmlspecialchars(@$this->criteria[$i][6]).'"><!--<B>/</B>';
×
1070
           echo '    <INPUT TYPE="text" NAME="ip_addr['.$i.'][7]" SIZE=3 VALUE="'.htmlspecialchars(@$this->criteria[$i][7]).'">-->'; 
×
1071
                }
1072
        echo '    <SELECT NAME="ip_addr['.$i.'][8]"><OPTION VALUE=" " '.chk_select(@$this->criteria[$i][8]," ").'>__';
×
1073
        echo '                                      <OPTION VALUE="(" '.chk_select(@$this->criteria[$i][8],"(").'>(';
×
1074
        echo '                                      <OPTION VALUE=")" '.chk_select(@$this->criteria[$i][8],")").'>)</SELECT>';
×
1075
        echo '    <SELECT NAME="ip_addr['.$i.'][9]"><OPTION VALUE=" "   '.chk_select(@$this->criteria[$i][9]," ").  '>__';
×
1076
        echo '                                      <OPTION VALUE="OR" '.chk_select(@$this->criteria[$i][9],"OR").  '>'._OR;
×
1077
        echo '                                      <OPTION VALUE="AND" '.chk_select(@$this->criteria[$i][9],"AND").'>'._AND.'</SELECT>';
×
1078
        if ( $i == $this->criteria_cnt-1 )
×
1079
          echo '    <INPUT TYPE="submit" NAME="submit" VALUE="'._ADDADDRESS.'">';
×
1080
        echo '<BR>';
×
1081
      }
1082
        }
1083
        function ToSQL(){
1084
                // Convert this criteria to SQL.
1085
        }
14✔
1086
        function Description($value) {
1087
      $human_fields["ip_src"] = _SOURCE;
×
1088
      $human_fields["ip_dst"] = _DEST;
×
1089
      $human_fields["ip_both"] = _SORD;
×
1090
      $human_fields[""] = ""; 
×
1091
      $human_fields["LIKE"] = _CONTAINS;
×
1092
      $human_fields["="] = "=";  
×
1093

1094
      $tmp2 = "";
×
1095

1096
      for ( $i = 0; $i < $this->criteria_cnt; $i++ )
×
1097
      {
1098
         $tmp = "";
×
1099
         if ( isset($this->criteria[$i][3]) && $this->criteria[$i][3] != "" )
×
1100
         {
1101
            $tmp = $tmp.$this->criteria[$i][3];
×
1102
            if ( $this->criteria[$i][4] != "" )
×
1103
            {
1104
               $tmp = $tmp.".".$this->criteria[$i][4];
×
1105
               if ( $this->criteria[$i][5] != "" )
×
1106
               {
1107
                  $tmp = $tmp.".".$this->criteria[$i][5];
×
1108
                  if ( $this->criteria[$i][6] != "" )
×
1109
                  {
1110
                     if ( ($this->criteria[$i][3].".".$this->criteria[$i][4].".".
×
1111
                        $this->criteria[$i][5].".".$this->criteria[$i][6]) == NULL_IP)
×
1112
                        $tmp = " unknown ";
×
1113
                     else
1114
                        $tmp = $tmp.".".$this->criteria[$i][6];
×
1115
                  }
1116
                  else
1117
                     $tmp = $tmp.'.*';
×
1118
               }
1119
               else
1120
                  $tmp = $tmp.'.*.*';
×
1121
            }
1122
            else
1123
               $tmp = $tmp.'.*.*.*';
×
1124
         }
1125
         /* Make sure that the IP isn't blank */
1126
         if ( $tmp != "" )
×
1127
         {
1128
            $mask = "";
×
1129
            if ( $this->criteria[$i][10] != "" )
×
1130
               $mask = "/".$this->criteria[$i][10];
×
1131

1132
             $tmp2 = $tmp2.$this->criteria[$i][0].
×
1133
                     $human_fields[($this->criteria[$i][1])].' '.$this->criteria[$i][2].
×
1134
                     ' '.$tmp.' '.$this->criteria[$i][8].' '.$this->criteria[$i][9].$mask.
×
1135
                     $this->cs->GetClearCriteriaString($this->export_name)."<BR>";
×
1136
         }
1137
                }
1138
                return $tmp2;
×
1139
        }
1140
};  /* IPAddressCriteria */
1141

1142
class IPFieldCriteria extends ProtocolFieldCriteria {
1143
// $ip_field[MAX][6]: stores all other ip fields parameters/operators row
1144
//  - [][0] : (                            [][3] : field value
1145
//  - [][1] : TOS, TTL, ID, offset, length [][4] : (, )
1146
//  - [][2] : =, !=, <, <=, >, >=          [][5] : AND, OR
1147
//
1148
// $ip_field_cnt: number of rows in the $ip_field[][] structure
1149

1150
        function __construct(
1151
                &$db, &$cs, $export_name, $element_cnt
1152
        ) { // PHP 5+ constructor Shim.
1153
                // Class/Method agnostic shim code.
1154
                $SCname = get_class();
×
1155
                if ( method_exists($this, $SCname) ) {
×
1156
                        $SCargs = func_get_args();
×
1157
                        // Custom non agnostic shim line for pass by refs.
1158
                        $SCargs = array(&$db, &$cs, $export_name, $element_cnt);
×
1159
                        call_user_func_array(array($this, $SCname), $SCargs);
×
1160
                }else{
1161
                        // @codeCoverageIgnoreStart
1162
                        // Should never execute.
1163
                        trigger_error( // Will need to add this message to the TD.
1164
                                "Class: $SCname No Legacy Constructor.\n",
1165
                                E_USER_ERROR
1166
                        );
1167
                        // @codeCoverageIgnoreEnd
1168
                }
1169
        }
1170
        function IPFieldCriteria(
1171
                &$db, &$cs, $export_name, $element_cnt
1172
        ) { // PHP 4x constructor.
1173
                $tdb =& $db;
×
1174
                $cs =& $cs;
×
1175
                parent::ProtocolFieldCriteria(
×
1176
                        $tdb, $cs, $export_name, $element_cnt,
1177
                        array(
1178
                                "ip_tos"  => "TOS",
×
1179
                                "ip_ttl"  => "TTL",
1180
                                "ip_id"   => "ID",
1181
                                "ip_off"  => "offset",
1182
                                "ip_csum" => "chksum",
1183
                                "ip_len"  => "length"
1184
                        )
1185
                );
1186
        }
1187
        function PrintForm($value1, $value2, $value3) {
1188
                parent::PrintForm($this->valid_field_list, _DISPFIELD, _ADDIPFIELD);
×
1189
        }
1190
   function ToSQL()
1191
   {
1192
     /* convert this criteria to SQL */
1193
   }
1194
        function Description($value) {
1195
      return parent::Description( array_merge( array ( "" => "", 
×
1196
                                                       "LIKE" => _CONTAINS,
1197
                                                       "=" => "="), $this->valid_field_list ) );  
×
1198
        }
1199
};
1200

1201
class TCPPortCriteria extends ProtocolFieldCriteria {
1202
// $tcp_port[MAX][6]: stores all port parameters/operators row
1203
//  - [][0] : (                            [][3] : port value
1204
//  - [][1] : Source Port, Dest Port       [][4] : (, )
1205
//  - [][2] : =, !=, <, <=, >, >=          [][5] : AND, OR
1206
//
1207
// $tcp_port_cnt: number of rows in the $tcp_port[][] structure
1208

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

1255
class TCPFieldCriteria extends ProtocolFieldCriteria {
1256
// TCP Variables
1257
// =============
1258
// $tcp_field[MAX][6]: stores all other tcp fields parameters/operators row
1259
//  - [][0] : (                            [][3] : field value
1260
//  - [][1] : windows, URP                 [][4] : (, )
1261
//  - [][2] : =, !=, <, <=, >, >=          [][5] : AND, OR
1262
//
1263
// $tcp_field_cnt: number of rows in the $tcp_field[][] structure
1264

1265
        function __construct(
1266
                &$db, &$cs, $export_name, $element_cnt
1267
        ) { // PHP 5+ constructor Shim.
1268
                // Class/Method agnostic shim code.
1269
                $SCname = get_class();
×
1270
                if ( method_exists($this, $SCname) ) {
×
1271
                        $SCargs = func_get_args();
×
1272
                        // Custom non agnostic shim line for pass by refs.
1273
                        $SCargs = array(&$db, &$cs, $export_name, $element_cnt);
×
1274
                        call_user_func_array(array($this, $SCname), $SCargs);
×
1275
                }else{
1276
                        // @codeCoverageIgnoreStart
1277
                        // Should never execute.
1278
                        trigger_error( // Will need to add this message to the TD.
1279
                                "Class: $SCname No Legacy Constructor.\n",
1280
                                E_USER_ERROR
1281
                        );
1282
                        // @codeCoverageIgnoreEnd
1283
                }
1284
        }
1285
        function TCPFieldCriteria(
1286
                &$db, &$cs, $export_name, $element_cnt
1287
        ) { // PHP 4x constructor.
1288
                $tdb =& $db;
×
1289
                $cs =& $cs;
×
1290
                parent::ProtocolFieldCriteria(
×
1291
                        $tdb, $cs, $export_name, $element_cnt,
1292
                        array (
1293
                                "tcp_win" => "window",
×
1294
                                "tcp_urp" => "urp",
1295
                                "tcp_seq" => "seq #",
1296
                                "tcp_ack" => "ack",
1297
                                "tcp_off" => "offset",
1298
                                "tcp_res" => "res",
1299
                                "tcp_csum" => "chksum"
1300
                        )
1301
                );
1302
        }
1303
        function PrintForm($value1, $value2, $value3) {
1304
                parent::PrintForm($this->valid_field_list, _DISPFIELD, _ADDTCPFIELD);
×
1305
        }
1306
   function ToSQL()
1307
   {
1308
     /* convert this criteria to SQL */
1309
   }
1310
        function Description($value) {
1311
                return parent::Description(array_merge ( array("" => ""), $this->valid_field_list) );
×
1312
        }
1313
};  /* TCPFieldCriteria */
1314

1315
class TCPFlagsCriteria extends SingleElementCriteria{
1316
        // $tcp_flags[9]: stores all other tcp flags parameters/operators row
1317
        //  - [0] : is, contains                   [5] : 16    (ACK)
1318
        //  - [1] : 1   (FIN)                      [6] : 32    (URG)
1319
        //  - [2] : 2   (SYN)                      [7] : 64    (RSV0)
1320
        //  - [3] : 4   (PUSH)                     [8] : 128   (RSV1)
1321
        //  - [4] : 8   (RST)
1322

1323
        function Init(){
1324
                InitArray($this->criteria, TCPFLAGS_CFCNT, 0, '');
88✔
1325
        }
64✔
1326
        function Import(){
1327
                $tmp = SetSessionVar($this->export_name);
44✔
1328
                if ( is_array($tmp) ){ // Type Lock criteria import. Fixes Issue #10.
44✔
1329
                        parent::Import();
22✔
1330
                        $SF = true;
22✔
1331
                }else{
8✔
1332
                        $SF = false;
22✔
1333
                }
1334
                $this->CTIFD(__FUNCTION__,$SF);
44✔
1335
        }
32✔
1336
        function Clear(){
1337
                // Clears the criteria.
1338
        }
16✔
1339
        function SanitizeElement($value) {
1340
                $this->criteria = CleanVariable($this->criteria, VAR_DIGIT);
×
1341
        }
1342
        function PrintForm($value1, $value2, $value3) {
1343
                GLOBAL $debug_mode;
1344
                if (!is_array($this->criteria)){
×
1345
                        $this->CTIFD(__FUNCTION__);
×
1346
                        print __FUNCTION__.": Criteria Data Error Detected<br/>\n";
×
1347
                        print "Re Initializing<br/>\n";
×
1348
                        $this->Init();
×
1349
                }
1350
      echo '<TD><SELECT NAME="tcp_flags[0]"><OPTION VALUE=" " '.chk_select($this->criteria[0]," ").'>'._DISPFLAGS;
×
1351
      echo '                              <OPTION VALUE="is" '.chk_select($this->criteria[0],"is").'>'._IS;
×
1352
      echo '                              <OPTION VALUE="contains" '.chk_select($this->criteria[0],"contains").'>'._CONTAINS.'</SELECT>';
×
1353
      echo '   <FONT>';
×
1354
      echo '    <INPUT TYPE="checkbox" NAME="tcp_flags[8]" VALUE="128" '.chk_check($this->criteria[8],"128").'> [RSV1] &nbsp'; 
×
1355
      echo '    <INPUT TYPE="checkbox" NAME="tcp_flags[7]" VALUE="64"  '.chk_check($this->criteria[7],"64").'> [RSV0] &nbsp';
×
1356
      echo '    <INPUT TYPE="checkbox" NAME="tcp_flags[6]" VALUE="32"  '.chk_check($this->criteria[6],"32").'> [URG] &nbsp';
×
1357
      echo '    <INPUT TYPE="checkbox" NAME="tcp_flags[5]" VALUE="16"  '.chk_check($this->criteria[5],"16").'> [ACK] &nbsp';
×
1358
      echo '    <INPUT TYPE="checkbox" NAME="tcp_flags[3]" VALUE="8"   '.chk_check($this->criteria[4],"8").'> [PSH] &nbsp'; 
×
1359
      echo '    <INPUT TYPE="checkbox" NAME="tcp_flags[4]" VALUE="4"   '.chk_check($this->criteria[3],"4").'> [RST] &nbsp';
×
1360
      echo '    <INPUT TYPE="checkbox" NAME="tcp_flags[2]" VALUE="2"   '.chk_check($this->criteria[2],"2").'> [SYN] &nbsp';
×
1361
      echo '    <INPUT TYPE="checkbox" NAME="tcp_flags[1]" VALUE="1"   '.chk_check($this->criteria[1],"1").'> [FIN] &nbsp';
×
1362
      echo '  </FONT>';
×
1363
        }
1364
        function ToSQL(){
1365
                // Convert this criteria to SQL.
1366
        }
16✔
1367
        function Description($value) {
1368
      $human_fields["1"] = "F";
×
1369
      $human_fields["2"] = "S";
×
1370
      $human_fields["4"] = "R";
×
1371
      $human_fields["8"] = "P";
×
1372
      $human_fields["16"] = "A";
×
1373
      $human_fields["32"] = "U";
×
1374
      $human_fields["64"] = "[R0]";
×
1375
      $human_fields["128"] = "[R1]";
×
1376
      $human_fields["LIKE"] = _CONTAINS;
×
1377
      $human_fields["="] = "="; 
×
1378

1379
      $tmp = "";
×
1380

1381
      if ( isset($this->criteria[0]) && ($this->criteria[0] != " ") && ($this->criteria[0] != "") )
×
1382
      {
1383
         $tmp = $tmp.'flags '.$this->criteria[0].' ';
×
1384
         for ( $i = 8; $i >=1; $i-- )
×
1385
            if ( $this->criteria[$i] == "" )
×
1386
               $tmp = $tmp.'-';
×
1387
            else
1388
               $tmp = $tmp.$human_fields[($this->criteria[$i])];
×
1389

1390
         $tmp = $tmp.$this->cs->GetClearCriteriaString("tcp_flags").'<BR>';
×
1391
      }
1392
                return $tmp;
×
1393
        }
1394
        function isEmpty(){
1395
                $Ret = false;
88✔
1396
                $TD = array ('', ' '); // Test Values
88✔
1397
                if ( is_null($this->criteria) || in_array($this->criteria[0], $TD) ){
88✔
1398
                        $Ret = true;
66✔
1399
                }
24✔
1400
                return $Ret;
88✔
1401
        }
1402
};  /* TCPFlagCriteria */
1403

1404
class UDPPortCriteria extends ProtocolFieldCriteria {
1405
// $udp_port[MAX][6]: stores all port parameters/operators row
1406
//  - [][0] : (                            [][3] : port value
1407
//  - [][1] : Source Port, Dest Port       [][4] : (, )
1408
//  - [][2] : =, !=, <, <=, >, >=          [][5] : AND, OR
1409
//
1410
// $udp_port_cnt: number of rows in the $udp_port[][] structure
1411

1412
        function __construct(
1413
                &$db, &$cs, $export_name, $element_cnt
1414
        ) { // PHP 5+ constructor Shim.
1415
                // Class/Method agnostic shim code.
1416
                $SCname = get_class();
×
1417
                if ( method_exists($this, $SCname) ) {
×
1418
                        $SCargs = func_get_args();
×
1419
                        // Custom non agnostic shim line for pass by refs.
1420
                        $SCargs = array(&$db, &$cs, $export_name, $element_cnt);
×
1421
                        call_user_func_array(array($this, $SCname), $SCargs);
×
1422
                }else{
1423
                        // @codeCoverageIgnoreStart
1424
                        // Should never execute.
1425
                        trigger_error( // Will need to add this message to the TD.
1426
                                "Class: $SCname No Legacy Constructor.\n",
1427
                                E_USER_ERROR
1428
                        );
1429
                        // @codeCoverageIgnoreEnd
1430
                }
1431
        }
1432
        function UDPPortCriteria(
1433
                &$db, &$cs, $export_name, $element_cnt
1434
        ) { // PHP 4x constructor.
1435
                $tdb =& $db;
×
1436
                $cs =& $cs;
×
1437
                parent::ProtocolFieldCriteria(
×
1438
                        $tdb, $cs, $export_name, $element_cnt,
1439
                        array (
1440
                                "layer4_sport" => _SOURCEPORT,
×
1441
                                "layer4_dport" => _DESTPORT
1442
                        )
1443
                );
1444
        }
1445
        function PrintForm($value1, $value2, $value3) {
1446
                parent::PrintForm($this->valid_field_list, _DISPPORT, _ADDUDPPORT);
×
1447
        }
1448
   function ToSQL()
1449
   {
1450
     /* convert this criteria to SQL */
1451
   }
1452
        function Description($value) {
1453
                return parent::Description(array_merge( array("" => "",  
×
1454
                                                    "=" => "="), $this->valid_field_list) );
×
1455
        }
1456
};  /* UDPPortCriteria */
1457

1458
class UDPFieldCriteria extends ProtocolFieldCriteria {
1459
// $udp_field[MAX][6]: stores all other udp fields parameters/operators row
1460
//  - [][0] : (                            [][3] : field value
1461
//  - [][1] : length                       [][4] : (, )
1462
//  - [][2] : =, !=, <, <=, >, >=          [][5] : AND, OR
1463
//
1464
// $udp_field_cnt: number of rows in the $udp_field[][] structure
1465

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

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

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

1567
class Layer4Criteria extends SingleElementCriteria
1568
{
1569
   function Init()
1570
   {
1571
      $this->criteria = "";
×
1572
   }
1573

1574
   function Clear()
1575
   {
1576
     /* clears the criteria */
1577
   }
1578
        function SanitizeElement($value) {
1579
                $this->criteria = CleanVariable($this->criteria, "", array("UDP", "TCP", "ICMP", "RawIP"));
×
1580
        }
1581
        function PrintForm($value1, $value2, $value3) {
1582
      if ( $this->criteria != "" )
×
1583
         echo '<INPUT TYPE="submit" NAME="submit" VALUE="'._NOLAYER4.'"> &nbsp';
×
1584
      if ( $this->criteria == "TCP" )
×
1585
         echo '  
×
1586
           <INPUT TYPE="submit" NAME="submit" VALUE="UDP"> &nbsp
1587
           <INPUT TYPE="submit" NAME="submit" VALUE="ICMP">';
1588
      else if ( $this->criteria == "UDP" )
×
1589
         echo '  
×
1590
           <INPUT TYPE="submit" NAME="submit" VALUE="TCP"> &nbsp
1591
           <INPUT TYPE="submit" NAME="submit" VALUE="ICMP">';
1592
      else if ( $this->criteria == "ICMP" )
×
1593
         echo '  
×
1594
           <INPUT TYPE="submit" NAME="submit" VALUE="TCP"> &nbsp
1595
           <INPUT TYPE="submit" NAME="submit" VALUE="UDP">';
1596
      else
1597
         echo '  
1598
           <INPUT TYPE="submit" NAME="submit" VALUE="TCP"> &nbsp
1599
           <INPUT TYPE="submit" NAME="submit" VALUE="UDP">
1600
           <INPUT TYPE="submit" NAME="submit" VALUE="ICMP">';
1601
        }
1602
   function ToSQL()
1603
   {
1604
     /* convert this criteria to SQL */
1605
   }
1606
        function Description($value) {
1607
      if ( $this->criteria == "TCP" )
×
1608
         return _QCTCPCRIT;
×
1609
      else if ( $this->criteria == "UDP" )
×
1610
         return _QCUDPCRIT;
×
1611
      else if ( $this->criteria == "ICMP" )
×
1612
         return _QCICMPCRIT ;
×
1613
      else
1614
         return _QCLAYER4CRIT;
×
1615
        }
1616
};  /* Layer4Criteria */
1617

1618
class DataCriteria extends MultipleElementCriteria {
1619
// $data_encode[2]: how the payload should be interpreted and converted
1620
//  - [0] : encoding type (hex, ascii)
1621
//  - [1] : conversion type (hex, ascii)
1622
//
1623
// $data[MAX][5]: stores all the payload related parameters/operators row
1624
//  - [][0] : (                            [][3] : (, )
1625
//  - [][1] : =, !=                        [][4] : AND, OR
1626
//  - [][2] : field value
1627
//
1628
// $data_cnt: number of rows in the $data[][] structure
1629
        var $data_encode = array();
1630

1631
        function __construct(
1632
                &$db, &$cs, $export_name, $element_cnt
1633
        ) { // PHP 5+ constructor Shim.
1634
                // Class/Method agnostic shim code.
1635
                $SCname = get_class();
160✔
1636
                if ( method_exists($this, $SCname) ) {
160✔
1637
                        $SCargs = func_get_args();
160✔
1638
                        // Custom non agnostic shim line for pass by refs.
1639
                        $SCargs = array(&$db, &$cs, $export_name, $element_cnt);
160✔
1640
                        call_user_func_array(array($this, $SCname), $SCargs);
160✔
1641
                }else{
48✔
1642
                        // @codeCoverageIgnoreStart
1643
                        // Should never execute.
1644
                        trigger_error( // Will need to add this message to the TD.
1645
                                "Class: $SCname No Legacy Constructor.\n",
1646
                                E_USER_ERROR
1647
                        );
1648
                        // @codeCoverageIgnoreEnd
1649
                }
1650
        }
112✔
1651
        function DataCriteria(
1652
                &$db, &$cs, $export_name, $element_cnt
1653
        ) { // PHP 4x constructor.
1654
                $tdb =& $db;
160✔
1655
                $cs =& $cs;
160✔
1656
                parent::MultipleElementCriteria(
160✔
1657
                        $tdb, $cs, $export_name, $element_cnt,
112✔
1658
                        array (
1659
                                "LIKE" => _HAS,
160✔
1660
                                "NOT LIKE" => _HASNOT
64✔
1661
                        )
48✔
1662
                );
48✔
1663
                InitArray($this->data_encode, 2, 0, '');
160✔
1664
        }
112✔
1665
        function Init(){
1666
                parent::Init();
20✔
1667
                InitArray($this->data_encode, 2, 0, '');
20✔
1668
        }
14✔
1669
        function Import(){
1670
                GLOBAL $debug_mode;
42✔
1671
                parent::Import();
60✔
1672
                $tmp = SetSessionVar("data_encode");
60✔
1673
                if ( is_array($tmp) ){ // Type Lock Property import. Fixes Issue #10.
60✔
1674
                        $this->data_encode = $tmp;
20✔
1675
                        $ISF = true;
20✔
1676
                }else{
6✔
1677
                        $ISF = false;
40✔
1678
                }
1679
                $_SESSION['data_encode'] = &$this->data_encode;
60✔
1680
                if ( $debug_mode > 1 ){
60✔
1681
                        $this->CTIFD(__FUNCTION__);
60✔
1682
                        print "Property Type: ".gettype($tmp)."<br/>\n";
60✔
1683
                        if ( is_bool($ISF) ){
60✔
1684
                                $msg = 'Property '.__FUNCTION__.': ';
60✔
1685
                                if ($ISF){
60✔
1686
                                        $msg .= 'Allowed';
20✔
1687
                                }else{
6✔
1688
                                        $msg .= 'Denied';
40✔
1689
                                }
1690
                                $msg .= ".<br/>\n";
60✔
1691
                                print $msg;
60✔
1692
                        }
18✔
1693
                }
18✔
1694
        }
42✔
1695
        function Clear(){
1696
                // Clears the criteria.
1697
        }
14✔
1698
   function SanitizeElement($i)
1699
   {
1700
      $this->data_encode[0] = CleanVariable($this->data_encode[0], "", array("hex", "ascii"));
×
1701
      $this->data_encode[1] = CleanVariable($this->data_encode[1], "", array("hex", "ascii"));
×
1702
      // Make a copy of the element array
1703
      $curArr = $this->criteria[$i];
×
1704
      // Sanitize the array
1705
      $this->criteria[$i][0] = CleanVariable($curArr[0], VAR_OPAREN);
×
1706
      $this->criteria[$i][1] = CleanVariable($curArr[1], "", array_keys($this->valid_field_list));
×
1707
      $this->criteria[$i][2] = CleanVariable($curArr[2], VAR_FSLASH | VAR_PERIOD | VAR_DIGIT | VAR_PUNC | VAR_LETTER );
×
1708
      $this->criteria[$i][3] = CleanVariable($curArr[3], VAR_OPAREN | VAR_CPAREN);
×
1709
      $this->criteria[$i][4] = CleanVariable($curArr[4], "", array("AND", "OR"));
×
1710
      // Destroy the copy
1711
      unset($curArr);
×
1712
   }
1713
        function PrintForm($value1, $value2, $value3) {
1714
                GLOBAL $debug_mode;
1715
                if (!is_array($this->criteria[0])){
×
1716
                        if ( $debug_mode > 0 ){
×
1717
                                $this->CTIFD(__FUNCTION__);
×
1718
                                print __FUNCTION__.": Criteria Data Error Detected<br/>\n";
×
1719
                                print "Re Initializing<br/>\n";
×
1720
                        }
1721
                        $this->Init();
×
1722
                }
1723
      echo '<B>'._INPUTCRTENC.':</B>';
×
1724
      echo '<SELECT NAME="data_encode[0]"><OPTION VALUE=" "    '.chk_select($this->data_encode[0]," ").'>'._DISPENCODING; 
×
1725
      echo '                              <OPTION VALUE="hex"  '.chk_select($this->data_encode[0],"hex").'>hex';
×
1726
      echo '                              <OPTION VALUE="ascii"'.chk_select($this->data_encode[0],"ascii").'>ascii</SELECT>';
×
1727
      echo '<B>'._CONVERT2WS.':</B>';
×
1728
      echo '<SELECT NAME="data_encode[1]"><OPTION VALUE=" "    '.chk_select(@$this->data_encode[1]," ").'>'._DISPCONVERT2; 
×
1729
      echo '                              <OPTION VALUE="hex"  '.chk_select(@$this->data_encode[1],"hex").'>hex';
×
1730
      echo '                              <OPTION VALUE="ascii"'.chk_select(@$this->data_encode[1],"ascii").'>ascii</SELECT>';
×
1731
      echo '<BR>';
×
1732

1733
      for ( $i = 0; $i < $this->criteria_cnt; $i++ )
×
1734
      {
1735
         echo '<SELECT NAME="data['.$i.'][0]"><OPTION VALUE=" " '.chk_select(@$this->criteria[$i][0]," ").'>__'; 
×
1736
         echo '                               <OPTION VALUE="("  '.chk_select(@$this->criteria[$i][0],"(").'>(</SELECT>';
×
1737
         echo '<SELECT NAME="data['.$i.'][1]"><OPTION VALUE=" "  '.chk_select(@$this->criteria[$i][1]," "). '>'._DISPPAYLOAD;    
×
1738
         echo '                               <OPTION VALUE="LIKE"     '.chk_select(@$this->criteria[$i][1],"LIKE"). '>'._HAS;
×
1739
         echo '                               <OPTION VALUE="NOT LIKE" '.chk_select(@$this->criteria[$i][1],"NOT LIKE").'>'._HASNOT.'</SELECT>';
×
1740

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

1743
         echo '<SELECT NAME="data['.$i.'][3]"><OPTION VALUE=" " '.chk_select(@$this->criteria[$i][3]," ").'>__';
×
1744
         echo '                               <OPTION VALUE="(" '.chk_select(@$this->criteria[$i][3],"(").'>(';
×
1745
         echo '                               <OPTION VALUE=")" '.chk_select(@$this->criteria[$i][3],")").'>)</SELECT>';
×
1746
         echo '<SELECT NAME="data['.$i.'][4]"><OPTION VALUE=" "   '.chk_select(@$this->criteria[$i][4]," ").  '>__';
×
1747
         echo '                               <OPTION VALUE="OR" '.chk_select(@$this->criteria[$i][4],"OR").  '>'._OR;
×
1748
         echo '                               <OPTION VALUE="AND" '.chk_select(@$this->criteria[$i][4],"AND").'>'._AND.'</SELECT>';
×
1749

1750
         if ( $i == $this->criteria_cnt-1 )
×
1751
            echo '    <INPUT TYPE="submit" NAME="submit" VALUE="'._ADDPAYLOAD.'">';
×
1752
         echo '<BR>';
×
1753
      }
1754
        }
1755
        function ToSQL(){
1756
                // Convert this criteria to SQL.
1757
        }
14✔
1758
        function Description($value) {
1759
      $human_fields["LIKE"] = _CONTAINS;
×
1760
      $human_fields["NOT LIKE"] = _DOESNTCONTAIN;
×
1761
      $human_fields[""] = ""; 
×
1762

1763
      $tmp = "";
×
1764

1765
      if ( $this->data_encode[0] != " " && $this->data_encode[1] != " ")
×
1766
      {
1767
          $tmp = $tmp.' ('._DENCODED.' '.$this->data_encode[0];
×
1768
          $tmp = $tmp.' => '.$this->data_encode[1];
×
1769
          $tmp = $tmp.')<BR>';
×
1770
      }
1771
      else
1772
          $tmp = $tmp.' '._NODENCODED.'<BR>';
×
1773

1774
      for ( $i = 0; $i < $this->criteria_cnt; $i++ )
×
1775
      {
1776
         if ($this->criteria[$i][1] != " " && $this->criteria[$i][2] != "" )
×
1777
            $tmp = $tmp.$this->criteria[$i][0].$human_fields[$this->criteria[$i][1]].' "'.$this->criteria[$i][2].
×
1778
                             '" '.$this->criteria[$i][3].' '.$this->criteria[$i][4];
×
1779
      }
1780
       
1781
      if ( $tmp != "" )
×
1782
         $tmp = $tmp.$this->cs->GetClearCriteriaString($this->export_name);
×
1783

1784
                return $tmp;
×
1785
        }
1786
};
1787
?>
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