-
Notifications
You must be signed in to change notification settings - Fork 2
/
webcp
executable file
·58 lines (53 loc) · 2.88 KB
/
webcp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/bin/bash
FILE="$(date +'%s').html"
SCP="$(head -n 1 ~/.config/webcp/config)"
WEB="$(tail -n 1 ~/.config/webcp/config)"
CLIPTOOL='/usr/bin/true'
CLIPARGS=''
unamestr=$(uname)
if [[ "$unamestr" == 'Linux' || "$unamestr" == "FreeBSD" ]]; then
CLIPTOOL='xclip'
CLIPARGS='-selection clipboard'
elif [[ "$unamestr" == 'Darwin' ]]; then
CLIPTOOL='pbcopy'
fi
if [ -p /dev/stdin ]; then
# If piping
echo "<html><head><meta charset=utf-8><title>Raw paste data</title></head><body><pre class=prettyprint style='border: none;'>" > $FILE
while IFS= read line; do
echo "${line}" | sed -r 's/&/\&/g; s/</\</g; s/>/\>/g' >> $FILE
done
echo "</pre></body><script src=https://cdn.jsdelivr.net/gh/google/code-prettify@master/loader/run_prettify.js></script></html>" >> $FILE
else
if [ -f "$1" ]; then
TYPE="$(file -b --mime-type $1 | awk -F/ '{print $1}')"
NAME="$(basename $1)"
# If putting a file
if [ $TYPE == "image" ]; then
# Creating an image page
echo "<html><head><meta charset=utf-8><title>$NAME</title></head><body style='background: #0d0d0d;'><img src='$NAME' style='margin: auto; height: auto; max-width: 100%;'></img></body></html>" > $FILE
scp $1 $SCP
elif [ $TYPE == "video" ]; then
# Creating a video page
echo "<html><head><meta charset=utf-8><title>$NAME</title></head><body style='background: #0d0d0d; width: 100%; height: 100%; margin: 0; padding: 0;'><video width='90%' height='auto' controls style='margin: auto; position: absolute; left: 0; right: 0; top: 0; bottom: 0;'><source src='$NAME' type='$(file -b --mime-type $1)'>Looks like your browser does not support the video tag</video></body></html>" > $FILE
scp $1 $SCP
elif [ $TYPE == "text" ]; then
# Creating a text page
echo "<html><head><meta charset=utf-8><title>$NAME</title></head><body><pre class=prettyprint style='border: none;'>" > $FILE
cat "$1" | sed -r 's/&/\&/g; s/</\</g; s/>/\>/g' >> $FILE
echo "</pre></body><script src=https://cdn.jsdelivr.net/gh/google/code-prettify@master/loader/run_prettify.js></script></html>" >> $FILE
else
# Creating the download page
echo "<!DOCTYPE html><html><head><meta charset='utf-8'><title>$NAME</title></head><body style='background-color: #111111;'><div style='position: absolute; left: 0; top: 50%; width: 100%; text-align: center;'><a href='$NAME' style='background-color: grey; border-radius: 2px; color: white; padding: 15px; text-align: center; text-decoration: none; display: inline-block; cursor: pointer;' download>$NAME</a></div></body>" > $FILE
scp $1 $SCP
fi
else
echo "No input given!"
fi
fi
# Putting the file to the server
scp $FILE $SCP
# Cleaning up
rm $FILE
# Copying the link
echo "$WEB$FILE" | $CLIPTOOL $CLIPARGS