<?php


/**
 * Klasse Info
 */

class Info {
	/*
	 * Funktion display erzeugt den Inhalt von der HTML-Seite
	 */
	function display($args) {

		require_once "./includes/amifunc.php";
                include '/usr/local/php/beroConf.php';

                $bc = new beroConf('root');

		include('./includes/header.php');
		//Die Tabelle Infos

		$ret .= "<br/><br/>
			<table class='contenttoc' width='36%'>
			<tr>
			<th>".INFO_SERIAL_NUMBER_DIS."</th>
			</tr>
			<tr>";
		$res=file_get_contents('/proc/cmdline');
		preg_match("/[^a-zA-Z0-9=]*?d=(?<serial>.+) /",$res,$serial);

		$ret.="<td nowrap>".$serial['serial']."</td>
			</tr>
			</table><br/>";

		$f=@file("/VERSION");
		$tmp=split("=",$f[1]);
		$rootfs=$tmp[1];

		// Verschiedene Versionsnummern
		$fpga=file_get_contents("/proc/FPGA_VERSION");
		$res=file_get_contents('/proc/cmdline');
		preg_match("/.*revision=(?<revision>.*)/",$res,$revision);
		$revision=$revision['revision'];
		$ret.="<table class='contenttoc' width='36%'>
					<tr><th colspan='2'>".INFO_VERSIONS_DIS."</th></tr>
		            <tr><td><b>appfs</b></td><td>". $bc->get("root", "app-image")."</td></tr>
		            <tr><td><b>rootfs</b></td><td>Version $rootfs</td></tr>
		            <tr><td><b>FPGA</b></td><td>Version $fpga</td></tr>
		            <tr><td><b>".INFO_HW_REVISION_DIS."</b></td><td>".$revision."</td></tr>
		            </table><br/>";

		//MAC Adresse
		$ret .= "<table class='contenttoc' width='36%'>
			<tr>
			<th>".INFO_MAC_ADDRESS_DIS."</th>
			</tr>
			<tr>";
		exec('/sbin/ifconfig eth0 | /bin/grep HWaddr',$resm);
		preg_match("/[^a-zA-Z0-9:]*? HWaddr (?<mac>.+)/",$resm[0],$mac);

		$ret.="<td nowrap>".$mac[mac]."</td>
			</tr>
			</table><br/>";

		//Netzwerk Konfiguration
		$ret .= "<table class='contenttoc' width='36%'>
			<tr>
			<th colspan='2'>".INFO_NET_CONFIGURATION_DIS."</th>
			</tr>
			<tr>";

		$ip=exec('/sbin/ifconfig eth0 | sed -ne "s/.*inet addr:\(.*\) Bcast.*/\1/p"');
		$mask=exec('/sbin/ifconfig eth0 | sed -ne "s/.*Mask:\(.*\)/\1/p"');
		$gateway=exec('/sbin/route -n | sed -ne "s/^0\.0\.0\.0[[:blank:]]*\([\.0-9]*\) .*/\1/p"');
		$ret.="<td nowrap>".INFO_IP_ADDRESS_DIS.":</td><td>". $ip."</td></tr>
			<tr><td>".INFO_NETMASK_DIS.":</td><td>".$mask."</td></tr>
			</tr><td>".INFO_GATEWAY_DIS.":</td><td>".$bc->get("root", "lan-gateway")."</td></tr>
			</table><br/>";

		//Aktuelles Datum und Uhrzeit der Karte
		$ret .= "<table class='contenttoc' width='36%'>
			<tr>
			<th >".INFO_DATE_TIME_DIS."</th>
			</tr>
			<tr>
			<td nowrap>".date("d-F-Y-H:i:s",time())."</td>
			</tr>
			</table><br/>";

		//Anzeige der installierte LI Module
		$ret .= "<table class='contenttoc' width='36%'>
			<tr>
			<th>".INFO_LINE_INTERFACES_DIS."</th>
			</tr>
			";
		$li0=file('/proc/li0');
		$li1=file('/proc/li1');
		$resl=array_merge($li0,$li1);
		$i=0;
		foreach ($resl as $zeile){
			preg_match("/type: (?<li>.+)/",$zeile,$lif);
			if (($lif[li]!="unknown") && ($lif[li]!="")){
				if ($lif[li]=="xhfc-4su") $ret.="<tr><td nowrap>li".$i++.":  BF4S0</td></tr>";
				if ($lif[li]=="hfc-e1") $ret.="<tr><td nowrap>li".$i++.":  BF1E1</td></tr>";
				if ($lif[li]=="hfc-2e1") $ret.="<tr><td nowrap> li".$i++.": BF2E1</td></tr>";
				if ($lif[li]=="si-4fxo") $ret.="<tr><td nowrap> li".$i++.": BF4FXO</td></tr>";
				if ($lif[li]=="si-4fxs") $ret.="<tr><td nowrap> li".$i++.": BF4FXS</td></tr>";
				if ($lif[li]=="xhfcSi-2s02fxs") $ret.="<tr><td nowrap> li".$i++.": BF2S02FXS</td></tr>";
				if ($lif[li]=="telit-2GSM") $ret.="<tr><td nowrap> li".$i++.": BF2GSM</td></tr>";
			}elseif($lif[li]=="unknown"){
				$i++;
			}
		}

		//UP Time
		require_once ('./includes/isgwtelnet.php');
		$isgw = new isgwtelnet();
		$isgw->isgw_login();
		$isgw_uptime=$isgw->isgw_uptime();
		$isgw_uptime=preg_split("/: /",$isgw_uptime);
		$ret.="</table><br/>";
		$ret .= "<table class='contenttoc' width='36%'>
			<tr>
			<th colspan=2>".INFO_UPTIME_DIS."</th>
			</tr>
			<tr>";
		exec('/usr/bin/uptime',$resup);
		preg_match("/(?<t>.+), load /",$resup[0],$uptime);

		$ret.="<td>System</td><td nowrap>".$uptime[t]."</td></tr>
			<tr><td>ISGW</td><td nowrap>".$isgw_uptime[1]."</td>
			</tr>
			</table><br/>";
	//Rückgabe: Der Inhalt von der HTML-Seite
		return $ret;
	}

}
?>
