PHP/Anzeige von Systeminformationen

Aus Mikiwiki
Zur Navigation springen Zur Suche springen

Beschreibung

Name systeminformation.php
Autor Michael Kuhn
Datum 19 October 2008 (Version 0.1)
Beschreibung Anzeige von Systeminformationen.

Konfiguration

Notwendiger Eintrag in der Datei "/etc/sudoers" mit "visudo".

www-data ALL=NOPASSWD: /usr/sbin/dmidecode

Skript

<?php

## Name         systeminformation.php
## Date         19 October 2008
## Description  Outputs some information about hardware and installed software
##              of the host the script is running on.
## Hints        The following line needs to be inserted into file "/etc/sudoers":
##              www-data ALL=NOPASSWD: /usr/sbin/dmidecode

##### CONFIGURATION #####

$DMIDECODE = "/usr/sbin/dmidecode";
$HWINFO    = "/usr/sbin/hwinfo";

$output_exists_dmidecode = shell_exec("[ -x /usr/sbin/dmidecode ] && echo -n $?");
$output_exists_hwinfo    = shell_exec("[ -x /usr/sbin/hwinfo    ] && echo -n $?");

##### FUNCTIONS #####

function tr_head($title)
{
  echo "<tr>\n<th align=\"left\" bgcolor=\"#C0C0C0\" colspan=\"2\">" . $title . "</th>\n</tr>\n";
}

function tr($title, $content)
{
  echo "<tr>\n<td bgcolor=\"#DCDCDC\"><b>" . $title . "</b></td>\n<td>" . $content . "</td>\n</tr>\n";
}

##### MAIN PROGRAM #####

## Prüfung auf Vorhandensein von "dmidecode" und "hwinfo".
if ("$output_exists_dmidecode" != "0" or "$output_exists_hwinfo" != "0")
{
  if ("$output_exists_dmidecode" != "0")
  {
    #echo "DMIDECODE: <pre>X" . $output_exists_dmidecode . "X</pre><br />\n";
    echo "\"dmidecode\" fehlt!<br />\n";
  }
  if ("$output_exists_hwinfo" != "0")
  {
    #echo "HWINFO: <pre>X" . $output_exists_hwinfo . "X</pre><br />\n";
    echo "\"hwinfo\" fehlt!<br />\n";
  }
  exit();
}

echo "<h1>Systeminformationen</h1>\n";

$output_date = shell_exec("date \"+%d. %B %Y\"");
echo "<p>Datum: "                       . $output_date . "</p>\n";

echo "<table border=1>\n";
tr_head("Allgemeine Informationen");

## Rechnername
$output_rechnername = shell_exec("uname -n");
tr("Rechnername", $output_rechnername);

## Betriebssystem
$output_betriebssystem = shell_exec("cat /etc/issue.net");
tr("Betriebssystem", $output_betriebssystem);

## Kernel 
$output_kernel = shell_exec("uname -sr");
tr("Kernel", $output_kernel);

## "root"-Passwort

## IP-Adresse
$output_ipadresse = shell_exec("ip address show | grep \"inet \" | awk '{ print $2 }'");
tr("IP-Adresse", $output_ipadresse);

## Nameserver
$output_nameserver = shell_exec("cat /etc/resolv.conf | grep \"nameserver \" | awk '{ print $2 }'");
tr("Nameserver", $output_nameserver);

## Hardware
tr_head("Hardware");

## Netzteil
tr ("Netzteil", "&nbsp;");

## Motherboard
$output_motherboard = shell_exec("sudo $DMIDECODE -s system-manufacturer && sudo $DMIDECODE -s system-product-name");
tr("Motherboard", $output_motherboard);

## BIOS
$output_bios = shell_exec("sudo $DMIDECODE -s bios-vendor && sudo dmidecode -s bios-version && sudo $DMIDECODE -s bios-release-date");
tr("BIOS", $output_bios);

## Prozessor
$output_prozessor       = shell_exec("$HWINFO --cpu | grep '^  Model:'    | tr '\042' '%' | awk -F% '{ print $2 }'");
$output_prozessor_cache = shell_exec("$HWINFO --cpu | grep '^  Cache:'                    | awk -F: '{ print $2 }'");
tr("Prozessor", $output_prozessor . " / " . $output_prozessor_cache . " Cache");

## Arbeitsspeicher
$output_arbeitsspeicher = shell_exec("$HWINFO --memory | grep '^  Memory Size:' | awk -F: '{ print $2 }'");
tr("Arbeitsspeicher", $output_arbeitsspeicher);

## Festplatte
$output_festplatte = shell_exec("$HWINFO --disk | grep '^  Model:'    | tr '\042' '%' | awk -F% '{ print $2 }'");
tr("Festplatte", $output_festplatte);

$output_belegung     = disk_free_space("/");
tr("Festplattenbelegung", number_format($output_belegung, 0, '.', '\'') . " Bytes freier Platz auf \"/\"");

## Tastatur
$output_tastatur = shell_exec("$HWINFO --keyboard | grep '^  Model:' | tr '\042' '%' | awk -F% '{ print $2 }'");
tr("Tastatur", $output_tastatur);

## Bildschirm
tr("Bildschirm", "&nbsp;");

## Grafikkarte
$output_grafikkarte = shell_exec("$HWINFO --gfxcard | grep '^  Model:'    | tr '\042' '%' | awk -F% '{ print $2 }'");
tr("Grafikkarte", $output_grafikkarte);

## Soundkarte
$output_soundkarte = shell_exec("$HWINFO --sound | grep '^  Model:'    | tr '\042' '%' | awk -F% '{ print $2 }'");
tr("Soundkarte", $output_soundkarte);

## Netzwerkkarte
$output_netzwerkkarte_vendor = shell_exec("$HWINFO --netcard | grep '^  Vendor:'    | tr '\042' '%' | awk -F% '{ print $2 }'");
$output_netzwerkkarte_device = shell_exec("$HWINFO --netcard | grep '^  Device:'    | tr '\042' '%' | awk -F% '{ print $2 }'");
tr("Netzwerkkarte", $output_netzwerkkarte_vendor . $output_netzwerkkarte_device);

## CD-ROM-Laufwerk
$output_cdrom          = shell_exec("$HWINFO --cdrom | grep '^  Model:'    | tr '\042' '%' | awk -F% '{ print $2 }'");
$output_cdrom_features = shell_exec("$HWINFO --cdrom | grep '^  Features:'                 | awk -F: '{ print $2 }'");
tr("CD-ROM-Laufwerk", $output_cdrom . " (" . trim($output_cdrom_features) . ")");

##### Software #####

echo "</table>\n";

echo "<h2>Installierte Pakete</h2>\n";
$output_software = shell_exec("COLUMNS=200 dpkg -l | grep ^ii");
echo "<pre>$output_software</pre>";

?>