Хотел вообще освободиться от зависимости от Яндекс камеры - но у меня на апаче нет WebDav
Вот оптимизированный движок - подготовленный для крона и с исправленными ошибками (пока без WebDav):
PHP код:
<?php
$max_photos=1000;
//cam init
$cams=Array (
"Моя комната|http://online.yandexcamera.ru/yandex/show/215/image?|rotate180|rec|",
"Парковка|http://online.yandexcamera.ru/yandex/show/3/image?|||",
);
//here is passwords for access cam view
$passwords=Array (
1=>"pass1", //pasha
2=>"pass2", //andrey
3=>"pass3",
4=>"pass4",
);
$salt="abcde12345"; //your secret salt
$refresh_time=50; //sec
$cam=doubleval(@$_GET['cam']);
$auth=0;
if(isset($_GET['pass'])) {$pass=$_GET['pass']; }elseif(isset($_POST['pass'])){ $pass=$_POST['pass']; }else {$pass="";}
if (!preg_match('/^[a-zA-Z0-9-]+$/i',$pass)) { if ($pass!="") { $auth=2; } $pass="";}
if(isset($_GET['rec'])) {$rec=$_GET['rec']; }elseif(isset($_POST['rec'])){ $rec=$_POST['rec']; } else {$rec=0;}
if (!preg_match('/^[0-9]+$/i',$rec)) { $rec=0;}
$hache=md5($_SERVER['HTTP_HOST'].$salt);
session_cache_limiter ('nocache');
session_name($hache);
session_start();
$sid=session_id();
$ids="s".md5($hache);
if (!isset($_SESSION[$ids])){$_SESSION[$ids]=0; }
$divst="";
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head><meta http-equiv="Content-Type" content="text/html; charset=windows-1251" />
<title>Cams by eurowebcart.ru</title>
<link href="http://getbootstrap.com/2.3.2/assets/css/bootstrap.css" rel="stylesheet">
<link href="http://getbootstrap.com/2.3.2/assets/css/bootstrap-responsive.css" rel="stylesheet">
<link href="http://getbootstrap.com/2.3.2/assets/css/docs.css" rel="stylesheet">
<link href="http://getbootstrap.com/2.3.2/assets/js/google-code-prettify/prettify.css" rel="stylesheet">
<!--[if lt IE 9]>
<script src="http://getbootstrap.com/2.3.2/assets/js/html5shiv.js"></script>
<![endif]-->
<script src="http://getbootstrap.com/2.3.2/assets/js/jquery.js"></script>
<script src="http://getbootstrap.com/2.3.2/assets/js/bootstrap-transition.js"></script>
<script src="http://getbootstrap.com/2.3.2/assets/js/bootstrap-alert.js"></script>
<script src="http://getbootstrap.com/2.3.2/assets/js/bootstrap-modal.js"></script>
<script src="http://getbootstrap.com/2.3.2/assets/js/bootstrap-dropdown.js"></script>
<script src="http://getbootstrap.com/2.3.2/assets/js/bootstrap-tooltip.js"></script>
<script src="http://getbootstrap.com/2.3.2/assets/js/bootstrap-popover.js"></script>
<script src="http://getbootstrap.com/2.3.2/assets/js/bootstrap-button.js"></script>
<script src="http://getbootstrap.com/2.3.2/assets/js/bootstrap-carousel.js"></script>
<script src="http://getbootstrap.com/2.3.2/assets/js/google-code-prettify/prettify.js"></script>
<?
if ($pass!="") {
if ($pass=="exit") {
$_SESSION[$ids]=0;
} else {
$auth=2;
while (list($k,$v)=each($passwords)) {
if ($v==$pass) {$_SESSION[$ids]=1; $auth=1; }
}
}
}
if ($auth==2) { $divst=" error"; }
unset ($k,$v,$passwords);
if ($_SESSION[$ids]==1) {
function savefoto ($camnum, $data, $rotate) {
global $max_photos;
$dir="./cams/cam".$camnum;
$t=@file($dir."/count.txt");
$count=doubleval(trim(@$t[0]));
$count++;
if ($count>=$max_photos) { $count==0; }
$fp=fopen($dir."/count.txt","w");
fputs($fp,"$count");
fclose($fp);
@unlink($dir."/$count".".jpg");
rename ($dir."/image.jpeg", $dir."/$count".".jpg");
}
function img2data ($camnum, $title=string,$req=string, $rotate=string, $rec=string, $link=string) {
if ($req) {
if(is_dir("./cams")!=true) { mkdir("./cams",0755); }
$dir="./cams/cam".$camnum;
if(is_dir($dir)!=true) { mkdir($dir,0755); }
$o=@fopen($dir."/image.jpeg","r");
$cur=@fread($o,@filesize($dir."/image.jpeg"));
@fclose($o);
$img="";
$req.=time();
if (function_exists('curl_init')) {
$ch = curl_init($req);
@curl_setopt($ch, CURLOPT_HEADER, FALSE);
@curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
@curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$img = curl_exec($ch);
curl_close($ch);
} else {
$img=file_get_contents($req);
}
if ($img=="") {
return "<div style=\"padding: 5px;\"><i class=\"icon-facetime-video icon-white\"></i> <strong>$title</strong></div><div style=\"padding: 5px;\">No Signal</div>";
} else {
if ($cur!=$img) {
if ($rec!="") { savefoto($camnum,$img,$rotate); }
$o=fopen($dir."/image.jpeg","w");
fputs($o,$img);
fclose($o);
$cur=$img;
}
$rclass="";
$rico="";
$rscr="parent.document.getElementById('modalimg').className='';";
$l1="";
$l2="";
if ($link!="") { $l1="<a href=\"$link\" target=\"blank\">"; $l2="</a>"; }
if ($rotate!="") { $rclass="class=$rotate"; $rscr="parent.document.getElementById('modalimg').className='$rotate';"; $rico="<i class=\"icon-repeat icon-white\" title=\"$rotate\"></i>";}
if ($rec!="") { $rico.="<div class=pull-right>$l1<img border=0 src=\"data:image/gif;base64,R0lGODlhEAAQAIABAP8AAP///yH/C05FVFNDQVBFMi4wAwEAAAAh/wtYTVAgRGF0YVhNUDw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0i".
"VzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMy1jMDExIDY2LjE0NTY2MSwgMjAxMi8wMi8wNi0xNDo1NjoyNyAgICAgICAgIj".
"4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAv".
"I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mLfwkFnKtcFACH5BAUyAAEALAAAAAAQABAAAAIOjI+py+0P".
"o5y02ouzPgUAOw==\"><font color=white>REC</font>$l2</div>";}
$data=base64_encode($cur);
$r="<div style=\"padding: 5px;\">$rico<i class=\"icon-facetime-video icon-white\"></i> <strong>$title</strong> ".date("H:i:s",time())."</div><a href=\"#fullscreen\" title=\"Fullscreen\">";
if ($link=="") {
$r.="<img onclick=\"parent.document.getElementById('modalframe').innerHTML='';
parent.document.getElementById('modalimg').src=this.src;
parent.document.getElementById('myModalLabel').innerHTML='".str_replace("'", "",str_replace("\"", "", strip_tags($title)))."';
".$rscr."parent.$('#myModal').modal('show');\"";
} else {
$r.="<img onclick=\"parent.document.getElementById('modalframe').innerHTML='<iframe class=preview src=".$link."></iframe>';
parent.document.getElementById('myModalLabel').innerHTML='".str_replace("'", "",str_replace("\"", "", strip_tags($title)))."';
parent.$('#myModal').modal('show');\"";
}
$r.=" id=cam".$camnum." src=\"data:image/jpeg;base64,".$data."\" style=\"cursor: zoom-in;\"".$rclass." /></a>";
return $r;
}
}
}
if ($cam==0) {
if (count($cams)>0) {
$camnum=1;
echo "<style>
.frame {
margin-right: 5px;
margin-bottom: 5px;
width: 320px;
height: 270px;
overflow: hidden;
}
.preview {
position: absolute;
width: 100%;
height: 100%;
overflow: hidden;
border: none;
}
.rotate180 {
-moz-transform: rotate(180deg)
scale(1);
-o-transform: rotate(180deg)
scale(1);
-webkit-transform: rotate(180deg)
scale(1);
transform: rotate(180deg)
scale(1);
}
.modal {
position: fixed;
top: 1%;
left: 25%;
z-index: 1050;
min-width: 50%;
max-width: 100%;
height: 90%;
margin-left: 0px;
background-color: #FFF;
border: 1px solid rgba(0, 0, 0, 0.3);
border-radius: 6px;
outline: medium none;
box-shadow: 0px 3px 7px rgba(0, 0, 0, 0.3);
background-clip: padding-box;
}
.modal-body {
height: 100%;
padding: 0px;
overflow-y: auto;
}
</style></head><body style=\"padding:10px; margin:0; color:#000; background-color:#fff;\"><div class=well>
<a href=\"".$_SERVER['PHP_SELF']."?pass=exit\" class=\"btn btn-info pull-right\" style=\"margin-left: 10px;\"><i class=\"icon-off icon-white\"></i> Exit</a>";
while (list($k,$v)=each($cams)) {
echo "<iframe class=\"thumbnail pull-left frame\" src=\"".$_SERVER['PHP_SELF']."?".SID."&cam=$camnum\"></iframe>";
$camnum++;
}
echo "<div style=\"clear: both;\"></div></div>";
echo " <!-- Modal -->
<div id=\"myModal\" class=\"modal hide\" tabindex=\"-1\" role=\"dialog\" aria-labelledby=\"myModalLabel\" aria-hidden=\"true\">
<div class=\"modal-header\">
<button type=\"button\" class=\"close\" data-dismiss=\"modal\" aria-hidden=\"true\">×</button>
<h3 id=\"myModalLabel\" style=\"color: #000;\"></h3>
</div>
<div class=\"modal-body\">
<p><img id=modalimg /><span id=modalframe></span></p>
</div>
</div>";
} else {
echo "No cams detected!";
}
} else {
if ($rec==0) {
echo "<META HTTP-EQUIV=\"REFRESH\" CONTENT=\"".($refresh_time+$cam).";URL=".$_SERVER['PHP_SELF']."?".SID."&cam=$cam\">";
}
echo "<style>
.rotate180 {
-moz-transform: rotate(180deg)
scale(1);
-o-transform: rotate(180deg)
scale(1);
-webkit-transform: rotate(180deg)
scale(1);
transform: rotate(180deg)
scale(1);
}
";
if ($rec!=0) {
echo ".carousel-fade .carousel-inner .item {
opacity: 0;
-webkit-transition-property: opacity;
-moz-transition-property: opacity;
-o-transition-property: opacity;
transition-property: opacity;
}
.carousel-fade .carousel-inner .active {
opacity: 1;
}
.carousel-fade .carousel-inner .active.left,
.carousel-fade .carousel-inner .active.right {
left: 0;
opacity: 0;
z-index: 1;
}
.carousel-fade .carousel-inner .next.left,
.carousel-fade .carousel-inner .prev.right {
opacity: 1;
}
.carousel-fade .carousel-control {
z-index: 2;
background: none;
border: none;
}
html,
body,
.carousel,
.carousel-inner,
.carousel-inner .item {
height: 100%;
width: 100%;
overflow-y: hidden;
}
.carousel-caption { background: none; text-shadow: 0px 1px 1px rgba(0, 0, 0, 0.8); }
";
}
echo "
</style>
</head><body style=\"padding:0; margin:0; color:#fff; background-color:#000;\">";
$camnum=1;
while (list($k,$v)=each($cams)) {
if ($camnum==$cam) {
$t=explode("|", $v);
if ($rec==0) {
echo img2data($cam,$t[0],$t[1],$t[2],$t[3],$_SERVER['PHP_SELF']."?".SID."&cam=$cam&rec=1");
} else {
$recs=Array();
$ff=0;
$rdir="./cams/cam".$cam;
$rst="";
if ($t[2]!="") { $rst=" class=".$t[2];}
if ($handle = opendir($rdir)) {
while (false !== ($fn = readdir($handle))) {
if (substr($fn,-4)==".jpg") {
$recs[filemtime($rdir."/".$fn)]=$fn;
$ff++;
}
}
}
closedir($handle);
echo "<div id=\"myCarousel\" class=\"carousel carousel-fade\" data-interval=\"100\" data-pause=\"hover\">
<div class=\"carousel-inner\">";
$z=0;
if ($ff>0) {
ksort($recs);
$a="";
array_reverse($recs);
reset($recs);
$c=count($recs);
while (list($k1,$v1)=each($recs)) {
echo "<div class=\"item\">
<img".$rst." src=\"cams/cam".$cam."/".$v1."\">
<div class=\"carousel-caption\">Frame <b>".($z+1)."/".($c+1)."</b> ".date("d.m.Y H:i:s", doubleval($k1))."<a class=\"pull-right\" href=\"".$_SERVER['PHP_SELF']."?".SID."&cam=$cam&rec=1\" title=\"Refresh scene\"><font color=white><i class=\"icon-refresh icon-white icon-large\"></i></font></a>
</div>
</div>";
$z++;
}
}
echo "<div class=\"item active\">
<img".$rst." src=\"cams/cam".$cam."/image.jpeg?".time()."\">
<div class=\"carousel-caption\"><b>NOW</b> ".date("d.m.Y H:i:s", time())."<a class=\"pull-right\" href=\"".$_SERVER['PHP_SELF']."?".SID."&cam=$cam&rec=1\" title=\"Refresh scene\"><font color=white><i class=\"icon-refresh icon-white icon-large\"></i></font></a>
</div>
</div>
</div>
<a class=\"carousel-control left\" href=\"#myCarousel\" data-slide=\"prev\">‹</a>
<a class=\"carousel-control right\" href=\"#myCarousel\" data-slide=\"next\">›</a>
</div>";
}
}
$camnum++;
}
}
} else {
echo "</head><body style=\"padding:10px; margin:0; color:#000; background-color:#fff;\">
<div class=\"well\" align=center>
<script type=\"text/javascript\">
function submit_auth(e)
{
if (e.keyCode == 13)
{
document.getElementById('form').submit();
return false;
}
}
</script>
<form action=\"".$_SERVER['PHP_SELF']."\" id=form method=POST>
<input type=hidden name=cam value=$cam>
<div class=\"control-group".$divst."\">
<br>
<h3>Enter Password:</h3>
<br><input type=password name=pass value=\"\" placeholder=\"password\" onkeyup=\"submit_auth(event);\" autocomplete=\"off\">
<br></div>
</form>
</div>";
}
?>
</body></html>