-
Notifications
You must be signed in to change notification settings - Fork 2
/
template_post
executable file
·147 lines (119 loc) · 2.74 KB
/
template_post
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
#!/bin/sh
cd $(dirname "$0")
if ! test -e ../params.sh
then
exit 1
fi
. ../params.sh
id=$(basename $(pwd))
if test "$MAX_POSTS" -gt 0 -a $(find -name '[0-9]*' | wc -l) -ge "$MAX_POSTS"
then
pherror "Post failed."
phinfo "Post limit reached ($MAX_POSTS)"
phitem 1 "Return to thread" "$CHAN_ROOT/$id"
exit 1
fi
comment="$@"
len=$(echo -n "$comment" | wc -c)
stamp=$(date +%s)
if test -e ../posts
then
no=$(cat ../posts)
else
no=0
fi
no=$((no + 1))
post="$stamp"_"$no"
if test "$comment" = ""
then
pherror "Post failed."
phline
phinfo "You must post a comment."
phitem 1 "Return to thread" "$CHAN_ROOT/$id"
exit 1
fi
if test "$len" -gt "$MAX_POSTLEN"
then
pherror "Post failed"
phline
phinfo "Comment too long ($len/$MAX_POSTLEN)"
phitem 1 "Return to thread" "$CHAN_ROOT/$id"
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
# 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 "$comment" | grep -Eq "$TRIPCODE_REGEX"
then
password=$(echo "$comment" | sed -r "s/${TRIPCODE_REGEX}/\1/")
tripcode=$(sh ../tripcode.sh "$SALT_DIR" "$password")
comment=$(echo "$comment" | sed -r "s/${TRIPCODE_REGEX}/\2/")
echo "${no} ${tripcode}" >> ../tripcodes
fi
# quotes
if echo "$comment" | grep -Eq '^>>[0-9]+ ?.*$'
then
targetno=$(echo "$comment" | sed -r 's/>>([0-9]+) ?.*/\1/')
target=$(find .. -name "[0-9]*_$targetno" | head -n 1)
if ! test -e "$target"
then
pherror "Post #$targetno does not exist."
phitem 1 "Return to thread" "$CHAN_ROOT/$id"
exit 1
fi
thread=$(echo "$target" | cut -d / -f 2)
if test "$thread" = "$id"
then
echo "#$targetno said:" >> $post
else
echo "1#$targetno said: $CHAN_ROOT/$thread $SERVER_HOST $SERVER_PORT" >> $post
fi
saveifs="$IFS"
IFS=''
cat $target | while read -r line
do
if echo "$line" | grep -v -q " "
then
echo "$line" | fmt -66 -s | fold -w 66 | while read -r fmtline
do
echo " >$fmtline" >> $post
done
else
kind=$(echo "$line" | head -c 1)
rest=$(echo "$line" | tail -c +2)
echo "$kind >$rest" >> $post
fi
done
IFS="$saveifs"
comment=$(echo "$comment" | sed -r 's/>>[0-9]+ ?(.*)/\1/' | sed 's/ / /g')
fi
echo "$comment" >> $post
if test -e "$post"
then
phinfo "Post successful!"
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
pherror "Could not post."
fi
phitem 1 "Return to thread" "$CHAN_ROOT/$id"