1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
| #!/usr/bin/perl
use strict;
use HTML::Parser;
#package MyParser;
#use base qw(HTML::Parser);
#my $p = new HTML::Parser;
# $p->parse_file("backup.html");
my $parser = HTML::Parser->new();
# définition des evenements
$parser->handler( text => \&text, "dtext" );
$parser->handler( start => \&start, "tagname,attr" );
$parser->handler( end => \&end, "tagname" );
my $count_td;
my $count_a;
my @data;
sub start {
my ($tag, $attr,$attrseq, $origtext) = @_;
$count_td++;
if( $tag eq 'td'){
#print "ne rien faire \n";
}
#elsif ($tag eq 'a'and $attr->{href} eq '/^objdef-id[0-9]/' ){
#$count_a++
#}
}
sub end {
my ($tag) = @_;
$count_td--;
#$count_a--;
if( $tag eq 'td' and $count_td){
#print " td \n";
}
#elsif ($tag eq 'a' and $count_a){
#print "a \n";
#}
}
sub text {
my ($text) = @_;
if ($count_td){
push @data, $text ;
#print " $text \n";
}
#elsif ($count_a){
#push (@data, $text);
#print" $text \n";
#}
}
#print @data ;
# package main;
my $html = <<EOHTML;
#<html>
<html xmlns:fwbuilder="http://www.fwbuilder.org/1.0/">
<head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"></head>
<body bgcolor="#ffffff" link="#0000ee" vlink="#551a8b" alinlk="#0000ee">
<h2>Firewall policy definition</h2>
<a href="#_NETWORKS">Networks</a> | <a href="#_ADDRRANGES">Address Ranges</a> | <a href="#_HOSTS">Hosts</a> | <a href="#_GROUPS"> Object Groups</a> | <a href="#_SERVICES">Services</a> |<a href="#_SERVGROUPS"> Service Groups</a>
<br><br><table border="1" cellspacing="0" width="%95"><tr><td><table border="0" cellspacing="2" width="%100">
<tr><th colspan="2" bgcolor="#CCCCCC">Firewall</th></tr>
<tr><th colspan="2"></th></tr>
<tr>
<th align="left" width="20%">Name:</th>
<td align="left">FW1</td>
</tr>
<tr>
<th align="left" width="20%">Platform:</th>
<td align="left">pix</td>
</tr>
<tr>
<th align="left" width="20%">Host OS:</th>
<td align="left">pix_os</td>
</tr>
<tr>
<th align="left" width="20%">Comment:</th>
<td align="left"></td>
</tr>
<tr><th colspan="2"></th></tr>
<tr><th colspan="2"></th></tr>
<tr><td colspan="2">
<br><table border="1" width="95%" cellspacing="0">
<caption align="left"><b><font size="+1">NAT rules</font></b></caption>
<tr>
<th width="20" bgcolor="#009900"><font color="#ffffff">Num</font></th>
<th bgcolor="#009900"><font color="#ffffff">OSrc</font></th>
<th bgcolor="#009900"><font color="#ffffff">ODst</font></th>
<th bgcolor="#009900"><font color="#ffffff">OSrv</font></th>
<th bgcolor="#009900"><font color="#ffffff">TSrc</font></th>
<th bgcolor="#009900"><font color="#ffffff">TDst</font></th>
<th bgcolor="#009900"><font color="#ffffff">TSrv</font></th>
</tr>
</table>
<br><table border="1" width="95%" cellspacing="0">
<caption align="left"><b><font size="+1">Policy Rules</font></b></caption>
<tr>
<th width="20" bgcolor="#009900"><font color="#ffffff">Num</font></th>
<th bgcolor="#009900"><font color="#ffffff">Src</font></th>
<th bgcolor="#009900"><font color="#ffffff">Dst</font></th>
<th bgcolor="#009900"><font color="#ffffff">Srv</font></th>
<th bgcolor="#009900"><font color="#ffffff">Action</font></th>
<th bgcolor="#009900"><font color="#ffffff">Comment</font></th>
</tr>
<tr>
<td>0</td>
<td>Any<br>
</td>
<td>Any<br>
</td>
<td>
<a href="#objdef-id3C20EEB5">any ICMP</a><br>
</td>
<td>Accept</td>
<td><br>
</td>
</tr>
#</html>
EOHTML
$parser->parse( $html );
print @data; |