3 # Variables - do not modify them
6 # Checking the location.
7 ls -la register_rule.sh > /dev/null 2>&1
12 ls -la register_rule.sh > /dev/null 2>&1
14 echo "ERROR: You must run this script from the same directory."
20 if [ "x$1" = "x" -o "x$1" = "xhelp" -o "x$1" = "x-h" ]; then
21 echo "$0 add <function_name>"
29 if [ "x$1" = "xlist" ]; then
30 echo "*Available functions: "
31 cat .function_list | sort | uniq;
34 elif [ "x$1" = "xsave" ]; then
35 ls -la /etc/ossec-init.conf > /dev/null 2>&1
37 echo "ERROR: Unable to save rules. You must have OSSEC installed to do so."
41 cat /etc/ossec-init.conf > /dev/null 2>&1
43 echo "ERROR: Unable to save rules. You must be root to do so."
47 . /etc/ossec-init.conf
49 ls ${DIRECTORY}/compiled_rules > /dev/null 2>&1
51 mkdir ${DIRECTORY}/compiled_rules > /dev/null 2>&1
53 echo "ERROR: Unable to save rules. You must be root to do so."
58 cp .function_list ${DIRECTORY}/compiled_rules/function_list > /dev/null 2>&1
60 echo "ERROR: Unable to save rules. You must be root to do so."
65 if [ ! "x$i" = "xgeneric_samples.c" ]; then
66 cp $i ${DIRECTORY}/compiled_rules/ > /dev/null 2>&1
69 echo "*Save completed at ${DIRECTORY}/compiled_rules/";
72 elif [ "x$1" = "xrestore" ]; then
74 ls -la /etc/ossec-init.conf > /dev/null 2>&1
76 echo "ERROR: Unable to restore rules. You must have OSSEC installed to do so."
80 cat /etc/ossec-init.conf > /dev/null 2>&1
82 echo "ERROR: Unable to restore rules. You must be root to do so."
86 . /etc/ossec-init.conf
88 ls ${DIRECTORY}/compiled_rules/function_list > /dev/null 2>&1
90 echo "*No local compiled rules available to restore."
94 cat ${DIRECTORY}/compiled_rules/function_list >> .function_list
96 echo "ERROR: Unable to restore rules. Function list not present."
100 for i in `ls ${DIRECTORY}/compiled_rules/*.c`; do
101 if [ ! "x$i" = "xgeneric_samples.c" ]; then
102 cp $i ./ > /dev/null 2>&1
105 echo "*Restore completed from ${DIRECTORY}/compiled_rules/";
108 elif [ "x$1" = "xbuild" ]; then
109 ls -la .function_list > /dev/null 2>&1
110 if [ ! $? = 0 ]; then
111 echo "ERROR: Unable to build. No function is registered."
115 # Auto generating the file.
116 echo "/* This file is auto generated by $0. Do not touch it. */" > ${CHF}
119 echo "/* Adding the function definitions. */" >> ${CHF};
120 for i in `cat .function_list | sort| uniq`; do
121 echo "void *$i(Eventinfo *lf);" >> ${CHF};
125 echo "/* Adding the rules list. */" >> ${CHF};
126 echo "void *(compiled_rules_list[]) = " >> ${CHF};
128 for i in `cat .function_list | sort| uniq`; do
129 echo " $i," >> ${CHF};
131 echo " NULL" >> ${CHF};
135 echo "/* Adding the rules list names. */" >> ${CHF};
136 echo "const char *(compiled_rules_name[]) = " >> ${CHF};
138 for i in `cat .function_list |sort | uniq`; do
139 echo " \"$i\"," >> ${CHF};
141 echo " NULL" >> ${CHF};
144 echo "/* EOF */" >> ${CHF};
146 echo "*Build completed."
148 elif [ "x$1" = "xadd" ]; then
149 if [ "x$2" = "x" ]; then
150 echo "ERROR: Missing function name.";
151 echo "ex: $0 add <function_name>";
155 grep $2 ./*.c > /dev/null 2>&1
156 if [ ! $? = 0 ]; then
157 echo "ERROR: Function '$2' not found.";
161 grep $2 .function_list > /dev/null 2>&1
163 echo "ERROR: Function '$2' already added.";
167 echo $2 >> .function_list;
168 echo "*Function $2 added."
171 echo "ERROR: Invalid argument.";