-
Notifications
You must be signed in to change notification settings - Fork 1
/
webcamProxy.php
58 lines (47 loc) · 1.7 KB
/
webcamProxy.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
<?php
function datacb($ch, $data) {
echo $data;
return strlen($data);
}
function Fetch($url, $config) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_USERPWD, $config['username'].":".$config['password']);
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_BUFFERSIZE, 8096);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
curl_setopt($ch, CURLOPT_WRITEFUNCTION, "datacb");
$f = curl_exec($ch);
return $f;
}
function UpdateConfigStrings($currentConfig) {
$newConfig = array();
foreach($currentConfig as $key=>$value) {
$value = str_replace("{USER}", $currentConfig['username'], $value);
$value = str_replace("{PASS}", $currentConfig['password'], $value);
$newConfig[$key] = $value;
}
return $newConfig;
}
##MAIN:
if (!function_exists('curl_init')) {
echo "php curl support must be installed!!!";
exit(1);
}
if(!isset($_GET['webcam']) || !isset($_GET["cmd"])) {
echo "require a webcam and a cmd param!";
exit(1);
}
$tmp = file_get_contents("webcamConfig.ini");
$configFile = parse_ini_string($tmp, true);
$currentConfig = $configFile[$_GET['webcam']];
header("Connection: close");
header("Content-Type: multipart/x-mixed-replace;boundary=".$currentConfig['boundary']);
$currentConfig = UpdateConfigStrings($currentConfig);
if($currentConfig['logFile'] !== false) {
$fp = fopen($currentConfig['logFile'], 'a');
fwrite($fp, "IN FROM CLIENT:\n".print_r($_GET, true)."\n----------\n");
fwrite($fp, print_r($currentConfig, true)."\n----------\n");
fwrite($fp, $currentConfig['url']."/".$currentConfig[$_GET['cmd']]."\n----------\n");
fclose($fp);
}
$out = Fetch($currentConfig['url']."/".$currentConfig[$_GET['cmd']], $currentConfig);