Merge branch 'master' of ssh://git.barkshark.tk:2222/izaliamae/scripts

This commit is contained in:
Izalia Mae 2019-04-19 11:55:53 -04:00
commit 0a2757fc34
6 changed files with 140 additions and 12 deletions

View file

@ -1,8 +0,0 @@
Copyright (c) <year> <owner> . All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
3. All advertising materials mentioning features or use of this software must display the following acknowledgement:
This product includes software developed by the organization .
4. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY COPYRIGHT HOLDER "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDER BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

93
blockinst.sh Executable file
View file

@ -0,0 +1,93 @@
#!/usr/bin/env bash
###
### Takes a list of instances (one per line), resolves their IPs,
### and creates a blocklist your server understands. Caddy does
### per-server blocks while nginx does server-wide blocks.
###
### Caddy example:
### ipfilter / {
### rule block
### prefix_dir blocks # folder relative to working dir
### blockpage www/blocked.html # optional block page
### }
###
### Nginx example: (not necessary if running debian or a debian derivative)
### http {
### ...
### include blockips.conf;
### ...
### }
###
### todo:
### ignore cloudflare IPs
### add apache
### add license text
###
# blocklist location
filename="$HOME/.config/blocked.txt"
# Which web server are you using? [nginx|caddy]
srv="caddy"
# Config locations. Ignore any you don't need
confCaddy="$HOME/.config/caddy/blocks"
confNginx="/etc/nginx/conf.d/blocks.conf"
# The DNS server to use for the domain lookups
# A local dnsmasq server is fine
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]*$')
# 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
# just say the domain isn't found if lookup fails
if [ -z "$rawip" ]; then
echo "$domain: not found"
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
# 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

0
debloat.sh Normal file → Executable file
View file

View file

@ -2,10 +2,9 @@
from mastodon import Mastodon
import random, sys, json, os
with open(os.environ.get('HOME')+'/.config/mastodon-tokens.json') as json_data:
apikey = json.load(json_data)
apikey = json.load(open(os.environ.get('HOME')+'/.config/mastodon-tokens.json', 'r'))
ident = "barkshark-izalia-emtoot"
ident = "barkshark-izalia-emoji"
mastodon = Mastodon(
access_token=apikey[ident]['token'],

44
ffmpeg.py Executable file
View 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>""")

View file

@ -10,4 +10,4 @@
"domain": "botsin.space",
"token": "access token goes here"
}
}
}