added ffmpeg.py
This commit is contained in:
parent
d31fee476a
commit
06b88b88e2
55
blockinst.sh
55
blockinst.sh
|
@ -19,6 +19,7 @@
|
|||
### }
|
||||
###
|
||||
### todo:
|
||||
### ignore cloudflare IPs
|
||||
### add apache
|
||||
### add license text
|
||||
###
|
||||
|
@ -27,7 +28,7 @@
|
|||
filename="$HOME/.config/blocked.txt"
|
||||
|
||||
# Which web server are you using? [nginx|caddy]
|
||||
srv="nginx"
|
||||
srv="caddy"
|
||||
|
||||
# Config locations. Ignore any you don't need
|
||||
confCaddy="$HOME/.config/caddy/blocks"
|
||||
|
@ -35,44 +36,58 @@ confNginx="/etc/nginx/conf.d/blocks.conf"
|
|||
|
||||
# The DNS server to use for the domain lookups
|
||||
# A local dnsmasq server is fine
|
||||
dnsServer="208.67.222.222"
|
||||
dnsServer="192.168.2.2"
|
||||
|
||||
### ----------------------------------------------------
|
||||
### Don't edit anything below unless you know what you're doing
|
||||
### -----------------------------------------------------
|
||||
|
||||
# Cloudflare ip matches
|
||||
cfThree="173.245.48|103.21.244|103.22.200|103.31.4|141.101.64|108.162.192|190.93.240|188.114.96|197.234.240|198.41.128"
|
||||
cfTwo="162.158|104.16|172.64"
|
||||
|
||||
# clear blocks if using nginx
|
||||
if [ "$srv" == "nginx" ]; then
|
||||
sudo rm $confNginx
|
||||
sudo touch $confNginx
|
||||
elif [ "$srv" == "caddy" ]; then
|
||||
rm $confCaddy/*
|
||||
fi
|
||||
|
||||
# read blocklist
|
||||
while read domain; do
|
||||
|
||||
# dns lookup
|
||||
rawip=$(dig +short $domain @$dnsServer | grep '^[.0-9]*$')
|
||||
|
||||
# just say the domain isn't found of lookup fails
|
||||
if [ -z "$rawip" ]; then
|
||||
echo "$domain: not found"
|
||||
# skip if the ip resolves to a cloudflare node
|
||||
if [[ "$(echo $ip | cut -d'.' -f1-3)" == "^($cfThree)$" ]] || [[ "$(echo $ip | cut -d'.' -f1-2)" == "^($cfTwo)$" ]] || [[ "$(echo $ip | cut -d'.' -f1).0.$(echo $ip | cut -d'.' -f3)" == "131.0.72" ]]; then
|
||||
echo "$domain: not willing to block a cloudflare node"
|
||||
else
|
||||
# read each ip in dig's output
|
||||
for ip in $rawip; do
|
||||
echo "$domain: $ip"
|
||||
|
||||
# create block files for caddy
|
||||
if [ "$srv" == "caddy" ]; then
|
||||
echo "$domain" > $confCaddy/$ip
|
||||
# just say the domain isn't found if lookup fails
|
||||
if [ -z "$rawip" ]; then
|
||||
echo "$domain: not found"
|
||||
else
|
||||
|
||||
# create block file for nginx
|
||||
elif [ "$srv" == "nginx" ]; then
|
||||
echo "deny $ip;" | sudo tee -a $confNginx > /dev/null
|
||||
# read each ip in dig's output
|
||||
for ip in $rawip; do
|
||||
echo "$domain: $ip"
|
||||
|
||||
# configured web server not supported
|
||||
else
|
||||
echo "Server unsupported or mis-spelt! Check the config and try again."
|
||||
echo "[ caddy | nginx ]"
|
||||
fi
|
||||
done
|
||||
# create block files for caddy
|
||||
if [ "$srv" == "caddy" ]; then
|
||||
echo "$domain" > $confCaddy/$ip
|
||||
|
||||
# create block file for nginx
|
||||
elif [ "$srv" == "nginx" ]; then
|
||||
echo "deny $ip;" | sudo tee -a $confNginx > /dev/null
|
||||
|
||||
# configured web server not supported
|
||||
else
|
||||
echo "Server unsupported or mis-spelt! Check the config and try again."
|
||||
echo "[ caddy | nginx ]"
|
||||
fi
|
||||
done
|
||||
fi
|
||||
fi
|
||||
done < $filename
|
||||
|
|
44
ffmpeg.py
Executable file
44
ffmpeg.py
Executable file
|
@ -0,0 +1,44 @@
|
|||
#!/usr/bin/env python3
|
||||
###
|
||||
# Upload a video and pipe it through ffmpeg
|
||||
###
|
||||
import cgitb, cgi, os, subprocess
|
||||
|
||||
cgitb.enable()
|
||||
form = cgi.FieldStorage()
|
||||
videoData = form.getvalue('filename')
|
||||
video = "/home/zoey/.config/caddy/www/main/misc/video.mp4"
|
||||
tmp = '/tmp/video.mp4'
|
||||
|
||||
if videoData != None:
|
||||
try:
|
||||
os.remove(video)
|
||||
except OSError:
|
||||
pass
|
||||
try:
|
||||
os.remove(tmp)
|
||||
except OSError:
|
||||
pass
|
||||
|
||||
open(tmp, 'wb').write(videoData)
|
||||
subprocess.Popen(['ffmpeg', '-i', tmp, video])
|
||||
|
||||
print("""\
|
||||
Content-Type: text/html\n
|
||||
<html>
|
||||
<body>
|
||||
<p><a href="/misc/video.mp4">Download Video</a></p>
|
||||
</body>
|
||||
</html>
|
||||
""")
|
||||
else:
|
||||
print("""\
|
||||
Content-Type: text/html\n
|
||||
<html>
|
||||
<body>
|
||||
<form enctype = "multipart/form-data" action = "/ffmpeg" method = "post">
|
||||
<p>File: <input type = "file" name = "filename" /></p>
|
||||
<p><input type = "submit" value = "Upload" /></p>
|
||||
</form>
|
||||
</body>
|
||||
</html>""")
|
Loading…
Reference in a new issue