Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Branch: master
Fetching contributors…

Cannot retrieve contributors at this time

executable file 147 lines (130 sloc) 2.895 kB
#!/bin/sh
# This is a shell script that looks for common problems and typos in rules.
[ -n "$1" ] && cd "$1"
if ! cat *.xml >/dev/null 2>/dev/null
then
echo There are no readable XML files in the current or specified directory.
echo Run this script inside a directory containing XML rule files or else
echo specify such a directory on the command line. E.g.,
echo
echo "$0" src/chrome/content/rules
exit 2
fi
fail=false
echo "-- Rules not anchored to beginning of a line:"
if grep from= *.xml | cut -d\" -f2 | grep '^[^^]'
then
fail=true
else
echo "(None.)"
fi
echo
echo "-- Rules with unescaped dots outside of brackets and left of a slash:"
if grep from= *.xml | cut -d\" -f2 | sed 's/\[[^]]*\]//g' | egrep 'http.?.?://[^/]*[^\]\.[^*]'
then
fail=true
else
echo "(None.)"
fi
echo
echo "-- Rules not containing trailing slash in from pattern:"
if grep from= *.xml | cut -d\" -f2 | grep -v '//.*/'
then
fail=true
else
echo "(None.)"
fi
echo
echo "-- Rules not containing trailing slash in to pattern:"
if grep 'to="' *xml | sed 's/^.*to="//' | sed 's/\".*$//' | grep -v '//.*/'
then
fail=true
else
echo "(None.)"
fi
echo
echo "-- Rules with missing closing slash in rule XML tag:"
if grep to= *xml | grep '[^/]>'
then
fail=true
else
echo "(None.)"
fi
echo
echo "-- Rules with multiple wildcards in a single target rule:"
if grep 'target host="' *xml | grep '\*.*\*'
then
fail=true
else
echo "(None.)"
fi
echo
echo "-- Rules with targets containing URLs/paths instead of hostnames:"
if grep 'target host="' *xml | egrep '="[^"]*/'
then
fail=true
else
echo "(None.)"
fi
echo
echo "-- Rules redirecting to http in to pattern:"
if grep 'to="' *xml | sed 's/^.*to="//' | sed 's/\".*$//' | grep '^http:'
then
fail=true
else
echo "(None.)"
fi
echo
if [ $(which xmllint) ]
then
echo "-- Rules with syntatically invalid XML:"
none=true
for rule in *.xml
do
xmllint "$rule" >/dev/null 2>&1 || { echo $rule; none=false; fail=true; }
done
$none && echo "(None.)"
else
echo "-- Could not check XML validity because xmllint not found."
fi
echo
echo "-- Rules containing non-ASCII characters (possible homoglyph attacks):"
none=true
for i in *.xml
do
if egrep '(from|to)=' "$i" | tr -d '[:print:][:space:]' | grep . >/dev/null
then
echo "$i contains non-ASCII character(s)."
none=false
#fail=true
echo "(not exiting)"
fi
done
$none && echo "(None.)"
echo
echo "--- Rules that lack at least one valid <target> tag:"
none=true
for i in *.xml
do
if ! egrep '<target .*host=".*/>' "$i" >/dev/null
then
echo $i
none=false
fail=true
fi
done
$none && echo "(None.)"
echo
echo "--- Duplicated ruleset names:"
if cat *.xml | grep 'ruleset name' | cut -d\" -f2 | sort | uniq -d | grep .
then
fail=true
else
echo "(None.)"
fi
if $fail
then
exit 1
else
exit 0
fi
Jump to Line
Something went wrong with that request. Please try again.