forked from merlinthemagic/MTS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMtsSetup.php
122 lines (97 loc) · 3.61 KB
/
MtsSetup.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
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
<?php
//© 2016 Martin Madsen
ini_set('max_execution_time', 120);
if (php_sapi_name() == "cli") {
//if run from the CLI
$mtsPath = trim(realpath(dirname(__FILE__))) . DIRECTORY_SEPARATOR . "MTS";;
$mtsInclude = $mtsPath . DIRECTORY_SEPARATOR . "EnableMTS.php";
require_once $mtsInclude;
$setupClass = new \MTS\Common\Devices\Actions\Local\Host\MtsSetup\SetupMTS();
echo "\nWe do not know which user you intend to execute the scripts with\n";
echo "All example commands use '".$setupClass->getRunUser()."' as the user, please replace with\n";
echo "the username you intent to use.\n\n\n";
$results = array_reverse($setupClass->getInstall());
foreach ($results as $result) {
echo strtoupper($result["msgHead"]);
echo "\n";
echo implode("\n", $result["msgLines"]);
echo "\n\n\n";
}
exit;
//end of cli version
} else {
//start Web version
$pathForm = '<!-- © 2016 Martin Madsen -->
<form name="setPath" method="post" action="" >
<center>
<table>
<tr>
<td><b>Absolute Path to the directory that holds the MTS folder:</b></td>
<td width="300"><input type="text" id="mtsBasePath" name="mtsBasePath" size="60"/></td>
<td> <input type="Submit" value="Setup" /></td>
</tr>
</table>
</center>
</form>
';
echo $pathForm;
//fill the mtsBasePath input box again
if (array_key_exists('mtsBasePath', $_POST) === true && strlen($_POST['mtsBasePath']) > 0) {
$mtsBasePath = trim($_POST['mtsBasePath']);
$mtsBasePath = rtrim($mtsBasePath, DIRECTORY_SEPARATOR);
echo "<script>document.getElementById('mtsBasePath').value = '".$mtsBasePath."';</script>";
} else {
$mtsBasePath = trim(realpath(dirname(__FILE__)));
$mtsBasePath = rtrim($mtsBasePath, DIRECTORY_SEPARATOR);
echo "<script>document.getElementById('mtsBasePath').value = '".$mtsBasePath."';</script>";
}
$baseExists = file_exists($mtsBasePath);
if ($baseExists === true) {
$mtsPath = $mtsBasePath . DIRECTORY_SEPARATOR . "MTS";
$mtsPathExists = file_exists($mtsPath);
if ($mtsPathExists === false) {
echo "<br><center><font color='#FF0000'><h2>The base path you specified exists, however it does not have a directory named 'MTS' inside</h2></center><br>";
//exit we must have a base path
exit;
}
} else {
echo "<br><center><font color='#FF0000'><h2>The base path you specified does not exist</h2></center><br>";
//exit we must have a base path
exit;
}
error_reporting(E_ALL);
ini_set('display_errors', true);
$mtsInclude = $mtsPath . DIRECTORY_SEPARATOR . "EnableMTS.php";
require_once $mtsInclude;
$setupClass = new \MTS\Common\Devices\Actions\Local\Host\MtsSetup\SetupMTS();
$results = array_reverse($setupClass->getInstall());
echo "<center>
<table border=1>
";
foreach ($results as $result) {
if (strtolower($result["errorLevel"]) == "error") {
$color = "FF0000";
} elseif (strtolower($result["errorLevel"]) == "warning") {
$color = "FFFF00";
} elseif (strtolower($result["errorLevel"]) == "info") {
$color = "7FFF00";
} else {
$color = "66CD00";
}
echo "<tr>";
echo "<th width='800' bgcolor='#".$color."'>".$result["msgHead"]."</th>";
echo "</tr>";
echo "<tr>";
echo "<td bgcolor='#".$color."'>" . implode("<br>", $result["msgLines"]) . "</th>";
echo "</tr>";
}
echo "</table>
</center>
<br><br>
";
exit;
//end of web version
}
?>
<!-- PHP not installed or module not loaded in webserver -->
<center><H3>PHP NOT INSTALLED</H3></center>