· 4 years ago · Jul 23, 2021, 03:08 PM
1#!/bin/env bash
2
3APIKEY=''
4
5generatePassword(){
6
7# https://tldp.org/LDP/abs/html/extmisc.html#ODREF
8# let urandom generate random set of numbers
9password=$(head -c3 /dev/urandom | od -N4 -tu4 | sed -ne '1s/.* //p')
10# for a bigger number just increase -c3 to -c5 or whatever
11}
12
13checkForCurl(){
14 curlVersion=$(curl --version &>/dev/null)
15 [ "$?" -ne 0 ] && echo "Curl not installed" && exit
16}
17
18sanityChecks(){
19
20 [ -z "$APIKEY" ] && echo "You didn't set an api key" && exit
21 [ -z "$setFile" ] && echo "You didn't select a file" && exit
22 [ -f "$setFile" ] || echo "File doesn't exist" || exit
23
24}
25parseJson(){
26 echo -en "\n"
27 linkDownload=$(echo $postUrl | sed 's/[{}]//g' | sed 's/\"\:\"/\ /g' | sed 's/\"//g' | awk '/key/ {print $2}' | sed 's/\,DeletionUrl*//')
28 linkDelete=$(echo $postUrl | sed 's/[{}]//g' | sed 's/\"\:\"/\ /g' | sed 's/\"//g' | awk '/delete/ {print $3}' | sed 's/.$//')
29 echo -en "Your download link is \e[1m$linkDownload\e[0m\n"
30 echo -en "\n"
31 echo -en "Your link for file deletion is \e[1m$linkDelete\e[0m\n"
32}
33
34helpMenu(){
35echo -en "\n"
36 cat << EOF
37 encrypting.host API Bash
38
39 Usage: encryptup -f file <args>
40 Example: encryptup -f video.mp4 -o
41
42 Arguments:
43 -n | --normal - normal domains
44 -o | --offensive - offensive domains
45 -w | --weeb - weeb domains
46 -s | --sad - sad domains
47 -h | --help - display this menu
48
49 A random password will be generated.
50EOF
51}
52
53# from a stackoverflow answer
54# set flags to handle arguments
55while [ "$#" -gt 0 ];
56do
57 args="$1"
58 case $args in
59 -n|--normal)
60 setDomainNormal=1
61 shift
62 shift
63 ;;
64 -o|--offensive)
65 setDomainOffensive=1
66 shift
67 shift
68 ;;
69 -s|--sad)
70 setDomainSad=1
71 shift
72 shift
73 ;;
74 -w|--weeb)
75 setDomainWeeb=1
76 shift
77 shift
78 ;;
79 -f|--file)
80 setFile="$2"
81 shift
82 shift
83 ;;
84 -h|--help)
85 helpMenu
86 exit
87 ;;
88 *)
89 echo "Oops, looks like you mistyped something"
90 helpMenu
91 exit
92 ;;
93 esac
94done
95
96# workflow
97# check for curl >> sanity checks >> do the upload >> parse the json
98
99# for offensive domains
100if [ -n "$setDomainOffensive" ] && [ -e "$setFile" ]
101then
102 checkForCurl
103 sanityChecks
104 generatePassword
105
106 postUrl=$(curl -XPOST -F"password=$password" -F"userKey=$APIKEY" -F'userStyle=query' -F'domains=["offensive"]' -F"file=@$setFile" https://encrypting.host/upload)
107 parseJson
108
109# for weeb domains
110elif [ -n "$setDomainWeeb" ] && [ -e "$setFile" ]
111then
112 checkForCurl
113 sanityChecks
114 generatePassword
115
116 postUrl=$(curl -XPOST -F"password=$password" -F"userKey=$APIKEY" -F'userStyle=query' -F'domains=["weeb"]' -F"file=@$setFile" https://encrypting.host/upload)
117 parseJson
118
119# for sad domains
120elif [ -n "$setDomainSad" ] && [ -e "$setFile" ]
121then
122 checkForCurl
123 sanityChecks
124 generatePassword
125
126 postUrl=$(curl -XPOST -F"password=$password" -F"userKey=$APIKEY" -F'userStyle=query' -F'domains=["sad"]' -F"file=@$setFile" https://encrypting.host/upload)
127 parseJson
128
129# for normal domains
130elif [ -n "$setDomainNormal" ] && [ -e "$setFile" ]
131then
132 checkForCurl
133 sanityChecks
134 generatePassword
135
136 postUrl=$(curl -XPOST -F"password=$password" -F"userKey=$APIKEY" -F'userStyle=query' -F'domains=["normal"]' -F"file=@$setFile" https://encrypting.host/upload)
137 parseJson
138
139else
140 helpMenu
141fi
142