This repository has been archived on 2022-12-28. You can view files and clone it, but cannot push or open issues or pull requests.
gemcapi/old/5.0.0/index.php
2020-08-25 22:40:22 +08:00

270 lines
14 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
error_reporting(0);
ini_set('user_agent', 'GeMCAPI/5.0.0 (GeMC API Sync 5.0.0;Release)');
$server_id=1;//服务器的ID
$active=array('mojang/launchermeta/mc/game/version_manifest.json','forge/last','optifine/versionlist','liteloader/dl/versions/versions.json');
$type=array('.com','.net','.com','.moe','.net');
//[0]:mojang,[1]:fabricmc,[2]:liteloader,[3]:authlib-injector,[4]:minecraft
function url_exists($url){
$opts = array(
'http'=>array(
'timeout'=>3,
)
);
$context = stream_context_create($opts);
return @file_get_contents($url, false, $context);
}
function download_file($url,$file,$other){//下载文件
system('python download.py --url "'.$url.'" --file "'.$file.'" --other "'.$other.'"');
}
function get_main_domain($file){
$str=preg_replace('/^[^\/]*\//is','',$file);
$str2=str_replace('/'.$str,'',$file);
return $str2;
}
function get_sub_domain($file){
$str=preg_replace('/^[^\/]*\//is','',$file);
$str2=preg_replace('/^[^\/]*\//is','',$str);
$str3=str_replace('/'.$str2,'',$str);
return $str3;
}
function get_file_path($file){
$str=preg_replace('/^[^\/]*\//is','',$file);
$str2=preg_replace('/^[^\/]*\//is','',$str);
return $str2;
}
function get_online_url($file,$id){
global $type;
$str='https://'.get_sub_domain($file).'.'.get_main_domain($file).$type[$id].'/'.get_file_path($file);
return $str;
}
function get_online_domain($file,$id){
global $type;
$str='https://'.get_sub_domain($file).'.'.get_main_domain($file).$type[$id].'/';
return $str;
}
function check_file_update($file,$dir,$url,$time){
global $replace_mode;
if($replace_mode==true){
$file=str_replace('?','/',$file);
}
header('Content-Disposition: attachment; filename="'.basename($file).'"');
$time=time()-@filemtime($file);
if($time<$time){//检查文件是否超出过期期限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)){
echo file_get_contents($file);
}else{
echo file_get_contents($url.'/'.str_replace($dir,'',$file));
download_file($url.'/'.str_replace($dir,'',$file),$file,'');
}
}else{
echo file_get_contents($file);
}
}
}
function check_file_update_json($file,$dir,$url,$time){
global $replace_mode;
if($replace_mode==true){
$file=str_replace('?','/',$file);
}
header('Content-Disposition: attachment; filename="'.basename($file).'.json"');
$time=time()-@filemtime($file.'/index.json');
if($time<$time){//检查文件是否超出过期期限1天86400秒
echo file_get_contents($file.'/index.json');
}else{
if(url_exists($url.'/'.str_replace($dir,'',$file))){//防止源无法访问而损坏文件
if(file_get_contents($url.'/'.str_replace($dir,'',$file))==@file_get_contents($file.'/index.json')){
echo file_get_contents($file);
}else{
echo file_get_contents($url.'/'.str_replace($dir,'',$file));
download_file($url.'/'.str_replace($dir,'',$file),$file.'/index.json','');
}
}else{
echo file_get_contents($file.'/index.json');
}
}
}
function check_file_update_jar($file,$dir,$url,$time){
global $replace_mode;
if($replace_mode==true){
$file=str_replace('?','/',$file);
}
header('Content-Disposition: attachment; filename="'.basename($file).'.jar"');
$time=time()-@filemtime($file.'/index.jar');
if($time<$time){//检查文件是否超出过期期限1天86400秒
echo file_get_contents($file.'/index.jar');
}else{
if(url_exists($url.'/'.str_replace($dir,'',$file))){//防止源无法访问而损坏文件
if(file_get_contents($url.'/'.str_replace($dir,'',$file))==@file_get_contents($file.'/index.jar')){
echo file_get_contents($file);
}else{
echo file_get_contents($url.'/'.str_replace($dir,'',$file));
download_file($url.'/'.str_replace($dir,'',$file),$file.'/index.jar','');
}
}else{
echo file_get_contents($file.'/index.jar');
}
}
}
function check_file_update_adv($file,$url,$check_url){
global $replace_mode;
if($replace_mode==true){
$file=str_replace('?','/',$file);
}
header('Content-Disposition: attachment; filename="'.basename($file).'"');
$time=time()-@filemtime($file);
if($time<86400){//检查文件是否超出过期期限1天86400秒
echo file_get_contents($file);
}else{
if(url_exists($check_url)){//防止源无法访问而损坏文件
if(file_get_contents($url)==@file_get_contents($file)){
echo file_get_contents($file);
}else{
echo @file_get_contents($url);
download_file($url,$file,'');
}
}else{
echo file_get_contents($file);
}
}
}
if(strstr($_GET['path'],'liteloader')!=False){//替换掉Literloader源中的特殊字符
$replace_mode=true;
}
if(get_main_domain($_GET['path'])=='mojang'){//分配顶级域名尾
$id=0;
}elseif(get_main_domain($_GET['path'])=='fabricmc'){
$id=1;
}elseif(get_main_domain($_GET['path'])=='liteloader'){
$id=2;
}elseif(get_main_domain($_GET['path'])=='yushi'){
$id=3;
}elseif(get_main_domain($_GET['path'])=='minecraft'){
$id=4;
}
if($_GET['error']!=""){
echo '{"wikis":"https://gitee.com/ghink/gemcapi/wikis","code":'.$_GET['error'].',"server_time":'.time().',"server_id":'.$server_id.'}';
}elseif($_GET['path']==""){
echo '{"wikis":"https://gitee.com/ghink/gemcapi/wikis","code":200,"server_time":'.time().',"server_id":'.$server_id.'}';
}else{
if(is_file($_GET['path'])){
//文件存在
if(in_array($_GET['path'],$active)){//判断是否为需要保持最新的文件
if(strstr($_GET['path'],'mojang/')!=False){//目录分组
if(strstr($_GET['path'],'mojang/launchermeta/')!=False){
check_file_update('mojang/launchermeta/mc/game/version_manifest.json',get_main_domain($_GET['path']).'/'.get_sub_domain($_GET['path']).'/','http://launchermeta.mojang.com',86400);
}
}elseif(strstr($_GET['path'],'forge/')!=False){//目录分组
if(strstr($_GET['path'],'forge/last')!=False){
check_file_update_adv('forge/last/index.json','https://download.mcbbs.net/forge/last','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');
}
}elseif(strstr($_GET['path'],'optifine/')!=False){//目录分组
if(strstr($_GET['path'],'optifine/versionlist')!=False){
check_file_update_adv('optifine/versionlist/index.json','https://download.mcbbs.net/optifine/versionlist','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');
}
}elseif(strstr($_GET['path'],'liteloader/')!=False){//目录分组
if(strstr($_GET['path'],'liteloader/dl/versions')!=False){
check_file_update_adv('liteloader/dl/versions/versions.json','http://dl.liteloader.com/versions/versions.json','http://dl.liteloader.com/versions/versions.json');
}
}
}else{//无需频繁更新的文件
if(@file_get_contents(get_online_url($_GET['path'],$id)=="")){
check_file_update($_GET['path'],get_main_domain($_GET['path']).'/'.get_sub_domain($_GET['path']).'/',get_online_domain($_GET['path'],$id),2592000);
}else{
check_file_update_json($_GET['path'],get_main_domain($_GET['path']).'/'.get_sub_domain($_GET['path']).'/',get_online_domain($_GET['path'],$id),2592000);
}
}
}elseif(is_dir($_GET['path'])){
//目录存在
if(strstr($_GET['path'],'forge/minecraft')!=False){//特殊目录返回
check_file_update_adv('forge/minecraft/minecraft.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');
}elseif(strstr($_GET['path'],'yushi/authlib-injector')!=False){
check_file_update_adv('yushi/authlib-injector/list.json','https://authlib-injector.yushi.moe','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');
//此处暂时使用bmclapi源检测文件欺骗检测authlib-injector原因见底部注释
}elseif(is_file($_GET['path'].'/index.json')){
check_file_update_json($_GET['path'],get_main_domain($_GET['path']).'/'.get_sub_domain($_GET['path']).'/',get_online_domain($_GET['path'],$id),86400);
}elseif(is_file($_GET['path'].'/index.jar')){
check_file_update_jar($_GET['path'],get_main_domain($_GET['path']).'/'.get_sub_domain($_GET['path']).'/',get_online_domain($_GET['path'],$id),31536000);
}else{
header('Content-Disposition: attachment; filename="'.basename($_GET['path']).'"');
echo file_get_contents($_GET['path']);
}
}else{
//目录或文件不存在
if(strstr($_GET['path'],'forge/')!=False){//特殊Forge采用二级源 BMCLAPI
if(url_exists('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')){
if(strstr($_GET['path'],'forge/minecraft')!=False){//forge/minecraft目录特殊同步
if($_GET['path']=='forge/minecraft'){
check_file_update_adv('forge/minecraft/minecraft.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'].'/index.json','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');
}
}elseif(strstr($_GET['path'],'forge/last')!=False){
check_file_update_adv($_GET['path'].'/index.json','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');
}elseif(strstr($_GET['path'],'forge/download')!=False){//forge/download目录特殊同步
check_file_update_adv($_GET['path'].'/index.jar','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('Content-Disposition: attachment; filename="'.basename($_GET['path']).'"');
echo file_get_contents($_GET['path']);
}
}else{
echo '{"wikis":"https://gitee.com/ghink/gemcapi/wikis","code":404,"server_time":'.time().'}';
header('HTTP/1.1 404 Not Found');
}
}elseif(strstr($_GET['path'],'optifine/')!=False){//Optifine同步
if($_GET['path']=='optifine'){
echo '{"wikis":"https://gitee.com/ghink/gemcapi/wikis","code":404,"server_time":'.time().'}';
header('HTTP/1.1 404 Not Found');
}elseif(strstr($_GET['path'],'optifine/versionlist')!=False){
check_file_update_adv(str_replace('?','/',$_GET['path']).'/index.json','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{
if(@file_get_contents(get_online_url($_GET['path'],$id)=="")){
check_file_update_adv($_GET['path'].'/index.jar','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{
if(strstr($_GET['path'],'HD_U')!=False){
check_file_update_adv($_GET['path'].'/index.jar','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{
check_file_update_adv($_GET['path'].'/index.json','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');
}
}
}
}elseif(strstr($_GET['path'],'liteloader/')!=False){//Liteloader同步
if(strstr($_GET['path'],'liteloader/list')!=False){
check_file_update_adv(str_replace('?','/',$_GET['path']).'/index.json','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');
}elseif(strstr($_GET['path'],'liteloader/download')!=False){
check_file_update_adv(str_replace('?','/',$_GET['path']).'/index.jar','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{
check_file_update_adv($_GET['path'],get_online_url($_GET['path'],$id),'http://dl.liteloader.com/versions/versions.json');
}
}else{
if(url_exists(get_online_url($_GET['path'],$id))){
if(@file_get_contents(get_online_url($_GET['path'],$id)=="")){
download_file(get_online_url($_GET['path'],$id),$_GET['path'],'');
header('Content-Disposition: attachment; filename="'.basename($_GET['path']).'"');
echo file_get_contents($_GET['path']);
}else{
download_file(get_online_url($_GET['path'],$id),$_GET['path'].'/index.json','');
header('Content-Disposition: attachment; filename="'.basename($_GET['path']).'"');
echo file_get_contents($_GET['path'].'/index.json');
}
}elseif(get_main_domain($_GET['path'])=='yushi'){
//暂不明确为何authlib-injector的服务器即使存活文件存在也会被判定为不存在
download_file(get_online_url($_GET['path'],$id),$_GET['path'].'/list.json','');
header('Content-Disposition: attachment; filename="'.basename($_GET['path']).'"');
echo file_get_contents($_GET['path'].'/list.json');
}elseif(get_main_domain($_GET['path'])=='minecraft'){
//暂不明确为何Minecraft的服务器即使存活文件存在也会被判定为不存在
download_file(get_online_url($_GET['path'],$id),$_GET['path'].'/index.jar','');
header('Content-Disposition: attachment; filename="'.basename($_GET['path']).'"');
echo file_get_contents($_GET['path'].'/index.jar');
}else{
echo '{"wikis":"https://gitee.com/ghink/gemcapi/wikis","code":404,"server_time":'.time().',"server_id":'.$server_id.'}';
header('HTTP/1.1 404 Not Found');
}
}
}
}