标准化格式

master
iyuu.cn 5 years ago
parent fcb2384949
commit f3b4deae4c
  1. 22
      app/AutoReseed.php
  2. 68
      app/Library/Table.php
  3. 86
      app/helper.php
  4. 18
      config/config.sample.php
  5. 4
      init.php

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

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

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

@ -43,6 +43,24 @@ return array(
'/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,
'TIMEOUT' => 600,
),

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

Loading…
Cancel
Save