Minor improvements (#1307)

* Minor improvements

* Updated

* Update Attach.php

* Update posting_attachments.php

* Update change_tor_status.php

* Updated
This commit is contained in:
Roman Kelesidis 2024-01-05 00:20:51 +07:00 committed by GitHub
commit f456c827d7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 28 deletions

View file

@ -13,13 +13,15 @@ if (!defined('IN_AJAX')) {
global $userdata, $bb_cfg, $lang; global $userdata, $bb_cfg, $lang;
if (!isset($this->request['attach_id'])) { if (!$attach_id = (int)$this->request['attach_id']) {
$this->ajax_die($lang['EMPTY_ATTACH_ID']); $this->ajax_die($lang['EMPTY_ATTACH_ID']);
} }
$attach_id = (int)$this->request['attach_id']; if (!$mode = (string)$this->request['mode']) {
$mode = (string)$this->request['mode']; $this->ajax_die('invalid mode (empty)');
}
$comment = false;
if ($bb_cfg['tor_comment']) { if ($bb_cfg['tor_comment']) {
$comment = (string)$this->request['comment']; $comment = (string)$this->request['comment'];
} }
@ -117,6 +119,9 @@ switch ($mode) {
send_pm($tor['checked_user_id'], $subject, $message, $userdata['user_id']); send_pm($tor['checked_user_id'], $subject, $message, $userdata['user_id']);
\TorrentPier\Sessions::cache_rm_user_sessions($tor['checked_user_id']); \TorrentPier\Sessions::cache_rm_user_sessions($tor['checked_user_id']);
break; break;
default:
$this->ajax_die('Invalid mode: ' . $mode);
} }
$this->response['attach_id'] = $attach_id; $this->response['attach_id'] = $attach_id;

View file

@ -11,11 +11,9 @@ if (!defined('BB_ROOT')) {
die(basename(__FILE__)); die(basename(__FILE__));
} }
define('FILENAME_PREFIX', false); define('FILENAME_PREFIX', true);
define('FILENAME_PREFIX_LENGTH', 6); define('FILENAME_PREFIX_LENGTH', 6);
define('FILENAME_MAX_LENGTH', 180); define('FILENAME_MAX_LENGTH', 128);
define('FILENAME_CRYPTIC', false);
define('FILENAME_CRYPTIC_LENGTH', 64);
/** /**
* Entry Point * Entry Point

View file

@ -845,23 +845,17 @@ class Attach
//bt end //bt end
// Upload File // Upload File
$this->thumbnail = 0; $this->thumbnail = 0;
if (!$error) { if (!$error) {
//
// Prepare Values // Prepare Values
$this->filetime = TIMENOW; $this->filetime = TIMENOW;
$this->filename = $r_file; $this->filename = $r_file;
// physical filename // physical filename
$this->attach_filename = $this->filename; $this->attach_filename = $this->filename;
//bt //bt
if (FILENAME_CRYPTIC) {
$this->attach_filename = make_rand_str(FILENAME_CRYPTIC_LENGTH);
} else {
$this->attach_filename = html_entity_decode(trim(stripslashes($this->attach_filename))); $this->attach_filename = html_entity_decode(trim(stripslashes($this->attach_filename)));
$this->attach_filename = pathinfo($this->attach_filename, PATHINFO_FILENAME); $this->attach_filename = pathinfo($this->attach_filename, PATHINFO_FILENAME);
$this->attach_filename = str_replace([' ', '-'], '_', $this->attach_filename); $this->attach_filename = str_replace([' ', '-'], '_', $this->attach_filename);
@ -873,13 +867,12 @@ class Attach
$this->attach_filename = rawurlencode($this->attach_filename); $this->attach_filename = rawurlencode($this->attach_filename);
$this->attach_filename = preg_replace("/(%[0-9A-F]{1,2})/i", '', $this->attach_filename); $this->attach_filename = preg_replace("/(%[0-9A-F]{1,2})/i", '', $this->attach_filename);
$this->attach_filename = trim($this->attach_filename . '_' . make_rand_str(13)); $this->attach_filename = trim($this->attach_filename . '_' . make_rand_str(13));
}
$this->attach_filename = str_replace(['&', '&', ' '], '_', $this->attach_filename); $this->attach_filename = str_replace(['&', '&', ' '], '_', $this->attach_filename);
$this->attach_filename = str_replace('php', '_php_', $this->attach_filename); $this->attach_filename = str_replace('php', '_php_', $this->attach_filename);
$this->attach_filename = substr(trim($this->attach_filename), 0, FILENAME_MAX_LENGTH);
$new_physical_filename = null;
for ($i = 0, $max_try = 5; $i <= $max_try; $i++) { for ($i = 0, $max_try = 5; $i <= $max_try; $i++) {
$fn_prefix = make_rand_str(FILENAME_PREFIX_LENGTH) . '_'; $fn_prefix = FILENAME_PREFIX ? (make_rand_str(FILENAME_PREFIX_LENGTH) . '_') : '';
$new_physical_filename = clean_filename($fn_prefix . $this->attach_filename); $new_physical_filename = clean_filename($fn_prefix . $this->attach_filename);
if (!physical_filename_already_stored($new_physical_filename)) { if (!physical_filename_already_stored($new_physical_filename)) {
@ -888,8 +881,11 @@ class Attach
if ($i === $max_try) { if ($i === $max_try) {
bb_die('Could not create filename for attachment'); bb_die('Could not create filename for attachment');
} }
}
$this->attach_filename = $new_physical_filename; $this->attach_filename = $new_physical_filename;
if (!empty($this->attach_filename)) {
$this->attach_filename = substr(trim($this->attach_filename), 0, FILENAME_MAX_LENGTH);
} }
// Do we have to create a thumbnail ? // Do we have to create a thumbnail ?