Skip to content

Commit

Permalink
版本更新至2.4
Browse files Browse the repository at this point in the history
1.修复百度云下载提示未选中文件的BUG
2.新增自动更新脚本功能
3.新增启动是否检查证书配置
4.新增GUI模式下记忆上次窗口的大小及位置
  • Loading branch information
monkeyWie committed Mar 23, 2018
1 parent 08b0b62 commit 89c12b7
Show file tree
Hide file tree
Showing 22 changed files with 310 additions and 119 deletions.
2 changes: 1 addition & 1 deletion common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>proxyee-down</artifactId>
<groupId>lee.study</groupId>
<version>2.36</version>
<version>2.4</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
22 changes: 9 additions & 13 deletions common/src/main/java/lee/study/down/util/ByteUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,28 +92,24 @@ public static byte[] objToBts(Serializable object) throws IOException {

public static void serialize(Serializable object, String path, boolean isHidden)
throws IOException {
FileUtil.initFile(path, isHidden);
try (
RandomAccessFile raf = new RandomAccessFile(path, "rw")
) {
raf.write(objToBts(object));
}
serialize(object, path, null, isHidden);
}

public static void serialize(Serializable object, String path, String bakPath, boolean isHidden)
throws IOException {
FileUtil.initFile(path, isHidden);
byte[] bts = objToBts(object);
try (
RandomAccessFile raf = new RandomAccessFile(path, "rw")
) {
raf.write(bts);
raf.write(objToBts(object));
}
FileUtil.initFile(bakPath, isHidden);
try (
RandomAccessFile raf2 = new RandomAccessFile(bakPath, "rw")
) {
raf2.write(bts);
if (bakPath != null) {
FileUtil.initFile(bakPath, isHidden);
try (
RandomAccessFile raf2 = new RandomAccessFile(bakPath, "rw")
) {
raf2.write(objToBts(object));
}
}
}

Expand Down
50 changes: 15 additions & 35 deletions common/src/main/java/lee/study/down/util/HttpUtil.java
Original file line number Diff line number Diff line change
@@ -1,36 +1,12 @@
package lee.study.down.util;

import io.netty.bootstrap.Bootstrap;
import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioSocketChannel;
import io.netty.handler.codec.http.DefaultLastHttpContent;
import io.netty.handler.codec.http.HttpClientCodec;
import io.netty.handler.codec.http.HttpContent;
import io.netty.handler.codec.http.HttpHeaderNames;
import io.netty.handler.codec.http.HttpHeaders;
import io.netty.handler.codec.http.HttpRequest;
import io.netty.handler.codec.http.HttpResponse;
import io.netty.handler.codec.http.HttpResponseStatus;
import io.netty.handler.ssl.SslContext;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.Map.Entry;
import java.util.UUID;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import lee.study.down.model.HttpRequestInfo;
import lee.study.down.model.TaskInfo;
import lee.study.proxyee.util.ProtoUtil.RequestProto;

public class HttpUtil {

/**
* 检测请求头是否存在
*/
Expand All @@ -47,7 +23,17 @@ public static boolean checkHeadKey(HttpHeaders httpHeaders, String regex) {
* 检测url是否匹配
*/
public static boolean checkUrl(HttpRequest httpRequest, String regex) {
return checkHead(httpRequest, HttpHeaderNames.HOST, regex);
String host = httpRequest.headers().get(HttpHeaderNames.HOST);
if (host != null && regex != null) {
String url;
if (httpRequest.uri().indexOf("/") == 0) {
url = host + httpRequest.uri();
} else {
url = httpRequest.uri();
}
return url.matches(regex);
}
return false;
}

/**
Expand All @@ -61,15 +47,9 @@ public static boolean checkReferer(HttpRequest httpRequest, String regex) {
* 检测某个http头是否匹配
*/
public static boolean checkHead(HttpRequest httpRequest, CharSequence headName, String regex) {
String host = httpRequest.headers().get(headName);
if (host != null && regex != null) {
String url;
if (httpRequest.uri().indexOf("/") == 0) {
url = host + httpRequest.uri();
} else {
url = httpRequest.uri();
}
return url.matches(regex);
String headValue = httpRequest.headers().get(headName);
if (headValue != null && regex != null) {
return headValue.matches(regex);
}
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>proxyee-down</artifactId>
<groupId>lee.study</groupId>
<version>2.36</version>
<version>2.4</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>lee.study</groupId>
<artifactId>proxyee-down</artifactId>
<version>2.36</version>
<version>2.4</version>
<packaging>pom</packaging>

<modules>
Expand Down
2 changes: 1 addition & 1 deletion sniff/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>proxyee-down</artifactId>
<groupId>lee.study</groupId>
<version>2.36</version>
<version>2.4</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
11 changes: 4 additions & 7 deletions sniff/src/main/java/lee/study/down/intercept/BdyIntercept.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package lee.study.down.intercept;

import io.netty.handler.codec.http.HttpResponse;
import java.nio.charset.Charset;
import lee.study.down.intercept.common.ResponseTextIntercept;
import lee.study.down.util.ByteUtil;
import lee.study.down.plug.PluginContent;
import lee.study.down.util.HttpUtil;
import lee.study.proxyee.intercept.HttpProxyInterceptPipeline;

Expand All @@ -12,10 +11,6 @@
*/
public class BdyIntercept extends ResponseTextIntercept {

private static final String hookJs = ByteUtil
.readJsContent(Thread.currentThread().getContextClassLoader()
.getResourceAsStream("hookjs/bdyHook.js"), Charset.forName("UTF-8"));

@Override
public boolean match(HttpResponse httpResponse, HttpProxyInterceptPipeline pipeline) {
return HttpUtil.checkUrl(pipeline.getHttpRequest(), "^(pan|yun).baidu.com.*$")
Expand All @@ -24,7 +19,9 @@ public boolean match(HttpResponse httpResponse, HttpProxyInterceptPipeline pipel

@Override
public String hookResponse() {
return hookJs;
return "<script type=\"text/javascript\">"
+ PluginContent.get("bdyHook.js").getContent()
+ "</script>";
}

}
11 changes: 11 additions & 0 deletions sniff/src/main/java/lee/study/down/model/PluginBean.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package lee.study.down.model;

import lombok.Data;

@Data
public class PluginBean {

private float version;
private String desc;
private String content;
}
63 changes: 63 additions & 0 deletions sniff/src/main/java/lee/study/down/plug/PluginContent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package lee.study.down.plug;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.JarURLConnection;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLConnection;
import java.util.Enumeration;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import lee.study.down.model.PluginBean;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class PluginContent {

private static final Logger LOGGER = LoggerFactory.getLogger(PluginContent.class);
private static final Map<String, PluginBean> content = new ConcurrentHashMap<>();

public static void init() {
try {
URL url = Thread.currentThread().getContextClassLoader()
.getResource("hookjs");
URLConnection connection = url.openConnection();
if (connection instanceof JarURLConnection) {
JarURLConnection jarURLConnection = (JarURLConnection) connection;
JarFile jarFile = jarURLConnection.getJarFile();
Enumeration<JarEntry> entries = jarFile.entries();
while(entries.hasMoreElements()){
JarEntry entry = entries.nextElement();
if (entry.getName().matches("^.*hookjs/[^/]+$")) {
String key = entry.getName().substring(entry.getName().indexOf("hookjs/")+7);
update(key, PluginUtil.getPluginBean(jarFile.getInputStream(entry)));
}
}
jarFile.close();
} else {
File file = new File(url.getPath());
for (File hook : file.listFiles()) {
update(hook.getName(), PluginUtil.getPluginBean(new FileInputStream(hook)));
}
}
} catch (Exception e) {
LOGGER.error("plugin content init error",e);
}
}

public static void update(String key, PluginBean value) {
content.put(key, value);
}

public static PluginBean get(String key) {
return content.get(key);
}

public static void main(String[] args) throws IOException, URISyntaxException {
init();
}
}
42 changes: 42 additions & 0 deletions sniff/src/main/java/lee/study/down/plug/PluginUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package lee.study.down.plug;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import lee.study.down.model.PluginBean;

public class PluginUtil {

public static PluginBean getPluginBean(InputStream inputStream, float currentVersion)
throws IOException {
PluginBean pluginBean = new PluginBean();
try (
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"))
) {
StringBuilder sb = new StringBuilder();
String line;
int num = 1;
while ((line = reader.readLine()) != null) {
if (num == 1) {
//版本号
float newVersion = Float.parseFloat(line.substring(2));
if (newVersion > currentVersion) {
pluginBean.setVersion(newVersion);
} else {
return null;
}
num++;
}
sb.append(line + "\r\n");
}
pluginBean.setContent(sb.toString());
}
return pluginBean;
}

public static PluginBean getPluginBean(InputStream inputStream)
throws IOException {
return getPluginBean(inputStream, -1F);
}
}
Loading

0 comments on commit 89c12b7

Please sign in to comment.