วันศุกร์ที่ 19 สิงหาคม พ.ศ. 2554

การ Export Policy CheckPoint Firewall


ใช้ Command
cp_merge export_policy
จะได้มาเป็น File .pol
ทำให้ดูง่ายด้วยการแปลงเป็น html โดยใช้ perl script
โปรแกรมค่อนข้างจะงงเพราะเขียนเอง มั่วไปเรื่อย
#!c:\perl\bin\perl
#print "Content-type:text/html\n\n";
#use DBI;
#$db="access";
#$host="localhost";
# $userdb="root";
# $passwd="helloyot";
#$connectionInfo="DBI:mysqlPP:$db;$host";
#use Switch 'Perl5';
sub ReadDIR(){
 my $dir = 'D:\1105';
 opendir DIR, $dir or die "read dir $dir - $!";
 my @FILEREAD = grep /^praudit/, readdir DIR;
#my @FILEREAD = grep /'TAF'/. readdir DIR;
 closedir DIR;
 open(IndexFile,"ReadFileLog.soc");
 @INDEX=<indexfile>;</indexfile>
 $index=join(/\|/,@INDEX);
 close(IndexFile);
 for($ii=0;$ii
  if($index !~/$FILEREAD[$ii]/){
   open(IndexFile,">>ReadFileLog.soc");
   #print IndexFile "$FILEREAD[$ii]\n";
   close(IndexFile);
   #print"$FILEREAD[$ii]\n";
   &ReadFile($FILEREAD[$ii]);
  }
 }
}
sub str_replace {
 my $replace_this = shift;
 my $with_this  = shift;
 my $string   = shift;

 my $length = length($string);
 my $target = length($replace_this);

 for(my $i=0; $i
  if(substr($string,$i,$target) eq $replace_this) {
   $string = substr($string,0,$i) . $with_this . substr($string,$i+$target);
   return $string; #Comment this if you what a global replace
  }
 }
 return $string;
}
sub ReadFile($){
#print $filetoread."\n";
 #my $dir = 'd:\CAT Data';
 #($filetoread)=@_;
 #print"--------------$filetoread-------------\n";
 #$rfile=$dir.'\\'.$filetoread;
 #print $rfile;
 #$dbh = DBI->connect($connectionInfo,$userdb,$passwd);
 #open(FILE,"$rfile");
 #open(FILE,"praudit-18Jun10");
 my $dir = 'D:\Log\TBank\log';
 ($filetoread)=@_;
 #print"--------------$filetoread-------------\n";
 $rfile=$dir.'\\'.$filetoread;
 #print $rfile."\n";
 $newfile="new-".$filetoread;
 #print $newfile."\n";
 #$dbh = DBI->connect($connectionInfo,$userdb,$passwd);
 #open(FILE,"$rfile");
 open(FILE,"cyfence.pol");
 @DATA=<file>;</file>
 chomp(@DATA);
 #$x=$DATA[2];
 #print $x;
 print "
<table border=1 cellpadding=0 cellspacing=0><tr><td>Action</td><td>Disabled</td><td>Track</td><td>src</td><td>dst</td><td>Services</td></tr>";
 for ($i=0;$i
  #print $DATA[$i]."\n";
  if(($DATA[$i] ne ")") || ($DATA[$i] ne "(")){
  @x=split(/:/,$DATA[$i]);
  $m=0;
  @x=split(/ /,$x[1]);
  if($x[0] eq "header_text"){
    $header=$DATA[$i];
    @h=split(/"/,$header);
    $header=$h[1];
  }
  $tdst="
<table>";
  if($x[0] eq "rule"){
   $a=0;
   $dst="";
   $src="";
   $service="";
   $r=$x[0];
   $rule="
<tr>";
  }else{
   if($x[0] eq "track"){
    $t="track";
   }
   if($x[0] eq "dst"){
    $cdst=$x[0];
   }
   if($x[0] eq "services"){
    $cservices=$x[0];
   }
   if($x[0] eq "src"){
    $cservices="";
    $csrc=$x[0];
   }
   
   if(($x[0] eq "type") && ($r eq "rule")){
    $action=$x[1];
    $action=str_replace("(","",$action);
    $action=str_replace(")","",$action);
   }elsif($x[0] eq disabled){
    $dis=$x[1];
    $dis=str_replace("(","",$dis);
    $dis=str_replace(")","",$dis);
   }elsif(($x[0] eq "Name") && ($t eq "track")){
    $track=$x[1];
    $track=str_replace("(","",$track);
    $track=str_replace(")","",$track);
    $t="";
   }elsif(($x[0] eq "Name") && ($cdst eq "dst")){
    $dst=$dst."
</tr><tr><td>".$x[1]."</td></tr>";
    $dst=str_replace("(","",$dst);
    $dst=str_replace(")","",$dst);
    
   }elsif($x[0] eq "install"){
    $cdst="";
   }elsif(($x[0] eq "Name") && ($cservices eq "services")){
   #print $x[0]."---".$cservices."\n";
    $services=$services."
<tr><td>".$x[1]."</td></tr>";
    $services=str_replace("(","",$services);
    $services=str_replace(")","",$services);
   }elsif(($x[0] eq "Name") && ($csrc eq "src")){
    $src=$src."
<tr><td>".$x[1]."</td></tr>";
    $src=str_replace("(","",$src);
    $src=str_replace(")","",$src);
   }elsif($x[0] eq "through"){
    #print $csrc."\n";
    $cdst="";
    $cservices="";
    $csrc="";
    if($dis eq "true"){
    #print $header."\n";
     if($header ne ""){
      print "
<tr bgcolor=blue><td colspan=6>".$header."</td></tr>";
      }
     print "
<tr bgcolor=red><td>".$action."</td><td>".$dis."</td><td>".$track."</td><td><table>".$src."</table></td><td><table>".$dst."</table></td><td><table>".$services."</table></td></tr>";
     $header="";
    }else{
     print "
<tr><td>".$action."</td><td>".$dis."</td><td>".$track."</td><td><table>".$src."</table></td><td><table>".$dst."</table></td><td><table>".$services."</table></td></tr>";
     
    }
    #print $action."-".$dis."-".$track."-".$dst."-".$services."-".$src."\n";
    $dst="";
    $services="";
    $src="";
   }
  }
  
  
 }

 #print $rule."
</table>";
 }
 print "
</table>";
 #print $newfile."\n";
 #print $i;
 #print $llog."xxxxx\n";
}
&ReadFile();

ไม่มีความคิดเห็น:

แสดงความคิดเห็น