datetime validation

fix stream details
This commit is contained in:
pepa65 2022-08-30 11:21:07 +07:00
parent 41cff4126a
commit f70bac1332
4 changed files with 15 additions and 9 deletions

2
encode
View File

@ -43,7 +43,7 @@ m=${date:13:2} m=${m#0} h=${date:11:2} h=${h#0}
D=${date:8:2} D=${D#0} M=${date:5:2} M=${M#0}
/usr/bin/crontab -l ||
echo -e "# m h dom mon dow command\n" |/usr/bin/crontab -
line="$m $h $D $M "'*'" $repopath/stream '${video##*/}'"
line="$m $h $D $M "'*'" $repopath/stream '$name'"
echo -e "$(/usr/bin/crontab -l)\n$line" |/usr/bin/crontab -
Log "crontab: '$line'" 0

10
stream
View File

@ -1,13 +1,15 @@
#!/usr/bin/env bash
# stream - Stream video when called from crontab
# Usage: stream <video>
# The video should have been re-encoded by `encode` first,
# and have the streamkey at the start of the filename.
# Usage: stream <tag>
# The tag refers to video files in $repopath/uploadpage/streams without the
# '.mp4', that should have been re-encoded by `encode`. The tag has no path
# information, has the "streamkey" at the start before the dot (it has to have
# a dot!) and the "target" at the very end, after the '@'.
repopath=/var/www
log=$repopath/process.log
in=$repopath/uploadpage/streams/$1 key=${1%%.*} target=${1##*@}
in=$repopath/uploadpage/streams/$1.mp4 key=${1%%.*} target=${1##*@}
case $target in
Facebook) rtmp=rtmps://live-api-s.facebook.com:443/rtmp/$key ;;
YouTube) rtmp=rtmp://a.rtmp.youtube.com/live2/$key ;;

View File

@ -25,7 +25,7 @@ function respond(){
</td></tr>
<tr>
<td class="left">Streamkey:</td>
<td class="right"><input type="text" name="streamkey" id="streamkey" required title="string of 0-9, a-z, A-Z or underscore characters" pattern="[a-zA-Z0-9_]+"></td></tr>
<td class="right"><input type="text" name="streamkey" id="streamkey" required title="string of 0-9, a-z, A-Z, underscore or dash characters" pattern="[a-zA-Z0-9_-]+"></td></tr>
<tr>
<td>Date and Time:</td>
<td><input type="datetime-local" name="datetime" id="datetime" required></td></tr>

View File

@ -16,9 +16,10 @@ function Back($msg){
header('Content-type: text/html; charset=utf-8');
$upload=htmlspecialchars(basename($_FILES['fileToUpload']['name']));
$key=$_POST['streamkey'];
$date=substr($_POST['datetime'], 0, 10);
$hour=substr($_POST['datetime'], 11, 2);
$min=substr($_POST['datetime'], 14, 2);
$datetime=$_POST['datetime'];
$date=substr($datetime, 0, 10);
$hour=substr($datetime, 11, 2);
$min=substr($datetime, 14, 2);
$time=$hour.$min;
$target=$_POST['target'];
$dir='streams/';
@ -32,6 +33,9 @@ print('<!DOCTYPE html>
<div class="container">
<h1>Encoding</h1>
File: '.$upload);
if(preg_match('/20[0-9][0-9]-[0-1][0-9]-[0-3][0-9]T[0-2][0-9]:[0-6][0-9]/', $datetime)===false){
Back('Date/time somehow incorrect: '.$datetime);
}
$now=date('Y-m-dHi');
if(strcmp($now, $date.$time)>0){
Back('Scheduling '.$now.' in the past: '.$date.' '.$time);