0) { if (($ab[1]/$ab[2]) < 10) { return sprintf("%1.1f", $ab[1]/$ab[2]); } else { return round($ab[1]/$ab[2]); } } return $s; } $exif= exif_read_data($filename); if ($exif && isset($exif['FNumber'])) { $model= $exif['Model']; $iso= $exif['ISOSpeedRatings']; $fnumber= exVal($exif['FNumber']); $exptime= exVal($exif['ExposureTime']); $bias= exVal($exif['ExposureBiasValue']); $foclen= exVal($exif['FocalLength']); // Remember some raw values for later usage (auto-exposure) $exif['iso']= $iso; $exif['fn']= $fnumber;; $exif['et']= $exptime; $exif['bias']= $bias; $exif['ExposureTime']= preg_replace("/10\/(\d+)0/", "1/$1", $exif['ExposureTime']); if ($exptime<0.3) { $exptime= $exif['ExposureTime']; } // Remember text representation for image text if ($iso && $foclen) { $exif['imgtxt']= "(f/$fnumber ${exptime}s iso$iso)"; } // Remember text file format compatible with exif command line $exif['file']= "Model|$model\n". "Exposure Time|${exptime} sec.\n". "FNumber|f/$fnumber\n". "ISO|$iso\n". "Exposure Bias|$bias eV\n". "Focal Length|${foclen}mm\n"; } return $exif; } // -------------------------------------------------------------------------- // Sample the grey-scale luminance value of a given image. // Use only the rectangle 0,0,xmax,ymax // -------------------------------------------------------------------------- function getLuminance($img, $xmax= 0, $ymax= 0) { $xmaxx= imagesx($img); $ymaxx= imagesy($img); if ($xmax>$xmaxx || $xmax==0) { $xmax= $xmaxx; } if ($ymax>$ymaxx || $ymax==0) { $ymax= $ymaxx; } $step= ceil(($xmax+$ymax)/50); # do only rough sampling due to performance $av= 0; $count= 0; for($y=0; $y<$ymax; $y+= $step) { for($x=0; $x<$xmax; $x+= $step) { $pos= imagecolorat($img, $x, $y); $f= imagecolorsforindex($img, $pos); $gst= $f["red"]*0.15 + $f["green"]*0.5 + $f["blue"]*0.35; $av+= $gst; $count++; } } if ($count) { return round(($av/$count)/0.256)/10; } return 0; } function filterRegions($img) { global $webcam; if (!isNight()){ if (isset($webcam['filterRegions'])) { if(isset($webcam['filterRegionsOnHotSummerDays'])){ $tempfile= $webcam['workPath']."/wetter/temp.txt"; if (@filemtime($tempfile) > (time()-900)) { $wxfile= fopen($tempfile, "r"); if ($wxfile) { $wx= fgets($wxfile); doLog($cmd, "info", "filterRegionsOnHotSummerDays". $wx); //$wx= preg_replace("/\s+$/","",$wx); fclose($wxfile); $temp= "$wx"; } } if ($temp >= 25){ doLog($cmd, "info", "filterRegionsOnHotSummerDays"); $webcam['filterRegions'] = $webcam['filterRegionsOnHotSummerDays']; } } doLog($cmd, "info", "filterregions"); $fn= "/tmp/filter-".$webcam['name'].".jpg"; for ($rectnum= 0; isset($webcam['filterRegions'][$rectnum]); $rectnum++) { $rect= $webcam['filterRegions'][$rectnum]; $xmin= $rect[0]; $ymin= $rect[1]; $xmax= $rect[2]; $ymax= $rect[3]; $noise= 5; $opacity= 100; if (isset($rect[4])) { $noise= $rect[4]; } if (isset($rect[5])) { $opacity= $rect[5]; } $srcimg= ImageCreateTrueColor($xmax-$xmin, $ymax-$ymin); ImageCopy($srcimg, $img, 0,0, $xmin, $ymin, $xmax-$xmin, $ymax-$ymin); ImageJPEG($srcimg, $fn); ImageDestroy($srcimg); if (system("mogrify -noise $noise $fn") == 0) { $srcimg= ImageCreateFromJPEG($fn); unlink($fn); $sz= min($xmax-$xmin,$ymax-$ymin); $trans= 0; // Increase transparency when iterating from border to middle for ($margin=0; $margin<$sz/2 && $trans<100; $margin+=5) { $trans= min($opacity*($margin/$sz),100); ImageCopyMerge($img, $srcimg, $xmin+$margin, $ymin+$margin, $margin, $margin, $xmax-$xmin-(2*$margin), $ymax-$ymin-(2*$margin), $trans); } ImageDestroy($srcimg); } } } } } // -------------------------------------------------------------------------- // Generate a transparent image and place text at the top of it // The text color is determined by the luminance value of the main image // To be merged with further images // -------------------------------------------------------------------------- function createTextImage($img, $tagZeit, $datum, $temp, $wind, $textImageFarbeBoe, $wassertemp) { $threshold= 45; // at day, prefer black text /*if (isNight()) { $threshold= 55; // at night, prefer white text }*/ $b= 255; /*if (getLuminance($img, 2000, 200) > $threshold) { $b= 0; }*/ $txtfileTest= fopen("/tmp/bastelzeug.txt", "a"); fwrite($txtfileTest,$temp."-----------\n"); //fwrite($txtfileTest,$wind."-----------\n"); //fwrite($txtfileTest,$wetter); $textImg= ImageCreateTrueColor(98, 40); $bgColor=ImageColorAllocateAlpha($textImg, $b,$b,$b, 80); $textColorAlpha=ImageColorAllocateAlpha($textImg, 0,0,0, 60); imagefill($textImg, 0, 0, ImageColorAllocateAlpha($textImg, $b,$b,$b, 127)); imagefill($textImg, 0, 0, $bgColor); imagepng($textImg,"/var/www/test/fileadmin/test_2.png"); if ($temp){ $tempImg= ImageCreateTrueColor(98, 38); imagefill($tempImg, 0, 0, ImageColorAllocateAlpha($tempImg, $b,$b,$b, 127)); imagefill($tempImg, 0, 0, $bgColor); } if ($temp && $wassertemp){ $tempImg= ImageCreateTrueColor(98, 67); imagefill($tempImg, 0, 0, ImageColorAllocateAlpha($tempImg, $b,$b,$b, 127)); imagefill($tempImg, 0, 0, $bgColor); } if ($wind){ $windImg= ImageCreateTrueColor(98, 67); imagefill($windImg, 0, 0, ImageColorAllocateAlpha($windImg, $b,$b,$b, 127)); } fclose($txtfileTest); ImageTtfText($textImg, 10, 0, 30, 19, $textColorAlpha, "/var/www/transfer/fonts/Exo2-Bold.ttf", $tagZeit); ImageTtfText($textImg, 8.5, 0, 30, 32, $textColorAlpha, "/var/www/transfer/fonts/Exo2-Bold.ttf", $datum); if ($temp){ if (strlen($temp)>3 ){ $temp=explode('.',$temp); $temp=$temp[0]; } if (strlen($wassertemp)>3 ){ $wassertemp=explode('.',$wassertemp); $wassertemp=$wassertemp[0]; } ImageTtfText($tempImg, 17, 0, 38, 27, $textColorAlpha, "/var/www/transfer/fonts/Exo2-Bold.ttf", $temp.'°c'); $tempicon= ImageCreateFromPNG("/var/www/addicted/fileadmin/webcam/v14include/temp.png"); ImageCopyResampled($tempImg, $tempicon, 13,9, 0, 0, ImageSX($tempicon), ImageSY($tempicon), ImageSX($tempicon),ImageSY($tempicon) ); /*ImageTtfText($tempImg, 8.5, 0, 8, 29, $textColorAlpha, "/var/www/transfer/fonts/Exo2-Bold.ttf", 'Luft:');*/ if ($wassertemp){ ImageTtfText($tempImg, 17, 0, 38, 57, $textColorAlpha, "/var/www/transfer/fonts/Exo2-Bold.ttf", $wassertemp.'°c'); $boe= ImageCreateFromPNG("/var/www/addicted/fileadmin/webcam/v14include/boe.png"); ImageCopyResampled($tempImg, $boe, 8,40, 0, 0, ImageSX($boe), ImageSY($boe), ImageSX($boe),ImageSY($boe) ); /*ImageTtfText($tempImg, 8.5, 0, 8, 57, $textColorAlpha, "/var/www/transfer/fonts/Exo2-Bold.ttf", 'Wasser:');*/ } } if ($wind){ $bgColor=ImageColorAllocateAlpha($textImg, 255,255,255, 80); $fahneID='01'; $wind=explode('-',$wind); //doLog($cmd, "textImage", $webcam['textImageFarbeBoe']); if (isset($textImageFarbeBoe)) $windWertFarbe=$wind[1]; else $windWertFarbe=$wind[0]; if ($windWertFarbe >= 8){ $bgColor=ImageColorAllocateAlpha($textImg, 0,150,254, 60); $fahneID='02'; } if ($windWertFarbe >= 12){ $bgColor=ImageColorAllocateAlpha($textImg, 0,200,254, 60); $fahneID='03'; } if ($windWertFarbe >= 14)$bgColor=ImageColorAllocateAlpha($textImg, 0,230,240, 60); if ($windWertFarbe >= 16)$bgColor=ImageColorAllocateAlpha($textImg, 37,193,146, 60); if ($windWertFarbe >= 18)$bgColor=ImageColorAllocateAlpha($textImg, 17,212,17, 60); if ($windWertFarbe >= 20)$bgColor=ImageColorAllocateAlpha($textImg, 0,230,0, 60); if ($windWertFarbe >= 24)$bgColor=ImageColorAllocateAlpha($textImg, 184,255,97, 60); if ($windWertFarbe >= 26)$bgColor=ImageColorAllocateAlpha($textImg, 254,254,0, 60); if ($windWertFarbe >= 28)$bgColor=ImageColorAllocateAlpha($textImg, 254,225,0, 60); if ($windWertFarbe >= 30)$bgColor=ImageColorAllocateAlpha($textImg, 254,200,0, 60); if ($windWertFarbe >= 32)$bgColor=ImageColorAllocateAlpha($textImg, 254,174,0, 60); if ($windWertFarbe >= 36){ $bgColor=ImageColorAllocateAlpha($textImg, 220,74,29, 40); $fahneID='04'; } if ($windWertFarbe >= 40)$bgColor=ImageColorAllocateAlpha($textImg, 254,0,150, 40); $fahne= ImageCreateFromPNG("/var/www/addicted/fileadmin/webcam/v14include/fahne_vektor_small_$fahneID.png"); imagefill($windImg, 0, 0, $bgColor); ImageTtfText($windImg, 10, 0, 38, 24, $textColorAlpha, "/var/www/transfer/fonts/Exo2-Bold.ttf", "$wind[0] kts"); ImageTtfText($windImg, 10, 0, 38, 54, $textColorAlpha, "/var/www/transfer/fonts/Exo2-Bold.ttf", "$wind[1] kts"); $boe= ImageCreateFromPNG("/var/www/addicted/fileadmin/webcam/v14include/boe.png"); ImageCopyResampled($windImg, $fahne, 9,10, 0, 0, ImageSX($fahne), ImageSY($fahne), ImageSX($fahne),ImageSY($fahne) ); /*ImageCopyResampled($windImg, $boe, 8,40, 0, 0, ImageSX($boe), ImageSY($boe), ImageSX($boe),ImageSY($boe) );*/ ImageTtfText($windImg, 8.5, 0, 8, 54, $textColorAlpha, "/var/www/transfer/fonts/Exo2-Bold.ttf", "Böe"); } $resImg = ImageCreateTrueColor(98, 40); // Bilder zusammen f�hren if ($temp and !$wind){ $resImg=ImageCreateTrueColor(98, 80); //imagefill($resImg, 0, 0, ImageColorAllocateAlpha($textImg, $b,$b,$b, 127)); } if (!$temp and $wind){ $resImg=ImageCreateTrueColor(98, 109); //imagefill($resImg, 0, 0, ImageColorAllocateAlpha($textImg, $b,$b,$b, 127)); $windimgoffset=42; } if ($temp and $wind){ $resImg=ImageCreateTrueColor(98, 149); $windimgoffset=82; } if ($temp && $wassertemp && $wind){ $resImg=ImageCreateTrueColor(98, 176); $windimgoffset=111; } imagefill($resImg, 0, 0, ImageColorAllocateAlpha($textImg, $b,$b,$b, 127)); ImageCopyResampled($resImg, $textImg, 0, 0, 0, 0, ImageSX($textImg), ImageSY($textImg), ImageSX($textImg),ImageSY($textImg) ); ImageCopyResampled($resImg, $tempImg, 0, 42, 0, 0, ImageSX($tempImg), ImageSY($tempImg), ImageSX($tempImg),ImageSY($tempImg) ); ImageCopyResampled($resImg, $windImg, 0, $windimgoffset, 0, 0, ImageSX($windImg), ImageSY($windImg), ImageSX($windImg),ImageSY($windImg) ); //imagefill($textImg, 0, 0, ImageColorAllocateAlpha($textImg, $b,$b,$b, 100)); $black = imagecolorallocate($textImg, 0, 0, 0); //imagepng($textImg,"/var/www/test/fileadmin/test_2.png"); //imagecolortransparent ($textImg,$textColor); //imagepng($textImg,"/var/www/test/fileadmin/test_3.png"); //ImageSaveAlpha($textImg, true); //convert (bild-1_schwarz.tif -alpha set -transparent white +level-colors 'rgb(255,69,0)', bild-1_rotorange_tr.tif); //imagegif($textImg, "/var/www/test/fileadmin/test_2.jpg"); //imagefill($textImg, 0, 0, ImageColorAllocateAlpha($textImg, $b,$b,$b, 127)); $path= dirname(__FILE__); return $resImg; } // -------------------------------------------------------------------------- // Sharpen a resampled image // -------------------------------------------------------------------------- function sharpenImage($image) { $sharpenMatrix = array( array(-1.2, -1, -1.2), array(-1, 20, -1), array(-1.2, -1, -1.2) ); $divisor = array_sum(array_map('array_sum', $sharpenMatrix)); $offset = 0; ImageConvolution($image, $sharpenMatrix, $divisor, $offset); } // -------------------------------------------------------------------------- // Generate a target image with desired size // -------------------------------------------------------------------------- function createResizedImage($img, $outputFile, $newWidth, $newHeight=0, $topOffset=0, $textImg=NULL, $fwlogo=NULL, $logo= NULL, $surferZoomLeftoffset=0, $surferZoomXCut=0, $surferZoomYCut=0) { global $webcam; $aspectRatio= 16/9; if (isset($webcam['aspectRatio'])) { $aspectRatio= $webcam['aspectRatio']; } $width= ImageSX($img); $height= ImageSY($img); if ($newWidth==0) { // Do not resample the original image $resImg= $img; } else { if ($newHeight<=0) { // The new image frame $newHeight= floor($newWidth/$aspectRatio); if ($topOffset<0) { $newHeight= floor(($newWidth/$width)*$height); $topOffset= 0; } } $resImg= ImageCreateTrueColor($newWidth, $newHeight); } $resX= ImageSX($resImg); $resY= ImageSY($resImg); if ($newWidth) { ImageCopyResampled($resImg ,$img, 0, 0, 0, $topOffset, $resX, $resY, $width, ($width*$resY)/$resX); } if ($surferZoomXCut>0) { imagecopyresized ($resImg ,$img, 0, 0, $surferZoomLeftoffset, $topOffset, $resX, $resY, $surferZoomXCut, $surferZoomYCut); } $iso= 100; if (isset($webcam['exif']['iso'])) { $iso= round($webcam['exif']['iso']); // Olympus 5050 is extra-noisy if (preg_match("/5050/", $webcam['exif']['Model'])) { $iso*= 10; } } if ($resX<200 || $iso<400 || ($resX<2000 && $iso<3200)) { // Sharpen image only if iso is not too high // sharpening noise is so ugly.. sharpenImage($resImg); } // Add prepared text to the image if ($textImg) { $txtXoffset= 0; if (isset($webcam['txtXoffset'])) { $txtXoffset= round($resX*($webcam['txtXoffset']/100.0)); } //Addicted - 620 = Werbefrei deswegen Text ganz oben if ($resX==620) $txtXoffsetO=0; $div= $resX/1333+0.4; if ($div<0.8) $div= 0.8; $newWidthTextImg=ImageSX($textImg); $newHeightTextImg=ImageSY($textImg); $umrechnung=1; if ($resX <940){ if ($resX<=780)$umrechnung=1.2; if ($resX<=780)$umrechnung=1.4; if ($resX<=640)$umrechnung=1.6; if ($resX<=512)$umrechnung=1.8; if ($resX<=320)$umrechnung=2; if ($resX<=180)$umrechnung=3; if ($resX<=150)$umrechnung=3; } $newWidthTextImg=$newWidthTextImg/$umrechnung; $newHeightTextImg=$newHeightTextImg/$umrechnung; $txtXoffsetO= round($resY-$newHeightTextImg); //Addicted - Text nur bei kleineren Aufl�sungen einblenden if ($resX<4000){ ImageCopyResampled($resImg, $textImg, $txtXoffset, $txtXoffsetO, 0, 0, $newWidthTextImg, $newHeightTextImg, ImageSX($textImg),ImageSY($textImg) ); /*ImageCopyResampled($resImg, $textImg, $txtXoffset, $txtXoffsetO, 0, 0, $resX/$div, $resX/($div*10), ImageSX($textImg),ImageSY($textImg) );*/ } } // Add the general logo to the right bottom corner if ($resX!=620){ if ($fwlogo) { $div= 6.68; if ($resX > 1000) $div= 9; if ($resX > 2000) $div= 15; /*--------------------------ANPASSUNGEN ADDICTED-----------------*/ //Logo nicht rechts unten sondern links oben $txtXoffset= 1; $txtXoffset= round($resX*($txtXoffset/100.0)); if ($resX<4000){ ImageCopyResampled($resImg, $fwlogo, $txtXoffset, 5, 0, 0, $resX/$div, $resX/($div*2.39), ImageSX($fwlogo), ImageSY($fwlogo) );} else { ImageCopyResampled($resImg, $fwlogo, $resX-($resX/$div), $resY-($resX/($div*2.39)), 0, 0, $resX/$div, $resX/($div*2.39), ImageSX($fwlogo), ImageSY($fwlogo) ); } } // Add the special logo at the right up corner if ($logo) { if ($resX<4000){ $div=10.88; if ($resX > 1000) $div= 11; if ($resX > 2000) $div= 24; /*--------------------------ANPASSUNGEN ADDICTED-----------------*/ ImageCopyResampled($resImg, $logo, $resX-($resX/$div)-$resX/($div*12), $resX/($div*12), 0, 0, $resX/$div, $resX/($div*(ImageSX($logo)/ImageSY($logo))), ImageSX($logo), ImageSY($logo) ); /*ImageCopyResampled($resImg, $logo, $resX-($resX/$div)-$resX/($div*12), $resX/($div*12), 0, 0, $resX/$div, $resX/($div*(ImageSX($logo)/ImageSY($logo))), ImageSX($logo), ImageSY($logo) );*/ } } } // Larger quality for smaller images $quality= 88; if ($resX>1000) $quality= 88; if ($resX>1400) $quality= 86; // Write image as jpeg file ImageJPEG($resImg, $outputFile, $quality); if ($newWidth>0) { // Only destroy it, if it was really generated and not copied ImageDestroy($resImg); } } // -------------------------------------------------------------------------- // Do all that is necessary to operate a Foto-Webcam within a directory // -------------------------------------------------------------------------- function prepareWebcamPath($webcamPath) { if (! file_exists("$webcamPath/current/.htaccess")) { $dirs= Array("current", "bestof", "tmp", "infos", "wetter"); foreach ($dirs as $dir) { $fulldir= "$webcamPath/$dir"; @mkdir($fulldir, 0775, true); @chmod($fulldir, 0775); } @mkdir("$webcamPath/wetter/cache", 0775, true); $ht= @fopen("$webcamPath/.htaccess", "w"); if ($ht) { fwrite($ht, 'RewriteEngine On'."\n". 'RewriteRule !\.jpg /webcam/include/webcam.php'."\n". 'ExpiresActive On'."\n". 'ExpiresByType image/jpeg "access plus 10 weeks"'."\n". 'ExpiresByType image/png "access plus 10 weeks"'."\n"); fclose($ht); } $ht= @fopen("$webcamPath/current/.htaccess", "w"); if ($ht) { fwrite($ht, 'RewriteEngine Off'."\n". 'ExpiresActive On'."\n". 'ExpiresByType image/jpeg "access plus 10 minutes"'."\n"); fclose($ht); } $ht= @fopen("$webcamPath/infos/.htaccess", "w"); if ($ht) { fwrite($ht, 'RewriteEngine Off'."\n". 'ExpiresActive Off'."\n"); fclose($ht); } $ht= @fopen("$webcamPath/wetter/.htaccess", "w"); if ($ht) { fwrite($ht, 'RewriteEngine Off'."\n". 'ExpiresActive Off'."\n"); fclose($ht); } } } // -------------------------------------------------------------------------- // Determine if we have day or night // -------------------------------------------------------------------------- function isNight($verbose= false) { $zenith= 98; // early twilight $lat= 47.5; $long= 11.5; $ret= false; // Check if we have configured a real place global $webcam; if (isset($webcam['latitude'])) { $lat= $webcam['latitude']; } if (isset($webcam['longitude'])) { $long= $webcam['longitude']; } $ss= date_sunset(time(), SUNFUNCS_RET_TIMESTAMP, $lat, $long, $zenith); if (time() > $ss) { $ret= true; } $sr= date_sunrise(time(), SUNFUNCS_RET_TIMESTAMP, $lat, $long, $zenith); if (time() < $sr) { $ret= true; } if ($verbose) { $xss= strftime("%H:%M:%S", $ss); $xsr= strftime("%H:%M:%S", $sr); echo("isNight: lat=$lat long=$long sr=$xsr ss=$xss ret=$ret\n"); } return $ret; } // -------------------------------------------------------------------------- // Check if image shall be gamma-tuned if too dark // -------------------------------------------------------------------------- function webcamGammaCorrect($img, $lum) { global $webcam; $maxGamma= 1.3; if (isset($webcam['maxGamma'])) { $maxGamma= $webcam['maxGamma']; } $newLum= $lum; $gamma= 1.0; if (isset($maxGamma)) { if ($lum<32) $gamma+= 0.3; if ($lum<16) $gamma+= 0.3; if ($lum<8) $gamma+= 0.3; if ($lum<4) $gamma+= 0.3; if ($gamma > $maxGamma) { $gamma= $maxGamma; } if ($gamma > 1.0) { ImageGammacorrect($img, 1.0, $gamma); $newLum= getLuminance($img); } } echo("Luminance: $lum - Gamma: $gamma - New luminance: $newLum\n"); } // -------------------------------------------------------------------------- // Send ISO and exposure parameters to camera to correct image if necessary // Return: luminance (in %) // -------------------------------------------------------------------------- function tuneExposure($exif, $img) { global $webcam; if (! isset($exif['Model'])) { // No exif values found, we do not seem to have valid exif header return; } $model= $exif['Model']; $iso= round($exif['iso']); $et= $exif['et']; $bias= round($exif['bias']); $night= isNight(true); $lum= getLuminance($img); echo("Model=$model iso=$iso exptime=$et bias=$bias lum=$lum night=$night\n"); if (preg_match("/5050/", $model)) { if ($et>3 && $iso!=400) { sendCommand("webcam_isoexp 400"); } if ($et<2 && $iso==400) { sendCommand("webcam_isoexp Auto"); } } if (preg_match("/EOS/", $model)) { $shallIso= 0; $shallExp= -1; if ($bias<0) { $shallExp= 0; } if ($et>25 && $iso<$webcam['maxIso']) { $shallIso= $iso*2; } if ($et<15 && $iso>=200) { $shallIso= $iso/2; } if ($et<1 && $iso>=400) { $shallIso= $iso/4; } if ($night) { if ($lum<20 && $bias<$webcam['maxExposure']) { $shallExp= $bias+1; } if ($lum>40 && $bias>0) { $shallExp= $bias-1; } if ($lum>50 && $bias>1) { $shallExp= $bias-2; } } elseif ($bias>0) { $shallExp= 0; } if ($shallIso>0 || $shallExp>=0) { if ($shallExp<0) $shallExp= ""; sendCommand("webcam_isoexp $shallIso $shallExp"); } } // On very dark images, do some gamma correction webcamGammaCorrect($img, $lum); return $lum; } // -------------------------------------------------------------------------- // Send one command to the webcam host // -------------------------------------------------------------------------- function sendCommand($cmd) { global $webcam; $serial= time(); $webcam['lastCommand']= $serial; doLog($cmd, "command", $serial); echo("Command: $cmd\n"); // If there is already a command pending, overwrite it silently // This is not really polite but avoids deadlock and command accumulation $cmdName= $webcam['workPath']."/tmp/command.txt"; $cmdf= @fopen($cmdName, "w"); if ($cmdf) { fwrite($cmdf, "$serial\n$cmd\n"); fclose($cmdf); } } // -------------------------------------------------------------------------- // Write some debugging output // -------------------------------------------------------------------------- function doLog($phrase, $facility= "log", $serial=0) { global $webcam; $logName= $webcam['workPath']."/tmp/log.txt"; $logFile= fopen($logName, "a+t"); if ($logFile) { $stamp= strftime("%d.%m.%y %H:%M:%S;",time()); $stamp.= time().";$facility;$serial;"; foreach (explode("\n", $phrase) as $line) { $line= preg_replace("/\r/", "", $line); fputs($logFile, $stamp.$line."\n"); } fclose($logFile); } } // -------------------------------------------------------------------------- // For all upload and command/response scripts some basic vars ar required // -------------------------------------------------------------------------- function checkUploadVars() { global $webcam; Header("Content-Type: text/plain"); if (! isset($_POST['wc'])) { echo("No cam parameter given.\n"); die; } if (! preg_match("/^[a-z0-9\-\_]+$/i", $webcam['name'])) { echo("No cam specified.\n"); die; } // at minimum the title MUST be set if (!isset($webcam['title'])) { echo("Cannot load config for {$webcam['name']}\n"); die; } //echo($_POST['key']); // Some kind of minimal security if ($webcam['uploadkey'] != $_POST['key'] && $webcam['uploadkeyTwo'] != $_POST['key']) { echo("Unauthorized."); die; } prepareWebcamPath($webcam['workPath']); return true; } // -------------------------------------------------------------------------- ?>