6 use Cwd qw/getcwd realpath/;
9 use File::Temp qw/tempfile/;
11 my $ossec_regex_convert = realpath(dirname($0) . '/../src/ossec-regex-convert');
13 sub get_install_dir () {
14 open(FILE, '<', 'src/LOCATION') || die("Cannot find INSTALL DIR");
15 my $dir = '/var/ossec';
18 if (m{^DIR\s*=\s*(["']?)(.*)\g1$}p) {
27 my $old_tags = join('|', split(/\n/m, `$ossec_regex_convert -t`));
29 sub convert_file ($) {
30 my $filename = shift();
31 print("Converting ${filename}...\n");
33 unless (open(SRC, '<', $filename)) {
34 print(STDERR "Cannot read '${filename}'\n");
37 my ($tmp_fh, $tmp_filename) = tempfile('tmp-ossec-config-convert.XXXXX', DIR => '/tmp', SUFFIX => '.xml');
40 if (m{^(\s*)<\s*($old_tags)([^>]*)>(.*?)<\s*/\s*\g2\s*>}pg) {
41 my ($indent, $old_type, $options, $old_regex) = ($1, $2, $3, $4);
42 $old_regex =~ s/'/'\\''/g;
43 my $out = qx/$ossec_regex_convert -b -- $old_type '$old_regex'/;
45 my ($type, $regex) = split(/ /, $out, 2);
47 print($tmp_fh "$indent<$type$options>$regex</$type>\n");
49 print($tmp_fh "$indent<$type$options></$type>\n");
59 rename($tmp_filename, $filename);
63 my $filename = $File::Find::name;
65 if ($filename =~ m/[.]xml$/) {
66 convert_file($filename);
70 my $INSTALL_DIR = get_install_dir();
71 if (! -d ${INSTALL_DIR}) {
72 print(STDERR "Please install OSSEC first\n");
76 find({wanted => \&wanted, no_chdir => 1}, $INSTALL_DIR);