1<?php 2class InfosServer 3{ 4 private $_osServer; 5 6 public function osServer() 7 { 8 return $this->_osServer; 9 } 10 11 public function setOsServer() 12 { 13 $this->_osServer = PHP_OS; 14 } 15 16 public function __construct() 17 { 18 $this->setOsServer(); 19 20 } 21 // Infos intermediaires CPU pour windows (car tps de chargement long) 22 public function getWinCpu() 23 { 24 exec("powershell -executionpolicy remotesigned -command gwmi win32_Processor name,DataWidth", $tmp); 25 return $tmp; 26 } 27 28 // Logo OS 29 public function getLogoOs() 30 { 31 $os = $this->osServer(); // OS installé 32 33 if ($os == 'Darwin') // Pour Macintosh 34 {$logo_os = "<img src='./lib/plugins/serverinfos/img/apple.jpg' width=100% alt='logo Apple' />";} 35 36 if ($os == 'FreeBSD') 37 {$logo_os = "<img src='./lib/plugins/serverinfos/img/freebsd.png' width=100% alt='logo Freebsd' />";} 38 39 if ($os == 'Linux') // Pour Linux 40 { 41 exec('lsb_release -ds', $distrib); 42 43 if (preg_match("#debian#i",$distrib[0])) 44 { 45 $logo_os = "<img src='./lib/plugins/serverinfos/img/debian.png' width=100% />"; 46 } 47 elseif (preg_match("#ubuntu#i",$distrib[0])) 48 { 49 $logo_os = "<img src='./lib/plugins/serverinfos/img/ubuntu.png' width=100% />"; 50 } 51 else 52 { 53 $logo_os = "<img src='./lib/plugins/serverinfos/img/linux.png' width=100% />"; 54 } 55 } 56 57 if ($os == "WINNT") 58 {$logo_os = "<img src='./lib/plugins/serverinfos/img/windows.jpg' width=100% />"; } 59 60 echo $logo_os; 61 } 62 63 // Nom du systeme 64 public function getSystem() 65 { 66 $os = $this->osServer(); // OS installé 67 68 if ($os == 'Darwin') // Pour Macintosh 69 { 70 exec("sw_vers", $os_type); 71 $os_tmp = explode('ProductName:',$os_type[0]); 72 $systeme = $os_tmp[1]; 73 } 74 75 if ($os == 'FreeBSD') 76 { 77 exec('uname -r', $distrib); 78 $systeme = $distrib[0]; 79 } 80 81 if ($os == 'Linux') // Pour Linux 82 { 83 exec('lsb_release -ds | cut -d" " -f1,3,4', $distrib); 84 $systeme = $distrib[0]; 85 } 86 87 if ($os == 'WINNT') 88 { 89 exec('powershell -executionpolicy remotesigned -command (gwmi -class Win32_OperatingSystem).Caption', $cpu_tmp64); 90 $exp = explode(' ', $cpu_tmp64[0],3); 91 $systeme = $exp[2]; 92 } 93 return $systeme; 94 } 95 96 // Version OS pour MAC 97 public function getMacVersion() 98 { 99 exec("sw_vers", $os_type); 100 $vos_tmp = explode('ProductVersion:',$os_type[1]); 101 $vos = $vos_tmp[1]; 102 103 return $vos; 104 } 105 106 // Modele MACINTOSH 107 public function getMacComputer() 108 { 109 exec("sysctl -n hw.model", $modelComputer); 110 return $modelComputer[0]; 111 } 112 113 // No Revision pour R-Pi 114 public function getRevisionPi() 115 { 116 $os = $this->osServer(); 117 $model_tmp = explode('@', $this->getTmp()); 118 119 if (preg_match("#arm#i",$model_tmp[0]) AND $os == 'Linux') 120 { 121 exec("sed -n '/^Revision/p' /proc/cpuinfo", $piTmp); 122 $tmp = explode(':', $piTmp[0]); 123 return $tmp[1]; 124 } 125 } 126 127 // Type de modele pour R-Pi 128 public function getModelPi($revision) 129 { 130 if (stristr($revision, "0002")) {$modelPi = 'R-Pi<br>Model B';} 131 if (stristr($revision, "0003")) {$modelPi = 'R-Pi<br>Model B<br>Fuses mode & D14 removed';} 132 if (stristr($revision, "0004")) {$modelPi = 'R-Pi<br>Model B<br>Made by Sony';} 133 if (stristr($revision, "0005")) {$modelPi = 'R-Pi<br>Model B<br>Made by Qisda';} 134 if (stristr($revision, "0006")) {$modelPi = 'R-Pi<br>Model B<br>Made by Egoman';} 135 if (stristr($revision, "0007")) {$modelPi = 'R-Pi<br>Model A<br>Made by Egoman';} 136 if (stristr($revision, "0008")) {$modelPi = 'R-Pi<br>Model A<br>Made by Sony';} 137 if (stristr($revision, "0009")) {$modelPi = 'R-Pi<br>Model A<br>Made by Qisda';} 138 if (stristr($revision, "000d")) {$modelPi = 'R-Pi<br>Model B<br>Made by Egoman';} 139 if (stristr($revision, "000e")) {$modelPi = 'R-Pi<br>Model B<br>Made by Sony';} 140 if (stristr($revision, "000f")) {$modelPi = 'R-Pi<br>Model B<br>Made by Qisda';} 141 if (stristr($revision, "0010")) {$modelPi = 'R-Pi<br>Model B+<br>Made by Sony';} 142 if (stristr($revision, "0011")) {$modelPi = 'R-Pi<br>Model CpM<br>Made by Sony';} 143 if (stristr($revision, "0012")) {$modelPi = 'R-Pi<br>Model A+<br>Made by Sony';} 144 if (stristr($revision, "0013")) {$modelPi = 'R-Pi<br>Model B+';} 145 if (stristr($revision, "a01041")) {$modelPi = 'R-Pi 2<br>Model B<br>Made by Sony';} 146 if (stristr($revision, "a21041")) {$modelPi = 'R-Pi 2<br>Model B<br>Made by Embest';} 147 if (stristr($revision, "900092")) {$modelPi = 'R-Pi Zero<br>Made by Sony';} 148 if (stristr($revision, "a02082")) {$modelPi = 'R-Pi 3<br>Model B<br>Made by Sony';} 149 if (stristr($revision, "a22082")) {$modelPi = 'R-Pi 3<br>Model B';} 150 return "<strong>".$modelPi."</strong>"; 151 } 152 153 // Recupere infos memoire 154 public function getRam() 155 { 156 $os = $this->osServer(); // OS installé 157 158 if ($os == 'Darwin') // Pour Macintosh 159 { 160 exec("sysctl -a hw.memsize", $tmp); 161 $memsize = explode(':', $tmp[0]); 162 $ram = $memsize[1]; 163 return round(($ram/1073741824), 2)."Go"; 164 } 165 166 if ($os == 'FreeBSD') 167 { 168 exec("dmesg | grep 'real memory' | cut -d'(' -f2 | cut -d' ' -f1", $ram); 169 return round(($ram[0]/1024), 2)."Go"; 170 } 171 172 if ($os == 'Linux') // Pour Linux 173 { 174 exec("free | grep 'Mem'", $tmpLinux); 175 $ram_tmp = explode('Mem:', $tmpLinux[0]); 176 $chaine = $ram_tmp[1]; 177 $chaine_preg = preg_replace('/\s{2,}/', ' ', $chaine); 178 $chaine_tmp = explode(' ',$chaine_preg); 179 $ram = $chaine_tmp[1]; 180 return round(($ram/1048576), 2)."Go"; 181 } 182 183 if ($os == 'WINNT') // Pour Windows 184 { 185 exec("powershell -executionpolicy remotesigned -command gwmi win32_computersystem", $tmpWin); 186 $exp = explode(':', $tmpWin[7]); 187 $ram = $exp[1]; 188 return round(($ram/1073741824), 2)."Go"; 189 } 190 } 191 192 // Variable temporaire pour CPU 193 public function getTmp() 194 { 195 $os = $this->osServer(); 196 if ($os == "Darwin") {exec("sysctl -n machdep.cpu.brand_string", $tmp);$cpu_tmp = $tmp[0];} 197 if ($os == "FreeBSD") {exec("sysctl hw.model | cut -d' ' -f2- ", $tmp);$cpu_tmp = $tmp[0];} 198 if ($os == "Linux") {exec("sed -n '/model name/p' /proc/cpuinfo | uniq", $tmp);$cpu_tmp = $tmp[0];} 199 if ($os == "WINNT") 200 { 201 $tmp = $this->getWinCpu(); 202 $exp = explode(':', $tmp[13]); 203 $cpu_tmp = $exp[1]; 204 } 205 206 return $cpu_tmp; 207 } 208 209 // CPU 64b 210 public function get64() 211 { 212 $os = $this->osServer(); 213 if ($os == "Darwin") 214 { 215 exec("sysctl -n hw.cpu64bit_capable", $cpu_tmp64); 216 $value64 = $cpu_tmp64[0]; 217 } 218 219 if ($os == "FreeBSD") 220 { 221 exec("getconf LONG_BIT", $cpu_tmp64); 222 if ($cpu_tmp64 == 64) {$value64 = 1;} 223 } 224 225 if ($os == "Linux") 226 { 227 exec("arch", $test64); 228 $cpu_tmp64 = explode('_', $test64[0]); 229 if ($cpu_tmp64[1] == 64) {$value64 = 1;} 230 } 231 232 if ($os == "WINNT") 233 { 234 $tmp = $this->getWinCpu(); 235 $cpu_tmp64 = explode(':', $tmp[12]); 236 if ($cpu_tmp64[1] == 64) {$value64 = 1;} 237 } 238 239 if ($value64 == 1) {$logo64 = "<img src='./lib/plugins/serverinfos/img/64b.png' width=100% />";} 240 ELSE {$logo64 = "<img src='./lib/plugins/serverinfos/img/32b.png' width=100% />";} 241 242 return $logo64; 243 } 244 245 // Marque du CPU 246 public function getMarkCpu() 247 { 248 $os = $this->osServer(); 249 $model_tmp = explode('@', $this->getTmp()); 250 $exp = explode('(TM)', $model_tmp[0]); 251 if ($os == "Darwin") {$mark = $exp[0];} 252 if ($os == "FreeBSD") {$mark = $exp[0];} 253 if ($os == "Linux") 254 { 255 if (preg_match("#arm#i",$model_tmp[0])) 256 { 257 $int = explode(':', $exp[0]); 258 $int2 = explode('Processor', $int[1]); 259 $mark = $int2[0]; 260 } 261 ELSE 262 { 263 $int = explode(':', $exp[0]); 264 $mark = $int[1]; 265 } 266 } 267 if ($os == "WINNT") {$mark = $exp[0];} 268 269 return $mark; 270 } 271 272 // Modele du CPU 273 public function getModelCpu() 274 { 275 $os = $this->osServer(); 276 $model_tmp = explode('@', $this->getTmp()); 277 278 if (preg_match("#arm#i",$model_tmp[0]) AND $os == 'Linux') 279 { 280 $int = explode(':', $model_tmp[0]); 281 $int2 = explode('Processor', $int[1]); 282 $modele = $int2[1]; 283 } 284 ELSE 285 { 286 $exp = explode('(TM)', $model_tmp[0]); 287 $modele = str_replace('CPU', '', $exp[1]); 288 } 289 290 return $modele; 291 } 292 293 // Frequence du CPU 294 public function getFreqCpu() 295 { 296 $os = $this->osServer(); 297 $model_tmp = explode('@', $this->getTmp()); 298 299 if (preg_match("#arm#i",$model_tmp[0]) AND $os == 'Linux') 300 { 301 exec("cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq", $tmp); 302 $frequence = ($tmp[0]/1000000)."GHz"; 303 } 304 ELSE {$frequence = $model_tmp[1];} 305 306 return $frequence; 307 } 308 309 // espace disque total 310 public function getDdTotal() 311 { 312 $os = $this->osServer(); // OS installé 313 $model_tmp = explode('@', $this->getTmp()); 314 $conv = 1073741824; 315 316 if ($os == "Darwin" || $os == "FreeBSD") 317 { 318 $data = disk_total_space("/"); 319 $total = round(($data)/$conv,2); 320 } 321 322 if ($os == "Linux") 323 { 324 $conv = 1044576; 325 exec("df --total | tail -1 | sed 's/ */ /g' | cut -d' ' -f2", $tmp_dd); 326 if (empty($tmp_dd[0])) {$tmp_dd[0] = disk_total_space("/");$conv = 1073741824;} 327 $total = round(($tmp_dd[0])/$conv,2); 328 } 329 330 if ($os == "WINNT") 331 { 332 $data = disk_total_space("c:/"); 333 $total = round(($data)/$conv,2); 334 } 335 return $total."Go"; 336 } 337 338 // espace disque libre 339 public function getDdFree() 340 { 341 $os = $this->osServer(); // OS installé 342 343 if ($os == "Darwin" || $os == "FreeBSD") 344 { 345 $data = disk_free_space("/"); 346 $conv = 1073741824; 347 $free = round(($data)/$conv,2); 348 } 349 350 if ($os == "Linux") 351 { 352 $conv = 1044576; 353 exec("df --total | tail -1 | sed 's/ */ /g' | cut -d' ' -f4", $tmp_dd); 354 if (empty($tmp_dd[0])) {$tmp_dd[0] = disk_free_space("/");$conv = 1073741824;} 355 $free = round(($tmp_dd[0])/$conv,2); 356 } 357 358 if ($os == "WINNT") 359 { 360 $data = disk_free_space("c:/"); 361 $conv = 1073741824; 362 $free = round(($data)/$conv,2); 363 } 364 return $free."Go"; 365 } 366 367 // espace disque occupé 368 public function getDdUsed() 369 { 370 $used = ($this->getDdTotal()) - ($this->getDdFree()); 371 return $used."Go"; 372 } 373 374 // Nom du serveur WEB 375 public function getWebServer() 376 { 377 $tmp_web = explode(" ", $_SERVER['SERVER_SOFTWARE']); 378 $webServer = $tmp_web[0]; 379 380 return $webServer; 381 } 382 383 // Version serveur php 384 public function getPhpVersion() 385 { 386 $tmp_php = explode("-", phpversion()); 387 $phpVersion = $tmp_php[0]; 388 389 return $phpVersion; 390 } 391} 392?> 393