-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.php
326 lines (292 loc) · 11.1 KB
/
options.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
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
<?php
/**
* Options page and form.
*
* @package ProjectSend
* @subpackage Options
*/
$allowed_levels = array(9);
require_once 'bootstrap.php';
$section = ( !empty( $_GET['section'] ) ) ? $_GET['section'] : $_POST['section'];
global $flash;
switch ( $section ) {
case 'general':
$section_title = __('General options','cftp_admin');
$checkboxes = array(
'xsendfile_enable',
'footer_custom_enable',
'files_descriptions_use_ckeditor',
'use_browser_lang',
);
break;
case 'clients':
$section_title = __('Clients','cftp_admin');
$checkboxes = array(
'clients_can_register',
'clients_auto_approve',
'clients_can_upload',
'clients_can_delete_own_files',
'clients_can_set_expiration_date',
);
break;
case 'privacy':
$section_title = __('Privacy','cftp_admin');
$checkboxes = array(
'privacy_noindex_site',
'enable_landing_for_all_files',
'public_listing_page_enable',
'public_listing_logged_only',
'public_listing_show_all_files',
'public_listing_use_download_link',
);
break;
case 'email':
$section_title = __('E-mail notifications','cftp_admin');
$checkboxes = array(
'mail_copy_user_upload',
'mail_copy_client_upload',
'mail_copy_main_user',
'mail_ssl_verify_peer',
'mail_ssl_verify_peer_name',
'mail_ssl_allow_self_signed',
);
break;
case 'security':
$section_title = __('Security','cftp_admin');
$checkboxes = array(
'svg_show_as_thumbnail',
'pass_require_upper',
'pass_require_lower',
'pass_require_number',
'pass_require_special',
'recaptcha_enabled',
);
break;
case 'branding':
$section_title = __('Branding','cftp_admin');
$checkboxes = array(
);
break;
case 'external_login':
$section_title = __('External Login','cftp_admin');
$checkboxes = array(
);
break;
default:
$location = BASE_URI . 'options.php?section=general';
header("Location: $location");
exit;
break;
}
$page_title = $section_title;
$page_id = 'options';
$active_nav = 'options';
/* Logo */
$logo_file_info = generate_logo_url();
// Clear logo
if ($section == 'branding' && !empty($_GET['clear']) && $_GET['clear'] == 'logo') {
save_option('logo_filename', null);
$flash->success(__('Options updated succesfuly.', 'cftp_admin'));
$location = BASE_URI . 'options.php?section=branding';
header("Location: $location");
exit;
}
/** Form sent */
if ($_POST) {
/**
* Escape all the posted values on a single function.
* Defined on functions.php
*/
/** Values that can be empty */
$allowed_empty_values = [
'footer_custom_content',
'mail_copy_addresses',
'mail_smtp_host',
'mail_smtp_port',
'mail_smtp_user',
'mail_smtp_pass',
'recaptcha_site_key',
'recaptcha_secret_key',
'google_client_id',
'google_client_secret',
'facebook_client_id',
'facebook_client_secret',
'linkedin_client_id',
'linkedin_client_secret',
'openid_client_id',
'openid_client_secret',
'twitter_client_id',
'twitter_client_secret',
'windowslive_client_id',
'windowslive_client_secret',
'yahoo_client_id',
'yahoo_client_secret',
'oidc_identifier_url',
'ldap_signin_enabled',
'ldap_hosts',
'ldap_port',
'ldap_bind_dn',
'ldap_admin_user',
'ldap_admin_password',
'ldap_search_base',
];
foreach ($checkboxes as $checkbox) {
$_POST[$checkbox] = (empty($_POST[$checkbox]) || !isset($_POST[$checkbox])) ? 0 : 1;
}
// Remove values that should not be saved
$remove_keys = array(
'csrf_token',
);
foreach ($remove_keys as $key) {
unset($_POST[$key]);
}
$keys = array_keys($_POST);
$options_total = count($keys);
$options_filled = 0;
$query_state = '0';
/**
* Check if all the options are filled.
*/
for ($i = 0; $i < $options_total; $i++) {
if (!in_array($keys[$i], $allowed_empty_values)) {
if (empty($_POST[$keys[$i]]) && $_POST[$keys[$i]] != '0') {
$query_state = '3';
}
else {
$options_filled++;
}
}
}
/** If every option is completed, continue */
if ($query_state == '0') {
// Convert file types, they are posted as a json string via tagify
if (!empty($_POST['allowed_file_types'])) {
$_POST['allowed_file_types'] = str_replace(' ', '', implode(', ', array_column(json_decode($_POST['allowed_file_types']), 'value')));
}
// Base URI should always end with /
if (!empty($_POST['base_uri'])) {
if (substr($_POST['base_uri'], -1) != '/') { $_POST['base_uri'] .= '/'; }
}
$updated = 0;
for ($j = 0; $j < $options_total; $j++) {
$save = save_option($keys[$j], $_POST[$keys[$j]]);
if ($save) {
$updated++;
}
}
if ($updated > 0){
$query_state = '1';
}
else {
$query_state = '2';
}
}
/** If uploading a logo on the branding page */
if (isset($_FILES['select_logo']) && !empty($_FILES['select_logo'])) {
$logo = option_file_upload( $_FILES['select_logo'], 'image', 'logo_filename', 29 );
$file_status = $logo['status'];
}
/** Record the action log */
$logger = new \ProjectSend\Classes\ActionsLog;
$new_record_action = $logger->addEntry([
'action' => 47,
'owner_id' => CURRENT_USER_ID,
'owner_user' => CURRENT_USER_USERNAME,
'details' => [
'section' => $section,
],
]);
/** Redirect so the options are reflected immediatly */
while (ob_get_level()) ob_end_clean();
$section_redirect = html_output($_POST['section']);
$location = BASE_URI . 'options.php?section=' . $section_redirect;
if ( !empty( $query_state ) ) {
$location .= '&status=' . $query_state;
}
if ( !empty( $file_status ) ) {
$location .= '&file_status=' . $file_status;
}
header("Location: $location");
exit;
}
include_once ADMIN_VIEWS_DIR . DS . 'header.php';
/**
* Replace | with , to use the tags system when showing
* the allowed filetypes on the form. This value comes from
* site.options.php
*/
/** Explode, sort, and implode the values to list them alphabetically */
$allowed_file_types = explode('|',get_option('allowed_file_types'));
sort($allowed_file_types);
/** If .php files are allowed, set the flag for the warning message */
if ( in_array( 'php', $allowed_file_types ) ) {
$php_allowed_warning = true;
}
$allowed_file_types = implode(',',$allowed_file_types);
?>
<div class="row">
<div class="col-xs-12 col-sm-12 col-lg-6">
<?php
if (isset($_GET['status'])) {
switch ($_GET['status']) {
case '1':
$msg = __('Options updated succesfuly.','cftp_admin');
echo system_message('success',$msg);
break;
case '2':
$msg = __('There was an error. Please try again.','cftp_admin');
echo system_message('danger',$msg);
break;
case '3':
$msg = __('Some fields were not completed. Options could not be saved.','cftp_admin');
echo system_message('danger',$msg);
$show_options_form = 1;
break;
}
}
/** Logo uploading status */
if (isset($_GET['file_status'])) {
switch ($_GET['file_status']) {
case '1':
break;
case '2':
$msg = __('The file could not be moved to the corresponding folder.','cftp_admin');
$msg .= __("This is most likely a permissions issue. If that's the case, it can be corrected via FTP by setting the chmod value of the",'cftp_admin');
$msg .= ' '.ADMIN_UPLOADS_DIR.' ';
$msg .= __('directory to 755, or 777 as a last resource.','cftp_admin');
$msg .= __("If this doesn't solve the issue, try giving the same values to the directories above that one until it works.",'cftp_admin');
echo system_message('danger',$msg);
break;
case '3':
$msg = __('The file you selected is not an allowed format.','cftp_admin');
echo system_message('danger',$msg);
break;
case '4':
$msg = __('There was an error uploading the file. Please try again.','cftp_admin');
echo system_message('danger',$msg);
break;
}
}
?>
<div class="white-box">
<div class="white-box-interior">
<form action="options.php" name="options" id="options" method="post" enctype="multipart/form-data" class="form-horizontal">
<input type="hidden" name="csrf_token" value="<?php echo getCsrfToken(); ?>" />
<input type="hidden" name="section" value="<?php echo $section; ?>">
<?php
$form_file = FORMS_DIR . DS . 'options' . DS . $section . '.php';
if (file_exists($form_file)) {
include_once $form_file;
}
?>
<div class="options_divide"></div>
<div class="after_form_buttons">
<button type="submit" class="btn btn-wide btn-primary empty"><?php _e('Save options','cftp_admin'); ?></button>
</div>
</form>
</div>
</div>
</div>
</div>
<?php
include_once ADMIN_VIEWS_DIR . DS . 'footer.php';