Option for docker

Allow logout
This commit is contained in:
gitlab.com/pepa65 2022-09-05 23:47:43 +07:00
parent 199025ce47
commit 4580ddebbe
9 changed files with 117 additions and 36 deletions

12
Caddyfile Normal file
View File

@ -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
}

16
Dockerfile Normal file
View File

@ -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 <pepa65@passchier.net>"
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

View File

@ -2,6 +2,8 @@
**Upload videos to be re-encoded and scheduled for streaming** **Upload videos to be re-encoded and scheduled for streaming**
## Install ## Install
### Manual
* Prepare a Linux server, set its timezone to the users' timezone * Prepare a Linux server, set its timezone to the users' timezone
(on deb-based systems: `dpkg-reconfigure tzdata`). (on deb-based systems: `dpkg-reconfigure tzdata`).
* On the server, `cd` to the place where you want the files (make sure that * 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`!). * Make a crontab-entry: "* * * * * $repopath/encode" (replace `$repopath`!).
* Install the `mailer` binary by downloading it from the repo at * Install the `mailer` binary by downloading it from the repo at
https://https://github.com/pepa65/mailer/releases/latest and moving it to 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. If it's not installed, everything except the email will still work.
* Run a php/webserver on `$repopath/uploadpage`: * Run a php/webserver on `$repopath/uploadpage`:
- Get it to restart on reboot. - Get it to restart on reboot.
@ -25,7 +27,7 @@
* `post_max_size` - Upper limit of uploaded video sizes, say `10G`. * `post_max_size` - Upper limit of uploaded video sizes, say `10G`.
* `upload_max_filesize` - same value as `post_max_size`. * `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 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 from https://caddyserver.com/download and place the `caddy` binary in
`/usr/local/bin` and make it executable: `chmod +x /usr/local/bin/caddy`. `/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 #!/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 # Make sure internet is reachable
while ! /usr/bin/ping -q -c 1 1.1.1.1 &>/dev/null while ! /usr/bin/ping -q -c 1 1.1.1.1 &>/dev/null
do sleep 1 do sleep 1

2
_vars
View File

@ -11,7 +11,7 @@ tz='UTC'
# Username/password and Username/email (multiple users allowed) # Username/password and Username/email (multiple users allowed)
# Defaults to none (no authentication required) # Defaults to none (no authentication required)
declare -A umail upw 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 # Variables for mailer
user='(smtp login)' user='(smtp login)'

2
encode
View File

@ -3,6 +3,8 @@
# encode - Encode for streaming and schedule cron job # encode - Encode for streaming and schedule cron job
# Usage: encode # Usage: encode
# Called by cron every minute; process oldest .upload file in ./uploadpage/streams) # 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 # Check for oldest uploaded file
_=$(readlink -f -- "${BASH_SOURCE:-$0}") repopath=${_%/*} _=$(readlink -f -- "${BASH_SOURCE:-$0}") repopath=${_%/*}

34
init Executable file
View File

@ -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

1
stream
View File

@ -6,6 +6,7 @@
# '.mp4', that should have been re-encoded by `encode`. The tag has no path # '.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 # 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 '@'. # 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=${_%/*} _=$(readlink -f -- "${BASH_SOURCE:-$0}") repopath=${_%/*}
log=$repopath/process.log log=$repopath/process.log

View File

@ -11,45 +11,48 @@ function respond(){
</script> </script>
<div class="container"> <div class="container">
<div class="incontainer"> <div class="incontainer">
<form action="upload.php" method="post" enctype="multipart/form-data" onsubmit="respond()">
<table> <table>
<tr><td></td><td align="center"><h1>Stream Upload</h1></td></tr>
<?php <?php
$headers=getallheaders(); $headers=getallheaders();
$authuser=$headers['X-User']; $authuser=$headers['X-User'];
if($authuser!==''){ if($authuser!==''){
print(' <tr> print('
<td class="left">User:</td> <form action="'.(isset($_SERVER['HTTPS']) ? 'https' : 'http').'://nouser@'.$_SERVER['HTTP_HOST'].'">
<td class="right"><center><b>'.$authuser.'</b></center></td></tr> <tr><td></td><td align="center"><h1>Stream Upload</h1></td></tr>
<tr>'); <tr>
<td class="left">User:</td>
<td class="right"><b>'.$authuser.'</b></td>
<td><input class="shiftleft" type="submit" value="Logoff"></td></tr>
</form>');
} }
?> ?>
<tr><td><br></td></tr> <form action="upload.php" method="post" enctype="multipart/form-data" onsubmit="respond()">
<tr> <tr>
<td>Target:</td> <td>Target:</td>
<td> <td>
<select name="target" id="target" required> <select name="target" id="target" required>
<option value="Restream">Restream</option> <option value="Restream">Restream</option>
<option value="Facebook">Facebook</option> <option value="Facebook">Facebook</option>
<option value="YouTube">YouTube</option> <option value="YouTube">YouTube</option>
</select> </select>
</td></tr> </td></tr>
<tr> <tr>
<td class="left">Streamkey:</td> <td class="left">Streamkey:</td>
<td class="right"><input type="text" name="streamkey" required title="string of 0-9, a-z, A-Z, underscore or dash characters" pattern="[a-zA-Z0-9_-]+"></td></tr> <td class="right"><input type="text" name="streamkey" required title="string of 0-9, a-z, A-Z, underscore or dash characters" pattern="[a-zA-Z0-9_-]+"></td></tr>
<tr> <tr>
<td>Date & Time:</td> <td>Date & Time:</td>
<td><input type="datetime-local" name="datetime" title="Click on the date to get a popup" required></td></tr> <td><input type="datetime-local" name="datetime" title="Click on the date to get a popup" required></td></tr>
<tr> <tr>
<td>Video File:</td> <td>Video File:</td>
<td><input type="file" name="file" required accept=".mp4"></td></tr> <td><input type="file" name="file" required accept=".mp4"></td></tr>
<td class="left">Notify email:</td> <tr>
<td class="right"><input type="email" name="email" title="Not required"></td></tr> <td class="left">Notify email:</td>
<tr><td><br></td></tr> <td class="right"><input type="email" name="email" title="Not required"></td></tr>
<tr><td></td><td><input type="submit" value="Schedule Stream" name="submit"></td></tr> <tr><td><br></td></tr>
<tr><td><br></td></tr> <tr><td></td><td><input type="submit" value="Schedule Stream" name="submit"></td></tr>
<tr><td align=center colspan="2" id="response"></td></tr> <tr><td><br></td></tr>
<tr><td align=center colspan="2" id="response"></td></tr>
</form>
</table> </table>
</form> </div>
</div>
</div> </div>

View File

@ -48,3 +48,7 @@ table {
.right { .right {
width:325px; width:325px;
} }
.shiftleft {
position:relative;
left:-95px;
}