From 89c12b7415ee779448ebf65019c672db316169d0 Mon Sep 17 00:00:00 2001 From: monkeyWie Date: Fri, 23 Mar 2018 14:31:55 +0800 Subject: [PATCH] =?UTF-8?q?=E7=89=88=E6=9C=AC=E6=9B=B4=E6=96=B0=E8=87=B32.?= =?UTF-8?q?4=201.=E4=BF=AE=E5=A4=8D=E7=99=BE=E5=BA=A6=E4=BA=91=E4=B8=8B?= =?UTF-8?q?=E8=BD=BD=E6=8F=90=E7=A4=BA=E6=9C=AA=E9=80=89=E4=B8=AD=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E7=9A=84BUG=202.=E6=96=B0=E5=A2=9E=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E8=84=9A=E6=9C=AC=E5=8A=9F=E8=83=BD=203.?= =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=90=AF=E5=8A=A8=E6=98=AF=E5=90=A6=E6=A3=80?= =?UTF-8?q?=E6=9F=A5=E8=AF=81=E4=B9=A6=E9=85=8D=E7=BD=AE=204.=E6=96=B0?= =?UTF-8?q?=E5=A2=9EGUI=E6=A8=A1=E5=BC=8F=E4=B8=8B=E8=AE=B0=E5=BF=86?= =?UTF-8?q?=E4=B8=8A=E6=AC=A1=E7=AA=97=E5=8F=A3=E7=9A=84=E5=A4=A7=E5=B0=8F?= =?UTF-8?q?=E5=8F=8A=E4=BD=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/pom.xml | 2 +- .../java/lee/study/down/util/ByteUtil.java | 22 ++-- .../java/lee/study/down/util/HttpUtil.java | 50 +++------ core/pom.xml | 2 +- pom.xml | 2 +- sniff/pom.xml | 2 +- .../study/down/intercept/BdyIntercept.java | 11 +- .../java/lee/study/down/model/PluginBean.java | 11 ++ .../lee/study/down/plug/PluginContent.java | 63 +++++++++++ .../java/lee/study/down/plug/PluginUtil.java | 42 ++++++++ .../src/main/resources/hookjs/bdyHook.js | 101 +++++++++++------- .../src/main/resources/hookjs/blobSniff.js | 1 + ui/pom.xml | 2 +- .../lee/study/down/content/ConfigContent.java | 9 +- .../study/down/gui/HttpDownApplication.java | 38 +++++-- .../HttpDownHandleInterceptFactory.java | 8 +- .../lee/study/down/model/ConfigBaseInfo.java | 8 +- .../java/lee/study/down/model/ConfigInfo.java | 5 +- .../down/task/PluginUpdateCheckTask.java | 40 +++++++ ui/src/main/resources/application.properties | 2 +- ui/view/src/components/ConfigPage.vue | 6 ++ update/pom.xml | 2 +- 22 files changed, 310 insertions(+), 119 deletions(-) create mode 100644 sniff/src/main/java/lee/study/down/model/PluginBean.java create mode 100644 sniff/src/main/java/lee/study/down/plug/PluginContent.java create mode 100644 sniff/src/main/java/lee/study/down/plug/PluginUtil.java rename {ui => sniff}/src/main/resources/hookjs/bdyHook.js (95%) rename {ui => sniff}/src/main/resources/hookjs/blobSniff.js (99%) create mode 100644 ui/src/main/java/lee/study/down/task/PluginUpdateCheckTask.java diff --git a/common/pom.xml b/common/pom.xml index 6bdf4997..0ca1327b 100644 --- a/common/pom.xml +++ b/common/pom.xml @@ -5,7 +5,7 @@ proxyee-down lee.study - 2.36 + 2.4 4.0.0 diff --git a/common/src/main/java/lee/study/down/util/ByteUtil.java b/common/src/main/java/lee/study/down/util/ByteUtil.java index 6c4ea8a5..63bca97f 100644 --- a/common/src/main/java/lee/study/down/util/ByteUtil.java +++ b/common/src/main/java/lee/study/down/util/ByteUtil.java @@ -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)); + } } } diff --git a/common/src/main/java/lee/study/down/util/HttpUtil.java b/common/src/main/java/lee/study/down/util/HttpUtil.java index d9e1708a..dad0a50c 100644 --- a/common/src/main/java/lee/study/down/util/HttpUtil.java +++ b/common/src/main/java/lee/study/down/util/HttpUtil.java @@ -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 { + /** * 检测请求头是否存在 */ @@ -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; } /** @@ -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; } diff --git a/core/pom.xml b/core/pom.xml index fa3c4956..a17348a2 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -5,7 +5,7 @@ proxyee-down lee.study - 2.36 + 2.4 4.0.0 diff --git a/pom.xml b/pom.xml index 1044821c..900a9e46 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ 4.0.0 lee.study proxyee-down - 2.36 + 2.4 pom diff --git a/sniff/pom.xml b/sniff/pom.xml index 57d4b665..79fc273a 100644 --- a/sniff/pom.xml +++ b/sniff/pom.xml @@ -5,7 +5,7 @@ proxyee-down lee.study - 2.36 + 2.4 4.0.0 diff --git a/sniff/src/main/java/lee/study/down/intercept/BdyIntercept.java b/sniff/src/main/java/lee/study/down/intercept/BdyIntercept.java index bd7e7ff6..634240d9 100644 --- a/sniff/src/main/java/lee/study/down/intercept/BdyIntercept.java +++ b/sniff/src/main/java/lee/study/down/intercept/BdyIntercept.java @@ -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; @@ -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.*$") @@ -24,7 +19,9 @@ public boolean match(HttpResponse httpResponse, HttpProxyInterceptPipeline pipel @Override public String hookResponse() { - return hookJs; + return ""; } } diff --git a/sniff/src/main/java/lee/study/down/model/PluginBean.java b/sniff/src/main/java/lee/study/down/model/PluginBean.java new file mode 100644 index 00000000..52752742 --- /dev/null +++ b/sniff/src/main/java/lee/study/down/model/PluginBean.java @@ -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; +} diff --git a/sniff/src/main/java/lee/study/down/plug/PluginContent.java b/sniff/src/main/java/lee/study/down/plug/PluginContent.java new file mode 100644 index 00000000..222e7f7b --- /dev/null +++ b/sniff/src/main/java/lee/study/down/plug/PluginContent.java @@ -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 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 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(); + } +} diff --git a/sniff/src/main/java/lee/study/down/plug/PluginUtil.java b/sniff/src/main/java/lee/study/down/plug/PluginUtil.java new file mode 100644 index 00000000..0aa76d59 --- /dev/null +++ b/sniff/src/main/java/lee/study/down/plug/PluginUtil.java @@ -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); + } +} diff --git a/ui/src/main/resources/hookjs/bdyHook.js b/sniff/src/main/resources/hookjs/bdyHook.js similarity index 95% rename from ui/src/main/resources/hookjs/bdyHook.js rename to sniff/src/main/resources/hookjs/bdyHook.js index 86d8fdca..7f4b318c 100644 --- a/ui/src/main/resources/hookjs/bdyHook.js +++ b/sniff/src/main/resources/hookjs/bdyHook.js @@ -1,3 +1,4 @@ +//1.0 var initHookInterval = setInterval(function () { if (!window.$) { return; @@ -159,6 +160,7 @@ var initHookInterval = setInterval(function () { //监视地址栏#标签的变化 function registerHashChange() { window.addEventListener('hashchange', function (e) { + obFlag = false; refreshListGridStatus(); if (getCurrentPage() == 'all') { if (currentPage == getCurrentPage()) { @@ -238,9 +240,9 @@ var initHookInterval = setInterval(function () { }); } else { var checkInterval = setInterval(function () { - if ($('a.g-button[title=下载]>span').length > 1) { + if ($('a.g-button[title^=下载]>span').length > 1) { clearInterval(checkInterval); - $('a.g-button[title=下载]>span').unbind('click') + $('a.g-button[title^=下载]>span').unbind('click') .click(function (e) { linkClick(e, isGrid); e.preventDefault(); @@ -251,12 +253,17 @@ var initHookInterval = setInterval(function () { } } + var obFlag = false; + //监视文件列表显示变化 function createObserver() { var options = { 'childList': true, }; - observer = new MutationObserver(function (mutations) { + var downButtonObServer = new MutationObserver(function (mutations) { + registerDownButton(false); + }); + var observer = new MutationObserver(function (mutations) { if (mutations.length == 1 && mutations[0].addedNodes && mutations[0].addedNodes.length > 0 @@ -264,7 +271,13 @@ var initHookInterval = setInterval(function () { == 'context-menu') { registerDownButton(true); } else { - registerDownButton(false); + if (!obFlag) { + obFlag = true; + $('div.' + wordMap['list-view'] + ' div.operate').each( + function () { + downButtonObServer.observe(this, options); + }); + } } }); @@ -296,22 +309,22 @@ var initHookInterval = setInterval(function () { } }); } else { - $('span.' + wordMap['checkbox']).parent().filter( - '.zbmh0WQ7').find('div.file-name').find('div.text>a').each( - function () { - var _this = $(this); - $.each(fileList, function (i, file) { - if (file.server_filename == _this.text()) { - selectFileList.push({ - filename: file.server_filename, - path: file.path, - fs_id: file.fs_id, - isdir: file.isdir - }); - return false; - } - }); + $('span.' + wordMap['checkbox']).parent().each(function () { + if ($(this).attr('class').split(' ').length > 3) { + var fileName = $(this).find('div.file-name div.text>a').text(); + $.each(fileList, function (i, file) { + if (file.server_filename == fileName) { + selectFileList.push({ + filename: file.server_filename, + path: file.path, + fs_id: file.fs_id, + isdir: file.isdir + }); + return false; + } }); + } + }); } var downloadType; var downloadLink; @@ -353,7 +366,7 @@ var initHookInterval = setInterval(function () { alert("发生错误!"); return; } - window.location.href = downloadLink; + window.open(downloadLink) } function getSign() { @@ -574,6 +587,7 @@ var initHookInterval = setInterval(function () { registerEventListener(); createObserver(); } + registerDownButton(); }; function initParams() { @@ -663,7 +677,6 @@ var initHookInterval = setInterval(function () { function registerEventListener() { registerHashChange(); registerListGridStatus(); - registerDownButton(); } //监视地址栏#标签变化 @@ -703,8 +716,8 @@ var initHookInterval = setInterval(function () { //监视文件选择框 function registerDownButton() { - $('a.g-button[title=下载]>span').unbind('click'); - $('a.g-button[title=下载]>span').click(function (e) { + $('a.g-button[title^=下载]>span').unbind('click'); + $('a.g-button[title^=下载]>span').click(function (e) { linkButtonClick(e); e.preventDefault(); e.stopPropagation(); @@ -828,7 +841,7 @@ var initHookInterval = setInterval(function () { } else { link = result.dlink; } - window.location.href = link + window.open(link) } else { alert('发生错误!'); return; @@ -860,21 +873,31 @@ var initHookInterval = setInterval(function () { } }); } else { - $('span.' + wordMap['checkbox']).parent().filter( - '.JS-item-active').find('a.filename').each(function () { - var _this = $(this); - $.each(fileList, function (i, file) { - if (file.server_filename == _this.text()) { - selectFileList.push({ - filename: file.server_filename, - path: file.path, - fs_id: file.fs_id, - isdir: file.isdir - }); - return false; - } + var fileInfo = yunData.FILEINFO[0]; + if(fileInfo.isdir==0){ + selectFileList.push({ + filename: fileInfo.server_filename, + path: fileInfo.path, + fs_id: fileInfo.fs_id, + isdir: fileInfo.isdir }); - }); + }else{ + $('span.' + wordMap['checkbox']).parent().filter( + '.JS-item-active').find('a.filename').each(function () { + var _this = $(this); + $.each(fileList, function (i, file) { + if (file.server_filename == _this.text()) { + selectFileList.push({ + filename: file.server_filename, + path: file.path, + fs_id: file.fs_id, + isdir: file.isdir + }); + return false; + } + }); + }); + } } if (selectFileList.length === 0) { alert('没有选中文件,请重试'); @@ -917,7 +940,7 @@ var initHookInterval = setInterval(function () { } } }); - window.location.href = link; + window.open(link) } else { alert('获取下载链接失败!'); return; diff --git a/ui/src/main/resources/hookjs/blobSniff.js b/sniff/src/main/resources/hookjs/blobSniff.js similarity index 99% rename from ui/src/main/resources/hookjs/blobSniff.js rename to sniff/src/main/resources/hookjs/blobSniff.js index 40544aca..eb256fe0 100644 --- a/ui/src/main/resources/hookjs/blobSniff.js +++ b/sniff/src/main/resources/hookjs/blobSniff.js @@ -1,3 +1,4 @@ +//1.0 if (self.fetch) { var _proxyee_down_oriFetch = window.fetch; Object.defineProperty(window, 'fetch', { diff --git a/ui/pom.xml b/ui/pom.xml index 1eece33f..c6185bc4 100644 --- a/ui/pom.xml +++ b/ui/pom.xml @@ -5,7 +5,7 @@ proxyee-down lee.study - 2.36 + 2.4 4.0.0 diff --git a/ui/src/main/java/lee/study/down/content/ConfigContent.java b/ui/src/main/java/lee/study/down/content/ConfigContent.java index f4fb5071..654c8958 100644 --- a/ui/src/main/java/lee/study/down/content/ConfigContent.java +++ b/ui/src/main/java/lee/study/down/content/ConfigContent.java @@ -1,6 +1,11 @@ package lee.study.down.content; +import com.alibaba.fastjson.JSON; +import java.io.FileInputStream; +import java.io.FileOutputStream; import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; import lee.study.down.boot.TimeoutCheckTask; import lee.study.down.constant.HttpDownConstant; import lee.study.down.model.ConfigInfo; @@ -29,7 +34,7 @@ public ConfigInfo get() { public void save() { synchronized (configContent) { try { - ByteUtil.serialize(configContent, HttpDownConstant.CONFIG_PATH); + JSON.writeJSONString(new FileOutputStream(HttpDownConstant.CONFIG_PATH), configContent); } catch (IOException e) { LOGGER.error("写入配置文件失败:", e); } @@ -39,7 +44,7 @@ public void save() { public void init() { if (FileUtil.exists(HttpDownConstant.CONFIG_PATH)) { try { - set((ConfigInfo) ByteUtil.deserialize(HttpDownConstant.CONFIG_PATH)); + set(JSON.parseObject(new FileInputStream(HttpDownConstant.CONFIG_PATH), ConfigInfo.class)); } catch (Exception e) { LOGGER.error("加载配置文件失败:", e); } diff --git a/ui/src/main/java/lee/study/down/gui/HttpDownApplication.java b/ui/src/main/java/lee/study/down/gui/HttpDownApplication.java index d31deba0..f1cfdc44 100644 --- a/ui/src/main/java/lee/study/down/gui/HttpDownApplication.java +++ b/ui/src/main/java/lee/study/down/gui/HttpDownApplication.java @@ -37,8 +37,11 @@ import lee.study.down.constant.HttpDownConstant; import lee.study.down.content.ContentManager; import lee.study.down.intercept.HttpDownHandleInterceptFactory; +import lee.study.down.model.ConfigInfo; import lee.study.down.mvc.HttpDownSpringBoot; +import lee.study.down.plug.PluginContent; import lee.study.down.task.HttpDownProgressEventTask; +import lee.study.down.task.PluginUpdateCheckTask; import lee.study.down.util.ByteUtil; import lee.study.down.util.ConfigUtil; import lee.study.down.util.FileUtil; @@ -101,6 +104,8 @@ private void initHandle() throws Exception { .run(args.toArray(new String[args.size()])); //上下文加载 ContentManager.init(); + //插件加载 + PluginContent.init(); //程序退出监听 Runtime.getRuntime().addShutdownHook(new Thread(() -> { try { @@ -117,9 +122,7 @@ private void afterTrayInit() { try { //根证书生成 if (!FileUtil.exists(HttpDownConstant.CA_PRI_PATH) - || !FileUtil.exists(HttpDownConstant.CA_CERT_PATH) - || !OsUtil.existsCert(HttpDownConstant.CA_SUBJECT, - ByteUtil.getCertHash(CertUtil.loadCert(HttpDownConstant.CA_CERT_PATH)))) { + || !FileUtil.exists(HttpDownConstant.CA_CERT_PATH)) { //生成ca证书和私钥 KeyPair keyPair = CertUtil.genKeyPair(); File priKeyFile = FileUtil.createFile(HttpDownConstant.CA_PRI_PATH, true); @@ -132,6 +135,11 @@ private void afterTrayInit() { new Date(System.currentTimeMillis() + TimeUnit.DAYS.toMillis(3650)), keyPair) .getEncoded()); + } + //启动检查证书安装 + if (ContentManager.CONFIG.get().isCheckCa() && + !OsUtil.existsCert(HttpDownConstant.CA_SUBJECT, + ByteUtil.getCertHash(CertUtil.loadCert(HttpDownConstant.CA_CERT_PATH)))) { if (OsUtil.existsCert(HttpDownConstant.CA_SUBJECT)) { //重新生成卸载之前的证书 if (OsUtil.isWindows() && OsUtil @@ -146,6 +154,8 @@ private void afterTrayInit() { OsUtil.installCert(HttpDownConstant.CA_CERT_PATH); } } catch (Exception e) { + ContentManager.CONFIG.get().setCheckCa(false); + ContentManager.CONFIG.save(); showMsg("证书安装失败,请手动安装"); LOGGER.error("cert handle error", e); } @@ -173,6 +183,7 @@ private void afterTrayInit() { //启动线程 new HttpDownProgressEventTask().start(); + new PluginUpdateCheckTask().start(); } private static boolean isSupportBrowser; @@ -189,11 +200,12 @@ public void start(Stage stage) throws Exception { initBrowser(); } stage.setTitle("proxyee-down-" + version); - Rectangle2D primaryScreenBounds = Screen.getPrimary().getVisualBounds(); - stage.setX(primaryScreenBounds.getMinX()); - stage.setY(primaryScreenBounds.getMinY()); - stage.setWidth(primaryScreenBounds.getWidth()); - stage.setHeight(primaryScreenBounds.getHeight()); + Rectangle2D bounds = Screen.getPrimary().getVisualBounds(); + ConfigInfo cf = ContentManager.CONFIG.get(); + stage.setX(cf.getGuiX() != -1 ? cf.getGuiX() : bounds.getMinX()); + stage.setY(cf.getGuiY() != -1 ? cf.getGuiY() : bounds.getMinY()); + stage.setWidth(cf.getGuiWidth() != -1 ? cf.getGuiWidth() : bounds.getWidth()); + stage.setHeight(cf.getGuiHeight() != -1 ? cf.getGuiHeight() : bounds.getHeight()); stage.getIcons().add(new Image( Thread.currentThread().getContextClassLoader().getResourceAsStream("favicon.png"))); stage.setOnCloseRequest(event -> { @@ -375,7 +387,15 @@ private void addTray() { })); MenuItem closeItem = new MenuItem("退出"); - closeItem.addActionListener(event -> System.exit(0)); + closeItem.addActionListener(event -> { + //记录窗口信息 + ContentManager.CONFIG.get().setGuiX(stage.getX()); + ContentManager.CONFIG.get().setGuiY(stage.getY()); + ContentManager.CONFIG.get().setGuiHeight(stage.getHeight()); + ContentManager.CONFIG.get().setGuiWidth(stage.getWidth()); + ContentManager.CONFIG.save(); + System.exit(0); + }); popupMenu.add(tasksItem); popupMenu.addSeparator(); diff --git a/ui/src/main/java/lee/study/down/intercept/HttpDownHandleInterceptFactory.java b/ui/src/main/java/lee/study/down/intercept/HttpDownHandleInterceptFactory.java index e204dbb2..43fd0424 100644 --- a/ui/src/main/java/lee/study/down/intercept/HttpDownHandleInterceptFactory.java +++ b/ui/src/main/java/lee/study/down/intercept/HttpDownHandleInterceptFactory.java @@ -13,6 +13,7 @@ import lee.study.down.model.HttpDownInfo; import lee.study.down.model.TaskInfo; import lee.study.down.util.HttpDownUtil; +import lee.study.down.util.HttpUtil; import lee.study.proxyee.intercept.HttpProxyIntercept; import lee.study.proxyee.intercept.HttpProxyInterceptPipeline; import lee.study.proxyee.proxy.ProxyConfig; @@ -43,7 +44,12 @@ public void afterResponse(Channel clientChannel, Channel proxyChannel, httpResponse.setStatus(HttpResponseStatus.OK); httpResponse.headers().clear(); httpResponse.headers().set(HttpHeaderNames.CONTENT_TYPE, "text/html"); - byte[] content = "".getBytes(); + byte[] content; + if (HttpUtil.checkHead(httpRequest, HttpHeaderNames.HOST, "^.*\\.baidupcs\\.com.*$")) { + content = "".getBytes(); + }else{ + content = "".getBytes(); + } httpResponse.headers().set(HttpHeaderNames.CONTENT_LENGTH, content.length); clientChannel.writeAndFlush(httpResponse); HttpContent httpContent = new DefaultLastHttpContent(); diff --git a/ui/src/main/java/lee/study/down/model/ConfigBaseInfo.java b/ui/src/main/java/lee/study/down/model/ConfigBaseInfo.java index 02133e55..efe52862 100644 --- a/ui/src/main/java/lee/study/down/model/ConfigBaseInfo.java +++ b/ui/src/main/java/lee/study/down/model/ConfigBaseInfo.java @@ -1,10 +1,9 @@ package lee.study.down.model; -import java.io.Serializable; import lombok.Data; @Data -public class ConfigBaseInfo implements Serializable { +public class ConfigBaseInfo { private int proxyPort = 9999; //代理端口号 private int sniffModel = 2; //嗅探模式 1.全网 2.百度云 3.关闭 @@ -14,4 +13,9 @@ public class ConfigBaseInfo implements Serializable { private boolean secProxyEnable; //二级代理开关 private String lastPath; //最后保存文件的路径 private int retryCount = 5; //失败重试次数 + private boolean checkCa = true; //启动是否自动检测和安装ca证书 + private double guiWidth = -1; + private double guiHeight = -1; + private double guiX = -1; + private double guiY = -1; } diff --git a/ui/src/main/java/lee/study/down/model/ConfigInfo.java b/ui/src/main/java/lee/study/down/model/ConfigInfo.java index 16e04401..cede800c 100644 --- a/ui/src/main/java/lee/study/down/model/ConfigInfo.java +++ b/ui/src/main/java/lee/study/down/model/ConfigInfo.java @@ -1,15 +1,12 @@ package lee.study.down.model; -import java.io.Serializable; import lee.study.proxyee.proxy.ProxyConfig; import lombok.Data; import lombok.EqualsAndHashCode; @Data @EqualsAndHashCode(callSuper = false) -public class ConfigInfo extends ConfigBaseInfo implements Serializable { - - private static final long serialVersionUID = 4780168673614933999L; +public class ConfigInfo extends ConfigBaseInfo { private ProxyConfig secProxyConfig; //二级代理设置 } diff --git a/ui/src/main/java/lee/study/down/task/PluginUpdateCheckTask.java b/ui/src/main/java/lee/study/down/task/PluginUpdateCheckTask.java new file mode 100644 index 00000000..f620455a --- /dev/null +++ b/ui/src/main/java/lee/study/down/task/PluginUpdateCheckTask.java @@ -0,0 +1,40 @@ +package lee.study.down.task; + +import java.io.IOException; +import java.net.URL; +import java.net.URLConnection; +import lee.study.down.model.PluginBean; +import lee.study.down.plug.PluginContent; +import lee.study.down.plug.PluginUtil; +import org.jsoup.Jsoup; +import org.jsoup.nodes.Document; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * 检查脚本 + */ +public class PluginUpdateCheckTask extends Thread { + + private static final Logger LOGGER = LoggerFactory.getLogger(PluginUpdateCheckTask.class); + private static final String HOST = "https://github.com/monkeyWie/proxyee-down-plugin/raw/master/"; + + @Override + public void run() { + try { + Document document = Jsoup.connect("https://github.com/monkeyWie/proxyee-down-plugin").get(); + for (String name : document.select("td.content span.css-truncate.css-truncate-target") + .eachText()) { + URL url = new URL(HOST + name); + URLConnection connection = url.openConnection(); + PluginBean pluginBean = PluginUtil + .getPluginBean(connection.getInputStream(), PluginContent.get(name).getVersion()); + if (pluginBean != null) { + PluginContent.update(name, pluginBean); + } + } + } catch (IOException e) { + LOGGER.error("plugin update error", e); + } + } +} diff --git a/ui/src/main/resources/application.properties b/ui/src/main/resources/application.properties index e436d967..c74fb52e 100644 --- a/ui/src/main/resources/application.properties +++ b/ui/src/main/resources/application.properties @@ -1,4 +1,4 @@ -app.version=2.36 +app.version=2.4 spring.profiles.active=prd view.server.port = 8999 tomcat.server.port = 26339 diff --git a/ui/view/src/components/ConfigPage.vue b/ui/view/src/components/ConfigPage.vue index 2a1ab25d..adafc268 100644 --- a/ui/view/src/components/ConfigPage.vue +++ b/ui/view/src/components/ConfigPage.vue @@ -30,6 +30,12 @@ + + + + + + diff --git a/update/pom.xml b/update/pom.xml index 6d47fed2..cb6e861f 100644 --- a/update/pom.xml +++ b/update/pom.xml @@ -7,7 +7,7 @@ lee.study proxyee-down-update jar - 2.36 + 2.4 UTF-8