Location: PHPKode > projects > SnortCenter 2.x > snortcenter-release/add_sensor.php
<?php
    /*
    ** SnortCenter Copyright (C) 2001,2002,2003 Stefan Dens
    **
    ** Author: Stefan Dens <hide@address.com>
    **
    ** This program is free software; you can redistribute it and/or modify
    ** it under the terms of the GNU General Public License as published by
    ** the Free Software Foundation; either version 2 of the License, or
    ** (at your option) any later version.
    **
    ** This program is distributed in the hope that it will be useful,
        ** but WITHOUT ANY WARRANTY; without even the implied warranty of
    ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    ** GNU General Public License for more details.
    **
    ** You should have received a copy of the GNU General Public License
    ** along with this program; if not, write to the Free Software
    ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
    */
?>
<?php
    include("config.php");
    include_once("list.inc.php");
    $db = NewACIDDBConnection($DBlib_path, $DBtype);
    $db->acidConnect($DB_dbname, $DB_host, $DB_port, $DB_user, $DB_password);
     
    if ($do == 'Deactivate') {
        deactivate($config, 'config', $sensor_id, $db);
    }
    if ($do == 'Activate') {
        activate($config, 'config', $sensor_id, $db);
    }

    if (($do == "Save as New") || ($do == "Save")) {
        $sensor_name = ereg_replace("[^[:alnum:] _]", "", $sensor_name);
        $sql_insert = "INSERT INTO sensor (sensor_ip, sensor_port, sensor_name, sensor_user, sensor_passw, net_proto, cmd_line, interface, enable ";
        $sql_values = "VALUES ('$sensor_ip', '$sensor_port', '$sensor_name', '$sensor_user', '$sensor_passw', '$net_proto', '$cmd_line', '$sensor_interface', '$sensor_enable' ";
        if ($sensor_default_config) {
            $result = $db->acidExecute("SELECT id FROM vars WHERE snort_default='yes'");
            while ($myrow = $result->acidFetchRow()) {
		$var_value .= "|$myrow[0]|;";     	    
	    }
            $result = $db->acidExecute("SELECT id FROM preprocessor WHERE snort_default='yes'");
            while ($myrow = $result->acidFetchRow()) {
		$spp_value .= "|$myrow[0]|;";     	    
	    }
            $result = $db->acidExecute("SELECT id FROM output WHERE snort_default='yes'");
            while ($myrow = $result->acidFetchRow()) {
		$spo_value .= "|$myrow[0]|;";     	    
	    }
            $result = $db->acidExecute("SELECT id FROM ruletype WHERE snort_default='yes'");
            while ($myrow = $result->acidFetchRow()) {
		$ruletype_value .= "|$myrow[0]|;";
	    }
            $result = $db->acidExecute("SELECT id FROM config WHERE snort_default='yes'");
            while ($myrow = $result->acidFetchRow()) {
		$config_value .= "|$myrow[0]|;";
	    }
	    $sql_insert .= ', vars, preprocessor, output, ruletype, config, rules_template';
	    $sql_values .= ", '$var_value', '$spp_value', '$spo_value', '$ruletype_value', '$config_value', '|1|;'";
	}
        $sql_insert  .= ")";
        $sql_values  .= ")";
        $result = $db->acidExecute("$sql_insert $sql_values");
        $result = $db->acidExecute("SELECT max(id) FROM sensor");
        $myrow = $result->acidFetchRow();
        $result->acidFreeRows();
        $sensor_id = $myrow[0];
	echo '<SCRIPT language=javascript>setTimeout("location.href=\'sensor.php?sensor_id='.$sensor_id.'\'",0);</SCRIPT>';    
    }
     
    if ($do == "Update") {
        $sensor_name = ereg_replace("[^[:alnum:] _]", "", $sensor_name);
        $result = $db->acidExecute("UPDATE sensor SET sensor_name='$sensor_name', sensor_ip='$sensor_ip', sensor_user='$sensor_user', sensor_passw='$sensor_passw', sensor_port='$sensor_port', net_proto='$net_proto', cmd_line='$cmd_line', interface='$sensor_interface', enable='$sensor_enable' where id='$sensor_id'");
        $result->acidFreeRows();
	echo '<SCRIPT language=javascript>setTimeout("location.href=\'sensor.php?sensor_id='.$sensor_id.'\'",0);</SCRIPT>';
    }
     
    if ($do  != "new") {
        $result = $db->acidExecute("SELECT id, sensor_name, sensor_ip, sensor_port, sensor_user, sensor_passw, net_proto, cmd_line, interface, enable FROM sensor where id='$sensor_id'");
        $myrow = $result->acidFetchRow();
        $result->acidFreeRows();
        list($id, $sensor_name, $sensor_ip, $sensor_port, $sensor_user, $sensor_passw, $net_proto, $cmd_line, $sensor_interface, $sensor_enable) = $myrow;
    }

    include('top.inc.php');
    echo "<BR>";
    echo "<table align=center border=0 cellpadding=1 cellspacing=0 width=60%><tr bgcolor=#f9f890><td>";
    echo "<table style=\"font-size:12px; font-family: Verdana;\" align=center border=0 cellspacing=0 cellpadding=0 width=100%>";
     
    echo "<FORM action=\"\" method=GET>";
    echo "<INPUT TYPE=HIDDEN NAME=sensor_id VALUE='$sensor_id'>";
    echo "<TR><TD colspan=2><B>$lang[46]</B></TD></TR>";
    echo "<TR bgcolor=#DDDDDD><TD>&nbsp;$lang[226]</TD><TD><INPUT NAME=\"sensor_enable\" TYPE='checkbox' value='1' ";
    if ($do == 'new') echo "CHECKED";
    elseif ($sensor_enable == '1') echo "CHECKED";
    echo "></TD></TR>";
    echo "<TR bgcolor=#DDDDDD><TD>&nbsp;$lang[47]</TD><TD><INPUT NAME=sensor_name TYPE=TEXT value='$sensor_name' SIZE=50></TD></TR>";
    echo "<TR bgcolor=#DDDDDD><TD>&nbsp;$lang[48]</TD><TD><INPUT NAME=sensor_ip TYPE=TEXT value='$sensor_ip' SIZE=15>&nbsp;&nbsp;Port#&nbsp;<INPUT NAME=sensor_port TYPE=TEXT value='$sensor_port' SIZE=15></TD></TR>";
    echo "<TR bgcolor=#DDDDDD><TD>&nbsp;$lang[49]</TD><TD><INPUT NAME=sensor_user TYPE=text value='$sensor_user' SIZE=50></TD></TR>";
    echo "<TR bgcolor=#DDDDDD><TD>&nbsp;$lang[50]</TD><TD><INPUT NAME=sensor_passw TYPE=PASSWORD value='$sensor_passw' SIZE=50></TD></TR>";
    echo "<TR bgcolor=#DDDDDD><TD>&nbsp;$lang[51]</TD><TD><SELECT NAME=net_proto><OPTION value='snortcenter_v1_ssl' ";
    if ($net_proto == 'snortcenter_v1_ssl') {
        echo 'SELECTED';
    }
    echo ">SnortCenter Agent v.1 (SSL enabled)</OPTION>";
     
    echo "<OPTION value='snortcenter_v1_nossl' ";
    if ($net_proto == 'snortcenter_v1_nossl') {
        echo 'SELECTED';
    }
    echo ">SnortCenter Agent v.1 (SSL disabled)</OPTION>";
     
    echo "<OPTION value='snortcenter_v1_windows_ssl' ";
    if ($net_proto == 'snortcenter_v1_windows_ssl') {
        echo 'SELECTED';
    }
    echo ">SnortCenter Agent for Windows v.1 (SSL enabled)</OPTION>";
     
    echo "<OPTION value='snortcenter_v1_windows_nossl' ";
    if ($net_proto == 'snortcenter_v1_windows_nossl') {
        echo 'SELECTED';
    }
    echo ">SnortCenter Agent for Windows v.1 (SSL disabled)</OPTION>";
     
    echo "</SELECT></TD></TR>";
    echo "<TR bgcolor=#DDDDDD><TD>&nbsp;$lang[225]</TD><TD><INPUT NAME=sensor_interface TYPE=TEXT value='$sensor_interface' SIZE=50></TD></TR>";
    echo "<TR bgcolor=#DDDDDD><TD>&nbsp;$lang[58]</TD><TD><INPUT NAME='cmd_line' TYPE=TEXT value='$cmd_line' SIZE=50></TD></TR>";
/*
    if ($do == "new") {
        echo "<TR bgcolor=#DDDDDD><TD>&nbsp;$lang[53]</TD><TD><INPUT NAME=\"sensor_default_config\" TYPE='checkbox' CHECKED></TD></TR>";
    }
    else {
	echo '<TR bgcolor=#DDDDDD><TD colspan=2>&nbsp</TD></TR><TR bgcolor=#DDDDDD><TD colspan=2>';
	$rule_act = get_active('config', $sensor_id, $db);
	display_list_start($sensor_id, 0);
     
    $result = $db->acidExecute("SELECT id,config_name,config_value, snort_default from config WHERE config_name != 'classification:' AND config_name != 'reference:' ORDER BY snort_default, config_name");
    $count = 0;
    while ($myrow = $result->acidFetchRow()) {
        list($id, $config_name, $config_value, $snort_default) = $myrow;
        if ($color  != "white") {
            $color = "white";
        } else {
            $color = "#DDDDDD";
        }
#	if ($snort_default == 'yes') $color = '#fffaa8';
        echo "<TR border=1 style='border : $color;' bgcolor=$color><TD width=25>";
        if (in_array ("|$id|", $rule_act)) {
            echo"<A href=\"add_sensor.php?config[$count]=$id&do=Deactivate&sensor_id=$sensor_id\"><img border=0 alt=\"Deactivate\" height=20 src='./images/green.png'></A>&nbsp;";
        } else {
            echo"<A href=\"add_sensor.php?config[$count]=$id&do=Activate&sensor_id=$sensor_id\"><img border=0 alt=\"Activate\" height=20 src='./images/red.png'></A>&nbsp;";
        }
        echo "</TD><TD><label for='$id'>config $config_name&nbsp;$config_value</label></TD></TR>";
        $count++;
    }
    echo '<TR><TD>&nbsp</TD></TR>';
    display_list_end(0);
    echo '</TD></TR>';
    }
*/    
    echo "<TR bgcolor=#DDDDDD><TD colspan=2>&nbsp;</TD></TR>";
    echo "</TABLE></TD></TR></TABLE><BR>";
    if ($do == "new") {
        echo "<CENTER><INPUT NAME='do' VALUE='Save' TYPE=SUBMIT>&nbsp;<INPUT VALUE='Reset' TYPE=RESET></CENTER>";
    } else {
        echo "<CENTER><INPUT NAME='do' VALUE='Update' TYPE=SUBMIT>&nbsp;<INPUT NAME='do' VALUE='Save as New' TYPE=SUBMIT>&nbsp;<INPUT VALUE='Reset' TYPE=RESET></CENTER>";
    }
    echo "</FORM>";
    echo "<BR>";
    require('bottom.inc.php');
?>
Return current item: SnortCenter 2.x