Packet Storm ATOM Feed

Written by Tully on March 4, 2010 Categories: PHP Tags: , , , ,

I was searching around Packet Storm today and wanted to add there new files as a RSS/ATOM feed on my browser. I didn’t find a link for this, so I created one in PHP. Below is the code that creates the atom.xml file.

Click Here To View


<?php
/*
* Connects to packstormsecurity.org and created a
* atom feed of the last 20 uploaded files.
*
* @requires php-curl php-tidy
* @author Tully Rankin
* @url    http://www.TullyRankin.com
*/
$ch = curl_init();
$url = 'http://www.packetstormsecurity.org/last20.html';
$site = 'http://www.packetstormsecurity.org';
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($ch);
curl_close($ch);

$tidy_config = array(
‘clean’ => true,
‘output-xhtml’ => true,
‘show-body-only’ => false,
‘wrap’ => 0
);
$tidy = tidy_parse_string($data, $tidy_config, ‘UTF8′);
$tidy->cleanRepair();
$xhtml = preg_replace(‘/<spacer.*>/’,,$tidy);

$xml = new DOMDocument();
$xml->loadHTML($xhtml);

$body = $xml->getElementsByTagName(“body”)->item(0);
$links = $body->getElementsByTagName(“a”);
$x = 0;
foreach(
$links as $link)
{
if (
$link->getAttribute(“class”) == “fname”)
{
$files[$x]['name'] = $link->nodeValue;
$files[$x]['link'] = $link->getAttribute(“href”);
$x++;
}
}

$tables = $body->getElementsByTagName
style=”color: #007700″>(
“table”);
foreach (
$tables as $table)
{
if (
$table->getAttribute(“class”) != “fbox2″) continue;
$tRows = $table->getElementsByTagName(“tr”);
foreach(
$tRows as $row)
{
if (
$row->getAttribute(“class”) == “finfo”)
{
if (
$row->getElementsByTagName(“td”)->item(1) != null &&
$row->getElementsByTagName(“td”)->item(1)->getAttribute(“valign”) == “top”)
{
$td = $row->getElementsByTagName(“td”)->item(1);
$text[] = $td->nodeValue;
}
}
}
}

$x = 0;
$fileNames = array();
foreach (
$files as $file)
{
if (
substr($file['link'],0,1) == “/”)
{
$content[$x]['name'] = $file['name'];
$content[$x]['link'] = $site.$file['link'];
$content[$x]['text'] = $text[$x];
$x++;
}
}

$result = ‘<?xml version=”1.0″ encoding=”utf-8″?>
<feed xmlns=”http://www.w3.org/2005/Atom”>
<title>PacketStorm Security</title>
<link rel=”alternate” type=”text/html” href=”http://www.tullyrankin.com/” />
<link rel=”self” type=”application/atom+xml” href=”http://www.tullyrankin.com/atom.xml” />
<id></id>
<updated>2010-03-03</updated>
<subtitle>Security Feed</subtitle>
;
foreach (
$content as $node)
{
$result .= “<entry>”;

$result .= “<title>{$node['name']}</title>”;
$result .= “<link href=”{$node['link']}” />”;
$result .= “<summary>{$node['text']}</summary>”;
$result .= “</entry>”;
}
$result .= “</feed>”;

$conn = @fopen(‘packetstorm.xml’,‘w+’);

if (@fwrite($conn, $result) === false)
{
die(
‘<h1>Could Not create feed</h1>’);

}
else
{
echo ‘<h1>Created new packetstorm.xml file!</h1>’;
}
fclose($conn);

No Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>