-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathcamera-manager.php
More file actions
187 lines (165 loc) · 6 KB
/
camera-manager.php
File metadata and controls
187 lines (165 loc) · 6 KB
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
<?php
require_once($_SERVER['DOCUMENT_ROOT'].'/include/main.php');
require_once($_SERVER['DOCUMENT_ROOT'].'/include/camera.php');
require_once($_SERVER['DOCUMENT_ROOT'].'/control/config.php');
// Add
if (isset($_POST['add']) && isset($_POST['name']) && isset($_POST['ip_address']) && isset($_POST['protocol']) && isset($_POST['url']) && isset($_POST['username']) && isset($_POST['password'])) {
$data = array(
'name'=>$_POST['name'],
'ip_address'=>$_POST['ip_address'],
'protocol'=>$_POST['protocol'],
'url'=>$_POST['url'],
'username'=>$_POST['username'],
'password'=>$_POST['password']
);
if (camera::create_camera($database, $data)) {
header('Location: '.$_SERVER['HTTP_REFERER']);
exit();
} else {
echo "Error adding device!";
exit();
}
}
// Delete
if (isset($_POST['delete']) && isset($_POST['id'])) {
$config = new config($database, $_POST['id']);
if (camera::delete_camera($database, $config->config_data, $_POST['id'])) {
header('Location: '.$_SERVER['HTTP_REFERER']);
exit();
} else {
echo "Error deleting device!";
exit();
}
}
// Update
if (isset($_POST['edit']) && isset($_POST['id']) && isset($_POST['field']) && isset($_POST['value'])) {
if (!in_array($_POST['field'], camera::get_valid_properties())) {
exit('1');
}
$config = new config($database, $_POST['id']);
$device = new camera($database, $config->config_data, $_POST['id']);
if ($device->device_data === false || $device->is_active()) {
// Camera does not exist or is running
exit('1');
}
$device->device_data[$_POST['field']] = $_POST['value'];
if ($device->update() === false) {
exit('1');
} else {
exit('0');
}
}
$pagepath = array(array('CCTV CONTROL', '/cctv.php'), array('CAMERA MANAGER', $_SERVER['REQUEST_URI']));
$topbar = true;
include $_SERVER['DOCUMENT_ROOT'].'/include/header.php';
?>
<script>
function remove(id) {
if (confirm('Delete device '+id+'?')) {
var form = document.createElement("form");
var e1 = document.createElement("input");
var e2 = document.createElement("input");
form.method = "POST";
e1.name = "delete";
e1.value = 1;
e1.type = "hidden";
e2.name = "id";
e2.value = id;
e2.type = "hidden";
form.appendChild(e1);
form.appendChild(e2);
document.body.appendChild(form);
form.submit();
}
}
function update(field) {
field.style.backgroundColor = "#FFFF00";
var data = field.name.split("+");
xhr = new XMLHttpRequest();
xhr.open("POST", "");
xhr.onreadystatechange = function() {
if (xhr.readyState === XMLHttpRequest.DONE && xhr.status === 200) {
if (xhr.responseText == 0) {
field.style.backgroundColor = "#FFFFFF";
} else {
field.style.backgroundColor = "#FF0000";
}
}
};
formData = new FormData();
formData.append('edit', 1);
formData.append('id', data[0]);
formData.append('field', data[1]);
formData.append('value', field.value);
xhr.send(formData);
}
</script>
<p><a class="btn btn-default" href="/cctv.php"><<BACK</a></p>
<p>ADD DEVICE:</p>
<form action="" method="POST">
<input type="hidden" name="add" value="1">
<table border="1">
<tr>
<th>ID</th>
<th>NAME</th>
<th>IP ADDRESS</th>
<th>PROTOCOL</th>
<th>URL</th>
<th>USERNAME</th>
<th>PASSWORD</th>
</tr>
<tr>
<td>#</td>
<td><input type="text" name="name"></td>
<td><input type="text" name="ip_address"></td>
<td><input type="text" name="protocol"></td>
<td><input type="text" name="url"></td>
<td><input type="text" name="username"></td>
<td><input type="text" name="password"></td>
<td><input class="btn btn-success" type="submit" value="ADD"></td>
</tr>
</table>
</form>
<hr>
<p>DEVICE LIST:</p>
<table border="1">
<tr>
<th>ID</th>
<th>NAME</th>
<th>IP ADDRESS</th>
<th>PROTOCOL</th>
<th>URL</th>
<th>USERNAME</th>
<th>PASSWORD</th>
</tr>
<?php
$database->query("select `id` from devices");
$highlight = 0;
if (isset($database->result[0])) {
$ids = $database->result;
foreach ($ids as $id) {
$config = new config($database, $id['id']);
$device = new camera($database, $config->config_data, $id['id']);
if ($device->is_active()) {
$running = ' disabled';
} else {
$running = '';
}
echo ($highlight) ? '<tr bgcolor="#CCCCCC">' : '<tr>';
$highlight = ($highlight) ? 0 : 1;
echo '<td>'.$device->device_data['id'].'</td>';
echo '<td><input type="text" name="'.$device->device_data['id'].'+name" value="'.$device->device_data['name'].'" onchange="update(this);"'.$running.'></td>';
echo '<td><input type="text" name="'.$device->device_data['id'].'+ip_address" value="'.$device->device_data['ip_address'].'" onchange="update(this);"'.$running.'></td>';
echo '<td><input type="text" name="'.$device->device_data['id'].'+protocol" value="'.$device->device_data['protocol'].'" onchange="update(this);"'.$running.'></td>';
echo '<td><input type="text" name="'.$device->device_data['id'].'+url" value="'.$device->device_data['url'].'" onchange="update(this);"'.$running.'></td>';
echo '<td><input type="text" name="'.$device->device_data['id'].'+username" value="'.$device->device_data['username'].'" onchange="update(this);"'.$running.'></td>';
echo '<td><input type="text" name="'.$device->device_data['id'].'+password" value="'.$device->device_data['password'].'" onchange="update(this);"'.$running.'></td>';
echo '<td><a class="btn btn-danger" href="#" onclick="remove('.$device->device_data['id'].')">DELETE</a></td>';
echo '</tr>';
}
}
?>
</table>
<?php
include $_SERVER['DOCUMENT_ROOT'].'/include/footer.php';
?>