2019-10-08 20:07:38 +02:00
|
|
|
<?php
|
|
|
|
|
2021-08-03 16:20:08 +02:00
|
|
|
/**
|
2023-09-16 10:43:05 +02:00
|
|
|
* System info class
|
2021-08-03 16:20:08 +02:00
|
|
|
*
|
|
|
|
* @description System info class for RaspAP
|
|
|
|
* @author Bill Zimmerman <billzimmerman@gmail.com>
|
|
|
|
* @license https://github.com/raspap/raspap-webgui/blob/master/LICENSE
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace RaspAP\System;
|
|
|
|
|
|
|
|
class Sysinfo
|
|
|
|
{
|
|
|
|
public function hostname()
|
|
|
|
{
|
2020-03-24 19:48:35 +01:00
|
|
|
return shell_exec("hostname -f");
|
|
|
|
}
|
|
|
|
|
2021-08-03 16:20:08 +02:00
|
|
|
public function uptime()
|
|
|
|
{
|
2020-03-24 19:48:35 +01:00
|
|
|
$uparray = explode(" ", exec("cat /proc/uptime"));
|
|
|
|
$seconds = round($uparray[0], 0);
|
|
|
|
$minutes = $seconds / 60;
|
|
|
|
$hours = $minutes / 60;
|
|
|
|
$days = floor($hours / 24);
|
|
|
|
$hours = floor($hours - ($days * 24));
|
|
|
|
$minutes = floor($minutes - ($days * 24 * 60) - ($hours * 60));
|
|
|
|
$uptime= '';
|
|
|
|
if ($days != 0) {
|
2021-08-03 16:20:08 +02:00
|
|
|
$uptime .= $days . ' day' . (($days > 1)? 's ':' ');
|
2020-03-24 19:48:35 +01:00
|
|
|
}
|
|
|
|
if ($hours != 0) {
|
2021-08-03 16:20:08 +02:00
|
|
|
$uptime .= $hours . ' hour' . (($hours > 1)? 's ':' ');
|
2020-03-24 19:48:35 +01:00
|
|
|
}
|
|
|
|
if ($minutes != 0) {
|
|
|
|
$uptime .= $minutes . ' minute' . (($minutes > 1)? 's ':' ');
|
|
|
|
}
|
|
|
|
|
|
|
|
return $uptime;
|
|
|
|
}
|
|
|
|
|
2023-06-04 17:27:54 +02:00
|
|
|
public function systime()
|
|
|
|
{
|
|
|
|
$systime = exec("date");
|
|
|
|
return $systime;
|
|
|
|
}
|
|
|
|
|
2021-08-03 16:20:08 +02:00
|
|
|
public function usedMemory()
|
|
|
|
{
|
2022-02-20 08:59:43 +01:00
|
|
|
$used = shell_exec("free -m | awk 'NR==2{ total=$2 ; used=$3 } END { print used/total*100}'");
|
2023-09-03 09:46:50 +02:00
|
|
|
return floor(intval($used));
|
2020-03-24 19:48:35 +01:00
|
|
|
}
|
|
|
|
|
2021-08-03 16:20:08 +02:00
|
|
|
public function processorCount()
|
|
|
|
{
|
2020-03-24 19:48:35 +01:00
|
|
|
$procs = shell_exec("nproc --all");
|
|
|
|
return intval($procs);
|
|
|
|
}
|
|
|
|
|
2021-08-03 16:20:08 +02:00
|
|
|
public function loadAvg1Min()
|
|
|
|
{
|
2020-03-24 19:48:35 +01:00
|
|
|
$load = exec("awk '{print $1}' /proc/loadavg");
|
|
|
|
return floatval($load);
|
|
|
|
}
|
|
|
|
|
2021-08-03 16:20:08 +02:00
|
|
|
public function systemLoadPercentage()
|
|
|
|
{
|
2020-03-24 19:48:35 +01:00
|
|
|
return intval(($this->loadAvg1Min() * 100) / $this->processorCount());
|
|
|
|
}
|
|
|
|
|
2021-08-03 16:20:08 +02:00
|
|
|
public function systemTemperature()
|
|
|
|
{
|
2020-03-24 19:48:35 +01:00
|
|
|
$cpuTemp = file_get_contents("/sys/class/thermal/thermal_zone0/temp");
|
|
|
|
return number_format((float)$cpuTemp/1000, 1);
|
|
|
|
}
|
|
|
|
|
2021-08-03 16:20:08 +02:00
|
|
|
public function hostapdStatus()
|
|
|
|
{
|
2020-03-24 19:48:35 +01:00
|
|
|
exec('pidof hostapd | wc -l', $status);
|
|
|
|
return $status;
|
|
|
|
}
|
2020-02-01 12:06:41 +01:00
|
|
|
|
2022-06-08 19:21:50 +02:00
|
|
|
public function operatingSystem()
|
|
|
|
{
|
|
|
|
$os_desc = shell_exec("lsb_release -sd");
|
|
|
|
return $os_desc;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function kernelVersion()
|
|
|
|
{
|
|
|
|
$kernel = shell_exec("uname -r");
|
|
|
|
return $kernel;
|
|
|
|
}
|
2023-09-16 10:43:05 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Returns RPi Model and PCB Revision from Pi Revision Code (cpuinfo)
|
|
|
|
* @see http://www.raspberrypi-spy.co.uk/2012/09/checking-your-raspberry-pi-board-version/
|
|
|
|
*/
|
|
|
|
public function rpiRevision()
|
|
|
|
{
|
|
|
|
$revisions = array(
|
|
|
|
'0002' => 'Model B Revision 1.0',
|
|
|
|
'0003' => 'Model B Revision 1.0 + ECN0001',
|
|
|
|
'0004' => 'Model B Revision 2.0 (256 MB)',
|
|
|
|
'0005' => 'Model B Revision 2.0 (256 MB)',
|
|
|
|
'0006' => 'Model B Revision 2.0 (256 MB)',
|
|
|
|
'0007' => 'Model A',
|
|
|
|
'0008' => 'Model A',
|
|
|
|
'0009' => 'Model A',
|
|
|
|
'000d' => 'Model B Revision 2.0 (512 MB)',
|
|
|
|
'000e' => 'Model B Revision 2.0 (512 MB)',
|
|
|
|
'000f' => 'Model B Revision 2.0 (512 MB)',
|
|
|
|
'0010' => 'Model B+',
|
|
|
|
'0013' => 'Model B+',
|
|
|
|
'0011' => 'Compute Module',
|
|
|
|
'0012' => 'Model A+',
|
|
|
|
'a01041' => 'a01041',
|
|
|
|
'a21041' => 'a21041',
|
|
|
|
'900092' => 'PiZero 1.2',
|
|
|
|
'900093' => 'PiZero 1.3',
|
|
|
|
'9000c1' => 'PiZero W',
|
|
|
|
'a02082' => 'Pi 3 Model B',
|
|
|
|
'a22082' => 'Pi 3 Model B',
|
|
|
|
'a32082' => 'Pi 3 Model B',
|
|
|
|
'a52082' => 'Pi 3 Model B',
|
|
|
|
'a020d3' => 'Pi 3 Model B+',
|
|
|
|
'a220a0' => 'Compute Module 3',
|
|
|
|
'a020a0' => 'Compute Module 3',
|
|
|
|
'a02100' => 'Compute Module 3+',
|
|
|
|
'a03111' => 'Model 4B Revision 1.1 (1 GB)',
|
|
|
|
'b03111' => 'Model 4B Revision 1.1 (2 GB)',
|
|
|
|
'c03111' => 'Model 4B Revision 1.1 (4 GB)'
|
|
|
|
);
|
|
|
|
|
|
|
|
$cpuinfo_array = '';
|
|
|
|
exec('cat /proc/cpuinfo', $cpuinfo_array);
|
|
|
|
$info = preg_grep("/^Revision/", $cpuinfo_array);
|
|
|
|
$tmp = explode(':', array_pop($info));
|
|
|
|
$rev = trim(array_pop($tmp));
|
|
|
|
if (array_key_exists($rev, $revisions)) {
|
|
|
|
return $revisions[$rev];
|
|
|
|
} else {
|
|
|
|
exec('cat /proc/device-tree/model', $model);
|
|
|
|
if (isset($model[0])) {
|
|
|
|
return $model[0];
|
|
|
|
} else {
|
|
|
|
return 'Unknown Device';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-02-01 12:06:41 +01:00
|
|
|
}
|
2021-08-03 16:20:08 +02:00
|
|
|
|