-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathLatchInstall.php
More file actions
127 lines (109 loc) · 4.55 KB
/
LatchInstall.php
File metadata and controls
127 lines (109 loc) · 4.55 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
<?php
/*
Latch phpMyAdmin plugin - Integrates Latch into the phpMyAdmin authentication process.
Copyright (C) 2013 Eleven Paths
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
if (file_exists("libraries/plugins/latch/LatchConfiguration.php")) {
echo "<h1>Latch is already installed.</h1>";
die();
}
echo "<h1>Latch installation started.</h1>";
echo "<ol>";
if (file_exists("index.php")) {
copy("index.php", "index.php.bak");
echo "<li> index.php backed up.</li>";
}
if (file_exists("config.inc.php")) {
copy("config.inc.php", "config.inc.php.bak");
echo "<li> config.inc.php backed up.</li>";
} else if (file_exists("config.sample.inc.php")) {
copy("config.sample.inc.php", "config.inc.php");
copy("config.inc.php", "config.inc.php.bak");
echo "<li> created config.inc.php from sample and backed up.</li>";
}
try {
copy("LatchPlugin/libraries/LatchWrapper.php", "libraries/LatchWrapper.php");
copy("LatchPlugin/libraries/LatchPersistence.php", "libraries/LatchPersistence.php");
copy("LatchPlugin/libraries/plugins/auth/AuthenticationLatch.class.php", "libraries/plugins/auth/AuthenticationLatch.class.php");
echo "<li> files copied </li>";
$src = "LatchPlugin/libraries/plugins/latch";
$dst = "libraries/plugins/latch";
$dir = opendir($src);
@mkdir($dst);
while (false !== ( $file = readdir($dir))) {
if (( $file != '.' ) && ( $file != '..' )) {
if (is_dir($src . '/' . $file)) {
recurse_copy($src . '/' . $file, $dst . '/' . $file);
} else {
copy($src . '/' . $file, $dst . '/' . $file);
}
}
}
closedir($dir);
} catch (Exception $e) {
echo "<b> there has been an error copying Latch files, please Uninstall the plugin and reinstall it. </b>";
die();
}
try {
$lineToWrite = 0;
$textToInclude = "include_once 'libraries/plugins/latch/LatchFields.php';";
$textToFind = 'main_pane_right';
$content = file("index.php");
for ($line = 0; $line < count($content); $line++) {
if (strpos($content[$line], $textToFind) !== false) {
$return = false;
$lineToWrite = --$line;
while (!$return) {
$prevLine = $content[$lineToWrite];
if (trim($prevLine) == "") {
$lineToWrite--;
} else {
$content[$lineToWrite] = $textToInclude . "\n" . $content[$lineToWrite];
file_put_contents("index.php", $content);
$return = true;
}
}
break;
echo "<li>index.php adapted. </li>";
}
}
} catch (Exception $e) {
echo "<b>there has been an error modifying index.php, please uninstall the plugin and reinstall it again. </b>";
die();
}
try {
$config = file("config.inc.php");
$auth_type = "Latch";
$auth_target = "";
for ($line = 0; $line < count($config); $line++) {
if (strpos($config[$line], '$cfg[\'Servers\'][$i][\'auth_type\']') !== false) {
$auth_ex = explode(" ", trim($config[$line]));
if ($auth_ex != null && count($auth_ex) > 0) {
$auth_target = $auth_ex[2];
$config[$line] = '$cfg[\'Servers\'][$i][\'auth_type\'] = \'Latch\';' . "\n";
$config[$line].= '$cfg[\'Servers\'][$i][\'auth_target\'] =' . $auth_target . "\n";
$config[$line].= 'include "libraries/LatchWrapper.php";' . "\n";
file_put_contents("config.inc.php", $config);
}
echo "<li>config.inc.php adapted.</li>";
break;
}
}
} catch (Exception $e) {
echo "<b>there has been an error modifying config.inc.php, please uninstall the plugin and reinstall it again. </b>";
die();
}
echo "</ol>";
echo "<h2>Latch installation completed, you may now delete this script and the LatchPlugin folder.</h2>";
?>