~josephjamesmills/zpanelcp/zpanelcp

« back to all changes in this revision

Viewing changes to backups/zpanelx-10-zpanelx/etc/apps/phpsysinfo/includes/os/class.SunOS.inc.php

  • Committer: Joseph Mills
  • Date: 2012-05-12 06:38:23 UTC
  • Revision ID: josephjamesmills@gmail.com-20120512063823-nnb5w44xdkkbg8ds
made new framework and got ride of the backupfiles fixed amny of the bugs or tried too at least. added steps tpwards making ssl by default. Fixed apache virtual host files and moved to the right area. fixed all things too go under /var/www. and not /etc/. changed all the persission so that no one can read all files.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<?php 
2
 
/**
3
 
 * SunOS System Class
4
 
 *
5
 
 * PHP version 5
6
 
 *
7
 
 * @category  PHP
8
 
 * @package   PSI_OS
9
 
 * @author    Michael Cramer <BigMichi1@users.sourceforge.net>
10
 
 * @copyright 2009 phpSysInfo
11
 
 * @license   http://opensource.org/licenses/gpl-2.0.php GNU General Public License
12
 
 * @version   SVN: $Id: class.SunOS.inc.php 287 2009-06-26 12:11:59Z bigmichi1 $
13
 
 * @link      http://phpsysinfo.sourceforge.net
14
 
 */
15
 
 /**
16
 
 * SunOS sysinfo class
17
 
 * get all the required information from SunOS systems
18
 
 *
19
 
 * @category  PHP
20
 
 * @package   PSI_OS
21
 
 * @author    Michael Cramer <BigMichi1@users.sourceforge.net>
22
 
 * @copyright 2009 phpSysInfo
23
 
 * @license   http://opensource.org/licenses/gpl-2.0.php GNU General Public License
24
 
 * @version   Release: 3.0
25
 
 * @link      http://phpsysinfo.sourceforge.net
26
 
 */
27
 
class SunOS extends OS
28
 
{
29
 
    /**
30
 
     * add warning to errors
31
 
     */
32
 
    public function __construct()
33
 
    {
34
 
        $this->error->addError("WARN", "The SunOS version of phpSysInfo is work in progress, some things currently don't work");
35
 
    }
36
 
    
37
 
    /**
38
 
     * Extract kernel values via kstat() interface
39
 
     *
40
 
     * @param string $key key for kstat programm
41
 
     *
42
 
     * @return string
43
 
     */
44
 
    private function _kstat($key)
45
 
    {
46
 
        if (CommonFunctions::executeProgram('kstat', '-p d '.$key, $m, PSI_DEBUG)) {
47
 
            list($key, $value) = preg_split("/\t/", trim($m), 2);
48
 
            return $value;
49
 
        } else {
50
 
            return '';
51
 
        }
52
 
    }
53
 
    
54
 
    /**
55
 
     * Virtual Host Name
56
 
     *
57
 
     * @return void
58
 
     */
59
 
    private function _hostname()
60
 
    {
61
 
        if (PSI_USE_VHOST === true) {
62
 
            $this->sys->setHostname(getenv('SERVER_NAME'));
63
 
        } else {
64
 
            if (CommonFunctions::executeProgram('uname', '-n', $result, PSI_DEBUG)) {
65
 
                $ip = gethostbyname($result);
66
 
                if ($ip != $result) {
67
 
                    $this->sys->setHostname(gethostbyaddr($ip));
68
 
                }
69
 
            }
70
 
        }
71
 
    }
72
 
    
73
 
    /**
74
 
     * IP of the Virtual Host Name
75
 
     *
76
 
     *  @return void
77
 
     */
78
 
    private function _ip()
79
 
    {
80
 
        if (PSI_USE_VHOST === true) {
81
 
            $this->sys->setIp(gethostbyname($this->_hostname()));
82
 
        } else {
83
 
            if (!($result = getenv('SERVER_ADDR'))) {
84
 
                $this->sys->setIp(gethostbyname($this->_hostname()));
85
 
            } else {
86
 
                $this->sys->setIp($result);
87
 
            }
88
 
        }
89
 
    }
90
 
    
91
 
    /**
92
 
     * Kernel Version
93
 
     *
94
 
     * @return void
95
 
     */
96
 
    private function _kernel()
97
 
    {
98
 
        if (CommonFunctions::executeProgram('uname', '-s', $os, PSI_DEBUG)) {
99
 
            if (CommonFunctions::executeProgram('uname', '-r', $version, PSI_DEBUG)) {
100
 
                $this->sys->setKernel($os.' '.$version);
101
 
            } else {
102
 
                $this->sys->setKernel($os);
103
 
            }
104
 
        }
105
 
    }
106
 
    
107
 
    /**
108
 
     * UpTime
109
 
     * time the system is running
110
 
     *
111
 
     * @return void
112
 
     */
113
 
    private function _uptime()
114
 
    {
115
 
        $this->sys->setUptime(time() - $this->_kstat('unix:0:system_misc:boot_time'));
116
 
    }
117
 
    
118
 
    /**
119
 
     * Number of Users
120
 
     *
121
 
     * @return void
122
 
     */
123
 
    private function _users()
124
 
    {
125
 
        if (CommonFunctions::executeProgram('who', '-q', $buf, PSI_DEBUG)) {
126
 
            $who = preg_split('/=/', $buf);
127
 
            $this->sys->setUsers($who[1]);
128
 
        }
129
 
    }
130
 
    
131
 
    /**
132
 
     * Processor Load
133
 
     * optionally create a loadbar
134
 
     *
135
 
     * @return void
136
 
     */
137
 
    private function _loadavg()
138
 
    {
139
 
        $load1 = $this->_kstat('unix:0:system_misc:avenrun_1min');
140
 
        $load5 = $this->_kstat('unix:0:system_misc:avenrun_5min');
141
 
        $load15 = $this->_kstat('unix:0:system_misc:avenrun_15min');
142
 
        $this->sys->setLoad(round($load1 / 256, 2).' '.round($load5 / 256, 2).' '.round($load15 / 256, 2));
143
 
    }
144
 
    
145
 
    /**
146
 
     * CPU information
147
 
     *
148
 
     * @return void
149
 
     */
150
 
    private function _cpuinfo()
151
 
    {
152
 
        $dev = new CpuDevice();
153
 
        if (CommonFunctions::executeProgram('uname', '-i', $buf, PSI_DEBUG)) {
154
 
            $dev->setModel(trim($buf));
155
 
        }
156
 
        $dev->setCpuSpeed($this->_kstat('cpu_info:0:cpu_info0:clock_MHz'));
157
 
        $dev->setCache($this->_kstat('cpu_info:0:cpu_info0:cpu_type') * 1024);
158
 
        $this->sys->setCpus($dev);
159
 
    }
160
 
    
161
 
    /**
162
 
     * Network devices
163
 
     *
164
 
     * @return void
165
 
     */
166
 
    private function _network()
167
 
    {
168
 
        if (CommonFunctions::executeProgram('netstat', '-ni | awk \'(NF ==10){print;}\'', $netstat, PSI_DEBUG)) {
169
 
            $lines = preg_split("/\n/", $netstat, -1, PREG_SPLIT_NO_EMPTY);
170
 
            foreach ($lines as $line) {
171
 
                $ar_buf = preg_split("/\s+/", $line);
172
 
                if (! empty($ar_buf[0]) && $ar_buf[0] !== 'Name') {
173
 
                    $dev = new NetDevice();
174
 
                    $dev->setName($ar_buf[0]);
175
 
                    $results[$ar_buf[0]]['errs'] = $ar_buf[5] + $ar_buf[7];
176
 
                    preg_match('/^(\D+)(\d+)$/', $ar_buf[0], $intf);
177
 
                    $prefix = $intf[1].':'.$intf[2].':'.$intf[1].$intf[2].':';
178
 
                    $cnt = $this->_kstat($prefix.'drop');
179
 
                    if ($cnt > 0) {
180
 
                        $dev->setDrops($cnt);
181
 
                    }
182
 
                    $cnt = $this->_kstat($prefix.'obytes64');
183
 
                    if ($cnt > 0) {
184
 
                        $dev->setTxBytes($cnt);
185
 
                    }
186
 
                    $cnt = $this->_kstat($prefix.'rbytes64');
187
 
                    if ($cnt > 0) {
188
 
                        $dev->setRxBytes($cnt);
189
 
                    }
190
 
                    $this->sys->setNetDevices($dev);
191
 
                }
192
 
            }
193
 
        }
194
 
    }
195
 
    
196
 
    /**
197
 
     * Physical memory information and Swap Space information
198
 
     *
199
 
     * @return void
200
 
     */
201
 
    private function _memory()
202
 
    {
203
 
        $pagesize = $this->_kstat('unix:0:seg_cache:slab_size');
204
 
        $this->sys->setMemTotal($this->_kstat('unix:0:system_pages:pagestotal') * $pagesize);
205
 
        $this->sys->setMemUsed($this->_kstat('unix:0:system_pages:pageslocked') * $pagesize);
206
 
        $this->sys->setMemFree($this->_kstat('unix:0:system_pages:pagesfree') * $pagesize);
207
 
        $dev = new DiskDevice();
208
 
        $dev->setName('SWAP');
209
 
        $dev->setFsType('swap');
210
 
        $dev->setTotal($this->_kstat('unix:0:vminfo:swap_avail') / 1024);
211
 
        $dev->setUsed($this->_kstat('unix:0:vminfo:swap_alloc') / 1024);
212
 
        $dev->setFree($this->_kstat('unix:0:vminfo:swap_free') / 1024);
213
 
        $this->sys->setSwapDevices($dev);
214
 
    }
215
 
    
216
 
    /**
217
 
     * filesystem information
218
 
     *
219
 
     * @return void
220
 
     */
221
 
    private function _filesystems()
222
 
    {
223
 
        if (CommonFunctions::executeProgram('df', '-k', $df, PSI_DEBUG)) {
224
 
            $mounts = preg_split("/\n/", $df, -1, PREG_SPLIT_NO_EMPTY);
225
 
            foreach ($mounts as $mount) {
226
 
                $ar_buf = preg_split('/\s+/', $mount, 6);
227
 
                $dev = new DiskDevice();
228
 
                $dev->setName($ar_buf[0]);
229
 
                $dev->setTotal($ar_buf[1] * 1024);
230
 
                $dev->setUsed($ar_buf[2] * 1024);
231
 
                $dev->setFree($ar_buf[3] * 1024);
232
 
                $dev->setMountPoint($ar_buf[5]);
233
 
                if (CommonFunctions::executeProgram('df', '-n', $dftypes, PSI_DEBUG)) {
234
 
                    $mounttypes = preg_split("/\n/", $dftypes, -1, PREG_SPLIT_NO_EMPTY);
235
 
                    foreach ($mounttypes as $type) {
236
 
                        $ty_buf = preg_split('/:/', $type, 2);
237
 
                        if ($ty_buf == $dev->getName()) {
238
 
                            $dev->setFsType($ty_buf[1]);
239
 
                            break;
240
 
                        }
241
 
                    }
242
 
                }
243
 
                $this->sys->setDiskDevices($dev);
244
 
            }
245
 
        }
246
 
    }
247
 
    
248
 
    /**
249
 
     * Distribution Icon
250
 
     *
251
 
     * @return void
252
 
     */
253
 
    private function _distro()
254
 
    {
255
 
        $this->sys->setDistribution('SunOS');
256
 
        $this->sys->setDistributionIcon('SunOS.png');
257
 
    }
258
 
    
259
 
    /**
260
 
     * get the information
261
 
     *
262
 
     * @see PSI_Interface_OS::build()
263
 
     *
264
 
     * @return Void
265
 
     */
266
 
    function build()
267
 
    {
268
 
        $this->_ip();
269
 
        $this->_hostname();
270
 
        $this->_distro();
271
 
        $this->_kernel();
272
 
        $this->_uptime();
273
 
        $this->_users();
274
 
        $this->_loadavg();
275
 
        $this->_cpuinfo();
276
 
        $this->_network();
277
 
        $this->_memory();
278
 
        $this->_filesystems();
279
 
    }
280
 
}
281
 
?>