Редакция 69 | Только различия | Учитывать пробелы | Содержимое файла | Авторство | Последнее изменение | Открыть журнал | RSS
Редакция 69 | Редакция 94 | ||
---|---|---|---|
1 | <?php
|
1 | <?php
|
2 | /**
|
2 | /**
|
3 | * The OS_Guess class
|
3 | * The OS_Guess class
|
4 | *
|
4 | *
|
5 | * PHP versions 4 and 5
|
5 | * PHP versions 4 and 5
|
6 | *
|
6 | *
|
7 | * LICENSE: This source file is subject to version 3.0 of the PHP license
|
7 | * LICENSE: This source file is subject to version 3.0 of the PHP license
|
8 | * that is available through the world-wide-web at the following URI:
|
8 | * that is available through the world-wide-web at the following URI:
|
9 | * http://www.php.net/license/3_0.txt. If you did not receive a copy of
|
9 | * http://www.php.net/license/3_0.txt. If you did not receive a copy of
|
10 | * the PHP License and are unable to obtain it through the web, please
|
10 | * the PHP License and are unable to obtain it through the web, please
|
11 | * send a note to license@php.net so we can mail you a copy immediately.
|
11 | * send a note to license@php.net so we can mail you a copy immediately.
|
12 | *
|
12 | *
|
13 | * @category pear
|
13 | * @category pear
|
14 | * @package PEAR
|
14 | * @package PEAR
|
15 | * @author Stig Bakken <ssb@php.net>
|
15 | * @author Stig Bakken <ssb@php.net>
|
16 | * @author Gregory Beaver <cellog@php.net>
|
16 | * @author Gregory Beaver <cellog@php.net>
|
17 | * @copyright 1997-2008 The PHP Group
|
17 | * @copyright 1997-2008 The PHP Group
|
18 | * @license http://www.php.net/license/3_0.txt PHP License 3.0
|
18 | * @license http://www.php.net/license/3_0.txt PHP License 3.0
|
19 | * @version CVS: $Id: Guess.php,v 1.26 2008/01/03 20:26:34 cellog Exp $
|
19 | * @version CVS: $Id: Guess.php,v 1.26 2008/01/03 20:26:34 cellog Exp $
|
20 | * @link http://pear.php.net/package/PEAR
|
20 | * @link http://pear.php.net/package/PEAR
|
21 | * @since File available since PEAR 0.1
|
21 | * @since File available since PEAR 0.1
|
22 | */
|
22 | */
|
23 | 23 | ||
24 | // {{{ uname examples
|
24 | // {{{ uname examples
|
25 | 25 | ||
26 | // php_uname() without args returns the same as 'uname -a', or a PHP-custom
|
26 | // php_uname() without args returns the same as 'uname -a', or a PHP-custom
|
27 | // string for Windows.
|
27 | // string for Windows.
|
28 | // PHP versions prior to 4.3 return the uname of the host where PHP was built,
|
28 | // PHP versions prior to 4.3 return the uname of the host where PHP was built,
|
29 | // as of 4.3 it returns the uname of the host running the PHP code.
|
29 | // as of 4.3 it returns the uname of the host running the PHP code.
|
30 | //
|
30 | //
|
31 | // PC RedHat Linux 7.1:
|
31 | // PC RedHat Linux 7.1:
|
32 | // Linux host.example.com 2.4.2-2 #1 Sun Apr 8 20:41:30 EDT 2001 i686 unknown
|
32 | // Linux host.example.com 2.4.2-2 #1 Sun Apr 8 20:41:30 EDT 2001 i686 unknown
|
33 | //
|
33 | //
|
34 | // PC Debian Potato:
|
34 | // PC Debian Potato:
|
35 | // Linux host 2.4.17 #2 SMP Tue Feb 12 15:10:04 CET 2002 i686 unknown
|
35 | // Linux host 2.4.17 #2 SMP Tue Feb 12 15:10:04 CET 2002 i686 unknown
|
36 | //
|
36 | //
|
37 | // PC FreeBSD 3.3:
|
37 | // PC FreeBSD 3.3:
|
38 | // FreeBSD host.example.com 3.3-STABLE FreeBSD 3.3-STABLE #0: Mon Feb 21 00:42:31 CET 2000 root@example.com:/usr/src/sys/compile/CONFIG i386
|
38 | // FreeBSD host.example.com 3.3-STABLE FreeBSD 3.3-STABLE #0: Mon Feb 21 00:42:31 CET 2000 root@example.com:/usr/src/sys/compile/CONFIG i386
|
39 | //
|
39 | //
|
40 | // PC FreeBSD 4.3:
|
40 | // PC FreeBSD 4.3:
|
41 | // FreeBSD host.example.com 4.3-RELEASE FreeBSD 4.3-RELEASE #1: Mon Jun 25 11:19:43 EDT 2001 root@example.com:/usr/src/sys/compile/CONFIG i386
|
41 | // FreeBSD host.example.com 4.3-RELEASE FreeBSD 4.3-RELEASE #1: Mon Jun 25 11:19:43 EDT 2001 root@example.com:/usr/src/sys/compile/CONFIG i386
|
42 | //
|
42 | //
|
43 | // PC FreeBSD 4.5:
|
43 | // PC FreeBSD 4.5:
|
44 | // FreeBSD host.example.com 4.5-STABLE FreeBSD 4.5-STABLE #0: Wed Feb 6 23:59:23 CET 2002 root@example.com:/usr/src/sys/compile/CONFIG i386
|
44 | // FreeBSD host.example.com 4.5-STABLE FreeBSD 4.5-STABLE #0: Wed Feb 6 23:59:23 CET 2002 root@example.com:/usr/src/sys/compile/CONFIG i386
|
45 | //
|
45 | //
|
46 | // PC FreeBSD 4.5 w/uname from GNU shellutils:
|
46 | // PC FreeBSD 4.5 w/uname from GNU shellutils:
|
47 | // FreeBSD host.example.com 4.5-STABLE FreeBSD 4.5-STABLE #0: Wed Feb i386 unknown
|
47 | // FreeBSD host.example.com 4.5-STABLE FreeBSD 4.5-STABLE #0: Wed Feb i386 unknown
|
48 | //
|
48 | //
|
49 | // HP 9000/712 HP-UX 10:
|
49 | // HP 9000/712 HP-UX 10:
|
50 | // HP-UX iq B.10.10 A 9000/712 2008429113 two-user license
|
50 | // HP-UX iq B.10.10 A 9000/712 2008429113 two-user license
|
51 | //
|
51 | //
|
52 | // HP 9000/712 HP-UX 10 w/uname from GNU shellutils:
|
52 | // HP 9000/712 HP-UX 10 w/uname from GNU shellutils:
|
53 | // HP-UX host B.10.10 A 9000/712 unknown
|
53 | // HP-UX host B.10.10 A 9000/712 unknown
|
54 | //
|
54 | //
|
55 | // IBM RS6000/550 AIX 4.3:
|
55 | // IBM RS6000/550 AIX 4.3:
|
56 | // AIX host 3 4 000003531C00
|
56 | // AIX host 3 4 000003531C00
|
57 | //
|
57 | //
|
58 | // AIX 4.3 w/uname from GNU shellutils:
|
58 | // AIX 4.3 w/uname from GNU shellutils:
|
59 | // AIX host 3 4 000003531C00 unknown
|
59 | // AIX host 3 4 000003531C00 unknown
|
60 | //
|
60 | //
|
61 | // SGI Onyx IRIX 6.5 w/uname from GNU shellutils:
|
61 | // SGI Onyx IRIX 6.5 w/uname from GNU shellutils:
|
62 | // IRIX64 host 6.5 01091820 IP19 mips
|
62 | // IRIX64 host 6.5 01091820 IP19 mips
|
63 | //
|
63 | //
|
64 | // SGI Onyx IRIX 6.5:
|
64 | // SGI Onyx IRIX 6.5:
|
65 | // IRIX64 host 6.5 01091820 IP19
|
65 | // IRIX64 host 6.5 01091820 IP19
|
66 | //
|
66 | //
|
67 | // SparcStation 20 Solaris 8 w/uname from GNU shellutils:
|
67 | // SparcStation 20 Solaris 8 w/uname from GNU shellutils:
|
68 | // SunOS host.example.com 5.8 Generic_108528-12 sun4m sparc
|
68 | // SunOS host.example.com 5.8 Generic_108528-12 sun4m sparc
|
69 | //
|
69 | //
|
70 | // SparcStation 20 Solaris 8:
|
70 | // SparcStation 20 Solaris 8:
|
71 | // SunOS host.example.com 5.8 Generic_108528-12 sun4m sparc SUNW,SPARCstation-20
|
71 | // SunOS host.example.com 5.8 Generic_108528-12 sun4m sparc SUNW,SPARCstation-20
|
72 | //
|
72 | //
|
73 | // Mac OS X (Darwin)
|
73 | // Mac OS X (Darwin)
|
74 | // Darwin home-eden.local 7.5.0 Darwin Kernel Version 7.5.0: Thu Aug 5 19:26:16 PDT 2004; root:xnu/xnu-517.7.21.obj~3/RELEASE_PPC Power Macintosh
|
74 | // Darwin home-eden.local 7.5.0 Darwin Kernel Version 7.5.0: Thu Aug 5 19:26:16 PDT 2004; root:xnu/xnu-517.7.21.obj~3/RELEASE_PPC Power Macintosh
|
75 | //
|
75 | //
|
76 | // Mac OS X early versions
|
76 | // Mac OS X early versions
|
77 | //
|
77 | //
|
78 | 78 | ||
79 | // }}}
|
79 | // }}}
|
80 | 80 | ||
81 | /* TODO:
|
81 | /* TODO:
|
82 | * - define endianness, to allow matchSignature("bigend") etc.
|
82 | * - define endianness, to allow matchSignature("bigend") etc.
|
83 | */
|
83 | */
|
84 | 84 | ||
85 | /**
|
85 | /**
|
86 | * Retrieves information about the current operating system
|
86 | * Retrieves information about the current operating system
|
87 | *
|
87 | *
|
88 | * This class uses php_uname() to grok information about the current OS
|
88 | * This class uses php_uname() to grok information about the current OS
|
89 | *
|
89 | *
|
90 | * @category pear
|
90 | * @category pear
|
91 | * @package PEAR
|
91 | * @package PEAR
|
92 | * @author Stig Bakken <ssb@php.net>
|
92 | * @author Stig Bakken <ssb@php.net>
|
93 | * @author Gregory Beaver <cellog@php.net>
|
93 | * @author Gregory Beaver <cellog@php.net>
|
94 | * @copyright 1997-2008 The PHP Group
|
94 | * @copyright 1997-2008 The PHP Group
|
95 | * @license http://www.php.net/license/3_0.txt PHP License 3.0
|
95 | * @license http://www.php.net/license/3_0.txt PHP License 3.0
|
96 | * @version Release: 1.7.2
|
96 | * @version Release: 1.7.2
|
97 | * @link http://pear.php.net/package/PEAR
|
97 | * @link http://pear.php.net/package/PEAR
|
98 | * @since Class available since Release 0.1
|
98 | * @since Class available since Release 0.1
|
99 | */
|
99 | */
|
100 | class OS_Guess
|
100 | class OS_Guess
|
101 | {
|
101 | {
|
102 | var $sysname; |
102 | var $sysname; |
103 | var $nodename; |
103 | var $nodename; |
104 | var $cpu; |
104 | var $cpu; |
105 | var $release; |
105 | var $release; |
106 | var $extra; |
106 | var $extra; |
107 | 107 | ||
108 | function OS_Guess($uname = null) |
108 | function OS_Guess($uname = null) |
109 | {
|
109 | {
|
110 | list($this->sysname, |
110 | list($this->sysname, |
111 | $this->release, |
111 | $this->release, |
112 | $this->cpu, |
112 | $this->cpu, |
113 | $this->extra, |
113 | $this->extra, |
114 | $this->nodename) = $this->parseSignature($uname); |
114 | $this->nodename) = $this->parseSignature($uname); |
115 | }
|
115 | }
|
116 | 116 | ||
117 | function parseSignature($uname = null) |
117 | function parseSignature($uname = null) |
118 | {
|
118 | {
|
119 | static $sysmap = array( |
119 | static $sysmap = array( |
120 | 'HP-UX' => 'hpux', |
120 | 'HP-UX' => 'hpux', |
121 | 'IRIX64' => 'irix', |
121 | 'IRIX64' => 'irix', |
122 | ); |
122 | ); |
123 | static $cpumap = array( |
123 | static $cpumap = array( |
124 | 'i586' => 'i386', |
124 | 'i586' => 'i386', |
125 | 'i686' => 'i386', |
125 | 'i686' => 'i386', |
126 | 'ppc' => 'powerpc', |
126 | 'ppc' => 'powerpc', |
127 | ); |
127 | ); |
128 | if ($uname === null) { |
128 | if ($uname === null) { |
129 | $uname = php_uname(); |
129 | $uname = php_uname(); |
130 | }
|
130 | }
|
131 | $parts = split('[[:space:]]+', trim($uname)); |
131 | $parts = split('[[:space:]]+', trim($uname)); |
132 | $n = count($parts); |
132 | $n = count($parts); |
133 | 133 | ||
134 | $release = $machine = $cpu = ''; |
134 | $release = $machine = $cpu = ''; |
135 | $sysname = $parts[0]; |
135 | $sysname = $parts[0]; |
136 | $nodename = $parts[1]; |
136 | $nodename = $parts[1]; |
137 | $cpu = $parts[$n-1]; |
137 | $cpu = $parts[$n-1]; |
138 | $extra = ''; |
138 | $extra = ''; |
139 | if ($cpu == 'unknown') { |
139 | if ($cpu == 'unknown') { |
140 | $cpu = $parts[$n-2]; |
140 | $cpu = $parts[$n-2]; |
141 | }
|
141 | }
|
142 | 142 | ||
143 | switch ($sysname) { |
143 | switch ($sysname) { |
144 | case 'AIX' : |
144 | case 'AIX' : |
145 | $release = "$parts[3].$parts[2]"; |
145 | $release = "$parts[3].$parts[2]"; |
146 | break; |
146 | break; |
147 | case 'Windows' : |
147 | case 'Windows' : |
148 | switch ($parts[1]) { |
148 | switch ($parts[1]) { |
149 | case '95/98': |
149 | case '95/98': |
150 | $release = '9x'; |
150 | $release = '9x'; |
151 | break; |
151 | break; |
152 | default: |
152 | default: |
153 | $release = $parts[1]; |
153 | $release = $parts[1]; |
154 | break; |
154 | break; |
155 | }
|
155 | }
|
156 | $cpu = 'i386'; |
156 | $cpu = 'i386'; |
157 | break; |
157 | break; |
158 | case 'Linux' : |
158 | case 'Linux' : |
159 | $extra = $this->_detectGlibcVersion(); |
159 | $extra = $this->_detectGlibcVersion(); |
160 | // use only the first two digits from the kernel version
|
160 | // use only the first two digits from the kernel version
|
161 | $release = ereg_replace('^([[:digit:]]+\.[[:digit:]]+).*', '\1', $parts[2]); |
161 | $release = ereg_replace('^([[:digit:]]+\.[[:digit:]]+).*', '\1', $parts[2]); |
162 | break; |
162 | break; |
163 | case 'Mac' : |
163 | case 'Mac' : |
164 | $sysname = 'darwin'; |
164 | $sysname = 'darwin'; |
165 | $nodename = $parts[2]; |
165 | $nodename = $parts[2]; |
166 | $release = $parts[3]; |
166 | $release = $parts[3]; |
167 | if ($cpu == 'Macintosh') { |
167 | if ($cpu == 'Macintosh') { |
168 | if ($parts[$n - 2] == 'Power') { |
168 | if ($parts[$n - 2] == 'Power') { |
169 | $cpu = 'powerpc'; |
169 | $cpu = 'powerpc'; |
170 | }
|
170 | }
|
171 | }
|
171 | }
|
172 | break; |
172 | break; |
173 | case 'Darwin' : |
173 | case 'Darwin' : |
174 | if ($cpu == 'Macintosh') { |
174 | if ($cpu == 'Macintosh') { |
175 | if ($parts[$n - 2] == 'Power') { |
175 | if ($parts[$n - 2] == 'Power') { |
176 | $cpu = 'powerpc'; |
176 | $cpu = 'powerpc'; |
177 | }
|
177 | }
|
178 | }
|
178 | }
|
179 | $release = ereg_replace('^([[:digit:]]+\.[[:digit:]]+).*', '\1', $parts[2]); |
179 | $release = ereg_replace('^([[:digit:]]+\.[[:digit:]]+).*', '\1', $parts[2]); |
180 | break; |
180 | break; |
181 | default: |
181 | default: |
182 | $release = ereg_replace('-.*', '', $parts[2]); |
182 | $release = ereg_replace('-.*', '', $parts[2]); |
183 | break; |
183 | break; |
184 | }
|
184 | }
|
185 | 185 | ||
186 | 186 | ||
187 | if (isset($sysmap[$sysname])) { |
187 | if (isset($sysmap[$sysname])) { |
188 | $sysname = $sysmap[$sysname]; |
188 | $sysname = $sysmap[$sysname]; |
189 | } else { |
189 | } else { |
190 | $sysname = strtolower($sysname); |
190 | $sysname = strtolower($sysname); |
191 | }
|
191 | }
|
192 | if (isset($cpumap[$cpu])) { |
192 | if (isset($cpumap[$cpu])) { |
193 | $cpu = $cpumap[$cpu]; |
193 | $cpu = $cpumap[$cpu]; |
194 | }
|
194 | }
|
195 | return array($sysname, $release, $cpu, $extra, $nodename); |
195 | return array($sysname, $release, $cpu, $extra, $nodename); |
196 | }
|
196 | }
|
197 | 197 | ||
198 | function _detectGlibcVersion() |
198 | function _detectGlibcVersion() |
199 | {
|
199 | {
|
200 | static $glibc = false; |
200 | static $glibc = false; |
201 | if ($glibc !== false) { |
201 | if ($glibc !== false) { |
202 | return $glibc; // no need to run this multiple times |
202 | return $glibc; // no need to run this multiple times |
203 | }
|
203 | }
|
204 | $major = $minor = 0; |
204 | $major = $minor = 0; |
205 | include_once "System.php"; |
205 | include_once "System.php"; |
206 | // Use glibc's <features.h> header file to
|
206 | // Use glibc's <features.h> header file to
|
207 | // get major and minor version number:
|
207 | // get major and minor version number:
|
208 | if (@file_exists('/usr/include/features.h') && |
208 | if (@file_exists('/usr/include/features.h') && |
209 | @is_readable('/usr/include/features.h')) { |
209 | @is_readable('/usr/include/features.h')) { |
210 | if (!@file_exists('/usr/bin/cpp') || !@is_executable('/usr/bin/cpp')) { |
210 | if (!@file_exists('/usr/bin/cpp') || !@is_executable('/usr/bin/cpp')) { |
211 | $features_file = fopen('/usr/include/features.h', 'rb'); |
211 | $features_file = fopen('/usr/include/features.h', 'rb'); |
212 | while (!feof($features_file)) { |
212 | while (!feof($features_file)) { |
213 | $line = fgets($features_file, 8192); |
213 | $line = fgets($features_file, 8192); |
214 | if (!$line || (strpos($line, '#define') === false)) { |
214 | if (!$line || (strpos($line, '#define') === false)) { |
215 | continue; |
215 | continue; |
216 | }
|
216 | }
|
217 | if (strpos($line, '__GLIBC__')) { |
217 | if (strpos($line, '__GLIBC__')) { |
218 | // major version number #define __GLIBC__ version
|
218 | // major version number #define __GLIBC__ version
|
219 | $line = preg_split('/\s+/', $line); |
219 | $line = preg_split('/\s+/', $line); |
220 | $glibc_major = trim($line[2]); |
220 | $glibc_major = trim($line[2]); |
221 | if (isset($glibc_minor)) { |
221 | if (isset($glibc_minor)) { |
222 | break; |
222 | break; |
223 | }
|
223 | }
|
224 | continue; |
224 | continue; |
225 | }
|
225 | }
|
226 | if (strpos($line, '__GLIBC_MINOR__')) { |
226 | if (strpos($line, '__GLIBC_MINOR__')) { |
227 | // got the minor version number
|
227 | // got the minor version number
|
228 | // #define __GLIBC_MINOR__ version
|
228 | // #define __GLIBC_MINOR__ version
|
229 | $line = preg_split('/\s+/', $line); |
229 | $line = preg_split('/\s+/', $line); |
230 | $glibc_minor = trim($line[2]); |
230 | $glibc_minor = trim($line[2]); |
231 | if (isset($glibc_major)) { |
231 | if (isset($glibc_major)) { |
232 | break; |
232 | break; |
233 | }
|
233 | }
|
234 | continue; |
234 | continue; |
235 | }
|
235 | }
|
236 | }
|
236 | }
|
237 | fclose($features_file); |
237 | fclose($features_file); |
238 | if (!isset($glibc_major) || !isset($glibc_minor)) { |
238 | if (!isset($glibc_major) || !isset($glibc_minor)) { |
239 | return $glibc = ''; |
239 | return $glibc = ''; |
240 | }
|
240 | }
|
241 | return $glibc = 'glibc' . trim($glibc_major) . "." . trim($glibc_minor) ; |
241 | return $glibc = 'glibc' . trim($glibc_major) . "." . trim($glibc_minor) ; |
242 | } // no cpp |
242 | } // no cpp |
243 | $tmpfile = System::mktemp("glibctest"); |
243 | $tmpfile = System::mktemp("glibctest"); |
244 | $fp = fopen($tmpfile, "w"); |
244 | $fp = fopen($tmpfile, "w"); |
245 | fwrite($fp, "#include <features.h>\n__GLIBC__ __GLIBC_MINOR__\n"); |
245 | fwrite($fp, "#include <features.h>\n__GLIBC__ __GLIBC_MINOR__\n"); |
246 | fclose($fp); |
246 | fclose($fp); |
247 | $cpp = popen("/usr/bin/cpp $tmpfile", "r"); |
247 | $cpp = popen("/usr/bin/cpp $tmpfile", "r"); |
248 | while ($line = fgets($cpp, 1024)) { |
248 | while ($line = fgets($cpp, 1024)) { |
249 | if ($line{0} == '#' || trim($line) == '') { |
249 | if ($line{0} == '#' || trim($line) == '') { |
250 | continue; |
250 | continue; |
251 | }
|
251 | }
|
252 | if (list($major, $minor) = explode(' ', trim($line))) { |
252 | if (list($major, $minor) = explode(' ', trim($line))) { |
253 | break; |
253 | break; |
254 | }
|
254 | }
|
255 | }
|
255 | }
|
256 | pclose($cpp); |
256 | pclose($cpp); |
257 | unlink($tmpfile); |
257 | unlink($tmpfile); |
258 | } // features.h |
258 | } // features.h |
259 | if (!($major && $minor) && @is_link('/lib/libc.so.6')) { |
259 | if (!($major && $minor) && @is_link('/lib/libc.so.6')) { |
260 | // Let's try reading the libc.so.6 symlink
|
260 | // Let's try reading the libc.so.6 symlink
|
261 | if (ereg('^libc-(.*)\.so$', basename(readlink('/lib/libc.so.6')), $matches)) { |
261 | if (ereg('^libc-(.*)\.so$', basename(readlink('/lib/libc.so.6')), $matches)) { |
262 | list($major, $minor) = explode('.', $matches[1]); |
262 | list($major, $minor) = explode('.', $matches[1]); |
263 | }
|
263 | }
|
264 | }
|
264 | }
|
265 | if (!($major && $minor)) { |
265 | if (!($major && $minor)) { |
266 | return $glibc = ''; |
266 | return $glibc = ''; |
267 | }
|
267 | }
|
268 | return $glibc = "glibc{$major}.{$minor}"; |
268 | return $glibc = "glibc{$major}.{$minor}"; |
269 | }
|
269 | }
|
270 | 270 | ||
271 | function getSignature() |
271 | function getSignature() |
272 | {
|
272 | {
|
273 | if (empty($this->extra)) { |
273 | if (empty($this->extra)) { |
274 | return "{$this->sysname}-{$this->release}-{$this->cpu}"; |
274 | return "{$this->sysname}-{$this->release}-{$this->cpu}"; |
275 | }
|
275 | }
|
276 | return "{$this->sysname}-{$this->release}-{$this->cpu}-{$this->extra}"; |
276 | return "{$this->sysname}-{$this->release}-{$this->cpu}-{$this->extra}"; |
277 | }
|
277 | }
|
278 | 278 | ||
279 | function getSysname() |
279 | function getSysname() |
280 | {
|
280 | {
|
281 | return $this->sysname; |
281 | return $this->sysname; |
282 | }
|
282 | }
|
283 | 283 | ||
284 | function getNodename() |
284 | function getNodename() |
285 | {
|
285 | {
|
286 | return $this->nodename; |
286 | return $this->nodename; |
287 | }
|
287 | }
|
288 | 288 | ||
289 | function getCpu() |
289 | function getCpu() |
290 | {
|
290 | {
|
291 | return $this->cpu; |
291 | return $this->cpu; |
292 | }
|
292 | }
|
293 | 293 | ||
294 | function getRelease() |
294 | function getRelease() |
295 | {
|
295 | {
|
296 | return $this->release; |
296 | return $this->release; |
297 | }
|
297 | }
|
298 | 298 | ||
299 | function getExtra() |
299 | function getExtra() |
300 | {
|
300 | {
|
301 | return $this->extra; |
301 | return $this->extra; |
302 | }
|
302 | }
|
303 | 303 | ||
304 | function matchSignature($match) |
304 | function matchSignature($match) |
305 | {
|
305 | {
|
306 | if (is_array($match)) { |
306 | if (is_array($match)) { |
307 | $fragments = $match; |
307 | $fragments = $match; |
308 | } else { |
308 | } else { |
309 | $fragments = explode('-', $match); |
309 | $fragments = explode('-', $match); |
310 | }
|
310 | }
|
311 | $n = count($fragments); |
311 | $n = count($fragments); |
312 | $matches = 0; |
312 | $matches = 0; |
313 | if ($n > 0) { |
313 | if ($n > 0) { |
314 | $matches += $this->_matchFragment($fragments[0], $this->sysname); |
314 | $matches += $this->_matchFragment($fragments[0], $this->sysname); |
315 | }
|
315 | }
|
316 | if ($n > 1) { |
316 | if ($n > 1) { |
317 | $matches += $this->_matchFragment($fragments[1], $this->release); |
317 | $matches += $this->_matchFragment($fragments[1], $this->release); |
318 | }
|
318 | }
|
319 | if ($n > 2) { |
319 | if ($n > 2) { |
320 | $matches += $this->_matchFragment($fragments[2], $this->cpu); |
320 | $matches += $this->_matchFragment($fragments[2], $this->cpu); |
321 | }
|
321 | }
|
322 | if ($n > 3) { |
322 | if ($n > 3) { |
323 | $matches += $this->_matchFragment($fragments[3], $this->extra); |
323 | $matches += $this->_matchFragment($fragments[3], $this->extra); |
324 | }
|
324 | }
|
325 | return ($matches == $n); |
325 | return ($matches == $n); |
326 | }
|
326 | }
|
327 | 327 | ||
328 | function _matchFragment($fragment, $value) |
328 | function _matchFragment($fragment, $value) |
329 | {
|
329 | {
|
330 | if (strcspn($fragment, '*?') < strlen($fragment)) { |
330 | if (strcspn($fragment, '*?') < strlen($fragment)) { |
331 | $reg = '^' . str_replace(array('*', '?', '/'), array('.*', '.', '\\/'), $fragment) . '$'; |
331 | $reg = '^' . str_replace(array('*', '?', '/'), array('.*', '.', '\\/'), $fragment) . '$'; |
332 | return eregi($reg, $value); |
332 | return eregi($reg, $value); |
333 | }
|
333 | }
|
334 | return ($fragment == '*' || !strcasecmp($fragment, $value)); |
334 | return ($fragment == '*' || !strcasecmp($fragment, $value)); |
335 | }
|
335 | }
|
336 | 336 | ||
337 | }
|
337 | }
|
338 | /*
|
338 | /*
|
339 | * Local Variables:
|
339 | * Local Variables:
|
340 | * indent-tabs-mode: nil
|
340 | * indent-tabs-mode: nil
|
341 | * c-basic-offset: 4
|
341 | * c-basic-offset: 4
|
342 | * End:
|
342 | * End:
|
343 | */
|
343 | */
|
344 | ?>
|
344 | ?>
|
345 | 345 |