Commit 0983f060 authored by renjie's avatar renjie

Merge branch 'dev-zrj' into 'staging'

设置国外服务器为专线

See merge request !44
parents b58a73bb 1df4e61c
......@@ -32,7 +32,7 @@ public class AuthenticationFailureEventListener implements ApplicationListener<A
if (userAttempts != null) {
if (userAttempts.getDate().getTime() >= (new Date().getTime() - 600000)) {
int fails = userAttempts.getAttempts();
if (fails < 5)
if (fails < 20)
saveUserAttemptsLogin(username, fails + 1);
else
throw new ClientRequestException(AuthErrorCode.LOGINTIMESEXCEEDED, "Login times exceeded");
......
......@@ -151,4 +151,20 @@ public class IpControlloer {
}
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 {
private List<String> proxyProtocol; //专线使用的协议
private List<String> proxyPort; //专线使用的端口
private String username; //专线代理服务器用户名
private String password; //专线代理服务器密码
public String getIp() {
return ip;
}
......@@ -46,4 +49,20 @@ public class SpecialLine {
public void setProxyPort(List<String> 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
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> findByValidTimeBetweenAndIsDeleted(long beginTime, long endTime, boolean isDeleted);
......
......@@ -722,4 +722,42 @@ public class IpResourceServiceImpl implements IpResourceService {
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 {
boolean queryIpExist(String username, IpResourceUpdateDto ipResourceUpdateDto);
IpResourceDto queryIp(String username, IpResourceRequestDto ipResourceRequestDto);
void setSpecialLine();
}
......@@ -37,14 +37,12 @@ public class Set3proxyTask {
@Autowired
private SpecialLineRepository specialLineRepository;
// @Scheduled(cron = "0 0/1 * * * ?")
@Scheduled(cron = "0 0/10 * * * ?")
public void set3proxy() {
long validTime = Instant.now().minusSeconds(43200).toEpochMilli();
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());
log.error(accountParents.size() +"");
List<IpResource> ipResources = ipResourceRepository.findByOwnerInAndSpecialLine(accountParents, true);
log.error(ipResources.size() + "");
File file = new File("3proxy.cfg");
SpecialLine specialLine = specialLineRepository.findAll().get(0);
StringBuilder stringBuilder = new StringBuilder();
......@@ -70,8 +68,9 @@ public class Set3proxyTask {
bw.flush();
bw.close();
log.info("成功写入文件");
// RemoteShellExecutor remoteShellExecutor = new RemoteShellExecutor(specialLine.getIp(), specialLine, "46xiLgy0xrgEaA1");
// remoteShellExecutor
// RemoteShellExecutor remoteShellExecutor = new RemoteShellExecutor(specialLine.getIp(), specialLine.getUsername(), specialLine.getPassword());
// remoteShellExecutor.transferFile("3proxy.cfg", "/root");
// remoteShellExecutor.execCommand("cd /root && sh restart.sh");
} catch (Exception e) {
log.error("出错了");
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