-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
executable file
·192 lines (171 loc) · 6.74 KB
/
index.php
File metadata and controls
executable file
·192 lines (171 loc) · 6.74 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
188
189
190
191
192
<?php
/* **********START CONFIGURATION ********** */
$RootDir = "./camera/";
$Fuzzy = "2 minutes"; // Filter for possible related files; ± 2 minutes 00 seconds.
$DateFormat = "Y-m-d H:i:s"; //FOR DISPLAY ONLY See PHP's date formatting for alternatives
$IMGFormat = "jpg"; //file extension of auto-generated images
$VIDFormat = "mp4"; //file extension of auto-generated videos
$FileCruft = "01_"; //If your generated-files contain any prefix prior to the date code enter it here.
$PlaybackRate = "5"; //Default playback rate of the video file.
/* **********END CONFIGURATION ********** */
clearstatcache();
$Cameras = array_values(array_diff(scandir($RootDir), array('..', '.', 'index.php')));
$CameraFiles = array();
//Returns a list of files in a given directory ($outerDir); matching any filters ($x)
function getAllFiles( $outerDir , $x){
$dirs = array_values(array_diff( scandir( $outerDir ), array( ".", ".." ) ));
$dir_array = array();
foreach( $dirs as $d ){
if( !is_dir($outerDir."/".$d) && filesize($outerDir."/".$d) ){
if (($x)?ereg($x.'$',$d):1) $dir_array[] = pathinfo($d, PATHINFO_FILENAME);
}
}
asort($dir_array);
return $dir_array;
}
//Loads all files into a nested array
//Format of $CameraFiles[CAMERA_NAME][NUMERICAL_KEY] = filename (no ext)
function getCameraFiles($Cameras, $RootDir, $VIDFormat){
for ($i = 0; $i < count($Cameras); $i++){
$tFiles = getAllFiles($RootDir.$Cameras[$i],$VIDFormat);
for ($x = 0; $x < count($tFiles); $x++){
$CameraFiles[$Cameras[$i]][] = $tFiles[$x];;
}
}
return $CameraFiles;
}
function scale_to_height ($filename, $targetheight) {
$size = getimagesize($filename);
$targetwidth = $targetheight * ($size[0] / $size[1]);
return $targetwidth;
}
function scale_to_width ($filename, $targetwidth) {
$size = getimagesize($filename);
$targetheight = $targetwidth * ($size[1] / $size[0]);
return $targetheight;
}
function dateFromFile($file, $FileCruft){
$file = ltrim($file, $FileCruft);
$date = date_create_from_format('YmdHis',$file);
return($date);
}
function css (){
?><style>
#video {
width: 50% !important;
height: auto !important;
}
.related {
position: absolute;
bottom: 20px;
}
.unlink {
}
</style>
<?php
}
$CameraFiles = getCameraFiles($Cameras, $RootDir, $VIDFormat);
/* **********START DISPLAY ********** */
if(!isset($_GET['index'])){
css();
?><a class='unlink' align='center' href="./?index=unlink&ALL=TRUE">DELETE ALL</a>
<?php
for ($i = 0; $i < count($Cameras); $i++){
if(@count($CameraFiles[$Cameras[$i]]) > 0){
echo "<table>";
echo "<th>". $Cameras[$i]." - ".count($CameraFiles[$Cameras[$i]])." </th><tr>";
//Displays timestamp
for($x = 0; $x < count($CameraFiles[$Cameras[$i]]); $x++){
echo "<td>";
$DateStamp = dateFromFile($CameraFiles[$Cameras[$i]][$x], $FileCruft);
$tWidth = scale_to_width($RootDir.$Cameras[$i]."/".$CameraFiles[$Cameras[$i]][$x].".".$IMGFormat, 250);
echo date_format($DateStamp, $DateFormat);
echo "</td>";
}
echo "</tr><tr>";
//displays screenshot with hyperlink
for($x = 0; $x < count($CameraFiles[$Cameras[$i]]); $x++){
$tWidth = scale_to_width($RootDir.$Cameras[$i]."/".$CameraFiles[$Cameras[$i]][$x].".".$IMGFormat, 250);
echo "<td><a href='./?index=video&camera=".$Cameras[$i]."&video=".$CameraFiles[$Cameras[$i]][$x]."'><img src='".$RootDir.$Cameras[$i]."/".$CameraFiles[$Cameras[$i]][$x].".".$IMGFormat."' height='".$tWidth."' /></a></td>";
}
echo "</tr><tr>";
//Quick Delete button
for($x = 0; $x < count($CameraFiles[$Cameras[$i]]); $x++){
echo "<td><a class='unlink' href='./?index=unlink&camera=".$Cameras[$i]."&video=".$CameraFiles[$Cameras[$i]][$x]."'>QUICK DELETE</a></td>";
}
echo "</tr>";
echo "</table>";
}
}
}
elseif($_GET['index'] == "video"){
if(is_file($RootDir.$_GET['camera']."/".$_GET['video'].".".$VIDFormat)){
css();
$DateStamp = dateFromFile($_GET['video'], $FileCruft);
$Future = clone $DateStamp;
$Past = clone $DateStamp;
echo date_format($DateStamp, $DateFormat)."<br />";
?>
<video id="video" preload="auto" controls autoplay><source src="<?php echo $RootDir.$_GET['camera']."/".$_GET['video'].".".$VIDFormat?>" type="audio/mpeg"></video>
<script type="text/javascript">document.getElementById("video").playbackRate = <?php echo $PlaybackRate;?>;</script>
<br />
<align='center'><a href="./?index=unlink&camera=<?php echo $_GET['camera'];?>&video=<?php echo $_GET['video'];?>"> DELETE THIS</a></align>
<div class="related">
<?php
$Future->modify("+".$Fuzzy);
$Past->modify("-".$Fuzzy);
for ($i = 0; $i < count($Cameras); $i++){
if($Cameras[$i] != $_GET['camera']){
for($x = 0; $x < count($CameraFiles[$Cameras[$i]]); $x++){
$DateStamp = dateFromFile($CameraFiles[$Cameras[$i]][$x], $FileCruft);
if($DateStamp < $Future && $DateStamp > $Past){
$tWidth = scale_to_width($RootDir.$Cameras[$i]."/".$CameraFiles[$Cameras[$i]][$x].".".$IMGFormat, 250);
$tWidth = scale_to_width($RootDir.$Cameras[$i]."/".$CameraFiles[$Cameras[$i]][$x].".".$IMGFormat, 250);
echo "<a href='./?index=video&camera=".$Cameras[$i]."&video=".$CameraFiles[$Cameras[$i]][$x]."'><img src='".$RootDir.$Cameras[$i]."/".$CameraFiles[$Cameras[$i]][$x].".".$IMGFormat."' height='".$tWidth."' /></a>";
}
}
}
}
?>
</div>
<?php
}
else{ echo "INVALID VIDEO FILE";}
}
elseif($_GET['index'] == 'unlink' && isset($_GET['camera']) && isset($_GET['video'])){
@unlink($RootDir.$_GET['camera']."/".$_GET['video'].".".$VIDFormat);
@unlink($RootDir.$_GET['camera']."/".$_GET['video'].".".$IMGFormat);
header('Location: ./');
}
elseif($_GET['index'] == 'unlink' && $_GET['ALL'] == TRUE){
if($_GET['serious'] == TRUE){
$dFiles = array();
for ($i = 0; $i < count($Cameras); $i++){
$mFiles = getAllFiles($RootDir.$Cameras[$i],$VIDFormat);
$jFiles = getAllFiles($RootDir.$Cameras[$i],$IMGFormat);
for ($x = 0; $x < count($mFiles); $x++){
//Only files older than 5 minutes to ensure no strays
$mtime = filemtime($RootDir.$Cameras[$i]."/".$mFiles[$x].".".$VIDFormat);
$now = time();
if(($now - $mtime) >= 300){
$dFiles[] = $RootDir.$Cameras[$i]."/".$mFiles[$x].".".$VIDFormat;
$dFiles[] = $RootDir.$Cameras[$i]."/".$jFiles[$x].".".$IMGFormat;
}
}
}
for($i = 0; $i <= count($dFiles); $i++){
@unlink ($dFiles[$i]);
header('Location: ./');
}
}
else{
?>
<div class='unlink'>ARE YOU CERTAIN? THIS CANNOT BE REVERSED</DIV>
<div class='unlink'> (This will only delete files last modified > 5 minutes ago)</div>
<div class='unlink'><a href='./?index=unlink&ALL=TRUE&serious=TRUE'>ABSOLUTELY</a></div>
<a href='./?index=FALSE'color='blue'>TAKE ME BACK</a>
<?php
}
}
else{header('Location: ./');}
?>