function demoplugin_Run($plugin_id) { print "<h3>Hello I'm the demo plugin with id {$plugin_id}</h3>\n"; print "Query backend plugin for function <b>try</b><br>\n"; // the command to be executed in the backend plugin $command = 'demoplugin::try'; // two scalar values $colour1 = '#72e3fa'; $colour2 = '#2a6f99'; // one array $colours = array('#12af7d', '#56fc7b'); // prepare arguments $opts = array(); $opts['colour1'] = $colour1; $opts['colour2'] = $colour2; $opts['colours'] = $colours; // call command in backened plugin $out_list = nfsend_query($command, $opts); // get result if (!is_array($out_list)) { SetMessage('error', "Error calling backend plugin"); return FALSE; } $string = $out_list['string']; print "Backend reported: <b>{$string}</b><br>\n"; print "<h3>Picture sent from the backend</h3>\n"; print "<IMG src='pic.php?picture=smily.jpg' border='0' alt='Smily'>\n"; }
function check_email_address(&$emaillist, $opts) { $emaillist = preg_replace("/^\\s+/", '', $emaillist); $emaillist = preg_replace("/\\s+\$/", '', $emaillist); if ($emaillist == '') { return 0; } foreach (explode(',', $emaillist) as $email) { $email = preg_replace("/^\\s+/", '', $email); $email = preg_replace("/\\s+\$/", '', $email); // Just make a rough check of characters. the backend will check the email address format if (!ereg("^[A-Za-z0-9_\\.@-]{6,128}\$", $email)) { SetMessage('error', "Error illegal characters in email address '{$email}'"); return 1; } return 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; } }
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); }
function PortTracker_ParseInput($plugin_id) { global $PortDisplayOrder; // Which graph to display if (isset($_GET["{$plugin_id}_graph"])) { $_tmp = $_GET["{$plugin_id}_graph"]; if (!is_numeric($_tmp) || $_tmp > count($PortDisplayOrder) || $_tmp < 0) { $_SESSION['warning'] = "Can't display graph '{$_tmp}'"; } else { $_SESSION["{$plugin_id}_graph"] = $_tmp; } } if (!isset($_SESSION["{$plugin_id}_graph"])) { $_SESSION["{$plugin_id}_graph"] = 0; } if (!isset($_SESSION["{$plugin_id}_skip"])) { $_SESSION["{$plugin_id}_skip"] = array(); } if (!isset($_SESSION["{$plugin_id}_track"])) { $_SESSION["{$plugin_id}_track"] = array(); } $_SESSION['rrdgraph_getparams']['profile'] = 1; // register 'get-portgraph' command for rrdgraph.php if (!array_key_exists('rrdgraph_cmds', $_SESSION) || !array_key_exists('PortTracker::get-portgraph', $_SESSION['rrdgraph_cmds'])) { $_SESSION['rrdgraph_cmds']['PortTracker::get-portgraph'] = 1; } $_SESSION['rrdgraph_getparams']['profile'] = 1; // Top N ports if (isset($_POST["{$plugin_id}_topN"])) { $_tmp = $_POST["{$plugin_id}_topN"]; if (!is_numeric($_tmp) || $_tmp > 10 || $_tmp < 0) { $_SESSION['warning'] = "Invalid Top N number. Defaults to 10."; $_SESSION["{$plugin_id}_topN"] = 10; } else { $_SESSION["{$plugin_id}_topN"] = $_tmp; } } if (!isset($_SESSION["{$plugin_id}_topN"])) { $_SESSION["{$plugin_id}_topN"] = 10; } // Static tracked ports if (isset($_POST["{$plugin_id}_action"])) { switch ($_POST["{$plugin_id}_action"]) { case 'Add': $_track_tmp = isset($_POST["{$plugin_id}_trackport"]) ? $_POST["{$plugin_id}_trackport"] : 0; $_skip_tmp = isset($_POST["{$plugin_id}_skipport"]) ? $_POST["{$plugin_id}_skipport"] : 0; if ($_track_tmp > 0 && $_track_tmp < 65536) { if (in_array($_track_tmp, $_SESSION["{$plugin_id}_track"])) { SetMessage('error', "Port {$_track_tmp} already in skip list"); } else { if (!in_array($_track_tmp, $_SESSION["{$plugin_id}_track"])) { $_SESSION["{$plugin_id}_track"][] = $_track_tmp; } } } else { if ($_skip_tmp > 0 && $_skip_tmp < 65536) { if (in_array($_skip_tmp, $_SESSION["{$plugin_id}_skip"])) { $_SESSION['error'] = "Port {$_skip_tmp} already in track list"; } else { if (!in_array($_skip_tmp, $_SESSION["{$plugin_id}_skip"])) { $_SESSION["{$plugin_id}_skip"][] = $_skip_tmp; } } } else { SetMessage('error', "Invalid Port"); } } break; case 'Delete': $_track_tmp = isset($_POST["{$plugin_id}_track"]) ? $_POST["{$plugin_id}_track"] : 0; if ($_track_tmp > 0 && $_track_tmp < 65536) { if (in_array($_track_tmp, $_SESSION["{$plugin_id}_track"])) { // remove $_track_tmp from array. As we don't know, where it is, cycle through the array $count = count($_SESSION["{$plugin_id}_track"]); for ($i = 0; $i < $count; $i++) { $_port = array_shift($_SESSION["{$plugin_id}_track"]); if ($_port != $_track_tmp) { array_push($_SESSION["{$plugin_id}_track"], $_port); } } } } $_skip_tmp = isset($_POST["{$plugin_id}_skip"]) ? $_POST["{$plugin_id}_skip"] : 0; if ($_skip_tmp > 0 && $_skip_tmp < 65536) { if (in_array($_skip_tmp, $_SESSION["{$plugin_id}_skip"])) { // remove $_skip_tmp from array. As we don't know, where it is, cycle through the array $count = count($_SESSION["{$plugin_id}_skip"]); for ($i = 0; $i < $count; $i++) { $_port = array_shift($_SESSION["{$plugin_id}_skip"]); if ($_port != $_skip_tmp) { array_push($_SESSION["{$plugin_id}_skip"], $_port); } } } } break; } } if (!isset($_SESSION["{$plugin_id}_track"])) { $_SESSION["{$plugin_id}_track"] = array(); } // Graph wsize if (isset($_POST["{$plugin_id}_wsize"])) { $_tmp = $_POST["{$plugin_id}_wsize"]; if (!is_numeric($_tmp) || $_tmp > 5 || $_tmp < 0) { $_SESSION['warning'] = "Invalid Window scale. Defaults to 1 day."; $_SESSION["{$plugin_id}_wsize"] = 1; } else { $_SESSION["{$plugin_id}_wsize"] = $_tmp; } } if (!isset($_SESSION["{$plugin_id}_wsize"])) { $_SESSION["{$plugin_id}_wsize"] = 1; } // Graph Scale if (isset($_POST["{$plugin_id}_logscale"])) { $_tmp = $_POST["{$plugin_id}_logscale"]; if (!is_numeric($_tmp) || $_tmp > 1 || $_tmp < 0) { $_SESSION['warning'] = "Invalid Graph Scaling. Defaults to linear."; $_SESSION["{$plugin_id}_logscale"] = 0; } else { $_SESSION["{$plugin_id}_logscale"] = $_tmp; } } if (!isset($_SESSION["{$plugin_id}_logscale"])) { $_SESSION["{$plugin_id}_logscale"] = 0; } // Stacked Graph if (isset($_POST["{$plugin_id}_stacked"])) { $_tmp = $_POST["{$plugin_id}_stacked"]; if (!is_numeric($_tmp) || $_tmp > 1 || $_tmp < 0) { $_SESSION['warning'] = "Invalid Graph Scaling. Defaults to linear."; $_SESSION["{$plugin_id}_stacked"] = 0; } else { $_SESSION["{$plugin_id}_stacked"] = $_tmp; } } if (!isset($_SESSION["{$plugin_id}_stacked"])) { $_SESSION["{$plugin_id}_stacked"] = 0; } // 24 hour average if (isset($_POST["{$plugin_id}_24avg"])) { $_tmp = $_POST["{$plugin_id}_24avg"]; if (!is_numeric($_tmp) || $_tmp > 1 || $_tmp < 0) { $_SESSION['warning'] = "Invalid Graph Scaling. Defaults to linear."; $_SESSION["{$plugin_id}_24avg"] = 0; } else { $_SESSION["{$plugin_id}_24avg"] = $_tmp; } } if (!isset($_SESSION["{$plugin_id}_24avg"])) { $_SESSION["{$plugin_id}_24avg"] = 0; } }
function Process_Details_tab($tab_changed, $profile_changed) { global $DisplayOrder; global $TypeOrder; global $ListNOption; global $TopNOption; global $IPStatOption; global $IPStatOrder; global $WinSizeScale; global $LimitScale; global $OutputFormatOption; $_SESSION['refresh'] = 0; unset($_SESSION['run']); if ($profile_changed || $tab_changed) { unset($_SESSION['detail_opts']); } // register 'get-detailsgraph' command for rrdgraph.php if (!array_key_exists('rrdgraph_cmds', $_SESSION) || !array_key_exists('get-detailsgraph', $_SESSION['rrdgraph_cmds'])) { $_SESSION['rrdgraph_cmds']['get-detailsgraph'] = 1; $_SESSION['rrdgraph_getparams']['profile'] = 1; } // process channels. 'channeltrigger' is a hidden field, always present to // trigger this block // put a compiled list into the POST array, which is scanned afterwards if (isset($_POST['srctrigger'])) { if (isset($_POST['MultipleSources'])) { if ($_POST['MultipleSources'] == 'All') { $_channels = get_channel_list(); if (!empty($_channels)) { $_POST['channellist'] = implode('!', $_channels); } else { $_POST['channellist'] = ''; } } else { $_POST['channellist'] = ''; } } else { $_channels = array(); foreach (array_keys($_SESSION['profileinfo']['channel']) as $channel) { if (array_key_exists($channel, $_POST)) { $_channels[] = $channel; } } $_POST['channellist'] = implode('!', $_channels); } } // move type from URL get to POST if (isset($_GET['type'])) { $_POST['type'] = Util::htmlentities($_GET['type']); } if (isset($_GET['proto'])) { $_POST['proto'] = Util::htmlentities($_GET['proto']); } if (isset($_COOKIE['statpref'])) { $_POST['statpref'] = Util::htmlentities($_COOKIE['statpref']); } if (isset($_COOKIE['statvisible'])) { $_POST['statvisible'] = Util::htmlentities($_COOKIE['statvisible']); } // to get the defaults in the parse_opts array if ($tab_changed || $profile_changed) { unset($_SESSION['detail_opts']); $detail_opts = array(); } else { $detail_opts = array_key_exists('detail_opts', $_SESSION) ? $_SESSION['detail_opts'] : array(); } //getting default channel list if (!empty($detail_opts['channellist'])) { $default_chanellist = $detail_opts['channellist']; } else { $_channels = get_channel_list(); $default_chanellist = implode('!', $_channels); } // process form data $parse_opts = array("type" => array("required" => 0, "default" => array_key_exists('type', $detail_opts) ? $detail_opts['type'] : 'flows', "allow_null" => 0, "match" => $TypeOrder, "validate" => NULL), "proto" => array("required" => 0, "default" => array_key_exists('proto', $detail_opts) ? $detail_opts['proto'] : 'any', "allow_null" => 0, "match" => $DisplayOrder, "validate" => NULL), "wsize" => array("required" => 0, "default" => array_key_exists('wsize', $detail_opts) ? $detail_opts['wsize'] : 1, "allow_null" => 0, "match" => range(0, count($WinSizeScale) - 1), "validate" => NULL), "ratescale" => array("required" => 0, "default" => array_key_exists('ratescale', $detail_opts) ? $detail_opts['ratescale'] : 1, "allow_null" => 0, "match" => array(0, 1), "validate" => NULL), "logscale" => array("required" => 0, "default" => array_key_exists('logscale', $detail_opts) ? $detail_opts['logscale'] : 0, "allow_null" => 0, "match" => array(0, 1), "validate" => NULL), "linegraph" => array("required" => 0, "default" => array_key_exists('linegraph', $detail_opts) ? $detail_opts['linegraph'] : 0, "allow_null" => 0, "match" => array(0, 1), "validate" => NULL), "cursor_mode" => array("required" => 0, "default" => array_key_exists('cursor_mode', $detail_opts) ? $detail_opts['cursor_mode'] : 1, "allow_null" => 0, "match" => array(0, 1), "validate" => NULL), "channellist" => array("required" => 0, "default" => $default_chanellist, "allow_null" => 1, "match" => "/^[a-zA-Z0-9\\-\\!]*\$/", "validate" => 'channellist_validate'), "statpref" => array("required" => 0, "default" => '0:0:0', "allow_null" => 0, "match" => "/^[0-5]:[0-5]:[0-5]\$/", "validate" => NULL), "statvisible" => array("required" => 0, "default" => 1, "allow_null" => 0, "match" => array(0, 1), "validate" => NULL)); list($detail_opts, $has_errors) = ParseForm($parse_opts); //if ( $has_errors ) // return; $_SESSION['detail_opts'] = $detail_opts; // for bookmarking only $_SESSION['channellist'] = $detail_opts['channellist']; // set cookie for javascript functions $_COOKIE['statpref'] = $detail_opts['statpref']; $_COOKIE['statvisible'] = $detail_opts['statvisible']; if ($tab_changed || $profile_changed || isset($_POST['wsize']) || (!isset($_SESSION['tend']) || !isset($_SESSION['tleft']) || !isset($_SESSION['tright']))) { $_SESSION['tend'] = $_SESSION['profileinfo']['tend']; if ($_SESSION['tend'] - 43200 < $_SESSION['profileinfo']['tstart']) { // the middle of the graph is outside the profile, so set the mark // to the beginning of the profile $_SESSION['tleft'] = $_SESSION['profileinfo']['tstart']; } else { $scale = $WinSizeScale[$detail_opts['wsize']]; // set the tleft to the middle of the graph $_SESSION['tleft'] = $_SESSION['tend'] - 14400 * $scale; } //$_SESSION['tright'] = $_SESSION['tleft']; $_SESSION['tright'] = $_SESSION['tend']; if (!array_key_exists('DefaultFilters', $_SESSION)) { DefaultFilters(); } $_SESSION['process_form'] = array(); } TimeSlotUpdate($detail_opts); // process the input data from the netflow processing form // to get the defaults in the parse_opts array if (array_key_exists('process', $_POST)) { $process_form = array(); } else { $process_form = array_key_exists('process_form', $_SESSION) ? $_SESSION['process_form'] : array(); } $default_selector = array(); if (is_array($process_form['srcselector'])) { $default_selector = $process_form['srcselector']; } else { if (!empty($process_form['srcselector'])) { $default_selector[] = $process_form['srcselector']; } } if (empty($default_selector)) { if (!empty($detail_opts['channellist'])) { $default_selector = explode('!', $detail_opts['channellist']); } } $parse_opts = array("modeselect" => array("required" => 0, "default" => array_key_exists('modeselect', $process_form) ? $process_form['modeselect'] : 0, "allow_null" => 0, "match" => array(0, 1), "validate" => NULL), "srcselector" => array("required" => 0, "default" => $default_selector, "allow_null" => 1, "match" => null, "validate" => 'srcselector_validate'), "DefaultFilter" => array("required" => 0, "default" => -1, "allow_null" => 0, "match" => array_merge(array(-1), array_keys($_SESSION['DefaultFilters'])), "validate" => NULL), "filter" => array("required" => 0, "default" => array_key_exists('filter', $process_form) ? implode("\n", $process_form['filter']) : NULL, "allow_null" => 1, "match" => "/^[\\s!-~]*\$/", "validate" => 'filter_validate'), "filter_name" => array("required" => 0, "default" => '', "allow_null" => 0, "match" => "/^\$|^[A-Za-z0-9\\.][A-Za-z0-9\\-+_\\/]+\$/", "validate" => NULL), "filter_edit" => array("required" => 0, "default" => null, "allow_null" => 1, "match" => array_merge(array(null), array_keys($_SESSION['DefaultFilters'])), "validate" => NULL), "filter_delete" => array("required" => 0, "default" => null, "allow_null" => 1, "match" => array_merge(array(null), array_keys($_SESSION['DefaultFilters'])), "validate" => NULL), "listN" => array("required" => 0, "default" => array_key_exists('listN', $process_form) ? $process_form['listN'] : 0, "allow_null" => 0, "match" => range(0, count($ListNOption) - 1), "validate" => NULL), "aggr_bidir" => array("required" => 0, "default" => array_key_exists('aggr_bidir', $process_form) ? $process_form['aggr_bidir'] : '', "allow_null" => 0, "match" => array('', 'checked'), "validate" => NULL), "aggr_proto" => array("required" => 0, "default" => array_key_exists('aggr_proto', $process_form) ? $process_form['aggr_proto'] : '', "allow_null" => 0, "match" => array('', 'checked'), "validate" => NULL), "aggr_srcip" => array("required" => 0, "default" => array_key_exists('aggr_srcip', $process_form) ? $process_form['aggr_srcip'] : '', "allow_null" => 0, "match" => array('', 'checked'), "validate" => NULL), "aggr_srcport" => array("required" => 0, "default" => array_key_exists('aggr_srcport', $process_form) ? $process_form['aggr_srcport'] : '', "allow_null" => 0, "match" => array('', 'checked'), "validate" => NULL), "aggr_dstip" => array("required" => 0, "default" => array_key_exists('aggr_dstip', $process_form) ? $process_form['aggr_dstip'] : '', "allow_null" => 0, "match" => array('', 'checked'), "validate" => NULL), "aggr_dstport" => array("required" => 0, "default" => array_key_exists('aggr_dstport', $process_form) ? $process_form['aggr_dstport'] : '', "allow_null" => 0, "match" => array('', 'checked'), "validate" => NULL), "aggr_srcselect" => array("required" => 0, "default" => array_key_exists('aggr_srcselect', $process_form) ? $process_form['aggr_srcselect'] : 0, "allow_null" => 0, "match" => array(0, 1, 2), "validate" => NULL), "aggr_dstselect" => array("required" => 0, "default" => array_key_exists('aggr_dstselect', $process_form) ? $process_form['aggr_dstselect'] : 0, "allow_null" => 0, "match" => array(0, 1, 2), "validate" => NULL), "aggr_srcnetbits" => array("required" => 0, "default" => array_key_exists('aggr_srcnetbits', $process_form) ? $process_form['aggr_srcnetbits'] : 24, "allow_null" => 0, "match" => "/^[0-9]+\$/", "validate" => NULL), "aggr_dstnetbits" => array("required" => 0, "default" => array_key_exists('aggr_dstnetbits', $process_form) ? $process_form['aggr_dstnetbits'] : 24, "allow_null" => 0, "match" => "/^[0-9]+\$/", "validate" => NULL), "timesorted" => array("required" => 0, "default" => array_key_exists('timesorted', $process_form) ? $process_form['timesorted'] : '', "allow_null" => 0, "match" => array('', 'checked'), "validate" => NULL), "IPv6_long" => array("required" => 0, "default" => array_key_exists('IPv6_long', $process_form) ? $process_form['IPv6_long'] : '', "allow_null" => 0, "match" => array('', 'checked'), "validate" => NULL), "output" => array("required" => 0, "default" => array_key_exists('output', $process_form) ? $process_form['output'] : 'extended', "allow_null" => 0, "match" => array_key_exists('formatlist', $_SESSION) ? array_keys($_SESSION['formatlist']) : array('extended'), "validate" => NULL), "customfmt" => array("required" => 0, "default" => array_key_exists('customfmt', $process_form) ? $process_form['customfmt'] : '', "allow_null" => 1, "match" => "/^\$|^[\\s!-~]+\$/", "validate" => NULL), "fmt_save" => array("required" => 0, "default" => array_key_exists('fmt_save', $process_form) ? $process_form['fmt_save'] : '', "allow_null" => 0, "match" => "/^\$|^[A-Za-z0-9\\.][A-Za-z0-9\\-+_\\/]+\$/", "validate" => NULL), "fmt_delete" => array("required" => 0, "default" => array_key_exists('fmt_delete', $process_form) ? $process_form['fmt_delete'] : '', "allow_null" => 0, "match" => "/^\$|^[A-Za-z0-9\\.][A-Za-z0-9\\-+_\\/]+\$/", "validate" => NULL), "topN" => array("required" => 0, "default" => array_key_exists('topN', $process_form) ? $process_form['topN'] : 0, "allow_null" => 0, "match" => range(0, count($TopNOption) - 1), "validate" => NULL), "stattype" => array("required" => 0, "default" => array_key_exists('stattype', $process_form) ? $process_form['stattype'] : 1, "allow_null" => 0, "match" => range(0, count($IPStatOption) - 1), "validate" => NULL), "statorder" => array("required" => 0, "default" => array_key_exists('statorder', $process_form) ? $process_form['statorder'] : 0, "allow_null" => 0, "match" => range(0, count($IPStatOrder) - 1), "validate" => NULL), "limitoutput" => array("required" => 0, "default" => array_key_exists('limitoutput', $process_form) ? $process_form['limitoutput'] : '', "allow_null" => 0, "match" => array('', 'checked'), "validate" => NULL), "limitwhat" => array("required" => 0, "default" => array_key_exists('limitwhat', $process_form) ? $process_form['limitwhat'] : '', "allow_null" => 0, "match" => array(0, 1), "validate" => NULL), "limithow" => array("required" => 0, "default" => array_key_exists('limithow', $process_form) ? $process_form['limithow'] : 0, "allow_null" => 0, "match" => array(0, 1), "validate" => NULL), "limitsize" => array("required" => 0, "default" => array_key_exists('limitsize', $process_form) ? $process_form['limitsize'] : 0, "allow_null" => 0, "match" => "/^[0-9]+\$/", "validate" => NULL), "limitscale" => array("required" => 0, "default" => array_key_exists('limitscale', $process_form) ? $process_form['limitscale'] : 0, "allow_null" => 0, "match" => range(0, count($LimitScale) - 1), "validate" => NULL)); list($process_form, $has_errors) = ParseForm($parse_opts); $_SESSION['process_form'] = $process_form; //if ( $has_errors ) // return; if (array_key_exists('fmt_save', $_POST)) { if (!get_magic_quotes_gpc()) { $cmd_opts['formatdef'] = addslashes($process_form['customfmt']); } else { $cmd_opts['formatdef'] = $process_form['customfmt']; } $cmd_opts['format'] = $process_form['fmt_save']; $cmd_opts['overwrite'] = 1; $cmd_out = nfsend_query("add-format", $cmd_opts, 0); if (is_array($cmd_out)) { unset($_SESSION['formatlist']); $_SESSION['process_form']['output'] = $process_form['fmt_save']; } } if (array_key_exists('fmt_delete', $_POST)) { $_tmp = Util::htmlentities($_POST['fmt_delete']); if (array_key_exists($_tmp, $OutputFormatOption)) { SetMessage('error', "Can not delete built in format '{$_tmp}'"); } else { if (!array_key_exists($_tmp, $_SESSION['formatlist'])) { SetMessage('error', "Unknon format '{$_tmp}'"); } else { $cmd_opts['format'] = $_tmp; $cmd_out = nfsend_query("delete-format", $cmd_opts, 0); unset($_SESSION['formatlist']); $_SESSION['process_form']['output'] = $parse_opts['output']['default']; } } } if (!array_key_exists('formatlist', $_SESSION)) { foreach ($OutputFormatOption as $opt) { $_SESSION['formatlist'][$opt] = $opt; } $cmd_out = nfsend_query("get-formatlist", array(), 0); if (is_array($cmd_out)) { foreach ($cmd_out as $key => $value) { $_SESSION['formatlist'][$key] = $value; } } $_SESSION['formatlist']['custom ...'] = 0; } if (array_key_exists('filter_save_x', $_POST)) { $cmd_opts['filtername'] = $process_form['filter_name']; $cmd_opts['overwrite'] = 1; $cmd_opts['filter'] = $process_form['filter']; $cmd_out = nfsend_query("add-filter", $cmd_opts, 0); if (is_array($cmd_out)) { unset($_SESSION['DefaultFilters']); $_SESSION['process_form']['DefaultFilter'] = -1; $_SESSION['process_form']['filter'] = array(); } } if (array_key_exists('filter_edit_x', $_POST)) { $cmd_opts['filter'] = $process_form['filter_name']; $cmd_out = nfsend_query("get-filter", $cmd_opts, 0); if (is_array($cmd_out)) { $_SESSION['process_form']['editfilter'] = $cmd_out['filter']; } $_SESSION['anchor'] = '#processing'; } if (array_key_exists('filter_delete_x', $_POST)) { $cmd_opts['filtername'] = $process_form['filter_name']; $cmd_out = nfsend_query("delete-filter", $cmd_opts, 0); if (is_array($cmd_out)) { unset($_SESSION['DefaultFilters']); $_SESSION['process_form']['DefaultFilter'] = -1; } } if (count(array_diff($_SESSION['process_form']['filter'], $_SESSION['auto_filter'])) == 0) { if ($_SESSION['detail_opts']['proto'] == 'any') { $_SESSION['process_form']['filter'] = array(); } else { if ($_SESSION['detail_opts']['proto'] == 'other') { $_SESSION['process_form']['filter'] = array('not (proto tcp or proto udp or proto icmp or proto icmp6)'); } else { $_SESSION['process_form']['filter'] = array('proto ' . $_SESSION['detail_opts']['proto']); } } $_SESSION['auto_filter'] = $_SESSION['process_form']['filter']; } else { $_SESSION['auto_filter'] = array(); } DefaultFilters(); if (array_key_exists('process', $_POST)) { $run = CompileCommand($process_form['modeselect']); $_SESSION['anchor'] = '#processing'; } else { $run = null; } $_SESSION['run'] = $run; }
function nfsend_query($command, $cmd_opts) { global $DEBUG; if (!isset($_SESSION['nfsend'])) { ReportLog("nfsend No socket - open connection first"); nfsend_connect(); } if (!isset($_SESSION['nfsend'])) { SetMessage('error', _("nfsend - connection failed!")); return FALSE; } $nfsend = $_SESSION['nfsend']; $is_binary = preg_match("/^@/", $command); if ($DEBUG == 1 && !$is_binary) { ReportLog("nfsend INTERNAL '.debug=1'"); @socket_write($nfsend, ".debug=1\n"); } ReportLog("nfsend COMMAND '{$command}' binary: {$is_binary}"); // Socket may have timouted since last query // check for errors while sending command, and reopenn socket in case of an error if (@socket_write($nfsend, "{$command}\n") == FALSE) { $errstr = socket_strerror(socket_last_error($nfsend)); ReportLog("nfsend 1st write() failed: reason: " . socket_strerror(socket_last_error($nfsend))); nfsend_connect(); $nfsend = $_SESSION['nfsend']; if (@socket_write($nfsend, "{$command}\n") == FALSE) { $errstr = socket_strerror(socket_last_error($nfsend)); SetMessage('error', _("nfsend socket_write() communication error") . ": {$errstr}"); @socket_close($nfsend); unset($_SESSION['nfsend']); return FALSE; } } // the socket is established and ready - just send the opts foreach ($cmd_opts as $key => $value) { if (is_array($value)) { foreach ($value as $val) { ReportLog("nfsend WRITE: '_{$key}'='{$val}'"); @socket_write($nfsend, "_{$key}={$val}\n"); } } else { ReportLog("nfsend WRITE: '{$key}'='{$value}'"); @socket_write($nfsend, "{$key}={$value}\n"); } } // send EODATA ReportLog("nfsend EODATA"); @socket_write($nfsend, ".\n"); $out_list = array(); $debug = array(); $done = 0; $EODATA = 0; $error_occured = 0; while (!$done) { if ($is_binary) { $line = @socket_read($nfsend, 1024, PHP_BINARY_READ); } else { $line = @socket_read($nfsend, 1024, PHP_NORMAL_READ); } if ($line == FALSE) { $errno = socket_last_error($nfsend); if ($errno) { $errstr = socket_strerror(socket_last_error($nfsend)); $ret = FALSE; SetMessage('error', _("nfsend socket_read() communication error") . ": {$errstr}"); ReportLog("nfsend connection error '{$errno}' '{$errstr}'"); } else { // connection closed in binary mode $ret = TRUE; } @socket_close($nfsend); unset($_SESSION['nfsend']); return $ret; } if ($is_binary) { print "{$line}"; continue; } $line = rtrim($line); if (preg_match("/^\$/", $line)) { continue; } // was last line EODATA? if ($EODATA) { // if so, $line contains the status message $done = 1; $EODATA = 0; ReportLog("nfsend STATUS '{$line}'"); // parse status line for various messages if (strncasecmp($line, "ok ", 3) == 0) { continue; } if (strncasecmp($line, "err ", 4) == 0) { $msg = substr($line, 4); $error_occured = 1; SetMessage('error', "nfsend: {$msg}"); continue; } if (strncasecmp($line, "warn ", 5) == 0) { $msg = substr($line, 5); SetMessage('warning', "nfsend: {$msg}"); continue; } if (strncasecmp($line, "alert ", 6) == 0) { $msg = substr($line, 6); SetMessage('alert', "nfsend: {$msg}"); continue; } // not needed, but catch it anyway continue; } if (preg_match("/^\\..+/", $line)) { ReportLog("nfsend Skip line '{$line}'"); $debug[] = $line; continue; } if (preg_match("/^INFO /", $line)) { ReportLog("nfsend Skip info line '{$line}'"); continue; } // EODATA received if (preg_match("/^\\.\$/", $line)) { $EODATA = 1; continue; } if (!preg_match("/=/", $line)) { ReportLog("nfsend Skip buggy line '{$line}' Expected key=value pair"); continue; } ReportLog("nfsend Process line '{$line}'"); // parse regular output lines list($key, $value) = split('=', $line, 2); // check for multiline output if (preg_match("/^\\_(.+)/", $key, $matches)) { $key = $matches[1]; $out_list[$key][] = $value; } else { $out_list[$key] = $value; } } return $is_binary ? TRUE : ($error_occured ? FALSE : $out_list); }
function check_email_address(&$emaillist, $opts) { $emaillist = preg_replace("/^\\s+/", '', $emaillist); $emaillist = preg_replace("/\\s+\$/", '', $emaillist); if ($emaillist == '') { return 0; } foreach (explode(',', $emaillist) as $email) { $email = preg_replace("/^\\s+/", '', $email); $email = preg_replace("/\\s+\$/", '', $email); // First, we check that there's one @ symbol, and that the lengths are right if (!ereg("^[^@]{1,64}@[^@]{1,255}\$", $email)) { // Email invalid because wrong number of characters in one section, or wrong number of @ symbols. SetMessage('error', _("Error 1 checking email address") . " '{$email}'"); return 1; } // Split it into sections to make life easier $email_array = explode("@", $email); $local_array = explode(".", $email_array[0]); for ($i = 0; $i < sizeof($local_array); $i++) { if (!ereg("^(([A-Za-z0-9!#\$%&'*+/=?^_`{|}~-][A-Za-z0-9!#\$%&'*+/=?^_`{|}~\\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))\$", $local_array[$i])) { SetMessage('error', _("Error 2 checking email address") . " '{$email}'"); return 1; } } if (!ereg("^\\[?[0-9\\.]+\\]?\$", $email_array[1])) { // Check if domain is IP. If not, it should be valid domain name $domain_array = explode(".", $email_array[1]); if (sizeof($domain_array) < 2) { SetMessage('error', _("Error 3 checking email address") . " '{$email}'"); return 1; // Not enough parts to domain } for ($i = 0; $i < sizeof($domain_array); $i++) { if (!ereg("^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]+))\$", $domain_array[$i])) { SetMessage('error', _("Error 4 checking email address") . " '{$email}'"); return 1; } } } } return 0; }