diff --git a/.env.example b/.env.example index 63cf76e..1227151 100644 --- a/.env.example +++ b/.env.example @@ -1,5 +1,5 @@ proxy= -#Tor的Socks5代理 +#Tor的Socks5代理,如 192.168.1.1:1080 RedisHost= #Redis主机名 @@ -19,5 +19,16 @@ ZlibraryLogin=loginzlib2vrak5zzpcocc3ouizykn6k5qecgj2tzlnab5wcbqhembyd.onion Zlibrary=bookszlibb74ugqojhzhg2a63w5i2atv5bqarulgczawnbmsb6s6qead.onion #除非Zlib的洋葱域名改变否则无需更改 -version=1.0.1 -#无需更改 \ No newline at end of file +reg_url="https://zh.singlelogin.rs/registration" +#注册按钮的链接 + +public_login=zh.singlelogin.rs +#公网登录域名 + +public_url=zh.z-library.rs +#公网域名 + +copyright=MimirLib +copyright_url="https://mimir.pp.ua" +version=1.2.2 +#无需更改 diff --git a/.gitignore b/.gitignore index b3da0af..294c86a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ .env -.history \ No newline at end of file +.history +runtime/* +books/* diff --git a/app/controller/File.php b/app/controller/File.php index 2f4777d..dc24fd8 100644 --- a/app/controller/File.php +++ b/app/controller/File.php @@ -38,20 +38,33 @@ class File $id=$request->cookie('id', 'blank'); $key=$request->cookie('key', 'blank'); $path=$request->input('path','blank'); + $tor=$request->cookie('tor', 'false'); if($key=='blank' || $id=='blank'){ return json(['code'=>509,'msg'=>'未登录或参数错误']); } $auth=array('remix_userid'=>"$id",'remix_userkey'=>"$key",'siteLanguageV2'=>'zh','selectedSiteMode'=>'books'); - $url='http://'.getenv('Zlibrary')."$path"; - $get=Http::withProxy('socks5h://'.getenv('proxy'))->withCookies($auth,getenv('Zlibrary')); + + $host=getenv('public_url'); + $httpquery=Http::timeout(60); + if($tor=='true'){ + $host=getenv('Zlibrary'); + $httpquery=$httpquery->withProxy('socks5h://'.getenv('proxy')); + } + + $url='http://'.$host.$path; + $get=$httpquery->withRedirect(['max'=> 5,'track_redirects' => true])->withCookies($auth,$host); $head=$get->head($url); - $ContentLength=(int)$head->header('Content-Length'); + $ContentLength=(int)$head->header('Content-Length'); $size=round(($ContentLength/1048576),2); + $redirectback=explode(', ',$head->header('X-Guzzle-Redirect-History')); + $outurl=end($redirectback); if($size>=30){ - return json(['code'=>500,'msg'=>'文件太大了!']); + return json(['code'=>500,'msg'=>'文件太大了!','url'=>$outurl]); } if($head->header('Content-Type')=='text/html; charset=UTF-8'){ - return json(['code'=>404,'msg'=>'链接错误']); + # print_r($head); + # return json(['code'=>404,'msg'=>'链接错误']); + return json(['code'=>808,'msg'=>$outurl]); } $redis = Redis::connection('default'); $name=base64_encode($path); @@ -98,4 +111,4 @@ class File } -} \ No newline at end of file +} diff --git a/app/controller/IndexController.php b/app/controller/IndexController.php index d54f0ed..8d9bc80 100644 --- a/app/controller/IndexController.php +++ b/app/controller/IndexController.php @@ -19,6 +19,8 @@ class IndexController $response = response(); $id=$request->cookie('id', 'blank'); $key=$request->cookie('key', 'blank'); + $tor=$request->cookie('tor', 'false'); + if($key=='blank' || $id=='blank'){ return redirect('/login'); } @@ -34,29 +36,47 @@ class IndexController $response->withBody($redis->hget($rpath,'body')); return $response; } - - $url='http://'.getenv('Zlibrary').$path; - $auth=array('remix_userid'=>"$id",'remix_userkey'=>"$key",'siteLanguageV2'=>'zh','selectedSiteMode'=>'books'); - $return = Http::withProxy('socks5h://'.getenv('proxy'))->withCookies($auth,getenv('Zlibrary'))->get($url); - $response->withHeaders($return->headers()); + + $host=getenv('public_url'); + $httpquery=Http::timeout(60); + $onion=''; + $torstatus='Off'; + if($tor=='true'){ + $host=getenv('Zlibrary'); + $httpquery=$httpquery->withProxy('socks5h://'.getenv('proxy')); + $onion=''; + $torstatus='On'; + } + + $url='http://'.$host.$path; + + $auth=array('remix_userid'=>"$id",'remix_userkey'=>"$key",'siteLanguageV2'=>'zh','siteLanguage'=>'zh','selectedSiteMode'=>'books'); + $return = $httpquery->withCookies($auth,$host)->get($url); $back=$return->body(); if($return->header('Content-Type')=='text/html; charset=UTF-8'){ $ver=getenv('version'); + $copyright=getenv('copyright'); + $copyright_url=getenv('copyright_url'); + $front= << - Zlibrary Proxy(v$ver) UserID:$id [退出账号] [PublicMirrorsNetwork] + Zlibrary Proxy(v$ver) UserID:$id [$onion Tor $torstatus] [退出账号] [$copyright]