Commit 1df4e61c authored by renjie's avatar renjie

设置国外服务器为专线

生成3proxy配置文件
增加登录错误次数
parent d75f0549
...@@ -32,7 +32,7 @@ public class AuthenticationFailureEventListener implements ApplicationListener<A ...@@ -32,7 +32,7 @@ public class AuthenticationFailureEventListener implements ApplicationListener<A
if (userAttempts != null) { if (userAttempts != null) {
if (userAttempts.getDate().getTime() >= (new Date().getTime() - 600000)) { if (userAttempts.getDate().getTime() >= (new Date().getTime() - 600000)) {
int fails = userAttempts.getAttempts(); int fails = userAttempts.getAttempts();
if (fails < 5) if (fails < 20)
saveUserAttemptsLogin(username, fails + 1); saveUserAttemptsLogin(username, fails + 1);
else else
throw new ClientRequestException(AuthErrorCode.LOGINTIMESEXCEEDED, "Login times exceeded"); throw new ClientRequestException(AuthErrorCode.LOGINTIMESEXCEEDED, "Login times exceeded");
......
...@@ -151,4 +151,20 @@ public class IpControlloer { ...@@ -151,4 +151,20 @@ public class IpControlloer {
} }
return resultDto; return resultDto;
} }
@RequestMapping(value = "/special/set", method = RequestMethod.PUT)
public ResultDto setSpecialLine(Principal principal) {
ResultDto resultDto = new ResultDto();
try {
ipResourceService.setSpecialLine();
resultDto.setStatus(0);
} catch (Exception e) {
resultDto.setStatus(-1);
Map<String, Object> statusInfo = new HashMap<>();
statusInfo.put("code", 80001);
statusInfo.put("message", e.getMessage());
resultDto.setStatusInfo(statusInfo);
}
return resultDto;
}
} }
...@@ -15,6 +15,9 @@ public class SpecialLine { ...@@ -15,6 +15,9 @@ public class SpecialLine {
private List<String> proxyProtocol; //专线使用的协议 private List<String> proxyProtocol; //专线使用的协议
private List<String> proxyPort; //专线使用的端口 private List<String> proxyPort; //专线使用的端口
private String username; //专线代理服务器用户名
private String password; //专线代理服务器密码
public String getIp() { public String getIp() {
return ip; return ip;
} }
...@@ -46,4 +49,20 @@ public class SpecialLine { ...@@ -46,4 +49,20 @@ public class SpecialLine {
public void setProxyPort(List<String> proxyPort) { public void setProxyPort(List<String> proxyPort) {
this.proxyPort = proxyPort; this.proxyPort = proxyPort;
} }
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
} }
...@@ -30,6 +30,8 @@ public interface IpResourceRepository extends MongoRepository<IpResource, String ...@@ -30,6 +30,8 @@ public interface IpResourceRepository extends MongoRepository<IpResource, String
List<IpResource> findByOwnerInAndSpecialLine(List<String> owners, boolean specialLine); List<IpResource> findByOwnerInAndSpecialLine(List<String> owners, boolean specialLine);
List<IpResource> findByRegionIn(List<String> regions);
List<IpResource> findByStatusAndLockedAndLockTimestampLessThan(int status, boolean locked, long timestamp); List<IpResource> findByStatusAndLockedAndLockTimestampLessThan(int status, boolean locked, long timestamp);
List<IpResource> findByValidTimeBetweenAndIsDeleted(long beginTime, long endTime, boolean isDeleted); List<IpResource> findByValidTimeBetweenAndIsDeleted(long beginTime, long endTime, boolean isDeleted);
......
...@@ -722,4 +722,42 @@ public class IpResourceServiceImpl implements IpResourceService { ...@@ -722,4 +722,42 @@ public class IpResourceServiceImpl implements IpResourceService {
return ipResourceDto; return ipResourceDto;
} }
@Override
public void setSpecialLine() {
List<IpResource> ipResources = ipResourceRepository.findByRegionIn(Arrays.asList(
"asiapa",
"hongkong",
"japan",
"s-korea",
"us",
"malaysia",
"yajiada",
"singapore",
"australia",
"germany",
"uk",
"brazil",
"moscow",
"canada",
"france",
"sweden",
"s-korea",
"india",
"meast",
"brazil",
"virginia",
"ohio",
"california",
"oregon",
"ireland",
"london",
"ireland"));
for (IpResource ipResource : ipResources) {
ipResource.setProxyUsername(ipResource.getAddr());
ipResource.setProxyPassword(genRandom(3, 12));
ipResource.setSpecialLine(true);
ipResourceRepository.save(ipResource);
}
}
} }
...@@ -28,4 +28,6 @@ public interface IpResourceService { ...@@ -28,4 +28,6 @@ public interface IpResourceService {
boolean queryIpExist(String username, IpResourceUpdateDto ipResourceUpdateDto); boolean queryIpExist(String username, IpResourceUpdateDto ipResourceUpdateDto);
IpResourceDto queryIp(String username, IpResourceRequestDto ipResourceRequestDto); IpResourceDto queryIp(String username, IpResourceRequestDto ipResourceRequestDto);
void setSpecialLine();
} }
...@@ -37,14 +37,12 @@ public class Set3proxyTask { ...@@ -37,14 +37,12 @@ public class Set3proxyTask {
@Autowired @Autowired
private SpecialLineRepository specialLineRepository; private SpecialLineRepository specialLineRepository;
// @Scheduled(cron = "0 0/1 * * * ?") @Scheduled(cron = "0 0/10 * * * ?")
public void set3proxy() { public void set3proxy() {
long validTime = Instant.now().minusSeconds(43200).toEpochMilli(); long validTime = Instant.now().minusSeconds(43200).toEpochMilli();
List<String> tokenUsernames = mongoOAuth2AccessTokenRepository.findByCreatedAtGreaterThan(validTime).stream().map(MongoOAuth2AccessToken::getUsername).collect(Collectors.toList()); List<String> tokenUsernames = mongoOAuth2AccessTokenRepository.findByCreatedAtGreaterThan(validTime).stream().map(MongoOAuth2AccessToken::getUsername).collect(Collectors.toList());
List<String> accountParents = accountRepository.findByNameIn(tokenUsernames).stream().map(x -> x.getParent() == null ? x.getName() : x.getParent()).distinct().collect(Collectors.toList()); List<String> accountParents = accountRepository.findByNameIn(tokenUsernames).stream().map(x -> x.getParent() == null ? x.getName() : x.getParent()).distinct().collect(Collectors.toList());
log.error(accountParents.size() +"");
List<IpResource> ipResources = ipResourceRepository.findByOwnerInAndSpecialLine(accountParents, true); List<IpResource> ipResources = ipResourceRepository.findByOwnerInAndSpecialLine(accountParents, true);
log.error(ipResources.size() + "");
File file = new File("3proxy.cfg"); File file = new File("3proxy.cfg");
SpecialLine specialLine = specialLineRepository.findAll().get(0); SpecialLine specialLine = specialLineRepository.findAll().get(0);
StringBuilder stringBuilder = new StringBuilder(); StringBuilder stringBuilder = new StringBuilder();
...@@ -70,8 +68,9 @@ public class Set3proxyTask { ...@@ -70,8 +68,9 @@ public class Set3proxyTask {
bw.flush(); bw.flush();
bw.close(); bw.close();
log.info("成功写入文件"); log.info("成功写入文件");
// RemoteShellExecutor remoteShellExecutor = new RemoteShellExecutor(specialLine.getIp(), specialLine, "46xiLgy0xrgEaA1"); // RemoteShellExecutor remoteShellExecutor = new RemoteShellExecutor(specialLine.getIp(), specialLine.getUsername(), specialLine.getPassword());
// remoteShellExecutor // remoteShellExecutor.transferFile("3proxy.cfg", "/root");
// remoteShellExecutor.execCommand("cd /root && sh restart.sh");
} catch (Exception e) { } catch (Exception e) {
log.error("出错了"); log.error("出错了");
log.error(e.getMessage()); log.error(e.getMessage());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment