-
Notifications
You must be signed in to change notification settings - Fork 1
/
upload
executable file
·287 lines (239 loc) · 8.96 KB
/
upload
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
#!/bin/sh
# Script to upload to various sites (delegating to pomfload)
# without having to remember their endpoint URLs and such.
# {{{ Various upload sites/configs
yapc='yet another pomf clone'
yapc() {
up="pomfload --upload https://$1/upload.php"
desc="$1, $yapc"
shift
if [ "$#" -ne 0 ]; then
desc="$desc ($*)"
fi
}
yauc() {
up="pomfload --upload-field file --raw-reply --upload 'https://$1/api.php?d=upload-tool'"
desc="$1, temporary file hosting"
shift
if [ "$#" -ne 0 ]; then
desc="$desc ($*)"
fi
}
ssh_wrap() {
ssh_gpg_wrapper=$(command -v ssh-gpg 2>/dev/null)
if [ -n "$ssh_gpg_wrapper" ]; then
"$ssh_gpg_wrapper" "$@"
else
"$@"
fi
}
rsync_service_up() {
address=$1 # e.g. "server:/srv/www/path/", including trailing slash
path=$2 # e.g. "https://my-server.com/path/", including trailing slash
upload_file=$3
base_filename=$(basename -- "$upload_file")
case $address in
*://*) delim=/;; # rsync://host/path
*) delim=:;; # host:path
esac
if
ssh_wrap rsync -qz --chmod=644 "$upload_file" "$address"
then
printf '%s%s\n' "$path" "$base_filename"
else
return 1
fi
}
rsync_service() {
up="rsync_service_up $(shell_quote_arg "$1") $(shell_quote_arg "$2")"
desc="rsync upload to $1 into $2"
shift 2
desc="$desc${1:+ ($*)}"
}
get_service() {
local complain_arg complain
complain_arg= complain=true
while true; do case $1 in
--no-complain) complain_arg=--no-complain complain=false; shift;;
*) break;;
esac; done
case $1 in
uguu) yauc uguu.se 24 hours, 100MB;;
0x0)
up='pomfload --upload-field file --raw-reply --upload https://0x0.st'
desc='The Null Pointer, temporary file hosting (30+ days, 256MB)'
;;
# catgirls)
# up='pomfload --upload http://catgirlsare.sexy/upload.php --download ""'
# desc="catgirlsare.sexy, $yapc (no HTTPS)"
# ;;
# che)
# up='pomfload --upload http://up.che.moe/upload.php'
# desc="up.che.moe, $yapc (no HTTPS)"
# ;;
# nya)
# up='pomfload --upload https://nya.is/upload --download ""'
# desc="nya.is, $yapc. Buggy (can't handle files without extensions)"
# ;;
pomfcat)
up='pomfload --upload https://pomf.cat/upload.php --download https://a.pomf.cat/'
desc="pomf.cat, $yapc"
;;
# kyaa)
# up='pomfload --upload https://kyaa.sg/upload.php --download https://r.kyaa.sg/'
# desc="kyaa.sg, $yapc"
# ;;
# safe) yapc safe.moe 300MB;;
# plebeianparty)
# up='pomfload --upload http://files.plebeianparty.com/upload.php --download http://a.plebeianparty.com/'
# desc="files.plebeianparty.com, $yapc (no HTTPS)"
# ;;
# glop)
# up='pomfload --upload http://glop.me/upload.php --download http://gateway.glop.me/ipfs/'
# desc="glop.me, $yapc with IPFS backend (no HTTPS)"
# ;;
owo)
need_config $complain_arg owo_key='YOUR OWO KEY' owo_download_url='https://owo.whats-th.is/ (example, change me)' ||
{ $complain && exit 1; }
up="pomfload --upload $(shell_quote_arg "https://api.awau.moe/upload/pomf?key=$owo_key") --download $(shell_quote_arg "$owo_download_url")"
desc="owo.whats-th.is, $yapc made in NodeJS <https://github.com/whats-this> (cloudflare & s3 HTTPS; requires registration)"
;;
# mixtape) yapc mixtape.moe;;
# minifiles)
# up='pomfload --upload https://minifiles.net/upload.php --download https://minifiles.net/files/'
# desc="minifiles.net, $yapc"
# ;;
# nyanimg)
# up='pomfload --redirects --upload-field pictures --upload https://nyanimg.com/upload.php'
# desc="nyanimg, $yapc (images only, cloudflare HTTPS)"
# ;;
# TODO: Fuwa has an ever so slightly different upload system.
# It has a "file" parameter (not "files[]"), and it replies with something like:
# {"file":{"url":"<full URL>","success":true,"name":"<name>"}}
# fuwa)
# up='fuwaload --upload https://fuwa.se/api/upload --download ""'
# desc="fuwa.se, $yapc (cloudflare HTTPS)"
# ;;
ratelimited)
need_config $complain_arg ratelimited_key='YOUR RATELIMITED KEY' ratelimited_download_url='https://blah.ratelimited.me/ (example, change me)' || { $complain && exit 1; }
up="pomfload --upload $(shell_quote_arg "https://api.ratelimited.me/api/upload/pomf?key=$ratelimited_key") --download $(shell_quote_arg "$ratelimited_download_url")"
desc="ratelimited.me, $yapc with custom domains (see config file. Cloudflare HTTPS)"
;;
# pyonpyon) yapc pomf.pyonpyon.moe 50MB;;
# doko) yapc doko.moe 512MB;;
# vidgame) yapc vidga.me 100MB;;
# catbox)
# TODO: needs to post reqtype=fileupload & userhash=
# up='pomfload --upload https://catbox.moe/user/api.php --raw-reply --upload-field fileToUpload'
# desc="catbox.moe, $yapc"
# ;;
# asis)
# up='pomfload --upload https://up.asis.io/upload.php --download https://dl.asis.io/'
# desc="up.asis.io, $yapc"
# ;;
# teknik)
# # TODO: should scrape deleteUrl or something too
# # TODO: needs fileType=<MIME> & fileExt=.<EXTENSION> & keySize=256 & blockSize=128
# up='pomfload --upload https://u.teknik.io/Action/Upload/Upload --upload-field data'
# desc="teknik.io, $yapc"
# ;;
cockfile) yauc cockfile.com;;
lewd) yauc lewd.se;;
gurren) rsync_service gurren:/srv/http/a/ https://score.moe/a/;;
# rokket)
# up='pomfload --upload https://rokket.space/upload'
# desc="rokket.space, temporary file hosting (48 hours, 150MB)"
# ;;
*) return 1;;
esac
}
# }}}
services='
0x0 cockfile lewd owo pomfcat ratelimited uguu
'
# BROKEN: fuwa
# DEAD: che nya plebeianparty glop nyanimg
# NEEDS ACCOUNT (not sure of the API here): catgirls kyaa pomf.space biyori.moe lithi.io
# NOT IMPLEMENTED: catbox dbr.ee teknik
##### Thus ends the configuration part of the program #####
shell_quote_arg() {
input=$1
output=\'
while true; do
case $input in
(*\'*)
output=$output${input%%\'*}\'\\\'\'
input=${input#*\'}
;;
(*)
output=$output$input\'
break
;;
esac
done
printf %s\\n "$output"
}
_already_read_config=false
need_config() {
local wanted_conf failure conf_key conf_example_val complain
conf_dir=${XDG_CONFIG_HOME:=${HOME:?}/.config}/pomfload
conf_file=$conf_dir/upload
complain=true
while true; do case $1 in
--no-complain) complain=false; shift;;
*) break;;
esac; done
if ! $_already_read_config && ! [ -f "$conf_file" ]; then
if [ -e "$conf_file" ]; then
printf 'There is a non-file at "%s". Please remove it or put it somewhere sensible.\n' \
"$conf_file" >&2
return 1
fi
mkdir -p -- "$conf_dir"
printf '# %s\n' \
'pomfload uploader config' \
'This is where registration details for websites will go.' \
> "$conf_file"
else
$_already_read_config || . "$conf_file"
_already_read_config=true
fi
failure=false
for wanted_conf do
conf_key=${wanted_conf%%=*}
conf_example_val=${wanted_conf#*=}
if eval "[ \"\${$conf_key:-\$conf_example_val}\" = \"\$conf_example_val\" ]"; then
failure=true
$complain && printf 'Missing a value for config: %s\n' "$conf_key"
fi
done
if $failure; then
for wanted_conf do
conf_key=${wanted_conf%%=*}
conf_val=${wanted_conf#*=}
eval "\${$conf_key+:} false" ||
printf %s=%s\\n "$conf_key" "$(shell_quote_arg "$conf_val")"
eval "$conf_key=\$conf_val"
done >> "$conf_file"
$complain &&
printf 'Please edit the config file by running:\n\t%s %s\n' \
"$(shell_quote_arg "${EDITOR:-${VISUAL:-vim}}")" \
"$(shell_quote_arg "$conf_file")" \
>&2
fi
! $failure
}
service=$1
[ "$#" != 0 ] && shift
if [ "$service" = list ]; then
for service in $services; do
get_service --no-complain "$service"
printf '%-15s%s\n' "$service" "$desc"
done
elif ! get_service "$service"; then
printf >&2 'Not a service: "%s"\nTry "%s list"\nInvoke like: "%s SERVICE FILE1 [FILE2 ...]"\n' "$service" "${0##*/}" "${0##*/}"
exit 1
else
eval "${up:?}"' "$@"'
fi
#vim:fdm=marker