iwla/tools/iwla_convert.pl

114 lines
2.6 KiB
Perl
Executable File

#!/usr/bin/perl
my $awstats_lib_root = '/usr/share/awstats/lib/';
# my $awstats_lib_root = './';
my @awstats_libs = ('search_engines.pm', 'robots.pm', 'operating_systems.pm', 'browsers.pm');
# my @awstats_libs = ('browsers.pm', 'browsers_phone.pm', 'mime.pm', 'referer_spam.pm', 'search_engines.pm', 'operating_systems.pm', 'robots.pm', 'worms.pm');
foreach $lib (@awstats_libs) {require $awstats_lib_root . $lib;}
require './tools/own_search_engines.pm';
sub dumpList {
my @list = @{$_[0]};
my $FIC = $_[1];
my $first = $_[2];
foreach $r (@list)
{
$r =~ s/\'/\\\'/g;
if ($first == 0)
{
print $FIC ", ";
}
else
{
$first = 0;
}
print $FIC "'$r'";
}
}
sub dumpHash {
my %hash = %{$_[0]};
my $FIC = $_[1];
my $first = $_[2];
while( my ($k,$v) = each(%hash) ) {
$k =~ s/\'/\\\'/g;
$v =~ s/\'/\\\'/g;
next if ($k eq "" || $v eq "");
if ($first == 0)
{
print $FIC ", ";
}
else
{
$first = 0;
}
print $FIC "'$k' : '$v'";
}
}
# Robots
open($FIC,">", "awstats_data.py") or die $!;
print $FIC "#This file was automatically generated by iwla_convert.pl. Do not edit manually.\n\n";
print $FIC "robots = [";
dumpList(\@RobotsSearchIDOrder_list1, $FIC, 1);
dumpList(\@RobotsSearchIDOrder_list2, $FIC, (@RobotsSearchIDOrder_list1 == 0) ? 1 : 0);
print $FIC "]\n\n";
print $FIC "search_engines = [";
dumpList(\@SearchEnginesSearchIDOrder_list1, $FIC, 1);
print $FIC "]\n\n";
print $FIC "search_engines_2 = [";
dumpList(\@SearchEnginesSearchIDOrder_list2, $FIC, 1);
dumpList(\@Own_SearchEnginesSearchIDOrder, $FIC, (@SearchEnginesSearchIDOrder_list2 == 0) ? 1 : 0);
print $FIC "]\n\n";
print $FIC "not_search_engines_keys = {";
dumpHash(\%NotSearchEnginesKeys, $FIC, 1);
print $FIC "}\n\n";
print $FIC "search_engines_hashid = {";
dumpHash(\%SearchEnginesHashID, $FIC, 1);
dumpHash(\%Own_SearchEnginesHashID, $FIC, 0);
print $FIC "}\n\n";
print $FIC "search_engines_knwown_url = {";
dumpHash(\%SearchEnginesKnownUrl, $FIC, 1);
dumpHash(\%Own_SearchEnginesKnownUrl, $FIC, 0);
print $FIC "}\n\n";
print $FIC "operating_systems = [";
dumpList(\@OSSearchIDOrder, $FIC, 1);
print $FIC "]\n\n";
print $FIC "operating_systems_hashid = {";
dumpHash(\%OSHashID, $FIC, 1);
print $FIC "}\n\n";
print $FIC "operating_systems_family = {";
dumpHash(\%OSFamily, $FIC, 1);
print $FIC "}\n\n";
print $FIC "browsers = [";
dumpList(\@BrowsersSearchIDOrder, $FIC, 1);
print $FIC "]\n\n";
print $FIC "browsers_hashid = {";
dumpHash(\%BrowsersHashIDLib, $FIC, 1);
print $FIC "}\n\n";
print $FIC "browsers_icons = {";
dumpHash(\%BrowsersHashIcon, $FIC, 1);
print $FIC "}\n\n";
close($FIC);
print "Done !\n";