-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInspector.php
91 lines (80 loc) · 3.09 KB
/
Inspector.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
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
<?php
/**
* Install_Ident
*
* PHP version 5
*
* @category Install_Ident
* @package Install_Ident
* @author Dave Holloway <dh@dajoho.com>
* @license MIT License http://www.opensource.org/licenses/mit-license.html
* @version GIT: <git_id>
* @link http://www.github.com/dajoho/Install_Ident
*/
/**
* Install_Ident_Inspector - Inspects a given configuration file and returns
* a class describing the installation.
*
* @category Install_Ident
* @package Install_Ident
* @author Dave Holloway <dh@dajoho.com>
* @license MIT License http://www.opensource.org/licenses/mit-license.html
* @version Release: <package_version>
* @link http://www.github.com/dajoho/Install_Ident
*/
class Install_Ident_Inspector
{
private $configFile;
private $idents = array(
'Joomla15' => array(
'identifier' => 'JConfig',
'pattern' => '/var \$host = \'(?P<host>.*?)\'.*var \$user = \'(?P<user>.*?)\'.*var \$db = \'(?P<db>.*?)\'.*var \$password = \'(?P<pass>.*?)\'.*/s'
),
'Joomla16' => array(
'identifier' => 'JConfig',
'pattern' => '/public \$host = \'(?P<host>.*?)\'.*public \$user = \'(?P<user>.*?)\'.*public \$password = \'(?P<pass>.*?)\'.*public \$db = \'(?P<db>.*?)\'.*/s'
),
'Mambo' => array(
'identifier' => 'mosConfig',
'pattern' => '/\$mosConfig_db = \'(?P<db>.*?)\'.*\$mosConfig_host = \'(?P<host>.*?)\'.*\$mosConfig_password = \'(?P<pass>.*?)\'.*\$mosConfig_user = \'(?P<user>.*?)\'.*/s'
)
);
public function __construct($file=null)
{
$this->configFile=$file;
}
public function inspect()
{
if ($this->configFile == null) {
return false;
}
$configuration = @file_get_contents($this->configFile);
$matches = array();
if ($configuration != '') {
$found = false;
foreach ($this->idents as $identName=>$identSettings) {
if (!$found) {
if (strpos($configuration, $identSettings['identifier']) !== false) {
preg_match($identSettings['pattern'], $configuration, $matches);
if (isset($matches['host']) && isset($matches['db']) && isset($matches['user'])) {
$found = true;
$matches['type'] = $identName;
}
}
}
}
if ($found) {
$installation = new stdClass;
$installation->path = dirname($this->configFile);
$installation->type = $matches['type'];
$installation->host = $matches['host'];
$installation->db = $matches['db'];
$installation->user = $matches['user'];
$installation->pass = $matches['pass'];
return $installation;
}
}
return false;
}
}
?>