Project

General

Profile

Download (4.99 KB) Statistics
| Branch: | Tag: | Revision:
1 df01982a Colin Smith
#!/usr/local/bin/php
2
<?php
3
/*
4 2eb4178b Colin Smith
	$Id$
5
6 df01982a Colin Smith
	diag_pkglogs.php
7
	Copyright (C) 2005 Colin Smith
8
	All rights reserved.
9
10
	Redistribution and use in source and binary forms, with or without
11
	modification, are permitted provided that the following conditions are met:
12
13
	1. Redistributions of source code must retain the above copyright notice,
14
	   this list of conditions and the following disclaimer.
15
16
	2. Redistributions in binary form must reproduce the above copyright
17
	   notice, this list of conditions and the following disclaimer in the
18
	   documentation and/or other materials provided with the distribution.
19
20
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
21
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
22
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
24
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29
	POSSIBILITY OF SUCH DAMAGE.
30 825275fa Colin Smith
31
	<logging>
32
		<logtab>arpwatch</logtab>
33
		<grepfor>arpwatch</logtab>
34
	</logging>
35
36
		<invertgrep/>
37
		<logfile>/var/log/arpwatch.log</logfile>
38
39 df01982a Colin Smith
*/
40
41
require("guiconfig.inc");
42
require("xmlparse_pkg.inc");
43
44
$nentries = $config['syslog']['nentries'];
45
if (!$nentries)
46
	$nentries = 50;
47
48
if ($_POST['clear']) {
49
	exec("/usr/sbin/clog -i -s 262144 {$system_logfile}");
50
}
51
52 2eb4178b Colin Smith
$i = 0;
53 9fc0d646 Colin Smith
$pkgwithlogging = false;
54 2eb4178b Colin Smith
$apkg = $_POST['pkg'];
55
if(!isset($_POST['pkg'])) { // If we aren't looking for a specific package, locate the first package that handles logging.
56 52da2110 Colin Smith
	if($config['installedpackages']['package'] <> "") {
57 c2eb36d9 Scott Ullrich
		foreach($config['installedpackages']['package'] as $package) {
58
			$pkg_config = parse_xml_config_pkg("/usr/local/pkg/" . $package['configurationfile'], "packagegui");
59
			if(is_array($pkg_config['logging'])) {
60 9fc0d646 Colin Smith
				$pkgwithlogging = true;
61 c2eb36d9 Scott Ullrich
				$apkg = $package['name'];
62
				$apkgid = $i;
63
				break;
64
			}
65
			$i++;
66 2eb4178b Colin Smith
		}
67 42e72ab3 Scott Ullrich
	}
68 2eb4178b Colin Smith
} else {
69 9fc0d646 Colin Smith
	$pkgwithlogging = true;
70 2eb4178b Colin Smith
	$apkgid = get_pkg_id($apkg);
71 52da2110 Colin Smith
	$i = $apkgid;
72 2eb4178b Colin Smith
}
73 df01982a Colin Smith
?>
74
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
75
<html>
76
<head>
77
<title><?=gentitle("Diagnostics: Package logs");?></title>
78
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
79
<link href="gui.css" rel="stylesheet" type="text/css">
80
</head>
81
82
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
83
<?php include("fbegin.inc"); ?>
84
<p class="pgtitle">Diagnostics: Package logs</p>
85
<table width="100%" border="0" cellpadding="0" cellspacing="0">
86
  <tr><td>
87
  <ul id="tabnav">
88
    <?php
89 9fc0d646 Colin Smith
	if($config['installedpackages']['package'] == "" or $pkgwithlogging == false) {
90 64d08e72 Colin Smith
		print_info_box("No packages with logging facilities are currently installed.");
91 52da2110 Colin Smith
	?>
92
		</ul></td></tr></table>
93
	<?php
94 42e72ab3 Scott Ullrich
		include("fend.inc");
95 52da2110 Colin Smith
		exit;
96 42e72ab3 Scott Ullrich
	}
97 52da2110 Colin Smith
	if($config['installedpackages']['package'] <> "") {
98
		foreach($config['installedpackages']['package'] as $package) {
99
        		$pkg_config = parse_xml_config_pkg("/usr/local/pkg/" . $package['configurationfile'], "packagegui");
100
			if(is_array($pkg_config['logging'])) {
101
				$pkgname = $package['name'];
102
				$logtab = $pkg_config['logging']['logtab'];
103
				if(!isset($pkg_config['logging']['logtab'])) $logtab = $pkgname;
104
				if($apkg == $pkgname) { ?>
105
					<li class="tabact"><?= $pkg_config['name']; ?></li>
106
    <?php
107
				} else { ?>
108
					<li class="tabinact"><a href="diag_pkglogs.php?pkg=<?= $pkgname; ?>"><?= $logtab; ?></a></li>
109
    <?php
110
				}
111 df01982a Colin Smith
			}
112 52da2110 Colin Smith
       		 }
113
	}
114 df01982a Colin Smith
    ?> 
115
  </ul>
116
  </td></tr>
117
  <tr>
118
    <td class="tabcont">
119
		<table width="100%" border="0" cellspacing="0" cellpadding="0">
120
		  <tr>
121
			<td colspan="2" class="listtopic">
122 52da2110 Colin Smith
			  Last <?=$nentries;?> <?=$apkg;?> log entries</td>
123 df01982a Colin Smith
		  </tr>
124
		  <?php
125
			$apkg_config = parse_xml_config_pkg("/usr/local/pkg/" . $config['installedpackages']['package'][$apkgid]['configurationfile'], "packagegui");
126
			if(isset($apkg_config['logging']['logfile'])) {
127
				$logfile = $apkg_config['logging']['logfile'];
128
			} else {
129
				$logfile = "{$g['varlog_path']}/system.log";
130
			}
131 c669ba56 Colin Smith
			if(isset($apkg_config['logging']['custom_php_logging_command'])) {
132
				eval($apkg_config['custom_php_global_functions']);
133 9187b46a Scott Ullrich
				eval($apkg_config['logging']['custom_php_logging_command']);
134 c669ba56 Colin Smith
			} elseif(isset($apkg_config['logging']['grepfor']) and isset($apkg_config['logging']['invertgrep'])) {
135 1d19a2fb Colin Smith
				dump_clog($logfile, $nentries, $apkg_config['logging']['grepfor'], true, true, false);
136 df01982a Colin Smith
			} elseif(isset($apkg_config['logging']['grepfor'])) {
137 1d19a2fb Colin Smith
				dump_clog($logfile, $nentries, $apkg_config['logging']['grepfor'], "", true, false);
138 df01982a Colin Smith
			} else {
139 1d19a2fb Colin Smith
				dump_clog($logfile, $nentries, "", "", true, false);
140 df01982a Colin Smith
			}
141
		?>
142
		</table>
143 52da2110 Colin Smith
		<br>
144
<!--
145
<form action="diag_pkglogs.php" method="post">
146 df01982a Colin Smith
<input name="clear" type="submit" class="formbtn" value="Clear log">
147
</form>
148 52da2110 Colin Smith
-->
149 df01982a Colin Smith
	</td>
150
  </tr>
151
</table>
152
<?php include("fend.inc"); ?>
153
</body>
154
</html>