<?php
/*
beroFix.php
*/
include("../../php/beroConf.php");
include("../berogui/misc/database.php");
include("../berogui/includes/isgwtelnet.php");

$Version="2.03";
(isset($_POST['cmd'])) ? $cmd=$_POST['cmd'] : $cmd=$_GET['cmd'];
(isset($_POST['data'])) ? $data=$_POST['data'] : $data=$_GET['data'];
static $display;
unset($display);

        if($cmd=="help"){
           	$result=help();
        	exit;
        }
        elseif($cmd=="info"){
			$tmp=split("=",$data);
           	if (count($tmp)!=2){
        		unset($display);
        	}else{
        		$cinfo=$tmp[1];
        		$display=infocmd($cinfo);
        	}
        }elseif($cmd=="fulltrace"){
        	echo fulltrace();
        	exit;
		}elseif($cmd=="getcdr"){
			echo getcdr();
			exit;
		}elseif ($cmd=="misdnportinfo"){
        	echo misdnportinfo();
        	exit;
		}elseif ($cmd=="setapipwd"){
				echo setapipwd();
				exit;
        }elseif ($cmd=="setwebpwd"){
				echo setwebpwd();
				exit;
        }elseif ($cmd=="getsipstate"){
               	echo getsipstate();
               	exit;
        }elseif ($cmd=="getisdnstate"){
				echo getisdnstate();
               	exit;
		}elseif ($cmd=="getanalogstate"){
				echo getanalogstate();
               	exit;
        }elseif ($cmd=="reload"){
				echo reload();
				exit;
        }elseif ($cmd=="restart"){
                echo restart();
                exit;
        }elseif ($cmd=="reboot"){
        		echo reboot();
                exit;
        }
        elseif ($cmd=="restoreoldconfig"){
                echo restoreoldconfig();
                exit;
        }
       elseif($cmd=="settftp"){
				echo settftp();
              	exit;
       }
       elseif($cmd=="sethttp"){
                echo sethttp();
                exit;
       }
       elseif($cmd=="setprovtype"){
                echo setprovtype();
                exit;
       }
        elseif ($cmd=="config_update" || $cmd=="tftp_config_update"){
              	echo config_update();
                exit;
        }
        elseif ($cmd=="firmware_update" || $cmd=="tftp_firmware_update") {
                echo firmware_update();
                exit;
        }
        elseif ($cmd=="getlif"){
        		echo getlif();
				exit;
        }
        elseif ($cmd=="getinfo"){
				echo getinfo();
				exit;
        }
        elseif ($cmd=="createconfig"){
				echo createconfig();
				exit;
		}elseif($cmd=="logging"){
			echo logging();
			exit;
		}elseif($cmd=="berocloud"){
			echo berocloud();
			exit;
		}elseif($cmd=="getisgwinfo"){
			echo getisgwinfo();
			exit;
		}elseif($cmd=="getisdnstats"){
			echo getisdnstats();
			exit;
		}elseif($cmd=="healthcheck"){
			echo healthcheck();
			exit;
		}elseif($cmd=="smslist"){
			echo smslist();
			exit;
		}elseif($cmd=="smsget"){
			echo smsget();
			exit;
		}elseif($cmd=="smssend"){
			echo smssend();
			exit;
		}elseif($cmd=="smsdelete"){
			echo smsdelete();
			exit;
		}else{

	 	}

	include "../berogui/includes/variables.php";
	//HEADER
	print '<html><head><link rel="stylesheet" type="text/css" href="http:../berogui/includes/template_css.css" />';
	print "<title>beroAri</title></head><body>";
	print "<br><table align=\"center\" bgcolor=\"#f0f0ec\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"500\">
	    <colgroup>
	    <col width=\"39\"></col>
	    </colgroup>
		<tbody><tr>
		<td colspan=\"2\"><img src=\"../berogui/includes/images/bg_top.png\"></td>
		</tr>
		<tr>
		<td background=\"../berogui/includes/images/bg_left.png\" style='background-repeat:repeat-y;' width=\"30\"><img src=\"../berogui/includes/images/trans.gif\" height=\"10\" width=\"39\"></td>
		<td><p align='left'><img src=\"../berogui/includes/images/berofixlogo.png\"/></p><center><hr size= \"1\" noshade>";
	//Start text
		echo "<font face='Loma,Sans,Arial' size='5' color='#918e8c'>beroFix Configuration API</font><font face='Loma,Sans,Arial' size='2' color='#918e8c'> v." . $Version . "</font><br>";
		if(!isset($display)){
			$ret .= "<br/><br/>
			    	<table class='contenttoc' width='90%'>
					<tr><th>Commands</th></tr>";

			$ret.="<tr><td nowrap>Commands have always the following schema:</td></tr>";
			$ret.="<td nowrap>beroFix.php?cmd=[command]&data=[key1]=[value1]:[key2]=[value2]...</td></table><br/><br/><br/>";
			$ret .= "<table  class='contenttocc' width='90%'><tr><th colspan='2' textalign ='left'>Commands Overview</th></tr>";
			$ret .= "<tr><td align='left'><a href='./beroFix.php?cmd=info&data=info=setapipwd'><B>SetAPIPWD</B></td><td nowrap>Function to set the beroFix Configuration API Password</a></td></tr>";
			$ret .= "<tr><td align='left'><a href='./beroFix.php?cmd=info&data=info=setwebpwd'><B>SetWebPWD</B></td><td nowrap>Function to set the beroFix Web Password</a></td></tr>";
			$ret .= "<tr><td align='left'><a href='./beroFix.php?cmd=info&data=info=setprovtype'><B>SetProvType</B></td><td>Function to set the beroFix provisioning mode to tftp or http</a></td></tr>";
			$ret .= "<tr><td align='left'><a href='./beroFix.php?cmd=info&data=info=settftp'><B>SetTFTP</B></td><td>Function to set TFTP Server and URL</a></td></tr>";
			$ret .= "<tr><td align='left'><a href='./beroFix.php?cmd=info&data=info=sethttp'><B>SetHTTP</B></td><td>Function to set HTTP Server and URL</a></td></tr>";

			$ret .= "<tr><td align='left'><a href='./beroFix.php?cmd=info&data=info=getlif'><B>GetLif</B></td><td>Function to get detected Lineinterfaces.</td></tr>";
			$ret .= "<tr><td align='left'><a href='./beroFix.php?cmd=info&data=info=getinfo'><B>GetInfo</B></td><td>Function to get Version infos for HW Revison or firmware ...</td></tr>";
			$ret .= "<tr><td align='left'><a href='./beroFix.php?cmd=info&data=info=getisdnstate'><B>GetISDNState</B></td><td>Function to get the state of each configured ISDN port</td></tr>";
			$ret .= "<tr><td align='left'><a href='./beroFix.php?cmd=info&data=info=getisdnstats'><B>GetISDNStats</B></td><td>Function to get ISDN Layer 1 / Layer 2 statistics.</td></tr>";
			$ret .= "<tr><td align='left'><a href='./beroFix.php?cmd=info&data=info=getanalogstate'><B>GetAnalogState</B></td><td>Function to get the state of each configured analog port</td></tr>";
			$ret .= "<tr><td align='left'><a href='./beroFix.php?cmd=info&data=info=getsipstate'><B>GetSIPState</B></td><td>Function to get the state of each SIP Registar</td></tr>";
			$ret .= "<tr><td align='left'><a href='./beroFix.php?cmd=info&data=info=getisgwinfo'><B>GetISGWInfo</B></td><td>Function to get the several infos from ISGW (Telnet Wrapper).</td></tr>";

			$ret .= "<tr><td align='left'><a href='./beroFix.php?cmd=info&data=info=logging'><B>Logging</B></td><td>Function to control logging features on berofix</td></tr>";

			$ret .= "<tr><td align='left'><a href='./beroFix.php?cmd=info&data=info=config_update'><B>Config_Update</B></td><td>Function to start Config Update via TFTP or HTTP depending on how setprovtype is set</td></tr>";
			$ret .= "<tr><td align='left'><a href='./beroFix.php?cmd=info&data=info=firmware_update'><B>Firmware_Update</B></td><td>Function to start Firmware update via TFTP or HTTP depending on how setprovtype is set</td></tr>";
			$ret .= "<tr><td align='left'><a href='./beroFix.php?cmd=info&data=info=berocloud'><B>beroCloud</B></td><td>Function to enable Monitoring for beroNet's Cloud solution</td></tr>";
			$ret .= "<tr><td align='left'><a href='./beroFix.php?cmd=info&data=info=createconfig'><B>CreateConfig</B></td><td>Function to create and download config files</td></tr>";
			$ret .= "<tr><td align='left'><a href='./beroFix.php?cmd=info&data=info=restoreoldconfig'><B>RestoreOldConfig</B></td><td>Function to Restore the previous provisioning config</td></tr>";

			$ret .= "<tr><td align='left'><a href='./beroFix.php?cmd=info&data=info=fulltrace'><B>Fulltrace</B></td><td>Function start/stop/download a Fulltrace</td></tr>";
			$ret .= "<tr><td align='left'><a href='./beroFix.php?cmd=info&data=info=reload'><B>Reload</B></td><td>Function Reload with new settings</td></tr>";
			$ret .= "<tr><td align='left'><a href='./beroFix.php?cmd=info&data=info=reboot'><B>Reboot</B></td><td>Function to Reboot berofix</td></tr>";

			$ret .= "<tr><td align='left'><a href='./beroFix.php?cmd=info&data=info=smslist'><B>SmsList</B></td><td>Function to list SMS Queues</td></tr>";
			$ret .= "<tr><td align='left'><a href='./beroFix.php?cmd=info&data=info=smsget'><B>SmsGet</B></td><td>Function to get SMS</td></tr>";
			$ret .= "<tr><td align='left'><a href='./beroFix.php?cmd=info&data=info=smssend'><B>SmsSend</B></td><td>Function to send SMS</td></tr>";
			$ret .= "<tr><td align='left'><a href='./beroFix.php?cmd=info&data=info=smsdelete'><B>SmsDelete</B></td><td>Function to delete SMS</td></tr>";

			$ret .= "<tr><td align='left'><a href='./beroFix.php?cmd=info&data=info=healthcheck'><B>HealthCheck</B></td><td>Function to check the health state of the berofix</td></tr>";
			$ret.="</table><br/>";

		}else{
			$ret= $display;
		}
		echo $ret;
		//FOOTER
		echo "<hr size= \"1\" noshade><br/><table align='right'>
			<tr><td></td></tr>
			<tr><td><a href=\"http://www.beronet.com\" target=\"_blank\" onfocus=\"if (this.blur()) { this.blur(); }\">
						<img src=\"../berogui/includes/images/beroLogo.gif\" align=\"right\" border=\"0\">
					</a>
			</td></tr></table>";
		echo "</center></td></tr>
		<tr><td colspan=\"2\" style=\"background-repeat:no-repeat\" background=\"../berogui/includes/images/bg_bottom.png\">
			<img src=\"../berogui/includes/images/trans.gif\" border=\"0\" height=\"39\" width=\"10\">
			<div style=\"color: white;\" align=\"right\">&nbsp;&nbsp;&nbsp;</div>
		</td></tr></body></html>";

	function misdnportinfo(){
		exec('/usr/local/bin/misdnportinfo',$result);
        $resultstring="misdnportinfo:\n";
        foreach($result as $row){
        		$resultstring.= $row . "\n";
		}
        return $resultstring;
	}
	function smslist(){
			global $data;
			$data=split("=",$data);
            if(count($data)!=2) return "smslist:failed:smslist_requires_1_parameter\n";
                $queue=$data[1];
                $strpath="/tmp/sms/".$queue;
				if ($handle = @opendir($strpath)) {
					while (false !== ($file = readdir($handle))) {
						if ($file != "." && $file != "..") {
							if ($queue!="failout" && preg_match("/.*\.sms$/",$file)){
								echo basename($file,".sms")."\n";
							}elseif($queue=="failout"){
								echo $file."\n";
							}
						}
					}
				}else{
					return "smslist:failed:smslist_queue_not_found\n";
				}
            return "smslist:success";
	}
	function smsget(){
			global $data;
			$data=split(":",$data);
            if(count($data)<2) return "smsget:failed:smsget_requires_at_least_2_parameter\n";
                $queue=split("=",$data[0]);
                $queue=$queue[1];
                $id=split("=",$data[1]);
                $id=$id[1];
                if (isset($data[2])){
					$delete=split("=",$data[2]);
					$delete=$delete[1];
				}
                $strpath="/tmp/sms/".$queue."/";
                if ($queue=="failout"){
					echo @file_get_contents($strpath.$id."/message")."\n";
					echo @file_get_contents($strpath.$id."/message.log")."\n";
					if ($delete=="yes"){
						@unlink($strpath.$id."/message");
						@unlink($strpath.$id."/message.log");
						@rmdir($strpath.$id);
					}

				}elseif($queue=="out"){
					echo @file_get_contents($strpath.$id.".sms")."\n";
					echo @file_get_contents($strpath.$id.".sms.log")."\n";
					if ($delete=="yes"){
						@unlink($strpath.$id.".sms");
						@unlink($strpath.$id.".sms.log");
					}
				}else if($queue=="in"){
					echo @file_get_contents($strpath.$id.".sms")."\n";
					if ($delete=="yes") @unlink($strpath.$id.".sms");
				}
            return "smsget:success";
	}
	function smsdelete(){
			global $data;
			$data=split(":",$data);
            if(count($data)!=2) return "smsdelete:failed:smsdelete_requires_2_parameters\n";
                $queue=split("=",$data[0]);
                $queue=$queue[1];
                $id=split("=",$data[1]);
                $id=$id[1];

                $strpath="/tmp/sms/".$queue."/";
                if ($queue=="failout"){
					@unlink($strpath.$id."/message");
					@unlink($strpath.$id."/message.log");
					@rmdir($strpath.$id);
				}elseif($queue=="out"){
					@unlink($strpath.$id.".sms");
					@unlink($strpath.$id.".sms.log");
				}else if($queue=="in"){
					@unlink($strpath.$id.".sms");
				}
            return "smsdelete:success";
	}
	function smssend(){
			global $data;
			$data=explode(":",$data,3);
            if(count($data)!=3) return "smssend:failed:smssend_requires_3_parameters\n";
                $num=split("=",$data[0]);
                $num=$num[1];
                if (!preg_match('~^(\+{0,1}[0-9]{1,70})~',$num)  || $num=="") return "smssend:failed:invalid_phone_number\n";
                $port=split("=",$data[1]);
                $port=$port[1];
                $msg=split("=",$data[2]);
                $msg=$msg[1];
                if (strlen($msg>670)) return "smssend:failed:message_too_long\n";

                $strpath = "/tmp/sms/out/".uniqid().".sms";
				// Open the file to get existing content
				$content = "num=".$num."\n".
							"port=".$port."\n".
							"msg=".$msg;
				// Write the contents back to the file
				file_put_contents($strpath, $content);

            return "smssend:success";
	}
	function getcdr(){
			$strpath="/usr/conf/";
			global $data;
			$db=new beroAri($strpath . "ari.db");
			if ($data=="log=yes"){
				$db->set("logcdr","1");
				return "getcdr:success" ."\n";
			}
			if ($data=="log=no"){
				$db->set("logcdr","0");
				return "getcdr:success" ."\n";
			}
			if ($data=="action=download"){
				if ($db->get("logcdr")=="1"){
					if (!file_exists("/tmp/isgw.cdr.gz")){
						$isgw = new isgwtelnet();
						$isgw->isgw_login();
						$isgw->flush_cdr();
						sleep(4);
					}
					if (file_exists("/tmp/isgw.cdr.gz")){
						$file = file("/tmp/isgw.cdr.gz");
						$file2 = implode("", $file);
						header("Content-Type: application/force-download");
						header("Content-Disposition: attachment; filename=isgw.cdr.gz\r\n\r\n");
						header("Content-Length: ".strlen($file2)."\n\n");
						echo $file2;
						return "getcdr:success" ."\n";

					}else{
						return "getcdr:failed:CDRs are not avaliable\n";
					}
				}else{
					return "getcdr:failed:cdrlog must be activated\n";
				}
			}
			if ($data=="action=delete")return "getcdr:delete success" ."\n";

	}
	function healthcheck(){
			exec('/usr/bin/uptime',$resup);
			preg_match("/.*load average: (.*),.*,.*/",$resup[0],$load);
			exec('/usr/bin/free',$resup);
			preg_match("/.*Mem:[ ]*[0-9]*[ ]*[0-9]*[ ]*([0-9]*)[ ]*[0.9]*[ ]*[0-9]*[ ]*/",$resup[2],$free_mem);

        //Coredump
        (file_exists("/tmp/debug-info.tar.gz")) ? $coredump=1 : $coredump=0;

		return ' CPU Load: '.$load[1].'\n Free RAM: '. $free_mem[1].'\n';

	}
	function fulltrace(){
		$strpath="/usr/conf/";
		global $data;
		$db=new beroAri($strpath . "ari.db");
		$qu = $db->select("select * from isdn");
		$ports="";
		//Alle Einträge von der Abfrage werden durchgelaufen
			while ($entry = $db->fetch_array($qu)) {
				if ($ports != "")
					$ports .= "," .  $entry['port'];
				else
					$ports .=  $entry['port'];

			}
			if ($data=="action=stop"){
					system("/usr/bin/killall tcpdump");
					system("/usr/bin/killall mISDNdebugtool");
					system("/sbin/rmmod mISDN_debugtool");
					//tar.gz erzeugen
					exec("/bin/rm /tmp/DebugFiles.tar.gz");
					$splitports = split(',', $ports);
					$files = "";
					foreach ($splitports as $value) {
						if (file_exists("/tmp/ISDNdebug-$value")) {
							if ($files != "")
								$files .= " ISDNdebug-" . $value;
							else
								$files .= "-C /tmp/ ISDNdebug-" . $value;
						}
					}
					if (file_exists("/tmp/tcpDump")) {
						if ($files != "")
							$files .= " tcpDump";
						else
							$files .= "-C /tmp/ tcpDump";
					}
					if (file_exists("/tmp/tcpDump.lo")) {
						if ($files != "")
							$files .= " tcpDump.lo";
						else
							$files .= "-C /tmp/ tcpDump.lo";
					}
					$err_files=glob("/tmp/isgw.err*");
					foreach($err_files as $file) {
						//echo basename($file)."<br/>";
						$files.=" ".basename($file);
					}
					$log_files=glob("/tmp/isgw.log*");
					foreach($log_files as $file) {
						//echo basename($file)."<br/>";
						$files.=" ".basename($file);
					}
					$files.=" /usr/conf ";
					exec("/bin/tar -czf /tmp/DebugFiles.tar.gz " . $files);
					exec("/bin/rm /tmp/ISDNdebug*");
					exec("/bin/rm /tmp/tcpDump");
					exec("/bin/rm /tmp/tcpDump.lo");
					$db->set("trace","no");
					return "fulltrace:success" ."\n";
			}
			if ($data=="action=download"){
				if (file_exists("/tmp/DebugFiles.tar.gz")){
					$file = file("/tmp/DebugFiles.tar.gz");
					$file2 = implode("", $file);
					header("Content-Type: application/force-download");
					header("Content-Disposition: attachment; filename=DebugFiles.tar.gz\r\n\r\n");
					header("Content-Length: " . strlen($file2) . "\n\n");
					echo $file2;
				}
				return "fulltrace:success" ."\n";

			}
			$data=split(":",$data);
			if(count($data)!=3)return "fulltrace:failed:fulltrace_requires_3_parameters\n";
			$tmp=split("=",$data[0]);
			$action=$tmp[1];
			$tmp=split("=",$data[1]);
			$sipsign=$tmp[1];
			$tmp=split("=",$data[2]);
			$sipaudio=$tmp[1];
			if ($db->get("trace")=="no" && $action=="start"){
				$db->set("trace","yes");
				if ($ports != "" ){
					exec("/sbin/insmod /usr/local/modules/mISDN_debugtool.ko");
					exec("/usr/local/bin/mISDNdebugtool -d -s 5000 -f /tmp/ISDNdebug -p " . $ports);
				}
				if ($sip_sign=='yes' && $sip_audio=='yes'){
					exec("/usr/local/sbin/tcpdump -s0 -w /tmp/tcpDump -C 2 > /dev/null &");
					exec("/usr/local/sbin/tcpdump -i lo -s0 -w /tmp/tcpDump.lo -C 2 > /dev/null &");
				}

				if ($sip_sign=='yes' && $sip_audio=="no"){
					exec("/usr/local/sbin/tcpdump -s0 -w /tmp/tcpDump -C 2 udp port ".$this->udp()." > /dev/null &");
					exec("/usr/local/sbin/tcpdump -i lo -s0 -w /tmp/tcpDump.lo -C 2 udp port ".$this->udp()." > /dev/null &");
				}
				return "fulltrace:success" ."\n";
			}else{
				return "fulltrace:full trace is already running" ."\n";
			}
	}
	function setapipwd(){
				global $data;
				$tmp=split("=",$data);
                if (count($tmp)!=2) return "setapipwd:error:requires_1_parameter" ."\n";
                $pwd=$tmp[1];
                $pwd=$tmp[1];
                if($pwd!=""){
               		@unlink("/usr/conf/apiusers.conf");
                	$handle = fopen("/usr/conf/apiusers.conf","w");
                	fputs($handle, "admin:". $pwd);
                	fclose($handle);
                	return "setapipwd:success" ."\n";
				}else{
					return "setapipwd:error:empty_password_not_allowed" ."\n";
				}
	}
	function setwebpwd(){
			global $data;
			$data=split(":",$data);
            if(count($data)!=2) return "setwebpwd:failed:setwebpwd_requires_2_parameters\n";
                $tmp=split("=",$data[0]);
                $opwd=$tmp[1];
                $tmp=split("=",$data[1]);
                $npwd=$tmp[1];
                $strpath="/usr/conf/";
				$db=new beroAri($strpath . "ari.db");
                $strsql=$db->select("SELECT password from users");
                $old_encyptedpwd=$db->fetch_array($strsql);
				require_once("../berogui/includes/password_func.php");
				if (tep_validate_password($opwd,$old_encyptedpwd['password'])){
					$pass=tep_encrypt_password($npwd);
					$strsql=$db->update("UPDATE users SET password='".$pass."' where user='admin'");
				}else{
					return "setwebpwd:failed:oldpwd_does_not_match";
				}
            return "setwebpwd:success";
	}
	function getsipstate(){
				$error=0;
                $isgw=new isgwtelnet();
                $result=$isgw->isgw_login();
				if(!$result)return "getsipstate:error" ."\n";
                $isdnresult=$isgw->isgw_sipstate();
				return "getsipstate:success" ."\n" . $isdnresult;
    }
    function getanalogstate(){
				$error=0;
                $isgw=new isgwtelnet();
                $result=$isgw->isgw_login();
				if(!$result)return "getanalogstate:error" ."\n";
                $analogresult=$isgw->isgw_analogstate();
				return "getanalogstate:success" ."\n" . $analogresult;
	}
    function getisdnstate(){

			$error=0;
            $isgw=new isgwtelnet();
            $result=$isgw->isgw_login();
			if(!$result)return "getisdnstate:error" ."\n";
            $isdnresult=$isgw->isgw_isdnstate();
			return "getisdnstate:success" ."\n" . $isdnresult;
	}
	function getisdnstats(){
			exec('/bin/cat /proc/l1_stats',$result);
        	foreach($result as $row){
        		$l1string.= $row . "\n";
			}
			exec('/bin/cat /proc/l2_stats',$result2);
        	foreach($result2 as $row2){
        		$l2string.= $row2 . "\n";
			}
			return "getisdnstats:success" . "\nLAYER1:\n" . $l1string . "\nLAYER2:\n" . $l1string;
	}
	function getisgwinfo(){
				global $data;
				$data=split(":",$data);
            	$ct=count($data);
            	if(count($data)!=1) return "getisgwinfo:failed:getisgwinfo_requires_1_parameter\n";
                $tmp=split("=",$data[0]);
                $command=$tmp[1];

				if ($command!=""){
					$error=0;
					$isgw=new isgwtelnet();
					$result=$isgw->isgw_login();
					if(!$result)return "getisgwinfo:error" ."\n";
					$isgwresult=$isgw->isgw_transparent($command);
					return "getisgwinfo:success" ."\n" . $isgwresult;
				}else{
					return "getisgwinfo:error" ."\n";
				}
	}
	function reload(){
				$error=0;
                $isgw=new isgwtelnet();
                $result=$isgw->isgw_login();
				if(!$result)$error=1;
                $result=$isgw->isgw_dialplanreload();
				if(!$result)$error=1;
                $result=$isgw->isgw_sipreload();
				if(!$result)$error=1;
                $strpath="/usr/conf/";
				$db=new beroAri($strpath . "ari.db");
				if(!$error){
					$strsql="Update activate set option=0 where option=1";
					$res=$db->delete($strsql);
                	return "reload:success";
                }else{
                	return "reload:error";
				}
	}

    function restart(){
		$result=exec('/usr/local/init/S50isgw stop');
        $result=exec('/usr/local/init/S10li-setup stop');
		$result=exec('/usr/local/init/S10li-setup start');
		$result=exec('/usr/local/init/S50isgw start');
		$strpath="/usr/conf/";
		$db=new beroAri($strpath . "ari.db");
		if($result){
			$strsql="Update activate set option=0";
			$res=$db->delete($strsql);
			return "restart:success";
		}else{
			return "restart:error";
		}
	}
    function reboot(){
		$result=exec('/sbin/reboot');
        return "reboot:rebooting....";
	}
    function restoreoldconfig(){
		$result=exec('/usr/local/bin/update-tftp.sh restore');
        return $result;
	}
	function settftp(){
				global $data;
				//echo $cmd . $data ."\n";
                $bc=new beroConf('root');
                $data=split(":",$data);
                if(count($data)!=3){
                	return "settftp:failed:settftp_requires_3_parameters\n";
                }
                $tmp=split("=",$data[0]);
                $tftphost=$tmp[1];
                $tmp=split("=",$data[1]);
                $tftpurl=$tmp[1];
                $tmp=split("=",$data[2]);
                $tftponboot=$tmp[1];
                if ($tftponboot =="yes" || $tftponboot=="no")
                {
                	$bc->set("root","tftp-host",$tftphost);
                	$bc->set("root","tftp-url",$tftpurl);
                	$bc->set("root","use-boot-prov",$tftponboot);
                	return "settftp:success\n";
                }else{
                	return "settftp:failed:valid_values_for_tftponboot_are[yes|no]\n";
				}
	}
	function sethttp(){
				//echo $cmd . $data ."\n";
				global $data;
                $bc=new beroConf('root');
                $data=split(":",$data);
                if(count($data)!=3 && count($data)!=4){
                	return "sethttp:failed:sethttp_requires_3_parameters\n";
                }
				for ($i = 0; $i < count($data) ; $i++)
				{
					if(substr_count($data[$i],"=")==1){
						$tmp=split("=",$data[$i]);
					}else{
						$pos=strpos($data[$i],"=");
						$tmp[0]=substr($data[$i],0,$pos);
						$tmp[1]=substr($data[$i],$pos+1);
					}
					switch ($tmp[0]){
						case 'httphost':
							$httphost=$tmp[1];
							//echo "host" . $httphost . "<br>";
							break;
						case 'httpurl':
							$httpurl=$tmp[1];
							//echo "URL" . $httpurl . "<br>";
							break;
						case 'httpport':
							$httpport=$tmp[1];
							//echo "port" . $httpport . "<br>";
							break;
						case 'httponboot':
							$httponboot=$tmp[1];
							if ($httponboot !="yes" && $httponboot!="no"){
								return "sethttp:failed:valid_values_for_httponboot_are[yes|no]\n";
							}
							break;
						default:
							return "sethttp:failed:unkown_key:" . $tmp[0] . "\n";
					}

				}

				$bc->set("root","http-host",$httphost);
                if($httpport==""){
                	$bc->set("root","http-host",$httphost);
                }else{
					$bc->set("root","http-host",$httphost . ":" . $httpport);
				}
				$bc->set("root","http-url",$httpurl);
                $bc->set("root","use-boot-prov",$httponboot);
                return "sethttp:success\n";
	}
	function logging(){
		global $data;
			$data=split(":",$data);
            $ct=count($data);

            if(count($data)!=4) return "logging:failed:logging_requires_at_least_4_parameters\n";

                $tmp=split("=",$data[0]);
                $active=$tmp[1];
                $tmp=split("=",$data[1]);
                $loglevel=$tmp[1];
                $tmp=split("=",$data[2]);
                $logserver=$tmp[1];
                $tmp=split("=",$data[3]);
                $logport=$tmp[1];


            	//isgwlogin
            		$isgw=new isgwtelnet();
                	$result=$isgw->isgw_login();
					if(!$result)$error=1;
					usleep(500);
                //set Logserver and Port
                	$result=$isgw->logserver($logserver,$logport);
					if(!$result)$error=1;
					//echo  "ls:" . $logserver . " lp:" . $logport. "<br>";
					usleep(500);
				//loglevel

                	$result=$isgw->isgw_login();
                	$result=$isgw->loglevel_message($loglevel);
					if(!$result)$error=1;
					//echo "ll:" . $loglevel . "<br>";
					usleep(500);
                //logmessage start
                	$result=$isgw->isgw_login();
                	$result=$isgw->logactive_message($active);
					if(!$result)$error=1;
					//echo "logmessage state:" . $active . "<br>";
					usleep(500);
				//netlog on
					$result=$isgw->isgw_login();
                	$result=$isgw->logactive($active);
					if(!$result)$error=1;
					//echo "netlog state:" . $active . "<br>";

            	return "logging:success";
	}
	function createconfig (){
			chdir("/tmp/");
            if(file_exists("beroconfig.tar.gz"))unlink("beroconfig.tar.gz");
            chdir("/usr/conf/");
            $result=exec('tar -czf /tmp/beroconfig.tar.gz hardware.conf isgw.tones isgw.dialplan isgw.sip isgw.conf isgw.isdn misc.conf isgw.analog isgw.causes');
            echo "createconfig:success";
            return "<script>window.location='config_download.php';</script>";
	}
	function setprovtype(){
				global $data;
				//echo $cmd . $data ."\n";
                $bc=new beroConf('root');
				$tmp=split("=",$data);
				if (count($tmp)!=2){
                	return "setprovtype:error:requires_1_parameter" ."\n";
                }
                $prov_type=$tmp[1];
                if ($prov_type =="http" || $prov_type=="tftp"){
                	$bc->set("root","provisioning-option",$prov_type);
                	return "setprovtype:success\n";
                }else{
                	return "setprovtype:failed:valid_values_for_setprovtype_are[http|tftp]\n";
			    }
	}
	function config_update(){
            $resultstring=exec('/usr/local/bin/update-tftp.sh config', $out);
            foreach ($out as $str) {
                if (preg_match("/FAILURE:(.*)/", $str, $matches)) {
                    $resultstring="$resultstring<br>$matches[1]";
                }
            }
            return $resultstring;
	}
	function firmware_update(){
			$resultstring=exec('/usr/local/bin/update-tftp.sh firmware');
            return $resultstring;
	}
	function getinfo(){
			//ROOTFS VERSION
			global $Version;
			$f=@file("/VERSION");
            $tmp=split("=",$f[1]);
            $rootfs=$tmp[1];
            $resultstring="ROOTFSVersion:" . $rootfs . "\n";

			//APPFS VERSION
			$bc = new beroConf('root');
			$appfs=$bc->get("root", "app-image");
			$resultstring.="APPFSVersion:" . $appfs . "\n";

			//HW REVISION
			exec('/bin/cat /proc/cmdline',$res);
            preg_match("/[^a-zA-Z0-9=]*?n=(?<number>.+)/",$res[0],$hwrev);
            $resultstring.="HWRevision:" . $hwrev[number] . "\n";

			//Serial
			preg_match("/[^a-zA-Z0-9=]*?d=(?<zahlen>.+)/",$res[0],$serial);
			$resultstring.="HWSerial:" . $serial[zahlen] . "\n";

			//MAC
			exec('/sbin/ifconfig eth0 | /bin/grep HWaddr',$resm);
            preg_match("/[^a-zA-Z0-9:]*? HWaddr (?<mac>.+)/",$resm[0],$mac);
            $resultstring.="MAC:" . $mac[mac] . "\n";

			//FPGA VERSION
			$fpga=exec("/bin/cat /proc/FPGA_VERSION");
			$resultstring.="FPGAVersion:" . $fpga . "\n";

			//API Version
			$resultstring.="APIVersion:" . $Version . "\n";
			return $resultstring;

	}
	function getlif(){
		exec('/bin/cat /proc/li*',$resl);
        $i=0;
        foreach ($resl as $zeile){
				preg_match("/type: (?<li>.+)/",$zeile,$lif);

				if (($lif[li]!="unknown") && ($lif[li]!="")){
						if ($lif[li]=="si-4fxo") $type="bf4FXO";
						if ($lif[li]=="si-4fxs") $type="bf4FXS";
						if ($lif[li]=="xhfcSi-2s02fxs") $type="bf2S02FXS";
						if ($lif[li]=="xhfc-4su") $type="bf4S0";
						if ($lif[li]=="hfc-e1") $type="bf1E1";
						if ($lif[li]=="hfc-2e1") $type="bf2E1";
						if ($lif[li]=="telit-1GSM") $type="bf1GSM";
						if ($lif[li]=="telit-2GSM") $type="bf2GSM";
						if ($lif[li]=="falc-2e1/t1") $type="bf2GSM";
						$resultstring.="lif:" . $i . ";type:" . $type . "\n" ;
						//echo "lif:" . $i . ";type:" . $type . "\n<br>" ;
						$i++;
				}
		}
		return $resultstring;
	}
	function berocloud(){
				global $data;
				//echo $cmd . $data ."\n";
                $bc=new beroConf('root');
                $data=split(":",$data);
                if(count($data)!=2){
                	return "berocloud:failed:cloud_requires_2_parameters\n";
                }
                $tmp=split("=",$data[0]);
                $cloud_enable=$tmp[1];
                $tmp=split("=",$data[1]);
                $cloud_key=$tmp[1];

                if (($cloud_enable=='1') || ($cloud_enable=='0')){
                	$bc->set("root","cloud_enable",$cloud_enable);
                	$bc->set("root","cloud_key",$cloud_key);
                	return "berocloud:success\n";
                }else{
                	return "berocloud:failed:valid_values_for_cloud_enable[1|0]\n";
				}
	}

	function infocmd ($sinfo) {

		$bc=new beroConf('root');
		$IPADDRESS=$bc->get('root','lan-ipaddr');
		if ($sinfo=="setapipwd"){
			$title=$sinfo;
			$helptext="Function to set the beroFix Configuration API Password";
			$usage=array("[command]=setapipwd","[key]=password","[value]=[yourpassword]","Example: http://" . $IPADDRESS . "/app/api/beroFix.php?cmd=setapipwd&data=password=admin");
			$return=array("setapipwd:success -> if everthing was ok.","setapipwd:error -> if an error occured.");
		 }
		 elseif ($sinfo=="smslist"){
			$title=$sinfo;
			$helptext="Function to list the SMS Queues.";
			$usage=array("[command]=smslist","[key]=queue","[value]=[queuename]","Example: http://" . $IPADDRESS . "/app/api/beroFix.php?cmd=smslist&data=queue=failout");
			$return=array("smslist:success -> if everthing was ok.","smslist:error -> if an error occured.");
		 }
		 elseif ($sinfo=="smsget"){
			$title=$sinfo;
			$helptext="Function to get a SMS.";
			$usage=array("[command]=smsget","[key1]=queue","[value1]=[queuename]","[key2]=idx","[value2]=[smsid]","[key3]=delete","[value3]=[yes] <i>just if you want to delete the sms</i>","Example: http://" . $IPADDRESS . "/app/api/beroFix.php?cmd=smsget&data=queue=out:idx=000013fb09d06:delete=yes");
			$return=array("smsget:success -> if everthing was ok.","smsget:error -> if an error occured.");
		 }
		 elseif ($sinfo=="smsdelete"){
			$title=$sinfo;
			$helptext="Function to delete a SMS.";
			$usage=array("[command]=smsdelete","[key1]=queue","[value1]=[queuename]","[key2]=idx","[value2]=[smsid]","Example: http://" . $IPADDRESS . "/app/api/beroFix.php?cmd=smsdelete&data=queue=out:idx=000013fb09d06");
			$return=array("smsdelete:success -> if everthing was ok.","smsdelete:error -> if an error occured.");
		 }
		 elseif ($sinfo=="healthcheck"){
			$title=$sinfo;
			$helptext="Function to check the health state of the berofix.";
			$usage=array("[command]=healthcheck","Example: http://" . $IPADDRESS . "/app/api/beroFix.php?cmd=healthcheck");
			$return=array("CPU Load:[number]","Free RAM:[number]");
		 }
		 elseif ($sinfo=="smssend"){
			$title=$sinfo;
			$helptext="Function to send a SMS.";
			$usage=array("[command]=smssend","[key1]=num","[value1]=[phonenumber] <i>HTML special characters have to be replaced</i>","[key2]=port","[value2]=[portnumber]","[key3]=msg","[value3]=[message] <i>HTML special characters have to be replaced</i>","Example: http://" . $IPADDRESS . "/app/api/beroFix.php?cmd=smssend&data=num=%2B123456:port=1:msg=This is the message");
			$return=array("smssend:success -> if everthing was ok.","smssend:error -> if an error occured.");
		 }
		 elseif ($sinfo=="fulltrace"){
			$title=$sinfo;
			$helptext="Function start,stop and download a Fulltrace on the berofix for support reasons.<br>Download File (DebugFiles.tar.gz) to analyze with Wireshark.";
			$usage=array("[command]=fulltrace","[key1]=action","[value1]=[start|stop|download]","[key2]=sipsig","[value2]=[yes|no] <i>only set if action=start</i>","[key3]=sipaudio","[value3]=[yes|no] <i>only set if action=start</i>","Examples:","<a href='./beroFix.php?cmd=fulltrace&data=action=start:sipsig=yes:sipaudio=no'>Start: http://" . $IPADDRESS . "/app/api/beroFix.php?cmd=fulltrace&data=action=start:sipsig=yes:sipaudio=no","<a href='./beroFix.php?cmd=fulltrace&data=action=stop'>Stop: http://" . $IPADDRESS . "/app/api/beroFix.php?cmd=fulltrace&data=action=stop","<a href='./beroFix.php?cmd=fulltrace&data=action=download'>Download: http://" . $IPADDRESS  ."/app/api/beroFix.php?cmd=fulltrace&data=action=download");
			$return=array("fulltrace:success -> if everthing was ok.","fulltrace:error -> if an error occured.");
		 }
		 elseif ($sinfo=="setwebpwd"){
			$title=$sinfo;
			$helptext="Function to set the beroFix Web Password";
			$usage=array("[command]=setwebpwd","[key1]=oldpassword","[value1]=[oldpassword]","[key2]=newpassword","[value2]=[newpassword]","<a href='./beroFix.php?cmd=setwebpwd&data=oldpassword=admin:newpassword=admin'>Example: http://" . $IPADDRESS . "/app/api/beroFix.php?cmd=setwebpwd&data=oldpassword=admin:newpassword=admin" . "</a>");
			$return=array("setwebpwd:success -> if everthing was ok.","setwebpwd:error -> if an error occured.");
		 }
		 elseif ($sinfo=="setprovtype"){
			$title=$sinfo;
			$helptext="Function to set the beroFix provisioning mode to tftp or http.";
			$usage=array("[command]=setprovtype","[key]=type","[value]=[tftp|http]","Example: http://" . $IPADDRESS . "/app/api/beroFix.php?cmd=setprovtype&data=type=tftp");
			$return=array("setprovtype:success -> if everthing was ok.","setprovtype:error -> if an error occured.");
		 }
		 elseif ($sinfo=="settftp"){
			$title=$sinfo;
			$helptext="Function to set TFTP Server and URL.";
			$usage=array("[command]=settftp","[key1]=tftphost","[value1]=[tftphostIP]","[key2]=tftpurl","[value2]=[tftURL]","[key3]=tftponboot","[value3]=[yes|no]","Example: http://" . $IPADDRESS . "/app/api/beroFix.php?cmd=settftp&data=tftphost=10.0.0.1:tftpurl=berofix:tftponboot=no");
			$return=array("settftp:success -> if everthing was ok.","settftp:error -> if an error occured.");
		 }
		 elseif ($sinfo=="sethttp"){
			$title=$sinfo;
			$helptext="Function to set HTTP Server and URL.";
			$usage=array("[command]=sethttp","[key1]=httphost","[value1]=[httphostIP]","[key2]=httpurl","[value2]=[httpurl]","[key3]=httponboot","[value3]=[yes|no]","[key4]=httpport","[value4]=[httpport]","Example: http://" . $IPADDRESS . "/app/api/beroFix.php?cmd=sethttp&data=httphost=10.0.0.1:httpport=81:httpurl=berofix:httponboot=no");
			$return=array("sethttp:success -> if everthing was ok.","sethttp:error -> if an error occured.");
		 }
		elseif ($sinfo=="config_update"){
			$title=$sinfo;
			$helptext="Function to start Config Update via TFTP or HTTP depending on how setprovtype is set.";
			$usage=array("[command]=config_update","<a href='./beroFix.php?cmd=config_update'>Example: http://" . $IPADDRESS . "/app/api/beroFix.php?cmd=config_update" . "</a>");
			$return=array("config_update:Prov_type:success -> if everthing was ok","config_update:Prov_type:failed:[comments] ->TFTP / HTTP problem or no Download selected.[comments] for details","config_update:Prov_type:error -> if an major error occured. Check Config Files.");
		 }
		elseif ($sinfo=="firmware_update"){
			$title=$sinfo;
			$helptext="Function to start Firmware update via TFTP or HTTP depending on how setprovtype is set.";
			$usage=array("[command]=firmware_update","<a href='./beroFix.php?cmd=firmware_update'>Example: http://" . $IPADDRESS . "/app/api/beroFix.php?cmd=firmware_update" . "</a>");
			$return=array("firmware_update:Prov_type:success -> if everthing was ok","firmware_update:Prov_type:failed:[comments] ->TFTP / HTTP problem or no Download selected.[comments] for details","firmware_update:Prov_type:error -> if an major error occured.");
		 }
		elseif ($sinfo=="getlif"){
			$title=$sinfo;
			$helptext="Function to get currently detected Lineinterfaces.";
			$usage=array("[command]=getlif","<a href='./beroFix.php?cmd=getlif'>Example: http://" . $IPADDRESS . "/app/api/beroFix.php?cmd=getlif" . "</a>");
			$return=array("lif:Lineinterface Number","type:Lineinterface type","lif:[0|1];type:[bf4S0|bf1E1|bf2E1|bf2GSM|bf4FXO|bf4FXS]","Example:","lif:0;type:bf2E1","lif:1;type:bf4S0");
		 }
		elseif ($sinfo=="getinfo"){
			$title=$sinfo;
			$helptext="Function to get Version infos for HW Revison,Firmwareversion etc.";
			$usage=array("[command]=getinfo","<a href='./beroFix.php?cmd=getinfo'>Example: http://" . $IPADDRESS . "/app/api/beroFix.php?cmd=getinfo" . "</a>");
			$return=array("ROOTFSVersion:[number]","APPFSVersion:[number]","HWRevision:[number]","HWSerial:[number]","FPGAVersion:[number]","MAC:[macaddress]","APIVersion:[version]");
		 }
		 elseif ($sinfo=="reload"){
			$title=$sinfo;
			$helptext="Function to reload settings.";
			$usage=array("[command]=reload","<a href='./beroFix.php?cmd=reload'>Example: http://" . $IPADDRESS . "/app/api/beroFix.php?cmd=reload" . "</a>");
			$return=array("reload:success -> if everthing was ok","reload:error ->if an error occured");
		 }
		 elseif ($sinfo=="reboot"){
			$title=$sinfo;
			$helptext="Function Reboot device.";
			$usage=array("[command]=reboot","<a href='./beroFix.php?cmd=reboot'>Example: http://" . $IPADDRESS . "/app/api/beroFix.php?cmd=reboot" . "</a>");
			$return=array("reboot:rebooting... -> if reboot is initiated");
		 }
		 elseif ($sinfo=="createconfig"){
			$title=$sinfo;
			$helptext="Function to create and download 'beroconfig.tar.gz' config files.";
			$usage=array("[command]=createconfig","<a href='./beroFix.php?cmd=createconfig'>Example: http://" . $IPADDRESS . "/app/api/beroFix.php?cmd=createconfig" . "</a>");
			$return=array("createconfig:success -> if everthing was ok","createconfig:error -> if an error occured");
		 }
		 elseif ($sinfo=="getisdnstate"){
			$title=$sinfo;
			$helptext="Function to get the state of each configured ISDN port.";
			$usage=array("[command]=getisdnstate","<a href='./beroFix.php?cmd=getisdnstate'>Example: http://" . $IPADDRESS . "/app/api/beroFix.php?cmd=getisdnstate" . "</a>");
			$return=array("getisdnstate:success -> if everthing was ok","getisdnstate:error -> if an error occured");
		 }
		 elseif ($sinfo=="getisdnstats"){
			$title=$sinfo;
			$helptext="Function to get ISDN Layer1 / Layer 2 stats.";
			$usage=array("[command]=getisdnstats","<a href='./beroFix.php?cmd=getisdnstats'>Example: http://" . $IPADDRESS . "/app/api/beroFix.php?cmd=getisdnstats" . "</a>");
			$return=array("getisdnstats:success -> if everthing was ok","getisdnstats:error -> if an error occured");
		 }
		 elseif ($sinfo=="getanalogstate"){
			$title=$sinfo;
			$helptext="Function to get the state of each configured analog port.";
			$usage=array("[command]=getanalogstate","<a href='./beroFix.php?cmd=getanalogstate'>Example: http://" . $IPADDRESS . "/app/api/beroFix.php?cmd=getanalogstate" . "</a>");
			$return=array("getanalogstate:success -> if everthing was ok","getanalogstate:error -> if an error occured");
		 }
		 elseif ($sinfo=="getsipstate"){
			$title=$sinfo;
			$helptext="Function to get the state of each SIP Registar.";
			$usage=array("[command]=getsipstate","<a href='./beroFix.php?cmd=getsipstate'>Example: http://" . $IPADDRESS . "/app/api/beroFix.php?cmd=getsipstate" . "</a>");
			$return=array("getsipstate:success -> if everthing was ok","getsipstate:error -> if an error occured");
		 }
		 elseif ($sinfo=="restoreoldconfig"){
			$title=$sinfo;
			$helptext="Function to Restore the previous provisioning config.";
			$usage=array("[command]=restoreoldconfig","<a href='./beroFix.php?cmd=restoreoldconfig'>Example: http://" . $IPADDRESS . "/app/api/beroFix.php?cmd=restoreoldconfig" . "</a>");
			$return=array("restoreoldconfig:success -> if everthing was ok","restoreoldconfig:error -> if an error occured");
		}
		 elseif ($sinfo=="logging"){
			$title=$sinfo;
			$helptext="Function to logging capabilities on the berofix.";
			$usage=array("[command]=logging","[key1]=active","[value1]=[0|1]","[key2]=loglevel","[value2]=[0-9]","[key3]=logserver","[value3]=[IP-Address]","[key4]=logport","[value4]=[udpport]","<a href='./beroFix.php?cmd=logging&data=active=1:loglevel=5:logserver=172.20.5.51:logport=55555'>Example: http://" . $IPADDRESS . "/app/api/beroFix.php?cmd=logging&data=active=1:loglevel=5:logserver=172.20.5.51:logport=55555" . "</a>");
			$return=array("logging:success -> if everthing was ok","logging:error -> if an error occured");
		}
		elseif ($sinfo=="berocloud"){
			$title=$sinfo;
			$helptext="Function to enable Monitoring for beroNets Cloud solution";
			$usage=array("[command]=berocloud","[key1]=cloud_enable","[value1]=[0|1]","[key2]=cloud_key","[value2]=[CLOUDKEY]","<a href='./beroFix.php?cmd=berocloud&data=cloud_enable=1:cloud_key=5555555555'>Example: http://" . $IPADDRESS . "/app/api/beroFix.php?cmd=berocloud&data=cloud_enable=0:cloud_key=5555555555" . "</a>");
			$return=array("berocloud:success -> if everthing was ok","berocloud:error -> if an error occured");
		}
		 elseif ($sinfo=="getisgwinfo"){
			$title=$sinfo;
			$helptext="Function to get several ISGW Info Telnet Wrapper.";
			$usage=array("[command]=getisgwinfo",
			"[key]=isgwcmd","[value]=[i |r |l |k |u |bc |ss |ssp | ...]",
			"i=isdn state","r=status of registration",
			"l=status of operation","k=status of operations (compact)",
			"u=uptime of isgw","bc=list bchannel objects",
			"ss=show call statistics","ssp=show port specific call statistics",
			"or any other valid ISGW Telnet command. Press h in the","telnet interface to get a list of possible commands.",
			"<a href='./beroFix.php?cmd=getisgwinfo&data=isgwcmd=u'>Example: http://" . $IPADDRESS . "/app/api/beroFix.php?cmd=getisgwinfo&data=isgwcmd=u" . "</a>");
			$return=array("getisgwinfo:success -> if everthing was ok","getisgwinfo:error -> if an error occured");

		}
		 else{

	 	}

		$dis  = "<br/><br/>";
		$dis .= "<table  class='contenttocc' width='90%'><tr><th colspan='2' textalign ='left'>" . $title . "</th></tr>";
		$dis .= "<tr><td nowrap>" . $helptext . "</td></tr>";
		$dis .= "<tr><td>Usage: <ul>";

		foreach ($usage as $value){
				$dis.="<li>" . $value . "</li>";
		}
		$dis .="</ul></td></tr>";
		$dis.= "<tr><td>Return values:<ul>";
		foreach ($return as $value){
					$dis.="<li>" . $value . "</li>";
		}
		$dis .="</ul></td></tr></table><br/>";
		$dis .="<a href='./beroFix.php'><B> << back >></B></a>";
		return $dis;

	}
?>

