diff --git a/.gitignore b/.gitignore index 558e183..7d7d497 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ vars +mailhash process.log uploadpage/streams/* diff --git a/_mailhash b/_mailhash new file mode 100644 index 0000000..1598fea --- /dev/null +++ b/_mailhash @@ -0,0 +1,3 @@ +# Separated by TABs: user/mail/bcrypt-hash +# Get hash: php -r "echo password_hash('$password', PASSWORD_BCRYPT);" +username e@ma.il $2y$10$XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX diff --git a/encode b/encode index d796ea9..4d44f94 100755 --- a/encode +++ b/encode @@ -20,10 +20,16 @@ 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,name,type,start,finish - source "$repopath/vars" # I:umail,user,password,smtp,port + source "$repopath/vars" # I:user,password,smtp,port local sbj msg from="Stream Upload server" - # If proper email set, use it, otherwise it's the authusername: look up email - [[ $email = *@* ]] && to=$email || to=${umail[$email]} + declare -A mails + mapfile -t <"$repopath/mailhash" + for line in "${MAPFILE[@]}" + do [[ ${line:0:1} = '#' ]] && continue + l=${line%$'\t'*} mails[${l%$'\t'*}]=${l#*$'\t'} + done + # If proper email set, strip ':', otherwise it's the user: look up email + [[ $email ]] && to=${email:1} || to=${mails[$email]} [[ $port ]] || port=587 sbj[0]="Stream Upload encoding done for ${name##*@}" sbj[1]="Stream Upload file wrong type: $type" @@ -32,12 +38,12 @@ Mail(){ # 1:kind(0:done, 1:wrong type, 2:encoding error) 2:logline I:repopath,em 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" if [[ $to && $user && $password && $smtp && $port ]] - then + then # All ingredients for a mail present 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]}' failed to send" Log "Start encoding on $start, finished on $finish" - else + else # Can't send Log "== Mail with subject '${sbj[$1]}' could not be sent" (($1==2)) && Log "Start encoding on $start, error on $finish" fi @@ -46,12 +52,9 @@ Mail(){ # 1:kind(0:done, 1:wrong type, 2:encoding error) 2:logline I:repopath,em # Rename upload and check type file=${upload%.upload} video=$file.mp4 name=${file##*/} key=${name%%.*} -rest=${name#*.} date=${rest:0:15} _=${rest:15} email=${_%@*} +rest=${name#*.} date=${rest:0:15} _=${rest:16} username=${_%%:*} _=${_%@*} email=${_#${username}} mv "$upload" "$file" -# Strip the '_' if email set -[[ $email ]] && email=${email:1} - type=$(file -bL --mime-type "$file") [[ ! ${type:0:5} = video ]] && Mail 1 "File $name is of type $type" diff --git a/uploadpage/check.php b/uploadpage/check.php new file mode 100644 index 0000000..f80fd1d --- /dev/null +++ b/uploadpage/check.php @@ -0,0 +1,9 @@ + diff --git a/uploadpage/index.php b/uploadpage/index.php index 5881019..c58edd5 100644 --- a/uploadpage/index.php +++ b/uploadpage/index.php @@ -1,32 +1,28 @@ - + -Stream Upload +Stream Upload scheduling
- - - - '); -} - print(''); -?> + + + + + - +

Stream Upload

User:'.$authuser.'
'.$user.'
Target: @@ -49,10 +45,11 @@ if($authuser!==''){ Notify email:


-
+'); +?> diff --git a/uploadpage/login.php b/uploadpage/login.php new file mode 100644 index 0000000..670a51d --- /dev/null +++ b/uploadpage/login.php @@ -0,0 +1,49 @@ + + +Stream Upload login + + +
+
+ + '); +if(isset($_POST['login'])){ + print(' + '); +} +print(' + + + + + + + + + +

Stream Upload

Invalid User or Password
User:
Password:
+
+
'); +?> diff --git a/uploadpage/page.css b/uploadpage/page.css index d7f2e3a..2c73f79 100644 --- a/uploadpage/page.css +++ b/uploadpage/page.css @@ -37,7 +37,7 @@ body { max-width:450px; } p { - flex-wrap: nowrap; + flex-wrap:nowrap; } table { width:100%; diff --git a/uploadpage/upload.php b/uploadpage/upload.php index c1c9a6b..3a246bb 100644 --- a/uploadpage/upload.php +++ b/uploadpage/upload.php @@ -1,28 +1,36 @@ -'.$msg.'

-
+
'); exit; } -header('Content-type: text/html; charset=utf-8'); +// Get mails +$mh=file(__DIR__.'/../mailhash',FILE_IGNORE_NEW_LINES & FILE_SKIP_EMPTY_LINES); +foreach($mh as $line){ + if(substr($line, 0, 1)!='#'){ + $field=explode("\t", $line); + $mails[$field[0]]=$field[1]; + } +} $upload=htmlspecialchars(basename($_FILES['file']['name'])); $key=$_POST['streamkey']; $datetime=$_POST['datetime']; $email=$_POST['email']; +$user=$_SESSION['user']; if($email){ - $email='_'.$email; -} else { - $email='_'.$authuser; + $to=$email; + $email=':'.$email; +}else{ + $to=$mails[$user]; } $date=substr($datetime, 0, 10); $hour=substr($datetime, 11, 2); @@ -30,16 +38,16 @@ $min=substr($datetime, 14, 2); $time=$hour.$min; $target=$_POST['target']; $dir='streams/'; -$name=$key.'.'.$date.'_'.$time.$email.'@'.$target; +$name=$key.'.'.$date.'_'.$time.'_'.$user.$email.'@'.$target; $file=$dir.$name.'.upload'; print(' -Encoding +Stream Upload encoding

Encoding

-'.($authuser==='' ? '' : '

For: '.$authuser.'

').' +

For: '.$user.'

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); @@ -60,8 +68,6 @@ if(!move_uploaded_file($_FILES['file']['tmp_name'], $file)){ } print('

File is now being encoded to '.$name.'.mp4

'); -if($email){ - print('

When done, an email will be sent to '.substr($email,1).'

'); -} +print('

When done, an email will be sent to '.$to.'

'); Back('Scheduling for '.$date.' at '.$hour.':'.$min.'h on '.$target.''); ?>