-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tur-rules.sh.org
127 lines (109 loc) · 2.98 KB
/
tur-rules.sh.org
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
#!/bin/bash
VER=1.1
by SiCiaTeCh
##CONFIG PART#########################
glroot=/glftpd
rules=/ftp-data/misc/site.rules
compress=" "
sections="
"
######################################################
# No changes below here. Can change the "echo" parts #
# if you like though. #
######################################################
IsGL="1"
## Can we read the rules file ?
if [ ! -r $rules ]; then
rules=$glroot/$rules
if [ ! -r $rules ]; then
echo "Cant read rules file. Check path and permissions."
exit 0
else
IsGL=0
fi
fi
## Procedure for listing all defined sections.
proc_listsections() {
for section in $sections; do
name="$( echo $section | cut -d':' -f1 )"
if [ "$names" ]; then
names="$names $name"
else
names="$name"
fi
done
echo "SiCiaTeCh-Rules $VER."
if [ $IsGL ]; then
echo "Usage: site rules <section> (searchword)"
else
echo "Usage: !rules <section> (searchword)"
fi
echo "Defined sections are: $names"
if [ $IsGL ]; then
echo "Usage: site rules $name limited"
else
echo "Example !rules $name limited"
fi
}
## If no argument, run the above proc.
if [ -z "$1" ]; then
proc_listsections
exit 0
fi
## Got inputs correct. Lets go searching.
for section in $sections; do
## Grab section name from data.
name="$( echo $section | cut -d':' -f1 )"
## Check if this section is what the user asked for..
if [ "$( echo $name | grep -wi "^$1$" )" ]; then
## Get the searchwords defined for this section.
search="$( echo $section | cut -d':' -f2 | tr -s '|' ' ' )"
## Add each searchword up, adding a ^ infront.
for each in $search; do
if [ "$searchline" ]; then
searchline="^$each|$searchline"
else
searchline="^$each"
fi
done
## Do a different search if a searchword was included.
if [ "$2" ]; then
if [ "$compress" ]; then
## If we have something to compress...
OUTPUT="$( egrep $searchline $rules | grep -i "$2" | tr -s "$compress" | tr -s ' ' '^' )"
else
## If compress is ""
OUTPUT="$( egrep $searchline $rules | grep -i "$2" | tr -s ' ' '^' )"
fi
msg=", containing '$2'"
else
if [ "$compress" ]; then
## If we have something to compress...
OUTPUT="$( egrep $searchline $rules | tr -s "$compress" | tr -s ' ' '^' )"
else
## If compress is ""
OUTPUT="$( egrep $searchline $rules | tr -s ' ' '^' )"
fi
fi
## Output the text we found.
if [ "$OUTPUT" ]; then
echo "Rules for section $name$msg:"
for each in $OUTPUT; do
echo $each | tr -s '^' ' '
done
fi
## Set GOTONE so we know we found a section.
GOTONE="TRUE"
fi
done
## User did not enter a defined section.
if [ -z "$GOTONE" ]; then
proc_listsections
exit 0
fi
## User entered a defined section but no rules found.
if [ -z "$OUTPUT" ]; then
echo "No rule found so... its allowed !!"
exit 0
fi
exit 0