From 542006d9231c8b10a53374681f4fb6f01332122c Mon Sep 17 00:00:00 2001 From: M_Viper Date: Sat, 25 Feb 2023 02:06:41 +0100 Subject: [PATCH] =?UTF-8?q?Dateien=20hochladen=20nach=20=E2=80=9Elibs?= =?UTF-8?q?=E2=80=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/cpu.php | 91 +++++++++++++++++++++++++++++++++ libs/disk.php | 52 +++++++++++++++++++ libs/last_login.php | 33 ++++++++++++ libs/load_average.php | 30 +++++++++++ libs/memory.php | 37 ++++++++++++++ libs/network.php | 115 ++++++++++++++++++++++++++++++++++++++++++ libs/ping.php | 30 +++++++++++ libs/server.php | 35 +++++++++++++ libs/services.php | 35 +++++++++++++ libs/swap.php | 32 ++++++++++++ libs/system.php | 71 ++++++++++++++++++++++++++ 11 files changed, 561 insertions(+) create mode 100644 libs/cpu.php create mode 100644 libs/disk.php create mode 100644 libs/last_login.php create mode 100644 libs/load_average.php create mode 100644 libs/memory.php create mode 100644 libs/network.php create mode 100644 libs/ping.php create mode 100644 libs/server.php create mode 100644 libs/services.php create mode 100644 libs/swap.php create mode 100644 libs/system.php diff --git a/libs/cpu.php b/libs/cpu.php new file mode 100644 index 0000000..9665c87 --- /dev/null +++ b/libs/cpu.php @@ -0,0 +1,91 @@ +get('cpu:enable_temperature')) +{ + if (exec('/usr/bin/sensors | grep -E "^(CPU Temp|Core 0)" | cut -d \'+\' -f2 | cut -d \'.\' -f1', $t)) + { + if (isset($t[0])) + $temp = $t[0].' °C'; + } + else + { + if (exec('cat /sys/class/thermal/thermal_zone0/temp', $t)) + { + $temp = round($t[0] / 1000).' °C'; + } + } +} + + +$datas = array( + 'model' => $model, + 'num_cores' => $num_cores, + 'frequency' => $frequency, + 'cache' => $cache, + 'bogomips' => $bogomips, + 'temp' => $temp, +); + +echo json_encode($datas); \ No newline at end of file diff --git a/libs/disk.php b/libs/disk.php new file mode 100644 index 0000000..f2b21cb --- /dev/null +++ b/libs/disk.php @@ -0,0 +1,52 @@ + 'N.A', + 'used' => 'N.A', + 'free' => 'N.A', + 'percent_used' => 0, + 'mount' => 'N.A', + 'filesystem' => 'N.A', + ); +} +else +{ + $mounted_points = array(); + $key = 0; + + foreach ($df as $mounted) + { + list($filesystem, $type, $total, $used, $free, $percent, $mount) = explode(',', $mounted); + + if (strpos($type, 'tmpfs') !== false && $Config->get('disk:show_tmpfs') === false) + continue; + + if (!in_array($mount, $mounted_points)) + { + $mounted_points[] = trim($mount); + + $datas[$key] = array( + 'total' => Misc::getSize($total * 1024), + 'used' => Misc::getSize($used * 1024), + 'free' => Misc::getSize($free * 1024), + 'percent_used' => trim($percent, '%'), + 'mount' => $mount, + ); + + if ($Config->get('disk:show_filesystem')) + $datas[$key]['filesystem'] = $filesystem; + } + + $key++; + } + +} + + +echo json_encode($datas); \ No newline at end of file diff --git a/libs/last_login.php b/libs/last_login.php new file mode 100644 index 0000000..4596e44 --- /dev/null +++ b/libs/last_login.php @@ -0,0 +1,33 @@ +get('last_login:enable')) +{ + if (!(exec('/usr/bin/lastlog --time 365 | /usr/bin/awk -F\' \' \'{ print $1";"$5, $4, $8, $6}\'', $users))) + { + $datas[] = array( + 'user' => 'N.A', + 'date' => 'N.A', + ); + } + else + { + $max = $Config->get('last_login:max'); + + for ($i = 1; $i < count($users) && $i <= $max; $i++) + { + list($user, $date) = explode(';', $users[$i]); + + $datas[] = array( + 'user' => $user, + 'date' => $date, + ); + } + } +} + +echo json_encode($datas); \ No newline at end of file diff --git a/libs/load_average.php b/libs/load_average.php new file mode 100644 index 0000000..09a2f3c --- /dev/null +++ b/libs/load_average.php @@ -0,0 +1,30 @@ + 100) + $v = 100; + return $v; + }, + $load_exp, + array_fill(0, 3, $cores) + ); +} + + +$datas = $load; + +echo json_encode($datas); \ No newline at end of file diff --git a/libs/memory.php b/libs/memory.php new file mode 100644 index 0000000..a4eda7b --- /dev/null +++ b/libs/memory.php @@ -0,0 +1,37 @@ + 0) + $percent_used = 100 - (round($free / $total * 100)); + + +$datas = array( + 'used' => Misc::getSize($used * 1024), + 'free' => Misc::getSize($free * 1024), + 'total' => Misc::getSize($total * 1024), + 'percent_used' => $percent_used, +); + +echo json_encode($datas); \ No newline at end of file diff --git a/libs/network.php b/libs/network.php new file mode 100644 index 0000000..c24fcd4 --- /dev/null +++ b/libs/network.php @@ -0,0 +1,115 @@ + array('ifconfig', '/sbin/ifconfig', '/usr/bin/ifconfig', '/usr/sbin/ifconfig'), + 'ip' => array('ip', '/bin/ip', '/sbin/ip', '/usr/bin/ip', '/usr/sbin/ip'), +); + +// Returns command line for retreive interfaces +function getInterfacesCommand($commands) +{ + $ifconfig = Misc::whichCommand($commands['ifconfig'], ' | awk -F \'[/ |: ]\' \'{print $1}\' | sed -e \'/^$/d\''); + + if (!empty($ifconfig)) + { + return $ifconfig; + } + else + { + $ip_cmd = Misc::whichCommand($commands['ip'], ' -V', false); + + if (!empty($ip_cmd)) + { + return $ip_cmd.' -oneline link show | awk \'{print $2}\' | sed "s/://"'; + } + else + { + return null; + } + } +} + +// Returns command line for retreive IP address from interface name +function getIpCommand($commands, $interface) +{ + $ifconfig = Misc::whichCommand($commands['ifconfig'], ' '.$interface.' | awk \'/inet / {print $2}\' | cut -d \':\' -f2'); + + if (!empty($ifconfig)) + { + return $ifconfig; + } + else + { + $ip_cmd = Misc::whichCommand($commands['ip'], ' -V', false); + + if (!empty($ip_cmd)) + { + return 'for family in inet inet6; do '. + $ip_cmd.' -oneline -family $family addr show '.$interface.' | grep -v fe80 | awk \'{print $4}\' | sed "s/\/.*//"; ' . + 'done'; + } + else + { + return null; + } + } +} + + +$getInterfaces_cmd = getInterfacesCommand($commands); + +if (is_null($getInterfaces_cmd) || !(exec($getInterfaces_cmd, $getInterfaces))) +{ + $datas[] = array('interface' => 'N.A', 'ip' => 'N.A'); +} +else +{ + foreach ($getInterfaces as $name) + { + $ip = null; + + $getIp_cmd = getIpCommand($commands, $name); + + if (is_null($getIp_cmd) || !(exec($getIp_cmd, $ip))) + { + $network[] = array( + 'name' => $name, + 'ip' => 'N.A', + ); + } + else + { + if (!isset($ip[0])) + $ip[0] = ''; + + $network[] = array( + 'name' => $name, + 'ip' => $ip[0], + ); + } + } + + foreach ($network as $interface) + { + // Get transmit and receive datas by interface + exec('cat /sys/class/net/'.$interface['name'].'/statistics/tx_bytes', $getBandwidth_tx); + exec('cat /sys/class/net/'.$interface['name'].'/statistics/rx_bytes', $getBandwidth_rx); + + $datas[] = array( + 'interface' => $interface['name'], + 'ip' => $interface['ip'], + 'transmit' => Misc::getSize($getBandwidth_tx[0]), + 'receive' => Misc::getSize($getBandwidth_rx[0]), + ); + + unset($getBandwidth_tx, $getBandwidth_rx); + } +} + + +echo json_encode($datas); \ No newline at end of file diff --git a/libs/ping.php b/libs/ping.php new file mode 100644 index 0000000..dc8121d --- /dev/null +++ b/libs/ping.php @@ -0,0 +1,30 @@ +get('ping:hosts')) > 0) + $hosts = $Config->get('ping:hosts'); +else + $hosts = array('google.com', 'wikipedia.org'); + +foreach ($hosts as $host) +{ + exec('/bin/ping -qc 1 '.$host.' | awk -F/ \'/^rtt/ { print $5 }\'', $result); + + if (!isset($result[0])) + { + $result[0] = 0; + } + + $datas[] = array( + 'host' => $host, + 'ping' => $result[0], + ); + + unset($result); +} + +echo json_encode($datas); \ No newline at end of file diff --git a/libs/server.php b/libs/server.php new file mode 100644 index 0000000..4ea57d7 --- /dev/null +++ b/libs/server.php @@ -0,0 +1,35 @@ +get('server:show_port'); + +if (count($Config->get('server:list')) > 0) +{ + foreach ($Config->get('server:list') as $service) + { + $host = $service['host']; + $port = $service['port']; + $name = $service['name']; + $protocol = isset($service['protocol']) && in_array($service['protocol'], $available_protocols) ? $service['protocol'] : 'tcp'; + + if (Misc::scanPort($host, $port, $protocol)) + $status = 1; + else + $status = 0; + + $datas[] = array( + 'port' => $show_port === true ? $port : '', + 'name' => $name, + 'status' => $status, + ); + } +} + + +echo json_encode($datas); \ No newline at end of file diff --git a/libs/services.php b/libs/services.php new file mode 100644 index 0000000..61411e4 --- /dev/null +++ b/libs/services.php @@ -0,0 +1,35 @@ +get('services:show_port'); + +if (count($Config->get('services:list')) > 0) +{ + foreach ($Config->get('services:list') as $service) + { + $host = $service['host']; + $port = $service['port']; + $name = $service['name']; + $protocol = isset($service['protocol']) && in_array($service['protocol'], $available_protocols) ? $service['protocol'] : 'tcp'; + + if (Misc::scanPort($host, $port, $protocol)) + $status = 1; + else + $status = 0; + + $datas[] = array( + 'port' => $show_port === true ? $port : '', + 'name' => $name, + 'status' => $status, + ); + } +} + + +echo json_encode($datas); \ No newline at end of file diff --git a/libs/swap.php b/libs/swap.php new file mode 100644 index 0000000..e3cc980 --- /dev/null +++ b/libs/swap.php @@ -0,0 +1,32 @@ + 0) + $percent_used = 100 - (round($free / $total * 100)); + + +$datas = array( + 'used' => Misc::getSize($used * 1024), + 'free' => Misc::getSize($free * 1024), + 'total' => Misc::getSize($total * 1024), + 'percent_used' => $percent_used, +); + +echo json_encode($datas); \ No newline at end of file diff --git a/libs/system.php b/libs/system.php new file mode 100644 index 0000000..39e4096 --- /dev/null +++ b/libs/system.php @@ -0,0 +1,71 @@ + $hostname, + 'os' => $os, + 'kernel' => $kernel, + 'uptime' => $uptime, + 'last_boot' => $last_boot, + 'current_users' => $current_users, + 'server_date' => $server_date, +); + +echo json_encode($datas); \ No newline at end of file