code.fastix.org

Dateiansicht:

Datei:Projekte -> Linux,PHP:System-Tools -> Server-Zustand -> Server-Zustand.php
md5:6e81e5d7fd8c0fec430002fe241027f3
sha1:8946e7837736b2181036306869faaf21a4631907
Download-Link:Download
  1. <?php
  2. /**
  3. * @author: Jörg Reinholz, fastix WebDesign & Consult, Kassel - http://www.fastix.org/
  4. **/
  5.  
  6. function ip2link($str) {
  7.     $arS[]='0.0.0.0';
  8.     $arR[]='<span title="(0&dot;0&dot;0&dot;0) - Alle IPv4-Adressen">ALL_IP4</span> ';
  9.     $arS[]='127.0.0.1';
  10.     $arR[]='<span title="(127&dot;0&dot;0&dot;1) - Localhost, IPv4">LOCALHOST</span> ';
  11.     $arS[]=':::';
  12.     $arR[]='<span title="(:::) - Alle IPv6-Adressen">IP6</span>:';
  13.     $arS[]='::1:';
  14.     $arR[]='<span title="(::1) - Localhost, IPv6">LOC6</span>:';
  15.     $arS[]='92.51.129.206';
  16.     $arR[]='<span title="(92&dot;51&dot;129&dot;206) - Dieser Server">[THIS_ HOST ] </span>';
  17.     $str=str_replace($arS, $arR, $str);
  18.     $pattern='/([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})/';
  19.     $replace='<a href="http://www.fastix.org/netztools/?addr=$1&amp;action=whois">$1</a>';
  20.     return preg_replace($pattern, $replace, $str);
  21. }
  22.  
  23.  
  24. function sys_uptimes() {
  25.     $arUptimes=explode(' ', trim(`uptime`));
  26.     $a['prozessors']=trim(`grep processor /proc/cpuinfo |wc -l`);
  27.     $a['days']=$arUptimes[2];
  28.     $s = $s-$a['days']*60*60*24;
  29.     list( $a['hours'], $a['minuts'] ) = explode(':', $arUptimes[4]);
  30.     $a['minuts'] = str_replace(',', '', $a['minuts']);
  31.     $a['syslast'] = round( str_replace( ',', '', $arUptimes[11] ) / $a['prozessors']*100, 2 );
  32.     return $a;
  33. }
  34.  
  35. function sys_mem_table() {
  36.     $table='<table>
  37.    <tr>
  38.        <th> </th>
  39.        <th>Gesamt:</th>
  40.        <th>Benutzt:</th>
  41.        <th>Frei:</th>
  42.        <th>Shared:</th>
  43.        <th>Puffer:</th>
  44.        <th>Cached:</th>
  45.    </tr>';
  46.     $data=`/usr/bin/free -m | /bin/grep Mem 2>&1`;
  47.     $data=trim(preg_replace('/[^0-9 \n]/', '', $data));
  48.     $data=preg_replace('/ {2,}/', ' ', $data);
  49.     $data=preg_replace('/\t/', ' ', $data);
  50.     $table .= '             <tr>
  51.                                <th>RAM:</th>
  52.                                <td>' .  str_replace(' ', ' MB</td><td>', $data) . 'MB</td>
  53.                        </tr>';
  54.     $data=`/usr/bin/free -m | /bin/grep -E Swapi 2>&1`;
  55.     $data=trim(preg_replace('/[^0-9 \n]/', '', $data));
  56.     $data=preg_replace('/ {2,}/', ' ', $data);
  57.     $data=preg_replace('/\t/', ' ', $data);
  58.     $table .= '<tr><th>Swap:</th><td>' .  str_replace(' ', ' MB</td><td>', $data) . 'MB</td></tr>';
  59.     $table.='</table>';
  60.     return $table;
  61. }
  62.  
  63. header("Content-Type: text/html; charset=UTF-8");
  64. ?><!doctype html>
  65. <html>
  66.   <head>
  67.     <title>Server-Zustand</title>
  68.     <meta http-equiv="refresh" content="60">
  69.     <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  70.     <style type="text/css">
  71.       html,body {margin:0; padding:0;background-color:#fafafa;}
  72.       h1 {margin-top:0;padding:.3em .5em .3em .5em;background-color:#ddd;border-bottom: 3px solid black;}
  73.       #content {padding:0 1em 0 1em;}
  74.       table {background-color:#ddd; font-size:.8em; margin-bottom:1em;}
  75.       table tr {background-color:#fafafa;}
  76.       table tr:hover {background-color:#cfc;}
  77.       th,td {padding:.3em; min-width:8em;}
  78.       th {padding-right:1em; text-align:left;}
  79.       th,td.str {text-align:left;}
  80.       td,th.int,th.dec {text-align:right;}
  81.       tr.aktiv td {background-color:#ffc;}
  82.       .buttonleiste {font-size:1em;}
  83.       #start_ping_button, #stop_ping_button,#reset_button,#cache_button {display:inline-block;font-size:.8em;width:10em;border:none;border-radius:1em;padding:.5em 1em .5em 1em;box-shadow:2px 2px 2px gray;margin:0;vertical-align:middle;text-align:center;cursor:pointer;}
  84.       #cache_button {background-color:#ffc;}
  85.       .download {margin-top:2em;padding-top:1em;border-top:1px solid black;}
  86.     </style>
  87.   </head>
  88.   <body>
  89.     <h1>Dieser Webserver funktioniert!</h1>
  90.     <div id="content">
  91. <h2>Systemüberblick:</h2>
  92. <?php
  93. $a=sys_uptimes();
  94. print "<p>". htmlspecialchars(`lsb_release -d | sed "s/Description://"`) ." auf " . $a['prozessors'] . " Prozessoren läuft seit " . $a['days'] . " Tagen, " . $a['hours'] . " Stunden und " . $a['minuts'] . " Minuten<br />
  95. Aktuelle Systemauslastung: " . $a['syslast'] . "%</p>";
  96. print "<p>Kernel: " . htmlspecialchars(`uname -ri`) . "</p>";
  97. print sys_mem_table("", "meminfo");
  98. print "<h2>Plattenauslastung:</h2><pre>";
  99. print `df -h`;
  100. print "</pre>";
  101. print "<h2>Aktuelle Prozessorlast:</h2><pre>";
  102. print `uptime`;
  103. print "</pre>";
  104. print "<h2>Offene (Standard-) Ports:</h2><pre>";
  105. print '<a href="http://www.fastix.org/netztools/?addr=fastix.org&amp;action=nmap">von außen testen</a>';
  106. print "</pre>";
  107. print "<h2>Erreichbarkeit:</h2><pre>";
  108. print '<a href="http://www.fastix.org/netztools/?addr=fastix.org&amp;action=ping">von außen testen</a>';
  109. print "</pre>";
  110. print "<h2>TCP-Verbindungen:</h2><pre>";
  111. print ip2link(`netstat -an | grep "tcp"`);
  112. print "</pre>";
  113. print "<h2>UDP-Verbindungen:</h2><pre>";
  114. print ip2link(`netstat -an | grep "udp"`);
  115. print "</pre>";
  116. print '<h2>Netzwerk:</h2><pre>';
  117. print ip2link(`ifconfig`);
  118. print "</pre>";
  119. ?>
  120.     </div>
  121.   </body>
  122. </html>