From 555c7b74447cf8fbf441dfce8b3cf8f4b2235f77 Mon Sep 17 00:00:00 2001 From: pepa65 Date: Wed, 31 Aug 2022 10:54:33 +0700 Subject: [PATCH] Input notify email --- encode | 17 +++++++++++------ stream | 4 ++-- uploadpage/index.php | 11 +++++++---- uploadpage/style.css | 2 +- uploadpage/upload.php | 19 +++++++++++++------ 5 files changed, 34 insertions(+), 19 deletions(-) diff --git a/encode b/encode index 10baba8..25097e9 100755 --- a/encode +++ b/encode @@ -14,26 +14,31 @@ upload=$(/usr/bin/ls -1tr "$dir"/*.upload 2>/dev/null |head -1) Log(){ # 1:message 2:returncode(empty: no exit) I:file echo "$1">>"$log" - [[ $2 ]] && exit $2 + [[ $2 ]] && exit $2 || return 0 } -Mail(){ # 1:kind(0:done, 1:wrong type, 2:encoding error) 2:logline I:to,user,password,smtp,port,name,type,start,finish +Mail(){ # 1:kind(0:done, 1:wrong type, 2:encoding error) 2:logline I:email,name,type,start,finish local sbj msg from="Stream Upload server" - source "$repopath/mailvars" + source "$repopath/mailvars" # I:to,user,password,smtp,port + [[ $email ]] && to=$email sbj[0]="Stream upload done for ${name##*@}" sbj[1]="Stream upload wrong type: $type" sbj[2]="Stream upload error encoding" - msg[0]="Heya,\n\nThe video $name started encoding on $start and finished on $finish.\n\nStream Upload server" + msg[0]="Heya,\n\nVideo file with tag $name\nEncoding started on $start and finished on $finish.\n\nStream Upload server" msg[1]="Heya,\n\nThe file $name from $start is of type $type and could not be used.\n\nStream Upload server\n" msg[2]="Heya,\n\nThe file $name started encoding on $start but ran into an error on $finish.\n\nStream Upload server\n" [[ $to && $user && $password && $smtp && $port ]] && - mailer -m "$(echo -e "${msg[$1]}")" -t "$to" -s "${sbj[$1]}" -u "$user" -p "$password" -S "$smtp" -P "$port" -f "$from" || + mailer -m "$(echo -e "${msg[$1]}")" -t "$to" -s "${sbj[$1]}" -u "$user" -p "$password" -S "$smtp" -P "$port" -f "$from" && + Log "Mail with subject '${sbj[$1]}' sent to $to" || Log "Mail with subject '${sbj[$1]}' could not be sent" Log "$2" $1 } # Rename upload and check type -file=${upload%.upload} name=${file##*/} key=${name%%.*} date=${name##*.} video=$file.mp4 +file=${upload%.upload} video=$file.mp4 name=${file##*/} key=${name%%.*} +rest=${name#*.} date=${rest:0:15} _=${rest:15} email=${_%@*} +# If email embedded, strip the '=' +[[ $email ]] && email=${email:1} /usr/bin/mv "$upload" "$file" type=$(file -bL --mime-type "$file") diff --git a/stream b/stream index a437a1b..d3c49a7 100755 --- a/stream +++ b/stream @@ -4,8 +4,8 @@ # Usage: stream # 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 '@'. +# information, has the "streamkey" at the start before the first dot (there +# has to be a dot!) and the "target" at the very end, after the last '@'. _=$(realpath -- "${BASH_SOURCE:-$0}") repopath=${_%/*} log=$repopath/process.log diff --git a/uploadpage/index.php b/uploadpage/index.php index 3e66308..009cc65 100644 --- a/uploadpage/index.php +++ b/uploadpage/index.php @@ -25,13 +25,16 @@ function respond(){ Streamkey: - + - Date and Time: - + Date & Time: + Video File: - + + + Notify email: +

diff --git a/uploadpage/style.css b/uploadpage/style.css index 50335e6..d89929e 100644 --- a/uploadpage/style.css +++ b/uploadpage/style.css @@ -1,4 +1,4 @@ -input[type=text],[type=file], select, [type=time], [type=date], [type=datetime-local] { +input,select { width:100%; padding:12px 20px; margin:0; diff --git a/uploadpage/upload.php b/uploadpage/upload.php index 7f11299..bef25c0 100644 --- a/uploadpage/upload.php +++ b/uploadpage/upload.php @@ -14,16 +14,20 @@ function Back($msg){ } header('Content-type: text/html; charset=utf-8'); -$upload=htmlspecialchars(basename($_FILES['fileToUpload']['name'])); +$upload=htmlspecialchars(basename($_FILES['file']['name'])); $key=$_POST['streamkey']; $datetime=$_POST['datetime']; +$email=$_POST['email']; +if($email){ + $email='='.$email; +} $date=substr($datetime, 0, 10); $hour=substr($datetime, 11, 2); $min=substr($datetime, 14, 2); $time=$hour.$min; $target=$_POST['target']; $dir='streams/'; -$name=$key.'.'.$date.'_'.$time.'@'.$target; +$name=$key.'.'.$date.'_'.$time.$email.'@'.$target; $file=$dir.$name.'.upload'; print(' @@ -44,13 +48,16 @@ $nextyear=date('Y-m-dHi', strtotime('+1 year')); if(strcmp($nextyear, $date.$time)<0){ Back('Scheduling too far into the future: '.$date.' '.$time); } -if($_FILES['fileToUpload']['error']!=UPLOAD_ERR_OK){ +if($_FILES['file']['error']!=UPLOAD_ERR_OK){ Back('Error uploading the file'); } -if(!move_uploaded_file($_FILES['fileToUpload']['tmp_name'], $file)){ +if(!move_uploaded_file($_FILES['file']['tmp_name'], $file)){ Back('Error moving the file'); } -Back('File is now being encoded to "'.$name.'.mp4"
 
-Scheduling for '.$date.' at '.$hour.':'.$min.'h on '.$target); +print('File is now being encoded to "'.$name.'.mp4"
 
'); +if($email){ + print('When done, an email will be sent to: '.substr($email,1)); +} +Back('Scheduling for '.$date.' at '.$hour.':'.$min.'h on '.$target); ?>