From a0d7122e1bd6d838b6ed024e469d3c0201a5bec8 Mon Sep 17 00:00:00 2001 From: Jan Michel Date: Fri, 8 Feb 2019 15:48:26 +0100 Subject: [PATCH] add automatic regenerate of xml-db cache files if none exists. Does not check for updates of the xml file because of performance. --- xml-db/get.pl | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/xml-db/get.pl b/xml-db/get.pl index de68502..0cdcebb 100755 --- a/xml-db/get.pl +++ b/xml-db/get.pl @@ -43,6 +43,7 @@ if (defined $ENV{'QUERY_STRING'}) { +my $RealBin = "."; foreach my $req (@request) { ############################### @@ -54,15 +55,14 @@ foreach my $req (@request) { if ($server =~ /HTTPi/i) { $isbrowser = 1; ($entity,$netaddr,$name,$style) = split("-",$req); - $file = "htdocs/xml-db/cache/$entity.entity"; + $RealBin = 'htdocs/xml-db'; } else { # use FindBin qw($RealBin); - my $RealBin = "."; + $RealBin = "."; $isbrowser = 1; ($entity,$netaddr,$name,$style) = split("-",$req); - $file = "$RealBin/cache/$entity.entity"; } - $storefile = "/dev/shm/xmldb-".$req.".store"; + $storefile = "/dev/shm/xmldb-$req.store"; } else { # use FindBin qw($RealBin); my $RealBin = "."; @@ -73,12 +73,13 @@ foreach my $req (@request) { ) or pod2usage(2); pod2usage(1) if $help; $entity = $ARGV[0] || ""; - $file = "$RealBin/cache/$ARGV[0].entity"; $netaddr = $ARGV[1] || ""; $name = $ARGV[2] || ""; $style = $ARGV[3] || ""; } + $file = "$RealBin/cache/$entity.entity"; + $style = "" unless $style; my $isInline = $style =~ /inline/i; my $isColor = $style =~ /color/i; @@ -92,8 +93,17 @@ foreach my $req (@request) { #### Check arguments for validity ############################### - die "Entity $file not found.\n" unless(-e $file) ; - + unless(-e $file) { + my $xmlfile = "$RealBin/database/$entity.xml"; + if(-e $xmlfile) { + system("./$RealBin/xml-db.pl"); + die "Entity $entity not found. Please run xml-db.pl manually.\n" unless(-e $file); + } + else { + die "Entity $entity not found.\n"; + } + } + # trim whitespace from netaddr $netaddr =~ s/^\s+|\s+$//g; @@ -101,7 +111,7 @@ foreach my $req (@request) { # split off some spi chain, if any, after reading the $db, it is parsed ($netaddr, $spi_chains[0]) = split(':',$netaddr); - if ($netaddr=~ m/^0x([0-9a-fA-F]{4})$/) { + if ($netaddr=~ m/^0x([0-9a-fA-F]{1,4})$/) { $netaddr = hex($1); } elsif ($netaddr=~ m/^([0-9]{1,5})$/) { $netaddr = $1; -- 2.43.0