External bencode library and some other changes.

This commit is contained in:
Yuriy Pikhtarev 2017-05-26 02:21:46 +03:00
commit bb6f772627
No known key found for this signature in database
GPG key ID: 3A9B5A757B48ECC6
10 changed files with 137 additions and 85 deletions

92
CONTRIBUTING.md Normal file
View file

@ -0,0 +1,92 @@
# Contributing
When contributing to this repository, please first discuss the change you wish to make via issue,
email, or any other method with the owners of this repository before making a change.
Please note we have a code of conduct, please follow it in all your interactions with the project.
## Pull Request Process
1. Ensure any install or build dependencies are removed before the end of the layer when doing a
build.
2. Update the README.md with details of changes to the interface, this includes new environment
variables, exposed ports, useful file locations and container parameters.
3. Increase the version numbers in any examples files and the README.md to the new version that this
Pull Request would represent. The versioning scheme we use is [SemVer](http://semver.org/).
4. You may merge the Pull Request in once you have the sign-off of two other developers, or if you
do not have permission to do that, you may request the second reviewer to merge it for you.
## Code of Conduct
### Our Pledge
In the interest of fostering an open and welcoming environment, we as
contributors and maintainers pledge to making participation in our project and
our community a harassment-free experience for everyone, regardless of age, body
size, disability, ethnicity, gender identity and expression, level of experience,
nationality, personal appearance, race, religion, or sexual identity and
orientation.
### Our Standards
Examples of behavior that contributes to creating a positive environment
include:
* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members
Examples of unacceptable behavior by participants include:
* The use of sexualized language or imagery and unwelcome sexual attention or
advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic
address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting
### Our Responsibilities
Project maintainers are responsible for clarifying the standards of acceptable
behavior and are expected to take appropriate and fair corrective action in
response to any instances of unacceptable behavior.
Project maintainers have the right and responsibility to remove, edit, or
reject comments, commits, code, wiki edits, issues, and other contributions
that are not aligned to this Code of Conduct, or to ban temporarily or
permanently any contributor for other behaviors that they deem inappropriate,
threatening, offensive, or harmful.
### Scope
This Code of Conduct applies both within project spaces and in public spaces
when an individual is representing the project or its community. Examples of
representing a project or community include using an official project e-mail
address, posting via an official social media account, or acting as an appointed
representative at an online or offline event. Representation of a project may be
further defined and clarified by project maintainers.
### Enforcement
Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported by contacting the project team at admin@torrentpier.me. All
complaints will be reviewed and investigated and will result in a response that
is deemed necessary and appropriate to the circumstances. The project team is
obligated to maintain confidentiality with regard to the reporter of an incident.
Further details of specific enforcement policies may be posted separately.
Project maintainers who do not follow or enforce the Code of Conduct in good
faith may face temporary or permanent repercussions as determined by other
members of the project's leadership.
### Attribution
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
available at [http://contributor-covenant.org/version/1/4][version]
[homepage]: http://contributor-covenant.org
[version]: http://contributor-covenant.org/version/1/4/

View file

@ -1,16 +1,21 @@
<p align="center"><img src="https://torrentpier.me/forum/styles/default/xenforo/bull-logo.svg" width="400px" /></p> <p align="center"><img src="https://torrentpier.me/forum/styles/default/xenforo/bull-logo.svg" width="400px" /></p>
<p align="center"> <p align="center">
<a href="https://gitter.im/torrentpier/torrentpier?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge"><img src="https://badges.gitter.im/Join%20Chat.svg" /> <a href="http://torrentpier.herokuapp.com/"><img src="http://torrentpier.herokuapp.com/badge.svg" alt="Slack"></a>
<a href="https://crowdin.com/project/torrentpier"><img src="https://d322cqt584bo4o.cloudfront.net/torrentpier/localized.svg" alt="Crowdin"></a>
<a href="https://scrutinizer-ci.com/g/torrentpier/torrentpier/"><img src="https://img.shields.io/scrutinizer/g/torrentpier/torrentpier.svg" alt="Scrutinizer"></a>
<a href="https://www.codacy.com/app/Exile37/torrentpier"><img src="https://img.shields.io/codacy/grade/8b79a63a6d464b81bf0a39923f42bdf5/master.svg" alt="Codacy"></a>
<br />
<a href="https://insight.sensiolabs.com/projects/1a5d5098-e0b0-45c2-816a-020dfd50acaf"><img src="https://img.shields.io/sensiolabs/i/1a5d5098-e0b0-45c2-816a-020dfd50acaf.svg" alt="SensioLabs Insight"></a>
<a href="https://travis-ci.org/torrentpier/torrentpier"><img src="https://img.shields.io/travis/torrentpier/torrentpier/master.svg" alt="Travis"></a>
<a href="https://circleci.com/gh/torrentpier/torrentpier"><img src="https://img.shields.io/circleci/project/github/torrentpier/torrentpier/master.svg" alt="CircleCI"></a>
<a href="https://codecov.io/gh/torrentpier/torrentpier"><img src="https://img.shields.io/codecov/c/github/torrentpier/torrentpier/master.svg" alt="Codecov"></a>
</p> </p>
TorrentPier # TorrentPier
======================
TorrentPier - движок торрент-трекера, написанный на php. Высокая скорость работы, простота модификации, устойчивость к высоким нагрузкам, в том числе и поддержка альтернативных анонсеров (например, Ocelot). Помимо этого, крайне развитый официальный форум поддержки, где помимо прочего можно испытать движок в работе на демо-версии, не устанавливая его, а также получить любую другую интересующую вас информацию и скачать моды. TorrentPier - движок торрент-трекера, написанный на php. Высокая скорость работы, простота модификации, устойчивость к высоким нагрузкам, в том числе и поддержка альтернативных анонсеров (например, Ocelot). Помимо этого, крайне развитый официальный форум поддержки, где помимо прочего можно испытать движок в работе на демо-версии, не устанавливая его, а также получить любую другую интересующую вас информацию и скачать моды.
## Установка ## Installation
Для установки вам необходимо выполнить несколько простых шагов: Для установки вам необходимо выполнить несколько простых шагов:
@ -44,7 +49,7 @@ TorrentPier - движок торрент-трекера, написанный
## Необходимая версия php ## Необходимая версия php
Минимально поддерживаемой версией в настоящий момент является 5.3. Существует поддержка вплоть до версии 7.1. Минимально поддерживаемой версией в настоящий момент является 5.5. Существует поддержка вплоть до версии 7.1.
## Необходимые настройки php ## Необходимые настройки php
@ -73,13 +78,18 @@ TorrentPier - движок торрент-трекера, написанный
Инструкция по сборке приведена на нашем форуме: https://torrentpier.me/threads/sborka-ocelot-pod-debian-7-1.26078/ Инструкция по сборке приведена на нашем форуме: https://torrentpier.me/threads/sborka-ocelot-pod-debian-7-1.26078/
Для работы анонсера требуется замена двух таблиц в базе данных - дамп в файле: **install/sql/ocelot.sql** Для работы анонсера требуется замена двух таблиц в базе данных - дамп в файле: **install/sql/ocelot.sql**
## Папка install ## Official Documentation
В корне движка присутствует папка **install**, в которой находятся служебные файлы, необходимые для его установки (дамп базы, примеры конфигов) и обновления (дамперы, скрипты конвертации). Доступ к данной папке по-умолчанию закрыт, но если ее присутствие вам мешает - вы можете ее удалить. На файл **README.md** это также распространяется. Documentation for TorrentPier can be found on the [TorrentPier docs website](https://docs.torrentpier.me).
## Полезные ссылки ## Contributing
+ Наш форум https://torrentpier.me/ Please read [CONTRIBUTING.md](CONTRIBUTING.md) for details on our code of conduct, and the process for submitting pull requests to us.
+ Центр загрузки https://get.torrentpier.me/
+ Часто задаваемые вопросы https://faq.torrentpier.me/ ## Versioning
+ Где задать вопрос https://torrentpier.me/forums/10/
We use [SemVer](http://semver.org/) for versioning. For the versions available, see the [tags on this repository](https://github.com/torrentpier/torrentpier/tags).
## License
This project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details

View file

@ -178,11 +178,11 @@ function msg_die($msg)
dbg_log(' ', '!die-' . clean_filename($msg)); dbg_log(' ', '!die-' . clean_filename($msg));
} }
$output = bencode(array( $output = \Rych\Bencode\Bencode::encode([
'min interval' => (int)1800, 'min interval' => (int)1800,
'failure reason' => (string)$msg, 'failure reason' => (string)$msg,
'warning message' => (string)$msg, 'warning message' => (string)$msg,
)); ]);
die($output); die($output);
} }
@ -473,7 +473,7 @@ if (!$output) {
} }
// Return data to client // Return data to client
echo bencode($output); echo \Rych\Bencode\Bencode::encode($output);
tracker_exit(); tracker_exit();
exit; exit;

View file

@ -75,7 +75,7 @@ function error_exit($msg = '')
silent_exit(); silent_exit();
echo bencode(array('failure reason' => str_compact($msg))); echo \Rych\Bencode\Bencode::encode(['failure reason' => str_compact($msg)]);
tracker_exit(); tracker_exit();
} }

View file

@ -50,11 +50,11 @@ function msg_die($msg)
dbg_log(' ', '!die-' . clean_filename($msg)); dbg_log(' ', '!die-' . clean_filename($msg));
} }
$output = bencode(array( $output = \Rych\Bencode\Bencode::encode([
'min interval' => (int)1800, 'min interval' => (int)1800,
'failure reason' => (string)$msg, 'failure reason' => (string)$msg,
'warning message' => (string)$msg, 'warning message' => (string)$msg,
)); ]);
die($output); die($output);
} }
@ -77,7 +77,7 @@ $output['files'][$info_hash] = array(
'incomplete' => (int)$row['leechers'], 'incomplete' => (int)$row['leechers'],
); );
echo bencode($output); echo \Rych\Bencode\Bencode::encode($output);
tracker_exit(); tracker_exit();
exit; exit;

View file

@ -70,7 +70,7 @@ if ($bb_cfg['bugsnag']['enabled'] && !empty($bb_cfg['bugsnag']['api_key'])) {
} }
$server_protocol = $bb_cfg['cookie_secure'] ? 'https://' : 'http://'; $server_protocol = $bb_cfg['cookie_secure'] ? 'https://' : 'http://';
$server_port = in_array($bb_cfg['server_port'], array(80, 443), true) ? '' : ':' . $bb_cfg['server_port']; $server_port = in_array((int)$bb_cfg['server_port'], array(80, 443), true) ? '' : ':' . $bb_cfg['server_port'];
define('FORUM_PATH', $bb_cfg['script_path']); define('FORUM_PATH', $bb_cfg['script_path']);
define('FULL_URL', $server_protocol . $bb_cfg['server_name'] . $server_port . $bb_cfg['script_path']); define('FULL_URL', $server_protocol . $bb_cfg['server_name'] . $server_port . $bb_cfg['script_path']);
unset($server_protocol, $server_port); unset($server_protocol, $server_port);
@ -311,52 +311,6 @@ function make_rand_str($len = 10)
return substr($str, 0, $len); return substr($str, 0, $len);
} }
// bencode: based on OpenTracker
function bencode($var)
{
if (is_string($var)) {
return strlen($var) . ':' . $var;
}
if (is_int($var)) {
return 'i' . $var . 'e';
} elseif (is_float($var)) {
return 'i' . sprintf('%.0f', $var) . 'e';
} elseif (is_array($var)) {
if (count($var) == 0) {
return 'de';
}
$assoc = false;
foreach ($var as $key => $val) {
if (!is_int($key)) {
$assoc = true;
break;
}
}
if ($assoc) {
ksort($var, SORT_REGULAR);
$ret = 'd';
foreach ($var as $key => $val) {
$ret .= bencode($key) . bencode($val);
}
return $ret . 'e';
}
$ret = 'l';
foreach ($var as $val) {
$ret .= bencode($val);
}
return $ret . 'e';
} else {
trigger_error('bencode error: wrong data type', E_USER_ERROR);
}
}
function array_deep(&$var, $fn, $one_dimensional = false, $array_only = false) function array_deep(&$var, $fn, $one_dimensional = false, $array_only = false)
{ {
if (is_array($var)) { if (is_array($var)) {
@ -462,11 +416,11 @@ elseif (defined('IN_TRACKER')) {
function dummy_exit($interval = 1800) function dummy_exit($interval = 1800)
{ {
$output = bencode(array( $output = \Rych\Bencode\Bencode::encode([
'interval' => (int)$interval, 'interval' => (int)$interval,
'min interval' => (int)$interval, 'min interval' => (int)$interval,
'peers' => (string)DUMMY_PEER, 'peers' => (string)DUMMY_PEER,
)); ]);
die($output); die($output);
} }

View file

@ -26,11 +26,6 @@
"name": "PheRum", "name": "PheRum",
"homepage": "https://torrentpier.me/forum/members/pherum.23/", "homepage": "https://torrentpier.me/forum/members/pherum.23/",
"role": "Developer" "role": "Developer"
},
{
"name": "tpuser",
"homepage": "https://torrentpier.me/forum/members/tpuser.7560/",
"role": "Developer"
} }
], ],
"support": { "support": {
@ -38,15 +33,16 @@
"issues": "https://github.com/torrentpier/torrentpier/issues", "issues": "https://github.com/torrentpier/torrentpier/issues",
"forum": "https://torrentpier.me/forum/", "forum": "https://torrentpier.me/forum/",
"get": "https://get.torrentpier.me/", "get": "https://get.torrentpier.me/",
"docs": "https://faq.torrentpier.me/" "docs": "https://docs.torrentpier.me/"
}, },
"require": { "require": {
"php": "^5.3 || ^7.0", "php": "^5.5 || ^7.0",
"bugsnag/bugsnag": "^3.0", "bugsnag/bugsnag": "^3.0",
"gigablah/sphinxphp": "^2.0", "gigablah/sphinxphp": "^2.0",
"google/recaptcha": "^1.0", "google/recaptcha": "^1.0",
"roave/security-advisories": "dev-master", "roave/security-advisories": "dev-master",
"swiftmailer/swiftmailer": "^6.0" "rych/bencode": "^1.0",
"swiftmailer/swiftmailer": "^5.4"
}, },
"autoload": { "autoload": {
"psr-4": { "psr-4": {

View file

@ -112,7 +112,7 @@ function bbcode_tpl_compact($text)
// prepare a posted message for entry into the database // prepare a posted message for entry into the database
function prepare_message($message) function prepare_message($message)
{ {
$message = bbcode::clean_up($message); $message = \TorrentPier\Legacy\BBCode::clean_up($message);
$message = htmlCHR($message, false, ENT_NOQUOTES); $message = htmlCHR($message, false, ENT_NOQUOTES);
return $message; return $message;
} }

View file

@ -287,7 +287,7 @@ function tracker_register($attach_id, $mode = '', $tor_status = TOR_NOT_APPROVED
if ($bb_cfg['bt_disable_dht']) { if ($bb_cfg['bt_disable_dht']) {
$tor['info']['private'] = (int)1; $tor['info']['private'] = (int)1;
$fp = fopen($filename, 'wb+'); $fp = fopen($filename, 'wb+');
fwrite($fp, bencode($tor)); fwrite($fp, \Rych\Bencode\Bencode::encode($tor));
fclose($fp); fclose($fp);
} }
@ -309,7 +309,7 @@ function tracker_register($attach_id, $mode = '', $tor_status = TOR_NOT_APPROVED
return torrent_error_exit($lang['TORFILE_INVALID']); return torrent_error_exit($lang['TORFILE_INVALID']);
} }
$info_hash = pack('H*', sha1(bencode($info))); $info_hash = pack('H*', sha1(\Rych\Bencode\Bencode::encode($info)));
$info_hash_sql = rtrim(DB()->escape($info_hash), ' '); $info_hash_sql = rtrim(DB()->escape($info_hash), ' ');
$info_hash_md5 = md5($info_hash); $info_hash_md5 = md5($info_hash);
@ -421,7 +421,7 @@ function send_torrent_with_passkey($filename)
} }
if (bf($userdata['user_opt'], 'user_opt', 'dis_passkey') && !IS_GUEST) { if (bf($userdata['user_opt'], 'user_opt', 'dis_passkey') && !IS_GUEST) {
bb_die('Could not add passkey'); bb_die($lang['DISALLOWED']);
} }
if ($bt_userdata = get_bt_userdata($user_id)) { if ($bt_userdata = get_bt_userdata($user_id)) {
@ -504,7 +504,7 @@ function send_torrent_with_passkey($filename)
unset($tor['comment.utf-8']); unset($tor['comment.utf-8']);
// Send torrent // Send torrent
$output = bencode($tor); $output = \Rych\Bencode\Bencode::encode($tor);
$dl_fname = ($bb_cfg['torrent_name_style'] ? '[' . $bb_cfg['server_name'] . '].t' . $topic_id . '.torrent' : clean_filename(basename($attachment['real_filename']))); $dl_fname = ($bb_cfg['torrent_name_style'] ? '[' . $bb_cfg['server_name'] . '].t' . $topic_id . '.torrent' : clean_filename(basename($attachment['real_filename'])));
if (!empty($_COOKIE['explain'])) { if (!empty($_COOKIE['explain'])) {

View file

@ -26,8 +26,8 @@
if (!defined('BB_ROOT')) { if (!defined('BB_ROOT')) {
die(basename(__FILE__)); die(basename(__FILE__));
} }
if (version_compare(PHP_VERSION, '5.3', '<')) { if (version_compare(PHP_VERSION, '5.5', '<')) {
die('TorrentPier requires PHP version 5.3+. Your PHP version ' . PHP_VERSION); die('TorrentPier requires PHP version 5.5+. Your PHP version ' . PHP_VERSION);
} }
if (!defined('BB_SCRIPT')) { if (!defined('BB_SCRIPT')) {
define('BB_SCRIPT', 'undefined'); define('BB_SCRIPT', 'undefined');