Skip to content

Commit 567dc4e

Browse files
committed
config fire wall
1 parent 668183e commit 567dc4e

File tree

118 files changed

+4195
-681
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

118 files changed

+4195
-681
lines changed

conf/proxy.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ proxy.cache.ttl=20
77
proxy.cache.type=redis
88

99
proxy.resource.staticUri=/static/.*
10-
proxy.resource.notfoundPage=404page.html
10+
proxy.resource.notfoundPage=notfound.html
1111
proxy.resource.badRequestPage=badrequest.html
1212
proxy.resource.forbidPage=forbidden.html
1313
proxy.resource.errorPage=error.html

conf/proxy.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
</property>
3232
<property>
3333
<name>proxy.resource.notfoundPage</name>
34-
<value>404page.html</value>
34+
<value>notfound.html</value>
3535
</property>
3636
<property>
3737
<name>proxy.resource.errorPage</name>

easyproxy-core/src/main/java/org/easyproxy/api/app/handler/ConfigHandler.java

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,7 @@
66
import org.easyarch.netpet.web.mvc.entity.Json;
77
import org.easyproxy.api.app.pojo.ConfigVO;
88
import org.easyproxy.config.Config;
9-
import org.easyproxy.config.ConfigEnum;
109
import org.easyproxy.config.ConfigFactory;
11-
import org.easyproxy.handler.http.server.AccessLogHandler;
12-
import org.easyproxy.handler.http.server.BaseServerChildHandler;
13-
import org.easyproxy.handler.http.server.IPFilterHandler;
14-
15-
import java.util.List;
16-
import java.util.Set;
1710

1811
/**
1912
* Created by xingtianyu on 17-3-30
@@ -36,39 +29,4 @@ public void handle(HandlerRequest request, HandlerResponse response) throws Exce
3629
response.json(new Json("message","config complete","code",200));
3730
}
3831

39-
private void resetHandler(Config config){
40-
boolean ipFilterOpen = config.getBoolean(ConfigEnum.FIREWALL_OPEN.key);
41-
boolean logOpen = config.getBoolean(ConfigEnum.LOG_OPEN.key);
42-
List<String> names = BaseServerChildHandler.PIPELINE.names();
43-
System.out.println("handler names:"+names);
44-
if (names.contains(BaseServerChildHandler.FILTERHANDLER)){
45-
System.out.println("-------------filter handler removed");
46-
BaseServerChildHandler.PIPELINE.remove(BaseServerChildHandler.FILTERHANDLER);
47-
}
48-
if (names.contains(BaseServerChildHandler.LOGHANDLER)){
49-
BaseServerChildHandler.PIPELINE.remove(BaseServerChildHandler.LOGHANDLER);
50-
}
51-
if (ipFilterOpen){
52-
Set<String> forbiddenHosts = ConfigFactory.getConfig().getForbiddenHosts();
53-
System.out.println("-------------new forbidden list:"+forbiddenHosts);
54-
BaseServerChildHandler.PIPELINE.addAfter(
55-
BaseServerChildHandler.AGGREGATOR,
56-
BaseServerChildHandler.FILTERHANDLER,
57-
new IPFilterHandler(forbiddenHosts));
58-
if (logOpen){
59-
BaseServerChildHandler.PIPELINE.addAfter(
60-
BaseServerChildHandler.FILTERHANDLER,
61-
BaseServerChildHandler.LOGHANDLER,
62-
new AccessLogHandler());
63-
}
64-
}else{
65-
if (logOpen){
66-
BaseServerChildHandler.PIPELINE.addAfter(
67-
BaseServerChildHandler.AGGREGATOR,
68-
BaseServerChildHandler.LOGHANDLER,
69-
new AccessLogHandler());
70-
}
71-
}
72-
73-
}
7432
}

easyproxy-core/src/main/java/org/easyproxy/api/app/handler/ParamsHandler.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import org.easyarch.netpet.web.http.response.HandlerResponse;
55
import org.easyarch.netpet.web.mvc.action.handler.HttpHandler;
66
import org.easyarch.netpet.web.mvc.entity.Json;
7+
import org.easyproxy.api.app.pojo.ConfigVO;
78
import org.easyproxy.config.Config;
89
import org.easyproxy.config.ConfigFactory;
910
import org.easyproxy.pojo.ConfigEntity;
@@ -20,7 +21,9 @@ public class ParamsHandler implements HttpHandler {
2021
public void handle(HandlerRequest request, HandlerResponse response) throws Exception {
2122
Config config = ConfigFactory.getConfig();
2223
ConfigEntity entity = config.getConfigEntity();
23-
Json json = Json.parse(entity);
24+
ConfigVO vo = new ConfigVO();
25+
vo.convert(entity);
26+
Json json = Json.parse(vo);
2427
System.out.println("current config json:\n"+json);
2528
response.json(json);
2629
}

easyproxy-core/src/main/java/org/easyproxy/api/app/pojo/ConfigVO.java

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public class ConfigVO {
3939
/**
4040
* 缓存类型
4141
*/
42-
private CacheType cacheType;
42+
private String cacheType;
4343
/**
4444
* 静态资源路径
4545
*/
@@ -149,11 +149,11 @@ public void setCacheTTL(Integer cacheTTL) {
149149
this.cacheTTL = cacheTTL;
150150
}
151151

152-
public CacheType getCacheType() {
152+
public String getCacheType() {
153153
return cacheType;
154154
}
155155

156-
public void setCacheType(CacheType cacheType) {
156+
public void setCacheType(String cacheType) {
157157
this.cacheType = cacheType;
158158
}
159159

@@ -293,13 +293,47 @@ public void setRecieveBuffer(Integer recieveBuffer) {
293293
this.recieveBuffer = recieveBuffer;
294294
}
295295

296+
public void convert(ConfigEntity entity){
297+
this.port = entity.getPort();
298+
this.strategy = entity.getStrategy().key;
299+
this.cacheOpen = entity.getCacheOpen();
300+
this.cacheTTL = entity.getCacheTTL();
301+
this.cacheType = entity.getCacheType().name;
302+
this.staticUrl = entity.getStaticUrl();
303+
this.notFoundPage = entity.getNotFoundPage();
304+
this.badRequestPage = entity.getBadRequestPage();
305+
this.errorPage = entity.getErrorPage();
306+
this.logOpen = entity.getLogOpen();
307+
this.antiLeechOpen = entity.getAntiLeechOpen();
308+
this.fireWallOpen = entity.getFireWallOpen();
309+
this.blackList = entity.getBlackList();
310+
this.backLog = entity.getBackLog();
311+
this.keepAlive = entity.getKeepAlive();
312+
this.noDely = entity.getNoDely();
313+
this.soLinger = entity.getSoLinger();
314+
this.sendBuffer = entity.getSendBuffer();
315+
this.reuseAddress = entity.getReuseAddress();
316+
this.recieveBuffer = entity.getRecieveBuffer();
317+
List<HostVO> vos = new ArrayList<>();
318+
if (nodes!= null){
319+
for (WeightHost host:entity.getNodes()){
320+
HostVO vo = new HostVO();
321+
vo.setPort(host.getAddress().getPort());
322+
vo.setIp(host.getAddress().getHostString());
323+
vo.setWeight(host.getWeight());
324+
vos.add(vo);
325+
}
326+
}
327+
this.nodes = vos;
328+
}
329+
296330
public ConfigEntity convert(){
297331
ConfigEntity entity = new ConfigEntity();
298332
entity.setPort(port);
299333
entity.setStrategy(LBStrategy.getStrategy(strategy));
300334
entity.setCacheOpen(cacheOpen);
301335
entity.setCacheTTL(cacheTTL);
302-
entity.setCacheType(cacheType);
336+
entity.setCacheType(CacheType.getCache(cacheType));
303337
entity.setStaticUrl(staticUrl);
304338
entity.setNotFoundPage(notFoundPage);
305339
entity.setBadRequestPage(badRequestPage);

easyproxy-core/src/main/java/org/easyproxy/api/app/pojo/HostVO.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ public class HostVO {
2020
private Integer weight;
2121

2222
public HostVO() {
23+
this.id = StringKits.uuid();
2324
}
2425

2526
public HostVO(WeightHost host){
26-
this.id = StringKits.uuid();
27-
System.out.println("host id:"+id);
27+
this();
2828
wrap(host);
2929
}
3030

easyproxy-core/src/main/java/org/easyproxy/cache/CacheType.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public enum CacheType {
1010
REDIS("redis"),
1111
EHCACHE("ehcache");
1212

13-
private String name;
13+
public String name;
1414

1515
CacheType(String name) {
1616
this.name = name;

0 commit comments

Comments
 (0)