-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcamera-www.php
73 lines (64 loc) · 2 KB
/
camera-www.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
<?php
define('DEBUG', false);
spl_autoload_register(function ($class_name) {
include 'inc/' . $class_name . '.inc.php';
});
$config = new Config(__DIR__ . '/config.inc.php');
$camera = new Camera($config->protocol, $config->address, $config->port, $config->username, $config->password);
$acl = new ACL($config);
$action = empty($_REQUEST['action']) ? 'home' : $_REQUEST['action'];
$code = empty($_REQUEST['code']) ? '' : $_REQUEST['code'];
$msg = empty($_REQUEST['msg']) ? '' : $_REQUEST['msg'];
$authenticated = false;
if ( !empty( $code ) and $acl->allowed( $code ) ) {
$authenticated = true;
} elseif ( $acl->allowed( $_SERVER['REMOTE_ADDR'] ) ) {
$authenticated = true;
}
if ( $authenticated ) {
$msg = $camera->state_hr() . '<br>' . $msg;
}
switch( $action ) {
case 'unlock':
if ( $authenticated ) {
$camera->disarm();
$acl->lock_state();
$acl->notify_state(Camera::$STATE_DISARM_LOCK, $_SERVER['REMOTE_ADDR'] );
header("Location: camera-www.php?action=home&msg=" . urlencode( 'Disarmed for ' . $config->lock_time . ' seconds'));
exit;
} else {
header("Location: camera-www.php?action=home&msg=Unauthorized");
exit;
}
break;
default:
# home
break;
}
?>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<h1>Camera control panel</h1>
<?php if ( !empty( $msg ) ) { ?>
<h2 style="color: #f77;"><?= $msg ?></h2>
<?php } ?>
<?php if ( $action == 'home' ) { ?>
<form method="post" action="camera-www.php" id="form1">
<input type="hidden" name="action" value="unlock">
<?php if ( !$authenticated ) { ?>
<input type="number" name="code" value="" id="codeInp" style="height: 1.3em;">
<script>
document.addEventListener("DOMContentLoaded", function(event) {
document.getElementById('codeInp').focus();
document.getElementById('codeInp').click();
});
</script>
<?php } ?>
<input type="submit" value="Unlock" style="padding: 10px;">
</form>
<?php } ?>
</body>
</html>