diff options
author | Ivan Davydov <lotigara@lotigara.ru> | 2025-06-21 18:29:46 +0300 |
---|---|---|
committer | Ivan Davydov <lotigara@lotigara.ru> | 2025-06-21 18:29:46 +0300 |
commit | 01773eabc92ef6ee90657e8fa179e36e52464f4e (patch) | |
tree | 18586cf57fc3c0ef2828f9d405ceb73c61bc080a /archive/status.php | |
parent | 401aa8724fb641bfae48fabef1d09ed448242cd3 (diff) |
Make the website minimalistic
Diffstat (limited to 'archive/status.php')
-rw-r--r-- | archive/status.php | 320 |
1 files changed, 320 insertions, 0 deletions
diff --git a/archive/status.php b/archive/status.php new file mode 100644 index 0000000..5946dcc --- /dev/null +++ b/archive/status.php @@ -0,0 +1,320 @@ +<!DOCTYPE html> +<html lang="ru"> + <head> + <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> + <title>Техническая информация | Веб-сайт самохостера Lotigara</title> + <link href="/css/main.css" rel="stylesheet" /> + <link href="/css/theme.css" rel="stylesheet" /> + <link href="/css/third-party.css" rel="stylesheet" /> + <link href="/css/responsivity.css" rel="stylesheet" /> + + <style> + @media (max-width: 1024px) { + tr.services_table_item td:nth-of-type(1):before { content: "Название"; } + tr.services_table_item td:nth-of-type(2):before { content: "Порт"; } + tr.services_table_item td:nth-of-type(3):before { content: "Состояние"; } + + tr.status_table_item td:nth-of-type(1):before { content: "Средняя загрузка"; } + tr.status_table_item td:nth-of-type(2):before { content: "Время работы"; } + tr.status_table_item td:nth-of-type(3):before { content: "Свободно ОЗУ"; } + } + </style> + </head> + <body> + <input type="checkbox" id="theme-switch"> + <div id="page"><div class="inner_page"> + <div class="page_header floating_element"><h1 class="floating_element">Техническая информация</h1></div> + <div class="floating_element"> + <h4 style="display:inline"><a style="color:white" href="/">главная|main page</a></h4> + <p style="display:inline">состояние|status</p> + <h4 style="display:inline"><a style="color:white" href="/blog">журнал|journal</a></h4> + <h4 style="display:inline"><a style="color:white" href="/files">файлы|files</a></h4> + <h4 style="display:inline"><a style="color:white" href="https://git.lotigara.ru">программы|software</a></h4> + <label id="switch-label" for="theme-switch"></label> + </div> + <div class="table_of_contents floating_element"> + <details> + <summary class="section_header section_header_last"> + Содержание + </summary> + <div class="table_of_contents_item floating_element"> + <a href="#net-daemons">Состояние сетевых демонов</a> + <div class="table_of_contents_item floating_element"> + <a href="#server-info">Информация о сервере</a> + </div> + <div class="table_of_contents_item floating_element"> + <a href="#license">Лицензия</a> + </div> + </details> + </div> + <div class="content_section floating_element"> +<?php +/* + + * + * @author Trường An Phạm Nguyễn, Ivan Davydov + * @copyright 2019, 2024, The authors + * @license GNU AFFERO GENERAL PUBLIC LICENSE + * http://www.gnu.org/licenses/agpl-3.0.html + * + * Jul 27, 2013 + +Original author: +* Disclaimer Notice(s) +* ex: This code is freely given to you and given "AS IS", SO if it damages +* your computer, formats your HDs, or burns your house I am not the one to +* blame. +* Moreover, don't forget to include my copyright notices and name. +* +------------------------------------------------------------------------------+ +* Author(s): Crooty.co.uk (Adam C) +* +------------------------------------------------------------------------------+ + + 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 3 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, see <http://www.gnu.org/licenses/>. +*/ + +$data = ""; +$data .= '<div class="section_header"><div id="server-info"></div>Состояние сетевых демонов</div><div class="content_section_text">'; + + +//configure script +$timeout = "1"; + +//set service checks +/* +The script will open a socket to the following service to test for connection. +Does not test the fucntionality, just the ability to connect +Each service can have a name, port and the Unix domain it run on (default to localhost) +*/ +$services = array(); + + +$services[] = array("port" => "80", "service" => "Nginx", "ip" => "") ; +$services[] = array("port" => "5222", "service" => "Prosody", "ip" => "") ; +$services[] = array("port" => "5281", "service" => "Веб-сервер Prosody", "ip" => "") ; +$services[] = array("port" => "25", "service" => "Postfix", "ip" => "") ; +$services[] = array("port" => "143", "service" => "Dovecot", "ip" => "") ; +$services[] = array("port" => "1323", "service" => "Alps", "ip" => "") ; +$services[] = array("port" => "5232", "service" => "Radicale", "ip" => "") ; +$services[] = array("port" => "80", "service" => "Yandex", "ip" => "ya.ru") ; + + +//begin table for status +$data .= "<table class='services_table'><thead><tr><th>Название</th><th>Порт</th><th>Состояние</th></tr></thead><tbody>"; +foreach ($services as $service) { + if($service['ip']==""){ + $service['ip'] = "localhost"; + } + $data .= "<tr class='services_table_item'><td>" . $service['service'] . "</td><td>". $service['port']; + + $fp = @fsockopen($service['ip'], $service['port'], $errno, $errstr, $timeout); + if (!$fp) { + $data .= "</td><td>Не работает </td></tr>"; + //fclose($fp); + } else { + $data .= "</td><td>Работает</td></tr>"; + fclose($fp); + } + +} +//close table +$data .= "</tbody></table>"; +$data .= '</div>'; +echo $data; + + +/* ===================================================================== +// +// ////////////////// SERVER INFORMATION ///////////////////////////////// +// +// +* =======================================================================/*/ + +$data1 = ""; +$data1 .= '<div class="section_header"><div id="server-info"></div>Информация о сервере</div><div class="content_section_text">'; + +$data1 .= "<table class='status_table'><thead><tr><th>Средняя загрузка</th><th>Время работы</th><th>Свободно ОЗУ</th></tr></thead><tbody>"; +// $data1 .= "<div class='table-responsive'><table class='table table-sm mb-0'>"; + +//GET SERVER LOADS +$loadresult = @exec('uptime'); +preg_match("/averages?: ([0-9\.]+),[\s]+([0-9\.]+),[\s]+([0-9\.]+)/",$loadresult,$avgs); + + +//GET SERVER UPTIME +$uptime = explode(' up ', $loadresult); +$uptime = explode(',', $uptime[1]); +$uptime = $uptime[0].', '.$uptime[1]; + +//Get the disk space +function getSymbolByQuantity($bytes) { + $symbol = array('B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB'); + $exp = floor(log($bytes)/log(1024)); + + return sprintf('%.2f'.$symbol[$exp].'', ($bytes/pow(1024, floor($exp)))); +} +function percent_to_color($p){ + if($p < 30) return 'success'; + if($p < 45) return 'info'; + if($p < 60) return 'primary'; + if($p < 75) return 'warning'; + return 'danger'; +} +function format_storage_info($disk_space, $disk_free, $disk_name){ + $str = ""; + $disk_free_precent = 100 - round($disk_free*1.0 / $disk_space*100, 2); + $str .= '<div class="col p-0 d-inline-flex">'; + $str .= "<span class='mr-2'>" . badge($disk_name,'secondary') .' '. getSymbolByQuantity($disk_free) . '/'. getSymbolByQuantity($disk_space) ."</span>"; + $str .= ' +<div class="progress flex-grow-1 align-self-center"> + <div class="progress-bar progress-bar-striped progress-bar-animated '; + $str .= 'bg-' . percent_to_color($disk_free_precent) .' + " role="progressbar" style="width: '.$disk_free_precent.'%;" aria-valuenow="'.$disk_free_precent.'" aria-valuemin="0" aria-valuemax="100">'.$disk_free_precent.'%</div> +</div> +</div> '; + + return $str; + +} + +function get_disk_free_status($disks){ + $str=""; + $max = 5; + foreach($disks as $disk){ + if(strlen($disk["name"]) > $max) + $max = strlen($disk["name"]); + } + + foreach($disks as $disk){ + $disk_space = disk_total_space($disk["path"]); + $disk_free = disk_free_space($disk["path"]); + + $str .= format_storage_info($disk_space, $disk_free, $disk['name']); + + } + return $str; +} +function badge($str, $type){ + return "<span class='badge badge-" . $type . " ' >$str</span>"; +} + +//Get ram usage +$total_mem = preg_split('/ +/', @exec('grep MemTotal /proc/meminfo')); +$total_mem = $total_mem[1]; +$free_mem = preg_split('/ +/', @exec('grep MemFree /proc/meminfo')); +$cache_mem = preg_split('/ +/', @exec('grep ^Cached /proc/meminfo')); + +$free_mem = $free_mem[1] + $cache_mem[1]; + + +//Get top mem usage +$tom_mem_arr = array(); +$top_cpu_use = array(); + +//-- The number of processes to display in Top RAM user +$i = 5; + + +/* ps command: +-e to display process from all user +-k to specify sorting order: - is desc order follow by column name +-o to specify output format, it's a list of column name. = suppress the display of column name +head to get only the first few lines +*/ +/*exec("ps -e k-rss -o rss,args | head -n $i", $tom_mem_arr, $status); +exec("ps -e k-pcpu -o pcpu,args | head -n $i", $top_cpu_use, $status); + + +$top_mem = implode('<br/>', $tom_mem_arr ); +$top_mem = "<pre class='mb-0 '><code>" . $top_mem . "</code></pre>"; + +$top_cpu = implode('<br/>', $top_cpu_use ); +$top_cpu = "<pre class='mb-0 '><code>" . $top_cpu. "</code></pre>";*/ + +$data1 .= "<tr class='status_table_item'><td><b>". $avgs[1]. ' ' .$avgs[2] . ' ' . $avgs[3] . " </b></td>\n"; +$data1 .= "<td>$uptime</td>"; + + +$disks = array(); + +/* +* The disks array list all mountpoint you wan to check freespace +* Display name and path to the moutpoint have to be provide, you can +*/ +$disks[] = array("name" => "local" , "path" => getcwd()) ; +// $disks[] = array("name" => "Your disk name" , "path" => '/mount/point/to/that/disk') ; + + +/*$data1 .= "<tr><td>Disk free </td><td>" . get_disk_free_status($disks) . "</td></tr>";*/ + +$data1 .= "<td>". format_storage_info($total_mem *1024, $free_mem *1024, '') ."</td>"; +/*$data1 .= "<tr><td>Top RAM user </td><td><small>$top_mem</small></td></tr>"; +$data1 .= "<tr><td>Top CPU user </td><td><small>$top_cpu</small></td></tr>";*/ +$data1 .= "<hr>"; + +$data1 .= "</tr>"; +$data1 .= "</tbody>"; +$data1 .= "</table>"; +$data1 .= '</div>'; +echo $data1; + +/* ============================================================================= +* +* DISPLAY BANDWIDTH STATISTIC, REQUIRE VNSTAT INSTALLED AND PROPERLY CONFIGURED. +* +* ===============================================================================s +*/ + + +/*if (!isset($_GET['showtraffic']) || $_GET['showtraffic'] == false) die(); + +$data2 = ""; +$data2 .= ' +<div class="card mb-2"> + <h4 class="card-header text-center"> + vnstat Network traffic + </h4> + <div class="card-body text-center"> +'; + + +$data2 .="<span class=' d-block'><pre class='d-inline-block text-left'><small>"; +$traffic_arr = array(); +exec('vnstat -' . escapeshellarg( $_GET['showtraffic'] ), $traffic_arr, $status); + +///for testing +$traffic = " +enp0s20 / monthly + +month rx | tx | total | avg. rate +------------------------+-------------+-------------+--------------- +Sep '18 36.60 GiB | 7.04 GiB | 43.64 GiB | 144.62 kbit/s +Oct '18 400.69 GiB | 1.19 TiB | 1.58 TiB | 5.19 Mbit/s +Nov '18 393.52 GiB | 2.19 TiB | 2.57 TiB | 8.72 Mbit/s +Dec '18 507.28 GiB | 2.05 TiB | 2.55 TiB | 8.37 Mbit/s +Jan '19 269.01 GiB | 1.39 TiB | 1.65 TiB | 7.51 Mbit/s +------------------------+-------------+-------------+--------------- +estimated 371.92 GiB | 1.92 TiB | 2.29 TiB | +"; +/// for real +$traffic = implode("\n", $traffic_arr); + +$data2 .="$traffic</small></pre></span>"; + +echo $data2;*/ +?> +<div class="section_header section_header_last"> + <div id="license"></div> + См. лицензию и исходный код в <a style="color: white;" href="/files/status.php.txt">этом</a> файле +</div> +</div></div></body></html> |