forked from elabftw/elabftw
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsysconfig-exec.php
More file actions
183 lines (158 loc) · 5.31 KB
/
Copy pathsysconfig-exec.php
File metadata and controls
183 lines (158 loc) · 5.31 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
<?php
/**
* sysconfig-exec.php
*
* @author Nicolas CARPi <[email protected]>
* @copyright 2012 Nicolas CARPi
* @see http://www.elabftw.net Official website
* @license AGPL-3.0
* @package elabftw
*/
namespace Elabftw\Elabftw;
use Exception;
/**
* Deal with requests from sysconfig.php
*/
try {
require_once '../inc/common.php';
// only sysadmin can use this
if ($_SESSION['is_sysadmin'] != 1 || $_SERVER['REQUEST_METHOD'] != 'POST') {
throw new Exception(_('This section is out of your reach.'));
}
$crypto = new CryptoWrapper();
$tab = '1';
// TAB 2 : SERVER
if (isset($_POST['lang'])) {
$tab = '2';
if (isset($_POST['lang']) && (strlen($_POST['lang']) === 5)) {
$lang = $_POST['lang'];
} else {
$lang = 'en_GB';
}
if (isset($_POST['proxy'])) {
$proxy = filter_var($_POST['proxy'], FILTER_SANITIZE_STRING);
} else {
$proxy = '';
}
// SQL
$updates = array(
'lang' => $lang,
'proxy' => $proxy
);
if (!update_config($updates)) {
throw new Exception('Error updating config');
}
}
// END TAB 2
// TAB 3 : TIMESTAMP
if (isset($_POST['stampshare'])) {
$tab = '3';
$post_stamp = processTimestampPost();
$updates = array(
'stampprovider' => $post_stamp['stampprovider'],
'stampcert' => $post_stamp['stampcert'],
'stampshare' => $post_stamp['stampshare'],
'stamplogin' => $post_stamp['stamplogin'],
'stamppass' => $post_stamp['stamppass']
);
if (!update_config($updates)) {
throw new Exception('Error updating config');
}
} // END TAB 3
// TAB 4 : SECURITY
if (isset($_POST['admin_validate'])) {
$tab = '4';
if ($_POST['admin_validate'] == 1) {
$admin_validate = 1;
} else {
$admin_validate = 0;
}
if (isset($_POST['login_tries'])) {
$login_tries = filter_var($_POST['login_tries'], FILTER_SANITIZE_STRING);
} else {
$login_tries = '3';
}
if (isset($_POST['ban_time'])) {
$ban_time = filter_var($_POST['ban_time'], FILTER_SANITIZE_STRING);
} else {
$ban_time = '30';
}
$updates = array(
'admin_validate' => $admin_validate,
'login_tries' => $login_tries,
'ban_time' => $ban_time
);
if (!update_config($updates)) {
throw new Exception('Error updating config');
}
} // END TAB 4
// TAB 5 : EMAIL
if (isset($_POST['mail_method'])) {
$tab = '5';
// Whitelist for valid mailing methods
$valid_mail_methods = array('smtp', 'php', 'sendmail');
// Check if POST variable for mail_method is white-listed
if (in_array($_POST['mail_method'], $valid_mail_methods)) {
$mail_method = $_POST['mail_method'];
// if not, fall back to sendmail method
} else {
$mail_method = 'sendmail';
}
if (isset($_POST['sendmail_path'])) {
$sendmail_path = filter_var($_POST['sendmail_path'], FILTER_SANITIZE_STRING);
} else {
$sendmail_path = '';
}
if (isset($_POST['mail_from'])) {
$mail_from = filter_var($_POST['mail_from'], FILTER_SANITIZE_EMAIL);
} else {
$mail_from = '';
}
if (isset($_POST['smtp_address'])) {
$smtp_address = filter_var($_POST['smtp_address'], FILTER_SANITIZE_STRING);
} else {
$smtp_address = '';
}
if (isset($_POST['smtp_encryption'])) {
$smtp_encryption = filter_var($_POST['smtp_encryption'], FILTER_SANITIZE_STRING);
} else {
$smtp_encryption = '';
}
if (isset($_POST['smtp_port']) && Tools::checkId($_POST['smtp_port'])) {
$smtp_port = $_POST['smtp_port'];
} else {
$smtp_port = '';
}
if (isset($_POST['smtp_username'])) {
$smtp_username = filter_var($_POST['smtp_username'], FILTER_SANITIZE_STRING);
} else {
$smtp_username = '';
}
if (isset($_POST['smtp_password']) && !empty($_POST['smtp_password'])) {
// the password is stored encrypted in the database
$smtp_password = $crypto->encrypt($_POST['smtp_password']);
} else {
$smtp_password = '';
}
$updates = array(
'smtp_address' => $smtp_address,
'smtp_encryption' => $smtp_encryption,
'smtp_port' => $smtp_port,
'smtp_username' => $smtp_username,
'smtp_password' => $smtp_password,
'mail_method' => $mail_method,
'mail_from' => $mail_from,
'sendmail_path' => $sendmail_path
);
if (!update_config($updates)) {
throw new Exception('Error updating config');
}
} // END EMAIL
$_SESSION['ok'][] = _('Configuration updated successfully.');
} catch (Exception $e) {
$_SESSION['ko'][] = Tools::error();
$Logs = new Logs();
$Logs->create('Error', $_SESSION['userid'], $e->getMessage());
} finally {
header('Location: ../sysconfig.php?tab=' . $tab);
}