This commit is contained in:
david 2021-09-05 14:45:46 +08:00
parent 0047826eff
commit 878238a91b
30 changed files with 47 additions and 55 deletions

1
.gitignore vendored
View File

@ -10,3 +10,4 @@
.env
/._.DS_Store
/.DS_Store
/php-cs-fixer.phar

View File

@ -3,7 +3,6 @@ namespace app\common;
/**
* 配置文件读写类
* @access private 常驻内存运行,禁止执行器调用
*/
class Config
{

View File

@ -26,12 +26,12 @@ class Constant
*/
const API_BASE = 'https://api.iyuu.cn';
const API = [
'login' => '/App.Api.Bind',
'sites' => '/App.Api.Sites',
'infohash'=> '/App.Api.Infohash',
'hash' => '/App.Api.Hash',
'notify' => '/App.Api.Notify',
'recommend' => '/Api/GetRecommendSites',
'login' => '/App.Api.Bind',
'sites' => '/App.Api.Sites',
'infohash' => '/App.Api.Infohash',
'hash' => '/App.Api.Hash',
'notify' => '/App.Api.Notify',
'recommend' => '/App.Api.GetRecommendSites',
'getSign' => '/App.Api.GetSign',
];
@ -76,7 +76,7 @@ class Constant
];
/**
* 下载种子,使用的请求方法
* 使用POST请求方法下载种子的站点
*/
const SITE_DOWNLOAD_METHOD_POST = ['hdsky', 'hdcity'];
}

View File

@ -78,28 +78,22 @@ class ICheck
public static function analysis(string $currentOs)
{
//检查版本
if(version_compare(PHP_VERSION, "7.2.0", "<"))
{
if (version_compare(PHP_VERSION, "7.2.0", "<")) {
exit('php version < 7.2.0');
}
//检查扩展
$waitExtends = static::$extends[$currentOs];
foreach ($waitExtends as $extend)
{
if (!extension_loaded($extend))
{
foreach ($waitExtends as $extend) {
if (!extension_loaded($extend)) {
exit("php_{$extend}.(dll/so) is not load,please check php.ini file");
}
}
//检查函数
$waitFunctions = static::$functions[$currentOs];
foreach ($waitFunctions as $func)
{
if (!function_exists($func))
{
foreach ($waitFunctions as $func) {
if (!function_exists($func)) {
exit("function $func may be disabled,please check disable_functions in php.ini");
}
}
}
}

View File

@ -65,7 +65,7 @@ class Curl
* @param bool $reset 是否重置Curl(默认true)
* @return ICurl
*/
public static function get($url, $data = array(), bool $reset = true): ICurl
public static function get(string $url, $data = array(), bool $reset = true): ICurl
{
return static::one($reset)->get($url, $data);
}
@ -78,7 +78,7 @@ class Curl
* @param bool $reset 是否重置Curl(默认true)
* @return ICurl
*/
public static function post($url, $data = array(), $asJson = false, bool $reset = true): ICurl
public static function post(string $url, $data = array(), bool $asJson = false, bool $reset = true): ICurl
{
static::one($reset);
if ($asJson) {

View File

@ -10,5 +10,4 @@ use Exception;
*/
class BusinessException extends Exception
{
}

View File

@ -7,6 +7,7 @@ use app\common\exception\BusinessException;
use app\common\Config as Conf;
use app\common\Constant;
use app\domain\Config;
/**
* Class Status
* @package app\controller

View File

@ -9,4 +9,4 @@ namespace app\domain;
interface CommandInterface
{
public function parse(array $param):string;
}
}

View File

@ -145,7 +145,8 @@ class Config
* 排除字段
* @param $data
*/
protected static function createDataExcludeKeys(&$data) {
protected static function createDataExcludeKeys(&$data)
{
if (is_array($data)) {
foreach ([Constant::config_filename, Constant::action] as $key) {
unset($data[$key]);

View File

@ -107,7 +107,7 @@ class Rss implements ConfigParserInterface
$sites = Config::getSites();
$sites = array_filter($sites, function ($k) use ($data) {
return in_array($k, $data);
},ARRAY_FILTER_USE_KEY);
}, ARRAY_FILTER_USE_KEY);
ksort($sites);
return $sites;

View File

@ -9,4 +9,4 @@ namespace app\domain;
interface ConfigParserInterface
{
public static function parser(string $uuid):array;
}
}

View File

@ -68,14 +68,14 @@ class Crontab
{
// 初始化目录
$sys_dir = [self::cron_dir, self::run_dir, self::pid_dir, self::lock_dir, self::log_dir];
array_walk($sys_dir, function ($v, $k){
array_walk($sys_dir, function ($v, $k) {
$dir = cron_path() . DIRECTORY_SEPARATOR . $v;
is_dir($dir) or mkdir($dir, 0777, true);
});
// 初始化计划任务文件[不同平台的配置会造成command错误需要重新解析命令]
$cron = Config::getCrontab();
array_walk($cron, function ($v, $k){
array_walk($cron, function ($v, $k) {
self::createHock($v);
});
}
@ -324,8 +324,7 @@ class Crontab
// 清理上次的日志
self::clearLogs($uuid);
// 运行命令
if(DIRECTORY_SEPARATOR === '\\')
{
if (DIRECTORY_SEPARATOR === '\\') {
pclose(popen('start /B '.$cmd.' >> '.$logFile, 'r'));
} else {
pclose(popen($cmd.' >> '.$logFile.' 2>&1 &', 'r'));

View File

@ -40,7 +40,7 @@ class Users
$api_url = Constant::API_BASE;
$api_action = Constant::API['sites'];
$url = sprintf('%s%s?sign=%s&version=%s', $api_url, $api_action, $token, IYUU_VERSION());
file_put_contents(db_path().'/_url.json',print_r($url, true));
file_put_contents(db_path().'/_url.json', print_r($url, true));
$res = $curl->get($url);
$rs = json_decode($res->response, true);
if (empty($res->response) || empty($rs) || !is_array($rs)) {
@ -49,7 +49,7 @@ class Users
$rs['msg'] = "无法访问{$api_url}接口请检查本地网络或重新创建容器网络模式改为HOST模式。";
return $rs;
}
file_put_contents(db_path().'/_response.json',print_r($res->response, true));
file_put_contents(db_path().'/_response.json', print_r($res->response, true));
if (isset($rs['ret']) && ($rs['ret'] === 200) && isset($rs['data']['sites']) && is_array($rs['data']['sites'])) {
$sites = array_column($rs['data']['sites'], null, 'site');
Conf::set('sites', $sites, Constant::config_format);
@ -131,7 +131,7 @@ class Users
//验证密码
$salt = $userProfile['salt'];
if ($userProfile['pass_hash'] !== self::createPassHash($password, $salt)) {
throw new BusinessException('密码错误,请重新输入!',250);
throw new BusinessException('密码错误,请重新输入!', 250);
}
return true;
}

View File

@ -1,8 +1,9 @@
<?php
use app\common\components\Curl as ICurl;
use app\domain\Config as domainConfig;
/**
* 返回IYUU当前版本号
* 返回IYUU客户端版本号
* @return string
*/
function IYUU_VERSION():string
@ -100,8 +101,7 @@ function check_token($token = ''):bool
*/
function run_exec($cmd = '')
{
if(DIRECTORY_SEPARATOR === '\\')
{
if (DIRECTORY_SEPARATOR === '\\') {
pclose(popen('start /B '.$cmd, 'r'));
} else {
pclose(popen($cmd, 'r'));
@ -119,8 +119,7 @@ function dataSize($bytes, string $delimiter = '', int $decimals = 2):string
{
$type = array('B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB');
$i = 0;
while($bytes >= 1024)
{
while ($bytes >= 1024) {
$bytes /= 1024;
$i++;
}

View File

@ -41,4 +41,4 @@ class ActionHook implements MiddlewareInterface
}
return $next($request);
}
}
}

View File

@ -25,4 +25,4 @@ class Test extends Model
* @var bool
*/
public $timestamps = false;
}
}

View File

@ -16,4 +16,4 @@ return [
'files' => [
base_path() . '/app/functions.php'
]
];
];

View File

@ -23,4 +23,4 @@ $builder->useAnnotations(true);
return $builder->build();*/
return new Webman\Container;
return new Webman\Container;

View File

@ -14,4 +14,4 @@
return [
];
];

View File

@ -14,4 +14,4 @@
return [
'' => app\common\exception\Handler::class,
];
];

View File

@ -28,4 +28,4 @@ return [
]
],
],
];
];

View File

@ -9,4 +9,4 @@ return [
//support\middleware\AuthCheckTest::class,
//support\middleware\AccessControlTest::class,
]
];
];

View File

@ -14,7 +14,6 @@
use Webman\Route;
Route::any('/test', function ($request) {
return response('test');
});

View File

@ -20,4 +20,4 @@ return [
'middleware' => [ // 静态文件中间件
support\middleware\StaticFile::class,
],
];
];

View File

@ -22,4 +22,4 @@ return [
'fallback_locale' => ['zh_CN', 'en'],
// 语言文件存放的文件夹
'path' => base_path() . '/resource/translations',
];
];

View File

@ -22,6 +22,5 @@ class send implements EventListenerInterface
*/
public function process(string $event):void
{
}
}

View File

@ -159,7 +159,7 @@ class AutoReseed
// 用户选择辅种的站点
self::$_sites = self::$conf['sites'];
// 对url拼接串进行预处理
array_walk(self::$_sites, function (&$v, $k){
array_walk(self::$_sites, function (&$v, $k) {
if (!empty($v['url_join'])) {
$url_join = http_build_query($v['url_join']);
$v['url_join'] = [$url_join];
@ -191,7 +191,7 @@ class AutoReseed
file_put_contents($lockFile, $data);
//注册一个会在php中止时执行的函数
register_shutdown_function(function () use (&$cron_name){
register_shutdown_function(function () use (&$cron_name) {
self::deletePid();
$lockFile = domainCrontab::getLockFile($cron_name);
is_file($lockFile) and unlink($lockFile);
@ -247,7 +247,7 @@ class AutoReseed
array_walk($list, function ($v, $k) {
echo microtime(true). $v . PHP_EOL;
});
$url = sprintf('%s?sign=%s&version=%s',Constant::API_BASE.Constant::API['sites'], Oauth::getSign(), self::VER);
$url = sprintf('%s?sign=%s&version=%s', Constant::API_BASE.Constant::API['sites'], Oauth::getSign(), self::VER);
$res = self::$curl->get($url);
$rs = json_decode($res->response, true);
$sites = empty($rs['data']['sites']) ? [] : $rs['data']['sites'];

View File

@ -318,4 +318,4 @@ class MoveTorrent extends AutoReseed
$desp .= $br.'*此消息将在3天后过期*。';
return static::ff($text, $desp);
}
}
}

View File

@ -5,6 +5,7 @@ use app\common\Constant;
use app\domain\ConfigParser\Spiders as domainSpiders;
use IYUU\Library\Rpc;
use IYUU\Library\Selector;
/**
* PT资源站基类
*/

View File

@ -258,7 +258,7 @@ function filter($filter = [], $torrent = array())
// NO2:分隔
$keywords = explode(',', $keyword);
// NO3:移除空白字符和预定义字符
array_walk($keywords, function (&$v, $k){
array_walk($keywords, function (&$v, $k) {
$v = trim($v);
});
// NO4:过滤空