<?php
/*******************************************************************************
** Basic Analysis and Security Engine (BASE)
** Copyright (C) 2004 BASE Project Team
** Copyright (C) 2000 Carnegie Mellon University
**
** (see the file 'base_main.php' for license details)
**
** Project Lead: Kevin Johnson <kjohnson@secureideas.net>
** Built upon work by Roman Danyliw <rdd@cert.org>, <roman@danyliw.com>
**
** Purpose: renders the HTML form to gather search criteria
********************************************************************************
** Authors:
********************************************************************************
** Kevin Johnson <kjohnson@secureideas.net
**
********************************************************************************
*/

if ( $submit == "TCP" )        {  $cs->criteria['layer4']->Set("TCP");   }
if ( $submit == "UDP" )        {  $cs->criteria['layer4']->Set("UDP");   }
if ( $submit == "ICMP" )       {  $cs->criteria['layer4']->Set("ICMP");  }
if ( $submit == "no layer4" )  {  $cs->criteria['layer4']->Set("");      }

if ( $submit == "ADD Time" && $cs->criteria['time']->GetFormItemCnt() < $MAX_ROWS)         
   $cs->criteria['time']->AddFormItem($submit, $cs->criteria['layer4']->Get());
if ( $submit == "ADD Addr" && $cs->criteria['ip_addr']->GetFormItemCnt() < $MAX_ROWS)     
   $cs->criteria['ip_addr']->AddFormItem($submit, $cs->criteria['layer4']->Get());
if ( $submit == "ADD IP Field" && $cs->criteria['ip_field']->GetFormItemCnt() < $MAX_ROWS)    
   $cs->criteria['ip_field']->AddFormItem($submit, $cs->criteria['layer4']->Get());
if ( $submit == "ADD TCP Port" && $cs->criteria['tcp_port']->GetFormItemCnt() < $MAX_ROWS)    
   $cs->criteria['tcp_port']->AddFormItem($submit, $cs->criteria['layer4']->Get());
if ( $submit == "ADD TCP Field" && $cs->criteria['tcp_field']->GetFormItemCnt() < $MAX_ROWS)   
   $cs->criteria['tcp_field']->AddFormItem($submit, $cs->criteria['layer4']->Get());
if ( $submit == "ADD UDP Port" && $cs->criteria['udp_port']->GetFormItemCnt() < $MAX_ROWS)    
   $cs->criteria['udp_port']->AddFormItem($submit, $cs->criteria['layer4']->Get());
if ( $submit == "ADD UDP Field" && $cs->criteria['udp_field']->GetFormItemCnt() < $MAX_ROWS)
   $cs->criteria['udp_field']->AddFormItem($submit, $cs->criteria['layer4']->Get());
if ( $submit == "ADD ICMP Field" && $cs->criteria['icmp_field']->GetFormItemCnt() < $MAX_ROWS)
   $cs->criteria['icmp_field']->AddFormItem($submit, $cs->criteria['layer4']->Get());
if ( $submit == "ADD Payload" && $cs->criteria['data']->GetFormItemCnt() < $MAX_ROWS)
   $cs->criteria['data']->AddFormItem($submit, $cs->criteria['layer4']->Get());

echo '
<!-- ************ Meta Criteria ******************** -->
<TABLE WIDTH="100%" BORDER=0>
  <TR>
      <TD WIDTH="40%" CLASS="metatitle"><B>'._QCMETACRIT.'</B></TD>
      <TD></TD></TR>
</TABLE>

<TABLE WIDTH="100%" border=2 class="query">
  <TR>
      <TD COLSPAN=2>
           <B>'._SENSOR.': </B>';
     $cs->criteria['sensor']->PrintForm();

     echo '<B>Alert Group: </B>';
     $cs->criteria['ag']->PrintForm();
     echo '</TD>';

     echo '<TR>
            <TD><B>'._SIGNATURE.': </B></TD>
           <TD>';  

     $cs->criteria['sig']->PrintForm();

     if ( $db->baseGetDBversion() >= 103 )
     {
        echo '<B>'._CHRTCLASS.': </B>';
        $cs->criteria['sig_class']->PrintForm();
        echo '<B>'._PRIORITY.': </B>';
        $cs->criteria['sig_priority']->PrintForm();
     }     

     echo '</TD></TR>';    

echo '<TR>
      <TD><B>Alert Time:</B></TD>
      <TD>';
      $cs->criteria['time']->PrintForm();    
      
        echo '
</TABLE>';

  echo '
<!-- ************ IP Criteria ******************** -->
<P>
<TABLE WIDTH="100%" BORDER=0>
  <TR>
      <TD WIDTH="40%" CLASS="iptitle"><B>'._QCIPCRIT.'</B></TD>
      <TD></TD></TR>
</TABLE>

<TABLE WIDTH="100%" BORDER=2 class="query">';
      echo '<TR><TD VALIGN=TOP><B>'._ADDRESS.':</B>';  
      echo '    <TD>';

      $cs->criteria['ip_addr']->PrintForm();

      echo '<TR><TD><B>Misc:</B>';
      echo '    <TD>';

      $cs->criteria['ip_field']->PrintForm();

   echo '
   <TR><TD><B>Layer-4:</B>
       <TD>';

   $cs->criteria['layer4']->PrintForm();
   
echo '
   </TABLE>';

if ( $cs->criteria['layer4']->Get() == "TCP" )
{
  echo '
<!-- ************ TCP Criteria ******************** -->
<P>
<TABLE WIDTH="100%" BORDER=0>
  <TR>
      <TD WIDTH="40%" CLASS="layer4title"><B>'._QCTCPCRIT.'</B></TD>
      <TD></TD>
</TABLE>

<TABLE WIDTH="100%" BORDER=2 class="query">';

      echo '<TR><TD><B>Port:</B>';
      echo '    <TD>';
      $cs->criteria['tcp_port']->PrintForm();

  echo '
  <TR>
      <TD VALIGN=TOP><B>Flags:</B>';
      $cs->criteria['tcp_flags']->PrintForm();

      echo '<TR><TD><B>Misc:</B>';
      echo '    <TD>';
      $cs->criteria['tcp_field']->PrintForm();

  echo'
</TABLE>';
}

if ( $cs->criteria['layer4']->Get() == "UDP" )
{
  echo '
<!-- ************ UDP Criteria ******************** -->
<P>
<TABLE WIDTH="100%" BORDER=0>
  <TR>
      <TD WIDTH="40%" CLASS="layer4title"><B>'._QCUDPCRIT.'</B></TD>
      <TD></TD>
</TABLE>

<TABLE WIDTH="100%" BORDER=2 class="query">';

      echo '<TR><TD><B>Port:</B>';
      echo '    <TD>';
      $cs->criteria['udp_port']->PrintForm();

      echo '<TR><TD><B>Misc:</B>';
      echo '    <TD>';
      $cs->criteria['udp_field']->PrintForm();
  echo'
</TABLE>';
}


if ( $cs->criteria['layer4']->Get() == "ICMP" )
{
  echo  '
<!-- ************ ICMP Criteria ******************** -->
<P>
<TABLE WIDTH="100%" BORDER=0>
  <TR>
      <TD WIDTH="40%" CLASS="layer4title"><B>'._QCICMPCRIT.'</B></TD>
      <TD></TD>
</TABLE>


<TABLE WIDTH="100%" BORDER=2 class="query">';

      echo '<TR><TD><B>Misc:</B>';
      echo '    <TD>';
      $cs->criteria['icmp_field']->PrintForm();
   echo '
</TABLE>'; 
}

echo '
<!-- ************ Payload Criteria ******************** -->
<P>
<TABLE WIDTH="100%" BORDER=0>
  <TR>
      <TD WIDTH="40%" CLASS="payloadtitle"><B>'._QCPAYCRIT.'</B></TD>
      <TD></TD></TR>
</TABLE>

<TABLE WIDTH="100%" BORDER=2 class="query">
  <TR>
      <TD>';
      $cs->criteria['data']->PrintForm();

        echo '
</TABLE>';

  echo '<INPUT TYPE="hidden" NAME="new" VALUE="1">';
  echo '<P>
        <CENTER>
        <TABLE BORDER=1>
        <TR><TD>
            <FONT>
            <B>'._QFRMSORTORDER.':</B>
            <INPUT TYPE="radio" NAME="sort_order" 
                   VALUE="none" '.chk_check($sort_order, "none").'> none |
            <INPUT TYPE="radio" NAME="sort_order" 
                   VALUE="time_a" '.chk_check($sort_order, "time_a").'> '._QFRMTIMEA.' |
            <INPUT TYPE="radio" NAME="sort_order" 
                   VALUE="time_d" '.chk_check($sort_order, "time_d").'> '._QFRMTIMED.' |
            <INPUT TYPE="radio" NAME="sort_order" 
                   VALUE="sig" '.chk_check($sort_order, "sig").'> '._QFRMSIG.' <!--|
            <INPUT TYPE="radio" NAME="sort_order" 
                   VALUE="sip" '.chk_check($sort_order, "sip").'> '._QFRMSIP.' |
            <INPUT TYPE="radio" NAME="sort_order" 
                   VALUE="dip" '.chk_check($sort_order, "dip").'> '._QFRMDIP.'-->
            <BR>
            <CENTER><INPUT TYPE="submit" NAME="submit" VALUE="Query DB"></CENTER>
             </FONT>
             </TD>
        </TR>
        </TABLE>
        </CENTER>';
?>
