forked from elabftw/elabftw
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsysconfig.php
More file actions
394 lines (367 loc) · 18 KB
/
sysconfig.php
File metadata and controls
394 lines (367 loc) · 18 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
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
<?php
/********************************************************************************
* *
* Copyright 2012 Nicolas CARPi (nicolas.carpi@gmail.com) *
* http://www.elabftw.net/ *
* *
********************************************************************************/
/********************************************************************************
* This file is part of eLabFTW. *
* *
* eLabFTW is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Affero General Public License as *
* published by the Free Software Foundation, either version 3 of *
* the License, or (at your option) any later version. *
* *
* eLabFTW 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 Affero General Public License for more details. *
* *
* You should have received a copy of the GNU Affero General Public *
* License along with eLabFTW. If not, see <http://www.gnu.org/licenses/>. *
* *
********************************************************************************/
/* sysconfig.php - configuration system */
require_once 'inc/common.php';
if ($_SESSION['is_sysadmin'] != 1) {
die(_('This section is out of your reach.'));
}
$page_title = _('eLabFTW configuration');
$selected_menu = null;
require_once 'inc/head.php';
require_once 'inc/info_box.php';
$crypto = new \Elabftw\Elabftw\Crypto();
$formKey = new \Elabftw\Elabftw\FormKey();
try {
$update = new \Elabftw\Elabftw\Update();
} catch (Exception $e) {
display_message('error', $e->getMessage());
}
// if we managed to get a version from the server
if (is_object($update)) {
// display current and latest version
echo "<br><p>" . _('Installed version:') . " " . $update::INSTALLED_VERSION . " ";
// show a little green check if we have latest version
if (!$update->updateIsAvailable()) {
echo "<img src='img/check.png' width='16px' length='16px' title='latest' style='position:relative;bottom:8px' alt='OK' />";
}
// display latest version
echo "<br>" . _('Latest version:') . " " . $update->getLatestVersion() . "</p>";
// if we don't have the latest version, show button redirecting to wiki
if ($update->updateIsAvailable()) {
$message = _('A new version is available!') . " <a href='https://github.com/elabftw/elabftw/wiki/How-to-update'>
<button class='submit button'>Update elabftw</button></a>";
display_message('error', $message);
}
}
if (strlen(get_config('mail_method')) == 0) {
$message = sprintf(_('Please finalize install : %slink to documentation%s.'), "<a href='https://github.com/elabftw/elabftw/wiki/finalizing'>", "</a>");
display_message('error', $message);
}
?>
<menu>
<ul>
<li class='tabhandle' id='tab1'><?php echo _('Teams'); ?></li>
<li class='tabhandle' id='tab2'><?php echo _('Server'); ?></li>
<li class='tabhandle' id='tab3'><?php echo _('Timestamp'); ?></li>
<li class='tabhandle' id='tab4'><?php echo _('Security'); ?></li>
<li class='tabhandle' id='tab5'><?php echo _('Email'); ?></li>
<li class='tabhandle' id='tab6'><?php echo _('Logs'); ?></li>
</ul>
</menu>
<div class='divhandle' id='tab1div'>
<p>
<h3><?php echo _('Add a new team'); ?></h3>
<form method='post' action='app/admin-exec.php'>
<input required type='text' placeholder='Enter new team name' name='new_team' id='new_team' />
<button type='submit' class='submit button'>Add</button>
</form>
</p>
<p>
<h3><?php echo _('Edit existing teams'); ?></h3>
<?php
// a lil' bit of stats can't hurt
$count_sql = "SELECT
(SELECT COUNT(users.userid) FROM users WHERE users.team = :team) AS totusers,
(SELECT COUNT(items.id) FROM items WHERE items.team = :team) AS totdb,
(SELECT COUNT(experiments.id) FROM experiments WHERE experiments.team = :team) AS totxp";
$count_req = $pdo->prepare($count_sql);
$sql = "SELECT * FROM teams";
$req = $pdo->prepare($sql);
$req->execute();
while ($team = $req->fetch()) {
$count_req->bindParam(':team', $team['team_id']);
$count_req->execute();
$count = $count_req->fetch(PDO::FETCH_NAMED);
echo " <input type='text' name='edit_team_name' value='" . $team['team_name'] . "' id='team_" . $team['team_id'] . "' />";
echo " <input id='button_" . $team['team_id'] . "' onClick=\"updateTeam('" . $team['team_id'] . "')\" type='submit' class='button' value='Save' />";
echo "<p>" . _('Members') . ": " . $count['totusers'] . " − " . ngettext('Experiment', 'Experiments', $count['totxp']) . ": " . $count['totxp'] . " − " . _('Items') . ": " . $count['totdb'] . " − " . _('Created') . ": " . $team['datetime'] . "<p>";
}
?>
</p>
</div>
<!-- TAB 2 -->
<div class='divhandle' id='tab2div'>
<form method='post' action='app/admin-exec.php'>
<h3><?php echo _('Language'); ?></h3>
<select id='lang' name="lang">
<?php
$lang_array = array('en_GB', 'ca_ES', 'de_DE', 'es_ES', 'fr_FR', 'it_IT', 'pt_BR', 'zh_CN');
foreach ($lang_array as $lang) {
echo "<option ";
if ($_SESSION['prefs']['lang'] === $lang) {
echo ' selected ';
}
echo "value='" . $lang . "'>" . $lang . "</option>";
}
?>
</select>
<h3><?php echo _('Under the hood'); ?></h3>
<label for='debug'><?php echo _('Activate debug mode:'); ?></label>
<select name='debug' id='debug'>
<option value='1'<?php
if (get_config('debug') == 1) { echo " selected='selected'"; } ?>
><?php echo _('Yes'); ?></option>
<option value='0'<?php
if (get_config('debug') == 0) { echo " selected='selected'"; } ?>
><?php echo _('No'); ?></option>
</select>
<p class='smallgray'><?php echo _('Content of SESSION and COOKIES array will be displayed in the footer for admins.'); ?></p>
<label for='proxy'><?php echo _('Address of the proxy:'); ?></label>
<input type='text' value='<?php echo get_config('proxy'); ?>' name='proxy' id='proxy' />
<p class='smallgray'><?php echo _('If you are behind a firewall/proxy, enter the address here. Example : http://proxy.example.com:3128'); ?></p>
<div class='center'>
<button type='submit' name='submit_config' class='submit button'><?php echo _('Save'); ?></button>
</div>
</form>
</div>
<!-- TAB 3 -->
<div class='divhandle' id='tab3div'>
<h3><?php echo _('Timestamping configuration'); ?></h3>
<form method='post' action='app/admin-exec.php'>
<label for='stampshare'><?php echo _('The teams can use the credentials below to timestamp:'); ?></label>
<select name='stampshare' id='stampshare'>
<option value='1'<?php
if (get_config('stampshare') == 1) { echo " selected='selected'"; } ?>
><?php echo _('Yes'); ?></option>
<option value='0'<?php
if (get_config('stampshare') == 0) { echo " selected='selected'"; } ?>
><?php echo _('No'); ?></option>
</select>
<p class='smallgray'><?php echo _('You can control if the teams can use the global timestamping account. If set to <em>no</em> the team admin must add login infos in the admin panel.'); ?></p>
<p>
<label for='stampprovider'><?php echo _('URL for external timestamping service:'); ?></label>
<input type='url' placeholder='https://ws.universign.eu/tsa' value='<?php echo get_config('stampprovider'); ?>' name='stampprovider' id='stampprovider' />
<span class='smallgray'><?php printf(_('This should be the URL used for %sRFC 3161%s-compliant timestamping requests.'), "<a href='https://tools.ietf.org/html/rfc3161'>", "</a>"); ?></span>
</p>
<p>
<label for='stampcert'><?php echo _('Chain of certificates of the external timestamping service:'); ?></label>
<input type='text' placeholder='vendor/universign-tsa-root.pem' value='<?php echo get_config('stampcert'); ?>' name='stampcert' id='stampcert' />
<span class='smallgray'><?php printf(_('This should point to the chain of certificates used by your external timestamping provider to sign the timestamps.%sLocal path relative to eLabFTW installation directory. The file needs to be in %sPEM-encoded (ASCII)%s format!'), "<br>", "<a href='https://en.wikipedia.org/wiki/Privacy-enhanced_Electronic_Mail'>", "</a>"); ?></span>
</p>
<label for='stamplogin'><?php echo _('Login for external timestamping service:'); ?></label>
<input type='text' value='<?php echo get_config('stamplogin'); ?>' name='stamplogin' id='stamplogin' />
<p class='smallgray'><?php echo _('Login for external timestamping service:'); ?></p>
<label for='stamppass'><?php echo _('Password for external timestamping service:'); ?></label>
<input type='password' value='<?php echo $crypto->decrypt(get_config('stamppass')); ?>' name='stamppass' id='stamppass' />
<div class='center'>
<button type='submit' name='submit_config' class='submit button'><?php echo _('Save'); ?></button>
</div>
</form>
</div>
<!-- TAB 4 -->
<div class='divhandle' id='tab4div'>
<h3><?php echo _('Security settings'); ?></h3>
<form method='post' action='app/admin-exec.php'>
<label for='admin_validate'><?php echo _('Users need validation by admin after registration:'); ?></label>
<select name='admin_validate' id='admin_validate'>
<option value='1'<?php
if (get_config('admin_validate') == 1) { echo " selected='selected'"; } ?>
><?php echo _('Yes'); ?></option>
<option value='0'<?php
if (get_config('admin_validate') == 0) { echo " selected='selected'"; } ?>
><?php echo _('No'); ?></option>
</select>
<p class='smallgray'><?php echo _('Set to yes for added security.'); ?></p>
<label for='login_tries'><?php echo _('Number of allowed login attempts:'); ?></label>
<input type='text' value='<?php echo get_config('login_tries'); ?>' name='login_tries' id='login_tries' />
<p class='smallgray'><?php echo _('3 might be too few. See for yourself :)'); ?></p>
<label for='ban_time'><?php echo _('Time of the ban after failed login attempts (in minutes:'); ?></label>
<input type='text' value='<?php echo get_config('ban_time'); ?>' name='ban_time' id='ban_time' />
<p class='smallgray'><?php echo _('To identify an user we use an md5 of user agent + IP. Because doing it only based on IP address would surely cause problems.'); ?></p>
<div class='center'>
<button type='submit' name='submit_config' class='submit button'><?php echo _('Save'); ?></button>
</div>
</form>
</div>
<!-- TAB 5 -->
<div class='divhandle' id='tab5div'>
<h3><?php echo _('E-mail settings'); ?></h3>
<?php
$mail_method = get_config('mail_method');
switch ($mail_method) {
case 'sendmail':
$disable_sendmail = false;
$disable_smtp = true;
$disable_php = true;
break;
case 'smtp':
$disable_sendmail = true;
$disable_smtp = false;
$disable_php = true;
break;
case 'php':
$disable_sendmail = true;
$disable_smtp = true;
$disable_php = false;
break;
default:
$disable_sendmail = true;
$disable_smtp = true;
$disable_php = true;
} ?>
<form method='post' action='app/admin-exec.php'>
<p><?php echo _("Without a valid way to send emails users won't be able to reset their password. It is recommended to create a specific Mandrill.com (or gmail account and add the infos here."); ?></p>
<p>
<label for='mail_method'><?php echo _('Send e-mails via:'); ?></label>
<select onchange='toggleMailMethod($("#toggle_main_method").val())' name='mail_method' id='toggle_main_method'>
<option value=''><?php echo _('Select mailing method...'); ?></option>
<option value='sendmail' <?php if (!$disable_sendmail) {
echo 'selected="selected"';
}
?>><?php echo _('Local MTA (default)'); ?></option>
<option value='smtp' <?php if (!$disable_smtp) {
echo 'selected="selected"';
}
?>><?php echo _('SMTP'); ?></option>
<option value='php' <?php if (!$disable_php) {
echo 'selected="selected"';
}
?>><?php echo _('PHP'); ?></option>
</select>
</p>
<div id='general_mail_config'>
<p>
<label for='mail_from'><?php echo _('Sender address:'); ?></label>
<input type='text' value='<?php echo get_config('mail_from'); ?>' name='mail_from' id='mail_from' />
</p>
</div>
<div id='sendmail_config'>
<p>
<label for='sendmail_path'><?php echo _('Path to sendmail:'); ?></label>
<input type='text' placeholder='/usr/bin/sendmail' value='<?php echo get_config('sendmail_path'); ?>' name='sendmail_path' id='sendmail_path' />
</p>
</div>
<div id='smtp_config'>
<p>
<label for='smtp_address'><?php echo _('Address of the SMTP server:'); ?></label>
<input type='text' value='<?php echo get_config('smtp_address'); ?>' name='smtp_address' id='smtp_address' />
</p>
<p>
<span class='smallgray'>smtp.mandrillapp.com</span>
<label for='smtp_encryption'><?php echo _('SMTP encryption (can be TLS or STARTSSL):'); ?></label>
<input type='text' value='<?php echo get_config('smtp_encryption'); ?>' name='smtp_encryption' id='smtp_encryption' />
</p>
<p>
<span class='smallgray'><?php echo _('Probably TLS'); ?></span>
<label for='smtp_port'><?php echo _('SMTP Port:'); ?></label>
<input type='text' value='<?php echo get_config('smtp_port'); ?>' name='smtp_port' id='smtp_port' />
</p>
<p>
<span class='smallgray'><?php echo _('Default is 587.'); ?></span>
<label for='smtp_username'><?php echo _('SMTP username:'); ?></label>
<input type='text' value='<?php echo get_config('smtp_username'); ?>' name='smtp_username' id='smtp_username' />
</p>
<p>
<label for='smtp_password'><?php echo _('SMTP password'); ?></label>
<input type='password' value='<?php echo $crypto->decrypt(get_config('smtp_password')); ?>' name='smtp_password' id='smtp_password' />
</p>
</div>
<div class='center'>
<button type='submit' name='submit_config' class='submit button'><?php echo _('Save'); ?></button>
</div>
</form>
</div>
<!-- TAB 6 -->
<div class='divhandle' id='tab6div'>
<div class='well'>
<ul>
<?php
$sql = "SELECT * FROM logs ORDER BY id DESC LIMIT 100";
$req = $pdo->prepare($sql);
$req->execute();
while ($logs = $req->fetch()) {
echo "<li>" . $logs['datetime'] . " [" . $logs['type'] . "] " . $logs['body'] . " (" . $logs['user'] . ")</li>";
}
?>
</ul>
</div>
</div>
<script>
// we need to add this otherwise the button will stay disabled with the browser's cache (Firefox)
var input_list = document.getElementsByTagName('input');
for (var i=0; i < input_list.length; i++) {
var input = input_list[i];
input.disabled = false;
}
// honor already saved mail_method setting and hide unused options accordingly
toggleMailMethod(<?php echo json_encode($mail_method); ?>);
// called when mail_method selector is changed; enables/disables the config for the selected/unselected method
function toggleMailMethod(value) {
if (value == 'sendmail') {
$('#smtp_config').hide();
$('#sendmail_config').show();
} else if (value == 'smtp') {
$('#smtp_config').show();
$('#sendmail_config').hide();
} else if (value == 'php') {
$('#smtp_config').hide();
$('#sendmail_config').hide();
$('#general_mail_config').show();
} else {
$('#smtp_config').hide();
$('#sendmail_config').hide();
$('#general_mail_config').hide();
}
}
function updateTeam(team_id) {
var new_team_name = document.getElementById('team_'+team_id).value;
var jqxhr = $.ajax({
type: "POST",
url: "app/quicksave.php",
data: {
id : team_id,
team_name : new_team_name,
}
}).done(function() {
document.getElementById('button_'+team_id).value = '<?php echo _('Saved')?>';
document.getElementById('button_'+team_id).disabled = true;
});
}
$(document).ready(function() {
// TABS
// get the tab=X parameter in the url
var params = getGetParameters();
var tab = parseInt(params['tab']);
if (!isInt(tab)) {
var tab = 1;
}
var initdiv = '#tab' + tab + 'div';
var inittab = '#tab' + tab;
// init
$(".divhandle").hide();
$(initdiv).show();
$(inittab).addClass('selected');
$(".tabhandle" ).click(function(event) {
var tabhandle = '#' + event.target.id;
var divhandle = '#' + event.target.id + 'div';
$(".divhandle").hide();
$(divhandle).show();
$(".tabhandle").removeClass('selected');
$(tabhandle).addClass('selected');
});
// END TABS
});
</script>
<?php require_once 'inc/footer.php';