4 # Variables - do not modify them.
9 # Checking the location.
10 ls -la register_rule.sh > /dev/null 2>&1
12 LOCALDIR=`dirname $0`;
15 ls -la register_rule.sh > /dev/null 2>&1
17 echo "ERROR: You must run this script from the same directory."
25 if [ "x$1" = "x" -o "x$1" = "xhelp" -o "x$1" = "x-h" ]; then
26 echo "$0 add <function_name>"
35 if [ "x$1" = "xlist" ]; then
36 echo "*Available functions: "
37 cat .function_list | sort | uniq;
41 elif [ "x$1" = "xsave" ]; then
43 ls -la /etc/ossec-init.conf > /dev/null 2>&1
45 echo "ERROR: Unable to save rules. You must have OSSEC installed to do so."
49 cat /etc/ossec-init.conf > /dev/null 2>&1
51 echo "ERROR: Unable to save rules. You must be root to do so."
56 . /etc/ossec-init.conf
59 ls ${DIRECTORY}/compiled_rules > /dev/null 2>&1
61 mkdir ${DIRECTORY}/compiled_rules > /dev/null 2>&1
63 echo "ERROR: Unable to save rules. You must be root to do so."
68 cp .function_list ${DIRECTORY}/compiled_rules/function_list > /dev/nulll 2>&1
70 echo "ERROR: Unable to save rules. You must be root to do so."
75 if [ ! "x$i" = "xgeneric_samples.c" ]; then
76 cp $i ${DIRECTORY}/compiled_rules/ > /dev/nulll 2>&1
79 echo "*Save completed at ${DIRECTORY}/compiled_rules/";
83 elif [ "x$1" = "xrestore" ]; then
85 ls -la /etc/ossec-init.conf > /dev/null 2>&1
87 echo "ERROR: Unable to restore rules. You must have OSSEC installed to do so."
91 cat /etc/ossec-init.conf > /dev/null 2>&1
93 echo "ERROR: Unable to restore rules. You must be root to do so."
98 . /etc/ossec-init.conf
101 ls ${DIRECTORY}/compiled_rules/function_list > /dev/null 2>&1
102 if [ ! $? = 0 ]; then
103 echo "*No local compiled rules available to restore."
107 cat ${DIRECTORY}/compiled_rules/function_list >> .function_list
108 if [ ! $? = 0 ]; then
109 echo "ERROR: Unable to restore rules. Function list not present."
113 for i in `ls ${DIRECTORY}/compiled_rules/*.c`; do
114 if [ ! "x$i" = "xgeneric_samples.c" ]; then
115 cp $i ./ > /dev/nulll 2>&1
118 echo "*Restore completed from ${DIRECTORY}/compiled_rules/";
122 elif [ "x$1" = "xbuild" ]; then
124 ls -la .function_list > /dev/null 2>&1
125 if [ ! $? = 0 ]; then
126 echo "ERROR: Unable to build. No function is registered."
130 # Auto generating the file.
131 echo "/* This file is auto generated by $0. Do not touch it. */" > ${CHF}
134 echo "/* Adding the function definitions. */" >> ${CHF};
135 for i in `cat .function_list | sort| uniq`; do
136 echo "void *$i(Eventinfo *lf);" >> ${CHF};
140 echo "/* Adding the rules list. */" >> ${CHF};
141 echo "void *(compiled_rules_list[]) = " >> ${CHF};
143 for i in `cat .function_list | sort| uniq`; do
144 echo " $i," >> ${CHF};
146 echo " NULL" >> ${CHF};
151 echo "/* Adding the rules list names. */" >> ${CHF};
152 echo "char *(compiled_rules_name[]) = " >> ${CHF};
154 for i in `cat .function_list |sort | uniq`; do
155 echo " \"$i\"," >> ${CHF};
157 echo " NULL" >> ${CHF};
160 echo "/* EOF */" >> ${CHF};
163 echo "*Build completed."
166 elif [ "x$1" = "xadd" ]; then
167 if [ "x$2" = "x" ]; then
168 echo "ERROR: Missing function name.";
169 echo "ex: $0 add <function_name>";
173 grep $2 ./*.c > /dev/null 2>&1
174 if [ ! $? = 0 ]; then
175 echo "ERROR: Function '$2' not found.";
179 grep $2 .function_list > /dev/null 2>&1
181 echo "ERROR: Function '$2' already added.";
185 echo $2 >> .function_list;
186 echo "*Function $2 added."
190 echo "ERROR: Invalid argument.";