This commit is contained in:
2024-06-21 20:30:44 +08:00
parent ea68301ae2
commit 60e0273d25
8 changed files with 205 additions and 72 deletions
+61 -11
View File
@@ -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='<svg style="margin-bottom: -4px;" t="1718896386758" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="9713" width="24" height="24"><path d="M512 597.333333C469.333333 597.333333 384 640 384 682.666667 384 768 512 768 512 768L512 725.333333C488.533333 725.333333 469.333333 706.133333 469.333333 682.666667 469.333333 659.2 488.533333 640 512 640L512 597.333333M512 810.666667C512 810.666667 341.333333 789.333333 341.333333 704 341.333333 576 469.333333 544 512 544L512 490.666667C469.333333 490.666667 298.666667 554.666667 298.666667 682.666667 298.666667 853.333333 512 853.333333 512 853.333333L512 810.666667M429.653333 299.946667 480.426667 322.56C498.773333 218.453333 547.84 149.333333 547.84 149.333333 529.493333 193.28 517.546667 229.546667 509.866667 258.133333 561.493333 151.466667 666.026667 85.333333 666.026667 85.333333 615.68 135.68 578.56 190.293333 553.386667 235.946667 620.8 164.266667 714.24 117.333333 714.24 117.333333 599.466667 190.72 547.84 307.2 535.04 339.626667L558.506667 343.04C558.506667 365.226667 558.506667 385.706667 569.173333 401.92 601.6 482.56 768 489.386667 768 682.666667 768 875.946667 596.053333 938.666667 504.746667 938.666667 413.44 938.666667 213.333333 897.28 213.333333 682.666667 213.333333 468.053333 424.533333 466.346667 462.08 380.586667 467.2 364.373333 429.653333 299.946667 429.653333 299.946667Z" p-id="9714" fill="#8a8a8a"></path></svg>';
$torstatus='<span>Off</span>';
if($tor=='true'){
$host=getenv('Zlibrary');
$httpquery=$httpquery->withProxy('socks5h://'.getenv('proxy'));
$onion='<svg style="margin-bottom: -4px;" t="1718896386758" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="9713" width="24" height="24"><path d="M512 597.333333C469.333333 597.333333 384 640 384 682.666667 384 768 512 768 512 768L512 725.333333C488.533333 725.333333 469.333333 706.133333 469.333333 682.666667 469.333333 659.2 488.533333 640 512 640L512 597.333333M512 810.666667C512 810.666667 341.333333 789.333333 341.333333 704 341.333333 576 469.333333 544 512 544L512 490.666667C469.333333 490.666667 298.666667 554.666667 298.666667 682.666667 298.666667 853.333333 512 853.333333 512 853.333333L512 810.666667M429.653333 299.946667 480.426667 322.56C498.773333 218.453333 547.84 149.333333 547.84 149.333333 529.493333 193.28 517.546667 229.546667 509.866667 258.133333 561.493333 151.466667 666.026667 85.333333 666.026667 85.333333 615.68 135.68 578.56 190.293333 553.386667 235.946667 620.8 164.266667 714.24 117.333333 714.24 117.333333 599.466667 190.72 547.84 307.2 535.04 339.626667L558.506667 343.04C558.506667 365.226667 558.506667 385.706667 569.173333 401.92 601.6 482.56 768 489.386667 768 682.666667 768 875.946667 596.053333 938.666667 504.746667 938.666667 413.44 938.666667 213.333333 897.28 213.333333 682.666667 213.333333 468.053333 424.533333 466.346667 462.08 380.586667 467.2 364.373333 429.653333 299.946667 429.653333 299.946667Z" p-id="9714" fill="#7A5EB7"></path></svg>';
$torstatus='<span style="color:green;">On</span>';
}
$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= <<<EOF
<html><body>
<center>
<div style="background-color: bisque;color: black;position:fixed!important;font-size:1.8rem;line-height:1.618;z-index:9999!important;text-align:-webkit-center;">
Zlibrary Proxy(v$ver) UserID:$id <a style="color: coral;" href="/login/logout">[退出账号]</a><a style="color: black;" href="//www.pmnet.gq" target="_blank_pmnet"> [PublicMirrorsNetwork]</a>
Zlibrary Proxy(v$ver) UserID:$id <a href='/login/switchtor?to=$path'>[$onion Tor $torstatus]</a> <a style="color: coral;" href="/login/logout">[退出账号]</a><a style="color: black;" href="$copyright_url" target="_blank_pmnet"> [$copyright]</a>
</div>
</center></body></html>
EOF;
$back=$front.$back;
}
$backhead=$return->headers();
$backhead['Content-Length']=strlen($back);
$response->withHeaders($backhead);
/**Make Cache */
if($path=='/resources/build/global.js?0.495' || $path=='/resources/build/global.css?0.495' || $path=='/resources/ext/freewall.js' || preg_match("/^image*/",$return->header('Content-Type')) ){
$redis->hset($rpath,'CT',json_encode($return->headers()));
$redis->hset($rpath,'CT',json_encode($backhead));
$redis->hset($rpath,'body',$back);
$redis->expire($rpath,43200);
}
@@ -76,6 +96,8 @@ EOF;
$username=$request->post('name','blank');
$password=$request->post('password','blank');
$code=$request->post('code','blank');
$tor=$request->post('tor',false);
if($username=='blank' || $password=='blank' || $code=='blank'){
return json(['code'=>500, 'msg'=>'缺少参数']);
}
@@ -102,8 +124,15 @@ EOF;
return json(['code' => 400, 'msg' => '输入的验证码不正确']);
}
$url='http://'.getenv('ZlibraryLogin').'/rpc.php';
$response = Http::withProxy('socks5h://'.getenv('proxy'))->post("$url", ['isModal' => true,'email'=>"$username",'password'=>"$password",'site_mode'=>'books','action'=>'login','redirectUrl'=>'','isSinglelogin'=>'1','isTorVersion'=>'1','gg_json_mode'=>'1']);
$url='https://'.getenv('public_login').'/rpc.php';
$response=Http::timeout(60);
if($tor=='true'){
$url='http://'.getenv('ZlibraryLogin').'/rpc.php';
$response=$response->withProxy('socks5h://'.getenv('proxy'));
}
$response = $response->post("$url", ['isModal' => true,'email'=>"$username",'password'=>"$password",'site_mode'=>'books','action'=>'login','redirectUrl'=>'','isSinglelogin'=>'1','isTorVersion'=>'1','gg_json_mode'=>'1']);
#print_r($response);
if(!$response->successful()){
return json(['code' => 501, 'msg' => '登陆失败,服务端错误']);
}
@@ -112,7 +141,13 @@ EOF;
if(isset($return->response->validationError)){
return json(['code' => 502, 'msg' => 'Zlib登陆失败:'.$return->response->message]);
}
$url=parse_url($return->response->params)['query'];
#print_r($return->response);
$rawparma=$return->response->params;
if($tor=='true'){
$rawparma=$return->response->priorityRedirectUrl;
}
$url=parse_url($rawparma)['query'];
#print_r($url);
$queryParts = explode('&', $url);
$params = array();
foreach ($queryParts as $param) {
@@ -120,7 +155,7 @@ EOF;
$params[$item[0]] = $item[1];
}
return json(['code'=>200,'msg'=>'登陆成功','userid'=>$params['remix_userid']])->cookie('id', $params['remix_userid'],43200,'/')->cookie('key', $params['remix_userkey'],43200,'/');
return json(['code'=>200,'msg'=>'登陆成功','userid'=>$params['remix_userid']])->cookie('id', $params['remix_userid'],43200,'/')->cookie('key', $params['remix_userkey'],43200,'/')->cookie('tor', $tor,43200,'/');
}
public function code(Request $request)
{
@@ -150,6 +185,8 @@ EOF;
$id=$request->cookie('id', 'blank');
$key=$request->cookie('key', 'blank');
$tor=$request->cookie('tor', 'false');
if($key=='blank' || $id=='blank'){
return redirect('/login');
}
@@ -158,6 +195,7 @@ EOF;
'id' => $id,
'key'=> $key,
'path'=> $path,
'tor'=>$tor,
]);
return view('index');
@@ -169,5 +207,17 @@ EOF;
return response()->file(base_path() . '/app/controller/IndexController.php');
}
public function tor(Request $request)
{
$to=$request->input('to','/');
$tor=$request->cookie('tor','false');
if($tor=='true'){
$tor='false';
}else{
$tor='true';
}
return redirect($to)->cookie('tor', $tor,43200,'/');
}
}