Project

General

Profile

Download (4.84 KB) Statistics
| Branch: | Tag: | Revision:
1
#!/usr/local/bin/php
2
<?php
3
/*
4
	$Id$
5

    
6
	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

    
31
	<logging>
32
		<logtab>arpwatch</logtab>
33
		<grepfor>arpwatch</logtab>
34
	</logging>
35

    
36
		<invertgrep/>
37
		<logfile>/var/log/arpwatch.log</logfile>
38

    
39
*/
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
$i = 0;
53
$apkg = $_POST['pkg'];
54
if(!isset($_POST['pkg'])) { // If we aren't looking for a specific package, locate the first package that handles logging.
55
	if(is_array($config['installedpackages']['package']))
56
		foreach($config['installedpackages']['package'] as $package) {
57
			$pkg_config = parse_xml_config_pkg("/usr/local/pkg/" . $package['configurationfile'], "packagegui");
58
			if(is_array($pkg_config['logging'])) {
59
				$apkg = $package['name'];
60
				$apkgid = $i;
61
				break;
62
			}
63
			$i++;
64
		}
65
} else {
66
	$apkgid = get_pkg_id($apkg);
67
}
68

    
69
?>
70
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
71
<html>
72
<head>
73
<title><?=gentitle("Diagnostics: Package logs");?></title>
74
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
75
<link href="gui.css" rel="stylesheet" type="text/css">
76
</head>
77

    
78
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
79
<?php include("fbegin.inc"); ?>
80
<p class="pgtitle">Diagnostics: Package logs</p>
81
<table width="100%" border="0" cellpadding="0" cellspacing="0">
82
  <tr><td>
83
  <ul id="tabnav">
84
    <?php
85
	if($apkgid == -1) {
86
                print_info_box_np("The specified package, {$apkg}, is not installed.");
87
		include("fend.inc"); ?>
88
		</html>
89
    <?php	exit();
90
		}
91
	if($i == 0) {
92
		print_info_box_np("No packages are currently installed.");
93
		include("fend.inc"); ?>
94
		</html>
95
    <?php	exit();
96
	
97
	
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
		}
112
        }
113
    ?> 
114
  </ul>
115
  </td></tr>
116
  <tr>
117
    <td class="tabcont">
118
		<table width="100%" border="0" cellspacing="0" cellpadding="0">
119
		  <tr>
120
			<td colspan="2" class="listtopic">
121
			  Last <?=$nentries;?> <?=$apkg;?> log entries</td>
122
		  </tr>
123
		  <?php
124
			$apkg_config = parse_xml_config_pkg("/usr/local/pkg/" . $config['installedpackages']['package'][$apkgid]['configurationfile'], "packagegui");
125
			if(isset($apkg_config['logging']['logfile'])) {
126
				$logfile = $apkg_config['logging']['logfile'];
127
			} else {
128
				$logfile = "{$g['varlog_path']}/system.log";
129
			}
130
			if(isset($apkg_config['logging']['custom_php_logging_command'])) {
131
				eval($apkg_config['custom_php_global_functions']);
132
				eval($apkg_config['logging']['custom_php_logging_command']));
133
			} elseif(isset($apkg_config['logging']['grepfor']) and isset($apkg_config['logging']['invertgrep'])) {
134
				dump_clog($logfile, $nentries, $apkg_config['logging']['grepfor'], true);
135
			} elseif(isset($apkg_config['logging']['grepfor'])) {
136
				dump_clog($logfile, $nentries, $apkg_config['logging']['grepfor']);
137
			} else {
138
				dump_clog($logfile, $nentries);
139
			}
140
		?>
141
		</table>
142
		<br><form action="diag_logs.php" method="post">
143
<input name="clear" type="submit" class="formbtn" value="Clear log">
144
</form>
145
	</td>
146
  </tr>
147
</table>
148
<?php include("fend.inc"); ?>
149
</body>
150
</html>
(16-16/111)