>>>> Unwanted output (e.g. text/warning/error) detected before \"UnwantedOutputCheckpoint($CheckpointNumber)\" in the script ".$_SERVER['PHP_SELF']); print("\r\n"); return true; } return false; } //------------------------------------------------------------- function OutputTextlogV10($Imei,$Data) { global $cgImeiTextLogfileV10; //probeer file $fn="$cgImeiTextLogfileV10 $Imei.txt"; if (LogText("$fn",$Data)) return true; LogError("Error: Txtlog append error: $fn"); return false; } //------------------------------------------------------------- function OutputTextlogV12($Imei,$Data) { global $cgUrlLocalHost; global $cgPortV12Txt; global $cgImeiTextLogfileV12; // probeer eerst socket if($fp=fsockopen($cgUrlLocalHost,$cgPortV12Txt,$errstr,$errno,5)) { fputs($fp,$Data); fclose($fp); return true; } //als dat niet ging: geef waarschuwing en probeer file LogError("Warning: Error opening txt socket URL $cgUrlLocalHost:$cgPortV12Txt IMEI: $Imei, trying filewrite"); $fn="$cgImeiTextLogfileV12 $Imei.txt"; LogInfo("Writing: $fn"); if (LogText("$fn",$Data)) return true; LogError("Error: Txtlog append error: $fn"); return false; } //------------------------------------------------------------- function OutputTextlogV13($Imei,$Data) { global $cgUrlLocalHost; global $cgPortV13Txt; global $cgImeiTextLogfileV13; // probeer eerst socket if($fp=@fsockopen($cgUrlLocalHost,$cgPortV13Txt,$errstr,$errno,5)) { @fputs($fp,$Data); @fclose($fp); return true; } //als dat niet ging: geef waarschuwing en probeer file LogError("Warning: Error opening txt socket URL $cgUrlLocalHost:$cgPortV13Txt IMEI: $Imei, trying filewrite"); $fn="$cgImeiTextLogfileV13 $Imei.txt"; LogInfo("Writing: $fn"); if (LogText("$fn",$Data)) return true; LogError("Error: Txtlog append error: $fn"); return false; } //------------------------------------------------------------- function OutputBinlogV10($Imei,$Data) { global $cgImeiBinLogfileV10; // if ($Imei==357023003608354) // { // LogText("d:\\temp\\V10 $Imei.bin",$Data); // } // probeer file $fn="$cgImeiBinLogfileV10 $Imei.bin"; if (LogText("$fn",$Data)) return true; LogError("Error: Binlog append error: $fn"); return false; } //------------------------------------------------------------- // function OutputBinlogV13($Imei,$Data) //data was 14+128+2=144 { global $cgUrlLocalHost; global $cgPortV13Bin; global $cgImeiBinLogfileV13; $Data = '@'.$Imei.'--'.date('YmdHis', time()).$Data;//data was 144, nu 176 ?? // if ($Imei==357023003608354) // { // LogText("d:\\temp\\V13 $Imei.bin",$Data); // } // probeer eerst socket if($fp=@fsockopen($cgUrlLocalHost,$cgPortV13Bin,$errstr,$errno,5)) { @fputs($fp,$Data); @fclose($fp); return true; } //als dat niet ging: geef waarschuwing en probeer file LogError("Warning: Error opening bin socket URL $cgUrlLocalHost:$cgPortV13Bin IMEI: $Imei, trying filewrite"); $fn="$cgImeiBinLogfileV13 $Imei.bin"; LogInfo("Writing: $fn"); if (LogText("$fn",$Data)) return true; LogError("Error: Binlog append error: $fn"); return false; } //------------------------------------------------------------- function ForwardTextData(&$pcGPS)//, $ExtraModuleData) { global $cgImeiDbgLogFile; $FileWriteData=''; for($DataPart=$Stored=0;$DataPart<$pcGPS->GetDataPartCount();$DataPart++,$Stored++) { if(!$pcGPS->SelectDataPart($DataPart) || !$pcGPS->IsValid()) { LogError($pcGPS->GetLastError().' data string: '.$pcGPS->GetHttpData()); continue; } { $Imei= $pcGPS->GetImei(); $FileWriteData.="IMEI=$Imei\t"; } { $Tmp = date('Y-m-d H:i:s', time()); $FileWriteData.="SDT=$Tmp\t"; } { $Time= $pcGPS->GetGpsTimeMySQL(); $FileWriteData.="DT=$Time\t"; } { $Swi = $pcGPS->GetSwitch(); $FileWriteData.="Swi=$Swi\t"; } if ($pcGPS->CanGetIndex() ) { $Tmp = $pcGPS->GetIndex(); $FileWriteData.="Seq=$Tmp\t"; } if ($pcGPS->CanGetLatLong() ) { $Tmp = $pcGPS->GetLatitudeFloat(); $FileWriteData.="Lat=$Tmp\t"; } if ($pcGPS->CanGetLatLong() ) { $Tmp = $pcGPS->GetLongitudeFloat(); $FileWriteData.="Lon=$Tmp\t"; } if ($pcGPS->CanGetHeading() ) { $Tmp = $pcGPS->GetHeading(); $FileWriteData.="Dir=$Tmp\t"; } if ($pcGPS->CanGetSpeed() ) { $Tmp = $pcGPS->GetSpeedKPH(); $FileWriteData.="Spd=$Tmp\t"; } if ($pcGPS->CanGetFix() ) { $Tmp = $pcGPS->GetFix(); $FileWriteData.="Fix=$Tmp\t"; } if ($pcGPS->CanGetAccu() ) { $Tmp = $pcGPS->GetAccu(); $FileWriteData.="Sup=$Tmp\t"; } if ($pcGPS->CanGetRev() ) { $Tmp = $pcGPS->GetRev(); $FileWriteData.="Rev=$Tmp\t"; } if ($pcGPS->CanGetVersion() ) { $Tmp = $pcGPS->GetVersion(); $FileWriteData.="Ver=$Tmp\t"; } if ($pcGPS->CanGetTemperature() ) { $Tmp = $pcGPS->GetTemperatureCelcius(); $FileWriteData.="Tmp=$Tmp\t"; } if ($pcGPS->CanGetIO() ) { $Tmp = $pcGPS->GetIO(); $FileWriteData.="IO=$Tmp\t"; } if ($pcGPS->CanGetIMSI() ) { $Tmp = $pcGPS->GetIMSI(); $FileWriteData.="IMSI=$Tmp\t"; } if ($pcGPS->CanGetLcdData() ) { $Tmp = $pcGPS->GetLcdDataBytes(); $FileWriteData.="Cell=$Tmp\t"; } if ($pcGPS->CanGetSettingsCrc() ) { $Tmp = $pcGPS->GetSettingsCrc(); $FileWriteData.="SetCRC=$Tmp\t"; } if ($pcGPS->CanGetPortData() ) { $Tmp = $pcGPS->GetPortDataBytes(); $FileWriteData.="Port=$Tmp\t"; } if ($pcGPS->CanGetReset() ) { $Rst = $pcGPS->GetReset(); $FileWriteData.="Reset=$Rst\t"; } if ($pcGPS->CanGetHardwareStatus()) { $Tmp = $pcGPS->GetHardwareStatus(); $FileWriteData.="HWStat=$Tmp\t"; } if ($pcGPS->CanGetRestartCause() ) { $Tmp = $pcGPS->GetRestartCause(); $FileWriteData.="Restart=$Tmp\t";} { $FileWriteData.="\r\n"; } $Tmp='TxtLog '.$Time.' SWI='.$Swi; if ($pcGPS->CanGetReset()) $Tmp.= ' Reset='.$Rst; LogText("$cgImeiDbgLogFile $Imei.log",date('Y-m-d H:i:s', time()).' '.$Tmp."\r\n"); } if(!strlen($FileWriteData)) return $Stored; //Number of items that the module does not need to resend //special swt output // 49 = 0x31 =SV_InternalStatus1' = no data... // 0 = 0x00 =SV_Position' // 78 = 0x4E =SV_KeepAlive' = Seq=0 Lat=52.08448 Lon=5.01355 Dir=10 Spd=11.0 Fix=3 Sup=12.72 Ver=123 Tmp=-58.53515625 IO=2 // 48 = 0x30 =SV_PowerUp' = Seq=250 Sup=12.372676485526 Ver=123 Tmp=-59.34765625 IO=0 SetCRC=16188 // 64 = 0x40 =SV_Network' = Sup=12.318334179787 Ver=123 IMSI=62443972712 SetCRC=16188 // 112 = 0x70 =SV_LcdData1 // 112 Rev=8 Cell=B8BC-B284-0000 // 0 Seq=201 Lat=52.08619 Lon=5.0100966666667 Dir=0 Spd=0 Fix=10 Sup=12.33 Rev=8 Ver=160 Tmp=11.53 IO=2 Reset=1835008 // 72 Sup=12.38 Rev=8 Ver=160 IMSI=62443973814 SetCRC=8640 // Diverse exports uit script V7 t/m V13... OutputTextlogV10($Imei,$FileWriteData); OutputTextlogV12($Imei,$FileWriteData); $OK = OutputTextlogV13($Imei,$FileWriteData); if ($OK) return $Stored; return 0; // niet goed: traceme moet opnieuw } //------------------------------------------------------------- function GetBinLog($ModuleDataString, &$Imei, &$BinDate) { $Con='0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-'; $aParts=explode('*',$ModuleDataString); $Bin=''; for($Part=0;;$Part++) { if(!$Part) { $Imei=DecompressImei($aParts[0]); if((strlen($Imei)!=15)||strspn($Imei, '0123456789')!=15) { LogError("Invalid IMEI in custom string: $ModuleDataString"); return 0; } continue; } if(!isset($aParts[$Part])) { if(($Part-1)%5) { LogError("Part $Part is missing in custom string: $ModuleDataString"); return 0; } break; } $Enc=$aParts[$Part]; $Len=strlen($Enc); if(($Len!=44)||strspn($Enc, $Con)!=44) { LogError("Part $Part has invalid length or characters in custom string: $ModuleDataString"); return 0; } $Hex=''; for($i=0;$i<$Len;$i+=4) { $v1=strpos($Con,$Enc[$i]); $v2=strpos($Con,$Enc[$i+1]); $v3=strpos($Con,$Enc[$i+2]); $v4=strpos($Con,$Enc[$i+3]); $Hex.=sprintf('%06X',(($v1<<18)+($v2<<12)+($v3<<6)+$v4)); } if(!(($Part-1)%5)) { $TimeStamp=(((float)hexdec(substr($Hex,0,8))*16.0)/100.0)+946684800.0; $Bin.=gmdate('YmdHis', $TimeStamp); $BinDate =gmdate('Y-m-d H:i:s', $TimeStamp)."\r\n"; } $Len=$Hex; for($i=8;$i<62;$i+=2) { if($i==16) continue; //Switch $Bin.=chr(hexdec(substr($Hex,$i,2))); } } return $Bin; } //------------------------------------------------------------- // BODY //------------------------------------------------------------- if(UnwantedOutputCheckpoint(1)) exit(); //Safety check to see if your code changes evoked any text/error/warning output in the execution before this checkpoint if(!file_exists($CgpsClassFileName)) { LogError("The required file '$CgpsClassFileName' is missing."); exit(); } if(((include $CgpsClassFileName)!='included') || headers_sent()) { LogError("This file '$CgpsClassFileName' seems to be incompatible. Please upgrade the file."); exit(); } if(isset($_GET[$ReceiptionVariableName])) //Here we check if the script received data via the variable above { //Received module data, so store the received data in a variable $ModuleDataString=$_GET[$ReceiptionVariableName]; if(strpos($ModuleDataString,'*')!==false) { $Bin = GetBinLog($ModuleDataString,$Imei,$BinDate); if (!$Bin) exit(); LogText("$cgImeiDbgLogFile $Imei.log",date('Y-m-d H:i:s', time())." BinLog $BinDate"); $OK = OutputBinlogV13($Imei,$Bin); OutputBinlogV10($Imei,$Bin); if (!$OK) exit(); if (UnwantedOutputCheckpoint(12345)) exit(); //Safety check to see if your code changes evoked any text/error/warning output in the execution before this checkpoint die("\r\n*A#G\r\nOK\r\n"); // acknowledge to traceme } //Get extra binary data if the module included it (e.g. picture data from a photo) //(Depending on the settings of your PHP setup, this data is also available via $HTTP_RAW_POST_DATA) $ExtraModuleData=@file_get_contents("php://input"); //Create an instance of the CGPS class and initialize it with the received module data. $pcGPS=new CGPS(); //Create new instance of the CGPS class. $pcGPS->ClearResponseActionMembers(); //Clear all response action members in the class by setting them to neutral. if(!$pcGPS->SetHttpData($ModuleDataString)) //Set class with received data. { //The class did not accept the received data. LogError($pcGPS->GetLastError()." Received data string: $ModuleDataString"); //Add message to the error log. UnwantedOutputCheckpoint(2); //Safety check to see if your code changes evoked any text/error/warning output in the execution before this checkpoint. print($pcGPS->BuildResponseHTTP(0)); //Makes the module retry later (assuming the transmission actually came from a module). exit(); //Silent script exit. } //Verify reported extra data size with the size of the actually received extra data. if($pcGPS->CanGetExtraDataSize() && ($pcGPS->GetExtraDataSize()!=strlen($ExtraModuleData))) { //The data size does not match the received data size. Presumable cause is some limiter or filter (e.g. proxy) in the network of your GPRS provider. LogError('Module says that '.$pcGPS->GetExtraDataSize().' bytes of extra data were included, while '.strlen($ExtraModuleData)." were received. Presumable cause is some limiter/filter/proxy (in the network of your GPRS provider) that modified the data. Received data string: $ModuleDataString"); UnwantedOutputCheckpoint(3); //Safety check to see if your code changes evoked any text/error/warning output in the execution before this checkpoint. print($pcGPS->BuildResponseHTTP(0)); //Let the module know that it was not accepted exit(); //Silent script exit. } // Begin foto opslaan if($pcGPS->GetSwitch()==SV_PhotoGps) { $PhotoFileName='D:\\EDServer\\ApacheLogfiles_V13\\'.$pcGPS->GetImei().'_'.$pcGPS->GetUtcTimeMySQL().'_'.$pcGPS->GetLatitudeFloat().'_'.$pcGPS->GetLatitudeFloat().'.jpg'; if($hFile=@fopen($PhotoFileName, 'wb')) { fwrite($hFile, $ExtraModuleData); fclose(); } else LogError("Error creating photo file: $PhotoFileName"); } // Einde foto opslaan //Forward incoming extracted and converted into dedicated form to another script/computer/device. $NumberOfProcessedDataParts=ForwardTextData($pcGPS);//, $ExtraModuleData); if(UnwantedOutputCheckpoint(5)) exit(); //Safety check to see if your code changes evoked any text/error/warning output in the execution before this checkpoint. //### INFO ### uploading from your server to the module (e.g. new firmware, new settings, command's, port data). //Because we actually accepted stored the received data at this point, we and are going to respond that to the transmitting module. //But if you want, you can include extra tasks for the module to performed if you want. //You are likely going to keep track of things like new module settings and actions and that //are pending for each of your modules in a database. //But for simplicity's sake of this example, we use command files that you put in the same directory //as this script on your server. //Every time a module transmits to your server, this script checks if you have put a command file //for it !!!in the same directory!!! as this script. //If such a file exists, it is handled and deleted afterwards so the action is performed only once. //### WARNING ### It is important that your server grants this script the priorities required //to actually delete these files from the directory. //In the file name of such a command file, you use every module's unique 15 digit IMEI serial number to address them idividually. //See below for supported command file extensions and their discription/contents/function. if(!$pcGPS->IsForwardedByGateway()) //Did we receive the data directly from a module and not from a gateway that forwarded it? { $Imei=$pcGPS->GetImei(); //Extract the module's IMEI code like "123456789012345" to see if we created pending commads for it. //***NEW MODULE SETTINGS*** $FileName="$Imei.tms"; //Construct file name like: 123456789012345.tms if(@is_file($FileName)) //Does a file with this name exist in the same directory as this script? { //The file is expected to contain settings from the CGPSsettings class or written to disk with the settings application. //When the new settings are received by the module, it will let the result know via a transmission type SV_SettingsAccepted or SV_SettingsRejected. $pcGPS->mSettings=@file_get_contents($FileName); LogInfo("Settings data from file '$FileName' uploaded to module $Imei."); @chmod($FileName, 0777); if(!@unlink($FileName)) LogError("!!!PROBLEM!!! The file '$FileName' could not be deleted."); } //***UPDATING FIRMWARE*** $FileName="$Imei.tmf"; //Construct filename like: 123456789012345.tmf if(@is_file($FileName)) //Does a file with this name exist in the same directory as this script? { //An ASCII text file is expected, containing only the 3 digits of the new firmware version. //If the file exists and contains for example the following three digits: 385 //the module will try to download this file from your server: traceme385.hex //NOTES: //- The tracemeXXX.hex firmware file must be downloadable from the root directory of your HTTP server. // You can manually check if the file can be downloaded from your server's HTTP root // directory with a web browser by entering an URL like: http://YourServerIP/tracemeXXX.hex // You may need to configure your server's settings and/or add a new mime type // (e.g. binary octet-stream) before it allows downloads of binary files with the .hex // extension that you put in the HTTP root directory. //- A module will only reboot and start using downloaded firmware data if the version number // of the firmware is higher than the one already in use. //- Some GPRS providers use limits and filters in their system that can prohibit the module // from downloading a firmware file unmodified and in it's full length. // In this case you can only upload new firmware into a module with the settings program // via a direct cable connection. $FileSize=@filesize($FileName); if(($FileSize>=3) && $FileSize<=3+2) { $FirmwareVersion=@substr(@file_get_contents($FileName), 0, 3); if(@strspn($FirmwareVersion, '0123456789')==3) { $pcGPS->mFirmware=$FirmwareVersion; //Store firmware version in the response member of the class. LogInfo("Module $Imei has been instructed to download the firmware file \"traceme$FirmwareVersion.hex\" from the root of your HTTP server"); } else LogError("Firmware command file \"$FileName\" contained invalid characters and must contain only the 3 digits of the firmware version."); } else LogError("Firmware command file \"$FileName\" file size was incorrect. It must contain only the 3 digits of the firmware version."); @chmod($FileName, 0777); if(!@unlink($FileName)) LogError("!!!PROBLEM!!! The file '$FileName' could not be deleted."); } //***PERFORM ACTION*** $FileName="$Imei.ra"; //Construct filename like: 123456789012345.ra if(@is_file($FileName)) //Does a file with this name exist in the same directory as this script? { //An ASCII text file is expected containing the action(s) that you want to be performed by the module. //All actions that you trigger in your file are set in the response action members of the CGPS class //and is used to build response that is send to the module to perform these actions. /************ copy lines below into your "123456789012345.ra" file ************ //Remove all the trigger lines below that do not want to be performed. GpsLog //Log current GPS position CountersLog //Log current reading of the counters TransmitLog //Transmit current log ResetTimer1 //Reset timer 1 ResetTimer2 //Reset timer 2 ResetTimer3 //Reset timer 3 ResetTimer4 //Reset timer 4 ResetTimer5 //Reset timer 5 ResetTimer6 //Reset timer 6 ResetTimer7 //Reset timer 7 ResetTimer8 //Reset timer 8 SmsAlert1 //Send an alert SMS message to phone number 1 SmsAlert2 //Send an alert SMS message to phone number 2 SmsAlert3 //Send an alert SMS message to phone number 3 SmsAlertCalledBy1 //Send an alert SMS message to "called by..." phone number 1 SmsAlertCalledBy2 //Send an alert SMS message to "called by..." phone number 2 SmsAlertCalledBy3 //Send an alert SMS message to "called by..." phone number 3 RebootModule //Force module reboot via watchdog. ***ALL*** active/pending actions will be terminated without finishing them. ClearGPSConfig //Clear configuration of the GPS receiver, resulting in a "cold start" position determination of the GPS receiver. ClearLog //Erase the FLASH memory in the module, clearing the log and uploaded user program/variables. //NOTE: If more than one trigger is used for the same item below, only the last one will be performed. Photo=HiRes //Take high resolution picture Photo=LoRes //Take low resolution picture DigitalOutput1=Enable //Enable digital output 1 DigitalOutput1=Disable //Disable digital output 1 DigitalOutput1=Toggle //Toggle digital output 1 DigitalOutput2=Enable //Enable digital output 2 DigitalOutput2=Disable //Disable digital output 2 DigitalOutput2=Toggle //Toggle digital output 2 DigitalOutput3=Enable //Enable digital output 3 DigitalOutput3=Disable //Disable digital output 3 DigitalOutput3=Toggle //Toggle digital output 3 DigitalOutput4=Enable //Enable digital output 4 DigitalOutput4=Disable //Disable digital output 4 DigitalOutput4=Toggle //Toggle digital output 4 ************* copy lines above into your "123456789012345.ra" file ************/ if(($ResponseActionFile=@file_get_contents($FileName)) && strlen($ResponseActionFile)) { $ActionResponseInfo=''; if(strpos($ResponseActionFile, 'GpsLog')!==false) {$pcGPS->mGpsLog=true; $ActionResponseInfo.='GpsLog|';} if(strpos($ResponseActionFile, 'CountersLog')!==false) {$pcGPS->mCountersLog=true; $ActionResponseInfo.='CountersLog|';} if(strpos($ResponseActionFile, 'TransmitLog')!==false) {$pcGPS->mTransmitLog=true; $ActionResponseInfo.='TransmitLog|';} if(strpos($ResponseActionFile, 'ResetTimer1')!==false) {$pcGPS->mResetTimer1=true; $ActionResponseInfo.='ResetTimer1|';} if(strpos($ResponseActionFile, 'ResetTimer2')!==false) {$pcGPS->mResetTimer2=true; $ActionResponseInfo.='ResetTimer2|';} if(strpos($ResponseActionFile, 'ResetTimer3')!==false) {$pcGPS->mResetTimer3=true; $ActionResponseInfo.='ResetTimer3|';} if(strpos($ResponseActionFile, 'ResetTimer4')!==false) {$pcGPS->mResetTimer4=true; $ActionResponseInfo.='ResetTimer4|';} if(strpos($ResponseActionFile, 'ResetTimer5')!==false) {$pcGPS->mResetTimer5=true; $ActionResponseInfo.='ResetTimer5|';} if(strpos($ResponseActionFile, 'ResetTimer6')!==false) {$pcGPS->mResetTimer6=true; $ActionResponseInfo.='ResetTimer6|';} if(strpos($ResponseActionFile, 'ResetTimer7')!==false) {$pcGPS->mResetTimer7=true; $ActionResponseInfo.='ResetTimer7|';} if(strpos($ResponseActionFile, 'ResetTimer8')!==false) {$pcGPS->mResetTimer8=true; $ActionResponseInfo.='ResetTimer8|';} if(strpos($ResponseActionFile, 'SmsAlert1')!==false) {$pcGPS->mSmsAlert1=true; $ActionResponseInfo.='SmsAlert1|';} if(strpos($ResponseActionFile, 'SmsAlert2')!==false) {$pcGPS->mSmsAlert2=true; $ActionResponseInfo.='SmsAlert2|';} if(strpos($ResponseActionFile, 'SmsAlert3')!==false) {$pcGPS->mSmsAlert3=true; $ActionResponseInfo.='SmsAlert3|';} if(strpos($ResponseActionFile, 'SmsAlertCalledBy1')!==false) {$pcGPS->mSmsAlertCalledBy1=true; $ActionResponseInfo.='SmsAlertCalledBy1|';} if(strpos($ResponseActionFile, 'SmsAlertCalledBy2')!==false) {$pcGPS->mSmsAlertCalledBy2=true; $ActionResponseInfo.='SmsAlertCalledBy2|';} if(strpos($ResponseActionFile, 'SmsAlertCalledBy3')!==false) {$pcGPS->mSmsAlertCalledBy3=true; $ActionResponseInfo.='SmsAlertCalledBy3|';} if(strpos($ResponseActionFile, 'RebootModule')!==false) {$pcGPS->mRebootModule=true; $ActionResponseInfo.='RebootModule|';} if(strpos($ResponseActionFile, 'ClearGPSConfig')!==false) {$pcGPS->mClearGPSConfig=true; $ActionResponseInfo.='ClearGPSConfig|';} if(strpos($ResponseActionFile, 'ClearLog')!==false) {$pcGPS->mClearLog=true; $ActionResponseInfo.='ClearLog|';} if(strpos($ResponseActionFile, 'DigitalOutput1=Enable')!==false) {$pcGPS->mDigitalOutput1=RACD_DigitalOutput_Enable; $ActionResponseInfo.='DigitalOutput1=Enable|';} if(strpos($ResponseActionFile, 'DigitalOutput1=Disable')!==false) {$pcGPS->mDigitalOutput1=RACD_DigitalOutput_Disable; $ActionResponseInfo.='DigitalOutput1=Disable|';} if(strpos($ResponseActionFile, 'DigitalOutput1=Toggle')!==false) {$pcGPS->mDigitalOutput1=RACD_DigitalOutput_Toggle; $ActionResponseInfo.='DigitalOutput1=Toggle|';} if(strpos($ResponseActionFile, 'DigitalOutput2=Enable')!==false) {$pcGPS->mDigitalOutput2=RACD_DigitalOutput_Enable; $ActionResponseInfo.='DigitalOutput2=Enable|';} if(strpos($ResponseActionFile, 'DigitalOutput2=Disable')!==false) {$pcGPS->mDigitalOutput2=RACD_DigitalOutput_Disable; $ActionResponseInfo.='DigitalOutput2=Disable|';} if(strpos($ResponseActionFile, 'DigitalOutput2=Toggle')!==false) {$pcGPS->mDigitalOutput2=RACD_DigitalOutput_Toggle; $ActionResponseInfo.='DigitalOutput2=Toggle|';} if(strpos($ResponseActionFile, 'DigitalOutput3=Enable')!==false) {$pcGPS->mDigitalOutput3=RACD_DigitalOutput_Enable; $ActionResponseInfo.='DigitalOutput3=Enable|';} if(strpos($ResponseActionFile, 'DigitalOutput3=Disable')!==false) {$pcGPS->mDigitalOutput3=RACD_DigitalOutput_Disable; $ActionResponseInfo.='DigitalOutput3=Disable|';} if(strpos($ResponseActionFile, 'DigitalOutput3=Toggle')!==false) {$pcGPS->mDigitalOutput3=RACD_DigitalOutput_Toggle; $ActionResponseInfo.='DigitalOutput3=Toggle|';} if(strpos($ResponseActionFile, 'DigitalOutput4=Enable')!==false) {$pcGPS->mDigitalOutput4=RACD_DigitalOutput_Enable; $ActionResponseInfo.='DigitalOutput4=Enable|';} if(strpos($ResponseActionFile, 'DigitalOutput4=Disable')!==false) {$pcGPS->mDigitalOutput4=RACD_DigitalOutput_Disable; $ActionResponseInfo.='DigitalOutput4=Disable|';} if(strpos($ResponseActionFile, 'DigitalOutput4=Toggle')!==false) {$pcGPS->mDigitalOutput4=RACD_DigitalOutput_Toggle; $ActionResponseInfo.='DigitalOutput4=Toggle|';} if(strpos($ResponseActionFile, 'Photo=HiRes')!==false) {$pcGPS->mPhoto=RACD_Photo_HiRes; $ActionResponseInfo.='Photo=HiRes|';} if(strpos($ResponseActionFile, 'Photo=LoRes')!==false) {$pcGPS->mPhoto=RACD_Photo_LoRes; $ActionResponseInfo.='Photo=LoRes|';} LogInfo("Action response sent to module $Imei: $ActionResponseInfo"); } else LogError("The file $FileName could not read or was empty"); @chmod($FileName, 0777); if(!@unlink($FileName)) LogError("!!!PROBLEM!!! The file '$FileName' could not be deleted."); } //***Module Serial Port Output*** $FileName="$Imei.sp1"; //Construct filename like: 123456789012345.sp1 for serial port #1 if(@is_file($FileName)) //Does a file with this name exist in the same directory as this script? { //The file is expected to contain the data that is to be sent via that serial port of the module. if(filesize($FileName)>256) //Safety check to prevent mistakes with large file sizes. LogError("The file size safety check rejected and deleted the file '$FileName' because it was too big."); else $pcGPS->mSerialPort1=@file_get_contents($FileName); @chmod($FileName, 0777); if(!@unlink($FileName)) LogError("!!!PROBLEM!!! The file '$FileName' could not be deleted."); } $FileName="$Imei.sp2"; //Construct filename like: 123456789012345.sp2 for serial port #2 if(@is_file($FileName)) //Does a file with this name exist in the same directory as this script? { //The file is expected to contain the data that is to be sent via that serial port of the module. if (filesize($FileName)>256) //Safety check to prevent mistakes with large file sizes. LogError("The file size safety check rejected and deleted the file '$FileName' because it was too big."); else $pcGPS->mSerialPort2=@file_get_contents($FileName); @chmod($FileName, 0777); if(!@unlink($FileName)) LogError("!!!PROBLEM!!! The file '$FileName' could not be deleted."); } $FileName="$Imei.sp3"; //Construct filename like: 123456789012345.sp3 for serial port #3 if(@is_file($FileName)) //Does a file with this name exist in the same directory as this script? { //The file is expected to contain the data that is to be sent via that serial port of the module. if (filesize($FileName)>256) //Safety check to prevent mistakes with large file sizes. LogError("The file size safety check rejected and deleted the file '$FileName' because it was too big."); else $pcGPS->mSerialPort3=@file_get_contents($FileName); @chmod($FileName, 0777); if(!@unlink($FileName)) LogError("!!!PROBLEM!!! The file '$FileName' could not be deleted."); } $FileName="$Imei.sp4"; //Construct filename like: 123456789012345.sp4 for serial port #4 if(@is_file($FileName)) //Does a file with this name exist in the same directory as this script? { //The file is expected to contain the data that is to be sent via that serial port of the module. if (filesize($FileName)>256) //Safety check to prevent mistakes with large file sizes. LogError("The file size safety check rejected and deleted the file '$FileName' because it was too big."); else $pcGPS->mSerialPort4=@file_get_contents($FileName); @chmod($FileName, 0777); if(!@unlink($FileName)) LogError("!!!PROBLEM!!! The file '$FileName' could not be deleted."); } //***Source Code / LCD Menu*** $FileName="$Imei.src"; //Construct file name like: 123456789012345.src if(@is_file($FileName)) //Does a file with this name exist in the same directory as this script? { //The file is expected to contain the source code that is to be executed by the module. //This source code can consist of a combination of things like: //- A full new program for example to generate a menu on the attached LCD dispay. //- One or more changes to variables of already executing code in the module at run-time. //- Replacement or additional parts of code for parts of the current code in the module. //- Execution of code parts that are included or already present in the module. $pcGPSCODE=new CGPSCODE(); //Create instance of the class if($pcGPSCODE->AddSourceCode(@file_get_contents($FileName))) //Add code in the file to the class { //Class accepted the source code, so it should be safe to upload it to the module. //First check if the upload needs to be stalled untill the next time. if(strlen($pcGPS->mSettings) && $pcGPSCODE->GetFirstServerUploadStallLine()) { //Uploading these items at the same time will lead to problems, so stall this source code upload for now. LogInfo("Temporarily stalled uploading source code from file '$FileName' to module $Imei."); } else { //Upload the source code into the action response class member. $pcGPS->mSourceCode=$pcGPSCODE->GetSourceCode(); //Asking it back from the class ensures that it is always properly formatted. LogInfo("The following source code from file '$FileName' has been uploaded to module $Imei:\r\n".@file_get_contents($FileName)."\r\n"); @chmod($FileName, 0777); if(!@unlink($FileName)) LogError("!!!PROBLEM!!! The file '$FileName' could not be deleted."); } } else { LogError("Source code in the file '$FileName' for module $Imei has been rejected. Reason: ".$pcGPSCODE->GetLastError()."\r\n".@file_get_contents($FileName)); @chmod($FileName, 0777); if(!@unlink($FileName)) LogError("!!!PROBLEM!!! The file '$FileName' could not be deleted."); } } } if(UnwantedOutputCheckpoint(6)) exit(); //Safety check to see if your code changes evoked any text/error/warning output in the execution before this checkpoint. //Build a response and return it to the transmitting module. //This response includes the acknowledge for the processed data parts (so the module will not send them again). //and the commands that are set via the response action member variables of the class. print($pcGPS->BuildResponseHTTP($NumberOfProcessedDataParts)); //Build and send the response to acknowledge. exit(); //Silent script exit }