update index.php.
This commit is contained in:
parent
f2e9e76a93
commit
fdb55db9ed
55
index.php
55
index.php
@ -1,8 +1,9 @@
|
||||
<?php
|
||||
ini_set('user_agent', 'GeMCAPI/4.1.0 (GeMC API Sync 1.1.0;Release)');
|
||||
$active=array('mojang/launchermeta/mc/game/version_manifest.json');
|
||||
$type=array('.com');
|
||||
//[0]:mojang
|
||||
function url_exists($url) {
|
||||
function url_exists($url){
|
||||
$ch = curl_init();
|
||||
curl_setopt ($ch, CURLOPT_URL, $url);
|
||||
curl_setopt($ch, CURLOPT_NOBODY, 1);
|
||||
@ -10,7 +11,7 @@ function url_exists($url) {
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, 3);
|
||||
curl_exec($ch);
|
||||
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
if($http_code == 200) {
|
||||
if($http_code == 200){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@ -46,12 +47,12 @@ function get_online_url($file,$id){
|
||||
return $str;
|
||||
}
|
||||
function check_file_update($file,$dir,$url){
|
||||
$time=time()-filemtime($file);
|
||||
$time=time()-@filemtime($file);
|
||||
if($time<86400){//检查文件是否超出过期期限(1天,86400秒)
|
||||
echo file_get_contents($file);
|
||||
}else{
|
||||
if(url_exists($url.'/'.str_replace($dir,'',$file))){//防止源无法访问而损坏文件
|
||||
if(file_get_contents($url.'/'.str_replace($dir,'',$file))==file_get_contents($file)){
|
||||
if(file_get_contents($url.'/'.str_replace($dir,'',$file))==@file_get_contents($file)){
|
||||
echo file_get_contents($file);
|
||||
}else{
|
||||
echo file_get_contents($url.'/'.str_replace($dir,'',$file));
|
||||
@ -64,6 +65,26 @@ function check_file_update($file,$dir,$url){
|
||||
}
|
||||
}
|
||||
}
|
||||
function check_file_update_adv($file,$url,$check_url){
|
||||
$time=time()-@filemtime($file);
|
||||
if($time<86400){//检查文件是否超出过期期限(1天,86400秒)
|
||||
echo file_get_contents($file);
|
||||
}else{
|
||||
if(url_exists_2($check_url)){//防止源无法访问而损坏文件
|
||||
if(file_get_contents($url)==@file_get_contents($file)){
|
||||
echo file_get_contents($file);
|
||||
}else{
|
||||
echo @file_get_contents($url);
|
||||
$jsonwrite = fopen($file, "w") or die('{"wikis":"https://gitee.com/ghink/gemcapi/wikis","code":502,"server_time":"'.date("Y-m-d h:i:s").'"}');
|
||||
fwrite($jsonwrite,file_get_contents($url));
|
||||
fclose($jsonwrite);
|
||||
}
|
||||
}else{
|
||||
echo file_get_contents($file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function download_file($url,$file,$other){//下载文件
|
||||
system('python download.py --url "'.$url.'" --file "'.$file.'" --other "'.$other.'"');
|
||||
}
|
||||
@ -82,19 +103,36 @@ if($_GET['error']!=""){
|
||||
}
|
||||
}
|
||||
}else{//无需更新的文件,直接重定向
|
||||
header('Location: http://1.gemcapi.ghink.net:10000/'.$_GET['path']);
|
||||
if(strstr($_GET['path'],'forge/minecraft')!=False){//特殊返回目录
|
||||
echo @file_get_contents($_GET['path']);
|
||||
}else{
|
||||
header('Location: http://1.gemcapi.ghink.net:10000/'.$_GET['path']);
|
||||
}
|
||||
}
|
||||
}elseif(is_dir($_GET['path'])){
|
||||
//目录存在
|
||||
header('Location: http://1.gemcapi.ghink.net:10000/'.$_GET['path']);
|
||||
if(strstr($_GET['path'],'forge/minecraft')!=False){//特殊目录返回
|
||||
check_file_update_adv('forge/minecraft/index.json','https://download.mcbbs.net/forge/minecraft','https://download.mcbbs.net/maven/net/minecraftforge/forge/1.7.10-10.13.0.1151/forge-1.7.10-10.13.0.1151-installer.jar');
|
||||
}else{
|
||||
header('Location: http://1.gemcapi.ghink.net:10000/'.$_GET['path']);
|
||||
}
|
||||
}else{
|
||||
//目录或文件不存在
|
||||
if(strstr($_GET['path'],'forge/')!=False){//特殊Forge,采用二级源
|
||||
if(url_exists_2('https://download.mcbbs.net/maven/net/minecraftforge/forge/1.7.10-10.13.0.1151/forge-1.7.10-10.13.0.1151-installer.jar')){
|
||||
download_file('https://download.mcbbs.net/'.$_GET['path'],$_GET['path'],'');
|
||||
header('Location: http://1.gemcapi.ghink.net:10000/'.$_GET['path']);
|
||||
if(strstr($_GET['path'],'forge/minecraft')!=False){//forge/minecraft目录特殊同步
|
||||
if($_GET['path']=='forge/minecraft'){
|
||||
check_file_update_adv('forge/minecraft/index.json','https://download.mcbbs.net/forge/minecraft','https://download.mcbbs.net/maven/net/minecraftforge/forge/1.7.10-10.13.0.1151/forge-1.7.10-10.13.0.1151-installer.jar');
|
||||
}else{
|
||||
check_file_update_adv($_GET['path'],'https://download.mcbbs.net/'.$_GET['path'],'https://download.mcbbs.net/maven/net/minecraftforge/forge/1.7.10-10.13.0.1151/forge-1.7.10-10.13.0.1151-installer.jar');
|
||||
}
|
||||
}else{
|
||||
download_file('https://download.mcbbs.net/'.$_GET['path'],$_GET['path'],'');
|
||||
header('Location: http://1.gemcapi.ghink.net:10000/'.$_GET['path']);
|
||||
}
|
||||
}else{
|
||||
echo '{"wikis":"https://gitee.com/ghink/gemcapi/wikis","code":404,"server_time":"'.date("Y-m-d h:i:s").'"}';
|
||||
header('HTTP/1.1 404 Not Found');
|
||||
}
|
||||
}else{
|
||||
if(get_main_domain($_GET['path'])=='mojang'){//分配顶级域名尾
|
||||
@ -105,6 +143,7 @@ if($_GET['error']!=""){
|
||||
header('Location: http://1.gemcapi.ghink.net:10000/'.$_GET['path']);
|
||||
}else{
|
||||
echo '{"wikis":"https://gitee.com/ghink/gemcapi/wikis","code":404,"server_time":"'.date("Y-m-d h:i:s").'"}';
|
||||
header('HTTP/1.1 404 Not Found');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user