From 01773eabc92ef6ee90657e8fa179e36e52464f4e Mon Sep 17 00:00:00 2001 From: Ivan Davydov Date: Sat, 21 Jun 2025 18:29:46 +0300 Subject: Make the website minimalistic --- archive/status.php | 320 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 320 insertions(+) create mode 100644 archive/status.php (limited to 'archive/status.php') 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 @@ + + + + + Техническая информация | Веб-сайт самохостера Lotigara + + + + + + + + + +
+ + + +
+. +*/ + +$data = ""; +$data .= '
Состояние сетевых демонов
'; + + +//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 .= ""; +foreach ($services as $service) { + if($service['ip']==""){ + $service['ip'] = "localhost"; + } + $data .= ""; + //fclose($fp); + } else { + $data .= ""; + fclose($fp); + } + +} +//close table +$data .= "
НазваниеПортСостояние
" . $service['service'] . "". $service['port']; + + $fp = @fsockopen($service['ip'], $service['port'], $errno, $errstr, $timeout); + if (!$fp) { + $data .= "Не работает
Работает
"; +$data .= '
'; +echo $data; + + +/* ===================================================================== +// +// ////////////////// SERVER INFORMATION ///////////////////////////////// +// +// +* =======================================================================/*/ + +$data1 = ""; +$data1 .= '
Информация о сервере
'; + +$data1 .= ""; +// $data1 .= "
Средняя загрузкаВремя работыСвободно ОЗУ
"; + +//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 .= '
'; + $str .= "" . badge($disk_name,'secondary') .' '. getSymbolByQuantity($disk_free) . '/'. getSymbolByQuantity($disk_space) .""; + $str .= ' +
+
'.$disk_free_precent.'%
+
+
'; + + 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 "$str"; +} + +//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('
', $tom_mem_arr ); +$top_mem = "
" . $top_mem . "
"; + +$top_cpu = implode('
', $top_cpu_use ); +$top_cpu = "
" . $top_cpu. "
";*/ + +$data1 .= "\n"; +$data1 .= ""; + + +$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 .= "";*/ + +$data1 .= ""; +/*$data1 .= ""; +$data1 .= "";*/ +$data1 .= "
"; + +$data1 .= ""; +$data1 .= ""; +$data1 .= "
". $avgs[1]. ' ' .$avgs[2] . ' ' . $avgs[3] . " $uptime
Disk free " . get_disk_free_status($disks) . "
". format_storage_info($total_mem *1024, $free_mem *1024, '') ."
Top RAM user $top_mem
Top CPU user $top_cpu
"; +$data1 .= '
'; +echo $data1; + +/* ============================================================================= +* +* DISPLAY BANDWIDTH STATISTIC, REQUIRE VNSTAT INSTALLED AND PROPERLY CONFIGURED. +* +* ===============================================================================s +*/ + + +/*if (!isset($_GET['showtraffic']) || $_GET['showtraffic'] == false) die(); + +$data2 = ""; +$data2 .= ' +
+

+ vnstat Network traffic +

+
+'; + + +$data2 .="
";
+$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
"; + +echo $data2;*/ +?> +
+
+ См. лицензию и исходный код в этом файле +
+
-- cgit v1.2.3