<?php


$GatewayNr = 2; //   <=================


include '/var/www/lng/lng.php'; //Sprachvariablen werden geladen
echo "<meta http-equiv=\"refresh\" content=\"5; URL=../index.php\" target=\"_parent\">";
?>

<link rel="stylesheet" href="../css/pigate.css" />

<div class="box">

<h1><?php echo $lng_set_save_top .$GatewayNr;?></span></h1>
<h3><?php echo $lng_set_save_sub ;?></h3>
<p>

<?php


// ******************************************************************************************************
// *                             Configfile des Klienten erstellen                                      *
// ******************************************************************************************************


$filename = "../datenbank/data.conf$GatewayNr";

$timestamp = time();
$datum = date("d.m.Y - H:i", $timestamp);

$data = "# Konfigurationsdatei für PiCQ-Gateway$GatewayNr\r\n";
$data .= "# Diese Datei wurde am: ". $datum. " durch das Web-UI erstellt und sollte\r\n";
$data .= "# NICHT von Hand editiert oder bearbeitet werden!!!\r\n";
$data .= "\r\n";

$data .= "[Auth]\r\n";
$data .= "Callsign=". $_POST["callsign"]. "\r\n";
$data .= "OperatorName=". $_POST["operatorname"]. "\r\n";
$data .= "EMailAddress=". $_POST["emailaddress"]. "\r\n";
$data .= "City=". $_POST["city"]. "\r\n";
$data .= "CityPart=". $_POST["citypart"]. "\r\n";
$data .= "Password=". $_POST["password"]. "\r\n";
$data .= "DynamicPassword=". $_POST["dynamicpassword"]. "\r\n";
$data .= "Country=". $_POST["country"]. "\r\n";
$data .= "Description=[http://picq.network] ". $_POST["description"]. "\r\n";
$data .= "BandChannel=". $_POST["bandchannel"]. "\r\n";
$data .= "ClientType=". $_POST["clienttype"]. "\r\n";
// $data .= "CharsetName=". $_POST["authcharsetname"]. "\r\n";
$data .= "CharsetName=WINDOWS-1252\r\n";
$data .= "ProtoShortFrames=no\r\n";
$data .= "\r\n";

$data .= "[Audio]\r\n";
$data .= "InDevice=". $_POST["indevice"]. "\r\n";
$data .= "InSampleRate=". $_POST["insamplerate"]. "\r\n";
$data .= "InQuality=". $_POST["inquality"]. "\r\n";
$data .= "InFactor=". $_POST["infactor"]. "\r\n";
$data .= "InPreCapturedTime=". $_POST["inprecapturedtime"]. "\r\n";
$data .= "InHPFEnabled=". $_POST["inhpfenabled"]. "\r\n";
$data .= "InHPFOrder=". $_POST["inhpforder"]. "\r\n";
$data .= "InHPFDouble=". $_POST["inhpfdouble"]. "\r\n";
$data .= "InAGCEnabled=". $_POST["inagcenabled"]. "\r\n";
$data .= "InAGCLevel=". $_POST["inagclevel"]. "\r\n";
$data .= "InAGCMaxGain=". $_POST["inagcmaxgain"]. "\r\n";
$data .= "InDTMFEnabled=". $_POST["indtmfenabled"]. "\r\n";
$data .= "OutDevice=". $_POST["outdevice"]. "\r\n";
$data .= "OutSampleRate=". $_POST["outsamplerate"]. "\r\n";
$data .= "OutQuality=". $_POST["outquality"]. "\r\n";
$data .= "OutFactor=". $_POST["outfactor"]. "\r\n";
$data .= "OutHPFEnabled=". $_POST["outhpfenabled"]. "\r\n";
$data .= "OutHPFOrder=". $_POST["outhpforder"]. "\r\n";
$data .= "OutHPFDouble=". $_POST["outhpfdouble"]. "\r\n";
$data .= "OutAGCEnabled=". $_POST["outagcenabled"]. "\r\n";
$data .= "OutAGCLevel=". $_POST["outagclevel"]. "\r\n";
$data .= "OutAGCMaxGain=". $_POST["outagcmaxgain"]. "\r\n";
$data .= "\r\n";

$data .= "[Radio]\r\n";
$data .= "PTT=". $_POST["ptt"]. "\r\n";
$data .= "COS=". $_POST["cos"]. "\r\n";
$data .= "STATIC=". $_POST["static"]. "\r\n";
$data .= "LIGHT=". $_POST["light"]. "\r\n";
$data .= "CTCSSWakeTime=". $_POST["ctcsswaketime"]. "\r\n";
$data .= "CarrierCatchTime=". $_POST["carriercatchtime"]. "\r\n";
$data .= "CarrierLostTime=". $_POST["carrierlosttime"]. "\r\n";
$data .= "SquelchSettlingTime=". $_POST["squelchsettlingtime"]. "\r\n";
$data .= "DtmfCommands=". $_POST["dtmfcommands"]. "\r\n";
$data .= "DtmfTimeout=". $_POST["dtmftimeout"]. "\r\n";
$data .= "\r\n";

$data .= "[Manager]\r\n";
$data .= "ManagerAddress=". $_POST["manageraddress"]. "\r\n";
$data .= "ManagerPort=". $_POST["managerport"]. "\r\n";
$data .= "DynamicPasswordMode=". $_POST["dynamicpasswordmode"]. "\r\n";
$data .= "\r\n";

$data .= "[Server]\r\n";
$data .= "ServerAddress=". $_POST["serveraddress"]. "\r\n";
$data .= "ServerPort=". $_POST["serverport"]. "\r\n";
$data .= "CharsetName=WINDOWS-1252\r\n";
$data .= "Network=". $_POST["network"]. "\r\n";
$data .= "VisibleStatus=". $_POST["visiblestatus"]. "\r\n";
$data .= "ServerReconnectCount=3\r\n";
$data .= "ServerReconnectInterval=300\r\n";
$data .= "BackupServerMode=". $_POST["backupservermode"]. "\r\n";
$data .= "ForcedBackupServerAddress=". $_POST["forcedbackupserveraddress"]. "\r\n";
$data .= "ForcedBackupServerPort=". $_POST["forcedbackupserverport"]. "\r\n";
$data .= "ForcedBackupServerNetwork=". $_POST["forcedbackupservernet"]. "\r\n";
$data .= "ProtoListFormat=frn\r\n";
$data .= "ProtoSoundAck=yes\r\n";
$data .= "ProtoUnicode=yes\r\n";
$data .= "ProtoShortFrames=no\r\n";
$data .= "ProtoCompressList=yes\r\n";
$data .= "ProtoSpeakerInfo=yes\r\n";
$data .= "\r\n";

$data .= "[Internet]\r\n";
$data .= "ProxyType=". $_POST["proxytype"]. "\r\n";
$data .= "ProxyAddress=". $_POST["proxyaddress"]. "\r\n";
$data .= "ProxyPort=". $_POST["proxyport"]. "\r\n";
// $data .= "CharsetName=". $_POST["proxycharsetname"]. "\r\n";
$data .= "CharsetName=WINDOWS-1252\r\n";
$data .= "\r\n";

$data .= "[Message]\r\n";
$data .= "PrivateAutoResponse=". $_POST["privateautoresponse"]. "\r\n";
$data .= "\r\n";

$data .= "[System]\r\n";
$data .= "WriteDir=\r\n";
$data .= "CharsetName=\r\n";
$data .= "PidFile=\r\n";
$data .= "LogFile=\r\n";
$data .= "LogControlSound=no\r\n";
$data .= "LogExternalSound=no\r\n";
$data .= "LogClientList=full\r\n";
$data .= "LogCarrier=yes\r\n";
$data .= "LogTiming=no\r\n";
$data .= "LogBackupServerMode=no\r\n";
$data .= "LogCheckServer=yes\r\n";
$data .= "LogRxWaitsPlayStop=yes\r\n";
$data .= "LogDtmfTones=no\r\n";
$data .= "LogDtmfCommands=yes\r\n";
$data .= "GpioScheme=LINUX\r\n";
$data .= "\r\n";

$data .= "[Sounds]\r\n";
$data .= "SoundsDir=". $_POST["soundsdir"]. "\r\n";
$data .= "SoundCourtesy=". $_POST["soundcourtesy"]. "\r\n";
$data .= "EnableCourtesy=". $_POST["enablecourtesy"]. "\r\n";
$data .= "SoundRoger=". $_POST["soundroger"]. "\r\n";
$data .= "EnableRoger=". $_POST["enableroger"]. "\r\n";
$data .= "SoundNoConnection=". $_POST["soundnoconnection"]. "\r\n";
$data .= "EnableNoConnection=". $_POST["enablenoconnection"]. "\r\n";
$data .= "SoundReject=". $_POST["soundreject"]. "\r\n";
$data .= "EnableReject=". $_POST["enablereject"]. "\r\n";
$data .= "SoundError=". $_POST["sounderror"]. "\r\n";
$data .= "EnableError=". $_POST["enableerror"]. "\r\n";
$data .= "SoundCourtesyEmptyNet=". $_POST["soundcourtesyemptynet"]. "\r\n";
$data .= "EnableCourtesyEmptyNet=". $_POST["enablecourtesyemptynet"]. "\r\n";
$data .= "SoundRadioBot=". $_POST["soundradiobot"]. "\r\n";
$data .= "EnableRadioBot=". $_POST["enableradiobot"]. "\r\n";
$data .= "EnableConnect=". $_POST["enableconnect"]. "\r\n";
$data .= "SoundConnect=\r\n";
$data .= "ConnectSoundCfgEnabled=yes\r\n";
$data .= "ConnectSoundCfgFileName=/opt/PiCQ/net/connsounds.cfg\r\n";
$data .= "\r\n";

$data .= "[Hours]\r\n";
$data .= "Dir=". $_POST["hoursdir"]. "\r\n";
$data .= "Enabled=". $_POST["hoursenabled"]. "\r\n";
$data .= "Interval=". $_POST["hoursinterval"]. "\r\n";
$data .= "Correction=". $_POST["correction"]. "\r\n";
$data .= "ExtEnabled=". $_POST["hoursextenabled"]. "\r\n";
$data .= "ExtScript=". $_POST["hoursextscript"]. "\r\n";
$data .= "ExtDir=". $_POST["hoursextdir"]. "\r\n";
$data .= "ExtTempDir=". $_POST["hoursexttempdir"]. "\r\n";
$data .= "\r\n";

$data .= "[Informer]\r\n";
$data .= "Enabled=". $_POST["informerenabled"]. "\r\n";
$data .= "Dir=". $_POST["informerdir"]. "\r\n";
$data .= "Interval=". $_POST["informerinterval"]. "\r\n";
$data .= "Mode=". $_POST["mode"]. "\r\n";
$data .= "SilenceEnabled=". $_POST["silenceenabled"]. "\r\n";
$data .= "SilenceInterval=". $_POST["silenceinterval"]. "\r\n";
$data .= "SilenceTime=". $_POST["silencetime"]. "\r\n";
$data .= "ExtEnabled=". $_POST["informerextenabled"]. "\r\n";
$data .= "ExtScript=". $_POST["informerextscript"]. "\r\n";
$data .= "ExtDir=". $_POST["informerextdir"]. "\r\n";
$data .= "ExtTempDir=". $_POST["informerexttempdir"]. "\r\n";
$data .= "\r\n";

// $data .= "Debug=". $_POST["debug"]. "\r\n";
$data .= "Debug=no\r\n";

$filehandle = fopen($filename, "w+") or die("Couldn't open $filename for writing!");
fwrite($filehandle, $data) or die("Couldn't write values to file!");
fclose($filehandle);


echo $lng_set_save_conf;

?>

<?php
// ******************************************************************************************************
// *                                  Datenbankfile erstellen                                           *
// ******************************************************************************************************

$datafilename = "../datenbank/data.gate$GatewayNr";

$data = "[Datenbank Datei für PiCQ-Gateway$GatewayNr]\r\n";
$data .= "[Diese Datei wurde durch das Web-UI erstellt und sollte]\r\n";
$data .= "[NICHT von Hand editiert oder bearbeitet werden!!!]\r\n";
$data .= "[]\r\n";

$data .= "[Auth]\r\n";
$data .= "Callsign=". $_POST["callsign"]. "\r\n";
$data .= "OperatorName=". $_POST["operatorname"]. "\r\n";
$data .= "EMailAddress=". $_POST["emailaddress"]. "\r\n";
$data .= "City=". $_POST["city"]. "\r\n";
$data .= "CityPart=". $_POST["citypart"]. "\r\n";
$data .= "Password=". $_POST["password"]. "\r\n";
$data .= "DynamicPassword=". $_POST["dynamicpassword"]. "\r\n";
$data .= "Country=". $_POST["country"]. "\r\n";
$data .= "Description=". $_POST["description"]. "\r\n";
$data .= "BandChannel=". $_POST["bandchannel"]. "\r\n";
$data .= "ClientType=". $_POST["clienttype"]. "\r\n";
$data .= "AuthCharsetName=WINDOWS-1252\r\n";
$data .= "ProtoShortFrames=no\r\n";
$data .= "AprsEnable=". $_POST["aprsenable"]. "\r\n";
$data .= "AprsServ=". $_POST["aprsserv"]. "\r\n";
$data .= "AprsName=". $_POST["aprsname"]. "\r\n";
$data .= "AprsPasswd=". $_POST["aprspasswd"]. "\r\n";
$data .= "AprsLong1=". $_POST["aprslong1"]. "\r\n";
$data .= "AprsLong2=". $_POST["aprslong2"]. "\r\n";
$data .= "AprsLong3=". $_POST["aprslong3"]. "\r\n";
$data .= "AprsLat1=". $_POST["aprslat1"]. "\r\n";
$data .= "AprsLat2=". $_POST["aprslat2"]. "\r\n";
$data .= "AprsLat3=". $_POST["aprslat3"]. "\r\n";

$data .= "[]\r\n";

$data .= "[Audio]\r\n";
$data .= "InDevice=". $_POST["indevice"]. "\r\n";
$data .= "InSampleRate=". $_POST["insamplerate"]. "\r\n";
$data .= "InQuality=". $_POST["inquality"]. "\r\n";
$data .= "InFactor=". $_POST["infactor"]. "\r\n";
$data .= "InPreCapturedTime=". $_POST["inprecapturedtime"]. "\r\n";
$data .= "InHPFEnabled=". $_POST["inhpfenabled"]. "\r\n";
$data .= "InHPFOrder=". $_POST["inhpforder"]. "\r\n";
$data .= "InHPFDouble=". $_POST["inhpfdouble"]. "\r\n";
$data .= "InAGCEnabled=". $_POST["inagcenabled"]. "\r\n";
$data .= "InAGCLevel=". $_POST["inagclevel"]. "\r\n";
$data .= "InAGCMaxGain=". $_POST["inagcmaxgain"]. "\r\n";
$data .= "InDTMFEnabled=". $_POST["indtmfenabled"]. "\r\n";
$data .= "OutDevice=". $_POST["outdevice"]. "\r\n";
$data .= "OutSampleRate=". $_POST["outsamplerate"]. "\r\n";
$data .= "OutQuality=". $_POST["outquality"]. "\r\n";
$data .= "OutFactor=". $_POST["outfactor"]. "\r\n";
$data .= "OutHPFEnabled=". $_POST["outhpfenabled"]. "\r\n";
$data .= "OutHPFOrder=". $_POST["outhpforder"]. "\r\n";
$data .= "OutHPFDouble=". $_POST["outhpfdouble"]. "\r\n";
$data .= "OutAGCEnabled=". $_POST["outagcenabled"]. "\r\n";
$data .= "OutAGCLevel=". $_POST["outagclevel"]. "\r\n";
$data .= "OutAGCMaxGain=". $_POST["outagcmaxgain"]. "\r\n";
$data .= "[]\r\n";

$data .= "[Radio]\r\n";
$data .= "PTT=". $_POST["ptt"]. "\r\n";
$data .= "COS=". $_POST["cos"]. "\r\n";
$data .= "STATIC=". $_POST["static"]. "\r\n";
$data .= "LIGHT=". $_POST["light"]. "\r\n";
$data .= "CTCSSWakeTime=". $_POST["ctcsswaketime"]. "\r\n";
$data .= "CarrierCatchTime=". $_POST["carriercatchtime"]. "\r\n";
$data .= "CarrierLostTime=". $_POST["carrierlosttime"]. "\r\n";
$data .= "SquelchSettlingTime=". $_POST["squelchsettlingtime"]. "\r\n";
$data .= "DtmfCommands=". $_POST["dtmfcommands"]. "\r\n";
$data .= "DtmfTimeout=". $_POST["dtmftimeout"]. "\r\n";
$data .= "[]\r\n";

$data .= "[Manager]\r\n";
$data .= "ManagerAddress=". $_POST["manageraddress"]. "\r\n";
$data .= "ManagerPort=". $_POST["managerport"]. "\r\n";
$data .= "DynamicPasswordMode=". $_POST["dynamicpasswordmode"]. "\r\n";
$data .= "[]\r\n";

$data .= "[Server]\r\n";
$data .= "ServerAddress=". $_POST["serveraddress"]. "\r\n";
$data .= "ServerPort=". $_POST["serverport"]. "\r\n";
$data .= "Network=". $_POST["network"]. "\r\n";
$data .= "ServerCharsetName=WINDOWS-1252\r\n";
$data .= "VisibleStatus=". $_POST["visiblestatus"]. "\r\n";
$data .= "ServerReconnectCount=3\r\n";
$data .= "ServerReconnectInterval=300\r\n";
$data .= "BackupServerMode=". $_POST["backupservermode"]. "\r\n";
$data .= "ForcedBackupServerAddress=". $_POST["forcedbackupserveraddress"]. "\r\n";
$data .= "ForcedBackupServerPort=". $_POST["forcedbackupserverport"]. "\r\n";
$data .= "ForcedBackupServerNet=". $_POST["forcedbackupservernet"]. "\r\n";
$data .= "[]\r\n";

$data .= "[Internet]\r\n";
$data .= "ProxyType=". $_POST["proxytype"]. "\r\n";
$data .= "ProxyAddress=". $_POST["proxyaddress"]. "\r\n";
$data .= "ProxyPort=". $_POST["proxyport"]. "\r\n";
$data .= "ProxyCharsetName=". $_POST["proxycharsetname"]. "\r\n";
$data .= "[]\r\n";

$data .= "[Message]\r\n";
$data .= "PrivateAutoResponse=". $_POST["privateautoresponse"]. "\r\n";
$data .= "[]\r\n";

$data .= "[Sounds]\r\n";
$data .= "SoundsDir=". $_POST["soundsdir"]. "\r\n";
$data .= "SoundCourtesy=". $_POST["soundcourtesy"]. "\r\n";
$data .= "EnableCourtesy=". $_POST["enablecourtesy"]. "\r\n";
$data .= "SoundRoger=". $_POST["soundroger"]. "\r\n";
$data .= "EnableRoger=". $_POST["enableroger"]. "\r\n";
$data .= "SoundNoConnection=". $_POST["soundnoconnection"]. "\r\n";
$data .= "EnableNoConnection=". $_POST["enablenoconnection"]. "\r\n";
$data .= "SoundReject=". $_POST["soundreject"]. "\r\n";
$data .= "EnableReject=". $_POST["enablereject"]. "\r\n";
$data .= "SoundError=". $_POST["sounderror"]. "\r\n";
$data .= "EnableError=". $_POST["enableerror"]. "\r\n";
$data .= "SoundCourtesyEmptyNet=". $_POST["soundcourtesyemptynet"]. "\r\n";
$data .= "EnableCourtesyEmptyNet=". $_POST["enablecourtesyemptynet"]. "\r\n";
$data .= "SoundRadioBot=". $_POST["soundradiobot"]. "\r\n";
$data .= "EnableRadioBot=". $_POST["enableradiobot"]. "\r\n";
$data .= "EnableConnect=". $_POST["enableconnect"]. "\r\n";
$data .= "SoundConnect=\r\n";
$data .= "ConnectSoundCfgEnabled=yes\r\n";
$data .= "ConnectSoundCfgFileName=/opt/PiCQ/net/connsounds.cfg\r\n";
$data .= "[]\r\n";

$data .= "[Hours]\r\n";
$data .= "HoursDir=". $_POST["hoursdir"]. "\r\n";
$data .= "HoursEnabled=". $_POST["hoursenabled"]. "\r\n";
$data .= "HoursInterval=". $_POST["hoursinterval"]. "\r\n";
$data .= "Correction=". $_POST["correction"]. "\r\n";
$data .= "HoursExtEnabled=". $_POST["hoursextenabled"]. "\r\n";
$data .= "HoursExtScript=". $_POST["hoursextscript"]. "\r\n";
$data .= "HoursExtDir=". $_POST["hoursextdir"]. "\r\n";
$data .= "HoursExtTempDir=". $_POST["hoursexttempdir"]. "\r\n";
$data .= "[]\r\n";

$data .= "[Informer]\r\n";
$data .= "InformerEnabled=". $_POST["informerenabled"]. "\r\n";
$data .= "InformerDir=". $_POST["informerdir"]. "\r\n";
$data .= "InformerInterval=". $_POST["informerinterval"]. "\r\n";
$data .= "Mode=". $_POST["mode"]. "\r\n";
$data .= "SilenceEnabled=". $_POST["silenceenabled"]. "\r\n";
$data .= "SilenceInterval=". $_POST["silenceinterval"]. "\r\n";
$data .= "SilenceTime=". $_POST["silencetime"]. "\r\n";
$data .= "InformerExtEnabled=". $_POST["informerextenabled"]. "\r\n";
$data .= "InformerExtScript=". $_POST["informerextscript"]. "\r\n";
$data .= "InformerExtDir=". $_POST["informerextdir"]. "\r\n";
$data .= "InformerExtTempDir=". $_POST["informerexttempdir"]. "\r\n";
$data .= "[]\r\n";

//$data .= "Debug=". $_POST["debug"]. "\r\n";
$data .= "Debug=no\r\n";
$data .= "[]\r\n";

$data .= "LcdDisplayAkt=". $_POST["displayakt"]. "\r\n";
$data .= "[]\r\n";

$filehandle = fopen($datafilename, "w+") or die("Couldn't open $filename for writing Database!");
fwrite($filehandle, $data) or die("Couldn't write values to Database!");
fclose($filehandle);

?>

<?php

// ******************************************************************************************************
// *                             Steuerfile für Display-Start erstellen                                 *
// ******************************************************************************************************

$displayfilename = "../datenbank/display$GatewayNr.gw";
$data = $_POST["displayakt"]. "\r\n";
	
$filehandle = fopen($displayfilename, "w+") or die("Couldn't open $displayfilename for writing Database!");
fwrite($filehandle, $data) or die("Couldn't write values to Database!");
fclose($filehandle);
?>

</p>

<p><A HREF="../index.php" target="_top"><?php echo $lng_set_save_link ;?></a></p>
</div>
<br />


<?php

echo $lng_set_save_data;

$stop = "sudo service PiCQ" .$GatewayNr ." stop";
echo exec($stop);
echo $lng_set_save_neu;

$delete = "sudo rm /opt/PiCQ/" .$GatewayNr ."/frnconsole.cfg.unix";
echo exec($delete);
$copy = "sudo cp /var/www/datenbank/data.conf" .$GatewayNr ." /opt/PiCQ/" .$GatewayNr ."/frnconsole.cfg.unix";
echo exec($copy);
$chmod = "sudo chmod 777 /opt/PiCQ/" .$GatewayNr ."/frnconsole.cfg.unix";
echo exec($chmod);

$start = "sudo service PiCQ" .$GatewayNr ." start";
echo exec($start);
// End Verschieben
?>
