Code Duplication    Length = 46-46 lines in 2 locations

phpsysinfo/includes/os/class.NetBSD.inc.php 1 location

@@ 60-105 (lines=46) @@
57
     *
58
     * @return void
59
     */
60
    private function _network()
61
    {
62
        CommonFunctions::executeProgram('netstat', '-nbdi | cut -c1-25,44- | grep "^[a-z]*[0-9][ \t].*Link"', $netstat_b);
63
        CommonFunctions::executeProgram('netstat', '-ndi | cut -c1-25,44- | grep "^[a-z]*[0-9][ \t].*Link"', $netstat_n);
64
        $lines_b = preg_split("/\n/", $netstat_b, -1, PREG_SPLIT_NO_EMPTY);
65
        $lines_n = preg_split("/\n/", $netstat_n, -1, PREG_SPLIT_NO_EMPTY);
66
        for ($i = 0, $max = sizeof($lines_b); $i < $max; $i++) {
67
            $ar_buf_b = preg_split("/\s+/", $lines_b[$i]);
68
            $ar_buf_n = preg_split("/\s+/", $lines_n[$i]);
69
            if (!empty($ar_buf_b[0]) && (!empty($ar_buf_n[3]) || ($ar_buf_n[3] === "0"))) {
70
                $dev = new NetDevice();
71
                $dev->setName($ar_buf_b[0]);
72
                $dev->setTxBytes($ar_buf_b[4]);
73
                $dev->setRxBytes($ar_buf_b[3]);
74
                $dev->setDrops($ar_buf_n[8]);
75
                $dev->setErrors($ar_buf_n[4] + $ar_buf_n[6]);
76
                if (defined('PSI_SHOW_NETWORK_INFOS') && (PSI_SHOW_NETWORK_INFOS) && (CommonFunctions::executeProgram('ifconfig', $ar_buf_b[0].' 2>/dev/null', $bufr2, PSI_DEBUG))) {
77
                    $speedinfo = "";
78
                    $bufe2 = preg_split("/\n/", $bufr2, -1, PREG_SPLIT_NO_EMPTY);
79
                    foreach ($bufe2 as $buf2) {
80
                        if (preg_match('/^\s+address:\s+(\S+)/i', $buf2, $ar_buf2))
81
                            $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').preg_replace('/:/', '-', strtoupper($ar_buf2[1])));
82
                        elseif (preg_match('/^\s+inet\s+(\S+)\s+netmask/i', $buf2, $ar_buf2))
83
                            $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$ar_buf2[1]);
84
                        elseif ((preg_match('/^\s+inet6\s+([^\s%]+)\s+prefixlen/i', $buf2, $ar_buf2)
85
                              || preg_match('/^\s+inet6\s+([^\s%]+)%\S+\s+prefixlen/i', $buf2, $ar_buf2))
86
                              && ($ar_buf2[1]!="::") && !preg_match('/^fe80::/i', $ar_buf2[1]))
87
                            $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').strtolower($ar_buf2[1]));
88
                        elseif (preg_match('/^\s+media:\s+/i', $buf2) && preg_match('/[\(\s](\d+)(G*)base/i', $buf2, $ar_buf2)) {
89
                            if (isset($ar_buf2[2]) && strtoupper($ar_buf2[2])=="G") {
90
                                $unit = "G";
91
                            } else {
92
                                $unit = "M";
93
                            }
94
                            if (preg_match('/\s(\S+)-duplex/i', $buf2, $ar_buf3))
95
                                $speedinfo = $ar_buf2[1].$unit.'b/s '.strtolower($ar_buf3[1]);
96
                            else
97
                                $speedinfo = $ar_buf2[1].$unit.'b/s';
98
                        }
99
                    }
100
                    if ($speedinfo != "") $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$speedinfo);
101
                }
102
                $this->sys->setNetDevices($dev);
103
            }
104
        }
105
    }
106
107
    /**
108
     * IDE information

phpsysinfo/includes/os/class.OpenBSD.inc.php 1 location

@@ 60-105 (lines=46) @@
57
     *
58
     * @return void
59
     */
60
    private function _network()
61
    {
62
        CommonFunctions::executeProgram('netstat', '-nbdi | cut -c1-25,44- | grep Link | grep -v \'* \'', $netstat_b, PSI_DEBUG);
63
        CommonFunctions::executeProgram('netstat', '-ndi | cut -c1-25,44- | grep Link | grep -v \'* \'', $netstat_n, PSI_DEBUG);
64
        $lines_b = preg_split("/\n/", $netstat_b, -1, PREG_SPLIT_NO_EMPTY);
65
        $lines_n = preg_split("/\n/", $netstat_n, -1, PREG_SPLIT_NO_EMPTY);
66
        for ($i = 0, $max = sizeof($lines_b); $i < $max; $i++) {
67
            $ar_buf_b = preg_split("/\s+/", $lines_b[$i]);
68
            $ar_buf_n = preg_split("/\s+/", $lines_n[$i]);
69
            if (!empty($ar_buf_b[0]) && (!empty($ar_buf_n[3]) || ($ar_buf_n[3] === "0"))) {
70
                $dev = new NetDevice();
71
                $dev->setName($ar_buf_b[0]);
72
                $dev->setTxBytes($ar_buf_b[4]);
73
                $dev->setRxBytes($ar_buf_b[3]);
74
                $dev->setErrors($ar_buf_n[4] + $ar_buf_n[6]);
75
                $dev->setDrops($ar_buf_n[8]);
76
                if (defined('PSI_SHOW_NETWORK_INFOS') && (PSI_SHOW_NETWORK_INFOS) && (CommonFunctions::executeProgram('ifconfig', $ar_buf_b[0].' 2>/dev/null', $bufr2, PSI_DEBUG))) {
77
                    $speedinfo = "";
78
                    $bufe2 = preg_split("/\n/", $bufr2, -1, PREG_SPLIT_NO_EMPTY);
79
                    foreach ($bufe2 as $buf2) {
80
                        if (preg_match('/^\s+lladdr\s+(\S+)/i', $buf2, $ar_buf2))
81
                            $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').preg_replace('/:/', '-', strtoupper($ar_buf2[1])));
82
                        elseif (preg_match('/^\s+inet\s+(\S+)\s+netmask/i', $buf2, $ar_buf2))
83
                            $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$ar_buf2[1]);
84
                        elseif ((preg_match('/^\s+inet6\s+([^\s%]+)\s+prefixlen/i', $buf2, $ar_buf2)
85
                              || preg_match('/^\s+inet6\s+([^\s%]+)%\S+\s+prefixlen/i', $buf2, $ar_buf2))
86
                              && ($ar_buf2[1]!="::") && !preg_match('/^fe80::/i', $ar_buf2[1]))
87
                            $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').strtolower($ar_buf2[1]));
88
                        elseif (preg_match('/^\s+media:\s+/i', $buf2) && preg_match('/[\(\s](\d+)(G*)base/i', $buf2, $ar_buf2)) {
89
                            if (isset($ar_buf2[2]) && strtoupper($ar_buf2[2])=="G") {
90
                                $unit = "G";
91
                            } else {
92
                                $unit = "M";
93
                            }
94
                            if (preg_match('/\s(\S+)-duplex/i', $buf2, $ar_buf3))
95
                                $speedinfo = $ar_buf2[1].$unit.'b/s '.strtolower($ar_buf3[1]);
96
                            else
97
                                $speedinfo = $ar_buf2[1].$unit.'b/s';
98
                        }
99
                    }
100
                    if ($speedinfo != "") $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$speedinfo);
101
                }
102
                $this->sys->setNetDevices($dev);
103
            }
104
        }
105
    }
106
107
    /**
108
     * IDE information