-
Notifications
You must be signed in to change notification settings - Fork 14
/
snapshot.php
executable file
·160 lines (137 loc) · 4.2 KB
/
snapshot.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
<?php
/* IP Camera Proxy
* PHP frontend to interface with cheap password-protected webcams and
* pull images for public display on a website
*
* Copyright Will Bradley, 2012 (www.zyphon.com)
* Distributed under a Creative Commons Attribution 3.0 license
* http://creativecommons.org/licenses/by/3.0/
*
* To use, change EXAMPLE.COM, the port number, EXAMPLEUSER, & EXAMPLEPASSWORD
* to their correct values for your setup. I use cheap Hootoo-brand cameras
* for my setup, yours may be different regarding snapshot urls and auth
* mechanisms. Then, host this on a PHP site and access it at
* /snapshot.php?camera=1
*
*/
if($_GET['camera'] == 1)
{
$rand = rand(1000,9999);
$url = 'http://EXAMPLE.COM:80/snapshot.cgi?'.$rand; // remember there needs to be a ? between the URL and the random number. Don't remove the question mark.
$curl_handle=curl_init();
curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER,1);
curl_setopt($curl_handle,CURLOPT_URL,$url);
curl_setopt($curl_handle, CURLOPT_USERPWD, "EXAMPLEUSER:EXAMPLEPASSWORD");
$buffer = curl_exec($curl_handle);
curl_close($curl_handle);
if (empty($buffer))
{
print "";
}
elseif($buffer == "Can not get image.")
{
print "Can not get image.";
}
else
{
header("Content-Type: image/jpeg");
print $buffer;
}
}
elseif($_GET['camera'] == 2)
{
$rand = rand(1000,9999);
$url = 'http://EXAMPLE.COM:81/snapshot.cgi?'.$rand; // remember there needs to be a ? between the URL and the random number. Don't remove the question mark.
$curl_handle=curl_init();
curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER,1);
curl_setopt($curl_handle,CURLOPT_URL,$url);
curl_setopt($curl_handle, CURLOPT_USERPWD, "EXAMPLEUSER:EXAMPLEPASSWORD");
$buffer = curl_exec($curl_handle);
curl_close($curl_handle);
if (empty($buffer))
{
print "";
}
elseif($buffer == "Can not get image.")
{
print "Can not get image.";
}
else
{
header("Content-Type: image/jpeg");
print $buffer;
}
}
elseif($_GET['camera'] == 3)
{
$rand = rand(1000,9999);
$url = 'http://EXAMPLE.COM:82/snapshot.cgi?'.$rand; // remember there needs to be a ? between the URL and the random number. Don't remove the question mark.
$curl_handle=curl_init();
curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER,1);
curl_setopt($curl_handle,CURLOPT_URL,$url);
curl_setopt($curl_handle, CURLOPT_USERPWD, "EXAMPLEUSER:EXAMPLEPASSWORD");
$buffer = curl_exec($curl_handle);
curl_close($curl_handle);
if (empty($buffer))
{
print "";
}
elseif($buffer == "Can not get image.")
{
print "Can not get image.";
}
else
{
header("Content-Type: image/jpeg");
print $buffer;
}
}
elseif($_GET['camera'] == 9)
{
# Used to separate multipart
$boundary = "IPCamBoundary";
# We start with the standard headers. PHP allows us this much
header("Cache-Control: no-cache");
header("Cache-Control: private");
header("Pragma: no-cache");
header("Content-type: image/jpeg");
# From here out, we no longer expect to be able to use the header() function
print "--$boundary\n";
# Set this so PHP doesn't timeout during a long stream
set_time_limit(0);
# Disable Apache and PHP's compression of output to the client
@apache_setenv('no-gzip', 1);
@ini_set('zlib.output_compression', 0);
# Set implicit flush, and flush all current buffers
@ini_set('implicit_flush', 1);
for ($i = 0; $i < ob_get_level(); $i++)
ob_end_flush();
ob_implicit_flush(1);
# The loop, producing one jpeg frame per iteration
// while (true) {
# Your function to get one jpeg image
$rand = rand(1000,9999);
$url = 'http://EXAMPLE.COM:81/GetData.cgi?'.$rand; // remember there needs to be a ? between the URL and the random number. Don't remove the question mark.
$curl_handle=curl_init();
curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER,1);
curl_setopt($curl_handle,CURLOPT_URL,$url);
$buffer = curl_exec($curl_handle);
curl_close($curl_handle);
if (!empty($buffer))
{
# Per-image header, note the two new-lines
print "Content-type: image/jpeg\n\n";
print $buffer;
}
else {
print "Content-type: text/html\n\n";
print "No image.";
}
# The separator
print "--$boundary\n";
// }
}
else {
print "Error: No camera requested.";
}
?>