-
Notifications
You must be signed in to change notification settings - Fork 7
/
cpt-request.sh
executable file
·344 lines (319 loc) · 12 KB
/
cpt-request.sh
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
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
#!/bin/bash
##############################################################
## lelijk eendje // cpt-request v0.3.4-ng-compat
##############################################################
## Description:
## Requestscript for glftpd+pzs-ng (r1450 and up). If you don't
## know what this is, you probably don't need it.
##
## Thanks:
## - pzs-ng team for giving feedback on code
## - testers. you know who you are :)
##
## Support is for wussies, but here we go anyway:
##
## REQDIR:
## full path to the directory where you want the request directories
## you need $GLROOTPATH/ in front to make it work from both
## the ftp and irc
##
## GLLOG:
## full path to glftpd.log. Used for logging requests and
## announcing it on irc. If you don't want announces/logs, set
## it to /dev/null or something
## you need $GLROOTPATH/ in front to make it work from both
## the ftp and irc.
##
## REQFILE:
## File where we can put a little 'database' of requests.
## create the file yourself and chmod 666 it, or things can
## get messy.
##
## FILLEDFILE:
## The 'database' file for all the filled requests. You also
## have to create this file yourself and chmod 666 it.
##
## Sitename:
## Set this to some short version of your sitename. Used for
## debug announces and the request list.
##
## ZSTFILE:
## TODO: let the debug files use pzs-ng's zst for announce-
## layout. [ not used currently ]
##
## REQDIRPREFIX:
## The prefix for newly created requests. You need a prefix.
##
## FILLEDDIRPREFIX:
## The prefix for filled requests. You need a prefix.
##
## MAXNUMBEROFREQS:
## The maximum number of requests your site can have. Don't
## set this too high, it will make your site look like crap. :-)
##
## SEPERATOR:
## A seperator for the reqfile (on popular request). This character
## will seperate the different entries in the req/filled-file.
## Don't change this unless you know what you're doing BLAH BLAH.
##
## DEBUG:
## Enable debug information. Nothing fancy, best to disable it.
##############################################################
## DO NOT TOUCH THIS
if [ -r /bin/glstrings.bin ]; then
TODO=$1
WHAT=$2
REQUSER=$USER
SITEREQ="TRUE" # request is being made from glftpd
GLROOTPATH=""
else
REQUSER=$1
TODO=$2
WHAT=$3
GLROOTPATH="/glftpd" # request is being made from irc (or something)
GROUP=`grep "^GROUP " $GLROOTPATH/ftp-data/users/$REQUSER | head -n 1 | cut -d ' ' -f2`
TAGLINE=`grep "^TAGLINE " $GLROOTPATH/ftp-data/users/$REQUSER | sed 's/^TAGLINE //'`
SITEREQ="FALSE"
fi
## You can start configging below
REQDIR="$GLROOTPATH/site/requests/"
GLLOG="$GLROOTPATH/ftp-data/logs/glftpd.log"
REQFILE="$GLROOTPATH/ftp-data/logs/reqfile"
FILLEDFILE="$GLROOTPATH/ftp-data/logs/filledfile"
SITENAME=""
#ZSTFILE="/glftpd/sitebot/pzs-ng/themes/default.zst"
REQDIRPREFIX="REQ-"
FILLEDDIRPREFIX="FILLED-"
MAXNUMBEROFREQS=20
SEPERATOR=':'
DEBUG="FALSE"
## CONFIG STOPS HERE. edit below and seal your fate.
NUMBEROFREQUESTS=`cat $REQFILE | wc -l | sed 's/ //g'`
case "$TODO" in
add)
if [ "$WHAT" = "" ]; then
echo "Usage: !!request <release>"
exit 0
else
if [ $MAXNUMBEROFREQS -le $NUMBEROFREQUESTS ]; then
echo "There are too many requests. Fill/del/wipe some :)."
exit 0
fi
#we don't want spaces in files. that's ugly. if you disagree, you can suck my hairy bawls.
WHAT=`echo $WHAT | tr ' ' '.'`
ALREADYTHERE="$( ls $REQDIR | grep $WHAT )"
if [ -z "$ALREADYTHERE" ]; then
mkdir -m777 "$REQDIR/$REQDIRPREFIX$WHAT"
echo "`date +%d%m`$SEPERATOR$REQUSER$SEPERATOR$GROUP$SEPERATOR$WHAT" >> $REQFILE
echo `date "+%a %b %e %T %Y"` REQUEST: \"$WHAT\" \"$REQUSER\" \"$GROUP\" \"$TAGLINE\" >> $GLLOG
else
echo "Already a request named like that, try to rephrase"
exit 0
fi
fi
;;
del)
if [ "$WHAT" = "" ]; then
echo "Specify a request to delete... Usage: !!delreq <releasename> or !!delreq #<number>"
exit 0
else
if [ `echo "$WHAT" | grep "#"` ]; then
whatisnumber="TRUE"
reqnumber=`echo $WHAT | tr -cd '0-9'`
if [ $reqnumber -gt `cat $REQFILE | wc -l | tr -s ' '` ];then
echo "That number isn't correct. You can count, right?"
exit 0
else
WHAT=`head -n $reqnumber $REQFILE | tail -n 1 | cut -d $SEPERATOR -f4`
fi
else
whatisnumber="FALSE"
fi
REQUEST=`grep "$WHAT" $REQFILE | head -n1 | cut -d $SEPERATOR -f4`
if [ "$REQUEST" = $WHAT ]; then
ACTUALLYTHERE="$( ls $REQDIR | grep $WHAT )"
if [ "$ACTUALLYTHERE" != "" ]; then
# do not delete requestdirs that have files in them. we might not be able to remove the dir
# (different ownership on the files in the dir)
if [ ! -z `ls -1 $REQDIR/$REQDIRPREFIX$WHAT 2>/dev/null` ]; then
echo "You can't delete that. The directory is not empty"
exit 0
fi
if [ "$DEBUG" = "ON" ]; then
echo "DEBUG: Dirname has been entered correctly and is in the reqfile"
fi
REQUESTDATE=`grep "$WHAT" $REQFILE | head -n1 | cut -d $SEPERATOR -f1`
REQUESTEDBY=`grep "$WHAT" $REQFILE | head -n1 | cut -d $SEPERATOR -f2`
REQUESTEDBYGROUP=`grep "$WHAT" $REQFILE | head -n1 | cut -d $SEPERATOR -f3`
if [ "$REQUESTEDBY" = "$REQUSER" ]; then
rm -rf $REQDIR/$REQDIRPREFIX$REQUEST
grep -v "$REQUEST" "$REQFILE" > $GLROOTPATH/tmp/.reqfile.tmp
cp -f "$GLROOTPATH/tmp/.reqfile.tmp" "$REQFILE"
rm -f "$GLROOTPATH/tmp/.reqfile.tmp"
echo `date "+%a %b %e %T %Y"` REQDEL: \"$REQUEST\" \"$REQUSER\" \"$GROUP\" \"$TAGLINE\" >> $GLLOG
if [ "$DEBUG" = "ON" ]; then
echo "DEBUG: Request has been deleted"
fi
else
echo "You're not the one who has requested this release."
fi
else
echo "Dir wasn't found. Removing it from the reqlog. Please reqwipe/reqdel through this script next time."
grep -v "$REQUEST" "$REQFILE" > $GLROOTPATH/tmp/.reqfile.tmp
cp -f "$GLROOTPATH/tmp/.reqfile.tmp" "$REQFILE"
rm -f "$GLROOTPATH/tmp/.reqfile.tmp"
exit 0
fi
else
echo "Please enter the *EXACT* dirname. Thank you :)"
fi
fi
;;
wipe)
if [ "$WHAT" = "" ]; then
echo "Specify a request to wipe... Usage: !!reqwipe <releasename> or !!reqwipe #<number>"
exit 0
else
if [ `echo "$WHAT" | grep "#"` ]; then
whatisnumber="TRUE"
reqnumber=`echo $WHAT | tr -cd '0-9'`
if [ $reqnumber -gt `cat $REQFILE | wc -l | tr -s ' '` ];then
echo "That number isn't correct."
exit 0
else
WHAT=`head -n $reqnumber $REQFILE | tail -n 1 | cut -d $SEPERATOR -f4`
fi
else
whatisnumber="FALSE"
fi
REQUEST=`grep "$WHAT" $REQFILE | head -n 1 | cut -d $SEPERATOR -f4`
if [ "$REQUEST" = $WHAT ]; then
ACTUALLYTHERE="$( ls $REQDIR | grep $WHAT )"
if [ "$ACTUALLYTHERE" != "" ]; then
if [ ! -z `ls -1 $REQDIR/$REQDIRPREFIX$WHAT 2>/dev/null` ]; then
echo "You can't delete that. The directory is not empty."
exit 0
fi
REQUESTDATE=`grep "$WHAT" $REQFILE | head -n1 | cut -d $SEPERATOR -f1`
REQUESTEDBY=`grep "$WHAT" $REQFILE | head -n1 | cut -d $SEPERATOR -f2`
REQUESTEDBYGROUP=`grep "$WHAT" $REQFILE | head -n1 | cut -d $SEPERATOR -f3`
if [ "$DEBUG" = "ON" ]; then
echo "DEBUG: Dirname has been entered correctly and is in the reqfile"
fi
rm -rf $REQDIR/$REQDIRPREFIX$REQUEST
echo `date "+%a %b %e %T %Y"` REQWIPE: \"$REQUEST\" \"$REQUSER\" \"$GROUP\" \"$TAGLINE\" \"$REQUESTEDBY\" \"$REQUESTEDBYGROUP\" >> $GLLOG
grep -v "$REQUEST" "$REQFILE" > $GLROOTPATH/tmp/.reqfile.tmp
cp -f "$GLROOTPATH/tmp/.reqfile.tmp" "$REQFILE"
rm -f "$GLROOTPATH/tmp/.reqfile.tmp"
# echo "Wiped Request: $REQUEST"
else
echo "Dir wasn't found. Removing it from the reqlog. Please reqwipe/reqdel through this script next time."
if [ "$DEBUG" = "ON" ]; then
echo "DEBUG: Going to grep -v "$REQUEST" from "$REQFILE" to "$GLROOTPATH/tmp/.reqfile.tmp""
fi
grep -v "$REQUEST" "$REQFILE" > "$GLROOTPATH/tmp/.reqfile.tmp"
cp -f "$GLROOTPATH/tmp/.reqfile.tmp" "$REQFILE"
rm -f "$GLROOTPATH/tmp/.reqfile.tmp"
# grep -v $RELEASE $REQFILE > $REQFILE
exit 0
fi
else
echo "Please enter the *EXACT* dirname. Thank you :)"
fi
fi
;;
fill)
if [ "$WHAT" = "" ]; then
echo "Specify a request to fill... Usage: !!reqfill <releasename> or !!reqfill #<number>"
exit 0
else
if [ `echo "$WHAT" | grep "#"` ]; then
whatisnumber="TRUE"
reqnumber=`echo $WHAT | tr -cd '0-9'`
if [ $reqnumber -gt `cat $REQFILE | wc -l | tr -s ' '` ] || [ $reqnumber = 0 ];then
echo "That number isn't correct."
exit 0
else
WHAT=`head -n $reqnumber $REQFILE | tail -n 1 | cut -d $SEPERATOR -f4`
fi
else
whatisnumber="FALSE"
fi
REQUEST=`grep "$WHAT" $REQFILE | head -n1 | cut -d $SEPERATOR -f4`
if [ "$REQUEST" = $WHAT ]; then
ACTUALLYTHERE="$( ls $REQDIR | grep $WHAT )"
if [ "$ACTUALLYTHERE" != "" ]; then
if [ -z "`ls -1 $REQDIR/$REQDIRPREFIX$WHAT 2> /dev/null`" ]; then
echo "You can't fill that. $WHAT is still empty."
exit 0
fi
REQUESTDATE=`grep "$WHAT" $REQFILE | head -n1 | cut -d $SEPERATOR -f1`
REQUESTEDBY=`grep "$WHAT" $REQFILE | head -n1 | cut -d $SEPERATOR -f2`
REQUESTEDBYGROUP=`grep "$WHAT" $REQFILE | head -n1 | cut -d $SEPERATOR -f3`
if [ "$DEBUG" = "ON" ]; then
echo "DEBUG: Dirname has been entered correctly and is in the reqfile"
fi
# ACTUALLYFILLED="$( ls $REQDIR/$REQDIRPREFIX$REQUEST |
# if
MSGED="0"
echo "`date +%d%m`$SEPERATOR$REQUESTEDBY$SEPERATOR$REQUESTEDBYGROUP$SEPERATOR$REQUSER$SEPERATOR$GROUP$SEPERATOR$REQUEST$SEPERATOR$MSGED" >> $FILLEDFILE
mv -f "$REQDIR/$REQDIRPREFIX$REQUEST" "$REQDIR/$FILLEDDIRPREFIX$REQUEST"
echo `date "+%a %b %e %T %Y"` REQFILL: \"$REQUEST\" \"$REQUSER\" \"$GROUP\" \"$TAGLINE\" \"$REQUESTEDBY\" \"$REQUESTEDBYGROUP\" >> $GLLOG
grep -v "$REQUEST" "$REQFILE" > $GLROOTPATH/tmp/.reqfile.tmp
cp -f "$GLROOTPATH/tmp/.reqfile.tmp" "$REQFILE"
rm -f "$GLROOTPATH/tmp/.reqfile.tmp"
else
echo "Dir wasn't found. Removing it from the reqlog. Please reqwipe/reqdel through this script next time. And don't try to reqfill something that isn't there, bastard ;-)"
if [ "$DEBUG" = "ON" ]; then
echo "DEBUG: Going to grep -v "$REQUEST" from "$REQFILE" to "$GLROOTPATH/tmp/.reqfile.tmp""
fi
grep -v "$REQUEST" "$REQFILE" > "$GLROOTPATH/tmp/.reqfile.tmp"
cp -f "$GLROOTPATH/tmp/.reqfile.tmp" "$REQFILE"
rm -f "$GLROOTPATH/tmp/.reqfile.tmp"
# grep -v $RELEASE $REQFILE > $REQFILE
exit 0
fi
else
echo "Please enter the *EXACT* dirname. Thank you :)"
fi
fi
;;
list)
REQNUM=0
for LINE in `cat $REQFILE` ; do
let REQNUM=$REQNUM+1
DATE=`echo $LINE | cut -d $SEPERATOR -f1`
REQUESTEDBY=`echo $LINE | cut -d $SEPERATOR -f2`
REQUESTEDBYGROUP=`echo $LINE | cut -d $SEPERATOR -f3`
REQUEST=`echo $LINE | cut -d $SEPERATOR -f4`
echo "($REQNUM) $REQUEST on $DATE by $REQUESTEDBY of group $REQUESTEDBYGROUP"
done
if [ `cat $REQFILE | wc -l` = 0 ]; then
echo "There are no requests at the moment, try again later ;)"
exit 0
fi
;;
joincheck)
for LINE in `cat $FILLEDFILE`; do
DATE=`echo $LINE | cut -d $SEPERATOR -f1`
REQUESTEDBY=`echo $LINE | cut -d $SEPERATOR -f2`
REQUESTEDBYGROUP=`echo $LINE | cut -d $SEPERATOR -f3`
FILLEDBY=`echo $LINE | cut -d $SEPERATOR -f4`
FILLEDBYGROUP=`echo $LINE | cut -d $SEPERATOR -f5`
REQUEST=`echo $LINE | cut -d $SEPERATOR -f6`
MSGED=`echo $LINE | cut -d $SEPERATOR -f7`
if [[ "$REQUESTEDBY" = "$REQUSER" && $MSGED -eq 0 ]]; then
echo "`date +%d%m` $REQUESTEDBY $REQUESTEDBYGROUP $FILLEDBY $FILLEDBYGROUP $REQUEST"
grep -v "$REQUEST" "$FILLEDFILE" > "$GLROOTPATH/tmp/.reqfile.tmp"
cp -f "$GLROOTPATH/tmp/.reqfile.tmp" "$FILLEDFILE"
rm -f "$GLROOTPATH/tmp/.reqfile.tmp"
MSGED=1
echo "`date +%d%m`$SEPERATOR$REQUESTEDBY$SEPERATOR$REQUESTEDBYGROUP$SEPERATOR$FILLEDBY$SEPERATOR$FILLEDBYGROUP$SEPERATOR$REQUEST$SEPERATOR$MSGED" >> $FILLEDFILE
fi
done
;;
*)
echo "Use this script correctly"
exit 0
;;
esac