标准化格式

This commit is contained in:
iyuu.cn
2020-01-22 10:47:24 +08:00
parent fcb2384949
commit f3b4deae4c
5 changed files with 98 additions and 100 deletions

View File

@ -109,7 +109,8 @@ class AutoReseed
/** /**
* 显示支持站点列表 * 显示支持站点列表
*/ */
private static function ShowTableSites(){ private static function ShowTableSites()
{
$list[] = 'gitee 源码仓库https://gitee.com/ledc/IYUUAutoReseed'; $list[] = 'gitee 源码仓库https://gitee.com/ledc/IYUUAutoReseed';
$list[] = 'github源码仓库https://github.com/ledccn/IYUUAutoReseed'; $list[] = 'github源码仓库https://github.com/ledccn/IYUUAutoReseed';
$list[] = '教程https://gitee.com/ledc/IYUUAutoReseed/tree/master/wiki'; $list[] = '教程https://gitee.com/ledc/IYUUAutoReseed/tree/master/wiki';
@ -130,14 +131,13 @@ class AutoReseed
ksort($json); ksort($json);
$json = json_encode($json, JSON_UNESCAPED_UNICODE); $json = json_encode($json, JSON_UNESCAPED_UNICODE);
$myfile = ROOT_PATH.DS.'config'.DS.'sites.json'; $myfile = ROOT_PATH.DS.'config'.DS.'sites.json';
$file_pointer = @fopen($myfile,"w"); $file_pointer = @fopen($myfile, "w");
$worldsnum = @fwrite($file_pointer,$json); $worldsnum = @fwrite($file_pointer, $json);
@fclose($file_pointer); @fclose($file_pointer);
} }
$data = []; $data = [];
$i = $j = $k = 0; $i = $j = $k = 0;
foreach($sites as $v) foreach ($sites as $v) {
{
// 控制多少列 // 控制多少列
if ($i > 4) { if ($i > 4) {
$k++; $k++;
@ -151,7 +151,7 @@ class AutoReseed
//输出表格 //输出表格
$table = new Table(); $table = new Table();
$table->setRows($data); $table->setRows($data);
echo($table->render()); echo($table->render());
} }
/** /**
* 连接远端RPC服务器 * 连接远端RPC服务器
@ -405,14 +405,14 @@ class AutoReseed
$hashArray['sign'] = Oauth::getSign(); $hashArray['sign'] = Oauth::getSign();
$hashArray['version'] = self::VER; $hashArray['version'] = self::VER;
// 写请求日志 // 写请求日志
wlog($hashArray,'hashString'); wlog($hashArray, 'hashString');
// 发起请求 // 发起请求
echo "正在提交辅种信息…… \n"; echo "正在提交辅种信息…… \n";
$res = $curl->post(self::$apiUrl . self::$endpoints['reseed'], $hashArray); $res = $curl->post(self::$apiUrl . self::$endpoints['reseed'], $hashArray);
$resArray = json_decode($res->response, true); $resArray = json_decode($res->response, true);
// 写返回日志 // 写返回日志
wlog($resArray,'reseed'); wlog($resArray, 'reseed');
// 判断返回值 // 判断返回值
if (isset($resArray['errmsg']) && ($resArray['errmsg'] == 'ok')) { if (isset($resArray['errmsg']) && ($resArray['errmsg'] == 'ok')) {
@ -475,7 +475,7 @@ class AutoReseed
$details_page = str_replace('{}', $value['torrent_id'], 'details.php?id={}&hit=1'); $details_page = str_replace('{}', $value['torrent_id'], 'details.php?id={}&hit=1');
$_url = 'https://' .$sites[$sitesID]['base_url']. '/' .$details_page; $_url = 'https://' .$sites[$sitesID]['base_url']. '/' .$details_page;
} }
wlog('clients_'.$k."\n".$downloadDir."\n"."-------因当前" .$sites[$sitesID]['site']. "站点触发流控,已跳过!! {$_url} \n\n",'reseedLimit'); wlog('clients_'.$k."\n".$downloadDir."\n"."-------因当前" .$sites[$sitesID]['site']. "站点触发流控,已跳过!! {$_url} \n\n", 'reseedLimit');
self::$wechatMsg['reseedSkip']++; self::$wechatMsg['reseedSkip']++;
continue; continue;
} }
@ -588,13 +588,13 @@ class AutoReseed
if ($ret) { if ($ret) {
// 成功的种子 // 成功的种子
wlog($url."\n", $value['info_hash'], self::$cacheHash); wlog($url."\n", $value['info_hash'], self::$cacheHash);
wlog($url."\n",'reseedSuccess'); wlog($url."\n", 'reseedSuccess');
// 成功累加 // 成功累加
self::$wechatMsg['reseedSuccess']++; self::$wechatMsg['reseedSuccess']++;
continue; continue;
} else { } else {
// 失败的种子 // 失败的种子
wlog($url."\n",'reseedError'); wlog($url."\n", 'reseedError');
// 失败累加 // 失败累加
self::$wechatMsg['reseedError']++; self::$wechatMsg['reseedError']++;
continue; continue;

View File

@ -124,8 +124,7 @@ class Table
$this->rows = $rows; $this->rows = $rows;
$this->cellAlign = $align; $this->cellAlign = $align;
foreach ($rows as $row) foreach ($rows as $row) {
{
$this->checkColWidth($row); $this->checkColWidth($row);
} }
} }
@ -138,12 +137,9 @@ class Table
*/ */
protected function checkColWidth($row) protected function checkColWidth($row)
{ {
if (is_array($row)) if (is_array($row)) {
{ foreach ($row as $key => $cell) {
foreach ($row as $key => $cell) if (!isset($this->colWidth[$key]) || strlen($cell) > $this->colWidth[$key]) {
{
if (!isset($this->colWidth[$key]) || strlen($cell) > $this->colWidth[$key])
{
$this->colWidth[$key] = strlen($cell); $this->colWidth[$key] = strlen($cell);
} }
} }
@ -159,12 +155,9 @@ class Table
*/ */
public function addRow($row, $first = false) public function addRow($row, $first = false)
{ {
if ($first) if ($first) {
{
array_unshift($this->rows, $row); array_unshift($this->rows, $row);
} } else {
else
{
$this->rows[] = $row; $this->rows[] = $row;
} }
@ -193,8 +186,7 @@ class Table
$style = $this->getStyle($pos); $style = $this->getStyle($pos);
$array = []; $array = [];
foreach ($this->colWidth as $width) foreach ($this->colWidth as $width) {
{
$array[] = str_repeat($style[1], $width + 2); $array[] = str_repeat($style[1], $width + 2);
} }
@ -211,17 +203,14 @@ class Table
$style = $this->getStyle('cell'); $style = $this->getStyle('cell');
$content = $this->renderSeparator('top'); $content = $this->renderSeparator('top');
foreach ($this->header as $key => $header) foreach ($this->header as $key => $header) {
{
$array[] = ' ' . str_pad($header, $this->colWidth[$key], $style[1], $this->headerAlign); $array[] = ' ' . str_pad($header, $this->colWidth[$key], $style[1], $this->headerAlign);
} }
if (!empty($array)) if (!empty($array)) {
{
$content .= $style[0] . implode(' ' . $style[2], $array) . ' ' . $style[3] . PHP_EOL; $content .= $style[0] . implode(' ' . $style[2], $array) . ' ' . $style[3] . PHP_EOL;
if ($this->rows) if ($this->rows) {
{
$content .= $this->renderSeparator('middle'); $content .= $this->renderSeparator('middle');
} }
} }
@ -231,12 +220,9 @@ class Table
protected function getStyle($style) protected function getStyle($style)
{ {
if ($this->format[$this->style]) if ($this->format[$this->style]) {
{
$style = $this->format[$this->style][$style]; $style = $this->format[$this->style][$style];
} } else {
else
{
$style = [' ', ' ', ' ', ' ']; $style = [' ', ' ', ' ', ' '];
} }
@ -251,8 +237,7 @@ class Table
*/ */
public function render($dataList = []) public function render($dataList = [])
{ {
if ($dataList) if ($dataList) {
{
$this->setRows($dataList); $this->setRows($dataList);
} }
@ -260,35 +245,26 @@ class Table
$content = $this->renderHeader(); $content = $this->renderHeader();
$style = $this->getStyle('cell'); $style = $this->getStyle('cell');
if ($this->rows) if ($this->rows) {
{ foreach ($this->rows as $row) {
foreach ($this->rows as $row) if (is_string($row) && '-' === $row) {
{
if (is_string($row) && '-' === $row)
{
$content .= $this->renderSeparator('middle'); $content .= $this->renderSeparator('middle');
} } elseif (is_scalar($row)) {
elseif (is_scalar($row))
{
$content .= $this->renderSeparator('cross-top'); $content .= $this->renderSeparator('cross-top');
$array = str_pad($row, 3 * (count($this->colWidth) - 1) + array_reduce($this->colWidth, function ($a, $b) { $array = str_pad($row, 3 * (count($this->colWidth) - 1) + array_reduce($this->colWidth, function ($a, $b) {
return $a + $b; return $a + $b;
})); }));
$content .= $style[0] . ' ' . $array . ' ' . $style[3] . PHP_EOL; $content .= $style[0] . ' ' . $array . ' ' . $style[3] . PHP_EOL;
$content .= $this->renderSeparator('cross-bottom'); $content .= $this->renderSeparator('cross-bottom');
} } else {
else
{
$array = []; $array = [];
foreach ($row as $key => $val) foreach ($row as $key => $val) {
{
$array[] = ' ' . str_pad($val, $this->colWidth[$key], ' ', $this->cellAlign); $array[] = ' ' . str_pad($val, $this->colWidth[$key], ' ', $this->cellAlign);
} }
$content .= $style[0] . implode(' ' . $style[2], $array) . ' ' . $style[3] . PHP_EOL; $content .= $style[0] . implode(' ' . $style[2], $array) . ' ' . $style[3] . PHP_EOL;
} }
} }
} }
@ -297,4 +273,4 @@ class Table
return $content; return $content;
} }
} }

View File

@ -198,16 +198,17 @@ function convertToMB($from)
/** /**
* 字节数Byte转换为KB、MB、GB、TB * 字节数Byte转换为KB、MB、GB、TB
* *
*/ */
function getFilesize($num){ function getFilesize($num)
{
$p = 0; $p = 0;
$format='bytes'; $format='bytes';
if($num>0 && $num<1024){ if ($num>0 && $num<1024) {
$p = 0; $p = 0;
return number_format($num).' '.$format; return number_format($num).' '.$format;
} }
if($num>=1024 && $num<pow(1024, 2)){ if ($num>=1024 && $num<pow(1024, 2)) {
$p = 1; $p = 1;
$format = 'KB'; $format = 'KB';
} }
@ -323,7 +324,8 @@ function filter($site = '', $torrent = array())
/** /**
* 日志记录函数 * 日志记录函数
*/ */
function wlog($data='',$name = '',$path = ''){ function wlog($data='', $name = '', $path = '')
{
// 数据转换 // 数据转换
if (is_bool($data)) { if (is_bool($data)) {
$show_data=$data ? 'true' : 'false'; $show_data=$data ? 'true' : 'false';
@ -336,8 +338,8 @@ function wlog($data='',$name = '',$path = ''){
$dir = $path===''? TORRENT_PATH . 'cache' . DS : $path; $dir = $path===''? TORRENT_PATH . 'cache' . DS : $path;
IFile::mkdir($dir); IFile::mkdir($dir);
$myfile = $dir.$name.'.txt'; $myfile = $dir.$name.'.txt';
$file_pointer = @fopen($myfile,"a"); $file_pointer = @fopen($myfile, "a");
$worldsnum = @fwrite($file_pointer,$show_data); $worldsnum = @fwrite($file_pointer, $show_data);
@fclose($file_pointer); @fclose($file_pointer);
return $worldsnum; return $worldsnum;
} }
@ -389,22 +391,23 @@ function oddFilter($var)
*/ */
function evenFilter($var) function evenFilter($var)
{ {
// 返回$var最后一个二进制位 // 返回$var最后一个二进制位
// 为0则保留偶数的二进制的最后一位肯定是0 // 为0则保留偶数的二进制的最后一位肯定是0
return(!($var & 1)); return(!($var & 1));
} }
/** /**
* 发布员签名 * 发布员签名
* 注意同时配置iyuu.cn与secret时优先使用secret。 * 注意同时配置iyuu.cn与secret时优先使用secret。
*/ */
function sign( $timestamp ){ function sign($timestamp)
global $configALL; {
// 爱语飞飞 global $configALL;
$token = isset($configALL['iyuu.cn']) && $configALL['iyuu.cn'] ? $configALL['iyuu.cn'] : ''; // 爱语飞飞
// 鉴权 $token = isset($configALL['iyuu.cn']) && $configALL['iyuu.cn'] ? $configALL['iyuu.cn'] : '';
$token = isset($configALL['secret']) && $configALL['secret'] ? $configALL['secret'] : $token; // 鉴权
return sha1($timestamp . $token); $token = isset($configALL['secret']) && $configALL['secret'] ? $configALL['secret'] : $token;
return sha1($timestamp . $token);
} }
/** /**
@ -412,15 +415,17 @@ function sign( $timestamp ){
* token算法IYUU + uid + T + sha1(openid+time+盐) * token算法IYUU + uid + T + sha1(openid+time+盐)
* @param string $token 用户请求token * @param string $token 用户请求token
*/ */
function getUid($token){ function getUid($token)
//验证是否IYUU开头strpos($token,'T')<15,token总长度小于60(40+10+5) {
return (strlen($token)<60)&&(strpos($token,'IYUU')===0)&&(strpos($token,'T')<15) ? substr($token,4,strpos($token,'T')-4): false; //验证是否IYUU开头strpos($token,'T')<15,token总长度小于60(40+10+5)
return (strlen($token)<60)&&(strpos($token, 'IYUU')===0)&&(strpos($token, 'T')<15) ? substr($token, 4, strpos($token, 'T')-4): false;
} }
/** /**
* 显示支持的站点列表 * 显示支持的站点列表
*/ */
function ShowTableSites($dir = 'Protocols',$filter = array()){ function ShowTableSites($dir = 'Protocols', $filter = array())
{
// 过滤的文件 // 过滤的文件
switch ($dir) { switch ($dir) {
case 'Protocols': case 'Protocols':
@ -434,31 +439,30 @@ function ShowTableSites($dir = 'Protocols',$filter = array()){
break; break;
} }
$data = []; $data = [];
$i = $j = $k = 0; $i = $j = $k = 0;
foreach(glob(APP_PATH.$dir.DS.'*.php') as $key => $start_file) foreach (glob(APP_PATH.$dir.DS.'*.php') as $key => $start_file) {
{ $start_file = str_replace("\\", "/", $start_file);
$start_file = str_replace("\\","/",$start_file); $offset = strripos($start_file, '/');
$offset = strripos($start_file,'/'); if ($offset===false) {
if ($offset===false) { $start_file = substr($start_file, 0, -4);
$start_file = substr($start_file,0,-4); } else {
} else { $start_file = substr($start_file, $offset+1, -4);
$start_file = substr($start_file,$offset+1,-4);
} }
// 过滤示例、过滤解码接口 // 过滤示例、过滤解码接口
if (in_array($start_file, $filter)) { if (in_array($start_file, $filter)) {
continue; continue;
} }
// 控制多少列 // 控制多少列
if ($i > 4) { if ($i > 4) {
$k++; $k++;
$i = 0; $i = 0;
} }
$i++; $i++;
$j++; $j++;
$data[$k][] = $j.". ".$start_file; $data[$k][] = $j.". ".$start_file;
} }
//输出表格 //输出表格
$table = new Table(); $table = new Table();
$table->setRows($data); $table->setRows($data);
echo($table->render()); echo($table->render());
} }

View File

@ -43,6 +43,24 @@ return array(
'/sda1' => '/volume1', '/sda1' => '/volume1',
), ),
), ),
'filter' => array(
'size'=>array(
'min' => '1GB',
'max' => '280GB',
),
'seeders'=>array(
'min' => 1,
'max' => 3,
),
'leechers'=>array(
'min' => 0,
'max' => 10000,
),
'completed'=>array(
'min' => 0,
'max' => 10000,
),
),
'CONNECTTIMEOUT'=> 60, 'CONNECTTIMEOUT'=> 60,
'TIMEOUT' => 600, 'TIMEOUT' => 600,
), ),

View File

@ -45,7 +45,7 @@ if (is_file(ROOT_PATH . "/config/sites.json")) {
require_once ROOT_PATH . '/vendor/autoload.php'; require_once ROOT_PATH . '/vendor/autoload.php';
global $argv; global $argv;
$start_file = str_replace("\\","/",trim($argv[0])); $start_file = str_replace("\\", "/", trim($argv[0]));
if( substr($start_file,-8)==="init.php" ){ if (substr($start_file, -8)==="init.php") {
require_once __DIR__ . '/iyuu.php'; require_once __DIR__ . '/iyuu.php';
} }