vtiger /modules/System/includes/os/class.Darwin.inc.php

Language PHP Lines 238
MD5 Hash 8d915432142299fab2019fa4cc33e37e Estimated Cost $4,126 (why?)
Repository https://bitbucket.org/yousef_fadila/vtiger.git View Raw File View Project SPDX
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
<?php 

// phpSysInfo - A PHP System Information Script
// http://phpsysinfo.sourceforge.net/

// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

// $Id: class.Darwin.inc.php,v 1.26 2006/04/15 21:42:20 bigmichi1 Exp $
if (!defined('IN_PHPSYSINFO')) {
    die("No Hacking");
}

require_once(APP_ROOT . '/includes/os/class.BSD.common.inc.php');

$error->addError("WARN", "The Darwin version of phpSysInfo is work in progress, some things currently don't work");

class sysinfo extends bsd_common {
  var $cpu_regexp;
  var $scsi_regexp; 
  // Our contstructor
  // this function is run on the initialization of this class
  function sysinfo () {
    // $this->cpu_regexp = "CPU: (.*) \((.*)-MHz (.*)\)";
    // $this->scsi_regexp1 = "^(.*): <(.*)> .*SCSI.*device";
    $this->cpu_regexp2 = "/(.*) ([0-9]+) ([0-9]+) ([0-9]+) ([0-9]+)/";
  } 

  function grab_key ($key) {
    $s = execute_program('sysctl', $key);
    $s = ereg_replace($key . ': ', '', $s);
    $s = ereg_replace($key . ' = ', '', $s); // fix Apple set keys
    
    return $s;
  } 

  function grab_ioreg ($key) {
    $s = execute_program('ioreg', '-cls "' . $key . '" | grep "' . $key . '"'); //ioreg -cls "$key" | grep "$key"
    $s = ereg_replace('\|', '', $s);
    $s = ereg_replace('\+\-\o', '', $s);
    $s = ereg_replace('[ ]+', '', $s);
    $s = ereg_replace('<[^>]+>', '', $s); // remove possible XML conflicts

    return $s;
  } 

  function get_sys_ticks () {
    $a = execute_program('sysctl', '-n kern.boottime'); // get boottime (value in seconds) 
    $sys_ticks = time() - $a;

    return $sys_ticks;
  } 

  function cpu_info () {
    $results = array(); 
    // $results['model'] = $this->grab_key('hw.model'); // need to expand this somehow...
    // $results['model'] = $this->grab_key('hw.machine');
    $results['model'] = ereg_replace('Processor type: ', '', execute_program('hostinfo', '| grep "Processor type"')); // get processor type
    $results['cpus'] = $this->grab_key('hw.ncpu');
    $results['cpuspeed'] = round($this->grab_key('hw.cpufrequency') / 1000000); // return cpu speed - Mhz
    $results['busspeed'] = round($this->grab_key('hw.busfrequency') / 1000000); // return bus speed - Mhz
    $results['cache'] = round($this->grab_key('hw.l2cachesize') / 1024); // return l2 cache

    if (($this->grab_key('hw.model') == "PowerMac3,6") && ($results['cpus'] == "2")) { $results['model'] = 'Dual G4 - (PowerPC 7450)';} // is Dual G4
    if (($this->grab_key('hw.model') == "PowerMac7,2") && ($results['cpus'] == "2")) { $results['model'] = 'Dual G5 - (PowerPC 970)';} // is Dual G5

    return $results;
  } 
  // get the pci device information out of ioreg
  function pci () {
    $results = array();
    $s = $this->grab_ioreg('IOPCIDevice');

    $lines = split("\n", $s);
    for ($i = 0, $max = sizeof($lines); $i < $max; $i++) {
      $ar_buf = preg_split("/\s+/", $lines[$i], 19);
      $results[$i] = $ar_buf[0];
    } 
    asort($results);
    return array_values(array_unique($results));
  } 
  // get the ide device information out of ioreg
  function ide () {
    $results = array(); 
    // ioreg | grep "Media  <class IOMedia>"
    $s = $this->grab_ioreg('IOATABlockStorageDevice'); 

    $lines = split("\n", $s);
    $j = 0;
    for ($i = 0, $max = sizeof($lines); $i < $max; $i++) {
      $ar_buf = preg_split("/\/\//", $lines[$i], 19);

      if ($ar_buf[1] == 'class IOMedia' && preg_match('/Media/', $ar_buf[0])) {
        $results[$j++]['model'] = $ar_buf[0];
      } 
    } 
    asort($results);
    return array_values(array_unique($results));
  } 

  function memory () {
    $s = $this->grab_key('hw.memsize');

    $results['ram'] = array();

    $pstat = execute_program('vm_stat'); // use darwin's vm_stat
    $lines = split("\n", $pstat);
    for ($i = 0, $max = sizeof($lines); $i < $max; $i++) {
      $ar_buf = preg_split("/\s+/", $lines[$i], 19);

      if ($i == 1) {
        $results['ram']['free'] = $ar_buf[2] * 4; // calculate free memory from page sizes (each page = 4MB)
      } 
    } 

    $results['ram']['total'] = $s / 1024;
    $results['ram']['shared'] = 0;
    $results['ram']['buffers'] = 0;
    $results['ram']['used'] = $results['ram']['total'] - $results['ram']['free'];
    $results['ram']['cached'] = 0;
    $results['ram']['t_used'] = $results['ram']['used'];
    $results['ram']['t_free'] = $results['ram']['free'];

    $results['ram']['percent'] = round(($results['ram']['used'] * 100) / $results['ram']['total']); 
    // need to fix the swap info...
    $pstat = execute_program('swapinfo', '-k');
    $lines = split("\n", $pstat);

    for ($i = 0, $max = sizeof($lines); $i < $max; $i++) {
      $ar_buf = preg_split("/\s+/", $lines[$i], 6);

      if ($i == 0) {
        $results['swap']['total'] = 0;
        $results['swap']['used'] = 0;
        $results['swap']['free'] = 0;
      } else {
        $results['swap']['total'] = $results['swap']['total'] + $ar_buf[1];
        $results['swap']['used'] = $results['swap']['used'] + $ar_buf[2];
        $results['swap']['free'] = $results['swap']['free'] + $ar_buf[3];
      } 
    } 
    $results['swap']['percent'] = round(($results['swap']['used'] * 100) / $results['swap']['total']);

    return $results;
  } 

  function network () {
    $netstat = execute_program('netstat', '-nbdi | cut -c1-24,42- | grep Link');
    $lines = split("\n", $netstat);
    $results = array();
    for ($i = 0, $max = sizeof($lines); $i < $max; $i++) {
      $ar_buf = preg_split("/\s+/", $lines[$i]);
      if (!empty($ar_buf[0])) {
        $results[$ar_buf[0]] = array();

        $results[$ar_buf[0]]['rx_bytes'] = $ar_buf[5];
        $results[$ar_buf[0]]['rx_packets'] = $ar_buf[3];
        $results[$ar_buf[0]]['rx_errs'] = $ar_buf[4];
        $results[$ar_buf[0]]['rx_drop'] = $ar_buf[10];

        $results[$ar_buf[0]]['tx_bytes'] = $ar_buf[8];
        $results[$ar_buf[0]]['tx_packets'] = $ar_buf[6];
        $results[$ar_buf[0]]['tx_errs'] = $ar_buf[7];
        $results[$ar_buf[0]]['tx_drop'] = $ar_buf[10];

        $results[$ar_buf[0]]['errs'] = $ar_buf[4] + $ar_buf[7];
        $results[$ar_buf[0]]['drop'] = $ar_buf[10];
      } 
    } 
    return $results;
  } 

  function filesystems () {
    $df = execute_program('df', '-k');
    $mounts = split("\n", $df);
    $fstype = array();

    $s = execute_program('mount');
    $lines = explode("\n", $s);

    $i = 0;
    while (list(, $line) = each($lines)) {
      ereg('(.*) \((.*)\)', $line, $a);

      $m = explode(' ', $a[0]);
      $fsdev[$m[0]] = $a[2];
    } 

    for ($i = 1, $j = 0, $max = sizeof($mounts); $i < $max; $i++) {
      $ar_buf = preg_split("/\s+/", $mounts[$i], 6);

      switch ($ar_buf[0]) {
        case 'automount': // skip the automount entries
        case 'devfs': // skip the dev filesystem
        case 'fdesc': // skip the fdesc
        case 'procfs': // skip the proc filesystem
        case '<volfs>': // skip the vol filesystem
          continue 2;
          break;
      } 
      if (hide_mount($ar_buf[5])) {
        continue;
      }													

      $results[$j] = array();

      $results[$j]['disk'] = $ar_buf[0];
      $results[$j]['size'] = $ar_buf[1];
      $results[$j]['used'] = $ar_buf[2];
      $results[$j]['free'] = $ar_buf[3];
      $results[$j]['percent'] = $ar_buf[4];
      $results[$j]['mount'] = $ar_buf[5];
      ($fstype[$ar_buf[5]]) ? $results[$j]['fstype'] = $fstype[$ar_buf[5]] : $results[$j]['fstype'] = $fsdev[$ar_buf[0]];
      $j++;
    } 
    return $results;
  } 
  
  function distroicon () {
    $result = 'Darwin.png';
    return($result);
  }

} 

?>
Back to Top