mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-14 20:40:49 +08:00
cache rss + redis require 2.0
This commit is contained in:
@@ -28,7 +28,7 @@ Complete PT website building solution. Based on NexusPHP + Laravel + Filament.
|
|||||||
## System Requirements
|
## System Requirements
|
||||||
- PHP: 8.0, must have extensions: bcmath, ctype, curl, fileinfo, json, mbstring, openssl, pdo_mysql, tokenizer, xml, mysqli, gd, redis, pcntl, sockets, posix
|
- PHP: 8.0, must have extensions: bcmath, ctype, curl, fileinfo, json, mbstring, openssl, pdo_mysql, tokenizer, xml, mysqli, gd, redis, pcntl, sockets, posix
|
||||||
- Mysql: 5.7 latest version or above
|
- Mysql: 5.7 latest version or above
|
||||||
- Redis:1.0.0 or above
|
- Redis:2.0.0 or above
|
||||||
|
|
||||||
## Quick Start
|
## Quick Start
|
||||||
Install docker.
|
Install docker.
|
||||||
|
|||||||
@@ -27,7 +27,7 @@
|
|||||||
## 系统要求
|
## 系统要求
|
||||||
- PHP: 8.0,必须扩展:bcmath, ctype, curl, fileinfo, json, mbstring, openssl, pdo_mysql, tokenizer, xml, mysqli, gd, redis, pcntl, sockets, posix
|
- PHP: 8.0,必须扩展:bcmath, ctype, curl, fileinfo, json, mbstring, openssl, pdo_mysql, tokenizer, xml, mysqli, gd, redis, pcntl, sockets, posix
|
||||||
- Mysql: 5.7最新版或以上版本
|
- Mysql: 5.7最新版或以上版本
|
||||||
- Redis:1.0.0或以上版本
|
- Redis:2.0.0或以上版本
|
||||||
|
|
||||||
## 快速开始
|
## 快速开始
|
||||||
安装 docker。
|
安装 docker。
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ namespace App\Console\Commands;
|
|||||||
use App\Repositories\ToolRepository;
|
use App\Repositories\ToolRepository;
|
||||||
use Illuminate\Console\Command;
|
use Illuminate\Console\Command;
|
||||||
|
|
||||||
class BackuAll extends Command
|
class BackupAll extends Command
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* The name and signature of the console command.
|
* The name and signature of the console command.
|
||||||
@@ -91,6 +91,7 @@ class NexusUpdate extends Command
|
|||||||
$symbolicLinks = $settingTableRows['symbolic_links'];
|
$symbolicLinks = $settingTableRows['symbolic_links'];
|
||||||
$fails = $settingTableRows['fails'];
|
$fails = $settingTableRows['fails'];
|
||||||
$mysqlInfo = $this->update->getMysqlVersionInfo();
|
$mysqlInfo = $this->update->getMysqlVersionInfo();
|
||||||
|
$redisInfo = $this->update->getRedisVersionInfo();
|
||||||
|
|
||||||
if (!empty($fails)) {
|
if (!empty($fails)) {
|
||||||
foreach ($fails as $value) {
|
foreach ($fails as $value) {
|
||||||
@@ -102,6 +103,10 @@ class NexusUpdate extends Command
|
|||||||
$this->doLog("Error: MySQL version: {$mysqlInfo['version']} is too low, please use the newest version of 5.7 or above.", 'error');
|
$this->doLog("Error: MySQL version: {$mysqlInfo['version']} is too low, please use the newest version of 5.7 or above.", 'error');
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
if (!$redisInfo['match']) {
|
||||||
|
$this->doLog("Error: Redis version: {$mysqlInfo['version']} is too low, please use 2.0.0 or above.", 'error');
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
$this->doLog("going to createSymbolicLinks...");
|
$this->doLog("going to createSymbolicLinks...");
|
||||||
$this->update->createSymbolicLinks($symbolicLinks);
|
$this->update->createSymbolicLinks($symbolicLinks);
|
||||||
$this->doLog("createSymbolicLinks done!");
|
$this->doLog("createSymbolicLinks done!");
|
||||||
|
|||||||
@@ -293,7 +293,7 @@ class ExamRepository extends BaseRepository
|
|||||||
$logPrefix = "uid: $uid, examId: $examId, begin: $begin, end: $end";
|
$logPrefix = "uid: $uid, examId: $examId, begin: $begin, end: $end";
|
||||||
$exam = Exam::query()->find($examId);
|
$exam = Exam::query()->find($examId);
|
||||||
$user = User::query()->findOrFail($uid);
|
$user = User::query()->findOrFail($uid);
|
||||||
if (Auth::user()->Class <= $user->class) {
|
if (Auth::user()->class <= $user->class) {
|
||||||
throw new NexusException("No permission !");
|
throw new NexusException("No permission !");
|
||||||
}
|
}
|
||||||
if (!$this->isExamMatchUser($exam, $user)) {
|
if (!$this->isExamMatchUser($exam, $user)) {
|
||||||
|
|||||||
@@ -233,7 +233,7 @@ class UserRepository extends BaseRepository
|
|||||||
}
|
}
|
||||||
$sourceField = $fieldMap[$field];
|
$sourceField = $fieldMap[$field];
|
||||||
$targetUser = User::query()->findOrFail($uid, User::$commonFields);
|
$targetUser = User::query()->findOrFail($uid, User::$commonFields);
|
||||||
if (Auth::user()->Class <= $targetUser->class) {
|
if (Auth::user()->class <= $targetUser->class) {
|
||||||
throw new NexusException("No permission !");
|
throw new NexusException("No permission !");
|
||||||
}
|
}
|
||||||
$old = $targetUser->{$sourceField};
|
$old = $targetUser->{$sourceField};
|
||||||
|
|||||||
@@ -663,6 +663,16 @@ class Install
|
|||||||
return compact('version', 'match');
|
return compact('version', 'match');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getRedisVersionInfo(): array
|
||||||
|
{
|
||||||
|
global $Cache;
|
||||||
|
$redis = $Cache->getRedis();
|
||||||
|
$result = $redis->info();
|
||||||
|
$version = $result['redis_version'];
|
||||||
|
$match = version_compare($version, '2.0.0', '>=');
|
||||||
|
return compact('version', 'match');
|
||||||
|
}
|
||||||
|
|
||||||
public function checkLock()
|
public function checkLock()
|
||||||
{
|
{
|
||||||
$fullFilename = ROOT_PATH . $this->lockFile;
|
$fullFilename = ROOT_PATH . $this->lockFile;
|
||||||
|
|||||||
@@ -104,6 +104,7 @@ if ($currentStep == 4) {
|
|||||||
$tableRows = $settingTableRows['table_rows'];
|
$tableRows = $settingTableRows['table_rows'];
|
||||||
$pass = $settingTableRows['pass'];
|
$pass = $settingTableRows['pass'];
|
||||||
$mysqlInfo = $install->getMysqlVersionInfo();
|
$mysqlInfo = $install->getMysqlVersionInfo();
|
||||||
|
$redisInfo = $install->getREdisVersionInfo();
|
||||||
while ($isPost) {
|
while ($isPost) {
|
||||||
set_time_limit(300);
|
set_time_limit(300);
|
||||||
try {
|
try {
|
||||||
@@ -136,7 +137,11 @@ if ($currentStep == 5) {
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($error) || (isset($mysqlInfo) && !$mysqlInfo['match'])) {
|
if (
|
||||||
|
!empty($error)
|
||||||
|
|| (isset($mysqlInfo) && !$mysqlInfo['match'])
|
||||||
|
|| (isset($redisInfo) && !$redisInfo['match'])
|
||||||
|
) {
|
||||||
$pass = false;
|
$pass = false;
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
@@ -184,6 +189,9 @@ if (!empty($error) || (isset($mysqlInfo) && !$mysqlInfo['match'])) {
|
|||||||
if (!$mysqlInfo['match']) {
|
if (!$mysqlInfo['match']) {
|
||||||
echo sprintf('<div class="text-red-700 pt-10">MySQL version: %s is too low, please use the newest version of 5.7 or above.</div>', $mysqlInfo['version']);
|
echo sprintf('<div class="text-red-700 pt-10">MySQL version: %s is too low, please use the newest version of 5.7 or above.</div>', $mysqlInfo['version']);
|
||||||
}
|
}
|
||||||
|
if (!$redisInfo['match']) {
|
||||||
|
echo sprintf('<div class="text-red-700 pt-10">Redis version: %s is too low, please use 2.0.0 or above.</div>', $redisInfo['version']);
|
||||||
|
}
|
||||||
} elseif ($currentStep == 5) {
|
} elseif ($currentStep == 5) {
|
||||||
echo $install->renderForm($userFormControls, '1/2', '1/4', '3/4');
|
echo $install->renderForm($userFormControls, '1/2', '1/4', '3/4');
|
||||||
} elseif ($currentStep > $maxStep) {
|
} elseif ($currentStep > $maxStep) {
|
||||||
|
|||||||
@@ -157,6 +157,7 @@ if ($currentStep == 4) {
|
|||||||
$tableRows = $settingTableRows['table_rows'];
|
$tableRows = $settingTableRows['table_rows'];
|
||||||
$pass = $settingTableRows['pass'];
|
$pass = $settingTableRows['pass'];
|
||||||
$mysqlInfo = $update->getMysqlVersionInfo();
|
$mysqlInfo = $update->getMysqlVersionInfo();
|
||||||
|
$redisInfo = $update->getREdisVersionInfo();
|
||||||
while ($isPost) {
|
while ($isPost) {
|
||||||
set_time_limit(300);
|
set_time_limit(300);
|
||||||
try {
|
try {
|
||||||
@@ -175,7 +176,11 @@ if ($currentStep == 4) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($error) || (isset($mysqlInfo) && !$mysqlInfo['match'])) {
|
if (
|
||||||
|
!empty($error)
|
||||||
|
|| (isset($mysqlInfo) && !$mysqlInfo['match'])
|
||||||
|
|| (isset($redisInfo) && !$redisInfo['match'])
|
||||||
|
) {
|
||||||
$pass = false;
|
$pass = false;
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
@@ -224,6 +229,9 @@ if (!empty($error) || (isset($mysqlInfo) && !$mysqlInfo['match'])) {
|
|||||||
if (!$mysqlInfo['match']) {
|
if (!$mysqlInfo['match']) {
|
||||||
echo sprintf('<div class="text-red-700 pt-10">MySQL version: %s is too low, please use the newest version of 5.7 or above.</div>', $mysqlInfo['version']);
|
echo sprintf('<div class="text-red-700 pt-10">MySQL version: %s is too low, please use the newest version of 5.7 or above.</div>', $mysqlInfo['version']);
|
||||||
}
|
}
|
||||||
|
if (!$redisInfo['match']) {
|
||||||
|
echo sprintf('<div class="text-red-700 pt-10">Redis version: %s is too low, please use 2.0.0 or above.</div>', $redisInfo['version']);
|
||||||
|
}
|
||||||
} elseif ($currentStep > $maxStep) {
|
} elseif ($currentStep > $maxStep) {
|
||||||
echo '<div class="text-green-900 text-6xl p-10">Congratulations, everything is ready!</div>';
|
echo '<div class="text-green-900 text-6xl p-10">Congratulations, everything is ready!</div>';
|
||||||
echo '<div class="mb-6">For questions, consult the upgrade log at: <code>' . $update->getLogFile() . '</code></div>';
|
echo '<div class="mb-6">For questions, consult the upgrade log at: <code>' . $update->getLogFile() . '</code></div>';
|
||||||
|
|||||||
@@ -1,5 +1,17 @@
|
|||||||
<?php
|
<?php
|
||||||
require "../include/bittorrent.php";
|
require "../include/bittorrent.php";
|
||||||
|
$cacheKey = 'nexus_rss';
|
||||||
|
$hashKey = md5(http_build_query($_GET));
|
||||||
|
$redis = $Cache->getRedis();
|
||||||
|
$cacheData = $redis->hGet($cacheKey, $hashKey);
|
||||||
|
if ($cacheData) {
|
||||||
|
$cacheData = unserialize($cacheData);
|
||||||
|
if (isset($cacheData['deadline']) && $cacheData['deadline'] > time()) {
|
||||||
|
do_log("rss get from cache");
|
||||||
|
header ("Content-type: text/xml");
|
||||||
|
die($cacheData['data']);
|
||||||
|
}
|
||||||
|
}
|
||||||
dbconn();
|
dbconn();
|
||||||
function hex_esc($matches) {
|
function hex_esc($matches) {
|
||||||
return sprintf("%02x", ord($matches[0]));
|
return sprintf("%02x", ord($matches[0]));
|
||||||
@@ -117,15 +129,12 @@ $url = get_protocol_prefix().$BASEURL;
|
|||||||
$year = substr($datefounded, 0, 4);
|
$year = substr($datefounded, 0, 4);
|
||||||
$yearfounded = ($year ? $year : 2007);
|
$yearfounded = ($year ? $year : 2007);
|
||||||
$copyright = "Copyright (c) ".$SITENAME." ".(date("Y") != $yearfounded ? $yearfounded."-" : "").date("Y").", all rights reserved";
|
$copyright = "Copyright (c) ".$SITENAME." ".(date("Y") != $yearfounded ? $yearfounded."-" : "").date("Y").", all rights reserved";
|
||||||
header ("Content-type: text/xml");
|
$xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>";
|
||||||
print("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
|
|
||||||
//The commented version passed feed validator at http://www.feedvalidator.org
|
//The commented version passed feed validator at http://www.feedvalidator.org
|
||||||
/*print('
|
/*print('
|
||||||
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom">');*/
|
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom">');*/
|
||||||
print('
|
$xml .= '<rss version="2.0">';
|
||||||
<rss version="2.0">');
|
$xml .= '<channel>
|
||||||
print('
|
|
||||||
<channel>
|
|
||||||
<title>' . addslashes($SITENAME.' Torrents'). '</title>
|
<title>' . addslashes($SITENAME.' Torrents'). '</title>
|
||||||
<link><![CDATA[' . $url . ']]></link>
|
<link><![CDATA[' . $url . ']]></link>
|
||||||
<description><![CDATA[' . addslashes('Latest torrents from '.$SITENAME.' - '.htmlspecialchars($SLOGAN)) . ']]></description>
|
<description><![CDATA[' . addslashes('Latest torrents from '.$SITENAME.' - '.htmlspecialchars($SLOGAN)) . ']]></description>
|
||||||
@@ -144,11 +153,11 @@ print('
|
|||||||
<width>100</width>
|
<width>100</width>
|
||||||
<height>100</height>
|
<height>100</height>
|
||||||
<description>' . addslashes($SITENAME.' Torrents') . '</description>
|
<description>' . addslashes($SITENAME.' Torrents') . '</description>
|
||||||
</image>');
|
</image>';
|
||||||
/*print('
|
/*print('
|
||||||
<atom:link href="'.$url.$_SERVER['REQUEST_URI'].'" rel="self" type="application/rss+xml" />');*/
|
<atom:link href="'.$url.$_SERVER['REQUEST_URI'].'" rel="self" type="application/rss+xml" />');*/
|
||||||
print('
|
//print('
|
||||||
');
|
//');
|
||||||
foreach ($list as $row)
|
foreach ($list as $row)
|
||||||
{
|
{
|
||||||
$title = "";
|
$title = "";
|
||||||
@@ -165,22 +174,25 @@ foreach ($list as $row)
|
|||||||
if (!empty($_GET['isize'])) $title .= "[".mksize($row['size'])."]";
|
if (!empty($_GET['isize'])) $title .= "[".mksize($row['size'])."]";
|
||||||
if (!empty($_GET['iuplder'])) $title .= "[".$author."]";
|
if (!empty($_GET['iuplder'])) $title .= "[".$author."]";
|
||||||
$content = format_comment($row['descr'], true, false, false, false);
|
$content = format_comment($row['descr'], true, false, false, false);
|
||||||
print(' <item>
|
$xml .= '<item>
|
||||||
<title><![CDATA['.$title.']]></title>
|
<title><![CDATA['.$title.']]></title>
|
||||||
<link>'.$itemurl.'</link>
|
<link>'.$itemurl.'</link>
|
||||||
<description><![CDATA['.$content.']]></description>
|
<description><![CDATA['.$content.']]></description>
|
||||||
');
|
';
|
||||||
//print(' <dc:creator>'.$author.'</dc:creator>');
|
//print(' <dc:creator>'.$author.'</dc:creator>');
|
||||||
print(' <author>'.$author.'@'.$_SERVER['HTTP_HOST'].' ('.$author.')</author>');
|
$xml .= '<author>'.$author.'@'.$_SERVER['HTTP_HOST'].' ('.$author.')</author>';
|
||||||
print('
|
$xml .= '<category domain="'.$url.'/torrents.php?cat='.$row['cat_id'].'">'.$row['cat_name'].'</category>
|
||||||
<category domain="'.$url.'/torrents.php?cat='.$row['cat_id'].'">'.$row['cat_name'].'</category>
|
|
||||||
<comments><![CDATA['.$url.'/details.php?id='.$row['id'].'&cmtpage=0#startcomments]]></comments>
|
<comments><![CDATA['.$url.'/details.php?id='.$row['id'].'&cmtpage=0#startcomments]]></comments>
|
||||||
<enclosure url="'.$itemdlurl.'" length="'.$row['size'].'" type="application/x-bittorrent" />
|
<enclosure url="'.$itemdlurl.'" length="'.$row['size'].'" type="application/x-bittorrent" />
|
||||||
<guid isPermaLink="false">'.preg_replace_callback('/./s', 'hex_esc', hash_pad($row['info_hash'])).'</guid>
|
<guid isPermaLink="false">'.preg_replace_callback('/./s', 'hex_esc', hash_pad($row['info_hash'])).'</guid>
|
||||||
<pubDate>'.date('r',strtotime($row['added'])).'</pubDate>
|
<pubDate>'.date('r',strtotime($row['added'])).'</pubDate>
|
||||||
</item>
|
</item>
|
||||||
');
|
';
|
||||||
}
|
}
|
||||||
print(' </channel>
|
$xml .= '</channel>
|
||||||
</rss>');
|
</rss>';
|
||||||
|
do_log("rss cache generated");
|
||||||
|
$redis->hSet($cacheKey, $hashKey, serialize(['data' => $xml, 'deadline' => time() + 300]));
|
||||||
|
header ("Content-type: text/xml");
|
||||||
|
echo $xml;
|
||||||
?>
|
?>
|
||||||
|
|||||||
Reference in New Issue
Block a user