Пример #1
0
function Process_stat_tab($tab_changed, $profile_changed)
{
    // the default display page - the profile stats
    $_SESSION['display'] = 'default';
    // if it's a new profile, only admin tasks make sense
    // no refresh
    if ($_SESSION['profileinfo']['status'] == 'new') {
        $_SESSION['tablock'] = "A new profile needs to be completed first.";
    } else {
        unset($_SESSION['tablock']);
    }
    if (isset($_COOKIE['extended_channellist'])) {
        $_POST['extended_channellist'] = $_COOKIE['extended_channellist'];
    }
    $parse_opts = array("extended_channellist" => array("required" => 0, "default" => 1, "allow_null" => 0, "match" => array(0, 1), "validate" => NULL));
    list($form_data, $has_errors) = ParseForm($parse_opts);
    $_COOKIE['extended_channellist'] = $form_data['extended_channellist'];
    // just display profile status
    if ($tab_changed || $profile_changed) {
        unset($_SESSION['form_data']);
        return;
    }
    // Delete this profile - process confirmed action
    if (array_key_exists('deleteprofile_x', $_POST)) {
        $parse_opts = array("switch" => array("required" => 1, "default" => NULL, "allow_null" => 0, "match" => "/^[A-Za-z0-9\\.][A-Za-z0-9\\-+_\\/]+\$/", "validate" => "profile_exists_validate", "must_exist" => 1));
        list($form_data, $has_errors) = ParseForm($parse_opts);
        if ($has_errors > 0) {
            return;
        }
        if ($form_data['switch'] != $_SESSION['profileswitch']) {
            SetMessage('error', "Profile to delete is not current profile");
            return;
        }
        // Do the work
        $cmd_opts['profile'] = $_SESSION['profileswitch'];
        if (array_key_exists('pid', $_SESSION)) {
            $cmd_opts['pid'] = $_SESSION['pid'];
        }
        $cmd_out = nfsend_query("delete-profile", $cmd_opts, 0);
        if (is_array($cmd_out)) {
            SetMessage('info', "Profile '" . $cmd_opts['profile'] . "' deleted");
            unset($_SESSION['ProfileList']);
            $profiles = GetProfiles();
            // as current profile no longer exists, switch to 'live'
            $_SESSION['profile'] = 'live';
            $_SESSION['profilegroup'] = '.';
            $_SESSION['profileswitch'] = './live';
            $profileinfo = ReadProfile($_SESSION['profileswitch']);
            $_SESSION['profileinfo'] = $profileinfo;
        }
        // else errors are displayed anyway - nothing to do
        return;
    }
    // Cancel building the profile
    if (array_key_exists('cancelbuild_x', $_POST)) {
        $parse_opts = array("switch" => array("required" => 1, "default" => NULL, "allow_null" => 0, "match" => "/^[A-Za-z0-9\\.][A-Za-z0-9\\-+_\\/]+\$/", "validate" => "profile_exists_validate", "must_exist" => 1));
        list($form_data, $has_errors) = ParseForm($parse_opts);
        if ($has_errors > 0) {
            return;
        }
        if ($form_data['switch'] != $_SESSION['profileswitch']) {
            SetMessage('error', "Profile to delete is not current profile");
            return;
        }
        // Do the work
        $cmd_opts['profile'] = $_SESSION['profileswitch'];
        $cmd_out = nfsend_query("cancel-profile", $cmd_opts, 0);
        if (is_array($cmd_out)) {
            SetMessage('info', "Building profile '" . $cmd_opts['profile'] . "' canceled");
            $profiles = GetProfiles();
            $_SESSION['cancel-inprogress'] = 1;
        }
        // else errors are displayed anyway - nothing to do
        $_SESSION['refresh'] = 5;
        return;
    }
    // put profile into another group?
    if (array_key_exists('regroup', $_POST)) {
        if (!array_key_exists('groupselect', $_POST) || !array_key_exists('profilegroup', $_POST)) {
            SetMessage('error', "Missing parameters");
            return;
        }
        $_group = Util::htmlentities($_POST['groupselect']);
        if ($_group == '(nogroup)') {
            $_group = '.';
        } else {
            if ($_group == 'New group ...') {
                $_group = Util::htmlentities($_POST['profilegroup']);
            }
        }
        if ($_group != '.' && !preg_match("/^[A-Za-z0-9][A-Za-z0-9\\-+_]+\$/", $_group)) {
            SetMessage('error', "Illegal characters in group name '{$_group}'");
            return;
        } else {
            $cmd_opts['profile'] = $_SESSION['profile'];
            $cmd_opts['profilegroup'] = $_SESSION['profilegroup'];
            $cmd_opts['newgroup'] = $_group;
        }
        if ($cmd_opts['profilegroup'] == $cmd_opts['newgroup']) {
            // nothing changed
            return;
        }
        // Do the work
        $cmd_out = nfsend_query("modify-profile", $cmd_opts, 0);
        if (is_array($cmd_out)) {
            // update new info in SESSION
            $_SESSION['profilegroup'] = $cmd_opts['newgroup'];
            $_SESSION['profileswitch'] = $cmd_opts['newgroup'] . '/' . $_SESSION['profile'];
            $profileinfo = ReadProfile($_SESSION['profileswitch']);
            $_SESSION['profileinfo'] = $profileinfo;
            unset($_SESSION['ProfileList']);
            $profiles = GetProfiles();
        }
        // else errors are displayed anyway - nothing to do
        return;
    }
    // Edit a profile
    if (array_key_exists('edit', $_POST)) {
        $cmd_opts = array();
        if (array_key_exists('profile_maxsize', $_POST)) {
            $_tmp = ParseMaxSize($_POST['profile_maxsize']);
            if (strlen($_tmp) > 0) {
                $cmd_opts['maxsize'] = $_tmp;
            } else {
                SetMessage('warning', "Invalid value for maxsize");
            }
        }
        if (array_key_exists('profile_expire', $_POST)) {
            $_tmp = ParseExpire($_POST['profile_expire']);
            if ($_tmp >= 0) {
                $cmd_opts['expire'] = $_tmp;
            } else {
                SetMessage('warning', "Invalid value for expire");
            }
        }
        if (array_key_exists('description', $_POST)) {
            $_tmp = preg_replace("/\r/", '', $_POST['description']);
            if (!get_magic_quotes_gpc()) {
                $description = addslashes($_tmp);
            } else {
                $description = $_tmp;
            }
            $cmd_opts['description'] = explode("\n", $description);
        }
        if (array_key_exists('profile_type', $_POST)) {
            $_tmp = $_POST['profile_type'];
            if (!is_numeric($_tmp) || $_tmp > 6) {
                SetMessage('warning', "Invalid value for profile_type");
            } else {
                if ($_SESSION['profileinfo']['type'] != $_tmp) {
                    $cmd_opts['profile_type'] = $_tmp;
                }
            }
        }
        if (count(array_keys($cmd_opts)) > 0) {
            $cmd_opts['profile'] = $_SESSION['profileswitch'];
            // Do the work
            $cmd_out = nfsend_query("modify-profile", $cmd_opts, 0);
            if (is_array($cmd_out)) {
                $profileinfo = ReadProfile($_SESSION['profileswitch']);
                $_SESSION['profileinfo'] = $profileinfo;
            }
        }
        return;
    }
    // Cancel an edit or add a channel dialog
    if (array_key_exists('edit_channel_cancel', $_POST) || array_key_exists('add_channel_cancel', $_POST)) {
        // nothing to do - default will do
        return;
    }
    // Add a new channel - provide add dialog
    if (array_key_exists('add_channel_x', $_POST)) {
        $_POST['add_channel'] = $_POST['add_channel_x'];
    }
    if (array_key_exists('add_channel', $_POST)) {
        $_SESSION['display'] = 'add_channel';
        $_SESSION['refresh'] = 0;
        return;
    }
    // edit a channel - provide edit dialog
    if (array_key_exists('edit_channel', $_POST)) {
        $parse_opts = array("edit_channel" => array("required" => 1, "default" => NULL, "allow_null" => 0, "match" => "/^[A-Za-z0-9][A-Za-z0-9\\-+_]+\$/", "validate" => NULL));
        list($form_data, $has_errors) = ParseForm($parse_opts);
        $form_data['profileswitch'] = $_SESSION['profileswitch'];
        if ($has_errors > 0) {
            return;
        }
        $_channel = $form_data['edit_channel'];
        if (!array_key_exists($_channel, $_SESSION['profileinfo']['channel'])) {
            SetMessage('error', "Channel '{$_channel}' does not exists in profile '" . $form_data['profile'] . "'");
            return;
        }
        $_SESSION['form_data'] = $form_data;
        $_SESSION['refresh'] = 0;
        $_SESSION['display'] = 'edit_channel';
        return;
    }
    // edit or add a channel? - process commited form entries
    if (array_key_exists('edit_channel_commit', $_POST) || array_key_exists('add_channel_commit', $_POST)) {
        if (array_key_exists('edit_channel_commit', $_POST)) {
            $_display = "edit_channel";
        } else {
            $_display = "add_channel";
        }
        $_SESSION['refresh'] = 0;
        $parse_opts = array("name" => array("required" => 1, "default" => NULL, "allow_null" => 0, "match" => "/^[A-Za-z0-9][A-Za-z0-9\\-+_]*\$/", "validate" => NULL), "colour" => array("required" => 1, "default" => NULL, "allow_null" => 0, "match" => "/^#[0-9a-f]{6}/i", "validate" => NULL), "sign" => array("required" => 1, "default" => '+', "allow_null" => 0, "match" => array('+', '-'), "validate" => NULL), "order" => array("required" => 1, "default" => 1, "allow_null" => 0, "match" => "/^[0-9]{1,2}/", "validate" => NULL), "filter" => array("required" => 1, "default" => NULL, "allow_null" => 0, "match" => "/^[\\s!-~]+\$/", "validate" => 'filter_validate'), "configured" => array("required" => 1, "default" => array(), "allow_null" => 0, "match" => NULL, "validate" => 'channel_validate'));
        list($form_data, $has_errors) = ParseForm($parse_opts);
        $form_data['profile'] = $_SESSION['profile'];
        $form_data['profilegroup'] = $_SESSION['profilegroup'];
        // additional checks
        if (!is_null($form_data['name'])) {
            $_channel = $form_data['name'];
            if ($_display == "edit_channel") {
                // verify channel in existing profile
                if (!array_key_exists($_channel, $_SESSION['profileinfo']['channel'])) {
                    SetMessage('error', "Channel '{$_channel}' does not exist in profile '{$profile}'");
                    $has_errors = 1;
                }
            } else {
                // verify channel name for new channel
                if (array_key_exists($_channel, $_SESSION['profileinfo']['channel'])) {
                    SetMessage('error', "Channel '{$_channel}' already exist in profile '" . $_SESSION['profile'] . "'");
                    $has_errors = 1;
                }
            }
        }
        // else error already reported by ParseForm
        // must not change the sourcelist or the filter of a channel in profile 'live'
        if ($form_data['profile'] == 'live') {
            unset($form_data['sourcelist']);
            unset($form_data['filter']);
        } else {
            $form_data['sourcelist'] = implode('|', $form_data['configured']);
        }
        unset($form_data['configured']);
        $_SESSION['form_data'] = $form_data;
        if ($has_errors > 0) {
            $_SESSION['display'] = $_display;
            return;
        }
        // Do the work
        $command = $_display == 'add_channel' ? 'add-channel' : 'modify-channel';
        // make sure parameters match for nfsend
        $form_data['channel'] = $form_data['name'];
        unset($form_data['name']);
        $cmd_out = nfsend_query($command, $form_data, 0);
        if (is_array($cmd_out)) {
            $profileinfo = ReadProfile($_SESSION['profileswitch']);
            $_SESSION['profileinfo'] = $profileinfo;
            unset($_SESSION['form_data']);
        } else {
            // fishy something went wrong
            $_SESSION['display'] = $_display;
        }
        return;
    }
    // delete a channel
    if (array_key_exists('delete_channel_commit_x', $_POST)) {
        if (!array_key_exists('name', $_POST)) {
            SetMessage('error', "Missing channel name");
            return;
        }
        $profile = $_SESSION['profile'];
        $_channelname = $_POST['name'];
        if (!array_key_exists($_channelname, $_SESSION['profileinfo']['channel'])) {
            SetMessage('error', "Channel '{$_tmp}' does not exist in profile '{$profile}'");
            return;
        }
        // do the work
        $cmd_opts['profile'] = $_SESSION['profileswitch'];
        $cmd_opts['channel'] = $_channelname;
        $cmd_out = nfsend_query("delete-channel", $cmd_opts, 0);
        if (is_array($cmd_out)) {
            $profileinfo = ReadProfile($_SESSION['profileswitch']);
            $_SESSION['profileinfo'] = $profileinfo;
        }
        return;
    }
    // Cancel a new profile dialog
    if (array_key_exists('new_profile_cancel', $_POST)) {
        if (array_key_exists("new_profile", $_SESSION)) {
            unset($_SESSION['new_profile']);
        }
        // default will do
        return;
    }
    // create a new profile - provide the new profile dialog
    // this input comes directly from the profile select menu
    if (array_key_exists('new_profile', $_SESSION)) {
        unset($_SESSION['new_profile']);
        $_SESSION['display'] = 'new_profile';
        return;
    }
    // create a new profile - process commited form
    if (array_key_exists('new_profile_commit', $_POST)) {
        $parse_opts = array("newprofileswitch" => array("required" => 1, "default" => NULL, "allow_null" => 0, "match" => "/^[A-Za-z0-9\\.][A-Za-z0-9\\-+_\\/]+\$/", "validate" => "profile_exists_validate", "must_exist" => 0), "tstart" => array("required" => 1, "default" => NULL, "allow_null" => 1, "match" => "/^[0-9]+[0-9\\-]+[0-9]+\$/", "validate" => "date_time_validate"), "tend" => array("required" => 1, "default" => NULL, "allow_null" => 1, "match" => "/^[0-9]+[0-9\\-]+[0-9]+\$/", "validate" => "date_time_validate"), "channel_wizard" => array("required" => 1, "default" => NULL, "allow_null" => 0, "match" => array('classic', 'individual'), "validate" => NULL), "expire" => array("required" => 0, "default" => 0, "allow_null" => 0, "match" => "/^[\\s!-~]+\$/", "validate" => 'expire_validate'), "maxsize" => array("required" => 0, "default" => 0, "allow_null" => 0, "match" => "/^[\\s!-~]+\$/", "validate" => 'maxsize_validate'), "description" => array("required" => 0, "default" => NULL, "allow_null" => 1, "match" => "/^[\\s!-~]+\$/", "validate" => 'description_validate'), "filter" => array("required" => 0, "default" => NULL, "allow_null" => 1, "match" => "/^[\\s!-~]+\$/", "validate" => 'filter_validate'), "channel" => array("required" => 0, "default" => array(), "allow_null" => 1, "match" => NULL, "validate" => 'channel_validate'), "shadow" => array("required" => 1, "default" => 1, "allow_null" => 1, "match" => array(0, 1), "validate" => NULL), "num_channels" => array("required" => 0, "default" => 0, "allow_null" => 1, "match" => "/^[0-9]{1,3}\$/", "validate" => NULL));
        list($form_data, $has_errors) = ParseForm($parse_opts);
        if (preg_match("/^(.+)\\/(.+)/", $form_data['newprofileswitch'], $matches)) {
            $_profilegroup = $matches[1];
            $_profilename = $matches[2];
            $form_data['profileswitch'] = $form_data['newprofileswitch'];
            $form_data['profile'] = $_profilename;
            $form_data['profilegroup'] = $_profilegroup;
            unset($form_data['newprofileswitch']);
        } else {
            $has_errors = 1;
        }
        // additional checks
        if (!is_null($form_data['tend']) && !is_null($form_data['tstart']) && $form_data['tend'] < $form_data['tstart']) {
            $ts = UNIX2DISPLAY($form_data['tstart']);
            $te = UNIX2DISPLAY($form_data['tend']);
            $form_data['tstart'] = NULL;
            $form_data['tend'] = NULL;
            SetMessage('error', "Profile end time '{$te}' earlier then Start time '{$ts}'");
            $has_errors = 1;
        }
        if (!is_null($form_data['tend']) && is_null($form_data['tstart'])) {
            $te = UNIX2DISPLAY($form_data['tend']);
            SetMessage('error', "Profile has end time '{$te}', but no start time set");
            $has_errors = 1;
        }
        if ($form_data['channel_wizard'] == 'classic') {
            if (is_null($form_data['filter']) || count($form_data['channel']) == 0) {
                SetMessage('error', "A classic profile needs a valid filter and at least one selected channel");
                $has_errors = 1;
            }
        }
        if ($has_errors > 0) {
            $_SESSION['form_data'] = $form_data;
            $_SESSION['display'] = 'new_profile';
            $_SESSION['refresh'] = 0;
            return;
        }
        // do the work
        if (array_key_exists('channel_wizard', $form_data)) {
            $type = $form_data['channel_wizard'];
            if (NewProfileCreate($form_data, $type) == TRUE) {
                // update NfSen to include the new profile
                unset($_SESSION['ProfileList']);
                $profiles = GetProfiles();
                // switch to new profile
                $_SESSION['profileswitch'] = $form_data['profileswitch'];
                $_SESSION['profile'] = $form_data['profile'];
                $_SESSION['profilegroup'] = $form_data['profilegroup'];
                $_SESSION['profileinfo'] = ReadProfile($_SESSION['profileswitch']);
                SetMessage('info', "Profile '" . $form_data['profile'] . "' created");
                //	if ( $_SESSION['profileinfo']['type'] == 1 && $_SESSION['profileinfo']['status'] != 'new' )
                if ($_SESSION['profileinfo']['tstart'] < $_SESSION['profileinfo']['tend']) {
                    $_SESSION['refresh'] = 5;
                }
            } else {
                $_SESSION['form_data'] = $form_data;
                $_SESSION['display'] = 'new_profile';
            }
        }
        return;
    }
    if (array_key_exists('commit_profile_x', $_POST)) {
        if ($_SESSION['profileinfo']['status'] != 'new' && $_SESSION['profileinfo']['status'] != 'stalled') {
            SetMessage('error', "Can not commit a profile, not in status 'new or stalled'");
            return;
        }
        // Do the work
        // if it fails, the default will do
        if (NewProfileCommit($_SESSION['profileswitch'])) {
            $profileinfo = ReadProfile($_SESSION['profileswitch']);
            $_SESSION['profileinfo'] = $profileinfo;
            unset($_SESSION['tablock']);
            if ($_SESSION['profileinfo']['tstart'] < $_SESSION['profileinfo']['tend']) {
                $_SESSION['refresh'] = 5;
            }
        }
        return;
    }
    // refresh time if profile building in progress
    if (preg_match("/built/", $_SESSION['profileinfo']['status'])) {
        $_SESSION['refresh'] = 5;
    }
}
Пример #2
0
function ParseInput()
{
    global $TabList;
    global $BookmarkVars;
    global $GraphTabs;
    global $Refresh;
    // Preset refresh value. Any Input pasring routing may reset refresh to 0, to disable refresh
    $_SESSION['refresh'] = $Refresh;
    /* 
     * user input may come from forms or links (POST or GET data) due to normal
     * form processing. If a bookmark is specified in the URL, this overwrites other
     * input data. To simplify data input checks, the bookmark is handled as any other post request
     */
    ReportLog("ParseInput:");
    if (isset($_GET['bookmark'])) {
        // process bookmarkstring
        $_bookmark = Util::htmlentities(base64_decode(urldecode($_GET['bookmark'])));
        ReportLog("Bookmark: '{$_bookmark}'");
        $_vars = explode('|', $_bookmark);
        if (count($BookmarkVars) == count($_vars)) {
            for ($i = 0; $i < count($BookmarkVars); $i++) {
                if ($_vars[$i] != '-') {
                    $_varpath = explode('/', $BookmarkVars[$i]);
                    $_varname = count($_varpath) == 2 ? $_varpath[1] : $_varpath[0];
                    ReportLog("Bookmark: Set {$_varname}");
                    $_POST[$_varname] = $_vars[$i];
                }
            }
        } else {
            SetMessage('warning', "Bookmark processing error");
        }
    }
    // process tab
    if (!array_key_exists('tab', $_SESSION)) {
        // first time in this session
        // initialize some more vars in the SESSION var
        InitSession(count($BookmarkVars));
    } else {
        $_tab = $_SESSION['tab'];
    }
    // click on tab list
    if (array_key_exists('tab', $_GET)) {
        $_tab = $_GET['tab'];
    }
    // tab from bookmark overwrites other entries
    if (array_key_exists('tab', $_POST)) {
        $_tab = $_POST['tab'];
    }
    $tab_changed = 0;
    if ($_tab != $_SESSION['tab'] || $_SESSION['tab'] == NULL) {
        // _tab changed since last cycle
        if (array_key_exists('tablock', $_SESSION)) {
            // must not change tab right now
            SetMessage('error', $_SESSION['tablock']);
        } else {
            // Verify new tab
            if (!is_numeric($_tab) || ($_tab > count($TabList) || $_tab < 0)) {
                SetMessage('warning', "Requested Tab not available. Set default tab to " . $TabList[0]);
                $_tab = 0;
            }
            $_tab = (int) $_tab;
            $_SESSION['tab'] = $_tab;
            if (!isset($_GET['bookmark'])) {
                $tab_changed = 1;
            }
            ReportLog("Tab: Set tab to {$_tab}: " . $TabList[$_tab]);
        }
    }
    // rebuild profile list
    if ($tab_changed && $_SESSION['tab'] == 4) {
        unset($_SESSION['ProfileList']);
        unset($_SESSION['PluginList']);
        $profiles = GetProfiles();
        GetPlugins();
    }
    // process sub tab
    $_tab = -1;
    if (array_key_exists('sub_tab', $_GET)) {
        $_tab = strip_tags($_GET['sub_tab']);
    }
    if (array_key_exists('sub_tab', $_POST)) {
        $_tab = strip_tags($_POST['sub_tab']);
    }
    if ($_tab >= 0) {
        if (!is_numeric($_tab) || $_tab < 0) {
            $_tab = 0;
        }
        $_SESSION['sub_tab'] = $_tab;
        ReportLog("Subtab: Set tab to {$_tab}: " . $GraphTabs[$_tab]);
    }
    // process profileswitch
    if (!array_key_exists('profileswitch', $_SESSION)) {
        // this is fishy - InitSession should have set this
        SetMessage('error', "Missing session parameter 'profileswitch'");
        $_SESSION['refresh'] = 0;
        return array(FALSE, 0, 0);
    } else {
        $_profileswitch = $_SESSION['profileswitch'];
    }
    if (array_key_exists('profileswitch', $_POST)) {
        $_profileswitch = Util::htmlentities($_POST['profileswitch']);
    }
    // the alerting module only accepts profile live for now
    if ($_SESSION['tab'] == 3) {
        $_profileswitch = './live';
    }
    $profile_changed = 0;
    if ($_profileswitch != $_SESSION['profileswitch']) {
        if ($_profileswitch == "New Profile ...") {
            // make sure the profile admin page gets this request;
            $_SESSION['tab'] = 4;
            $_SESSION['new_profile'] = TRUE;
            $_SESSION['refresh'] = 0;
        } else {
            // process new profileswitch
            if (preg_match("/^(.+)\\/(.+)/", $_profileswitch, $matches)) {
                $_profilegroup = $matches[1];
                $_profilename = $matches[2];
                // Check if profilegroup/profilename exists
                $_found = FALSE;
                foreach ($_SESSION['ProfileList'] as $p) {
                    if ($p == $_profileswitch) {
                        $_found = TRUE;
                    }
                }
                if (!$_found) {
                    SetMessage('error', "Profile '{$_profilename}' does not exists in profile group '{$_profilegroup}'");
                    SetMessage('warning', "Fall back to profile live");
                    $_profilegroup = '.';
                    $_profilename = 'live';
                }
            } else {
                SetMessage('error', "Can not parse profileswitch");
                SetMessage('warning', "Fall back to profile live");
                $_profilegroup = '.';
                $_profilename = 'live';
            }
            $profile_changed = 1;
            $_SESSION['profile'] = $_profilename;
            $_SESSION['profilegroup'] = $_profilegroup;
            $_SESSION['profileswitch'] = $_profileswitch;
        }
    }
    $profileinfo = ReadProfile($_SESSION['profileswitch']);
    if ($profileinfo == FALSE) {
        SetMessage('warning', "Fall back to profile live");
        unset($_SESSION['ProfileList']);
        $profiles = GetProfiles();
        $_SESSION['profileswitch'] = './live';
        $_SESSION['profile'] = 'live';
        $_SESSION['profilegroup'] = '.';
        $profileinfo = ReadProfile('./live');
        if ($profileinfo == FALSE) {
            // double failure
            SetMessage('error', "Can't read profile 'live'");
            $_SESSION['refresh'] = 0;
            return array(FALSE, 0, 0);
        }
    }
    if ($profileinfo['status'] == 'new') {
        $_SESSION['tab'] = 4;
        $_SESSION['refresh'] = 0;
        $_SESSION['tablock'] = "A new profile needs to be completed first.";
    } else {
        unset($_SESSION['tablock']);
    }
    $_SESSION['profileinfo'] = $profileinfo;
    // no refresh for history profiles
    if (($profileinfo['type'] & 3) == 1) {
        $_SESSION['refresh'] = 0;
    }
    return array(TRUE, $tab_changed, $profile_changed);
}
/**
 * setProfiledVars
 */
function transfer_setProfiledVars()
{
    global $cfg, $tmpl, $transfer, $transferLabel, $ch;
    // set vars for transfer
    if ($cfg['transfer_profiles'] <= 0) {
        $with_profiles = 0;
    } else {
        if ($cfg['transfer_profiles'] >= 2) {
            $with_profiles = 1;
        } else {
            $with_profiles = $cfg['isAdmin'] ? 1 : 0;
        }
    }
    if ($with_profiles == 0) {
        // set vars for transfer from ch
        transfer_setVarsFromCHSettings();
        $tmpl->setvar('useLastSettings', 1);
    } else {
        $profile = tfb_getRequestVar('profile');
        if ($profile != "" && $profile != "last_used") {
            // set vars for transfer from profile
            transfer_setVarsFromProfileSettings($profile);
            $tmpl->setvar('useLastSettings', 0);
            $tmpl->setvar('profile', $profile);
        } else {
            // set vars for transfer from ch
            transfer_setVarsFromCHSettings();
            $tmpl->setvar('useLastSettings', 1);
        }
        // load profile lists
        $profiles = $cfg['transfer_profiles'] >= 3 || $cfg['isAdmin'] ? GetProfiles($cfg["uid"], $profile) : array();
        $public_profiles = $cfg['transfer_profiles'] >= 2 || $cfg['isAdmin'] ? GetPublicProfiles($profile) : array();
        if (count($profiles) + count($public_profiles) > 0) {
            $tmpl->setloop('profiles', $profiles);
            $tmpl->setloop('public_profiles', $public_profiles);
        } else {
            $with_profiles = 0;
        }
    }
    $tmpl->setvar('with_profiles', $with_profiles);
}
Пример #4
0
function navigator()
{
    global $self;
    global $TabList;
    global $GraphTabs;
    $numtabs = count($TabList);
    $plugins = GetPlugins();
    $profiles = GetProfiles();
    $profileswitch = $_SESSION['profileswitch'];
    switch ($_SESSION['profileinfo']['type'] & 3) {
        case 0:
            $profile_type = 'live';
            break;
        case 1:
            $profile_type = 'history';
            break;
        case 2:
            $profile_type = 'continuous';
            break;
        default:
            $type = 'unknown';
    }
    $profile_type .= ($_SESSION['profileinfo']['type'] & 4) > 0 ? '&nbsp;/&nbsp;shadow' : '';
    global $conf;
    echo "<link rel='stylesheet' type='text/css' href='../style/style.css'/>";
    include "../hmenu.php";
    ?>
    <div style="position:absolute;right:95px;top:11px;vertical-align:bottom;width:450px;">
        <table border=0 align="right" style="margin:0px;padding:0px;background-color:transparent;border:0px none">
        <tr><td align="right" class="white" nowrap style="background-color:transparent;border:0px none">
            <a class="white<?php 
    echo $_SESSION['tab'] == 2 ? "n" : "";
    ?>
" href="index.php?tab=2&hmenu=Network&smenu=Network"><?php 
    echo _("Details");
    ?>
</a> |
			<a class="white<?php 
    echo $_SESSION['tab'] == 0 ? "n" : "";
    ?>
" href="index.php?tab=0&hmenu=Network&smenu=Network"><?php 
    echo _("Overview");
    ?>
</a> |
            <a class="white<?php 
    echo $_SESSION['tab'] == 1 ? "n" : "";
    ?>
" href="index.php?tab=1&hmenu=Network&smenu=Network"><?php 
    echo _("Graphs");
    ?>
</a>
            
        </td>
        <td align="right" class="white" nowrap style="padding-left:40px;padding-right:20px;background-color:transparent;border:0px none">
            <!--<?php 
    echo $profile_type;
    ?>
--> <?php 
    echo _("Profile");
    ?>
:
                <a class="select_pullup" id="profilemenu" href="javascript:void(0);" 
                onclick="openSelect(this);" onMouseover="openSelect(this);" 
                onMouseout="selectMouseOut();"></a> | 
            <a class="white<?php 
    echo $_SESSION['tab'] == 3 ? "n" : "";
    ?>
" href="index.php?tab=3&hmenu=Network&smenu=Network"><?php 
    echo _("Alerts");
    ?>
</a> |
            <a class="white<?php 
    echo $_SESSION['tab'] == 4 ? "n" : "";
    ?>
" href="index.php?tab=4&hmenu=Network&smenu=Network"><?php 
    echo _("Stats");
    ?>
</a> |
            <a class="white<?php 
    echo $_SESSION['tab'] == 5 ? "n" : "";
    ?>
" href="index.php?tab=5&hmenu=Network&smenu=Network"><?php 
    echo _("Plugins");
    ?>
</a> |
            <a class="white" href="../sensor/sensor.php?hmenu=SIEM+Components&smenu=SIEM+Components"><?php 
    echo _("Sensors");
    ?>
</a>
        </td></tr>
        </table>
    </div>
	<form action="<?php 
    echo $self;
    ?>
" name='navi' method="POST">
	<input type="hidden" id="profilemenu_field" name="profileswitch" value="<?php 
    echo $profileswitch;
    ?>
"> 
	<div class="shadetabs" style="display:none"><br>
	<table border='0' cellpadding="0" cellspacing="0">
	<tr>
		<td>
			<ul>
<?php 
    for ($i = 0; $i < $numtabs; $i++) {
        if ($i == $_SESSION['tab']) {
            print "<li class='selected'><a href='{$self}?tab={$i}'>" . $TabList[$i] . "</a></li>\n";
        } else {
            print "<li><a href='{$self}?tab={$i}'>" . $TabList[$i] . "</a></li>\n";
        }
    }
    ?>
			</ul>
		</td>
		<td class="navigator">
<?php 
    echo $profile_type;
    ?>
		</td>
		<td class="navigator">
<?php 
    print "<a href='{$self}?bookmark=" . $_SESSION['bookmark'] . "'>" . _("Bookmark URL") . "</a>\n";
    ?>
		</td>
		<td class="navigator"><?php 
    echo _("Profile");
    ?>
:</td>
		<td>
			<!-- <a class="select_pullup" id="profilemenu" href="javascript:void(0);" 
				onclick="openSelect(this);" onMouseover="selectMouseOver();" 
				onMouseout="selectMouseOut();"></a> -->
		</td>
	</tr>
	</table>
 	</div>

<?php 
    $_tab = $_SESSION['tab'];
    if ($TabList[$_tab] == 'Graphs') {
        $_sub_tab = $_SESSION['sub_tab'];
        ?>
		<div class="shadetabs">
		<table border='0' cellpadding="0" cellspacing="0" class="noborder" align="center">
		<tr>
			<td class="noborder" style="padding-bottom:5px;text-align:center">
<?php 
        for ($i = 0; $i < count($GraphTabs); $i++) {
            if ($i > 0) {
                echo "&nbsp;";
            }
            if ($i == $_sub_tab) {
                print "<b>[ <a href='{$self}?sub_tab={$i}'>" . $GraphTabs[$i] . "</a> ]</b>\n";
            } else {
                print "[ <a href='{$self}?sub_tab={$i}'>" . $GraphTabs[$i] . "</a> ]\n";
            }
        }
        ?>
			</td>
		</tr>
		</table>
		</div>
<?php 
    }
    if ($TabList[$_tab] == 'Plugins') {
        if (count($plugins) == 0) {
            ?>
			<div class="shadetabs"><br>
				<h3 style='margin-left: 10px;margin-bottom: 2px;margin-top: 2px;'><?php 
            echo _("No plugins available!");
            ?>
</h3>
			</div>
<?php 
        } else {
            ?>
		<div class="shadetabs"><br>
		<table border='0' cellpadding="0" cellspacing="0">
		<tr>
			<td>
				<ul>
<?php 
            for ($i = 0; $i < count($plugins); $i++) {
                if ($i == $_SESSION['sub_tab']) {
                    print "<li class='selected'><a href='{$self}?sub_tab={$i}'>" . $plugins[$i] . "</a></li>\n";
                } else {
                    print "<li><a href='{$self}?sub_tab={$i}'>" . $plugins[$i] . "</a></li>\n";
                }
            }
            ?>
				</ul>
			</td>
		</tr>
		</table>
		</div>
<?php 
        }
    }
    print "</form>\n";
    print "<script language='Javascript' type='text/javascript'>\n";
    print "selectMenus['profilemenu'] = 0;\n";
    $i = 0;
    $savegroup = '';
    $groupid = 0;
    foreach ($profiles as $profileswitch) {
        if (preg_match("/^(.+)\\/(.+)/", $profileswitch, $matches)) {
            $profilegroup = $matches[1];
            $profilename = $matches[2];
            if ($profilegroup == '.') {
                print "selectOptions[selectOptions.length] = '0||{$profilename}||./{$profilename}'; \n";
            } else {
                if ($profilegroup != $savegroup) {
                    $savegroup = $profilegroup;
                    print "selectOptions[selectOptions.length] = '0||{$profilegroup}||@@0.{$i}'; \n";
                    $groupid = $i;
                    $i++;
                }
                print "selectOptions[selectOptions.length] = '0.{$groupid}||{$profilename}||{$profilegroup}/{$profilename}'; \n";
            }
        } else {
            print "selectOptions[selectOptions.length] = '0||{$profileswitch}||{$profileswitch}'; \n";
        }
        $i++;
    }
    print "selectRelateMenu('profilemenu', function() { document.navi.submit(); });\n";
    // print "selectRelateMenu('profilemenu', false );\n";
    print "</script>\n";
    print "<noscript><h3 class='errstring'>" . _("Your browser does not support JavaScript! NfSen will not work properly!") . "</h3></noscript>\n";
    $bk = base64_decode(urldecode($_SESSION['bookmark']));
}
Пример #5
0
function navigator()
{
    global $self;
    global $TabList;
    global $GraphTabs;
    $numtabs = count($TabList);
    $plugins = GetPlugins();
    $profiles = GetProfiles();
    $profileswitch = $_SESSION['profileswitch'];
    switch ($_SESSION['profileinfo']['type'] & 3) {
        case 0:
            $profile_type = 'live';
            break;
        case 1:
            $profile_type = 'history';
            break;
        case 2:
            $profile_type = 'continuous';
            break;
        default:
            $type = 'unknown';
    }
    $profile_type .= ($_SESSION['profileinfo']['type'] & 4) > 0 ? '&nbsp;/&nbsp;shadow' : '';
    ?>
	<form action="<?php 
    echo $self;
    ?>
" name='navi' method="POST">
	<div class="shadetabs"><br>
	<table border='0' cellpadding="0" cellspacing="0">
	<tr>
		<td>
			<ul>
<?php 
    for ($i = 0; $i < $numtabs; $i++) {
        if ($i == $_SESSION['tab']) {
            print "<li class='selected'><a href='{$self}?tab={$i}'>" . $TabList[$i] . "</a></li>\n";
        } else {
            print "<li><a href='{$self}?tab={$i}'>" . $TabList[$i] . "</a></li>\n";
        }
    }
    ?>
			</ul>
		</td>
		<td class="navigator">
<?php 
    echo $profile_type;
    ?>
		</td>
		<td class="navigator">
<?php 
    print "<a href='{$self}?bookmark=" . $_SESSION['bookmark'] . "'>Bookmark URL</a>\n";
    ?>
		</td>
		<td class="navigator">Profile:</td>
		<td>
			<a class="select_pullup" id="profilemenu" href="javascript:void(0);" 
				onclick="openSelect(this);" onMouseover="selectMouseOver();" 
				onMouseout="selectMouseOut();"></a>
		</td>
	</tr>
	</table>
	<input type="hidden" id="profilemenu_field" name="profileswitch" value="<?php 
    echo $profileswitch;
    ?>
"> 
 	</div>

<?php 
    $_tab = $_SESSION['tab'];
    if ($TabList[$_tab] == 'Graphs') {
        $_sub_tab = $_SESSION['sub_tab'];
        ?>
		<div class="shadetabs"><br>
		<table border='0' cellpadding="0" cellspacing="0">
		<tr>
			<td>
				<ul>
<?php 
        for ($i = 0; $i < count($GraphTabs); $i++) {
            if ($i == $_sub_tab) {
                print "<li class='selected'><a href='{$self}?sub_tab={$i}'>" . $GraphTabs[$i] . "</a></li>\n";
            } else {
                print "<li><a href='{$self}?sub_tab={$i}'>" . $GraphTabs[$i] . "</a></li>\n";
            }
        }
        ?>
				</ul>
			</td>
		</tr>
		</table>
		</div>
<?php 
    }
    if ($TabList[$_tab] == 'Plugins') {
        if (count($plugins) == 0) {
            ?>
			<div class="shadetabs"><br>
				<h3 style='margin-left: 10px;margin-bottom: 2px;margin-top: 2px;'>No plugins available!</h3>
			</div>
<?php 
        } else {
            ?>
		<div class="shadetabs"><br>
		<table border='0' cellpadding="0" cellspacing="0">
		<tr>
			<td>
				<ul>
<?php 
            for ($i = 0; $i < count($plugins); $i++) {
                if ($i == $_SESSION['sub_tab']) {
                    print "<li class='selected'><a href='{$self}?sub_tab={$i}'>" . $plugins[$i] . "</a></li>\n";
                } else {
                    print "<li><a href='{$self}?sub_tab={$i}'>" . $plugins[$i] . "</a></li>\n";
                }
            }
            ?>
				</ul>
			</td>
		</tr>
		</table>
		</div>
<?php 
        }
    }
    print "</form>\n";
    print "<script language='Javascript' type='text/javascript'>\n";
    print "selectMenus['profilemenu'] = 0;\n";
    $i = 0;
    $savegroup = '';
    $groupid = 0;
    foreach ($profiles as $profileswitch) {
        if (preg_match("/^(.+)\\/(.+)/", $profileswitch, $matches)) {
            $profilegroup = $matches[1];
            $profilename = $matches[2];
            if ($profilegroup == '.') {
                print "selectOptions[selectOptions.length] = '0||{$profilename}||./{$profilename}'; \n";
            } else {
                if ($profilegroup != $savegroup) {
                    $savegroup = $profilegroup;
                    print "selectOptions[selectOptions.length] = '0||{$profilegroup}||@@0.{$i}'; \n";
                    $groupid = $i;
                    $i++;
                }
                print "selectOptions[selectOptions.length] = '0.{$groupid}||{$profilename}||{$profilegroup}/{$profilename}'; \n";
            }
        } else {
            print "selectOptions[selectOptions.length] = '0||{$profileswitch}||{$profileswitch}'; \n";
        }
        $i++;
    }
    print "selectRelateMenu('profilemenu', function() { document.navi.submit(); });\n";
    // print "selectRelateMenu('profilemenu', false );\n";
    print "</script>\n";
    print "<noscript><h3 class='errstring'>Your browser does not support JavaScript! NfSen will not work properly!</h3></noscript>\n";
    $bk = base64_decode(urldecode($_SESSION['bookmark']));
}
Пример #6
0
function navigator()
{
    global $self;
    global $TabList;
    global $GraphTabs;
    $numtabs = count($TabList);
    $plugins = GetPlugins();
    $profiles = GetProfiles();
    $profileswitch = $_SESSION['profileswitch'];
    switch ($_SESSION['profileinfo']['type'] & 3) {
        case 0:
            $profile_type = 'live';
            break;
        case 1:
            $profile_type = 'history';
            break;
        case 2:
            $profile_type = 'continuous';
            break;
        default:
            $type = 'unknown';
    }
    $profile_type .= ($_SESSION['profileinfo']['type'] & 4) > 0 ? '&nbsp;/&nbsp;shadow' : '';
    $perms = allowed_nfsen_section();
    $disabled = '';
    if (!$perms) {
        $disabled = 'font-style:italic;color: #aeaeae;text-decoration:none;cursor:default;';
    }
    global $conf;
    ?>
    
    <!--
    <div style="position:absolute;right:30px;top:15px;vertical-align:bottom;width:450px;">
        <table border=0 align="right" style="margin:0px;padding:0px;background-color:transparent;border:0px none">
            <tr>
                <td align="right" class="black" nowrap style="background-color:transparent;border:0px none">
                    <a class="white" <?php 
    echo $_SESSION['tab'] == 2 ? "style='font-weight:bold !important'" : "";
    ?>
 href="nfsen.php?tab=2"><?php 
    echo _("Details");
    ?>
</a>
                </td>
                <td style='padding:0px 7px 0px 7px' class='separator'><img src='/ossim/pixmaps/1x1.png'/></td>
                
                <td>
                    <a style="<?php 
    echo $disabled;
    echo $_SESSION['tab'] == 0 ? ";font-weight:bold !important" : "";
    ?>
" class="white" href="<?php 
    echo $perms ? "nfsen.php?tab=0" : "javascript:;";
    ?>
"><?php 
    echo _("Overview");
    ?>
                    </a>
                </td>
                
                <td style='padding:0px 7px 0px 7px' class='separator'><img src='/ossim/pixmaps/1x1.png'/></td>
                
                <td>                
                    <a style="<?php 
    echo $disabled;
    echo $_SESSION['tab'] == 1 ? ";font-weight:bold !important" : "";
    ?>
" class="white" href="<?php 
    echo $perms ? "nfsen.php?tab=1" : "javascript:;";
    ?>
"><?php 
    echo _("Graphs");
    ?>
                    </a>
                </td>
            </tr>
        </table>
    </div>
	-->
	
	
	<form action="<?php 
    echo $self;
    ?>
" name='navi' method="POST">
	<div class="shadetabs" style="display:none"><br>
        <table border='0' cellpadding="0" cellspacing="0">
            <tr>
                <td>
                    <ul>
                        <?php 
    for ($i = 0; $i < $numtabs; $i++) {
        if ($i == $_SESSION['tab']) {
            echo "<li class='selected'><a href='{$self}?tab={$i}'>" . $TabList[$i] . "</a></li>\n";
        } else {
            echo "<li><a href='{$self}?tab={$i}'>" . $TabList[$i] . "</a></li>\n";
        }
    }
    ?>
                    </ul>
                </td>
                
                <td class="navigator">
                    <?php 
    echo $profile_type;
    ?>
                </td>
            
                <td class="navigator"><?php 
    echo _("Profile");
    ?>
:</td>
            
            </tr>
    	</table>
    	
    	<input type="hidden" id="profilemenu_field" name="profileswitch" value="<?php 
    echo Util::htmlentities($profileswitch);
    ?>
"> 
 	</div>

 	<?php 
    $_tab = $_SESSION['tab'];
    if ($TabList[$_tab] == 'Graphs') {
        $_sub_tab = $_SESSION['sub_tab'];
        $base_url = Menu::get_menu_url('/ossim/nfsen/nfsen.php?tab=1', 'environment', 'netflow', 'graph');
        ?>
        <div class="shadetabs">
        <br>
            <table border='0' cellpadding="0" cellspacing="0" class="noborder" align="center">
                <tr>
                    <td class="noborder" style="padding-bottom:5px;text-align:center">
                    <?php 
        for ($i = 0; $i < count($GraphTabs); $i++) {
            $g_url = $base_url . '&sub_tab=' . $i;
            if ($i > 0) {
                echo "| ";
            }
            if ($i == $_sub_tab) {
                echo "<a href='{$g_url}'><strong>" . $GraphTabs[$i] . "</strong></a>\n";
            } else {
                echo "<a href='{$g_url}'>" . $GraphTabs[$i] . "</a>\n";
            }
        }
        ?>
                   
                    </td>
                </tr>
            </table>
		</div>
    <?php 
    }
    if ($TabList[$_tab] == 'Plugins') {
        if (count($plugins) == 0) {
            ?>
    		<div class="shadetabs"><br>
    			<h3 style='margin-left: 10px;margin-bottom: 2px;margin-top: 2px;'>No plugins available!</h3>
    		</div>
    		<?php 
        } else {
            ?>
            <div class="shadetabs"><br>
                <table border='0' cellpadding="0" cellspacing="0">
                	<tr>
                		<td>
                			<ul>
                				<?php 
            for ($i = 0; $i < count($plugins); $i++) {
                if ($i == $_SESSION['sub_tab']) {
                    print "<li class='selected'><a href='{$self}?sub_tab={$i}'>" . Util::htmlentities($plugins[$i]) . "</a></li>\n";
                } else {
                    print "<li><a href='{$self}?sub_tab={$i}'>" . Util::htmlentities($plugins[$i]) . "</a></li>\n";
                }
            }
            ?>
                			</ul>
                		</td>
                	</tr>
                </table>
            </div>
            <?php 
        }
    }
    print "</form>\n";
    print "<script language='Javascript' type='text/javascript'>\n";
    print "selectMenus['profilemenu'] = 0;\n";
    /*
    $i = 0;
    $savegroup = '';
    $groupid = 0;
        foreach ($profiles as $profileswitch) {
    	if (preg_match("/^(.+)\/(.+)/", $profileswitch, $matches)) {
    		$profilegroup = $matches[1];
    		$profilename  = $matches[2];
                
                $profilename  = Util::htmlentities($profilename);
                $profilegroup = Util::htmlentities($profilegroup);
                $profileswitch = Util::htmlentities($profileswitch);
                
    		if ($profilegroup == '.') {
    			print "selectOptions[selectOptions.length] = '0||$profilename||./$profilename'; \n";
    		} else {
    			if ($profilegroup != $savegroup) {
    				$savegroup = $profilegroup;
    				print "selectOptions[selectOptions.length] = '0||$profilegroup||@@0.$i'; \n";
    				$groupid = $i;
    				$i++;
    			}
    			print "selectOptions[selectOptions.length] = '0.$groupid||$profilename||$profilegroup/$profilename'; \n";
    		}
    	} else {
    		print "selectOptions[selectOptions.length] = '0||".Util::htmlentities($profileswitch)."||".Util::htmlentities($profileswitch)."'; \n";
    	}
    	$i++;
        }
    */
    //print "selectRelateMenu('profilemenu', function() { document.navi.submit(); });\n";
    // print "selectRelateMenu('profilemenu', false);\n";
    print "</script>\n";
    print "<noscript><h3 class='errstring'>" . _("Your browser does not support JavaScript! NfSen will not work properly!") . "</h3></noscript>\n";
    $bk = base64_decode(urldecode($_SESSION['bookmark']));
}