forked from Krisseck/Detect-CMS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDetect-CMS.php
More file actions
103 lines (57 loc) · 1.65 KB
/
Detect-CMS.php
File metadata and controls
103 lines (57 loc) · 1.65 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<?php
class DetectCMS {
public $systems = array("Drupal","Wordpress","Joomla");
private $common_methods = array("generator_header","generator_meta");
protected $home_html = "";
protected $home_headers = array();
public function check($url) {
/*
* Common, easy way first: check for Generator metatags or Generator headers
*/
$this->home_html = $this->fetch($url);
$this->home_headers = $this->fetchHeaders($url);
foreach($this->systems as $system_name) {
require_once(dirname(__FILE__)."/systems/".$system_name.".php");
$system = new $system_name();
foreach($this->common_methods as $method) {
if($system->$method()) {
return $system_name;
}
}
}
/*
* Didn't find it yet, let's just use regular tricks
*/
foreach($this->systems as $system_name) {
require_once(dirname(__FILE__)."/systems/".$system_name.".php");
$system = new $system_name();
foreach($system->methods as $method) {
if(!in_array($method,$this->common_methods)) {
if($system->$method($url)) {
return $system_name;
}
}
}
}
return FALSE;
}
protected function fetch($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 60);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
$return = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if($httpCode == 404) {
curl_close($ch);
return FALSE;
}
curl_close($ch);
return $return;
}
protected function fetchHeaders($url) {
return get_headers($url);
}
}