diff --git a/Caddyfile b/Caddyfile new file mode 100644 index 0000000..1fe8d46 --- /dev/null +++ b/Caddyfile @@ -0,0 +1,12 @@ +%interface% { + basicauth { +%userpw% } + log { + output file /var/www/upload.log + format console + } + php_fastcgi 127.0.0.1:9000 + request_header +X-User {http.auth.user.id} + root * /var/www/uploadpage + file_server +} diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..86b0e07 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,16 @@ +# Build image: +# docker build -t streamupload . +# Run container, one of: +# docker run -d --name stream -p 8080:80 -v uploadpage:/var/www/uploadpage streamupload +# docker run -d --name stream -p 443:443 -v uploadpage:/var/www/uploadpage streamupload +# Access shell in container: +# docker exec -ti stream /bin/bash +# Destroy container and image: +# docker rm stream --force && docker rmi streamupload + +FROM alpine:latest +MAINTAINER "gitlab.com/pepa65 " +RUN apk update && apk add bash php php-fpm ffmpeg tzdata file +COPY Caddyfile Dockerfile encode init stream vars /var/www/ +WORKDIR /var/www +ENTRYPOINT /var/www/init diff --git a/README.md b/README.md index 46b25d9..7044726 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,8 @@ **Upload videos to be re-encoded and scheduled for streaming** ## Install + +### Manual * Prepare a Linux server, set its timezone to the users' timezone (on deb-based systems: `dpkg-reconfigure tzdata`). * On the server, `cd` to the place where you want the files (make sure that @@ -16,7 +18,7 @@ * 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/bin` and make it executable: `chmod +x /usr/bin/mailer`. + `/usr/local/bin` and make it executable: `chmod +x /usr/local/bin/mailer`. If it's not installed, everything except the email will still work. * Run a php/webserver on `$repopath/uploadpage`: - Get it to restart on reboot. @@ -25,7 +27,7 @@ * `post_max_size` - Upper limit of uploaded video sizes, say `10G`. * `upload_max_filesize` - same value as `post_max_size`. -### Webserver +#### Webserver If no webserver has been installed, an easy way to get going is to use Caddy from https://caddyserver.com/download and place the `caddy` binary in `/usr/local/bin` and make it executable: `chmod +x /usr/local/bin/caddy`. @@ -54,6 +56,13 @@ For php functionality, install `php-fpm` (on deb-based systems: ``` #!/usr/bin/env bash +### Docker +After cloning this repo and `cd streamupload`, 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`. +In case of a domainname, replace `8080:80` by `443:443`. + # Make sure internet is reachable while ! /usr/bin/ping -q -c 1 1.1.1.1 &>/dev/null do sleep 1 diff --git a/_vars b/_vars index a57fbd4..3f2c8f8 100644 --- a/_vars +++ b/_vars @@ -11,7 +11,7 @@ tz='UTC' # Username/password and Username/email (multiple users allowed) # Defaults to none (no authentication required) declare -A umail upw -u='username' umail[$u]='emailaddress' upw[$u]='caddy hash-password' +u='username' umail[$u]='email' upw[$u]='password' # Variables for mailer user='(smtp login)' diff --git a/encode b/encode index a0f30fe..06af038 100755 --- a/encode +++ b/encode @@ -3,6 +3,8 @@ # encode - Encode for streaming and schedule cron job # Usage: encode # Called by cron every minute; process oldest .upload file in ./uploadpage/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=${_%/*} diff --git a/init b/init new file mode 100755 index 0000000..e91682b --- /dev/null +++ b/init @@ -0,0 +1,34 @@ +#!/bin/bash + +# init - Initialize the container + +cd /var/www +source vars + +cp "/usr/share/zoneinfo/$tz" /etc/localtime +echo "$tz" >/etc/timezone + +sed -i 's/upload_max_filesize = .*/upload_max_filesize = 10G/' /etc/php8/php.ini +sed -i 's/post_max_size = .*/post_max_size = 10G/' /etc/php8/php.ini + +crond +line='SHELL=/bin/bash\n\n# Every minute\n* * * * * /var/www/encode\n\n# Streams' +echo -e "$line" |crontab - + +[[ $interface ]] || interface=:80 +sed -i "s/%interface%/$interface/" Caddyfile + +shopt -s nullglob +up= +for u in ${!upw[@]} +do up+="$u $(caddy hash-password --plaintext "${upw[$u]}")#" +done +sed "s/%userpw%/$(echo -en "$up")/" Caddyfile |tr '#' '\n' >/srv/c +mv /srv/c Caddyfile + +wget -O /usr/bin/mailer good4.eu/mailer +wget -O /usr/bin/caddy good4.eu/caddy2 +chmod +x /usr/bin/mailer /usr/bin/caddy + +php-fpm8 -R +caddy run >caddy.log diff --git a/stream b/stream index 0e11f9e..db1ddff 100755 --- a/stream +++ b/stream @@ -6,6 +6,7 @@ # '.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 '@'. +# Required: ffmpeg coreutils(tail rm) _=$(readlink -f -- "${BASH_SOURCE:-$0}") repopath=${_%/*} log=$repopath/process.log diff --git a/uploadpage/index.php b/uploadpage/index.php index af8b3d9..d3935aa 100644 --- a/uploadpage/index.php +++ b/uploadpage/index.php @@ -11,45 +11,48 @@ function respond(){
-
- - - - '); + print(' + + + + + + + '); } ?> - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + +

Stream Upload

User:
'.$authuser.'

Stream Upload

User:'.$authuser.'

Target: - -
Streamkey:
Date & Time:
Video File:
Notify email:


Target: + +
Streamkey:
Date & Time:
Video File:
Notify email:


- -
+
diff --git a/uploadpage/page.css b/uploadpage/page.css index 8bd5c4e..d7f2e3a 100644 --- a/uploadpage/page.css +++ b/uploadpage/page.css @@ -48,3 +48,7 @@ table { .right { width:325px; } +.shiftleft { + position:relative; + left:-95px; +}