Advertisement
Guest User

Untitled

a guest
Aug 15th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.79 KB | None | 0 0
  1. #!/usr/bin/perl
  2.  
  3. #use strict;
  4. use Spreadsheet::WriteExcel;
  5. use DBI;
  6. use warnings;
  7.  
  8. ## Global Variables
  9.  
  10. my $host = "localhost";
  11. my $user = "user";
  12. my $password = "password";
  13. my $database = "customer";
  14.  
  15. ##
  16. # Create Excel Layout
  17. ##
  18.  
  19. my $workbook = Spreadsheet::WriteExcel->new("firstreport.xls");
  20. my $worksheet = $workbook->add_worksheet(WebFilter-Blocked);
  21. my $worksheet1 = $workbook->add_worksheet(Traffic);
  22. my $worksheet2 = $workbook->add_worksheet(Virus);
  23. my $ipssheet = $workbook->add_worksheet(IPS);
  24.  
  25. my $alignc = $workbook->add_format(); #simple center only format
  26. $alignc->set_align('center');
  27. $alignc->set_align('vcenter');
  28.  
  29.  
  30. $worksheet->write_string(0, 1, "Time");
  31. $worksheet->write_string(0, 2, "Source");
  32. $worksheet->write_string(0, 3, "Type");
  33. $worksheet->write_string(0, 4, "Website");
  34. $worksheet->write_string(0, 5, "Catergory");
  35. $worksheet->write_string(0, 6, "Stauts");
  36.  
  37. $ipssheet->write_string(0, 1, "Time");
  38. $ipssheet->write_string(0, 2, "Severity");
  39. $ipssheet->write_string(0, 3, "Source");
  40. $ipssheet->write_string(0, 4, "Destination");
  41. $ipssheet->write_string(0, 5, "Reference");
  42. $ipssheet->write_string(0, 6, "Attack Message");
  43.  
  44. ##
  45. # Database Part
  46. ##
  47.  
  48. my $dbh = DBI->connect("DBI:mysql:$database:$host", $user, $password);
  49. my $sth= $dbh->prepare("SELECT itime,src,service,hostname,cat_desc,status FROM FG100A3907507179_webfilter WHERE `status` = 'blocked'");
  50. my $attack_q= $dbh->prepare("SELECT itime,severity,src,dst,ref,msg FROM FG100A3907507179_attacks");
  51. $sth->execute();
  52. $attack_q->execute();
  53.  
  54. #capture output into array and variablize the results
  55.  
  56. while ( @row = $sth->fetchrow_array ) {
  57. ($time,$src,$service,$website,$cat_desc,$status) = @row;
  58.  
  59. # Write data into Webfilter Workbook
  60.  
  61. my $workbook = Spreadsheet::WriteExcel->new("firstreport.xls");
  62.  
  63. $worksheet->write($row+2, 1, $time,$alignc);
  64. $worksheet->write($row+2, 2, $src,$alignc);
  65. $worksheet->write($row+2, 3, $service,$alignc);
  66. $worksheet->write_string($row+2, 4, $website,$alignc);
  67. $worksheet->write_string($row+2, 5, $cat_desc,$alignc);
  68. $worksheet->write_string($row+2, 6, $status,$alignc);
  69. $row++;
  70. }
  71.  
  72. while ( @attacks = $attack_q->fetchrow_array ) {
  73. my ($time,$severity,$src,$dst,$ref,$msg) = @attacks;
  74.  
  75. $ipssheet->write($row+2, 1, $time,$alignc);
  76. $ipssheet->write($row+2, 2, $severiy,$alignc);
  77. $ipssheet->write($row+2, 3, $src,$alignc);
  78. $ipssheet->write_string($row+2, 4, $dst,$alignc);
  79. $ipssheet->write_string($row+2, 5, $ref,$alignc);
  80. $ipssheet->write_string($row+2, 6, $msg,$alignc);
  81. $row++;
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement