-
Notifications
You must be signed in to change notification settings - Fork 2
/
template_postfileb64
executable file
·231 lines (185 loc) · 4.39 KB
/
template_postfileb64
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
#!/bin/bash
cd "${0%/*}"
if [ "${#@}" -lt 1 ]
then
exit
fi
if [ ! -e ../params.sh ]
then
exit
fi
source ../params.sh
id=$(basename $(pwd))
if [[ "$MAX_POSTS" -gt 0 && $(ls [0-9]* 2>/dev/null | wc -l) -ge $MAX_POSTS ]]
then
printf "3Post failed. fake (NULL) 0\r\n"
printf "iPost limit reached ($MAX_POSTS) fake (NULL) 0\r\n"
printf "1Return to thread $CHAN_ROOT/$id $SERVER_HOST $SERVER_PORT\r\n"
exit 1
fi
if [ ! $MAX_UPLOAD -gt 0 ]
then
printf "3Uploads are disabled fake (NULL) 0\r\n"
printf "1Return to thread $CHAN_ROOT/$id $SERVER_HOST $SERVER_PORT\r\n"
exit 1
fi
stamp=$(date +%s)
if [[ -e ../posts ]]
then
no=$(cat ../posts)
else
no=0
fi
no=$(($no + 1))
post="$stamp"_"$no"
data="$1"
disp="${@:2}"
if [ ! "$disp" ]
then
disp="untitled"
fi
disp=$(echo "$disp" | cut -c1-70)
size="${#data}"
if [ ! "$size" ]
then
size=0
fi
if [ $size -lt 1 ]
then
printf "3Unable to retrieve file size fake (NULL) 0\r\n"
printf "1Return to thread $CHAN_ROOT/$id $SERVER_HOST $SERVER_PORT\r\n"
exit 1
fi
if [ $size -gt $MAX_UPLOAD ]
then
printf "3File too large (max $MAX_UPLOAD bytes) fake (NULL) 0\r\n"
printf "1Return to thread $CHAN_ROOT/$id $SERVER_HOST $SERVER_PORT\r\n"
exit 1
fi
if ! sh ../cooldown.sh post
then
pherror "Post failed"
phline
phinfo "Please wait $POST_LIMIT seconds before posting again."
phitem 1 "Return to thread" "$CHAN_ROOT/$id"
exit 1
fi
cd ..
fname="file_$post"
echo "$data" | base64 -d > "$fname"
mime=$(file -i -b "$fname")
mime="${mime%;*}"
if [[ "$MAX_IMAGE" && "$mime" == "image/"* ]]
then
maxw=$(echo $MAX_IMAGE | cut -f 1 -d 'x')
maxh=$(echo $MAX_IMAGE | cut -f 2 -d 'x')
dims=$(identify "$fname" | head -n 1 | cut -f 3 -d ' ')
imgw=$(echo $dims | cut -f 1 -d 'x')
imgh=$(echo $dims | cut -f 2 -d 'x')
if [[ $imgw -gt $maxw || $imgh -gt $maxh ]]
then
printf "3Image too large ($imgw x $imgh, max $maxw x $maxh) fake (NULL) 0\r\n"
printf "1Return to thread $CHAN_ROOT/$id $SERVER_HOST $SERVER_PORT\r\n"
rm -f "$fname"
exit 1
fi
fi
case "$mime" in
"image/png") type='p';;
"image/jpeg") type='I';;
"image/gif") type='g';;
"audio/wav") type='s';;
"text/html") type='h';;
"text/"*) type='0';;
"video/"*) type=';';;
*) type='9';;
esac
case "$mime" in
"video/webm") ext="webm";;
"image/png") ext="png";;
"image/jpeg") ext="jpg";;
"text/html") ext="html";;
"text/x-c") ext="c";;
*) ext="";;
esac
if [[ "$ext" != "" ]]
then
mv "$fname" "$fname.$ext"
fname="$fname.$ext"
fi
mv "$fname" $id/
cd $id
# post id
if test "$ENABLE_POST_IDS" = y
then
postid=$(sh ../tripcode.sh "$SALT_DIR" "$REMOTE_HOST")
echo "${no} ${postid}" >> ../postids
fi
# tripcode
TRIPCODE_REGEX='^##([^ ]+) (.*)$'
if echo "$disp" | grep -Eq "$TRIPCODE_REGEX"
then
password=$(echo "$disp" | sed -r "s/${TRIPCODE_REGEX}/\1/")
tripcode=$(sh ../tripcode.sh "$SALT_DIR" "$password")
disp=$(echo "$disp" | sed -r "s/${TRIPCODE_REGEX}/\2/")
echo "${no} ${tripcode}" >> ../tripcodes
fi
# quotes
targetno=$(echo "$disp" | sed -r 's/>>([0-9]+) ?.*/\1/')
if [[ "$disp" == ">>"* && "$targetno" -gt 0 ]]
then
target=$(ls ../[0-9]*_*/[0-9]*_$targetno 2>/dev/null | head -n 1)
target="${target#../}"
if [[ ! "$target" ]]
then
printf "3Post #$targetno does not exist! fake (NULL) 0\r\n"
printf "1Return to thread $CHAN_ROOT/$id $SERVER_HOST $SERVER_PORT\r\n"
exit 1
fi
thread="${target%/*}"
if [[ "$thread" == "$id" ]]
then
echo "#$targetno said:" >> $post
else
echo "1$targetno said: $CHAN_ROOT/$thread $SERVER_HOST $SERVER_PORT" >> $post
fi
saveifs="$IFS"
IFS=''
while read -r line
do
if echo "$line" | grep -q -v " "
then
while read -r fmtline
do
echo " >$fmtline" >> $post
done < <(echo "$line" | fmt -66 -s | fold -w 66)
else
kind=$(echo "$line" | head -c 1)
rest=$(echo "$line" | tail -c +2)
echo "$kind >$rest" >> $post
fi
done < ../$target
IFS="$saveifs"
disp=$(echo "$disp" | sed -r 's/>>[0-9]+ ?(.*)/\1/')
if [[ ! "$disp" ]]
then
disp="untitled"
fi
fi
echo "$type$disp $CHAN_ROOT/$id/$fname $SERVER_HOST $SERVER_PORT" >> $post
if [ -e $post ]
then
printf "iPost successful! fake (NULL) 0\r\n"
echo $no > ../posts
sh ../addpostpass.sh $no
sh ../updatepostcache.sh $id $post >> postcache
cd ..
sh updatethreadcache.sh > threadcache
if [ "$MAX_RSS_ITEMS" -gt 0 ]
then
sh updaterss.sh $id $no "$comment"
fi
else
printf "3Could not post. fake (NULL) 0\r\n"
fi
printf "1Return to thread $CHAN_ROOT/$id $SERVER_HOST $SERVER_PORT\r\n"