source: josm/trunk/scripts/TestHTTPS.pl@ 13585

Last change on this file since 13585 was 13585, checked in by stoecker, 6 years ago

see #16123 - add domain ignore list to output

  • Property svn:executable set to *
File size: 2.8 KB
Line 
1#! /usr/bin/perl -w
2
3use strict;
4use utf8;
5use open qw/:std :encoding(utf8)/;
6use Net::HTTPS;
7use XML::LibXML;
8
9my %urls;
10
11my %known = map {$_ => 1} qw(
12 a.tile.osm-tools.org
13 b.tile.osm-tools.org
14 c.tile.osm-tools.org
15 d.tile.osm-tools.org
16 e-mapa.net
17 ge.ch
18 gis.mapa.lodz.pl
19 osmdata.asitvd.ch
20 siglon.londrina.pr.gov.br
21 tiles.itoworld.com
22 tms.cadastre.openstreetmap.fr
23 wms.openstreetmap.de
24 www.jgoodies.com
25 www.osm-tools.org
26 www.webatlasde.de
27 zibi.openstreetmap.org.pl
28);
29
30sub getmaps
31{
32 my $dom = XML::LibXML->load_xml(location => "imagery_josm.imagery.xml");
33 my $xpc = XML::LibXML::XPathContext->new($dom);
34 $xpc->registerNs('j', 'http://josm.openstreetmap.de/maps-1.0');
35 foreach my $entry ($xpc->findnodes("//j:entry"))
36 {
37 my $name = $xpc->findvalue("./j:name", $entry);
38 for my $e ($xpc->findnodes(".//j:*", $entry))
39 {
40 if($e->textContent =~ /^http:\/\/(.*?)[\/]/)
41 {
42 my $u = $1;
43 if($u =~ /^(.*)\{switch:(.*)\}(.*)$/)
44 {
45 my ($f,$switch,$e) = ($1, $2, $3);
46 for my $s (split(",", $switch))
47 {
48 $urls{"$f$s$e"}{"MAP:$name"}++;
49 }
50 }
51 else
52 {
53 $urls{$u}{"MAP:$name"}++;
54 }
55 }
56 }
57 }
58}
59
60sub getfile($$)
61{
62 my ($type, $file) = @_;
63 open FILE,"<:encoding(utf-8)",$file or die;
64 my $name;
65 for my $line (<FILE>)
66 {
67 if($line =~ /^([^ \t].*);/)
68 {
69 $name = $1;
70 }
71 if($line =~ /http:\/\/(.*?)[\/]/)
72 {
73 $urls{$1}{"$type:$name"}++;
74 }
75 }
76}
77
78print "Options: PLUGIN STYLE RULE PRESET MAP GETPLUGIN GETSTYLE GETRULE GETPRESET GETMAP LOCAL\n" if !@ARGV;
79
80my $local = 0;
81for my $ARG (@ARGV)
82{
83 if($ARG eq "LOCAL") {$local = 1; }
84 if($ARG eq "GETMAP") { system "curl https://josm.openstreetmap.de/maps -o imagery_josm.imagery.xml"; getmaps();}
85 if($ARG eq "MAP") { getmaps(); }
86 for my $x ("PLUGIN", "STYLE", "RULE", "PRESET")
87 {
88 my $t = lc($x);
89 my $url = $x eq "PLUGIN" ? $t : "${t}s";
90 my $file = "josm_$t.xml";
91 if($ARG eq "GET$x") { system "curl https://josm.openstreetmap.de/$url -o $file"; getfile($x, $file);}
92 if($ARG eq $x) { getfile($x, $file); }
93 }
94}
95
96for my $url (sort keys %urls)
97{
98 my $i = join(" # ", sort keys %{$urls{$url}});
99 if($local) # skip test
100 {
101 print "* ".($known{$url} ? "~~" : "")."$url:$i\n";
102 next;
103 }
104 eval
105 {
106 local $SIG{ALRM} = sub {die "--Alarm--"};
107
108 alarm(5);
109 my $s = Net::HTTPS->new(Host => $url) || die $@;
110 $s->write_request(GET => "/", 'User-Agent' => "TestHTTPS/1.0");
111 my($code, $mess, %h) = $s->read_response_headers;
112 alarm(0);
113 print "* ".($known{$url} ? "~~" : "")."$url [$code $mess]: $i\n";
114 };
115 if($@ && $@ !~ "(--Alarm--|Connection refused)")
116 {
117 my $e = $@;
118 $e =~ s/[\r\n]//g;
119 $e =~ s/ at scripts\/TestHTTPS.pl .*//;
120 print "* ".($known{$url} ? "~~" : "")."$url [Error $e] :$i\n";
121 }
122}
Note: See TracBrowser for help on using the repository browser.