mirror of
https://github.com/UzixLS/armastuff.git
synced 2025-07-18 23:01:34 +03:00
stdout mode, additional checks, multiple predefined urls
This commit is contained in:
@ -15,15 +15,23 @@ my $debug = 0;
|
|||||||
my $noempty = 0;
|
my $noempty = 0;
|
||||||
my $watch = 0;
|
my $watch = 0;
|
||||||
my $html = 0;
|
my $html = 0;
|
||||||
my $url = 'http://simamo.de/~manuel/arma-serverlist.js/serverxml.php';
|
my $stdout = 0;
|
||||||
my $file = 'armalist.xml';
|
my $file = 'armalist.xml';
|
||||||
my $logfile = 'armalist.log';
|
my $logfile = 'armalist.log';
|
||||||
|
my $url;
|
||||||
|
my @urls = (
|
||||||
|
'http://crazy-tronners.com/grid/serverxml.php',
|
||||||
|
'http://browser.hashpickup.net/serverxml.xml',
|
||||||
|
'http://simamo.de/~manuel/arma-serverlist.js/serverxml.php',
|
||||||
|
'http://wrtlprnft.ath.cx/serverlist/serverxml.php',
|
||||||
|
);
|
||||||
|
|
||||||
GetOptions (
|
GetOptions (
|
||||||
"debug" => \$debug,
|
"debug" => \$debug,
|
||||||
"noempty" => \$noempty,
|
"noempty" => \$noempty,
|
||||||
"watch" => \$watch,
|
"watch" => \$watch,
|
||||||
"html" => \$html,
|
"html" => \$html,
|
||||||
|
"stdout" => \$stdout,
|
||||||
"url=s" => \$url,
|
"url=s" => \$url,
|
||||||
"file=s" => \$file,
|
"file=s" => \$file,
|
||||||
"logfile=s" => \$logfile,
|
"logfile=s" => \$logfile,
|
||||||
@ -57,10 +65,12 @@ sub read_inet
|
|||||||
|
|
||||||
$retcode = $curl->perform;
|
$retcode = $curl->perform;
|
||||||
if ($retcode != 0) {
|
if ($retcode != 0) {
|
||||||
die ("An error happened: $retcode ".$curl->strerror($retcode)." ".$curl->errbuf."\n");
|
die ("Curl error $retcode: ".$curl->strerror($retcode)." ".$curl->errbuf."\n");
|
||||||
}
|
}
|
||||||
print "...done\n" if $debug;
|
print "...done\n" if $debug;
|
||||||
|
|
||||||
|
XMLin($response_body, ForceArray => 1, parseropts => [ load_ext_dtd => 0 ]) or die "Incorrect HTTP data";
|
||||||
|
|
||||||
if ($outfile) {
|
if ($outfile) {
|
||||||
print "Writting file $outfile\n" if $debug;
|
print "Writting file $outfile\n" if $debug;
|
||||||
open my $out, '>', $outfile or die "Cannot open file $outfile: $!\n";
|
open my $out, '>', $outfile or die "Cannot open file $outfile: $!\n";
|
||||||
@ -68,14 +78,14 @@ sub read_inet
|
|||||||
close $out;
|
close $out;
|
||||||
}
|
}
|
||||||
|
|
||||||
return XMLin($response_body, ForceArray => 1, parseropts => [ load_ext_dtd => 0 ])
|
return XMLin($response_body, ForceArray => 1, parseropts => [ load_ext_dtd => 0 ]);
|
||||||
}
|
}
|
||||||
|
|
||||||
sub read_file
|
sub read_file
|
||||||
{
|
{
|
||||||
my $in = shift;
|
my $in = shift;
|
||||||
print "Reading file $in\n" if $debug;
|
print "Reading file $in\n" if $debug;
|
||||||
return XMLin($in, ForceArray => 1, parseropts => [ load_ext_dtd => 0 ]);
|
return (XMLin($in, ForceArray => 1, parseropts => [ load_ext_dtd => 0 ]) or die "Incorrect file data");
|
||||||
}
|
}
|
||||||
|
|
||||||
sub bold
|
sub bold
|
||||||
@ -158,11 +168,17 @@ sub compare_log
|
|||||||
$time = "<i>$time</i>";
|
$time = "<i>$time</i>";
|
||||||
}
|
}
|
||||||
print "Comparing server lists\n" if $debug;
|
print "Comparing server lists\n" if $debug;
|
||||||
|
|
||||||
print "Open file $outfile\n" if $debug;
|
print "Open file $outfile\n" if $debug;
|
||||||
open my $out, '>>', $outfile or die "Cannot open file $outfile: $!\n";
|
my $out;
|
||||||
|
if ($stdout) {
|
||||||
|
open $out, '>-';
|
||||||
|
} else {
|
||||||
|
open $out, '>>', $outfile or die "Cannot open file $outfile: $!\n";
|
||||||
|
}
|
||||||
|
|
||||||
if (! keys %{$new}) {
|
if (! keys %{$new}) {
|
||||||
print $out "$time: error upgrading server list.".&endl;
|
print $out "$time: Error upgrading server list.".&endl;
|
||||||
die "$time: error upgrading server list.";
|
die "$time: error upgrading server list.";
|
||||||
}
|
}
|
||||||
if (! keys %{$old}) {
|
if (! keys %{$old}) {
|
||||||
@ -180,7 +196,7 @@ sub compare_log
|
|||||||
if (defined $old->{$sname}) {
|
if (defined $old->{$sname}) {
|
||||||
for (qw/addr descr url ver maxpl/) {
|
for (qw/addr descr url ver maxpl/) {
|
||||||
if (! ($old->{$sname}{$_} ~~ $new->{$sname}{$_})) {
|
if (! ($old->{$sname}{$_} ~~ $new->{$sname}{$_})) {
|
||||||
print $out "$time: server ".&bold($sname)." changed ".&bold($_).
|
print $out "$time: Server ".&bold($sname)." changed ".&bold($_).
|
||||||
" from ".&bold($old->{$sname}{$_})." to ".&bold($new->{$sname}{$_}).&endl;
|
" from ".&bold($old->{$sname}{$_})." to ".&bold($new->{$sname}{$_}).&endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -252,6 +268,8 @@ sub fill_serverhash
|
|||||||
|
|
||||||
print "Starting " if $debug;
|
print "Starting " if $debug;
|
||||||
|
|
||||||
|
$url = $urls[0] if (length($url) < 1);
|
||||||
|
|
||||||
if ($watch) {
|
if ($watch) {
|
||||||
print "watcher\n" if $debug;
|
print "watcher\n" if $debug;
|
||||||
my %savedservers = &fill_serverhash (&read_file ($file)) if (-r $file);
|
my %savedservers = &fill_serverhash (&read_file ($file)) if (-r $file);
|
||||||
@ -259,8 +277,7 @@ if ($watch) {
|
|||||||
&compare_log (\%savedservers, \%activservers, $logfile);
|
&compare_log (\%savedservers, \%activservers, $logfile);
|
||||||
} else {
|
} else {
|
||||||
print "lister\n" if $debug;
|
print "lister\n" if $debug;
|
||||||
#my %activservers = &fill_serverhash (&read_inet ($url));
|
my %activservers = &fill_serverhash (&read_inet ($url));
|
||||||
my %activservers = &fill_serverhash (&read_file("serverxml.php"));
|
|
||||||
$html && &print_html(\%activservers) || &print_plain(\%activservers);
|
$html && &print_html(\%activservers) || &print_plain(\%activservers);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user