This repository was archived by the owner on Jan 29, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.php
More file actions
272 lines (248 loc) · 9.85 KB
/
Copy pathinstall.php
File metadata and controls
272 lines (248 loc) · 9.85 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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
<?php
$error = "";
$info = "";
error_reporting(0);
if (checkformVar($_POST['submit'])) {
if (checkformVar($_POST['databaseserver'])
&& checkformVar($_POST['databasename'])
&& checkformVar($_POST['databaseuser'])
&& checkformVar($_POST['databasepassword'])
&& checkformVar($_POST['databaseprefix'])
&& checkformVar($_POST['loginenabled'])
&& checkformVar($_POST['registerenabled'])
&& checkformVar($_POST['needapproval'])
&& checkformVar($_POST['passwordalgorithm'])
&& checkformVar($_POST['saltlength'])
&& checkformVar($_POST['cpudifficulty'])
&& checkformVar($_POST['memdifficulty'])
&& checkformVar($_POST['parallelDifficulty'])
&& checkformVar($_POST['keylength'])
&& checkformVar($_POST['rounds'])
&& checkformVar($_POST['activationcodelength'])
&& checkformVar($_POST['sendemail'])
&& checkformVar($_POST['autologouttime'])
&& checkformVar($_POST['maxloginattempts'])
&& checkformVar($_POST['loginblocktime'])
&& checkformVar($_POST['securesessions'])) {
$error = formEvaluation();
if (empty($error))
$info = "Installation successfull";
} else
$error = "Missing information, all fields are mandatory";
}
function formEvaluation() {
$error = "";
$dbServer = $_POST['databaseserver'];
$dbName = $_POST['databasename'];
$dbUser = $_POST['databaseuser'];
$dbPassword = $_POST['databasepassword'];
$dbPrefix = $_POST['databaseprefix'];
$loginEnabled = $_POST['loginenabled'];
$registerEnabled = $_POST['registerenabled'];
$needApproval = $_POST['needapproval'];
$passwordAlgorithm = $_POST['passwordalgorithm'];
$passwordSaltLength = $_POST['saltlength'];
$passwordCpuDifficulty = $_POST['cpudifficulty'];
$passwordMemDifficulty = $_POST['memdifficulty'];
$passwordParallelDifficulty = $_POST['parallelDifficulty'];
$passwordKeyLength = $_POST['keylength'];
$passwordRounds = $_POST['rounds'];
$lengthActivationcode = $_POST['activationcodelength'];
$sendEmail = $_POST['sendemail'];
$autologouttime = $_POST['autologouttime'];
$maxLoginAttempts = $_POST['maxloginattempts'];
$loginBlockTime = $_POST['loginblocktime'];
$securesessions = $_POST['securesessions'];
$loginEnabled = convStringToBool($loginEnabled);
$registerEnabled = convStringToBool($registerEnabled);
$needApproval = convStringToBool($needApproval);
$securesessions = convStringToBool($securesessions);
if ($loginEnabled === null)
return "Login has to be enabled or disabled";
if ($registerEnabled === null)
return "Registration has to be enabled or disabled";
if ($needApproval === null)
return "The approval of new users has to be enabled or disabled";
if ($securesessions === null)
return "Securesessions has to be enabled or disabled";
if (! is_numeric($lengthActivationcode))
return "The length of the activationcode has to be numeric";
if (! is_numeric($autologouttime))
return "The auto-logout-time has to be numeric";
if (! is_numeric($maxLoginAttempts))
return "The maximum amount of failed logins has to be numeric";
if (! is_numeric($loginBlockTime))
return "The blocking time has to be numeric";
if (strlen($lengthActivationcode) < 0 || strlen($lengthActivationcode) > 50)
return "The length of the activationcode has to be between 0 and 50";
if (strlen($autologouttime) < 0)
return "The auto-logout-time has to be bigger than 0";
if (strlen($maxLoginAttempts) < 0)
return "The maximum amount of failed logins has to be bigger than 0";
if (strlen($loginBlockTime) < 0)
return "The blocking time has to be bigger than 0";
$error = createSettingFile($dbServer,
$dbName,
$dbUser,
$dbPassword,
$dbPrefix,
$loginEnabled,
$registerEnabled,
$needApproval,
$passwordAlgorithm,
$passwordSaltLength,
$passwordCpuDifficulty,
$passwordMemDifficulty,
$passwordParallelDifficulty,
$passwordKeyLength,
$passwordRounds,
$lengthActivationcode,
$sendEmail,
$autologouttime,
$maxLoginAttempts,
$loginBlockTime,
$securesessions
);
return $error;
}
function createSettingFile(
$dbServer,
$dbName,
$dbUser,
$dbPassword,
$dbPrefix,
$loginEnabled,
$registerEnabled,
$needApproval,
$passwordAlgorithm,
$passwordSaltLength,
$passwordCpuDifficulty,
$passwordMemDifficulty,
$passwordParallelDifficulty,
$passwordKeyLength,
$passwordRounds,
$lengthActivationcode,
$sendEmail,
$autologouttime,
$maxLoginAttempts,
$loginBlockTime,
$securesessions) {
$loginEnabled = convStringToBoolString($loginEnabled);
$registerEnabled = convStringToBoolString($registerEnabled);
$needApproval = convStringToBoolString($needApproval);
$securesessions = convStringToBoolString($securesessions);
$settingsString = <<<EOF
<?php
class UserLibrarySettings {
const DB_server = "$dbServer";
const DB_database = "$dbName";
const DB_user = "$dbUser";
const DB_password = "$dbPassword";
const DB_prefix = "$dbPrefix";
const login_enabled = $loginEnabled;
const register_enabled = $registerEnabled;
const need_approval = $needApproval;
const password_algorithm = '$passwordAlgorithm';
const password_salt_length = $passwordSaltLength;
const password_cpu_difficulty = $passwordCpuDifficulty;
const password_mem_difficulty = $passwordMemDifficulty;
const password_parallel_difficulty = $passwordParallelDifficulty;
const password_key_length = $passwordKeyLength;
const password_rounds = $passwordRounds;
const length_activationcode = $lengthActivationcode;
const send_mailaddress = "$sendEmail";
const autologouttime = $autologouttime;
const maxloginattempts = $maxLoginAttempts;
const loginblocktime = $loginBlockTime;
const securesessions = $securesessions;
}
?>
EOF;
$file = "data/settings.php";
$numberOfBytes = file_put_contents($file, $settingsString);
if ($numberOfBytes === false) {
return "Error when trying to write settings.php. Please check the file permissions";
}
}
function checkformVar(&$var) {
if (! isset($var) || empty($var))
return false;
else
return true;
}
function convStringToBoolString($bool) {
if ($bool)
return "true";
elseif (! $bool)
return "false";
}
function convStringToBool($string) {
if ($string == "Yes")
return true;
elseif ($string == "No")
return false;
else
return null;
}
?>
<!DOCTYPE html>
<html>
<head>
<title>User Library Installation Assistent</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<h1>User Library Installation Assistent (0.73)</h1>
<?php
if (! empty($error))
echo "\n<span style=\"color:red;\">Error: $error</span>\n";
if (! empty($info))
echo "\n<span style=\"color:green;\">$info</span>\n";
?>
<form action="./install.php" method="POST">
<fieldset>
<legend>Database</legend>
<table>
<tbody>
<tr><td style="text-align:right">Database Server:</td><td><input type="text" name="databaseserver" /></td></tr>
<tr><td style="text-align:right">Database Name:</td><td><input type="text" name="databasename" /></td></tr>
<tr><td style="text-align:right">Database User:</td><td><input type="text" name="databaseuser" /></td></tr>
<tr><td style="text-align:right">Database Password:</td><td><input type="password" name="databasepassword" /></td></tr>
<tr><td style="text-align:right">Table Prefix:</td><td><input type="text" name="databaseprefix" /></td></tr>
</tbody>
</table>
</fieldset>
<fieldset>
<legend>Registration/Login/Session</legend>
<table>
<tbody>
<tr><td style="text-align:right">Login enabled:</td><td><select name="loginenabled" size="1"><option>Yes</option><option>No</option></select></td></tr>
<tr><td style="text-align:right">Registration enabled:</td><td><select name="registerenabled" size="1"><option>Yes</option><option>No</option></select></td></tr>
<tr><td style="text-align:right">Users need approval:</td><td><select name="needapproval" size="1"><option>Yes</option><option>No</option></select></td></tr>
<tr><td style="text-align:right">Length of the activationcode:</td><td><input type="text" name="activationcodelength" /></td></tr>
<tr><td style="text-align:right">Mail address for sending:</td><td><input type="text" name="sendemail" /></td></tr>
<tr><td style="text-align:right">Auto-Logout-Time:</td><td><input type="text" name="autologouttime" /></td></tr>
<tr><td style="text-align:right">Maximum amount of failed logins:</td><td><input type="text" name="maxloginattempts" /></td></tr>
<tr><td style="text-align:right">Blocking time after too many failed logins:</td><td><input type="text" name="loginblocktime" /></td></tr>
<tr><td style="text-align:right">Securesessions (The IP address must not change during a session):</td><td><select name="securesessions" size="1"><option>Yes</option><option selected="selected">No</option></select></td></tr>
</tbody>
</table>
</fieldset>
<fieldset>
<legend>Password Encryption</legend>
<table>
<tbody>
<tr><td style="text-align:right">Password algorithm:</td><td><select name="passwordalgorithm"><option>scrypt<?php if (! extension_loaded("scrypt")) echo "(You have to install the php-scrypt extension before using it)"; ?></option><option>bcrypt</option></select></td></tr>
<tr><td style="text-align:right">scrypt: Salt length:</td><td><input type="text" name="saltlength" value="20" /></td></tr>
<tr><td style="text-align:right">scrypt: CPU Difficulty:</td><td><input type="text" name="cpudifficulty" value="16384" /></td></tr>
<tr><td style="text-align:right">scrypt: Mem Difficulty:</td><td><input type="text" name="memdifficulty" value="8" /></td></tr>
<tr><td style="text-align:right">scrypt: Parallel Difficulty:</td><td><input type="text" name="parallelDifficulty" value="1" /></td></tr>
<tr><td style="text-align:right">scrypt: Key Length:</td><td><input type="text" name="keylength" value="32" /></td></tr>
<tr><td style="text-align:right">bcrypt: Rounds:</td><td><input type="text" name="rounds" value="10" /></td></tr>
</tbody>
</table>
</fieldset>
<input type="submit" name="submit" value="Send" />
</form>
</body>
</html>