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

NathanGibbs3 / BASE / 624

pending completion
624

push

travis-ci-com

NathanGibbs3
Merge branch 'devel'

562 of 562 new or added lines in 28 files covered. (100.0%)

3145 of 17504 relevant lines covered (17.97%)

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

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

154
class MultipleElementCriteria extends BaseCriteria {
155
        var $element_cnt;
156
        var $criteria_cnt;
157
        var $valid_field_list = array();
158

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

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

289
         echo '    <SELECT NAME="'.htmlspecialchars($this->export_name).'['.$i.'][2]">';
×
290
         echo '      <OPTION VALUE="="  '.chk_select($this->criteria[$i][2],"="). '>=</OPTION>';
×
291
         echo '      <OPTION VALUE="!=" '.chk_select($this->criteria[$i][2],"!=").'>!=</OPTION>';
×
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 '    </SELECT>';
×
297

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

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

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

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

383
                return $tmp;
×
384
        }
385
}
386

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

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

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

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

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

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

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

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

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

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

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

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

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

602
      return $tmp;
×
603
        }
604
};  /* SignatureClassificationCriteria */
605

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

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

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

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

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

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

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

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

735
      return $tmp;
×
736
        }
737
};  /* AlertGroupCriteria */
738

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

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

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

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

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

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

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

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

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

822
      return $tmp;
×
823
        }
824
};  /* SensorCriteria */
825

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

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

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

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

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

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

942
                return $tmp;
×
943
        }
944
};  /* TimeCriteria */
945

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

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

1092
      $tmp2 = "";
×
1093

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

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

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

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

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

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

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

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

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

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

1377
      $tmp = "";
×
1378

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

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

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

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

1456
class UDPFieldCriteria extends ProtocolFieldCriteria {
1457
// $udp_field[MAX][6]: stores all other udp fields parameters/operators row
1458
//  - [][0] : (                            [][3] : field value
1459
//  - [][1] : length                       [][4] : (, )
1460
//  - [][2] : =, !=, <, <=, >, >=          [][5] : AND, OR
1461
//
1462
// $udp_field_cnt: number of rows in the $udp_field[][] 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 UDPFieldCriteria(
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
                                "udp_len" => "length",
×
1493
                                "udp_csum" => "chksum"
1494
                        )
1495
                );
1496
        }
1497
        function PrintForm($value1, $value2, $value3) {
1498
                parent::PrintForm($this->valid_field_list, _DISPFIELD, _ADDUDPFIELD);
×
1499
        }
1500
   function ToSQL()
1501
   {
1502
     /* convert this criteria to SQL */
1503
   }
1504
        function Description($value) {
1505
                return parent::Description(array_merge ( array("" => ""), $this->valid_field_list) );
×
1506
        }
1507
};  /* UDPFieldCriteria */
1508

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

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

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

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

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

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

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

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

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

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

1761
      $tmp = "";
×
1762

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

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

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