IP storage and attachment system bugfix. PHP 5.6+.

This commit is contained in:
Yuriy Pikhtarev 2017-06-12 03:31:39 +03:00
commit 8c6097f5d8
No known key found for this signature in database
GPG key ID: 3A9B5A757B48ECC6
14 changed files with 74 additions and 123 deletions

View file

@ -28,7 +28,7 @@ and go from there. The documentation will be translated into english in the near
* Apache / nginx
* MySQL / MariaDB / Percona
* PHP: 5.5 / 5.6 / 7.0 / 7.1
* PHP: 5.6 / 7.0 / 7.1
* PHP Extensions: bcmath, intl, tidy (optional)
## Installation

View file

@ -60,12 +60,8 @@ switch ($ajax->action) {
case 'view_torrent':
case 'mod_action':
case 'change_tor_status':
case 'gen_passkey':
require ATTACH_DIR . '/attachment_mod.php';
require INC_DIR . '/functions_torrent.php';
break;
case 'change_torrent':
case 'gen_passkey':
require ATTACH_DIR . '/attachment_mod.php';
require INC_DIR . '/functions_torrent.php';
break;

View file

@ -43,7 +43,7 @@ if ($t_data['seeders'] > 2) {
bb_die(sprintf($lang['CALLSEED_MSG_SPAM'], $time_left));
}
$ban_user_id = array();
$ban_user_id = [];
$sql = DB()->fetch_rowset("SELECT ban_userid FROM " . BB_BANLIST . " WHERE ban_userid != 0");

View file

@ -114,13 +114,6 @@ if (file_exists(__DIR__ . '/library/config.local.php')) {
require_once __DIR__ . '/library/config.local.php';
}
// Bugsnag error reporting
if ($bb_cfg['bugsnag']['enabled'] && !empty($bb_cfg['bugsnag']['api_key'])) {
/** @var Bugsnag\Handler $bugsnag */
$bugsnag = Bugsnag\Client::make($bb_cfg['bugsnag']['api_key']);
Bugsnag\Handler::register($bugsnag);
}
$server_protocol = $bb_cfg['cookie_secure'] ? 'https://' : 'http://';
$server_port = in_array((int)$bb_cfg['server_port'], array(80, 443), true) ? '' : ':' . $bb_cfg['server_port'];
define('FORUM_PATH', $bb_cfg['script_path']);
@ -156,12 +149,19 @@ define('GUEST_UID', -1);
define('BOT_UID', -746);
/**
* Whoops error handler
* Progressive error reporting
*/
if (DBG_USER) {
if ($bb_cfg['bugsnag']['enabled'] && !empty($bb_cfg['bugsnag']['api_key'])) {
/** @var Bugsnag\Handler $bugsnag */
$bugsnag = Bugsnag\Client::make($bb_cfg['bugsnag']['api_key']);
Bugsnag\Handler::register($bugsnag);
} else {
/** @var Whoops\Run $whoops */
$whoops = new \Whoops\Run;
$whoops->pushHandler(new \Whoops\Handler\PrettyPageHandler);
$whoops->register();
}
}
/**

View file

@ -35,11 +35,11 @@
"docs": "https://docs.torrentpier.me/"
},
"require": {
"php": "^5.5 || ^7.0",
"bugsnag/bugsnag": "^3.0",
"php": "^5.6 || ^7.0",
"bugsnag/bugsnag": "^3.5",
"filp/whoops": "^2.1",
"gigablah/sphinxphp": "^2.0",
"google/recaptcha": "^1.0",
"google/recaptcha": "^1.1",
"longman/ip-tools": "^1.2",
"roave/security-advisories": "dev-master",
"rych/bencode": "^1.0",

View file

@ -1,3 +0,0 @@
php_flag engine off
RemoveHandler .php .php5 .php4 .php3 .phtml .pl .asp
AddType text/plain .php .php .htm .html .phtml .pl .asp

View file

@ -146,7 +146,7 @@ DROP TABLE IF EXISTS `bb_banlist`;
CREATE TABLE IF NOT EXISTS `bb_banlist` (
`ban_id` MEDIUMINT(8) UNSIGNED NOT NULL AUTO_INCREMENT,
`ban_userid` MEDIUMINT(8) NOT NULL DEFAULT '0',
`ban_ip` VARCHAR(32) NOT NULL DEFAULT '',
`ban_ip` VARCHAR(42) NOT NULL DEFAULT '0',
`ban_email` VARCHAR(255) NOT NULL DEFAULT '',
PRIMARY KEY (`ban_id`),
KEY `ban_ip_user_id` (`ban_ip`, `ban_userid`)
@ -340,9 +340,7 @@ CREATE TABLE IF NOT EXISTS `bb_bt_tracker` (
`topic_id` MEDIUMINT(8) UNSIGNED NOT NULL DEFAULT '0',
`peer_id` VARCHAR(20) NOT NULL DEFAULT '0',
`user_id` MEDIUMINT(9) NOT NULL DEFAULT '0',
`ip` CHAR(8)
CHARACTER SET utf8
COLLATE utf8_bin NOT NULL DEFAULT '0',
`ip` VARCHAR(42) NOT NULL DEFAULT '0',
`ipv6` VARCHAR(32) DEFAULT NULL,
`port` SMALLINT(5) UNSIGNED NOT NULL DEFAULT '0',
`client` VARCHAR(51) NOT NULL DEFAULT 'Unknown',
@ -825,9 +823,7 @@ DROP TABLE IF EXISTS `bb_log`;
CREATE TABLE IF NOT EXISTS `bb_log` (
`log_type_id` MEDIUMINT(8) UNSIGNED NOT NULL DEFAULT '0',
`log_user_id` MEDIUMINT(9) NOT NULL DEFAULT '0',
`log_user_ip` VARCHAR(32)
CHARACTER SET utf8
COLLATE utf8_bin NOT NULL DEFAULT '',
`log_user_ip` VARCHAR(42) NOT NULL DEFAULT '0',
`log_forum_id` SMALLINT(5) UNSIGNED NOT NULL DEFAULT '0',
`log_forum_id_new` SMALLINT(5) UNSIGNED NOT NULL DEFAULT '0',
`log_topic_id` MEDIUMINT(8) UNSIGNED NOT NULL DEFAULT '0',
@ -853,7 +849,7 @@ DROP TABLE IF EXISTS `bb_poll_users`;
CREATE TABLE IF NOT EXISTS `bb_poll_users` (
`topic_id` INT(10) UNSIGNED NOT NULL,
`user_id` INT(11) NOT NULL,
`vote_ip` VARCHAR(32) NOT NULL,
`vote_ip` VARCHAR(42) NOT NULL DEFAULT '0',
`vote_dt` INT(11) NOT NULL DEFAULT '0',
PRIMARY KEY (`topic_id`, `user_id`)
)
@ -892,9 +888,7 @@ CREATE TABLE IF NOT EXISTS `bb_posts` (
`forum_id` SMALLINT(5) UNSIGNED NOT NULL DEFAULT '0',
`poster_id` MEDIUMINT(8) NOT NULL DEFAULT '0',
`post_time` INT(11) NOT NULL DEFAULT '0',
`poster_ip` CHAR(32)
CHARACTER SET utf8
COLLATE utf8_bin NOT NULL DEFAULT '',
`poster_ip` VARCHAR(42) NOT NULL DEFAULT '0',
`poster_rg_id` MEDIUMINT(8) NOT NULL DEFAULT '0',
`attach_rg_sig` TINYINT(4) NOT NULL DEFAULT '0',
`post_username` VARCHAR(25) NOT NULL DEFAULT '',
@ -983,9 +977,7 @@ CREATE TABLE IF NOT EXISTS `bb_privmsgs` (
`privmsgs_from_userid` MEDIUMINT(8) NOT NULL DEFAULT '0',
`privmsgs_to_userid` MEDIUMINT(8) NOT NULL DEFAULT '0',
`privmsgs_date` INT(11) NOT NULL DEFAULT '0',
`privmsgs_ip` VARCHAR(32)
CHARACTER SET utf8
COLLATE utf8_bin NOT NULL DEFAULT '',
`privmsgs_ip` VARCHAR(42) NOT NULL DEFAULT '0',
PRIMARY KEY (`privmsgs_id`),
KEY `privmsgs_from_userid` (`privmsgs_from_userid`),
KEY `privmsgs_to_userid` (`privmsgs_to_userid`)
@ -1114,9 +1106,7 @@ CREATE TABLE IF NOT EXISTS `bb_sessions` (
`session_user_id` MEDIUMINT(8) NOT NULL DEFAULT '0',
`session_start` INT(11) NOT NULL DEFAULT '0',
`session_time` INT(11) NOT NULL DEFAULT '0',
`session_ip` CHAR(32)
CHARACTER SET utf8
COLLATE utf8_bin NOT NULL DEFAULT '',
`session_ip` VARCHAR(42) NOT NULL DEFAULT '0',
`session_logged_in` TINYINT(1) NOT NULL DEFAULT '0',
`session_admin` TINYINT(2) NOT NULL DEFAULT '0',
PRIMARY KEY (`session_id`)
@ -1295,9 +1285,9 @@ CREATE TABLE IF NOT EXISTS `bb_users` (
COLLATE utf8_bin NOT NULL DEFAULT '',
`user_session_time` INT(11) NOT NULL DEFAULT '0',
`user_lastvisit` INT(11) NOT NULL DEFAULT '0',
`user_last_ip` CHAR(32) NOT NULL DEFAULT '',
`user_last_ip` VARCHAR(42) NOT NULL DEFAULT '0',
`user_regdate` INT(11) NOT NULL DEFAULT '0',
`user_reg_ip` CHAR(32) NOT NULL DEFAULT '',
`user_reg_ip` VARCHAR(42) NOT NULL DEFAULT '0',
`user_level` TINYINT(4) NOT NULL DEFAULT '0',
`user_posts` MEDIUMINT(8) UNSIGNED NOT NULL DEFAULT '0',
`user_timezone` DECIMAL(5, 2) NOT NULL DEFAULT '0.00',

View file

@ -1,59 +1,7 @@
Схема изменений начиная с версии 2.1 (R600):
Схема изменений начиная с версии 2.1.5:
Изменения в базе:
// 2.1.1
DROP TABLE IF EXISTS `bb_reports`;
DROP TABLE IF EXISTS `bb_reports_changes`;
DROP TABLE IF EXISTS `bb_reports_modules`;
DROP TABLE IF EXISTS `bb_reports_reasons`;
DELETE FROM `bb_config` WHERE `config_name` = 'report_subject_auth';
DELETE FROM `bb_config` WHERE `config_name` = 'report_modules_cache';
DELETE FROM `bb_config` WHERE `config_name` = 'report_hack_count';
DELETE FROM `bb_config` WHERE `config_name` = 'report_notify';
DELETE FROM `bb_config` WHERE `config_name` = 'report_list_admin';
DELETE FROM `bb_config` WHERE `config_name` = 'report_new_window';
DELETE FROM `bb_config` WHERE `config_name` = 'reports_enabled';
ALTER TABLE `bb_posts` DROP COLUMN `post_reported`;
ALTER TABLE `bb_privmsgs` DROP COLUMN `privmsgs_reported`;
ALTER TABLE `bb_topics` DROP COLUMN `topic_reported`;
DELETE FROM `bb_cron` WHERE `cron_script` = 'site_backup.php';
DELETE FROM `bb_cron` WHERE `cron_script` = 'db_backup.php';
UPDATE `bb_cron` SET `cron_script` = 'board_maintenance.php' WHERE `cron_script` = 'bb_maintenance.php';
UPDATE `bb_attachments_config` SET `config_value` = 'data/old_files' WHERE `config_name` = 'upload_dir';
UPDATE `bb_attachments_config` SET `config_value` = 'styles/images/icon_clip.gif' WHERE `config_name` = 'upload_img';
UPDATE `bb_attachments_config` SET `config_value` = 'styles/images/icon_clip.gif' WHERE `config_name` = 'topic_icon';
UPDATE `bb_config` SET `config_value` = 'styles/images/smiles' WHERE `config_name` = 'smilies_path';
// 2.1.4
ALTER TABLE `bb_bt_tracker` DROP COLUMN `ul_gdc`;
ALTER TABLE `bb_bt_tracker` DROP COLUMN `ul_gdc_c`;
ALTER TABLE `bb_bt_tracker` DROP COLUMN `ul_16k_c`;
ALTER TABLE `bb_bt_tracker` DROP COLUMN `ul_eq_dl`;
ALTER TABLE `bb_bt_torrents` CHANGE `info_hash` `info_hash` VARBINARY(20) NOT NULL DEFAULT '';
ALTER TABLE `bb_bt_torrents` CHANGE `speed_up` `speed_up` INT(11) NOT NULL DEFAULT '0';
ALTER TABLE `bb_bt_torrents` CHANGE `speed_down` `speed_down` INT(11) NOT NULL DEFAULT '0';
ALTER TABLE `bb_bt_tracker` CHANGE `peer_id` `peer_id` VARCHAR(20) NOT NULL DEFAULT '0';
UPDATE `bb_config` SET `config_value` = '180' WHERE `config_name` = 'cron_check_interval';
ALTER TABLE `bb_cron` CHANGE `run_order` `run_order` TINYINT(4) unsigned NOT NULL DEFAULT '0';
ALTER TABLE `bb_cron` CHANGE `run_interval` `run_interval` TIME DEFAULT NULL DEFAULT '0';
ALTER TABLE `bb_groups` CHANGE `group_description` `group_description` TEXT NOT NULL;
ALTER TABLE `bb_groups` CHANGE `group_signature` `group_signature` TEXT NOT NULL;
ALTER TABLE `bb_posts` CHANGE `mc_comment` `mc_comment` TEXT NOT NULL;
ALTER TABLE `bb_posts` CHANGE `mc_user_id` `mc_user_id` MEDIUMINT(8) NOT NULL DEFAULT '0';
ALTER TABLE `bb_posts_html` CHANGE `post_html` `post_html` MEDIUMTEXT NOT NULL DEFAULT '';
ALTER TABLE `bb_users` CHANGE `user_regdate` `user_regdate` INT(11) NOT NULL DEFAULT '0';
ALTER TABLE `bb_users` CHANGE `user_lang` `user_lang` VARCHAR(255) NOT NULL DEFAULT 'ru';
ALTER TABLE `bb_users` CHANGE `avatar_ext_id` `avatar_ext_id` TINYINT(4) NOT NULL DEFAULT '0';
ALTER TABLE `bb_user_group` CHANGE `user_time` `user_time` INT(11) NOT NULL DEFAULT '0';
ALTER TABLE `bb_bt_tracker` ADD `client` VARCHAR(51) NOT NULL DEFAULT 'Unknown' AFTER `port`;
ALTER TABLE `bb_bt_tracker` ADD `complete` INT(11) NOT NULL DEFAULT '0' AFTER `complete_percent`;
// 2.1.5
DROP TABLE IF EXISTS `bb_captcha`;
DELETE FROM `bb_cron` WHERE `cron_script` = 'captcha_gen_gc.php';
INSERT INTO `bb_cron` VALUES ('', '1', 'Accrual seedbonus', 'tr_seed_bonus.php', 'interval', '', '', '25', '', '', '00:15:00', '0', '', '0', '0', '0');
// 2.1.6
UPDATE `bb_config` SET `config_value` = 'http://whatismyipaddress.com/ip/' WHERE `config_name` = 'whois_info';
DELETE FROM `bb_smilies` WHERE `code` = ':ad:';
@ -62,3 +10,21 @@ DROP TABLE IF EXISTS `bb_ads`;
DELETE FROM `bb_config` WHERE `config_name` = 'active_ads';
ALTER TABLE `bb_log` DROP COLUMN `log_username`;
DELETE FROM `bb_config` WHERE `config_name` = 'new_tpls';
UPDATE `bb_posts` SET `poster_ip` = '0';
ALTER TABLE `bb_posts` CHANGE `poster_ip` `poster_ip` varchar(42) NOT NULL DEFAULT '0';
UPDATE `bb_bt_tracker` SET `ip` = '0';
ALTER TABLE `bb_bt_tracker` CHANGE `ip` `ip` varchar(42) NOT NULL DEFAULT '0';
UPDATE `bb_users` SET `user_last_ip` = '0';
ALTER TABLE `bb_users` CHANGE `user_last_ip` `user_last_ip` varchar(42) NOT NULL DEFAULT '0';
UPDATE `bb_users` SET `user_reg_ip` = '0';
ALTER TABLE `bb_users` CHANGE `user_reg_ip` `user_reg_ip` varchar(42) NOT NULL DEFAULT '0';
UPDATE `bb_log` SET `log_user_ip` = '0';
ALTER TABLE `bb_log` CHANGE `log_user_ip` `log_user_ip` varchar(42) NOT NULL DEFAULT '0';
UPDATE `bb_poll_users` SET `vote_ip` = '0';
ALTER TABLE `bb_poll_users` CHANGE `vote_ip` `vote_ip` varchar(42) NOT NULL DEFAULT '0';
UPDATE `bb_privmsgs` SET `privmsgs_ip` = '0';
ALTER TABLE `bb_privmsgs` CHANGE `privmsgs_ip` `privmsgs_ip` varchar(42) NOT NULL DEFAULT '0';
UPDATE `bb_sessions` SET `session_ip` = '0';
ALTER TABLE `bb_sessions` CHANGE `session_ip` `session_ip` varchar(42) NOT NULL DEFAULT '0';
UPDATE `bb_banlist` SET `ban_ip` = '0';
ALTER TABLE `bb_banlist` CHANGE `ban_ip` `ban_ip` varchar(42) NOT NULL DEFAULT '0';

View file

@ -127,7 +127,7 @@ function auth_unpack($auth_cache)
$one_char_encoding = '#';
$two_char_encoding = '.';
$auth = array();
$auth = [];
$auth_len = 1;
for ($pos = 0; $pos < strlen($auth_cache); $pos += $auth_len) {
@ -162,7 +162,7 @@ function is_forum_authed($auth_cache, $check_forum_id)
return true;
}
$auth = array();
$auth = [];
$auth_len = 1;
for ($pos = 0; $pos < strlen($auth_cache); $pos += $auth_len) {
@ -269,7 +269,7 @@ function get_attachments_from_post($post_id_array)
{
global $attach_config;
$attachments = array();
$attachments = [];
if (!is_array($post_id_array)) {
if (empty($post_id_array)) {
@ -278,7 +278,7 @@ function get_attachments_from_post($post_id_array)
$post_id = (int)$post_id_array;
$post_id_array = array();
$post_id_array = [];
$post_id_array[] = $post_id;
}
@ -305,7 +305,7 @@ function get_attachments_from_post($post_id_array)
DB()->sql_freeresult($result);
if ($num_rows == 0) {
return array();
return [];
}
return $attachments;
@ -358,7 +358,7 @@ function attachment_sync_topic($topics)
if (is_array($topics)) {
$topics = implode(',', $topics);
}
$posts_without_attach = $topics_without_attach = array();
$posts_without_attach = $topics_without_attach = [];
// Check orphan post_attachment markers
$sql = "SELECT p.post_id
@ -513,9 +513,10 @@ function get_var($var_name, $default, $multibyte = false)
$type = gettype($default);
$key_type = null;
} else {
list($key_type, $type) = $default;
$type = gettype($type);
foreach ($default as $key_type => $type) {
$key_type = gettype($key_type);
$type = gettype($type);
}
}
if (is_array($var)) {
@ -565,8 +566,8 @@ function attach_mod_sql_build_array($query, $assoc_ary = false)
return false;
}
$fields = array();
$values = array();
$fields = [];
$values = [];
if ($query == 'INSERT' || $query == 'INSERT_SELECT') {
foreach ($assoc_ary as $key => $var) {
$fields[] = $key;
@ -584,9 +585,9 @@ function attach_mod_sql_build_array($query, $assoc_ary = false)
$query = ($query == 'INSERT') ? ' (' . implode(', ', $fields) . ') VALUES (' . implode(', ', $values) . ')' : ' (' . implode(', ', $fields) . ') SELECT ' . implode(', ', $values) . ' ';
} elseif ($query == 'MULTI_INSERT') {
$ary = array();
$ary = [];
foreach ($assoc_ary as $id => $sql_ary) {
$values = array();
$values = [];
foreach ($sql_ary as $key => $var) {
if (null === $var) {
$values[] = 'NULL';
@ -601,7 +602,7 @@ function attach_mod_sql_build_array($query, $assoc_ary = false)
$query = ' (' . implode(', ', array_keys($assoc_ary[0])) . ') VALUES ' . implode(', ', $ary);
} elseif ($query == 'UPDATE' || $query == 'SELECT') {
$values = array();
$values = [];
foreach ($assoc_ary as $key => $var) {
if (null === $var) {
$values[] = "$key = NULL";

View file

@ -243,8 +243,8 @@ $bb_cfg['adv_email'] = "adv@$domain_name";
// Bugsnag error reporting
$bb_cfg['bugsnag'] = [
'enabled' => false,
'api_key' => '',
'enabled' => true,
'api_key' => 'ee1adc9739cfceb01ce4a450ae1e52bf',
];
// Special users

View file

@ -30,8 +30,8 @@ if (!defined('BB_ROOT')) {
/**
* Check PHP version
*/
if (version_compare(PHP_VERSION, '5.5', '<')) {
die('TorrentPier requires PHP version 5.5+. Your PHP version ' . PHP_VERSION);
if (version_compare(PHP_VERSION, '5.6', '<')) {
die('TorrentPier requires PHP version 5.6+. Your PHP version ' . PHP_VERSION);
}
/**

View file

@ -591,8 +591,6 @@ switch ($mode) {
case 'ip':
$anon = GUEST_UID;
$rdns_ip_num = (isset($_GET['rdns'])) ? $_GET['rdns'] : "";
if (!$post_id) {
bb_die($lang['NO_SUCH_POST']);
}
@ -607,8 +605,9 @@ switch ($mode) {
bb_die($lang['NO_SUCH_POST']);
}
$ip_this_post = decode_ip($post_row['poster_ip']);
$ip_this_post = ($rdns_ip_num == $ip_this_post) ? gethostbyaddr($ip_this_post) : $ip_this_post;
if (!$ip_this_post = decode_ip($post_row['poster_ip'])) {
$ip_this_post = $lang['NOT_AVAILABLE'];
}
$poster_id = $post_row['poster_id'];
@ -638,8 +637,9 @@ switch ($mode) {
continue;
}
$ip = decode_ip($row['poster_ip']);
$ip = ($rdns_ip_num == $row['poster_ip'] || $rdns_ip_num == 'all') ? gethostbyaddr($ip) : $ip;
if (!$ip = decode_ip($row['poster_ip'])) {
$ip = $lang['NOT_AVAILABLE'];
}
$template->assign_block_vars('iprow', array(
'ROW_CLASS' => !($i % 2) ? 'row4' : 'row5',

View file

@ -864,7 +864,7 @@ class Attach
$this->attach_filename = preg_replace('#([\xC2\xC3])([\x80-\xBF])#', 'chr(ord(\'$1\')<<6&0xC0|ord(\'$2\')&0x3F)', $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 = trim($this->attach_filename);
$this->attach_filename = trim($this->attach_filename . time());
}
$this->attach_filename = str_replace(['&amp;', '&', ' '], '_', $this->attach_filename);
$this->attach_filename = str_replace('php', '_php_', $this->attach_filename);

View file

@ -127,6 +127,7 @@ if (!$t_data = DB()->fetch_row($sql)) {
$forum_topic_data =& $t_data;
$topic_id = $t_data['topic_id'];
$forum_id = $t_data['forum_id'];
$topic_attachment = isset($t_data['topic_attachment']) ? (int)$t_data['topic_attachment'] : null;
if ($t_data['allow_porno_topic'] && bf($userdata['user_opt'], 'user_opt', 'user_porn_forums')) {
bb_die($lang['ERROR_PORNO_FORUM']);
@ -137,7 +138,7 @@ if ($userdata['session_admin'] && !empty($_REQUEST['mod'])) {
$datastore->enqueue(array('viewtopic_forum_select'));
}
}
if (isset($t_data['topic_attachment'])) {
if ($topic_attachment) {
$datastore->enqueue(array(
'attach_extensions',
));
@ -556,7 +557,7 @@ $template->assign_vars(array(
));
require INC_DIR . '/torrent_show_dl_list.php';
if (isset($t_data['topic_attachment'])) {
if ($topic_attachment) {
require ATTACH_DIR . '/attachment_mod.php';
init_display_post_attachments($t_data['topic_attachment']);
}