|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Basic OS Class |
|
4
|
|
|
* |
|
5
|
|
|
* PHP version 5 |
|
6
|
|
|
* |
|
7
|
|
|
* @category PHP |
|
8
|
|
|
* @package PSI OS class |
|
9
|
|
|
* @author Michael Cramer <[email protected]> |
|
10
|
|
|
* @copyright 2009 phpSysInfo |
|
11
|
|
|
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License |
|
12
|
|
|
* @version SVN: $Id: class.OS.inc.php 699 2012-09-15 11:57:13Z namiltd $ |
|
13
|
|
|
* @link http://phpsysinfo.sourceforge.net |
|
14
|
|
|
*/ |
|
15
|
|
|
/** |
|
16
|
|
|
* Basic OS functions for all OS classes |
|
17
|
|
|
* |
|
18
|
|
|
* @category PHP |
|
19
|
|
|
* @package PSI OS class |
|
20
|
|
|
* @author Michael Cramer <[email protected]> |
|
21
|
|
|
* @copyright 2009 phpSysInfo |
|
22
|
|
|
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License |
|
23
|
|
|
* @version Release: 3.0 |
|
24
|
|
|
* @link http://phpsysinfo.sourceforge.net |
|
25
|
|
|
*/ |
|
26
|
|
|
abstract class OS implements PSI_Interface_OS |
|
|
|
|
|
|
27
|
|
|
{ |
|
28
|
|
|
/** |
|
29
|
|
|
* object for error handling |
|
30
|
|
|
* |
|
31
|
|
|
* @var Error |
|
32
|
|
|
*/ |
|
33
|
|
|
protected $error; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @var System |
|
37
|
|
|
*/ |
|
38
|
|
|
protected $sys; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* build the global Error object |
|
42
|
|
|
*/ |
|
43
|
|
|
public function __construct() |
|
44
|
|
|
{ |
|
45
|
|
|
$this->error = PSI_Error::singleton(); |
|
|
|
|
|
|
46
|
|
|
$this->sys = new System(); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* get os specific encoding |
|
51
|
|
|
* |
|
52
|
|
|
* @see PSI_Interface_OS::getEncoding() |
|
53
|
|
|
* |
|
54
|
|
|
* @return string |
|
55
|
|
|
*/ |
|
56
|
|
|
public function getEncoding() |
|
57
|
|
|
{ |
|
58
|
|
|
return PSI_SYSTEM_CODEPAGE; |
|
59
|
|
|
} |
|
60
|
|
|
/** |
|
61
|
|
|
* get os specific language |
|
62
|
|
|
* |
|
63
|
|
|
* @see PSI_Interface_OS::getLanguage() |
|
64
|
|
|
* |
|
65
|
|
|
* @return string |
|
66
|
|
|
*/ |
|
67
|
|
|
public function getLanguage() |
|
68
|
|
|
{ |
|
69
|
|
|
return PSI_SYSTEM_LANG; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* Number of Users |
|
74
|
|
|
* |
|
75
|
|
|
* @return void |
|
76
|
|
|
*/ |
|
77
|
|
|
protected function _users() |
|
78
|
|
|
{ |
|
79
|
|
|
if (CommonFunctions::executeProgram('who', '', $strBuf, PSI_DEBUG)) { |
|
80
|
|
|
if (strlen($strBuf) > 0) { |
|
81
|
|
|
$lines = preg_split('/\n/', $strBuf); |
|
82
|
|
|
$this->sys->setUsers(count($lines)); |
|
83
|
|
|
} |
|
84
|
|
|
} elseif (CommonFunctions::executeProgram('uptime', '', $buf, PSI_DEBUG) && preg_match("/,\s+(\d+)\s+user[s]?,/", $buf, $ar_buf)) { |
|
85
|
|
|
//} elseif (CommonFunctions::executeProgram('uptime', '', $buf) && preg_match("/,\s+(\d+)\s+user[s]?,\s+load average[s]?:\s+(.*),\s+(.*),\s+(.*)$/", $buf, $ar_buf)) { |
|
|
|
|
|
|
86
|
|
|
$this->sys->setUsers($ar_buf[1]); |
|
87
|
|
|
} else { |
|
88
|
|
|
$processlist = glob('/proc/*/cmdline', GLOB_NOSORT); |
|
89
|
|
|
if (($total = count($processlist)) > 0) { |
|
90
|
|
|
$count = 0; |
|
91
|
|
|
$buf = ""; |
|
92
|
|
|
for ($i = 0; $i < $total; $i++) { |
|
93
|
|
|
if (CommonFunctions::rfts($processlist[$i], $buf, 0, 4096, false)) { |
|
94
|
|
|
$name = str_replace(chr(0), ' ', trim($buf)); |
|
95
|
|
|
if (preg_match("/^-/", $name)) { |
|
96
|
|
|
$count++; |
|
97
|
|
|
} |
|
98
|
|
|
} |
|
99
|
|
|
} |
|
100
|
|
|
if ($count > 0) { |
|
101
|
|
|
$this->sys->setUsers($count); |
|
102
|
|
|
} |
|
103
|
|
|
} |
|
104
|
|
|
} |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
/** |
|
108
|
|
|
* IP of the Host |
|
109
|
|
|
* |
|
110
|
|
|
* @return void |
|
111
|
|
|
*/ |
|
112
|
|
|
protected function _ip() |
|
113
|
|
|
{ |
|
114
|
|
|
if (PSI_USE_VHOST === true) { |
|
115
|
|
|
if ((($result = getenv('SERVER_ADDR')) || ($result = getenv('LOCAL_ADDR'))) //is server address defined |
|
116
|
|
|
&& !strstr($result, '.') && strstr($result, ':')){ //is IPv6, quick version of preg_match('/\(([[0-9A-Fa-f\:]+)\)/', $result) |
|
117
|
|
|
$dnsrec = dns_get_record($this->sys->getHostname(), DNS_AAAA); |
|
118
|
|
|
if (isset($dnsrec[0]['ipv6'])) { //is DNS IPv6 record |
|
119
|
|
|
$this->sys->setIp($dnsrec[0]['ipv6']); //from DNS (avoid IPv6 NAT translation) |
|
120
|
|
|
} else { |
|
121
|
|
|
$this->sys->setIp(preg_replace('/^::ffff:/i', '', $result)); //from SERVER_ADDR or LOCAL_ADDR |
|
122
|
|
|
} |
|
123
|
|
|
} else { |
|
124
|
|
|
$this->sys->setIp(gethostbyname($this->sys->getHostname())); //IPv4 only |
|
125
|
|
|
} |
|
126
|
|
|
} else { |
|
127
|
|
|
if (($result = getenv('SERVER_ADDR')) || ($result = getenv('LOCAL_ADDR'))) { |
|
128
|
|
|
$this->sys->setIp(preg_replace('/^::ffff:/i', '', $result)); |
|
129
|
|
|
} else { |
|
130
|
|
|
$this->sys->setIp(gethostbyname($this->sys->getHostname())); |
|
131
|
|
|
} |
|
132
|
|
|
} |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
/** |
|
136
|
|
|
* get the filled or unfilled (with default values) System object |
|
137
|
|
|
* |
|
138
|
|
|
* @see PSI_Interface_OS::getSys() |
|
139
|
|
|
* |
|
140
|
|
|
* @return System |
|
141
|
|
|
*/ |
|
142
|
|
|
final public function getSys() |
|
143
|
|
|
{ |
|
144
|
|
|
$this->build(); |
|
145
|
|
|
$this->_ip(); |
|
146
|
|
|
|
|
147
|
|
|
return $this->sys; |
|
148
|
|
|
} |
|
149
|
|
|
} |
|
150
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.