Subversion Repositories ALCASAR

Rev

Details | Last modification | View Log

Rev Author Line No. Line
325 richard 1
<?php
2
/***************************************************************************
3
 *   Copyright (C) 2006 by phpSysInfo - A PHP System Information Script    *
4
 *   http://phpsysinfo.sourceforge.net/                                    *
5
 *                                                                         *
6
 *   This program is free software; you can redistribute it and/or modify  *
7
 *   it under the terms of the GNU General Public License as published by  *
8
 *   the Free Software Foundation; either version 2 of the License, or     *
9
 *   (at your option) any later version.                                   *
10
 *                                                                         *
11
 *   This program is distributed in the hope that it will be useful,       *
12
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
13
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
14
 *   GNU General Public License for more details.                          *
15
 *                                                                         *
16
 *   You should have received a copy of the GNU General Public License     *
17
 *   along with this program; if not, write to the                         *
18
 *   Free Software Foundation, Inc.,                                       *
19
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
20
 ***************************************************************************/
21
 
22
// $Id: class.parseProgs.inc.php,v 1.12 2007/02/01 17:37:06 bigmichi1 Exp $
23
 
24
class Parser {
25
	var $debug	= false;
26
	var $df_param	= "";
27
 
28
	function parse_lspci() {
29
 
30
		$arrResults = array();
31
 
32
		if ( ( $strBuff = execute_program( "lspci", "", $this->debug ) ) != "ERROR" ) {
33
			$arrLines = explode( "\n", $strBuff );
34
			foreach( $arrLines as $strLine ) {
35
				list( $strAddr, $strName) = explode( ' ', trim( $strLine ), 2 );
36
				$strName = preg_replace( '/\(.*\)/', '', $strName);
37
				$arrResults[] = $strName;
38
			}
39
		}
40
		if( empty( $arrResults ) ) {
41
			return false;
42
		} else {
43
			asort( $arrResults );
44
			return $arrResults;
45
		}
46
	}
47
 
48
	function parse_pciconf() {
49
 
50
		$arrResults = array();
51
		$intS = 0;
52
 
53
		if( ( $strBuff = execute_program( "pciconf", "-lv", $this->debug ) ) != "ERROR" ) {
54
			$arrLines = explode( "\n", $strBuff );
55
			foreach( $arrLines as $strLine ) {
56
				if( preg_match( "/(.*) = '(.*)'/", $strLine, $arrParts ) ) {
57
					if( trim( $arrParts[1] ) == "vendor" ) {
58
						$arrResults[$intS] = trim( $arrParts[2] );
59
					} elseif( trim( $arrParts[1]) == "device" ) {
60
						$arrResults[$intS] .= " - " . trim( $arrParts[2] );
61
						$intS++;
62
					}
63
				}
64
			}
65
		}
66
		if( empty( $arrResults ) ) {
67
			return false;
68
		} else {
69
			asort( $arrResults );
70
			return $arrResults;
71
		}
72
	}
73
 
74
	function parse_filesystems() {
75
 
76
		global $show_bind, $show_inodes;
77
 
78
		$results = array();
79
		$j = 0;
80
 
81
		$df = execute_program('df', '-k' . $this->df_param );
82
		$df = preg_split("/\n/", $df, -1, PREG_SPLIT_NO_EMPTY);
83
		sort($df);
84
		if( $show_inodes ) {
85
			$df2 = execute_program('df', '-i' . $this->df_param );
86
			$df2 = preg_split("/\n/", $df2, -1, PREG_SPLIT_NO_EMPTY);
87
			sort( $df2 );
88
		}
89
		$mount = execute_program('mount');
90
		$mount = preg_split("/\n/", $mount, -1, PREG_SPLIT_NO_EMPTY);
91
		sort($mount);
92
 
93
		foreach( $df as $df_line) {
94
			$df_buf1  = preg_split("/(\%\s)/", $df_line, 2);
95
			if( count($df_buf1) != 2) {
96
				continue;
97
			}
98
			preg_match("/(.*)(\s+)(([0-9]+)(\s+)([0-9]+)(\s+)([0-9]+)(\s+)([0-9]+)$)/", $df_buf1[0], $df_buf2);
99
			$df_buf = array($df_buf2[1], $df_buf2[4], $df_buf2[6], $df_buf2[8], $df_buf2[10], $df_buf1[1]);
100
			if( $show_inodes ) {
101
				preg_match_all("/([0-9]+)%/", $df2[$j + 1], $inode_buf, PREG_SET_ORDER);
102
			}
103
			if( count($df_buf) == 6 ) {
104
				$df_buf[5] = trim( $df_buf[5] );
105
				if( hide_mount( $df_buf[5] ) ) {
106
					continue;
107
				}
108
				$df_buf[0] = trim( str_replace("\$", "\\$", $df_buf[0] ) );
109
				$current = 0;
110
				foreach( $mount as $mount_line ) {
111
					if ( preg_match("#" . $df_buf[0] . " on " . $df_buf[5] . " type (.*) \((.*)\)#", $mount_line, $mount_buf) ) {
112
						$mount_buf[1] .= "," . $mount_buf[2];
113
					} elseif ( !preg_match("#" . $df_buf[0] . "(.*) on " . $df_buf[5] . " \((.*)\)#", $mount_line, $mount_buf) ) {
114
						continue;
115
					}
116
					$strFstype = substr( $mount_buf[1], 0, strpos( $mount_buf[1], "," ) );
117
					if( hide_fstype( $strFstype ) ) {
118
						continue;
119
					}
120
					$current++;
121
					if( $show_bind || !stristr($mount_buf[2], "bind")) {
122
						$results[$j] = array();
123
						$results[$j]['disk'] = str_replace( "\\$", "\$", $df_buf[0] );
124
						$results[$j]['size'] = $df_buf[1];
125
						$results[$j]['used'] = $df_buf[2];
126
						$results[$j]['free'] = $df_buf[3];
127
						// --> Bug 1527673
128
						if( $results[$j]['used'] < 0 ) {
129
							$results[$j]['size'] = $results[$j]['free'];
130
							$results[$j]['free'] = 0;
131
							$results[$j]['used'] = $results[$j]['size'];
132
						}
133
						// <-- Bug 1527673
134
						// --> Bug 1649430
135
						if( $results[$j]['size'] == 0 ) {
136
							break;
137
						} else {
138
							$results[$j]['percent'] = round(($results[$j]['used'] * 100) / $results[$j]['size']);
139
						}
140
						// <-- Bug 1649430
141
						$results[$j]['mount'] = $df_buf[5];
142
						$results[$j]['fstype'] = $strFstype;
143
						$results[$j]['options'] = substr( $mount_buf[1], strpos( $mount_buf[1], "," ) + 1, strlen( $mount_buf[1] ) );
144
						if( $show_inodes && isset($inode_buf[ count( $inode_buf ) - 1][1]) ) {
145
							$results[$j]['inodes'] = $inode_buf[ count( $inode_buf ) - 1][1];
146
						}
147
						$j++;
148
						unset( $mount[$current - 1] );
149
						sort( $mount );
150
						break;
151
					}
152
				}
153
			}
154
		}
155
		return $results;
156
	}
157
 
158
}
159
?>