Commit 184af7d7 authored by Administrator's avatar Administrator

Merge branch 'staging' into 'master'

Staging

See merge request !46
parents a2c37855 73170831
......@@ -461,7 +461,7 @@ public class AccountController {
}
@RequestMapping(path = "/ali/withdraw", method = RequestMethod.PUT)
public ResultDto alipayWithdraw(Principal principal, @RequestParam("account") String account, @RequestParam("realName") String realName, @RequestParam("amount") int amount) {
public ResultDto alipayWithdraw(Principal principal, @RequestParam("account") String account, @RequestParam("realName") String realName, @RequestParam("amount") double amount) {
// //获取支付宝GET过来反馈信息
// Map<String,String> params = new HashMap<String,String>();
// Map requestParams = request.getParameterMap();
......
......@@ -181,7 +181,7 @@ public class AdministratorController {
//查询某时段内增加的用户
@PreAuthorize("hasRole('ADMIN')")
@RequestMapping(path ="/0xadministrator/searchperioduser",method = RequestMethod.GET)
public Page<Account> searchCreateAccount(@RequestParam(value="page") int page, @RequestParam(value="size") int size, @RequestParam(value="strDate1") String strDate1, @RequestParam(value="strDate2") String strDate2, @RequestParam("isAuthorized") boolean isAuthorized ){
public Page<Account> searchCreateAccount(@RequestParam(value="page") int page, @RequestParam(value="size") int size, @RequestParam(value="strDate1") String strDate1, @RequestParam(value="strDate2") String strDate2, @RequestParam(value = "isAuthorized", defaultValue = "5") int isAuthorized ){
Pageable pageable = PageRequest.of(page, size);
return administratorService.searchCreateAccountBetween(pageable,strDate1,strDate2,isAuthorized);
}
......
......@@ -35,7 +35,7 @@ public interface AccountRepository extends MongoRepository<Account, String>, Acc
Page<Account> findAllBySignupDateBetweenAndParentIsNull(Pageable pageable, Date startDate, Date endDate);
Page<Account> findAllBySignupDateBetweenAndParentIsNullAndAuthorizedNot(Pageable pageable, Date startDate, Date endDate, int authorized);
Page<Account> findAllBySignupDateBetweenAndParentIsNullAndAuthorized(Pageable pageable, Date startDate, Date endDate, int authorized);
Page<Account> findAll(Pageable pageable);
......
......@@ -8,8 +8,6 @@ public interface AccountRepositoryCustom {
List<String> findInName(String[] name);
List<String> findParents(List<String> names);
void updateRealNameAndIdCard(String username, String realName, String idCard);
Account findByPromotion(String code);
......
......@@ -9,7 +9,6 @@ import org.springframework.data.mongodb.core.aggregation.AggregationResults;
import org.springframework.data.mongodb.core.aggregation.MatchOperation;
import org.springframework.data.mongodb.core.aggregation.ProjectionOperation;
import org.springframework.data.mongodb.core.query.BasicQuery;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Update;
import java.util.ArrayList;
......@@ -42,19 +41,6 @@ public class AccountRepositoryCustomImpl implements AccountRepositoryCustom {
return accountTelephones;
}
@Override
public List<String> findParents(List<String> names) {
Document query = new Document();
Document fields = new Document();
fields.put("name", 1);
BasicQuery basicQuery = new BasicQuery(query, fields);
Criteria criteria = new Criteria();
basicQuery.addCriteria(criteria.orOperator(where("name").in(names)));
return null;
}
@Override
public void updateRealNameAndIdCard(String username, String realName, String idCard) {
Document doc = new Document();
......
......@@ -38,7 +38,7 @@ public interface AdministratorService {
Page<UserPrePaidBilling> searchAllUserBillingPage(int page, int year1, int month1, int year2, int month2);
Page<Account> searchCreateAccountBetween(Pageable pageable, String strDate1, String strDate2, boolean isAuthorized);
Page<Account> searchCreateAccountBetween(Pageable pageable, String strDate1, String strDate2, int isAuthorized);
List<UserPrePaidBilling> getServiceFeeOwedUserInfo();
......
......@@ -22,7 +22,7 @@ public interface PaymentService {
UserPaymentDto h5wxPayOrder(String ip, String username, int amount);
boolean alipayWithdraw(String username, String account, String realName, int amount);
boolean alipayWithdraw(String username, String account, String realName, double amount);
public UserPaymentDto wxCheckOrderStatus(String tradeno);
......
......@@ -225,16 +225,16 @@ public class AdministratorServiceImpl implements AdministratorService {
}
@Override
public Page<Account> searchCreateAccountBetween(Pageable pageable, String strDate1, String strDate2, boolean isAuthorized ) {
public Page<Account> searchCreateAccountBetween(Pageable pageable, String strDate1, String strDate2, int isAuthorized ) {
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
Page<Account> accounts = null;
try {
Date dateTime1 = formatter.parse(strDate1);
Date dateTime2 = formatter.parse(strDate2);
if (isAuthorized)
accounts = accountRepository.findAllBySignupDateBetweenAndParentIsNullAndAuthorizedNot(pageable, dateTime1, dateTime2, 0);
else
if (isAuthorized == 5)
accounts = accountRepository.findAllBySignupDateBetweenAndParentIsNull(pageable, dateTime1, dateTime2);
else
accounts = accountRepository.findAllBySignupDateBetweenAndParentIsNullAndAuthorized(pageable, dateTime1, dateTime2, isAuthorized);
}catch (ParseException e){
e.printStackTrace();
}
......
......@@ -35,6 +35,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.stereotype.Service;
import javax.swing.text.Document;
import java.text.SimpleDateFormat;
import java.time.Instant;
import java.time.YearMonth;
......@@ -590,7 +591,8 @@ public class PaymentServiceImpl implements PaymentService {
}
@Override
public boolean alipayWithdraw(String username, String account, String realName, int amount) {
public boolean alipayWithdraw(String username, String account, String realName, double amount) {
java.text.DecimalFormat df = new java.text.DecimalFormat("#.00");
Account byName = accountService.findByName(username);
if (byName == null)
throw new ClientRequestException(AccountErrorCode.NAMENOTEXIST, "account does not exist: " + username);
......@@ -619,7 +621,7 @@ public class PaymentServiceImpl implements PaymentService {
AlipayFundTransToaccountTransferRequest alipayRequest = new AlipayFundTransToaccountTransferRequest();
String out_biz_no = internalOrder.getTradeNo();
String trans_amount = "" + amount + ".00";
String trans_amount = "" + df.format(amount);
String identity_type = "ALIPAY_LOGONID";
String subject = "礼金提现" + out_biz_no;
......
......@@ -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;
}
}
......@@ -21,7 +21,7 @@ public class IpResource implements Serializable {
private String vendorCn;
private String region;
private String regionCn;
//0:正常, 1:已过期, 2:即将过期, 3:正在分配, 4:未使用, 5:已失效, 6:未分配, 7:未缴费
//0:正常, 1:已过期, 2:即将过期, 3:正在分配, 4:未使用, 5:已失效, 6:未分配, 7:未缴费, 8:分配成功
private int status;
private List<String> port;
private long purchasedTime;
......@@ -36,8 +36,10 @@ public class IpResource implements Serializable {
private String password;
private double price;
private String proxyUsername;
private String proxyPassword;
private boolean specialLine; //是否使用专线
//专线数据
private String proxyUsername; //专线的代理用户名
private String proxyPassword; //专线的代理密码
private String shopId;
private String shopName;
......@@ -48,7 +50,8 @@ public class IpResource implements Serializable {
private String unit;
private int period;
private boolean specialLine;
public IpResource() {
}
public String getDetails() {
return details;
......@@ -281,4 +284,5 @@ public class IpResource implements Serializable {
public void setSpecialLine(boolean specialLine) {
this.specialLine = specialLine;
}
}
package com.edgec.browserbackend.browser.domain;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
import java.util.List;
@Document("specialline")
public class SpecialLine {
@Id
private String Id;
private String ip;
private List<String> proxyProtocol; //专线使用的协议
private List<String> proxyPort; //专线使用的端口
private String username; //专线代理服务器用户名
private String password; //专线代理服务器密码
public String getIp() {
return ip;
}
public void setIp(String ip) {
this.ip = ip;
}
public String getId() {
return Id;
}
public void setId(String id) {
Id = id;
}
public List<String> getProxyProtocol() {
return proxyProtocol;
}
public void setProxyProtocol(List<String> proxyProtocol) {
this.proxyProtocol = proxyProtocol;
}
public List<String> getProxyPort() {
return proxyPort;
}
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;
}
}
......@@ -24,6 +24,15 @@ public class IpResourceDto {
ShopDto bindShop;
private List<BindHistory> bindHistories;
private boolean specialLine;
//专线数据
private String proxyUsername;
private String proxyPassword;
private List<String> proxyProtocol;
private List<String> proxyPort;
private String specialLineIp;
public IpResourceDto(){
}
......@@ -40,7 +49,35 @@ public class IpResourceDto {
this.details = ipResource.getDetails();
this.password = ipResource.getPassword();
this.protocol = ipResource.getProtocol();
this.specialLine = ipResource.isSpecialLine();
if (shopDto != null)
this.bindShop = shopDto;
if (useHistory)
this.bindHistories = ipResource.getBindHistory();
else
this.bindHistories = new ArrayList<>();
}
public IpResourceDto(IpResource ipResource, ShopDto shopDto, boolean useHistory, SpecialLine specialLine1){
this.id = ipResource.getId();
this.addr = ipResource.getAddr();
this.vendor = ipResource.getVendor();
this.region = ipResource.getRegion();
this.status = ipResource.getStatus();
this.port = ipResource.getPort();
this.purchasedTime = ipResource.getPurchasedTime();
this.validTime = ipResource.getValidTime();
this.username = ipResource.getUsername();
this.details = ipResource.getDetails();
this.password = ipResource.getPassword();
this.protocol = ipResource.getProtocol();
this.proxyUsername = ipResource.getProxyUsername();
this.proxyPassword = ipResource.getProxyPassword();
this.proxyPort = specialLine1.getProxyPort();
this.proxyProtocol = specialLine1.getProxyProtocol();
this.specialLine = ipResource.isSpecialLine();
this.bindShop = shopDto;
this.specialLineIp = specialLine1.getIp();
if (useHistory)
this.bindHistories = ipResource.getBindHistory();
else
......@@ -158,4 +195,52 @@ public class IpResourceDto {
public void setBindHistories(List<BindHistory> bindHistories) {
this.bindHistories = bindHistories;
}
public String getProxyPassword() {
return proxyPassword;
}
public void setProxyPassword(String proxyPassword) {
this.proxyPassword = proxyPassword;
}
public String getProxyUsername() {
return proxyUsername;
}
public void setProxyUsername(String proxyUsername) {
this.proxyUsername = proxyUsername;
}
public boolean isSpecialLine() {
return specialLine;
}
public void setSpecialLine(boolean specialLine) {
this.specialLine = specialLine;
}
public List<String> getProxyProtocol() {
return proxyProtocol;
}
public void setProxyProtocol(List<String> proxyProtocol) {
this.proxyProtocol = proxyProtocol;
}
public String getSpecialLineIp() {
return specialLineIp;
}
public void setSpecialLineIp(String specialLineIp) {
this.specialLineIp = specialLineIp;
}
public List<String> getProxyPort() {
return proxyPort;
}
public void setProxyPort(List<String> proxyPort) {
this.proxyPort = proxyPort;
}
}
......@@ -32,11 +32,11 @@ public class ShopResultDto {
private String shopCookie;
private IpResource bindIp;
private IpResourceDto bindIp;
private long createTime;
public static ShopResultDto of(Shop shop, String group, IpResource ipResources) {
public static ShopResultDto of(Shop shop, String group, IpResourceDto ipResources) {
ShopResultDto shopResultDto = new ShopResultDto();
shopResultDto.setShopId(shop.getShopId());
if (shop.getShopName() != null)
......@@ -135,11 +135,11 @@ public class ShopResultDto {
this.shopUrl = shopUrl;
}
public IpResource getBindIp() {
public IpResourceDto getBindIp() {
return bindIp;
}
public void setBindIp(IpResource bindIp) {
public void setBindIp(IpResourceDto bindIp) {
this.bindIp = bindIp;
}
......
......@@ -22,11 +22,16 @@ public interface IpResourceRepository extends MongoRepository<IpResource, String
List<IpResource> findByOwnerAndStatusIsNotInAndIsDeletedAndShopIdIsNull(String owner, List<Integer> status, boolean isDeleted);
List<IpResource> findByOwnerAndStatusAndIsDeletedAndShopIdIsNull(String owner, int status, boolean isDeleted);
List<IpResource> findByStatusAndShopIdInAndIsDeleted(int status, List<String> ipIds, boolean isDeleted);
Page<IpResource> findByAddrLikeAndIdInAndIsDeletedOrderByPurchasedTimeDesc(String addr, List<String> ipIds, boolean isDeleted, Pageable pageable);
Page<IpResource> findByVendorCnLikeAndIdInAndIsDeletedOrderByPurchasedTimeDesc(String vendorCn, List<String> ipIds, boolean isDeleted, Pageable pageable);
Page<IpResource> findByVendorLikeAndIdInAndIsDeletedOrderByPurchasedTimeDesc(String vendor, List<String> ipIds, boolean isDeleted, Pageable pageable);
Page<IpResource> findByRegionCnLikeAndIdInAndIsDeletedOrderByPurchasedTimeDesc(String region, List<String> ipIds, boolean isDeleted, Pageable pageable);
List<IpResource> findByRegionCnLikeAndShopIdInAndIsDeleted(String regionCn, List<String> shopIds, boolean isDeleted);
Page<IpResource> findByIsDeletedAndIdInAndAddrLikeOrderByPurchasedTimeDesc(boolean isDeleted, List<String> ipIds, String addr, Pageable pageable);
Page<IpResource> findByIsDeletedAndIdInAndVendorCnLikeOrderByPurchasedTimeDesc(boolean isDeleted, List<String> ipIds, String vendorCn, Pageable pageable);
Page<IpResource> findByIsDeletedAndIdInAndVendorLikeOrderByPurchasedTimeDesc(boolean isDeleted, List<String> ipIds, String vendor, Pageable pageable);
Page<IpResource> findByIsDeletedAndIdInAndRegionCnLikeOrderByPurchasedTimeDesc(boolean isDeleted, List<String> ipIds, String region, Pageable pageable);
List<IpResource> findByIsDeletedAndShopIdInAndRegionCnLike(boolean isDeleted, List<String> shopIds, String regionCn);
List<IpResource> findByOwnerInAndSpecialLine(List<String> owners, boolean specialLine);
List<IpResource> findBySpecialLine(boolean specialLine);
List<IpResource> findByRegionIn(List<String> regions);
List<IpResource> findByStatusAndLockedAndLockTimestampLessThan(int status, boolean locked, long timestamp);
......
package com.edgec.browserbackend.browser.repository;
import com.edgec.browserbackend.browser.domain.SpecialLine;
import org.springframework.data.mongodb.repository.MongoRepository;
public interface SpecialLineRepository extends MongoRepository<SpecialLine, String> {
}
......@@ -83,6 +83,9 @@ public class IpResourceServiceImpl implements IpResourceService {
@Autowired
private IpAndShopService ipAndShopService;
@Autowired
private SpecialLineRepository specialLineRepository;
public HttpHeaders buildPostHeader() {
HttpHeaders header = new HttpHeaders();
header.setContentType(MediaType.APPLICATION_JSON);
......@@ -150,6 +153,11 @@ public class IpResourceServiceImpl implements IpResourceService {
return retStr;
}
public static void main(String[] args) {
String password = genRandom(3, 12);
System.out.println(password);
}
private IpChargeRequestDto buildIpChargeRequestDto(IpResourceRequestDto request, int chargeType, int payMethod) {
IpChargeRequestDto ipChargeRequestDto = new IpChargeRequestDto();
ipChargeRequestDto.setAmount(request.getAmount());
......@@ -510,13 +518,13 @@ public class IpResourceServiceImpl implements IpResourceService {
List<String> allIpIds = ipResources.stream().map(x -> x.getId()).collect(Collectors.toList());
Page<IpResource> ipResources1 = null;
if (ipFilterDto != null && StringUtils.isNotBlank(ipFilterDto.getRegion())) {
ipResources1 = ipResourceRepository.findByRegionCnLikeAndIdInAndIsDeletedOrderByPurchasedTimeDesc(ipFilterDto.getRegion(), allIpIds, false, pageable);
ipResources1 = ipResourceRepository.findByIsDeletedAndIdInAndRegionCnLikeOrderByPurchasedTimeDesc(false, allIpIds, ipFilterDto.getRegion(), pageable);
}
else if (ipFilterDto != null && StringUtils.isNotBlank(ipFilterDto.getAddr())) {
ipResources1 = ipResourceRepository.findByAddrLikeAndIdInAndIsDeletedOrderByPurchasedTimeDesc(ipFilterDto.getAddr(), allIpIds, false, pageable);
ipResources1 = ipResourceRepository.findByIsDeletedAndIdInAndAddrLikeOrderByPurchasedTimeDesc(false, allIpIds, ipFilterDto.getAddr(), pageable);
}
else if (ipFilterDto != null && StringUtils.isNotBlank(ipFilterDto.getVendor())) {
ipResources1 = ipResourceRepository.findByVendorCnLikeAndIdInAndIsDeletedOrderByPurchasedTimeDesc(ipFilterDto.getVendor(), allIpIds, false, pageable);
ipResources1 = ipResourceRepository.findByIsDeletedAndIdInAndVendorCnLikeOrderByPurchasedTimeDesc(false, allIpIds, ipFilterDto.getVendor(), pageable);
} else {
ipResources1 = ipResourceRepository.findByIdInAndIsDeletedOrderByPurchasedTimeDesc(allIpIds, false, pageable);
}
......@@ -532,7 +540,10 @@ public class IpResourceServiceImpl implements IpResourceService {
shopDto = new ShopDto(shop);
}
if (StringUtils.isNotBlank(x.getAddr())) {
if (x.getValidTime() <= Instant.now().plusSeconds(60*60*24*7).toEpochMilli() && x.getValidTime() >Instant.now().toEpochMilli()) {
if (x.getLockTimestamp() >= Instant.now().minusSeconds(120).toEpochMilli() && x.getIpType() == IpType.VENDOR && (x.getStatus() == 0 || x.getStatus() == 2)) {
x.setStatus(3);
}
else if (x.getValidTime() <= Instant.now().plusSeconds(60*60*24*7).toEpochMilli() && x.getValidTime() >Instant.now().toEpochMilli()) {
if (x.getStatus() != 5 && x.getStatus() != 3 && x.getStatus() != 6) {
x.setStatus(2);
ipResourceRepository.save(x);
......@@ -569,7 +580,11 @@ public class IpResourceServiceImpl implements IpResourceService {
if (x.getStatus() == 3) {
x.setAddr("");
}
ipResourceDtos.add(new IpResourceDto(x, shopDto, false));
SpecialLine specialLine = specialLineRepository.findAll().get(0);
if (x.isSpecialLine())
ipResourceDtos.add(new IpResourceDto(x, shopDto, false, specialLine));
else
ipResourceDtos.add(new IpResourceDto(x, shopDto, false));
});
}
......@@ -692,11 +707,7 @@ public class IpResourceServiceImpl implements IpResourceService {
ipResource.setStatus(2);
ipResourceRepository.save(ipResource);
} else if (ipResource.getValidTime() <= Instant.now().minusSeconds(60 * 60 * 24 * 7).toEpochMilli()) {
if (ipResource.getIpType() == IpType.VENDOR) {
deleteIp(username, ipResourceRequestDto);
} else {
deleteIp(username, ipResourceRequestDto);
}
deleteIp(username, ipResourceRequestDto);
} else if (ipResource.getValidTime() <= Instant.now().toEpochMilli()) {
ipResource.setStatus(1);
ipResourceRepository.save(ipResource);
......@@ -711,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);
}
}
}
......@@ -7,10 +7,7 @@ import com.edgec.browserbackend.account.repository.AccountRepository;
import com.edgec.browserbackend.browser.ErrorCode.BrowserErrorCode;
import com.edgec.browserbackend.browser.domain.*;
import com.edgec.browserbackend.browser.dto.*;
import com.edgec.browserbackend.browser.repository.GroupRepository;
import com.edgec.browserbackend.browser.repository.IpResourceRepository;
import com.edgec.browserbackend.browser.repository.ShopRepository;
import com.edgec.browserbackend.browser.repository.UserShopRepository;
import com.edgec.browserbackend.browser.repository.*;
import com.edgec.browserbackend.browser.service.IpAndShopService;
import com.edgec.browserbackend.browser.service.ShopService;
import com.edgec.browserbackend.common.commons.error.ClientRequestException;
......@@ -25,6 +22,7 @@ import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.security.core.parameters.P;
import org.springframework.security.task.DelegatingSecurityContextAsyncTaskExecutor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
......@@ -63,6 +61,9 @@ public class ShopServiceImpl implements ShopService {
@Autowired
IpAndShopService ipAndShopService;
@Autowired
SpecialLineRepository specialLineRepository;
@Override
public String addShop(String username, ShopResultDto shopResultDto) {
Account account = accountRepository.findByName(username);
......@@ -319,7 +320,13 @@ public class ShopServiceImpl implements ShopService {
if (ipResource == null)
throw new ClientRequestException(BrowserErrorCode.IPNOTEXIST);
String group = userShopRepository.findByUsernameAndShopId(username, shop.getShopId()).getGroupId();
ShopResultDto shopResultDto = ShopResultDto.of(shop, group, ipResource);
ShopResultDto shopResultDto = null;
if (ipResource.isSpecialLine()) {
SpecialLine specialLine = specialLineRepository.findAll().get(0);
shopResultDto = ShopResultDto.of(shop, group, new IpResourceDto(ipResource, null, false, specialLine));
}
else
shopResultDto = ShopResultDto.of(shop, group, new IpResourceDto(ipResource, null, false));
return shopResultDto;
}
......@@ -382,7 +389,7 @@ public class ShopServiceImpl implements ShopService {
}
Page<Shop> shops;
if (shopFilterDto != null && StringUtils.isNotBlank(shopFilterDto.getIpRegion())) {
List<String> filter = ipResourceRepository.findByRegionCnLikeAndShopIdInAndIsDeleted(shopFilterDto.getIpRegion(), shopIds, false)
List<String> filter = ipResourceRepository.findByIsDeletedAndShopIdInAndRegionCnLike(false, shopIds, shopFilterDto.getIpRegion())
.stream().map(x -> x.getShopId()).collect(Collectors.toList());
shops = shopRepository.findByShopIdInOrderByCreateTimeDesc(filter, pageable);
}
......@@ -400,7 +407,14 @@ public class ShopServiceImpl implements ShopService {
if (ipResource == null)
ipResource = new IpResource();
String group1 = userShopRepository.findByUsernameAndShopId(username, x.getShopId()).getGroupId();
shopResultDtos.add(ShopResultDto.of(x, group1, ipResource));
ShopResultDto shopResultDto = null;
if (ipResource.isSpecialLine()) {
SpecialLine specialLine = specialLineRepository.findAll().get(0);
shopResultDto = ShopResultDto.of(x, group1, new IpResourceDto(ipResource, null, false, specialLine));
}
else
shopResultDto = ShopResultDto.of(x, group1, new IpResourceDto(ipResource, null, false));
shopResultDtos.add(shopResultDto);
});
Page<ShopResultDto> shopDtoPage = new PageImpl<>(shopResultDtos, pageable, shopIds.size());
ShopPageResultDto shopPageResultDto = new ShopPageResultDto();
......
......@@ -28,4 +28,6 @@ public interface IpResourceService {
boolean queryIpExist(String username, IpResourceUpdateDto ipResourceUpdateDto);
IpResourceDto queryIp(String username, IpResourceRequestDto ipResourceRequestDto);
void setSpecialLine();
}
package com.edgec.browserbackend.browser.task;
import com.edgec.browserbackend.account.repository.AccountRepository;
import com.edgec.browserbackend.auth.domain.mongo.MongoOAuth2AccessToken;
import com.edgec.browserbackend.auth.repository.mongo.MongoOAuth2AccessTokenRepository;
import com.edgec.browserbackend.browser.domain.IpResource;
import com.edgec.browserbackend.browser.domain.SpecialLine;
import com.edgec.browserbackend.browser.repository.IpResourceRepository;
import com.edgec.browserbackend.browser.repository.SpecialLineRepository;
import com.edgec.browserbackend.browser.service.Impl.IpResourceServiceImpl;
import com.edgec.browserbackend.common.commons.utils.RemoteShellExecutor;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.io.*;
import java.time.Instant;
import java.util.List;
import java.util.stream.Collectors;
@Component
public class Set3proxyTask {
private static final Logger log = LoggerFactory.getLogger(Set3proxyTask.class);
@Autowired
private AccountRepository accountRepository;
@Autowired
private MongoOAuth2AccessTokenRepository mongoOAuth2AccessTokenRepository;
@Autowired
private IpResourceRepository ipResourceRepository;
@Autowired
private SpecialLineRepository specialLineRepository;
@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());
List<IpResource> ipResources = ipResourceRepository.findBySpecialLine(true);
File file = new File("3proxy.cfg");
SpecialLine specialLine = specialLineRepository.findAll().get(0);
try {
file.delete();
file.createNewFile();
FileWriter fileWriter =new FileWriter(file, true);
BufferedWriter bw = new BufferedWriter(fileWriter);
bw.write("daemon\nlog /var/log/3proxy.log D\nrotate 30\n");
bw.write("config /root/3proxy.cfg\n");
bw.write("monitor /root/3proxy.cfg\n");
for (IpResource ipResource : ipResources) {
if (StringUtils.isNotBlank(ipResource.getAddr()))
bw.write("users \"" + ipResource.getProxyUsername() + ":CL:" + ipResource.getProxyPassword() + "\"\n");
}
bw.write("\nauth strong\n");
for (IpResource ipResource : ipResources) {
if (StringUtils.isNotBlank(ipResource.getAddr())) {
bw.write("allow " + ipResource.getProxyUsername() + "\n");
bw.write("parent 1000 " + specialLine.getProxyProtocol().get(0) + " " + ipResource.getAddr() + " " + ipResource.getPort().get(1) + " fangguanlianbrowser " + ipResource.getPassword() + "\n");
}
}
bw.write("\nallow none\nproxy -p20004\nsocks-p20005");
bw.flush();
bw.close();
log.info("成功写入文件");
// 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());
}
}
}
......@@ -72,6 +72,7 @@ public class RemoteShellExecutor {
out = new PrintWriter(new OutputStreamWriter(session.getStdin(),
"UTF-8"));
out.println(command);
System.out.println(command);
out.flush();
} finally {
if (null != out) {
......@@ -231,22 +232,59 @@ public class RemoteShellExecutor {
throw new RuntimeException(localFile + " is not a file");
}
String fileName = file.getName();
System.out.println(fileName);
InputStream stdOut = null;
InputStream stdErr = null;
String outStr = "";
String outErr = "";
try {
Session session = conn.openSession();
executeCommand("mkdir -p " + remoteTargetDirectory, session);
} catch (Exception e) {
throw new Exception("登录远程机器失败" + ip);
}
SCPClient sCPClient = conn.createSCPClient();
SCPOutputStream scpOutputStream = sCPClient.put(fileName, file.length(), remoteTargetDirectory, "0600");
if (login()) {
Session session = conn.openSession();
session.startShell();
stdOut = new StreamGobbler(session.getStdout());
stdErr = new StreamGobbler(session.getStderr());
BufferedReader stdoutReader = new BufferedReader(new InputStreamReader(stdOut));
BufferedReader stderrReader = new BufferedReader(new InputStreamReader(stdErr));
executeCommand("mkdir -p " + remoteTargetDirectory, session);
SCPClient sCPClient = conn.createSCPClient();
SCPOutputStream scpOutputStream = sCPClient.put(fileName, file.length(), remoteTargetDirectory, "0600");
String content = IOUtils.toString(new FileInputStream(file), StandardCharsets.UTF_8);
scpOutputStream.write(content.getBytes());
scpOutputStream.flush();
scpOutputStream.close();
String content = IOUtils.toString(new FileInputStream(file), StandardCharsets.UTF_8);
scpOutputStream.write(content.getBytes());
scpOutputStream.flush();
scpOutputStream.close();
session.waitForCondition(ChannelCondition.CLOSED | ChannelCondition.EOF | ChannelCondition.EXIT_STATUS , 30000);
logger.error("Here is the output from stdout:");
while (true)
{
String line = stdoutReader.readLine();
if (line == null)
break;
System.out.println(line);
}
logger.error("Here is the output from stderr:");
while (true)
{
String line = stderrReader.readLine();
if (line == null)
break;
System.out.println(line);
}
/* Show exit status, if available (otherwise "null") */
logger.error("ExitCode: " + session.getExitStatus());
session.close();/* Close this session */
conn.close();/* Close the connection */
}
} catch (IOException e) {
logger.error(e.getMessage());
throw new Exception("登录远程机器失败" + ip);
}finally {
if (conn != null) {
conn.close();
}
IOUtils.closeQuietly(stdOut);
IOUtils.closeQuietly(stdErr);
}
}
......@@ -281,8 +319,8 @@ public class RemoteShellExecutor {
}
public static void main(String args[]) throws Exception {
RemoteShellExecutor executor = new RemoteShellExecutor("120.25.233.237", "root", "5t8EsTuDH00uaA1");
RemoteShellExecutor executor = new RemoteShellExecutor("47.112.253.229", "root", "hIB4EbOcnkF5aA1");
executor.transferFile("3proxy.cfg", "/root");
// executor.execCommand("cd /root && sh restart.sh");
executor.execCommand("cd /root && sh restart.sh");
}
}
\ No newline at end of file
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