header("Location: /snort/snort_interfaces.php");
        exit;
    }
}
/* start/stop barnyard2 */
if ($_POST['bartoggle'] && is_numericint($_POST['id'])) {
    $snortcfg = $config['installedpackages']['snortglobal']['rule'][$_POST['id']];
    $if_real = get_real_interface($snortcfg['interface']);
    $if_friendly = convert_friendly_interface_to_friendly_descr($snortcfg['interface']);
    if (!snort_is_running($snortcfg['uuid'], $if_real, 'barnyard2')) {
        log_error("Toggle (barnyard starting) for {$if_friendly}({$snortcfg['descr']})...");
        sync_snort_package_config();
        snort_barnyard_start($snortcfg, $if_real);
    } else {
        log_error("Toggle (barnyard stopping) for {$if_friendly}({$snortcfg['descr']})...");
        snort_barnyard_stop($snortcfg, $if_real);
    }
    sleep(3);
    // So the GUI reports correctly
}
/* start/stop snort */
if ($_POST['toggle'] && is_numericint($_POST['id'])) {
    $snortcfg = $config['installedpackages']['snortglobal']['rule'][$_POST['id']];
    $if_real = get_real_interface($snortcfg['interface']);
    $if_friendly = convert_friendly_interface_to_friendly_descr($snortcfg['interface']);
    if (snort_is_running($snortcfg['uuid'], $if_real)) {
        log_error("Toggle (snort stopping) for {$if_friendly}({$snortcfg['descr']})...");
        snort_stop($snortcfg, $if_real);
    } else {
        log_error("Toggle (snort starting) for {$if_friendly}({$snortcfg['descr']})...");
        /* set flag to rebuild interface rules before starting Snort */
            $natent['barnconfigpassthru'] = base64_encode($_POST['barnconfigpassthru']);
        } else {
            unset($natent['barnconfigpassthru']);
        }
        $a_nat[$id] = $natent;
        write_config("Snort pkg: modified Barnyard2 settings.");
        // No need to rebuild rules for Barnyard2 changes
        $rebuild_rules = false;
        sync_snort_package_config();
        // If disabling Barnyard2 on the interface, stop any
        // currently running instance.  If an instance is
        // running, signal it to reload the configuration.
        // If Barnyard2 is enabled but not running, notify the
        // user to restart Snort to enable Unified2 output.
        if ($a_nat[$id]['barnyard_enable'] == "off") {
            snort_barnyard_stop($a_nat[$id], get_real_interface($a_nat[$id]['interface']));
        } elseif ($a_nat[$id]['barnyard_enable'] == "on") {
            if (snort_is_running($a_nat[$id]['uuid'], get_real_interface($a_nat[$id]['interface']), "barnyard2")) {
                snort_barnyard_reload_config($a_nat[$id], "HUP");
            } else {
                // Notify user a Snort restart is required if enabling Barnyard2 for the first time
                $savemsg = gettext("NOTE: you must restart Snort on this interface to activate unified2 logging for Barnyard2.");
            }
        }
        $pconfig = $natent;
    } else {
        // We had errors, so save previous field data to prevent retyping
        $pconfig = $_POST;
    }
}
$if_friendly = convert_friendly_interface_to_friendly_descr($a_nat[$id]['interface']);