Parsing PCAP file into XML file using Perl - php

I'm trying to get Perl to read an offline pcap file and save the output into XML file so I can work with it in PHP.
I can't use PHP because its not my server but I can Perl. So my aim is to convert the PCAP file into XML so I have fun with it.
I have no idea where to start and have looked at the Perl Net::Pcap but I just don't understand the language.
Any ideas on what I should do?
Thank-you
Paul

Using Net::Pcap is a decent idea, although figuring out the format you'd want to write out the capture in doesn't seem all that easy. My favourite solution would be to use tshark (the command line version of wireshark) like so:
tshark -r $dmp_filename -Tpsml
This would give you the output in a XML standard format.
Of course if you don't have tshark, not very helpful...

Related

PHP - Syntax of exec() function to call another php file

This question is in reference to:
Free (preferably) PHP RTF to HTML converter?
I'm trying to execute that last line of code in my php:
exec(rtf2htm file.rtf file.html)
I understand what parameters need to go within the parentheses, I just do not know how to write it. I've looked at multiple examples along with the php documentation and still I remain confused, so could someone show me how it is written? rtf2htm refers to a PHP file which converts RTF to HTML.
Ultimately what I am trying to do is convert the content of numerous RTF docs to HTML, maintaining the formatting, while not creating tags such as<head> or <body> which programs like Word or TextEdit generate when converting to HTML.
rtf2htm is not a php script, it is a program installed on the server. exec() is used to call external applications.
EDIT: After looking up this script, it seems that it is indeed a php script. But it has been coded to be usable from the command line only.
This should work:
<?php
exec('php /path/to/rtf2htm /path/to/source.rtf /path/to/output.html');
?>

A way to return XML output from a PHP shell_exec?

I need to be able to run the Linux find command from a PHP program, and want to be able to have it return the output of the find as an XML. Is this possible to do? I want to be able to do this so I can easily find the parent (directory) for each child (file). Or is there a better way to do this? Thanks!
You wouldn't get the output from the find command as xml, it will just return text (as it only ever should).
your best bet would probably to create the xml you want from the text that is returned when you use exec to run find.
example sudo code:
get all info you want to find: exec(find);
create barebones xml string;
create xml object ("i'd use simplexml in this example");
simplexml->addchild(info found from exec find);
sorry for only sudo code, couldn't write anything up in my current situtation
Helpful refenece if you don't know about simplexml:
http://us3.php.net/manual/en/book.simplexml.php

Why do I see `á` instead of a space when writing to screen (encoding problem)?

I am completely lost with encoding issues, I have no idea what's going on, what the problem is exactly and how to fix it.
Basically I'm just trying to read an HTML file from a Zip file, parse it then output pieces to XML. Now something funky is happening with the text I get out of the parser.
When parsing the HTML, instead of a space I get á only if I write to the screen. If I keep it in a variable and write to a file it looks fine in the file. However even though it looks right in the XML something is wrong with it, my PHP parser can't parse that XML nor does IE seem to like it.
I had to first mb_convert_encoding($xmlcontent, "ASCII"); so I could get that XML to parse in PHP.
Any idea what my problem is?
extract HTML from a .tar.gz file using Perl
my $tar = Archive::Tar->new;
$tar->read("myfile.tar.gz");
$tar->extract_file('index.html', 'output.html');
load HTML, this is where it starts to get funky, I get output like Numberáofásourceálines
my $tree = HTML::TreeBuilder->new;
$tree->parse_file('output.html') or die $!;
$tree->elementify;
write to XML
my $output = new IO::File(">output.xml");
my $writer = new XML::Writer(OUTPUT => $output, DATA_MODE => 1,DATA_INDENT => 2);
If it looks correct when you write it to a file and wrong when you write it to the terminal, it sounds like your terminal is expecting the wrong encoding. Check your terminal settings.'
Also, see Jon Rockway's answer to "Why does modern Perl avoid UTF-8 by default?". With encodings, you have to convert your input to the correct encoding and convert your output to the correct encoding. Everything that looks at the data needs to know which encoding you're using.
I think I just fixed it by processing this on the html before parsing it, thanks for all the great pointers!
s/\&nbsp\;/ /g;

rtf format to pdf

Is there any way to convert rtf format to pdf using PHP?
Thanks
If you want to stick with pure PHP, you can probably use HTML as an intermediary:
Convert RTF to HTML
http://freshmeat.net/projects/rtf2htm/ , http://www.phpclasses.org/package/1930-PHP-RTF-to-HTML-converter-with-latin-character-support.html
Optionally: clean up the HTML
http://htmlpurifier.org/
Convert HTML to PDF
http://dompdf.github.io/
You can use OpenOffice command line interface for that. Check my answer to a similar question.
Ted is the tool you're looking for. Ted brings also a script called rtf2pdf.sh you can execute by PHP to create a PDF file.
You should try out livedocx livedocx.com . The latest Zend Framework 1.10 has a ready built module to help you out. You can read more about it at this place http://www.phpfreaks.com/tutorial/template-based-document-generation-using-livedocx-and-zend-framework

How can I convert PHP Code Sniffer XML report into HTML?

Can you suggest some method of converting PHP Code Sniffer XML report into HTML page(s). I guess I might need some XSLT translation… Thanks in advance for the advice.
Few days ago I posted XSLT stylesheet on my blog: http://phpdojo.blogspot.com/2010/12/converting-phpcodesniffer-xml-report.html including new type of report: xsl.
Just to add: If you run phpcs through Jenkins, then you can output the report in 'checkstyle' format.
phpcs --report=checkstyle --report-file=/phpcs/out.xml
Then configure your Jenkins job to parse the output using that file.
Here's the plugin:
https://wiki.jenkins-ci.org/display/JENKINS/Checkstyle+Plugin
Here's some output samples:
XSLT is quite cumbersome to write, very few people I know can do it well; you can instead parse the XML in a PHP script and spit out HTML.
CodeSniffer can also output its report as a CSV file - if that's easier for you to parse, use that instead.

Categories