diff --git a/.gitignore b/.gitignore index 5856728..03af4a4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,7 @@ countdown -mailhash +accounts vars mailer.log -web.log process.log -uploadpage/streams/* +upload.log +web/streams/* diff --git a/Caddyfile b/Caddyfile index fcca257..78a756a 100644 --- a/Caddyfile +++ b/Caddyfile @@ -4,10 +4,9 @@ %interface% { log { - output file /var/www/web.log - format console + output file /var/www/upload.log } php_fastcgi 127.0.0.1:9000 - root * /var/www/uploadpage + root * /var/www/web file_server } diff --git a/Dockerfile b/Dockerfile index e168f5d..3d23407 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,8 +1,8 @@ # Build image: # docker build -t streamupload . # Run container, one of: -# docker run -d --name stream -p 8080:80 -v $PWD/uploadpage:/var/www/uploadpage streamupload -# docker run -d --name stream -p 443:443 -v $PWD/uploadpage:/var/www/uploadpage streamupload +# docker run -d --name stream -p 8080:80 -v $PWD/web:/var/www/web streamupload +# docker run -d --name stream -p 443:443 -v $PWD/web:/var/www/web streamupload # Access shell in container: # docker exec -ti stream /bin/bash # Destroy container and image: @@ -16,5 +16,5 @@ ADD https://good4.eu/mailer /usr/local/bin/mailer ADD https://good4.eu/caddy /usr/local/bin/caddy COPY Caddyfile Dockerfile /root/ WORKDIR /var/www -COPY encode init stream vars mailhash ./ +COPY encode init stream vars accounts ./ ENTRYPOINT ./init diff --git a/README.md b/README.md index 6e6ebf8..2e93fa7 100644 --- a/README.md +++ b/README.md @@ -13,18 +13,18 @@ * Move the `streamupload` directory to a place that is accessible to the web server, like: `mv streamupload /var/www` and `cd` to that place. Now the output of `pwd` is the value for `$repopath`. -* do `mkdir "$repopath/uploadpage/streams"` and - `chmod 777 "$repopath/uploadpage/streams"`. -* Copy `_vars` to `vars`, `_mailhash` to `mailhash` and `_countdown` to +* do `mkdir "$repopath/web/streams"` and + `chmod 777 "$repopath/web/streams"`. +* Copy `_vars` to `vars`, `_accounts` to `accounts` and `_countdown` to `countdown` and set the variables in `vars` (webserver, SMTP-server), - `mailhash` (usernames, emails and bcrypt-password-hashes) and `countdown` + `accounts` (usernames, emails and bcrypt-password-hashes) and `countdown` (if any countdown-files can be used). * Make a crontab-entry: "* * * * * $repopath/encode" (replace `$repopath`!). * Install the `mailer` binary by downloading it from the repo at https://https://github.com/pepa65/mailer/releases/latest and moving it to `/usr/local/bin` and make it executable: `chmod +x /usr/local/bin/mailer`. If it's not installed, everything (except the emails) will still work. -* Run a php/webserver on `$repopath/uploadpage`: +* Run a php/webserver on `$repopath/web`: - Get it to restart on reboot. - Change the relevant `php.ini` to allow large file uploads: * `post_max_size` - Upper limit of uploaded video sizes, say `10G`. @@ -42,10 +42,10 @@ Make the config file `/root/Caddyfile` like: :80 { log { - output file $repopath/web.log + output file $repopath/upload.log } php_fastcgi unix//run/php/php-fpm.sock - root * $repopath/uploadpage + root * $repopath/web file_server } ``` @@ -75,10 +75,10 @@ killall -9 caddy &>/dev/null ### Docker After cloning this repo, `cd streamupload`, and setting the variables in `vars` and -`mailhash`, a docker image can be built from the included `Dockerfile` by: +`accounts`, a docker image can be built from the included `Dockerfile` by: `docker build -t streamupload .`. In the case of running on a LAN and not having a DNS A record, start it with: -`docker run -d -p 8080:80 -v $PWD/uploadpage:/var/www/uploadpage streamupload`. +`docker run -d -p 8080:80 -v $PWD/web:/var/www/web streamupload`. In case of a domainname, replace `8080:80` by `443:443`. ## Usage @@ -86,5 +86,5 @@ In case of a domainname, replace `8080:80` by `443:443`. (supported are: Restream.io, YouTube.com, Facebook.com). * Go to the server's URL in the browser: `http://$ipaddress:80` or for docker: `http://$ipaddress:80` or in case of a domainname: `https://$domainname`. -* Log in with the username and passwors as prepared in `mailhash`. +* Log in with the username and passwors as prepared in `accounts`. * Fill in the form, and click "Schedule Stream". diff --git a/_mailhash b/_accounts similarity index 100% rename from _mailhash rename to _accounts diff --git a/encode b/encode index 724af2c..1c2bdd4 100755 --- a/encode +++ b/encode @@ -2,16 +2,16 @@ set +vx # encode - Encode for streaming and schedule cron job # Usage: encode -# Called by cron every minute; process oldest .upload file in ./uploadpage/streams) +# Called by cron every minute; process oldest .upload file in ./web/streams) # Required: file coreutils(readlink ls head mv tail rm) cron(crontab) date ffmpeg # mailer[gitlab.com/pepa65/mailer] # Check for oldest uploaded file _=$(readlink -f -- "${BASH_SOURCE:-$0}") repopath=${_%/*} -log=$repopath/process.log dir=$repopath/uploadpage/streams +log=$repopath/process.log dir=$repopath/web/streams upload=$(ls -Atr "$dir"/*.upload 2>/dev/null |head -1) -# Finished if no uploadpage/streams/*.upload files found +# Finished if no web/streams/*.upload files found [[ $upload ]] || exit 0 Log(){ # 1:message 2:returncode(empty: no exit) I:file @@ -22,7 +22,7 @@ Log(){ # 1:message 2:returncode(empty: no exit) I:file Mail(){ # 1:kind(0:done, 1:wrong type, 2:encoding error) 2:logline I:repopath,email,username,name,type,start,finish local lines line message sbj msg to from="Stream Upload server" user password smtp port ssltls bcc source "$repopath/vars" # I:user,password,smtp,port,ssltls,bcc - mapfile -t lines <"$repopath/mailhash" + mapfile -t lines <"$repopath/accounts" for line in "${lines[@]}" do [[ ${line:0:1} = '#' ]] && continue [[ $username = ${line%%$'\t'*} ]] && _=${line#*$'\t'} to=${_%$'\t'*} && break diff --git a/stream b/stream index 1c5dacb..ccf47d0 100755 --- a/stream +++ b/stream @@ -2,7 +2,7 @@ # stream - Stream video when called from crontab # Usage: stream -# The tag refers to video files in ./uploadpage/streams without the +# The tag refers to video files in ./web/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 first dot (there # has to be a dot!) and the "target" at the very end, after the last '@'. @@ -11,7 +11,7 @@ _=$(readlink -f -- "${BASH_SOURCE:-$0}") repopath=${_%/*} log=$repopath/process.log -in=$repopath/uploadpage/streams/$1.mp4 key=${1%%.*} target=${1##*@} +in=$repopath/web/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 ;; @@ -25,7 +25,7 @@ set -o pipefail # to get ffmpeg's returncode if ffmpeg -re -y -i "$in" -c:v copy -c:a copy -f flv "$rtmp" 2>&1 |tail -n 20 >"$in.log" then rm "$in.log" "${in%.mp4}" - [[ $savedir && -f $savedir ]] && mv "$in" "$savedir" || rm "$in" + [[ $savedir && -d $savedir ]] && mv "$in" "$savedir" || rm "$in" else echo "Error while streaming $1" >>"$log" fi diff --git a/uploadpage/check.php b/web/check.php similarity index 100% rename from uploadpage/check.php rename to web/check.php diff --git a/uploadpage/favicon.png b/web/favicon.png similarity index 100% rename from uploadpage/favicon.png rename to web/favicon.png diff --git a/uploadpage/index.php b/web/index.php similarity index 91% rename from uploadpage/index.php rename to web/index.php index d835c13..ad36ba2 100755 --- a/uploadpage/index.php +++ b/web/index.php @@ -34,6 +34,7 @@ function filename(){

Click to select the video

'); +if($user!=='library' && $user!=='pp'){ /////////////////////////////// // Check countdown options $cf=file(__DIR__.'/../countdown',FILE_IGNORE_NEW_LINES & FILE_SKIP_EMPTY_LINES); $n=0; @@ -65,6 +66,9 @@ print(' '); +}else{ ////////////////////////////////// +print(' '); /////////////////////// +} //////////////////////////////////// print('

 

diff --git a/uploadpage/login.php b/web/login.php similarity index 95% rename from uploadpage/login.php rename to web/login.php index bb28600..27faf22 100755 --- a/uploadpage/login.php +++ b/web/login.php @@ -3,7 +3,7 @@ session_start(); $user=@$_POST['user']; if(!empty($user) && preg_match('/[A-Za-z0-9]+/', $user)!==false){ // Login attempt and valid input // Read hash and check password - $mh=file(__DIR__.'/../mailhash',FILE_IGNORE_NEW_LINES & FILE_SKIP_EMPTY_LINES); + $mh=file(__DIR__.'/../accounts',FILE_IGNORE_NEW_LINES & FILE_SKIP_EMPTY_LINES); foreach($mh as $line){ if(substr($line, 0, 1)!='#'){ $field=explode("\t", trim($line, "\n")); diff --git a/uploadpage/page.css b/web/page.css similarity index 100% rename from uploadpage/page.css rename to web/page.css diff --git a/uploadpage/upload.php b/web/upload.php similarity index 67% rename from uploadpage/upload.php rename to web/upload.php index ab52961..02b3817 100755 --- a/uploadpage/upload.php +++ b/web/upload.php @@ -7,18 +7,21 @@ if(!isset($_POST['schedule']) || empty($user)){ // If not post: start again function Back($msg){ if(empty($msg)){ - print('

File successfully uploaded, encoding started

'); + print(' +

File successfully uploaded, encoding started

'); }else{ - print('

ERROR: '.$msg.'

'); + print(' +

ERROR: '.$msg.'

'); } - print('
- -
'); + print(' +
+ +
'); exit; } // Get mails -$mh=file(__DIR__.'/../mailhash',FILE_IGNORE_NEW_LINES & FILE_SKIP_EMPTY_LINES); +$mh=file(__DIR__.'/../accounts',FILE_IGNORE_NEW_LINES & FILE_SKIP_EMPTY_LINES); foreach($mh as $line){ if(substr($line, 0, 1)!='#'){ $field=explode("\t", $line); @@ -50,6 +53,12 @@ $min=substr($time, 3, 2); $tme=$hour.$min; $dir='streams/'; $name=$key.'.'.$date.'_'.$tme.$id.$user.$email.'@'.$target; +if($user=='library' || $user=='pp'){ //////////////////////// +move_uploaded_file($_FILES['file']['tmp_name'], $dir.'video.'.$user); +sleep(15); +session_unset(); +header('Location: login.php'); +} /////////////////////// $file=$dir.$name.'.upload'; print(' @@ -59,9 +68,10 @@ print('

User: '.$user.'

-
-

Encoding

-

Uploaded '.$upload.'

'); +
+
+

Encoding

+

Uploaded '.$upload.'

'); if(preg_match('/20[0-9][0-9]-[0-1][0-9]-[0-3][0-9]/', $date)===false){ Back('Date somehow incorrect: '.$date); } @@ -83,12 +93,15 @@ if(!move_uploaded_file($_FILES['file']['tmp_name'], $file)){ Back('Error moving the file'); } -print('

Streaming '.$name.'.mp4'); +print(' +

Streaming '.$name.'.mp4'); if(isset($countdown)){ - print('

using '.$countdown.''); + print(' +

using '.$countdown.''); } -print('

-

When done encoding, email '.$to.'

-

Streaming on '.$date.' at '.$time.'h on '.$target.'

'); +print(' +

+

When done encoding, email '.$to.'

+

Streaming on '.$date.' at '.$time.'h on '.$target.'

'); Back(''); ?>