#!/usr/clearos/sandbox/usr/bin/php
<?php

/**
 * Intrusion detection network connected change handler.
 *
 * @category   apps
 * @package    intrusion-detection
 * @subpackage scripts
 * @author     ClearFoundation <developer@clearfoundation.com>
 * @copyright  2013 ClearFoundation
 * @license    http://www.gnu.org/copyleft/gpl.html GNU General Public License version 3 or later
 * @link       http://www.clearfoundation.com/docs/developer/apps/intrusion_detection/
 */

///////////////////////////////////////////////////////////////////////////////
//
// 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 3 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, see <http://www.gnu.org/licenses/>.
//
///////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////
// B O O T S T R A P
///////////////////////////////////////////////////////////////////////////////

$bootstrap = getenv('CLEAROS_BOOTSTRAP') ? getenv('CLEAROS_BOOTSTRAP') : '/usr/clearos/framework/shared';
require_once $bootstrap . '/bootstrap.php';

///////////////////////////////////////////////////////////////////////////////
// D E P E N D E N C I E S
///////////////////////////////////////////////////////////////////////////////

use \clearos\apps\intrusion_detection\Snort as Snort;

clearos_load_library('intrusion_detection/Snort');

///////////////////////////////////////////////////////////////////////////////
// M A I N
///////////////////////////////////////////////////////////////////////////////

$snort = new Snort();

// Update configuration (HOME_NET)
$snort->auto_configure();

/**
 * PPPOEKLUDGE
 *
 * PPPoE and Snort do not mix well.  When a ppp0 interface is torn down,
 * it takes Snort down with it.  This script restarts snort when the
 * "network connected" event is triggered.
 */

$running_state = $snort->get_running_state();
$boot_state = $snort->get_boot_state();

if ($boot_state && !$running_state) {
    $snort->set_running_state(TRUE);
    clearos_log('intrusion-detection', 'restarting intrusion detection');
}
