Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ TIME_ZONE=Asia/Ho_Chi_Minh
NTP_SERVER=pool.ntp.org
DOWNLOAD_INVERVAL=300
DATA_PATH=/var/www/app/data/
#CUSTOM_SCRIPT_192_168_1_10=http://url/custom_download_script_for_your_camera.sh
#CUSTOM_SCRIPT_192_168_1_10=http://url/custom_download_script_for_your_camera.sh
HOTLINK_SECRET=hellowordmyseret
39 changes: 20 additions & 19 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,28 @@ RUN apk --update add wget \
mkdir -p /var/log/supervisor && \
rm /etc/nginx/nginx.conf

WORKDIR /var/www/app
ADD ./webui/composer.json ./webui/composer.lock ./
RUN composer install
ADD ./webui/scripts/package.json ./webui/scripts/yarn.lock ./scripts/
RUN npm install -g yarn && cd /var/www/app/scripts/ && yarn install
ADD ./webui/scripts/main.js ./webui/scripts/player.js ./scripts/
ADD ./webui/index.php ./
ADD ./webui/libs ./libs
ADD ./webui/templates ./templates


RUN mkdir -p /opt/yidownload/
WORKDIR /opt/yidownload/
ADD ./cronjob/yiantcopy.sh ./
ADD ./config/start.sh ./
RUN chmod 755 /opt/yidownload/*.sh

RUN mkdir -p /var/www/app/data

ADD ./config/nginx/nginx.conf /etc/nginx/nginx.conf
ADD ./config/supervisord/supervisord.conf /etc/supervisord.conf

ADD ./config/start.sh /start.sh

# tweak php-fpm config
RUN sed -i -e "s/;cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/g" /etc/php5/php.ini && \
sed -i -e "s/upload_max_filesize\s*=\s*2M/upload_max_filesize = 500M/g" /etc/php5/php.ini && \
Expand All @@ -60,28 +77,12 @@ RUN sed -i -e "s/;cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/g" /etc/php5/php.ini
rm -Rf /etc/nginx/conf.d/* && \
rm -Rf /etc/nginx/sites-available/default && \
mkdir -p /etc/nginx/ssl/ && \
chmod 755 /start.sh && \
find /etc/php5/conf.d/ -name "*.ini" -exec sed -i -re 's/^(\s*)#(.*)/\1;\2/g' {} \;

ADD ./config/nginx/site-default.conf /etc/nginx/sites-enabled/default.conf
RUN mkdir -p /var/www/app/tmp/ && chmod 777 /var/www/app/tmp/
WORKDIR /var/www/app
ADD ./webui/composer.json ./webui/composer.lock ./
RUN composer install
ADD ./webui/scripts ./scripts
RUN cd /var/www/app/scripts/ && npm install
ADD ./webui/index.php ./
ADD ./webui/libs ./libs
ADD ./webui/templates ./templates

RUN mkdir -p /var/www/app/tmp/ && chmod 777 /var/www/app/tmp/

RUN mkdir -p /opt/yidownload/
WORKDIR /opt/yidownload/
ADD ./cronjob/yiantcopy.sh ./
ADD ./config/start.sh ./
RUN chmod 755 /opt/yidownload/*.sh

RUN mkdir -p /var/www/app/data
VOLUME /var/www/app/data

# Expose Ports
Expand Down
18 changes: 15 additions & 3 deletions config/nginx/site-default.conf
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ server {

index index.php;

add_header X-Frame-Options "SAMEORIGIN";
add_header X-Frame-Options "ALLOW-FROM http://hassio.phuonglm.net/";
add_header X-XSS-Protection "1; mode=block";
add_header X-Content-Type-Options "nosniff";

Expand All @@ -35,14 +35,26 @@ server {
internal;
}


location / {
# First attempt to serve request as file, then
# as directory, then fall back to front-end controller
# (do not forget to pass GET parameters).
try_files $uri $uri/ /index.php$is_args$args;
}

location /data {
secure_link $arg_md5,$arg_expires;
secure_link_md5 "$secure_link_expires$uri <HOTLINK_SECRET>";

if ($secure_link = "") {
return 403;
}

if ($secure_link = "0") {
return 410;
}
root /var/www/app;
}

location ~ ^/.+\.php {
root /var/www/app;
Expand Down Expand Up @@ -97,4 +109,4 @@ server {
# Don't log robots.txt or favicon.ico files
location = /favicon.ico { log_not_found off; access_log off; }
location = /robots.txt { allow all; access_log off; log_not_found off; }
}
}
3 changes: 2 additions & 1 deletion config/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ echo -e "Host *\n\tStrictHostKeyChecking no\n" >> /root/.ssh/config
# Tweak nginx to match the workers to cpu's
procs=$(cat /proc/cpuinfo |grep processor | wc -l)
sed -i -e "s/worker_processes 5/worker_processes $procs/" /etc/nginx/nginx.conf
sed -i -e "s/<HOTLINK_SECRET>/$HOTLINK_SECRET/" /etc/nginx/sites-enabled/default.conf


# If an htpasswd file is provided, download and configure nginx
Expand All @@ -23,7 +24,7 @@ printenv | grep -v affinity:container | xargs -I{} echo {} | awk 'BEGIN { FS = "
if [ -f /var/www/app/phing ]; then
cd /var/www/app
/var/www/app/phing ${STAGE}
fi
fi

chown -R nginx:nginx /var/www/app

Expand Down
34 changes: 24 additions & 10 deletions webui/libs/utils.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<?php
$GLOBALS['DATA_DIR'] = getenv("DATA_PATH") ? getenv("DATA_PATH") : "data/";
date_default_timezone_set(getenv("TIME_ZONE") ? getenv("TIME_ZONE") : "UTC");
$GLOBALS['HOTLINK_SECRET'] = getenv("HOTLINK_SECRET") ? getenv("HOTLINK_SECRET") : "hellosecret";
$GLOBALS['HOTLINK_TTL'] = getenv("HOTLINK_TTL") ? getenv("HOTLINK_TTL") : 3600;

class Segment {
public $start;
public $end;
Expand Down Expand Up @@ -52,7 +55,7 @@ public static function getRecordList($basePath, $start, $end){
$dirList = [];
if ($dh = opendir($GLOBALS['DATA_DIR'].$basePath)) {
while (($file = readdir($dh)) !== false) {
if(filetype($GLOBALS['DATA_DIR'].$basePath . '/' . $file) == 'dir' &&
if(filetype($GLOBALS['DATA_DIR'].$basePath . '/' . $file) == 'dir' &&
DateTime::createFromFormat('Y\Ym\Md\DH\H',$file) >= DateTime::createFromFormat('Y\Ym\Md\DH\H',$start->format('Y\Ym\Md\DH\H')) &&
DateTime::createFromFormat('Y\Ym\Md\DH\H',$file) <= DateTime::createFromFormat('Y\Ym\Md\DH\H',$end->format('Y\Ym\Md\DH\H'))){
array_push($dirList, $file);
Expand Down Expand Up @@ -150,7 +153,7 @@ function getData(){
$hostsname = explode(" ", getenv('CAMERAS'));
foreach ($hostsname as $hostname) {
$timeLine = new TimeLine($hostname.'/');
$records = $timeLine->getRange($startDate,
$records = $timeLine->getRange($startDate,
$endDate);
foreach ($records as $record) {
array_push($data->rows, array('c' => array(
Expand All @@ -163,7 +166,17 @@ function getData(){
echo json_encode($data);
};

function path_hash($path, $expires, $secret){
$expires = time() + $expires;
$md5 = md5("$expires$path $secret", true);
$md5 = base64_encode($md5);
$md5 = strtr($md5, '+/', '-_');
$md5 = str_replace('=', '', $md5);
return $path . '?md5=' . $md5 . '&expires=' . $expires;
}

function getPlaylist(){

$base = $_GET['base'];
$start = new DateTime();
$start->setTimestamp( intval($_GET['start']/1000));
Expand All @@ -172,19 +185,20 @@ function getPlaylist(){
$end->setTimestamp(intval($_GET['end']/1000));
$playlist = Utils::getRecordList($base, $start, $end);

$protocol = explode("/",$_SERVER['SERVER_PROTOCOL']);
$protocol = strtolower(array_shift($protocol));

$protocol = "http";
if(isset($_SERVER['HTTP_X_FORWARDED_SCHEME'])){
$protocol = $_SERVER['HTTP_X_FORWARDED_SCHEME'];
}
if ($_GET['type'] == 'm3u'){
header("content-type: audio/x-mpegurl");
echo "#EXTM3U \r\n";
foreach ($playlist as $media) {
echo $protocol."://".$_SERVER['HTTP_HOST'] . '/data/' . $base . '/' . $media . "\r\n";
echo $protocol."://".$_SERVER['HTTP_HOST'] . path_hash('/data/' . $base . '/' . $media, $GLOBALS['HOTLINK_TTL'], $GLOBALS['HOTLINK_SECRET']) . "\r\n";
}
} elseif ($_GET['type'] == 'json') {
$result = array();
foreach ($playlist as $media) {
$fullUrl = $protocol."://".$_SERVER['HTTP_HOST'] . '/data/'. $base . '/' . $media;
$fullUrl = $protocol."://".$_SERVER['HTTP_HOST'] . path_hash('/data/' . $base . '/' . $media, $GLOBALS['HOTLINK_TTL'], $GLOBALS['HOTLINK_SECRET']);
array_push($result, $fullUrl);
}
echo json_encode($result);
Expand All @@ -210,11 +224,11 @@ function deletePlaylist(){
}

$module = "";
if ($_GET['a'] == 'getData'){
if (isset($_GET['a']) && $_GET['a'] == 'getData'){
getData();
} elseif ($_GET['a'] == 'getPlaylist') {
} elseif (isset($_GET['a']) && $_GET['a'] == 'getPlaylist') {
getPlaylist();
} elseif ($_GET['a'] == 'deletePlaylist') {
} elseif (isset($_GET['a']) && $_GET['a'] == 'deletePlaylist') {
deletePlaylist();
} else {
$module = "index";
Expand Down
15 changes: 7 additions & 8 deletions webui/scripts/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ $(document).ready(function(){
});

function getDateFromMedia(url){
return moment(url.substring(44,65),"YYYY[Y]MM[M]DD[D]HH[H]/mm[M]ss[S]");
return moment(url.match(/^.*\.mp4/)[0].slice(-25).substring(0,21),"YYYY[Y]MM[M]DD[D]HH[H]/mm[M]ss[S]");
}

function drawChart() {
Expand Down Expand Up @@ -145,11 +145,10 @@ function drawChart() {
$("#cameraVideo").data("base", base);





$('#myModal').bind('keydown', function(e){
$('#myModal').bind('keydown',function(e){
var keycode = e.keyCode;
var myPlayer = videojs('cameraVideo');

if (keycode == 39) {
var item = myPlayer.playlist.next();
if(item){
Expand All @@ -165,7 +164,7 @@ function drawChart() {
}
});

$('#video_container').swipe({
$('#video_container video').swipe({
swipe:function(event, direction, distance, duration, fingerCount, fingerData) {
if (direction === 'left') {
var item = myPlayer.playlist.next();
Expand All @@ -178,14 +177,15 @@ function drawChart() {
$('#pushModalLabel').html(getDateFromMedia(videojs('cameraVideo').currentSource().src).format("D/M HH:mm"));
}
}
return true;
},
doubleTab: function(event, target){
myPlayer.requestFullscreen();
return true;
}
});

$('#video_container').bind('dblclick', function() { myPlayer.requestFullscreen(); });
$('#video_container video').bind('dblclick', function() { myPlayer.requestFullscreen(); });
myPlayer.playlist(playlist, 0);
myPlayer.playlist.autoadvance(0);

Expand All @@ -199,4 +199,3 @@ function drawChart() {


}

6 changes: 3 additions & 3 deletions webui/scripts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
"bootstrap-datepicker": "1.8.0",
"bootstrap4-fs-modal": "^0.1.5",
"font-awesome": "^4.7.0",
"jquery": "^3.3.1",
"jquery": "^3.5.0",
"jquery-touchswipe": "^1.6.19",
"moment": "2.22.2",
"popper.js": "^1.14.3",
"video.js": "6.2.0",
"videojs-playlist": "^4.2.0"
"video.js": "7.4.1",
"videojs-playlist": "^4.3.0"
},
"devDependencies": {},
"scripts": {
Expand Down
Loading