Link to home
Start Free TrialLog in
Avatar of 3XLcom
3XLcom

asked on

Perl - Create HTML Table

I have text files which has sample output as given below  and i am sending this emails in the given way below also  and the result on email is really bad seems as given below also


i want to organize the file output as how should i do it ?


required output of text lines :
<table>
<tr><td>timestampfromfile</td><td>srcIP</td><td>dstIP</td><td>prot</td><td>srcPort </td><td>dstPort</td><td>octets</td><td>packets</tr>
<tr><td>2013-12-23  12:06:53.776</td><td>205.196.121.163</td><td>178.20.224.151</td><td>6</td><td>80</td><td>64450</td><td>1552</td><td>256</tr>
<tr><td>2013-12-23  12:06:53.776</td><td>205.196.121.163</td><td>178.20.224.151</td><td>6</td><td>80</td><td>64450</td><td>1552</td><td>256</tr>
<tr><td>2013-12-23  12:06:53.776</td><td>205.196.121.163</td><td>178.20.224.151</td><td>6</td><td>80</td><td>64450</td><td>1552</td><td>256</tr>
<tr><td>2013-12-23  12:06:53.776</td><td>205.196.121.163</td><td>178.20.224.151</td><td>6</td><td>80</td><td>64450</td><td>1552</td><td>256</tr>
<tr><td>2013-12-23  12:06:53.776</td><td>205.196.121.163</td><td>178.20.224.151</td><td>6</td><td>80</td><td>64450</td><td>1552</td><td>256</tr><tr><td>2013-12-23  12:06:53.776</td><td>205.196.121.163</td><td>178.20.224.151</td><td>6</td><td>80</td><td>64450</td><td>1552</td><td>256</tr>
..................
</table>

Open in new window



Mail code :


$to = 'c.e@xxxxx.com.tr';
$cc = 'abuse@xxxxx.com.tr';
$from = 'no-reply@noc.xxxxx.com.tr';
$subject = 'Attack Information - '.$ipaddress;

 $message = ' <style type="text/css">';
 $message .= ' .auto-style1 {';
 $message .= ' font-size: small;';
 $message .= ' }';
 $message .= ' .auto-style2 ';
 $message .= ' font-size: 8px;';
 $message .= ' color: #666666;';
 $message .= ' }';
 $message .=   '   </style>';
$message .= 'We realize that your ip address attacking to our ip address ("'.$victim.'") Please stop the attacker. <br/><br/>';


 open (MYFILE, $fileurl);
 while (<MYFILE>) {
        chomp;
        $message .= "$_ <br/>";
 }
 close (MYFILE);




 $message .= '<p>';
 $message .= ' <span class="auto-style2"><strong>Noc Team / xxxxx Telekom</strong></span><br class="auto-style1" />';
 $message .=   '        <br class="auto-style1" />';
 $message .= ' <span class="auto-style1">Email:&nbsp;info@xxxxx.com.tr&nbsp;<br/> </span>';
 $message .= ' <span class="auto-style1">Office:&nbsp;+90 - (232) 332 01 05&nbsp;/ Fax:+90 - (232) 332 01 05&nbsp; </span>';
 $message .= ' <br class="auto-style1" />';
 $message .= ' <span class="auto-style1">68 Sk. No:17 /3 Üçkuyular / Izmir </span>';
 $message .=   '        <br class="auto-style1" />';
 $message .= ' <a href="https://www.xxxxx.com.tr"><span class="auto-style1">https://www.xxxxx.com.tr</span></a>';


$msg = MIME::Lite->new(
                 From     => $from,
                 To       => $to,
                 Cc       => $cc,
                 Subject  => $subject,
                 Data     => $message
                 );


$msg->attr("content-type" => "text/html");

Open in new window




cat result of txt file :

[root@sflow ispsend]# cat 1387793258-205.196.121.163.txt
timestampfromfile       srcIP   dstIP   prot    srcPort dstPort octets  packets
2013-12-23 12:06:44.876 205.196.121.163 178.20.224.151  6       80      64449   1522    256
2013-12-23 12:06:44.926 205.196.121.163 178.20.224.151  6       80      64439   1522    256
2013-12-23 12:06:45.454 205.196.121.163 178.20.224.151  6       80      64451   1522    256
2013-12-23 12:06:45.563 205.196.121.163 178.20.224.151  6       80      64439   1522    256
2013-12-23 12:06:45.645 205.196.121.163 178.20.224.151  6       80      64448   1522    256
2013-12-23 12:06:45.649 205.196.121.163 178.20.224.151  6       80      64439   1522    256
2013-12-23 12:06:45.650 205.196.121.163 178.20.224.151  6       80      64439   1522    256
2013-12-23 12:06:45.736 205.196.121.163 178.20.224.151  6       80      64450   1522    256
2013-12-23 12:06:45.739 205.196.121.163 178.20.224.151  6       80      64450   1522    256
2013-12-23 12:06:45.800 205.196.121.163 178.20.224.151  6       80      64439   1522    256
2013-12-23 12:06:45.802 205.196.121.163 178.20.224.151  6       80      64439   1522    256
2013-12-23 12:06:45.806 205.196.121.163 178.20.224.151  6       80      64448   1522    256
2013-12-23 12:06:45.866 205.196.121.163 178.20.224.151  6       80      64439   1522    256
2013-12-23 12:06:45.868 205.196.121.163 178.20.224.151  6       80      64439   1522    256
2013-12-23 12:06:45.954 205.196.121.163 178.20.224.151  6       80      64439   1522    256
2013-12-23 12:06:46.045 205.196.121.163 178.20.224.151  6       80      64451   1522    256
2013-12-23 12:06:46.437 205.196.121.163 178.20.224.151  6       80      64449   1522    256
2013-12-23 12:06:46.455 205.196.121.163 178.20.224.151  6       80      64453   1522    256
2013-12-23 12:06:46.466 205.196.121.163 178.20.224.151  6       80      64448   1522    256
2013-12-23 12:06:46.469 205.196.121.163 178.20.224.151  6       80      64439   1522    256
2013-12-23 12:06:46.471 205.196.121.163 178.20.224.151  6       80      64454   446     256
2013-12-23 12:06:46.561 205.196.121.163 178.20.224.151  6       80      64453   1522    256
2013-12-23 12:06:46.572 205.196.121.163 178.20.224.151  6       80      64450   1522    256
2013-12-23 12:06:46.691 205.196.121.163 178.20.224.151  6       80      64453   1522    256
2013-12-23 12:06:46.755 205.196.121.163 178.20.224.151  6       80      64450   1522    256
2013-12-23 12:06:46.932 205.196.121.163 178.20.224.151  6       80      64439   1522    256
2013-12-23 12:06:46.936 205.196.121.163 178.20.224.151  6       80      64453   1522    256
2013-12-23 12:06:46.942 205.196.121.163 178.20.224.151  6       80      64449   1522    256
2013-12-23 12:06:47.192 205.196.121.163 178.20.224.151  6       80      64439   1522    256
2013-12-23 12:06:47.198 205.196.121.163 178.20.224.151  6       80      64449   1522    256
2013-12-23 12:06:47.201 205.196.121.163 178.20.224.151  6       80      64449   1522    256
2013-12-23 12:06:47.207 205.196.121.163 178.20.224.151  6       80      64439   1522    256
2013-12-23 12:06:47.268 205.196.121.163 178.20.224.151  6       80      64439   1522    256
2013-12-23 12:06:47.270 205.196.121.163 178.20.224.151  6       80      64439   1522    256
2013-12-23 12:06:47.271 205.196.121.163 178.20.224.151  6       80      64449   1522    256
2013-12-23 12:06:47.386 205.196.121.163 178.20.224.151  6       80      64453   1522    256
2013-12-23 12:06:47.496 205.196.121.163 178.20.224.151  6       80      64449   1522    256
2013-12-23 12:06:47.499 205.196.121.163 178.20.224.151  6       80      64450   1522    256
2013-12-23 12:06:47.642 205.196.121.163 178.20.224.151  6       80      64450   1522    256
2013-12-23 12:06:47.664 205.196.121.163 178.20.224.151  6       80      64450   1522    256
2013-12-23 12:06:47.666 205.196.121.163 178.20.224.151  6       80      64450   1522    256
2013-12-23 12:06:47.738 205.196.121.163 178.20.224.151  6       80      64453   1522    256
2013-12-23 12:06:47.788 205.196.121.163 178.20.224.151  6       80      64453   1522    256
2013-12-23 12:06:47.876 205.196.121.163 178.20.224.151  6       80      64449   1522    256
2013-12-23 12:06:47.886 205.196.121.163 178.20.224.151  6       80      64451   1522    256
2013-12-23 12:06:47.928 205.196.121.163 178.20.224.151  6       80      64439   1522    256
2013-12-23 12:06:48.041 205.196.121.163 178.20.224.151  6       80      64449   1522    256
2013-12-23 12:06:48.068 205.196.121.163 178.20.224.151  6       80      64451   1522    256
2013-12-23 12:06:48.182 205.196.121.163 178.20.224.151  6       80      64439   1522    256
2013-12-23 12:06:48.400 205.196.121.163 178.20.224.151  6       80      64450   1522    256
2013-12-23 12:06:48.426 205.196.121.163 178.20.224.151  6       80      64451   1522    256
2013-12-23 12:06:49.800 205.196.121.163 178.20.224.151  6       80      64449   1522    256
2013-12-23 12:06:49.983 205.196.121.163 178.20.224.151  6       80      64449   1522    256
2013-12-23 12:06:50.520 205.196.121.163 178.20.224.151  6       80      64448   1522    256
2013-12-23 12:06:50.523 205.196.121.163 178.20.224.151  6       80      64449   1522    256
2013-12-23 12:06:50.529 205.196.121.163 178.20.224.151  6       80      64450   1522    256
2013-12-23 12:06:50.540 205.196.121.163 178.20.224.151  6       80      64439   1522    256
2013-12-23 12:06:50.553 205.196.121.163 178.20.224.151  6       80      64449   1522    256
2013-12-23 12:06:50.559 205.196.121.163 178.20.224.151  6       80      64451   1522    256
2013-12-23 12:06:50.573 205.196.121.163 178.20.224.151  6       80      64454   1522    256
2013-12-23 12:06:50.587 205.196.121.163 178.20.224.151  6       80      64449   1522    256
2013-12-23 12:06:50.589 205.196.121.163 178.20.224.151  6       80      64449   1522    256
2013-12-23 12:06:50.598 205.196.121.163 178.20.224.151  6       80      64451   1522    256
2013-12-23 12:06:50.600 205.196.121.163 178.20.224.151  6       80      64451   1522    256
2013-12-23 12:06:50.604 205.196.121.163 178.20.224.151  6       80      64439   1522    256
2013-12-23 12:06:50.617 205.196.121.163 178.20.224.151  6       80      64450   1522    256
2013-12-23 12:06:50.623 205.196.121.163 178.20.224.151  6       80      64451   1522    256
2013-12-23 12:06:50.631 205.196.121.163 178.20.224.151  6       80      64439   1522    256
2013-12-23 12:06:50.644 205.196.121.163 178.20.224.151  6       80      64449   1522    256
2013-12-23 12:06:50.648 205.196.121.163 178.20.224.151  6       80      64450   1522    256
2013-12-23 12:06:50.649 205.196.121.163 178.20.224.151  6       80      64450   1522    256
2013-12-23 12:06:50.652 205.196.121.163 178.20.224.151  6       80      64449   1522    256
2013-12-23 12:06:50.678 205.196.121.163 178.20.224.151  6       80      64450   1522    256
2013-12-23 12:06:50.679 205.196.121.163 178.20.224.151  6       80      64451   1522    256
2013-12-23 12:06:50.800 205.196.121.163 178.20.224.151  6       80      64439   1522    256
2013-12-23 12:06:51.039 205.196.121.163 178.20.224.151  6       80      64454   1522    256
2013-12-23 12:06:51.041 205.196.121.163 178.20.224.151  6       80      64449   1522    256
2013-12-23 12:06:51.049 205.196.121.163 178.20.224.151  6       80      64450   1522    256
2013-12-23 12:06:51.070 205.196.121.163 178.20.224.151  6       80      64439   1522    256
2013-12-23 12:06:51.072 205.196.121.163 178.20.224.151  6       80      64439   1522    256
2013-12-23 12:06:51.081 205.196.121.163 178.20.224.151  6       80      64450   1522    256
2013-12-23 12:06:51.082 205.196.121.163 178.20.224.151  6       80      64450   1522    256
2013-12-23 12:06:51.089 205.196.121.163 178.20.224.151  6       80      64450   1522    256
2013-12-23 12:06:51.119 205.196.121.163 178.20.224.151  6       80      64450   1522    256
2013-12-23 12:06:51.122 205.196.121.163 178.20.224.151  6       80      64449   1522    256
2013-12-23 12:06:51.124 205.196.121.163 178.20.224.151  6       80      64451   1522    256
2013-12-23 12:06:51.126 205.196.121.163 178.20.224.151  6       80      64451   1522    256
2013-12-23 12:06:51.143 205.196.121.163 178.20.224.151  6       80      64439   1522    256
2013-12-23 12:06:51.154 205.196.121.163 178.20.224.151  6       80      64450   1522    256
2013-12-23 12:06:51.162 205.196.121.163 178.20.224.151  6       80      64450   1522    256
2013-12-23 12:06:51.165 205.196.121.163 178.20.224.151  6       80      64454   1522    256
2013-12-23 12:06:51.192 205.196.121.163 178.20.224.151  6       80      64453   1522    256
2013-12-23 12:06:51.211 205.196.121.163 178.20.224.151  6       80      64439   1522    256
2013-12-23 12:06:51.268 205.196.121.163 178.20.224.151  6       80      64449   1522    256
2013-12-23 12:06:51.675 205.196.121.163 178.20.224.151  6       80      64449   1522    256
2013-12-23 12:06:51.691 205.196.121.163 178.20.224.151  6       80      64453   1522    256
2013-12-23 12:06:52.176 205.196.121.163 178.20.224.151  6       80      64449   866     256
2013-12-23 12:06:52.177 205.196.121.163 178.20.224.151  6       80      64448   1522    256
2013-12-23 12:06:52.180 205.196.121.163 178.20.224.151  6       80      64449   1522    256
2013-12-23 12:06:52.188 205.196.121.163 178.20.224.151  6       80      64451   1522    256
2013-12-23 12:06:52.210 205.196.121.163 178.20.224.151  6       80      64439   1522    256
2013-12-23 12:06:52.655 205.196.121.163 178.20.224.151  6       80      64450   1522    256
2013-12-23 12:06:52.894 205.196.121.163 178.20.224.151  6       80      64450   1522    256
2013-12-23 12:06:52.896 205.196.121.163 178.20.224.151  6       80      64451   1522    256
2013-12-23 12:06:53.183 205.196.121.163 178.20.224.151  6       80      64439   1522    256
2013-12-23 12:06:53.299 205.196.121.163 178.20.224.151  6       80      64450   1522    256
2013-12-23 12:06:53.403 205.196.121.163 178.20.224.151  6       80      64450   1522    256
2013-12-23 12:06:53.417 205.196.121.163 178.20.224.151  6       80      64449   1522    256
2013-12-23 12:06:53.737 205.196.121.163 178.20.224.151  6       80      64451   1522    256
2013-12-23 12:06:53.739 205.196.121.163 178.20.224.151  6       80      64450   1522    256
2013-12-23 12:06:53.776 205.196.121.163 178.20.224.151  6       80      64450   1522    256
2013-12-23 12:06:53.778 205.196.121.163 178.20.224.151  6       80      64449   1522    256
2013-12-23 12:06:53.786 205.196.121.163 178.20.224.151  6       80      64450   1522    256
2013-12-23 12:06:53.804 205.196.121.163 178.20.224.151  6       80      64449   1522    256
2013-12-23 12:06:53.806 205.196.121.163 178.20.224.151  6       80      64453   1522    256

Open in new window







sample mail output :


http://prntscr.com/2dfzd6
Avatar of FishMonger
FishMonger
Flag of United States of America image

There are multiple ways to build the table and all of them require you to parse each line of your data file into the required fields for each cell in each row.

The approach I'd take would be to use the HTML::Template module.  You would need to create an html email template file.  As you parse each line of the data file putting that data into a hash which is then pushed onto an array.  That array would then be passed to the template to build your email content which is then passed to the MIME::lite object to send the email.

Doing it this way would remove all html specific code from the script which simplifies your script and its maintenance.
ASKER CERTIFIED SOLUTION
Avatar of FishMonger
FishMonger
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of 3XLcom
3XLcom

ASKER

thank you so much