Subversion Repositories ALCASAR

Rev

Details | Last modification | View Log

Rev Author Line No. Line
3100 rexy 1
<?php
2
/**
3
 * GNU Class
4
 *
5
 * PHP version 5
6
 *
7
 * @category  PHP
8
 * @package   PSI GNU class
9
 * @author    Mieczyslaw Nalewaj <namiltd@users.sourceforge.net>
10
 * @copyright 2012 phpSysInfo
11
 * @license   http://opensource.org/licenses/gpl-2.0.php GNU General Public License version 2, or (at your option) any later version
12
 * @version   SVN: $Id: class.GNU.inc.php 687 2012-09-06 20:54:49Z namiltd $
13
 * @link      http://phpsysinfo.sourceforge.net
14
 */
15
 /**
16
 * GNU sysinfo class
17
 * get all the required information from GNU
18
 *
19
 * @category  PHP
20
 * @package   PSI GNU class
21
 * @author    Mieczyslaw Nalewaj <namiltd@users.sourceforge.net>
22
 * @copyright 2022 phpSysInfo
23
 * @license   http://opensource.org/licenses/gpl-2.0.php GNU General Public License version 2, or (at your option) any later version
24
 * @version   Release: 3.0
25
 * @link      http://phpsysinfo.sourceforge.net
26
 */
27
class GNU extends Linux
28
{
29
    /**
30
     * Network devices
31
     * includes also rx/tx bytes
32
     *
33
     * @return void
34
     */
35
    protected function _network($bufr = null)
36
    {
37
        if ($this->sys->getOS() == 'GNU') {
38
            if (CommonFunctions::executeProgram('ifconfig', '-a', $bufr, PSI_DEBUG)) {
39
                $lines = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
40
                $was = false;
41
                $macaddr = "";
42
                $dev = null;
43
                foreach ($lines as $line) {
44
                    if (preg_match("/^\/dev\/([^\s:]+)/", $line, $ar_buf) || preg_match("/^([^\s:]+)/", $line, $ar_buf)) {
45
                        if ($was) {
46
                            if ($macaddr != "") {
47
                                $dev->setInfo($macaddr.($dev->getInfo()?';'.$dev->getInfo():''));
48
                            }
49
                            $this->sys->setNetDevices($dev);
50
                        }
51
                        $macaddr = "";
52
                        $dev = new NetDevice();
53
                        $dev->setName($ar_buf[1]);
54
                        $was = true;
55
                    } else {
56
                        if ($was) {
57
                            if (defined('PSI_SHOW_NETWORK_INFOS') && (PSI_SHOW_NETWORK_INFOS)) {
58
                                if (preg_match('/^\s+inet address\s+(\S+)$/', $line, $ar_buf)) {
59
                                    $dev->setInfo($ar_buf[1]);
60
                                } elseif (preg_match('/^\s+hardware addr\s+(\S+)$/', $line, $ar_buf)) {
61
                                    if (!defined('PSI_HIDE_NETWORK_MACADDR') || !PSI_HIDE_NETWORK_MACADDR) {
62
                                        $macaddr = preg_replace('/:/', '-', strtoupper($ar_buf[1]));
63
                                        if ($macaddr === '00-00-00-00-00-00') { // empty
64
                                            $macaddr = "";
65
                                        }
66
                                    }
67
                                }
68
                            }
69
                        }
70
                    }
71
                }
72
                if ($was) {
73
                    if ($macaddr != "") {
74
                        $dev->setInfo($macaddr.($dev->getInfo()?';'.$dev->getInfo():''));
75
                    }
76
                    $this->sys->setNetDevices($dev);
77
                }
78
            }
79
        } else {
80
            parent::_network($bufr);
81
        }
82
    }
83
 
84
    /**
85
     * Number of Users
86
     *
87
     * @return void
88
     */
89
    protected function _users()
90
    {
91
        if ($this->sys->getOS() == 'GNU') {
92
            if (CommonFunctions::executeProgram('who', '', $strBuf, PSI_DEBUG)) {
93
                if (strlen($strBuf) > 0) {
94
                    $lines = preg_split('/\n/', $strBuf);
95
                    preg_match_all('/^login\s+/m', $strBuf, $ttybuf);
96
                    if (($who = count($lines)-count($ttybuf[0])) > 0) {
97
                        $this->sys->setUsers($who);
98
                    }
99
                }
100
            }
101
        } else {
102
            parent::_users();
103
        }
104
    }
105
 
106
     /**
107
     * get the information
108
     *
109
     * @return void
110
     */
111
    public function build()
112
    {
113
        if ($this->sys->getOS() == 'GNU') {
114
            $this->error->addWarning("The GNU Hurd version of phpSysInfo is a work in progress, some things currently don't work");
115
        }
116
        parent::build();
117
    }
118
}