-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcrawler.php
49 lines (41 loc) · 1.48 KB
/
crawler.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
require_once('config.php');
require_once('parse.php');
require_once __DIR__.'/vendor/autoload.php';
use Goutte\Client;
use Doctrine\ORM\Tools\Setup;
use Doctrine\ORM\EntityManager;
$config = Setup::createAnnotationMetadataConfiguration(array(__DIR__), true);
$entityManager = EntityManager::create($dbParams, $config);
$cve_list_base_url = 'https://www.drupal.org/security/contrib?page=';
// Find the total number of pages to crawl.
$client = new Client();
$crawler = $client->request('GET', $cve_list_base_url . '0');
$body = $crawler->html();
if (preg_match('~href="/security/contrib\?page=(\d+)">last~', $body, $matches)) {
$total_pages = $matches[1];
} else {
die("Cannot determine total pages to crawl.");
}
// Crawl the page listings and parse the CVE's.
for ($page = 0; $page <= $total_pages; $page++) {
$client = new Client();
$crawler = $client->request('GET', $cve_list_base_url . $page);
$body = $crawler->html();
$cve_urls = parse_cve_list($body);
foreach ($cve_urls as $url) {
echo "Processing: {$url}\r\n";
$crawler = $client->request('GET', $url);
$body = $crawler->html();
$u = parse_cve($body);
if (!empty($u)) {
$u['advisory_url'] = $url; // Keep track of the advisory_url
$conn = $entityManager->getConnection();
try {
$conn->insert('cve', $u);
} catch (Doctrine\DBAL\Exception\UniqueConstraintViolationException $e) {
$conn->update('cve', $u, array('advisory_id' => $u['advisory_id']));
}
}
}
}