function FindMaxValue() { $profileswitch = $_SESSION['profileswitch']; $detail_opts = $_SESSION['detail_opts']; $type = $detail_opts['type'] . '_' . $detail_opts['proto']; $channellist = $detail_opts['channellist']; $tslot = UNIX2ISO($_SESSION['tleft']); $cmd_opts['profile'] = $profileswitch; $cmd_opts['channellist'] = $channellist; $cmd_opts['tinit'] = $tslot; $cmd_opts['type'] = $type; $tmp = nfsend_query("get-peek", $cmd_opts, 0); if (!is_array($tmp)) { return 0; } return ISO2UNIX($tmp['tpeek']); }
function NewProfileCreate($profileinfo, $type) { ob_start(); print "ADD PROFILE, type {$type}"; // compile argument options for nfsend $cmd_opts['profile'] = $profileinfo['profileswitch']; $cmd_opts['description'] = $profileinfo['description']; if (!is_null($profileinfo['tstart'])) { $cmd_opts['tstart'] = UNIX2ISO($profileinfo['tstart']); } if (!is_null($profileinfo['tend'])) { $cmd_opts['tend'] = UNIX2ISO($profileinfo['tend']); } $cmd_opts['expire'] = $profileinfo['expire']; $cmd_opts['maxsize'] = $profileinfo['maxsize']; $cmd_opts['shadow'] = $profileinfo['shadow']; print "Add profile"; $cmd_out = nfsend_query("add-profile", $cmd_opts, 0); if (is_bool($cmd_out) && $cmd_out == FALSE) { // Add profile failed. print "Add profile failed."; ReportLog(ob_get_contents()); ob_clean(); return FALSE; } if ($type == 'individual') { print "Add profile succeeded."; ReportLog(ob_get_contents()); ob_clean(); return TRUE; } // clear argument options to start over for each channel unset($cmd_opts); $cmd_opts['profile'] = $profileinfo['profileswitch']; $cmd_opts['sign'] = '+'; $cmd_opts['filter'] = $profileinfo['filter']; foreach ($profileinfo['channel'] as $channel) { $cmd_opts['channel'] = $channel; $cmd_opts['sourcelist'] = $channel; print "Add channel '{$channel}'"; $cmd_out = nfsend_query("add-channel", $cmd_opts, 0); if (is_bool($cmd_out) && $cmd_out == FALSE) { // Add channel failed. - hmm .. ugly unset($cmd_opts); print "Add channel failed."; // we force to delete this profile to clean up any remains $cmd_opts['profile'] = $profileinfo['profileswitch']; $cmd_opts['force'] = 1; print "Delete profile"; $cmd_out = nfsend_query("delete-profile", $cmd_opts, 0); if (is_bool($cmd_out) && $cmd_out == FALSE) { // Delete profile failed. - double failure print "Add profile failed."; ReportLog(ob_get_contents()); ob_clean(); } return FALSE; } } print "All channels added"; // successfully added all channels => commit the profile unset($cmd_opts); $cmd_opts['profile'] = $profileinfo['profileswitch']; print "Commit profile"; $cmd_out = nfsend_query("commit-profile", $cmd_opts, 0); if (is_bool($cmd_out) && $cmd_out == FALSE) { // Commit profile failed. - strange .. print "Commit failed"; $cmd_opts['force'] = 1; print "Force delete profile"; $cmd_out = nfsend_query("delete-profile", $cmd_opts, 0); if (is_bool($cmd_out) && $cmd_out == FALSE) { // Delete profile failed. - double failure print "Force delete profile failed."; ReportLog(ob_get_contents()); ob_clean(); } return FALSE; } print "Add profile succeeded.>"; ReportLog(ob_get_contents()); ob_clean(); return TRUE; }
function CompileCommand($mode) { global $ListNOption; global $TopNOption; global $IPStatOption; global $IPStatOrder; global $IPStatArg; global $LimitScale; global $OutputFormatArg; $process_form = $_SESSION['process_form']; $profile = $_SESSION['profile']; $profilegroup = $_SESSION['profilegroup']; // get the sources selected for processing $args = ''; // From the argument checks, we know at least one source is selected // multiple sources if ($_SESSION['tleft'] == $_SESSION['tright']) { // a single 5 min timeslice $tslot1 = UNIX2ISO($_SESSION['tleft']); $subdirs = SubdirHierarchy($_SESSION['tleft']); if (strlen($subdirs) == 0) { $args .= " -r nfcapd.{$tslot1}"; } else { $args .= " -r {$subdirs}/nfcapd.{$tslot1}"; } } else { // several 5 min timeslices $tslot1 = UNIX2ISO($_SESSION['tleft']); $subdirs1 = SubdirHierarchy($_SESSION['tleft']); $tslot2 = UNIX2ISO($_SESSION['tright']); $subdirs2 = SubdirHierarchy($_SESSION['tright']); if (strlen($subdirs1) == 0) { $args .= " -R nfcapd.{$tslot1}:nfcapd.{$tslot2}"; } else { $args .= " -R {$subdirs1}/nfcapd.{$tslot1}:{$subdirs2}/nfcapd.{$tslot2}"; } } // process list request if ($mode == 0) { $_tmp = CompileAggregateFormat($process_form); if ($_tmp != '') { $args .= " -a {$_tmp}"; } // process list request $args .= CompileOutputFormat($process_form); // IPv6 long listing $args .= $process_form['IPv6_long'] == 'checked' ? " -6" : ''; // sort the flows from all sources $args .= $process_form['timesorted'] == 'checked' ? " -m" : ''; // list this number of flows $args .= " -c " . $ListNOption[$process_form['listN']]; } // process stat request if ($mode == 1) { $args .= " -n " . $TopNOption[$process_form['topN']]; // -s record $type_index = $process_form['stattype']; $order_index = $process_form['statorder']; $args .= ' ' . $IPStatArg[$type_index] . '/' . $IPStatOrder[$order_index]; if ($process_form['stattype'] == 0) { $args .= CompileAggregateFormat($process_form); $args .= CompileOutputFormat($process_form); } // IPv6 long listing $args .= $process_form['IPv6_long'] == 'checked' ? " -6" : ''; // limits -L/-l if ($process_form['limitoutput'] == 'checked') { $args .= $process_form['limitwhat'] == 1 ? " -L " : " -l "; if ($process_form['limithow'] == 1) { $args .= '-'; } $args .= $process_form['limitsize']; if ($process_form['limitscale'] > 0) { $args .= $LimitScale[$process_form['limitscale']]; } } } return "{$args}"; }