mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-24 03:57:22 +08:00
require redis and use reids to check ReAnnounce
This commit is contained in:
+2
-2
@@ -20,9 +20,9 @@ Complete PT website building solution. Based on NexusPHP + Laravel Framework + E
|
|||||||
- ....
|
- ....
|
||||||
|
|
||||||
## System Requirements
|
## System Requirements
|
||||||
- PHP: 8.0, must have extensions: bcmath, ctype, fileinfo, json, mbstring, openssl, pdo_mysql, tokenizer, xml, mysqli, gd
|
- PHP: 8.0, must have extensions: bcmath, ctype, fileinfo, json, mbstring, openssl, pdo_mysql, tokenizer, xml, mysqli, gd, redis
|
||||||
- Mysql: 5.7 latest version or above
|
- Mysql: 5.7 latest version or above
|
||||||
- Redis:optional
|
- Redis:1.0.0 or above
|
||||||
|
|
||||||
## More information
|
## More information
|
||||||
Blog:[https://nexusphp.org](https://nexusphp.org/)
|
Blog:[https://nexusphp.org](https://nexusphp.org/)
|
||||||
|
|||||||
@@ -19,9 +19,9 @@
|
|||||||
- ....
|
- ....
|
||||||
|
|
||||||
## 系统要求
|
## 系统要求
|
||||||
- PHP: 8.0,必须扩展:bcmath, ctype, fileinfo, json, mbstring, openssl, pdo_mysql, tokenizer, xml, mysqli, gd
|
- PHP: 8.0,必须扩展:bcmath, ctype, fileinfo, json, mbstring, openssl, pdo_mysql, tokenizer, xml, mysqli, gd, redis
|
||||||
- Mysql: 5.7最新版或以上版本
|
- Mysql: 5.7最新版或以上版本
|
||||||
- Redis:可选
|
- Redis:1.0.0或以上版本
|
||||||
|
|
||||||
## 捐赠
|
## 捐赠
|
||||||
此程序由个人维护,如果对你有帮助,可以请我喝杯咖啡。感谢以下捐赠者:
|
此程序由个人维护,如果对你有帮助,可以请我喝杯咖啡。感谢以下捐赠者:
|
||||||
|
|||||||
@@ -21,8 +21,10 @@ class class_cache_redis {
|
|||||||
function __construct() {
|
function __construct() {
|
||||||
$success = $this->connect(); // Connect to Redis
|
$success = $this->connect(); // Connect to Redis
|
||||||
if ($success) {
|
if ($success) {
|
||||||
|
do_log("Redis is enabled!");
|
||||||
$this->isEnabled = 1;
|
$this->isEnabled = 1;
|
||||||
} else {
|
} else {
|
||||||
|
do_log("Redis is disabled!");
|
||||||
$this->isEnabled = 0;
|
$this->isEnabled = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -61,6 +63,7 @@ class class_cache_redis {
|
|||||||
}
|
}
|
||||||
return $connectResult;
|
return $connectResult;
|
||||||
} catch (\Exception $exception) {
|
} catch (\Exception $exception) {
|
||||||
|
do_log("Redis connect fail: " . $exception->getMessage(), 'error');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,6 +29,7 @@
|
|||||||
"ext-mysqli": "*",
|
"ext-mysqli": "*",
|
||||||
"ext-xml": "*",
|
"ext-xml": "*",
|
||||||
"ext-bcmath": "*",
|
"ext-bcmath": "*",
|
||||||
|
"ext-redis": "*",
|
||||||
"doctrine/dbal": "^3.1",
|
"doctrine/dbal": "^3.1",
|
||||||
"fideloper/proxy": "^4.4",
|
"fideloper/proxy": "^4.4",
|
||||||
"fruitcake/laravel-cors": "^2.0",
|
"fruitcake/laravel-cors": "^2.0",
|
||||||
|
|||||||
@@ -10,8 +10,10 @@ require "bittorrent.php";
|
|||||||
$fd = fopen(sprintf('%s/nexus_cleanup_cli.lock', sys_get_temp_dir()), 'w+');
|
$fd = fopen(sprintf('%s/nexus_cleanup_cli.lock', sys_get_temp_dir()), 'w+');
|
||||||
if (!flock($fd, LOCK_EX|LOCK_NB)) {
|
if (!flock($fd, LOCK_EX|LOCK_NB)) {
|
||||||
do_log("can not get lock, skip!");
|
do_log("can not get lock, skip!");
|
||||||
|
exit();
|
||||||
}
|
}
|
||||||
register_shutdown_function(function () use ($fd) {
|
register_shutdown_function(function () use ($fd) {
|
||||||
|
flock($fd, LOCK_UN);
|
||||||
fclose($fd);
|
fclose($fd);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -1009,7 +1009,7 @@ function begin_compose($title = "",$type="new", $body="", $hassubject=true, $sub
|
|||||||
print("<table class=\"main\" width=\"100%\" border=\"1\" cellspacing=\"0\" cellpadding=\"5\">\n");
|
print("<table class=\"main\" width=\"100%\" border=\"1\" cellspacing=\"0\" cellpadding=\"5\">\n");
|
||||||
if ($hassubject)
|
if ($hassubject)
|
||||||
print("<tr><td class=\"rowhead\">".$lang_functions['row_subject']."</td>" .
|
print("<tr><td class=\"rowhead\">".$lang_functions['row_subject']."</td>" .
|
||||||
"<td class=\"rowfollow\" align=\"left\"><input type=\"text\" style=\"width: 650px;\" name=\"subject\" maxlength=\"".$maxsubjectlength."\" value=\"".$subject."\" /></td></tr>\n");
|
"<td class=\"rowfollow\" align=\"left\"><input type=\"text\" style=\"width: 650px;\" name=\"subject\" maxlength=\"".$maxsubjectlength."\" value=\"".htmlspecialchars($subject)."\" /></td></tr>\n");
|
||||||
print("<tr><td class=\"rowhead\" valign=\"top\">".$lang_functions['row_body']."</td><td class=\"rowfollow\" align=\"left\"><span style=\"display: none;\" id=\"previewouter\"></span><div id=\"editorouter\">");
|
print("<tr><td class=\"rowhead\" valign=\"top\">".$lang_functions['row_body']."</td><td class=\"rowfollow\" align=\"left\"><span style=\"display: none;\" id=\"previewouter\"></span><div id=\"editorouter\">");
|
||||||
textbbcode("compose","body", $body, false);
|
textbbcode("compose","body", $body, false);
|
||||||
print("</div></td></tr>");
|
print("</div></td></tr>");
|
||||||
|
|||||||
@@ -126,7 +126,7 @@ class Install
|
|||||||
public function listRequirementTableRows()
|
public function listRequirementTableRows()
|
||||||
{
|
{
|
||||||
$gdInfo = function_exists('gd_info') ? gd_info() : [];
|
$gdInfo = function_exists('gd_info') ? gd_info() : [];
|
||||||
$extensions = ['ctype', 'fileinfo', 'json', 'mbstring', 'openssl', 'pdo_mysql', 'tokenizer', 'xml', 'mysqli', 'gd', 'bcmath'];
|
$extensions = ['ctype', 'fileinfo', 'json', 'mbstring', 'openssl', 'pdo_mysql', 'tokenizer', 'xml', 'mysqli', 'bcmath', 'redis', 'gd'];
|
||||||
$tableRows = [];
|
$tableRows = [];
|
||||||
$tableRows[] = [
|
$tableRows[] = [
|
||||||
'label' => 'PHP version',
|
'label' => 'PHP version',
|
||||||
@@ -160,12 +160,6 @@ class Install
|
|||||||
'current' => $gdInfo['GIF Read Support'] ?? '',
|
'current' => $gdInfo['GIF Read Support'] ?? '',
|
||||||
'result' => $this->yesOrNo($gdInfo['GIF Read Support'] ?? ''),
|
'result' => $this->yesOrNo($gdInfo['GIF Read Support'] ?? ''),
|
||||||
];
|
];
|
||||||
$tableRows[] = [
|
|
||||||
'label' => 'PHP extension redis',
|
|
||||||
'required' => 'optional',
|
|
||||||
'current' => extension_loaded('redis'),
|
|
||||||
'result' => $this->yesOrNo(extension_loaded('redis')),
|
|
||||||
];
|
|
||||||
|
|
||||||
$fails = array_filter($tableRows, function ($value) {return in_array($value['required'], ['true', 'enabled']) && $value['result'] == 'NO';});
|
$fails = array_filter($tableRows, function ($value) {return in_array($value['required'], ['true', 'enabled']) && $value['result'] == 'NO';});
|
||||||
$pass = empty($fails);
|
$pass = empty($fails);
|
||||||
@@ -434,15 +428,13 @@ class Install
|
|||||||
$this->doLog("[CREATE ENV] final newData: " . json_encode($newData));
|
$this->doLog("[CREATE ENV] final newData: " . json_encode($newData));
|
||||||
unset($key, $value);
|
unset($key, $value);
|
||||||
mysql_connect($newData['DB_HOST'], $newData['DB_USERNAME'], $newData['DB_PASSWORD'], $newData['DB_DATABASE'], $newData['DB_PORT']);
|
mysql_connect($newData['DB_HOST'], $newData['DB_USERNAME'], $newData['DB_PASSWORD'], $newData['DB_DATABASE'], $newData['DB_PORT']);
|
||||||
if (extension_loaded('redis') && !empty($newData['REDIS_HOST'])) {
|
$redis = new \Redis();
|
||||||
$redis = new \Redis();
|
$redis->connect($newData['REDIS_HOST'], $newData['REDIS_PORT'] ?: 6379);
|
||||||
$redis->connect($newData['REDIS_HOST'], $newData['REDIS_PORT'] ?: 6379);
|
if (isset($newData['REDIS_DB'])) {
|
||||||
if (isset($newData['REDIS_DB'])) {
|
if (!ctype_digit($newData['REDIS_DB']) || $newData['REDIS_DB'] < 0 || $newData['REDIS_DB'] > 15) {
|
||||||
if (!ctype_digit($newData['REDIS_DB']) || $newData['REDIS_DB'] < 0 || $newData['REDIS_DB'] > 15) {
|
throw new \InvalidArgumentException("invalid redis database: " . $newData['REDIS_DB']);
|
||||||
throw new \InvalidArgumentException("invalid redis database: " . $newData['REDIS_DB']);
|
|
||||||
}
|
|
||||||
$redis->select($newData['REDIS_DB']);
|
|
||||||
}
|
}
|
||||||
|
$redis->select($newData['REDIS_DB']);
|
||||||
}
|
}
|
||||||
$content = "";
|
$content = "";
|
||||||
foreach ($newData as $key => $value) {
|
foreach ($newData as $key => $value) {
|
||||||
|
|||||||
@@ -173,7 +173,6 @@ if (!empty($error)) {
|
|||||||
echo $install->renderTable($header, $requirements['table_rows']);
|
echo $install->renderTable($header, $requirements['table_rows']);
|
||||||
} elseif ($currentStep == 2) {
|
} elseif ($currentStep == 2) {
|
||||||
echo $install->renderTable($header, $tableRows);
|
echo $install->renderTable($header, $tableRows);
|
||||||
echo '<div class="text-gray-700 p-4 text-red-400">若 Redis 不启用,相关项目留空</div>';
|
|
||||||
echo $install->renderForm($envFormControls);
|
echo $install->renderForm($envFormControls);
|
||||||
|
|
||||||
} elseif ($currentStep == 3) {
|
} elseif ($currentStep == 3) {
|
||||||
|
|||||||
@@ -200,7 +200,7 @@ if (!empty($error)) {
|
|||||||
echo $update->renderTable($header, $requirements['table_rows']);
|
echo $update->renderTable($header, $requirements['table_rows']);
|
||||||
} elseif ($currentStep == 3) {
|
} elseif ($currentStep == 3) {
|
||||||
echo $update->renderTable($header, $tableRows);
|
echo $update->renderTable($header, $tableRows);
|
||||||
echo '<div class="text-gray-700 p-4 text-red-400">若 Redis 不启用,相关项目留空</div>';
|
echo '<div class="text-gray-700 p-4 text-red-400">下一步之前,请确保在根目录执行了 composer install 更新了依赖。</div>';
|
||||||
echo $update->renderForm($envFormControls);
|
echo $update->renderForm($envFormControls);
|
||||||
|
|
||||||
} elseif ($currentStep == 2) {
|
} elseif ($currentStep == 2) {
|
||||||
|
|||||||
+30
-9
@@ -4,11 +4,27 @@ dbconn();
|
|||||||
loggedinorreturn();
|
loggedinorreturn();
|
||||||
if (get_user_class() < UC_MODERATOR)
|
if (get_user_class() < UC_MODERATOR)
|
||||||
stderr("Error", "Access denied.");
|
stderr("Error", "Access denied.");
|
||||||
|
$seedBonusAll = [
|
||||||
|
1 => 100,
|
||||||
|
2 => 1000,
|
||||||
|
3 => 10000,
|
||||||
|
];
|
||||||
|
$selectName = 'seed_bonus_type';
|
||||||
|
$select = '<select name="' . $selectName . '">';
|
||||||
|
foreach ($seedBonusAll as $key => $value) {
|
||||||
|
$select .= sprintf('<option value="%s">%s</option>', $key, $value);
|
||||||
|
}
|
||||||
|
$select .= '</select>';
|
||||||
|
|
||||||
if ($_SERVER["REQUEST_METHOD"] == "POST")
|
if ($_SERVER["REQUEST_METHOD"] == "POST")
|
||||||
{
|
{
|
||||||
if ($_POST['doit'] == 'yes') {
|
if (isset($_POST['doit']) && $_POST['doit'] == 'yes') {
|
||||||
sql_query("UPDATE users SET seedbonus = seedbonus + 25.0 WHERE status='confirmed'");
|
if (empty($_POST[$selectName]) || !isset($seedBonusAll[$_POST[$selectName]])) {
|
||||||
stderr("Bonus", "25.0 bonus point is sent to everyone...");
|
stderr("Error", "Invalid form data: $selectName.");
|
||||||
|
}
|
||||||
|
$seedBonusIncrease = $seedBonusAll[$_POST[$selectName]];
|
||||||
|
sql_query("UPDATE users SET seedbonus = seedbonus + $seedBonusIncrease WHERE status='confirmed'");
|
||||||
|
stderr("Bonus", "$seedBonusIncrease bonus point is sent to everyone...");
|
||||||
die;
|
die;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -40,14 +56,19 @@ print("<table width=100% border=1 cellspacing=0 cellpadding=5>\n");
|
|||||||
<?php end_table();?>
|
<?php end_table();?>
|
||||||
</form>
|
</form>
|
||||||
<?php end_main_frame();?>
|
<?php end_main_frame();?>
|
||||||
<?php begin_main_frame("Send 25.0 bonus point to everyone",false,30);?>
|
<?php begin_main_frame("Send bonus point to everyone",false,30);?>
|
||||||
<form action="amountbonus.php" method="post">
|
<form action="amountbonus.php" method="post">
|
||||||
<table width=100% border=1 cellspacing=0 cellpadding=5>
|
<table width=100% border=1 cellspacing=0 cellpadding=5>
|
||||||
<tr><td class="rowfollow" width="100%">
|
<tr>
|
||||||
Are you sure you want to give all confirmed users 25.0 extra bonus point?<br /><br /></td></tr>
|
<td class="rowhead">Bonus</td>
|
||||||
<tr><td class="toolbox" align="center"><input type = "hidden" name = "doit" value = "yes" />
|
<td class="rowfollow"><?php echo $select?></td>
|
||||||
<input type="submit" class="btn" value="Yes" />
|
</tr>
|
||||||
</td></tr>
|
<tr>
|
||||||
|
<td class="toolbox" align="center" colspan="2">
|
||||||
|
<input type = "hidden" name = "doit" value = "yes" />
|
||||||
|
<input type="submit" class="btn" value="Okay" />
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
<?php end_table();?>
|
<?php end_table();?>
|
||||||
</form>
|
</form>
|
||||||
<?php
|
<?php
|
||||||
|
|||||||
+4
-9
@@ -147,7 +147,6 @@ $fields = "seeder, peer_id, ip, port, uploaded, downloaded, (".TIMENOW." - UNIX_
|
|||||||
* @since 1.6.0-beta12
|
* @since 1.6.0-beta12
|
||||||
*/
|
*/
|
||||||
$peerlistsql = "SELECT ".$fields." FROM peers WHERE torrent = " . $torrentid . $only_leech_query . $limit;
|
$peerlistsql = "SELECT ".$fields." FROM peers WHERE torrent = " . $torrentid . $only_leech_query . $limit;
|
||||||
$res = sql_query($peerlistsql);
|
|
||||||
|
|
||||||
$real_annnounce_interval = $announce_interval;
|
$real_annnounce_interval = $announce_interval;
|
||||||
if ($anninterthreeage && ($anninterthree > $announce_wait) && (TIMENOW - $torrent['ts']) >= ($anninterthreeage * 86400))
|
if ($anninterthreeage && ($anninterthree > $announce_wait) && (TIMENOW - $torrent['ts']) >= ($anninterthreeage * 86400))
|
||||||
@@ -172,17 +171,16 @@ if ($compact == 1) {
|
|||||||
//check ReAnnounce
|
//check ReAnnounce
|
||||||
$params = $_GET;
|
$params = $_GET;
|
||||||
unset($params['key']);
|
unset($params['key']);
|
||||||
$lockKey = implode('', $params);
|
$lockKey = md5(http_build_query($params));
|
||||||
$fp = fopen($lockKey, 'w+');
|
$redis = $Cache->getRedis();
|
||||||
if (!fopen($fp, LOCK_EX|LOCK_NB)) {
|
if (!$redis->setnx($lockKey, $announce_wait, TIMENOW)) {
|
||||||
do_log('ReAnnounce');
|
do_log('ReAnnounce');
|
||||||
benc_resp($rep_dict);
|
benc_resp($rep_dict);
|
||||||
fclose($fp);
|
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
unset($self);
|
unset($self);
|
||||||
|
$res = sql_query($peerlistsql);
|
||||||
if (isset($event) && $event == "stopped") {
|
if (isset($event) && $event == "stopped") {
|
||||||
// Don't fetch peers for stopped event
|
// Don't fetch peers for stopped event
|
||||||
} else {
|
} else {
|
||||||
@@ -494,8 +492,5 @@ if(count($USERUPDATESET) && $userid)
|
|||||||
{
|
{
|
||||||
sql_query("UPDATE users SET " . join(",", $USERUPDATESET) . " WHERE id = ".$userid);
|
sql_query("UPDATE users SET " . join(",", $USERUPDATESET) . " WHERE id = ".$userid);
|
||||||
}
|
}
|
||||||
|
|
||||||
flock($fp, LOCK_UN);
|
|
||||||
fclose($fp);
|
|
||||||
benc_resp($rep_dict);
|
benc_resp($rep_dict);
|
||||||
?>
|
?>
|
||||||
|
|||||||
Reference in New Issue
Block a user