summaryrefslogtreecommitdiffstats
path: root/usr/local/www/widgets
diff options
context:
space:
mode:
authorScott Dale <sdale@pfsense.org>2007-05-07 02:21:35 +0000
committerScott Dale <sdale@pfsense.org>2007-05-07 02:21:35 +0000
commit1db766dfbeaee353cbafbce8926d359454994415 (patch)
tree0b8e7d6cd608966dddf8167998ecda3a32daa9d1 /usr/local/www/widgets
parentaacd6b3dcc8bc76c3d7f54945a8092121d2cdd1c (diff)
downloadpfsense-1db766dfbeaee353cbafbce8926d359454994415.zip
pfsense-1db766dfbeaee353cbafbce8926d359454994415.tar.gz
Widget base. Note: changes to widgets are not saved yet.
Diffstat (limited to 'usr/local/www/widgets')
-rw-r--r--usr/local/www/widgets/include/log.inc166
-rw-r--r--usr/local/www/widgets/javascript/log.js155
-rw-r--r--usr/local/www/widgets/widgets/interfaces.widget.php56
-rw-r--r--usr/local/www/widgets/widgets/log.widget.php41
4 files changed, 418 insertions, 0 deletions
diff --git a/usr/local/www/widgets/include/log.inc b/usr/local/www/widgets/include/log.inc
new file mode 100644
index 0000000..8c26603
--- /dev/null
+++ b/usr/local/www/widgets/include/log.inc
@@ -0,0 +1,166 @@
+<?php
+
+//set variables for log
+$filter_logfile = "{$g['varlog_path']}/filter.log";
+$nentries = 5;
+$filterlog = conv_clog_filter($filter_logfile, $nentries);
+
+/* AJAX related routines */
+ handle_ajax();
+
+
+/* format filter logs */
+function conv_clog_filter($logfile, $tail = 50) {
+ global $config, $nentries, $logfile;
+
+ $logfile = "/var/log/filter.log";
+
+ /* make interface/port table */
+ $iftable = array();
+ $iftable[$config['interfaces']['lan']['if']] = "LAN";
+ $iftable[get_real_wan_interface()] = "WAN";
+ for ($i = 1; isset($config['interfaces']['opt' . $i]); $i++)
+ $iftable[$config['interfaces']['opt' . $i]['if']] = $config['interfaces']['opt' . $i]['descr'];
+
+ $sor = isset($config['syslog']['reverse']) ? "-r" : "";
+
+ $logarr = "";
+ exec("/usr/sbin/clog {$logfile} | /usr/bin/tail {$sor} -n {$tail}", $logarr);
+
+ $filterlog = array();
+
+ $counter = 0;
+
+ foreach ($logarr as $logent) {
+
+ if($counter > $nentries)
+ break;
+
+ $log_split = "";
+
+ preg_match("/(\b(?:\d{1,3}\.){3}\d{1,3}(\.\w+)?)\s.*\s(\b(?:\d{1,3}\.){3}\d{1,3}(\.\w+)?)/", $logent, $log_split);
+
+ $flent['src'] = convert_port_period_to_colon($log_split[1]);
+ $flent['dst'] = convert_port_period_to_colon($log_split[3]);
+
+ preg_match("/(.*)\s.*\spf:\s.*\srule\s(.*)\(match\)\:\s(.*)\s\w+\son\s(\w+)\:\s(.*)\s>\s(.*)\:\s.*/", $logent, $log_split);
+
+ $logent = strtoupper($logent);
+
+ $do_not_display = false;
+
+ if(stristr(strtoupper($logent), "UDP") == true)
+ $flent['proto'] = "UDP";
+ else if(stristr(strtoupper($logent), "TCP") == true)
+ $flent['proto'] = "TCP";
+ else if(stristr(strtoupper($logent), "ICMP") == true)
+ $flent['proto'] = "ICMP";
+ else if(stristr(strtoupper($logent), "HSRP") == true)
+ $flent['proto'] = "HSRP";
+ else if(stristr(strtoupper($logent), "ESP") == true)
+ $flent['proto'] = "ESP";
+ else if(stristr(strtoupper($logent), "AH") == true)
+ $flent['proto'] = "AH";
+ else if(stristr(strtoupper($logent), "GRE") == true)
+ $flent['proto'] = "GRE";
+ else if(stristr(strtoupper($logent), "IGMP") == true)
+ $flent['proto'] = "IGMP";
+ else if(stristr(strtoupper($logent), "CARP") == true)
+ $flent['proto'] = "CARP";
+ else if(stristr(strtoupper($logent), "PFSYNC") == true)
+ $flent['proto'] = "PFSYNC";
+ else
+ $flent['proto'] = "TCP";
+
+ $time_regex = "";
+ preg_match("/.*([0-9][0-9]:[0-9][0-9]:[0-9][0-9])/", $log_split[1], $time_regex);
+ $row_time = strtotime($time_regex[1]);
+
+ $flent['time'] = $row_time;
+ $flent['act'] = $log_split[3];
+
+ $friendly_int = convert_real_interface_to_friendly_interface_name($log_split[4]);
+
+ $flent['interface'] = strtoupper($friendly_int);
+
+ if($config['interfaces'][$friendly_int]['descr'] <> "")
+ $flent['interface'] = "{$config['interfaces'][$friendly_int]['descr']}";
+
+ $flent['src'] = convert_port_period_to_colon($log_split[5]);
+ $flent['dst'] = convert_port_period_to_colon($log_split[6]);
+
+ $flent['dst'] = str_replace(": NBT UDP PACKET(137)", "", $flent['dst']);
+
+ $tmp = split("/", $log_split[2]);
+ $flent['rulenum'] = $tmp[0];
+
+ $counter++;
+ $filterlog[] = $flent;
+
+ }
+
+ return $filterlog;
+}
+
+function convert_port_period_to_colon($addr) {
+ $addr_split = split("\.", $addr);
+ if($addr_split[4] == "")
+ $newvar = $addr_split[0] . "." . $addr_split[1] . "." . $addr_split[2] . "." . $addr_split[3];
+ else
+ $newvar = $addr_split[0] . "." . $addr_split[1] . "." . $addr_split[2] . "." . $addr_split[3] . ":" . $addr_split[4];
+ if($newvar == "...")
+ return $addr;
+ return $newvar;
+}
+
+function format_ipf_ip($ipfip) {
+ list($ip,$port) = explode(",", $ipfip);
+ if (!$port)
+ return $ip;
+
+ return $ip . ", port " . $port;
+}
+
+/* AJAX specific handlers */
+function handle_ajax() {
+ if($_GET['getrulenum'] or $_POST['getrulenum']) {
+ if($_GET['getrulenum'])
+ $rulenum = $_GET['getrulenum'];
+ if($_POST['getrulenum'])
+ $rulenum = $_POST['getrulenum'];
+ $rule = `pfctl -vvsr | grep @{$rulenum}`;
+ echo "The rule that triggered this action is:\n\n{$rule}";
+ exit;
+ }
+
+ if($_GET['lastsawtime'] or $_POST['lastsawtime']) {
+ global $filter_logfile,$filterent;
+ if($_GET['lastsawtime'])
+ $lastsawtime = $_GET['lastsawtime'];
+ if($_POST['lastsawtime'])
+ $lastsawtime = $_POST['lastsawtime'];
+ /* compare lastsawrule's time stamp to filter logs.
+ * afterwards return the newer records so that client
+ * can update AJAX interface screen.
+ */
+ $new_rules = "";
+ $filterlog = conv_clog_filter($filter_logfile, 50);
+ foreach($filterlog as $log_row) {
+ $time_regex = "";
+ preg_match("/.*([0-9][0-9]:[0-9][0-9]:[0-9][0-9])/", $log_row['time'], $time_regex);
+ $row_time = strtotime($time_regex[1]);
+ if (strstr(strtolower($log_row['act']), "p"))
+ $img = "<img border='0' src='/themes/metallic/images/icons/icon_pass.gif'>";
+ else if(strstr(strtolower($filterent['act']), "r"))
+ $img = "<img border='0' src='/themes/metallic/images/icons/icon_reject.gif'>";
+ else
+ $img = "<img border='0' src='/themes/metallic/images/icons/icon_block.gif'>";
+ //echo "{$time_regex[1]} - $row_time > $lastsawtime<p>";
+ if($row_time > $lastsawtime)
+ $new_rules .= "{$img}||{$log_row['time']}||{$log_row['interface']}||{$log_row['src']}||{$log_row['dst']}||{$log_row['proto']}||" . time() . "||\n";
+ }
+ echo $new_rules;
+ exit;
+ }
+}
+?> \ No newline at end of file
diff --git a/usr/local/www/widgets/javascript/log.js b/usr/local/www/widgets/javascript/log.js
new file mode 100644
index 0000000..cc823a1
--- /dev/null
+++ b/usr/local/www/widgets/javascript/log.js
@@ -0,0 +1,155 @@
+
+lastsawtime = '<?php echo time(); ?>;';
+var lines = Array();
+var timer;
+var updateDelay = 12000;
+var isBusy = false;
+var isPaused = false;
+
+<?php
+ if(isset($config['syslog']['reverse']))
+ echo " var isReverse = true;\n";
+ else
+ echo " var isReverse = false;\n";
+?>
+
+if (typeof getURL == 'undefined') {
+ getURL = function(url, callback) {
+ if (!url)
+ throw 'No URL for getURL';
+ try {
+ if (typeof callback.operationComplete == 'function')
+ callback = callback.operationComplete;
+ } catch (e) {}
+ if (typeof callback != 'function')
+ throw 'No callback function for getURL';
+ var http_request = null;
+ if (typeof XMLHttpRequest != 'undefined') {
+ http_request = new XMLHttpRequest();
+ }
+ else if (typeof ActiveXObject != 'undefined') {
+ try {
+ http_request = new ActiveXObject('Msxml2.XMLHTTP');
+ } catch (e) {
+ try {
+ http_request = new ActiveXObject('Microsoft.XMLHTTP');
+ } catch (e) {}
+ }
+ }
+ if (!http_request)
+ throw 'Both getURL and XMLHttpRequest are undefined';
+ http_request.onreadystatechange = function() {
+ if (http_request.readyState == 4) {
+ callback( { success : true,
+ content : http_request.responseText,
+ contentType : http_request.getResponseHeader("Content-Type") } );
+ }
+ }
+ http_request.open('GET', url, true);
+ http_request.send(null);
+ }
+}
+
+function outputrule(req) {
+ alert(req.content);
+}
+function fetch_new_rules() {
+ if(isPaused)
+ return;
+ if(isBusy)
+ return;
+ isBusy = true;
+ getURL('diag_logs_filter_dynamic.php?lastsawtime=' + lastsawtime, fetch_new_rules_callback);
+}
+function fetch_new_rules_callback(callback_data) {
+ if(isPaused)
+ return;
+
+ var data_split;
+ var new_data_to_add = Array();
+ var data = callback_data.content;
+
+ data_split = data.split("\n");
+
+ for(var x=0; x<data_split.length-1; x++) {
+ /* loop through rows */
+ row_split = data_split[x].split("||");
+ var line = '';
+ line = '<div class="log-entry">';
+ line += ' <span class="log-action-mini" nowrap>&nbsp;' + row_split[0] + '&nbsp;</span>';
+ line += ' <span class="log-interface-mini" nowrap>' + row_split[2] + '</span>';
+ line += ' <span class="log-source-mini" nowrap>' + row_split[3] + '</span>';
+ line += ' <span class="log-destination-mini" nowrap>' + row_split[4] + '</span>';
+ line += ' <span class="log-protocol-mini" nowrap>' + row_split[5] + '</span>';
+ line += '</tr></div>';
+ lastsawtime = row_split[6];
+ new_data_to_add[new_data_to_add.length] = line;
+ }
+ update_div_rows(new_data_to_add);
+ isBusy = false;
+}
+function update_div_rows(data) {
+ if(isPaused)
+ return;
+
+ var isIE = navigator.appName.indexOf('Microsoft') != -1;
+ var isSafari = navigator.userAgent.indexOf('Safari') != -1;
+ var isOpera = navigator.userAgent.indexOf('Opera') != -1;
+ var rulestable = document.getElementById('log');
+ var rows = rulestable.getElementsByTagName('div');
+ var showanim = 1;
+ if (isIE) {
+ showanim = 0;
+ }
+ //alert(data.length);
+ for(var x=0; x<data.length; x++) {
+ var numrows = rows.length;
+ var appearatrow;
+ /* if reverse logging is enabled we need to show the
+ * records in a reverse order with new items appearing
+ * on the top
+ */
+ //if(isReverse == false) {
+ // for (var i = 2; i < numrows; i++) {
+ // nextrecord = i + 1;
+ // if(nextrecord < numrows)
+ // rows[i].innerHTML = rows[nextrecord].innerHTML;
+ // }
+ // appearatrow = numrows - 1;
+ //} else {
+ for (var i = numrows; i > 0; i--) {
+ nextrecord = i + 1;
+ if(nextrecord < numrows)
+ rows[nextrecord].innerHTML = rows[i].innerHTML;
+ }
+ appearatrow = 1;
+ //}
+ var item = document.getElementById('firstrow');
+ if(x == data.length-1) {
+ /* nothing */
+ showanim = false;
+ } else {
+ showanim = false;
+ }
+ if (showanim) {
+ rows[appearatrow].style.display = 'none';
+ rows[appearatrow].innerHTML = data[x];
+ new Effect.Appear(rows[appearatrow]);
+ } else {
+ rows[appearatrow].innerHTML = data[x];
+ }
+ }
+ /* rechedule AJAX interval */
+ timer = setInterval('fetch_new_rules()', updateDelay);
+}
+function toggle_pause() {
+ if(isPaused) {
+ isPaused = false;
+ fetch_new_rules();
+ } else {
+ isPaused = true;
+ }
+}
+/* start local AJAX engine */
+lastsawtime = '<?php echo time(); ?>;';
+timer = setInterval('fetch_new_rules()', updateDelay);
diff --git a/usr/local/www/widgets/widgets/interfaces.widget.php b/usr/local/www/widgets/widgets/interfaces.widget.php
new file mode 100644
index 0000000..1ebaa95
--- /dev/null
+++ b/usr/local/www/widgets/widgets/interfaces.widget.php
@@ -0,0 +1,56 @@
+<?php $i = 0; $ifdescrs = array('wan' => 'WAN', 'lan' => 'LAN');
+ for ($j = 1; isset($config['interfaces']['opt' . $j]); $j++) {
+ $ifdescrs['opt' . $j] = $config['interfaces']['opt' . $j]['descr'];
+ }?>
+
+ <table bgcolor="#990000" width="100%" border="0" cellspacing="0" cellpadding="0">
+ <?php
+ $counter = 1;
+ foreach ($ifdescrs as $ifdescr => $ifname){
+ $ifinfo = get_interface_info($ifdescr);
+ $iswireless = is_interface_wireless($ifdescr);
+ ?>
+ <tr>
+ <td class="vncellt" width="30%">
+ <?php if($iswireless) {
+ if($ifinfo['status'] == "associated") { ?>
+ <img src="./themes/<?= $g['theme']; ?>/images/icons/icon_wlan.gif" />
+ <? } else { ?>
+ <img src="./themes/<?= $g['theme']; ?>/images/icons/icon_wlan_d.gif" />
+ <? } ?>
+ <? } else { ?>
+ <img src="./themes/<?= $g['theme']; ?>/images/icons/icon_cablenic.gif"/>
+ <? } ?>&nbsp;
+ <strong>
+ <?php
+ if ($ifname == "WAN") { ?>
+ <a href="/interfaces_wan.php">
+ <? } else if ($ifname == "LAN") { ?>
+ <a href="/interfaces_lan.php">
+ <? } else { ?>
+ <a href="/interfaces_opt.php?index=<?=$counter; ?>">
+ <?
+ $counter++;
+ } ?>
+
+
+ <span style="color:#000000"><?=htmlspecialchars($ifname);?></span></a></strong>
+ </td>
+ <td width="70%" class="listr">
+
+ <?php if ($ifinfo['dhcplink'] != "down" && $ifinfo['pppoelink'] != "down" && $ifinfo['pptplink'] != "down"){ ?>
+ <?php if($ifinfo['status'] == "up") { ?>
+ <img src="./themes/<?= $g['theme']; ?>/images/icons/icon_pass.gif" title="<?=$ifname;?> is up" />&nbsp;
+ <? } else if ($ifinfo['status'] == "down") { ?>
+ <img src="./themes/<?= $g['theme']; ?>/images/icons/icon_block.gif" title="<?=$ifname;?> is down" />&nbsp;
+ <? } else if ($ifinfo['status'] == "associated") { ?>
+ <img src="./themes/<?= $g['theme']; ?>/images/icons/icon_pass.gif" title="<?=$ifname;?> is associated" />&nbsp;
+ <? } else { ?><?=htmlspecialchars($ifinfo['status']);
+ }?>
+ <?php if ($ifinfo['ipaddr']){ ?>
+ <?=htmlspecialchars($ifinfo['ipaddr']);}?>&nbsp;
+ <?=htmlspecialchars($ifinfo['media']);?>
+ </tr><?php }
+ }
+ ?>
+ </table> \ No newline at end of file
diff --git a/usr/local/www/widgets/widgets/log.widget.php b/usr/local/www/widgets/widgets/log.widget.php
new file mode 100644
index 0000000..3e6259f
--- /dev/null
+++ b/usr/local/www/widgets/widgets/log.widget.php
@@ -0,0 +1,41 @@
+<div class="log-header">
+ <span class="log-action-mini-header">Act</span>
+ <span class="log-interface-mini-header">IF</span>
+ <span class="log-source-mini-header">Source</span>
+ <span class="log-destination-mini-header">Destination</span>
+ <span class="log-protocol-mini-header">Proto</span>
+</div>
+<?php $counter=0; foreach ($filterlog as $filterent): ?>
+<?php
+ if(isset($config['syslog']['reverse'])) {
+ /* honour reverse logging setting */
+ if($counter == 0)
+ $activerow = " id=\"firstrow\"";
+ else
+ $activerow = "";
+
+ } else {
+ /* non-reverse logging */
+ if($counter == count($filterlog))
+ $activerow = " id=\"firstrow\"";
+ else
+ $activerow = "";
+ }
+?>
+<div class="log-entry-mini" <?php echo $activerow; ?> style="clear:both;">
+ <span class="log-action-mini" nowrap>
+ <?php
+ if (strstr(strtolower($filterent['act']), "p"))
+ $img = "/themes/metallic/images/icons/icon_pass.gif";
+ else if(strstr(strtolower($filterent['act']), "r"))
+ $img = "/themes/metallic/images/icons/icon_reject.gif";
+ else
+ $img = "/themes/metallic/images/icons/icon_block.gif";
+ ?>
+ &nbsp;<img border="0" src="<?=$img;?>">&nbsp;</span>
+ <span class="log-interface-mini" ><?=htmlspecialchars(convert_real_interface_to_friendly_interface_name($filterent['interface']));?></span>
+ <span class="log-source-mini" ><?=htmlspecialchars($filterent['src']);?></span>
+ <span class="log-destination-mini" ><?=htmlspecialchars($filterent['dst']);?></span>
+ <span class="log-protocol-mini" ><?=htmlspecialchars($filterent['proto']);?></span>
+</div>
+<?php $counter++; endforeach; ?> \ No newline at end of file
OpenPOWER on IntegriCloud