Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
B
browser-backend
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
browser-backend
Commits
71f58f31
Commit
71f58f31
authored
May 07, 2020
by
renjie
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'dev-zrj' into 'staging'
1.生成3proxy配置文件 See merge request
!49
parents
9640bc43
1452ec1b
Hide whitespace changes
Inline
Side-by-side
Showing
22 changed files
with
295 additions
and
80 deletions
+295
-80
AdministratorController.java
...erbackend/account/controller/AdministratorController.java
+31
-1
AccountRepository.java
.../browserbackend/account/repository/AccountRepository.java
+1
-1
CompanyAuthorizeRepository.java
...ackend/account/repository/CompanyAuthorizeRepository.java
+1
-2
FileRepository.java
...gec/browserbackend/account/repository/FileRepository.java
+4
-2
FileRepositoryImpl.java
...browserbackend/account/repository/FileRepositoryImpl.java
+38
-15
AdministratorService.java
.../browserbackend/account/service/AdministratorService.java
+3
-0
AccountServiceImpl.java
...owserbackend/account/service/impl/AccountServiceImpl.java
+5
-5
AdministratorServiceImpl.java
...ackend/account/service/impl/AdministratorServiceImpl.java
+23
-1
PaymentServiceImpl.java
...owserbackend/account/service/impl/PaymentServiceImpl.java
+3
-3
WebSecurityConfig.java
...m/edgec/browserbackend/auth/config/WebSecurityConfig.java
+1
-1
AuthenticationFailureEventListener.java
.../service/security/AuthenticationFailureEventListener.java
+6
-0
AuthenticationSuccessEventListener.java
.../service/security/AuthenticationSuccessEventListener.java
+1
-1
ProxyConfig.java
.../com/edgec/browserbackend/browser/domain/ProxyConfig.java
+26
-0
ProxyConfigRepository.java
...wserbackend/browser/repository/ProxyConfigRepository.java
+8
-0
ProxyConfigRepositoryCustom.java
...ckend/browser/repository/ProxyConfigRepositoryCustom.java
+7
-0
ProxyConfigRepositoryCustomImpl.java
...d/browser/repository/ProxyConfigRepositoryCustomImpl.java
+42
-0
IpResourceServiceImpl.java
...erbackend/browser/service/Impl/IpResourceServiceImpl.java
+40
-28
BrowserTask.java
...va/com/edgec/browserbackend/browser/task/BrowserTask.java
+8
-0
ExpireSoonWarn.java
...com/edgec/browserbackend/browser/task/ExpireSoonWarn.java
+2
-0
PromotionTask.java
.../com/edgec/browserbackend/browser/task/PromotionTask.java
+6
-6
Set3proxyTask.java
.../com/edgec/browserbackend/browser/task/Set3proxyTask.java
+35
-11
RemoteShellExecutor.java
...wserbackend/common/commons/utils/RemoteShellExecutor.java
+4
-3
No files found.
src/main/java/com/edgec/browserbackend/account/controller/AdministratorController.java
View file @
71f58f31
...
...
@@ -8,6 +8,7 @@ import com.edgec.browserbackend.account.domain.*;
import
com.edgec.browserbackend.browser.ErrorCode.BrowserErrorCode
;
import
com.edgec.browserbackend.common.auth.Securitys
;
import
com.edgec.browserbackend.common.commons.error.ClientRequestException
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.data.domain.Page
;
import
org.springframework.data.domain.PageRequest
;
...
...
@@ -31,6 +32,8 @@ import java.util.Map;
@RequestMapping
(
"/vpsadmin"
)
public
class
AdministratorController
{
static
final
String
mykey
=
"Xi6JZQ1SbUTxjO62u1MX01hBeB7A!qQXR6jVfer@s8@9JZxNqB@NTs$vpwH9aVXe"
;
@Autowired
private
AdministratorService
administratorService
;
@Autowired
...
...
@@ -301,7 +304,7 @@ public class AdministratorController {
e
.
printStackTrace
();
throw
new
ClientRequestException
(
BrowserErrorCode
.
UNKNOWN
);
}
finally
{
tempFile
.
delete
OnExit
();
tempFile
.
delete
();
}
resultDto
.
setStatus
(
0
);
}
catch
(
ClientRequestException
e
)
{
...
...
@@ -426,6 +429,33 @@ public class AdministratorController {
return
resultDto
;
}
//获取3proxy.cfg
@RequestMapping
(
path
=
"/0xadministrator/getconfig"
,
method
=
RequestMethod
.
GET
)
public
void
getProxyConfig
(
@RequestParam
(
"key"
)
String
key
,
HttpServletResponse
response
)
{
File
file
=
null
;
if
(
StringUtils
.
isNotBlank
(
key
)
&&
key
.
equals
(
mykey
))
file
=
administratorService
.
getProxyConfig
();
if
(
file
!=
null
)
{
try
(
OutputStream
os
=
response
.
getOutputStream
();
FileInputStream
fis
=
new
FileInputStream
(
file
)){
response
.
setHeader
(
"content-type"
,
"application/octet-stream"
);
response
.
setHeader
(
"Content-Disposition"
,
"attachment;filename="
+
URLEncoder
.
encode
(
"3proxy.cfg"
,
"UTF-8"
));
int
len
=
0
;
byte
[]
bt
=
new
byte
[
5
*
1024
];
while
((
len
=
fis
.
read
(
bt
))
!=
-
1
)
{
os
.
write
(
bt
,
0
,
len
);
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
throw
new
ClientRequestException
(
BrowserErrorCode
.
UNKNOWN
);
}
finally
{
file
.
delete
();
}
}
}
}
...
...
src/main/java/com/edgec/browserbackend/account/repository/AccountRepository.java
View file @
71f58f31
...
...
@@ -41,7 +41,7 @@ public interface AccountRepository extends MongoRepository<Account, String>, Acc
List
<
Account
>
findByNameIn
(
List
<
String
>
names
);
List
<
Account
>
findByPromotionCode
(
String
code
);
List
<
Account
>
findByPromotionCode
AndParentIsNull
(
String
code
);
int
countByPromotionCodeAndParentIsNull
(
String
promotionCode
);
}
src/main/java/com/edgec/browserbackend/account/repository/CompanyAuthorizeRepository.java
View file @
71f58f31
package
com
.
edgec
.
browserbackend
.
account
.
repository
;
import
com.edgec.browserbackend.account.domain.CompanyAuthorize
;
import
com.edgec.browserbackend.account.dto.CompanyAuthorizeDto
;
import
org.springframework.data.mongodb.repository.MongoRepository
;
public
interface
CompanyAuthorizeRepository
extends
MongoRepository
<
CompanyAuthorize
,
String
>,
CompanyAuthorizeRepositoryCustom
{
public
interface
CompanyAuthorizeRepository
extends
MongoRepository
<
CompanyAuthorize
,
String
>,
FileRepository
{
CompanyAuthorize
findByUsername
(
String
username
);
}
src/main/java/com/edgec/browserbackend/account/repository/
CompanyAuthorizeRepositoryCustom
.java
→
src/main/java/com/edgec/browserbackend/account/repository/
FileRepository
.java
View file @
71f58f31
...
...
@@ -5,8 +5,10 @@ import org.springframework.web.multipart.MultipartFile;
import
java.io.File
;
public
interface
CompanyAuthorizeRepositoryCustom
{
public
interface
FileRepository
{
String
saveFile
(
MultipartFile
file
,
String
filename
);
String
saveFile
(
File
file
,
String
filename
);
void
deleteFile
(
String
fileId
);
File
getFile
(
String
fileId
);
File
getFile
(
String
fileId
,
String
suffix
);
String
updateFile
(
File
file
,
String
filename
);
}
src/main/java/com/edgec/browserbackend/account/repository/
CompanyAuthorizeRepositoryCustom
Impl.java
→
src/main/java/com/edgec/browserbackend/account/repository/
FileRepository
Impl.java
View file @
71f58f31
...
...
@@ -2,18 +2,13 @@ package com.edgec.browserbackend.account.repository;
import
com.edgec.browserbackend.browser.ErrorCode.BrowserErrorCode
;
import
com.edgec.browserbackend.common.commons.error.ClientRequestException
;
import
com.mongodb.DB
;
import
com.mongodb.client.gridfs.GridFSBucket
;
import
com.mongodb.client.gridfs.GridFSDownloadStream
;
import
com.mongodb.client.gridfs.model.GridFSFile
;
import
com.mongodb.gridfs.GridFS
;
import
com.mongodb.gridfs.GridFSDBFile
;
import
com.mongodb.gridfs.GridFSInputFile
;
import
org.bson.types.ObjectId
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.data.mongodb.MongoDbFactory
;
import
org.springframework.data.mongodb.core.MongoTemplate
;
import
org.springframework.data.mongodb.core.query.Criteria
;
import
org.springframework.data.mongodb.core.query.Query
;
...
...
@@ -22,14 +17,11 @@ import org.springframework.data.mongodb.gridfs.GridFsResource;
import
org.springframework.data.mongodb.gridfs.GridFsTemplate
;
import
org.springframework.web.multipart.MultipartFile
;
import
java.io.ByteArrayOutputStream
;
import
java.io.File
;
import
java.io.FileOutputStream
;
import
java.io.InputStream
;
import
java.io.*
;
public
class
CompanyAuthorizeRepositoryCustomImpl
implements
CompanyAuthorizeRepositoryCustom
{
public
class
FileRepositoryImpl
implements
FileRepository
{
private
final
Logger
logger
=
LoggerFactory
.
getLogger
(
CompanyAuthorizeRepositoryCustom
Impl
.
class
);
private
final
Logger
logger
=
LoggerFactory
.
getLogger
(
FileRepository
Impl
.
class
);
@Autowired
private
GridFsTemplate
gridFsTemplate
;
...
...
@@ -56,6 +48,18 @@ public class CompanyAuthorizeRepositoryCustomImpl implements CompanyAuthorizeRep
}
}
@Override
public
String
saveFile
(
File
file
,
String
filename
)
{
try
{
InputStream
in
=
new
FileInputStream
(
file
);
ObjectId
id
=
gridFsTemplate
.
store
(
in
,
filename
);
return
id
.
toString
();
}
catch
(
Exception
e
)
{
logger
.
error
(
"存储文件时发生错误!!!"
,
e
);
throw
new
ClientRequestException
(
BrowserErrorCode
.
UNKNOWN
);
}
}
@Override
public
void
deleteFile
(
String
fileId
)
{
Query
query
=
Query
.
query
(
Criteria
.
where
(
"_id"
).
is
(
fileId
));
...
...
@@ -68,7 +72,7 @@ public class CompanyAuthorizeRepositoryCustomImpl implements CompanyAuthorizeRep
}
@Override
public
File
getFile
(
String
fileId
)
{
public
File
getFile
(
String
fileId
,
String
suffix
)
{
Query
query
=
Query
.
query
(
Criteria
.
where
(
"_id"
).
is
(
fileId
));
// 查询单个文件
GridFSFile
gridFSFile
=
gridFsTemplate
.
findOne
(
query
);
...
...
@@ -81,7 +85,7 @@ public class CompanyAuthorizeRepositoryCustomImpl implements CompanyAuthorizeRep
InputStream
inputStream
=
gridFsResource
.
getInputStream
();
byte
[]
f
=
getBytes
(
inputStream
);
File
file
=
new
File
(
gridFSFile
.
getFilename
()
+
".png"
);
File
file
=
new
File
(
gridFSFile
.
getFilename
()
+
suffix
);
FileOutputStream
out
=
new
FileOutputStream
(
file
);
out
.
write
(
f
);
out
.
close
();
...
...
@@ -102,6 +106,25 @@ public class CompanyAuthorizeRepositoryCustomImpl implements CompanyAuthorizeRep
return
bos
.
toByteArray
();
}
@Override
public
String
updateFile
(
File
file
,
String
filename
)
{
try
{
InputStream
in
=
new
FileInputStream
(
file
);
Query
query
=
Query
.
query
(
Criteria
.
where
(
"filename"
).
is
(
filename
));
// 查询单个文件
GridFSFile
gridFSFile
=
gridFsTemplate
.
findOne
(
query
);
ObjectId
id
;
if
(
gridFSFile
==
null
)
id
=
gridFsTemplate
.
store
(
in
,
filename
);
else
{
gridFsTemplate
.
delete
(
query
);
id
=
gridFsTemplate
.
store
(
in
,
filename
);
}
in
.
close
();
return
id
.
toString
();
}
catch
(
Exception
e
)
{
logger
.
error
(
"更新文件时发生错误!!!"
,
e
);
throw
new
ClientRequestException
(
BrowserErrorCode
.
UNKNOWN
);
}
}
}
src/main/java/com/edgec/browserbackend/account/service/AdministratorService.java
View file @
71f58f31
...
...
@@ -9,6 +9,7 @@ import com.edgec.browserbackend.browser.dto.IpResourceDto;
import
org.springframework.data.domain.Page
;
import
org.springframework.data.domain.Pageable
;
import
java.io.File
;
import
java.util.HashMap
;
import
java.util.List
;
...
...
@@ -60,4 +61,6 @@ public interface AdministratorService {
PromotionQueryResultDto
queryPromotion
(
Pageable
pageable
,
String
username
,
String
promotionCode
,
String
strDate1
,
String
strDate2
);
void
addWhiteList
(
String
website
);
File
getProxyConfig
();
}
src/main/java/com/edgec/browserbackend/account/service/impl/AccountServiceImpl.java
View file @
71f58f31
...
...
@@ -1142,15 +1142,15 @@ public class AccountServiceImpl implements AccountService {
CompanyAuthorize
companyAuthorize
=
companyAuthorizeRepository
.
findByUsername
(
username
);
if
(
companyAuthorize
==
null
)
return
null
;
File
companyLicense
=
companyAuthorizeRepository
.
getFile
(
companyAuthorize
.
getCompanyLicenseId
());
File
coporationLicense_Front
=
companyAuthorizeRepository
.
getFile
(
companyAuthorize
.
getCoporationLicenseFront
());
File
coporationLicense_Back
=
companyAuthorizeRepository
.
getFile
(
companyAuthorize
.
getCoporationLicenseBack
());
File
companyLicense
=
companyAuthorizeRepository
.
getFile
(
companyAuthorize
.
getCompanyLicenseId
()
,
".png"
);
File
coporationLicense_Front
=
companyAuthorizeRepository
.
getFile
(
companyAuthorize
.
getCoporationLicenseFront
()
,
".png"
);
File
coporationLicense_Back
=
companyAuthorizeRepository
.
getFile
(
companyAuthorize
.
getCoporationLicenseBack
()
,
".png"
);
File
agencyLicense_Front
=
null
;
File
agencyLicense_Back
=
null
;
if
(
companyAuthorize
.
getAgencyFront
()
!=
null
)
agencyLicense_Front
=
companyAuthorizeRepository
.
getFile
(
companyAuthorize
.
getAgencyFront
());
agencyLicense_Front
=
companyAuthorizeRepository
.
getFile
(
companyAuthorize
.
getAgencyFront
()
,
".png"
);
if
(
companyAuthorize
.
getAgencyBack
()
!=
null
)
agencyLicense_Back
=
companyAuthorizeRepository
.
getFile
(
companyAuthorize
.
getAgencyBack
());
agencyLicense_Back
=
companyAuthorizeRepository
.
getFile
(
companyAuthorize
.
getAgencyBack
()
,
".png"
);
try
{
File
tempFile
=
File
.
createTempFile
(
"tempFile"
,
"zip"
);
List
<
File
>
files
=
Arrays
.
asList
(
companyLicense
,
coporationLicense_Front
,
coporationLicense_Back
);
...
...
src/main/java/com/edgec/browserbackend/account/service/impl/AdministratorServiceImpl.java
View file @
71f58f31
...
...
@@ -10,8 +10,11 @@ import com.edgec.browserbackend.account.repository.*;
import
com.edgec.browserbackend.account.service.AdministratorService
;
import
com.edgec.browserbackend.auth.service.UserService
;
import
com.edgec.browserbackend.browser.ErrorCode.BrowserErrorCode
;
import
com.edgec.browserbackend.browser.domain.ProxyConfig
;
import
com.edgec.browserbackend.browser.repository.IpResourceRepository
;
import
com.edgec.browserbackend.browser.repository.ProxyConfigRepository
;
import
com.edgec.browserbackend.common.commons.error.ClientRequestException
;
import
com.edgec.browserbackend.common.commons.utils.DateConverter
;
import
org.apache.commons.lang3.StringUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
...
...
@@ -23,6 +26,7 @@ import org.springframework.data.domain.PageRequest;
import
org.springframework.data.domain.Pageable
;
import
org.springframework.stereotype.Service
;
import
java.io.File
;
import
java.text.ParseException
;
import
java.text.SimpleDateFormat
;
import
java.time.ZoneOffset
;
...
...
@@ -60,6 +64,9 @@ public class AdministratorServiceImpl implements AdministratorService {
@Autowired
private
WhiteSiteRepository
whiteSiteRepository
;
@Autowired
private
ProxyConfigRepository
proxyConfigRepository
;
@Override
public
Administrator
createAdministrator
(
Administrator
administrator
)
{
Administrator
administrator1
=
new
Administrator
();
...
...
@@ -424,7 +431,7 @@ public class AdministratorServiceImpl implements AdministratorService {
promotion
.
setCommission
(
promotion
.
getCommission
()
+
x
.
getPromotion
().
getCommission
());
double
secondCommission
=
0
;
if
(
finalAccount
.
getPromotion
().
isSale
()
&&
x
.
getParent
()
==
null
)
{
List
<
Account
>
secondPromotes
=
accountRepository
.
findByPromotionCode
(
x
.
getPromotion
().
getCode
());
List
<
Account
>
secondPromotes
=
accountRepository
.
findByPromotionCode
AndParentIsNull
(
x
.
getPromotion
().
getCode
());
if
(
secondPromotes
!=
null
&&
secondPromotes
.
size
()
>
0
)
{
for
(
Account
secondPromote
:
secondPromotes
)
{
List
<
UserPrePaidBilling
>
userPrePaidBillings1
=
userPrePaidBillingRepository
.
findByAdministratorAndPayMethodInAndTimestampBetween
(
secondPromote
.
getName
(),
Arrays
.
asList
(
1
,
2
,
3
),
dateTime1
.
getTime
(),
dateTime2
.
getTime
());
...
...
@@ -457,6 +464,21 @@ public class AdministratorServiceImpl implements AdministratorService {
whiteSite
.
setWhite
(
website
);
whiteSiteRepository
.
save
(
whiteSite
);
}
@Override
public
File
getProxyConfig
()
{
ProxyConfig
proxyConfig
=
null
;
if
(
proxyConfigRepository
.
count
()
>
0
)
proxyConfig
=
proxyConfigRepository
.
findAll
().
get
(
0
);
if
(
proxyConfig
==
null
)
return
null
;
File
file
=
proxyConfigRepository
.
getFile
(
proxyConfig
.
getConfigFileId
(),
".cfg"
);
if
(
file
!=
null
)
return
file
;
else
return
null
;
}
}
...
...
src/main/java/com/edgec/browserbackend/account/service/impl/PaymentServiceImpl.java
View file @
71f58f31
...
...
@@ -284,7 +284,7 @@ public class PaymentServiceImpl implements PaymentService {
+
"}"
);
AlipayTradeQueryResponse
response
=
alipayClient
.
execute
(
alipayRequest
);
log
.
error
(
"ali order status :"
+
JSONObject
.
toJSONString
(
response
));
log
.
info
(
"ali order status :"
+
JSONObject
.
toJSONString
(
response
));
if
(
response
.
getTradeStatus
()
==
null
)
{
result
.
setPaid
(
false
);
result
.
setStatus
(
convertAlipayStatus
(
"WAIT_BUYER_PAY"
));
...
...
@@ -678,7 +678,7 @@ public class PaymentServiceImpl implements PaymentService {
accountRepository
.
save
(
byName
);
internalOrder
.
setSucceed
(
false
);
userWithdrawRepository
.
save
(
internalOrder
);
log
.
error
(
response
.
getBody
());
log
.
info
(
response
.
getBody
());
return
false
;
}
}
catch
(
Exception
e
)
{
...
...
@@ -815,7 +815,7 @@ public class PaymentServiceImpl implements PaymentService {
+
"}"
);
AlipayTradeQueryResponse
response
=
alipayClient
.
execute
(
alipayRequest
);
log
.
error
(
"ali order status :"
+
JSONObject
.
toJSONString
(
response
));
log
.
info
(
"ali order status :"
+
JSONObject
.
toJSONString
(
response
));
result
.
setStatus
(
convertAlipayStatus
(
response
.
getTradeStatus
()));
if
(
"TRADE_SUCCESS"
.
equals
(
response
.
getTradeStatus
())
||
"TRADE_FINISHED"
.
equals
(
response
.
getTradeStatus
()))
{
...
...
src/main/java/com/edgec/browserbackend/auth/config/WebSecurityConfig.java
View file @
71f58f31
...
...
@@ -33,7 +33,7 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
public
void
configure
(
WebSecurity
web
)
throws
Exception
{
web
.
ignoring
()
.
antMatchers
(
"/user/authCode"
,
"/user/signUp"
,
"/user/forgot**"
);
"/user/forgot**"
,
"/0xadministrator/getconfig**"
);
}
@Override
...
...
src/main/java/com/edgec/browserbackend/auth/service/security/AuthenticationFailureEventListener.java
View file @
71f58f31
...
...
@@ -6,6 +6,8 @@ import com.edgec.browserbackend.auth.exception.AuthErrorCode;
import
com.edgec.browserbackend.auth.repository.UserAttemptsLoginRepository
;
import
com.edgec.browserbackend.auth.repository.UserRepository
;
import
com.edgec.browserbackend.common.commons.error.ClientRequestException
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.context.ApplicationListener
;
import
org.springframework.security.authentication.event.AuthenticationFailureBadCredentialsEvent
;
...
...
@@ -16,6 +18,8 @@ import java.util.Date;
@Component
public
class
AuthenticationFailureEventListener
implements
ApplicationListener
<
AuthenticationFailureBadCredentialsEvent
>
{
private
static
final
Logger
log
=
LoggerFactory
.
getLogger
(
AuthenticationFailureEventListener
.
class
);
@Autowired
private
UserRepository
userRepository
;
...
...
@@ -30,8 +34,10 @@ public class AuthenticationFailureEventListener implements ApplicationListener<A
if
(
user
!=
null
)
{
UserAttemptsLogin
userAttempts
=
userAttemptsLoginRepository
.
findById
(
username
).
orElse
(
null
);
if
(
userAttempts
!=
null
)
{
log
.
error
(
userAttempts
.
getAttempts
()
+
"!!!"
);
if
(
userAttempts
.
getDate
().
getTime
()
>=
(
new
Date
().
getTime
()
-
600000
))
{
int
fails
=
userAttempts
.
getAttempts
();
log
.
error
(
"faile"
+
fails
);
if
(
fails
<
20
)
saveUserAttemptsLogin
(
username
,
fails
+
1
);
else
...
...
src/main/java/com/edgec/browserbackend/auth/service/security/AuthenticationSuccessEventListener.java
View file @
71f58f31
...
...
@@ -31,7 +31,7 @@ public class AuthenticationSuccessEventListener implements ApplicationListener<A
if
(
user
!=
null
)
{
UserAttemptsLogin
userAttempts
=
userAttemptsLoginRepository
.
findById
(
username
).
orElse
(
null
);
if
(
userAttempts
!=
null
)
{
if
(
userAttempts
.
getAttempts
()
>=
5
)
{
if
(
userAttempts
.
getAttempts
()
>=
20
)
{
if
(
userAttempts
.
getDate
().
getTime
()
>=
(
new
Date
().
getTime
()
-
600000
))
throw
new
ClientRequestException
(
AuthErrorCode
.
LOGINTIMESEXCEEDED
,
"Login times exceeded"
);
}
else
if
(
userAttempts
.
getAttempts
()
!=
0
)
{
...
...
src/main/java/com/edgec/browserbackend/browser/domain/ProxyConfig.java
0 → 100644
View file @
71f58f31
package
com
.
edgec
.
browserbackend
.
browser
.
domain
;
import
org.springframework.data.mongodb.core.mapping.Document
;
@Document
(
collection
=
"proxyconfig"
)
public
class
ProxyConfig
{
private
long
timestamp
;
private
String
configFileId
;
public
long
getTimestamp
()
{
return
timestamp
;
}
public
void
setConfigFileId
(
String
configFileId
)
{
this
.
configFileId
=
configFileId
;
}
public
String
getConfigFileId
()
{
return
configFileId
;
}
public
void
setTimestamp
(
long
timestamp
)
{
this
.
timestamp
=
timestamp
;
}
}
src/main/java/com/edgec/browserbackend/browser/repository/ProxyConfigRepository.java
0 → 100644
View file @
71f58f31
package
com
.
edgec
.
browserbackend
.
browser
.
repository
;
import
com.edgec.browserbackend.account.repository.FileRepository
;
import
com.edgec.browserbackend.browser.domain.ProxyConfig
;
import
org.springframework.data.mongodb.repository.MongoRepository
;
public
interface
ProxyConfigRepository
extends
MongoRepository
<
ProxyConfig
,
String
>,
FileRepository
,
ProxyConfigRepositoryCustom
{
}
src/main/java/com/edgec/browserbackend/browser/repository/ProxyConfigRepositoryCustom.java
0 → 100644
View file @
71f58f31
package
com
.
edgec
.
browserbackend
.
browser
.
repository
;
import
java.io.File
;
public
interface
ProxyConfigRepositoryCustom
{
boolean
updateProxy
(
File
file
,
long
time
);
}
src/main/java/com/edgec/browserbackend/browser/repository/ProxyConfigRepositoryCustomImpl.java
0 → 100644
View file @
71f58f31
package
com
.
edgec
.
browserbackend
.
browser
.
repository
;
import
com.edgec.browserbackend.account.repository.FileRepository
;
import
com.edgec.browserbackend.account.repository.FileRepositoryImpl
;
import
com.edgec.browserbackend.browser.domain.ProxyConfig
;
import
com.edgec.browserbackend.browser.domain.UserShop
;
import
com.mongodb.client.result.DeleteResult
;
import
com.mongodb.client.result.UpdateResult
;
import
org.bson.Document
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Qualifier
;
import
org.springframework.data.mongodb.core.MongoTemplate
;
import
org.springframework.data.mongodb.core.query.BasicQuery
;
import
org.springframework.data.mongodb.core.query.Update
;
import
java.io.File
;
import
static
org
.
springframework
.
data
.
mongodb
.
core
.
query
.
Criteria
.
where
;
public
class
ProxyConfigRepositoryCustomImpl
implements
ProxyConfigRepositoryCustom
{
@Autowired
private
FileRepositoryImpl
fileRepository
;
@Autowired
private
MongoTemplate
mongoTemplate
;
@Override
public
boolean
updateProxy
(
File
file
,
long
time
)
{
String
fileId
=
fileRepository
.
updateFile
(
file
,
"3proxy"
);
Document
doc
=
new
Document
();
BasicQuery
basicQuery
=
new
BasicQuery
(
doc
);
Update
update
=
new
Update
();
update
.
set
(
"configFileId"
,
fileId
).
set
(
"timestamp"
,
time
);
UpdateResult
operation
=
mongoTemplate
.
upsert
(
basicQuery
,
update
,
ProxyConfig
.
class
);
if
(
operation
.
getModifiedCount
()
<
1
)
return
false
;
else
return
true
;
}
}
src/main/java/com/edgec/browserbackend/browser/service/Impl/IpResourceServiceImpl.java
View file @
71f58f31
...
...
@@ -52,6 +52,35 @@ public class IpResourceServiceImpl implements IpResourceService {
private
static
String
TESTURL
=
"http://112.74.13.2"
;
private
static
String
USERNAME
=
"fangguanlianbrowser"
;
public
static
List
<
String
>
region
=
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"
);
private
static
List
<
String
>
port
=
Arrays
.
asList
(
"20000"
,
"20001"
);
private
static
List
<
String
>
protocol
=
Arrays
.
asList
(
"socks5"
,
"proxy"
);
...
...
@@ -255,6 +284,11 @@ public class IpResourceServiceImpl implements IpResourceService {
if
(
account
.
getParent
()
!=
null
)
ipResource
.
setUserParent
(
account
.
getParent
());
ipResource
.
setRegion
(
ipResourceRequestDto
.
getRegion
());
if
(
StringUtils
.
isNotBlank
(
ipResource
.
getRegion
())
&&
region
.
contains
(
ipResource
.
getRegion
()))
{
ipResource
.
setProxyUsername
(
ipResource
.
getAddr
());
ipResource
.
setProxyPassword
(
genRandom
(
3
,
12
));
ipResource
.
setSpecialLine
(
true
);
}
ipResource
.
setRegionCn
(
ipResourceRequestDto
.
getRegionCn
());
ipResource
.
setProtocol
(
protocol
);
ipResource
.
setPassword
(
password
);
...
...
@@ -660,6 +694,11 @@ public class IpResourceServiceImpl implements IpResourceService {
if
(
StringUtils
.
isNotBlank
(
ipResourceUpdateDto
.
getAddr
()))
{
ipResource
.
setAddr
(
ipResourceUpdateDto
.
getAddr
());
}
if
(
StringUtils
.
isNotBlank
(
ipResource
.
getRegion
())
&&
region
.
contains
(
ipResource
.
getRegion
()))
{
ipResource
.
setProxyUsername
(
ipResource
.
getAddr
());
ipResource
.
setProxyPassword
(
genRandom
(
3
,
12
));
ipResource
.
setSpecialLine
(
true
);
}
ipResource
.
setStatus
(
ipResourceUpdateDto
.
getStatus
());
ipResourceRepository
.
save
(
ipResource
);
}
...
...
@@ -725,34 +764,7 @@ public class IpResourceServiceImpl implements IpResourceService {
@Override
public
void
setSpecialLine
()
{
List
<
IpResource
>
ipResources
=
ipResourceRepository
.
findByRegionInAndIsDeleted
(
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"
),
false
);
List
<
IpResource
>
ipResources
=
ipResourceRepository
.
findByRegionInAndIsDeleted
(
region
,
false
);
for
(
IpResource
ipResource
:
ipResources
)
{
ipResource
.
setProxyUsername
(
ipResource
.
getAddr
());
ipResource
.
setProxyPassword
(
genRandom
(
3
,
12
));
...
...
src/main/java/com/edgec/browserbackend/browser/task/BrowserTask.java
View file @
71f58f31
...
...
@@ -26,6 +26,9 @@ import java.util.Map;
import
java.util.concurrent.CompletableFuture
;
import
java.util.concurrent.atomic.AtomicInteger
;
import
static
com
.
edgec
.
browserbackend
.
browser
.
service
.
Impl
.
IpResourceServiceImpl
.
genRandom
;
import
static
com
.
edgec
.
browserbackend
.
browser
.
service
.
Impl
.
IpResourceServiceImpl
.
region
;
@Component
public
class
BrowserTask
{
...
...
@@ -123,6 +126,11 @@ public class BrowserTask {
ipResource
.
setAddr
(
x
.
getIp
());
ipResource
.
setStatus
(
3
);
ipResource
.
setValidTime
(
Instant
.
parse
(
x
.
getValidTill
()).
toEpochMilli
());
if
(
StringUtils
.
isNotBlank
(
ipResource
.
getRegion
())
&&
region
.
contains
(
ipResource
.
getRegion
()))
{
ipResource
.
setProxyUsername
(
ipResource
.
getAddr
());
ipResource
.
setProxyPassword
(
genRandom
(
3
,
12
));
ipResource
.
setSpecialLine
(
true
);
}
ipResourceRepository
.
save
(
ipResource
);
}
else
{
log
.
error
(
"no ipResource"
);
...
...
src/main/java/com/edgec/browserbackend/browser/task/ExpireSoonWarn.java
View file @
71f58f31
...
...
@@ -6,6 +6,7 @@ import com.edgec.browserbackend.account.repository.AccountRepository;
import
com.edgec.browserbackend.browser.domain.IpResource
;
import
com.edgec.browserbackend.browser.repository.IpResourceRepository
;
import
com.edgec.browserbackend.common.commons.utils.SmsUtils
;
import
net.javacrumbs.shedlock.core.SchedulerLock
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.scheduling.annotation.Scheduled
;
import
org.springframework.stereotype.Component
;
...
...
@@ -26,6 +27,7 @@ public class ExpireSoonWarn {
private
IpResourceRepository
ipResourceRepository
;
@Scheduled
(
cron
=
"0 0 9 * * ?"
)
@SchedulerLock
(
name
=
"ExpireSoonWarnsendMessages"
,
lockAtMostForString
=
"PT600S"
,
lockAtLeastForString
=
"PT600S"
)
public
void
sendMessages
()
{
this
.
sendExpiredIpAccount
(
0
);
this
.
sendExpiredIpAccount
(
7
);
...
...
src/main/java/com/edgec/browserbackend/browser/task/PromotionTask.java
View file @
71f58f31
...
...
@@ -29,13 +29,13 @@ public class PromotionTask {
@Autowired
private
UserPrePaidBillingRepository
userPrePaidBillingRepository
;
@SchedulerLock
(
name
=
"
transferExpiredScalingGroups
"
,
lockAtLeastForString
=
"PT1H"
,
lockAtMostForString
=
"PT2H"
)
@SchedulerLock
(
name
=
"
countGift
"
,
lockAtLeastForString
=
"PT1H"
,
lockAtMostForString
=
"PT2H"
)
@Scheduled
(
cron
=
"0 0 1 1 * ?"
)
public
void
countGift
()
{
List
<
Account
>
accounts
=
accountRepository
.
findByParentIsNull
();
for
(
Account
account
:
accounts
)
{
String
code
=
account
.
getPromotion
().
getCode
();
List
<
Account
>
promotes
=
accountRepository
.
findByPromotionCode
(
code
);
List
<
Account
>
promotes
=
accountRepository
.
findByPromotionCode
AndParentIsNull
(
code
);
double
totalCommission
=
0
;
double
secondCommission
=
0
;
for
(
Account
promote
:
promotes
)
{
...
...
@@ -44,7 +44,7 @@ public class PromotionTask {
YearMonth
.
now
().
minusMonths
(
1
).
getMonthValue
(),
Arrays
.
asList
(
1
,
2
,
3
));
totalCommission
+=
userPrePaidBillings
.
stream
().
mapToDouble
(
UserPrePaidBilling:
:
getTotal
).
sum
();
if
(
account
.
getPromotion
().
isSale
()
&&
promote
.
getParent
()
==
null
)
{
List
<
Account
>
secondPromotes
=
accountRepository
.
findByPromotionCode
(
promote
.
getPromotion
().
getCode
());
List
<
Account
>
secondPromotes
=
accountRepository
.
findByPromotionCode
AndParentIsNull
(
promote
.
getPromotion
().
getCode
());
if
(
secondPromotes
!=
null
&&
secondPromotes
.
size
()
>
0
)
{
for
(
Account
secondPromote
:
secondPromotes
)
{
List
<
UserPrePaidBilling
>
userPrePaidBillings1
=
userPrePaidBillingRepository
.
findByAdministratorAndYearAndMonthAndPayMethodIn
(
secondPromote
.
getName
(),
...
...
@@ -67,13 +67,13 @@ public class PromotionTask {
}
}
@SchedulerLock
(
name
=
"
transferExpiredScalingGroups
"
,
lockAtLeastForString
=
"PT1H"
,
lockAtMostForString
=
"PT2H"
)
@SchedulerLock
(
name
=
"
countCommission
"
,
lockAtLeastForString
=
"PT1H"
,
lockAtMostForString
=
"PT2H"
)
@Scheduled
(
cron
=
"0 0 1 * * ?"
)
public
void
countCommission
()
{
List
<
Account
>
accounts
=
accountRepository
.
findByParentIsNull
();
for
(
Account
account
:
accounts
)
{
String
code
=
account
.
getPromotion
().
getCode
();
List
<
Account
>
promotes
=
accountRepository
.
findByPromotionCode
(
code
);
List
<
Account
>
promotes
=
accountRepository
.
findByPromotionCode
AndParentIsNull
(
code
);
double
totalCommission
=
0
;
double
secondCommission
=
0
;
for
(
Account
promote
:
promotes
)
{
...
...
@@ -82,7 +82,7 @@ public class PromotionTask {
YearMonth
.
now
().
getMonthValue
(),
Arrays
.
asList
(
1
,
2
,
3
));
totalCommission
+=
userPrePaidBillings
.
stream
().
mapToDouble
(
UserPrePaidBilling:
:
getTotal
).
sum
();
if
(
account
.
getPromotion
().
isSale
()
&&
promote
.
getParent
()
==
null
)
{
List
<
Account
>
secondPromotes
=
accountRepository
.
findByPromotionCode
(
promote
.
getPromotion
().
getCode
());
List
<
Account
>
secondPromotes
=
accountRepository
.
findByPromotionCode
AndParentIsNull
(
promote
.
getPromotion
().
getCode
());
if
(
secondPromotes
!=
null
&&
secondPromotes
.
size
()
>
0
)
{
for
(
Account
secondPromote
:
secondPromotes
)
{
List
<
UserPrePaidBilling
>
userPrePaidBillings1
=
userPrePaidBillingRepository
.
findByAdministratorAndYearAndMonthAndPayMethodIn
(
secondPromote
.
getName
(),
...
...
src/main/java/com/edgec/browserbackend/browser/task/Set3proxyTask.java
View file @
71f58f31
package
com
.
edgec
.
browserbackend
.
browser
.
task
;
import
com.edgec.browserbackend.account.repository.AccountRepository
;
import
com.edgec.browserbackend.account.repository.CompanyAuthorizeRepository
;
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.ProxyConfig
;
import
com.edgec.browserbackend.browser.domain.SpecialLine
;
import
com.edgec.browserbackend.browser.repository.IpResourceRepository
;
import
com.edgec.browserbackend.browser.repository.ProxyConfigRepository
;
import
com.edgec.browserbackend.browser.repository.SpecialLineRepository
;
import
com.edgec.browserbackend.browser.service.Impl.IpResourceServiceImpl
;
import
com.edgec.browserbackend.common.commons.utils.RemoteShellExecutor
;
import
net.javacrumbs.shedlock.core.SchedulerLock
;
import
org.apache.commons.lang3.StringUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
...
...
@@ -38,17 +40,28 @@ public class Set3proxyTask {
@Autowired
private
SpecialLineRepository
specialLineRepository
;
@Autowired
private
ProxyConfigRepository
proxyConfigRepository
;
@Scheduled
(
cron
=
"0 0/10 * * * ?"
)
@SchedulerLock
(
name
=
"proxyTask"
,
lockAtLeastFor
=
60
*
1000
*
5
,
lockAtMostFor
=
60
*
1000
*
9
)
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"
);
if
(
proxyConfigRepository
.
count
()
>
0
)
{
ProxyConfig
proxyConfig
=
proxyConfigRepository
.
findAll
().
get
(
0
);
if
(
Instant
.
now
().
toEpochMilli
()
<
proxyConfig
.
getTimestamp
())
return
;
}
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
.
findByOwnerInAndSpecialLine
(
accountParents
,
true
);
// List<IpResource> ipResources = ipResourceRepository.findBySpecialLine(true);
File
file
=
new
File
(
"3proxy "
+
Instant
.
now
().
toEpochMilli
());
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"
);
...
...
@@ -64,16 +77,27 @@ public class Set3proxyTask {
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
(
"parent 1000
http
"
+
ipResource
.
getAddr
()
+
" "
+
ipResource
.
getPort
().
get
(
1
)
+
" fangguanlianbrowser "
+
ipResource
.
getPassword
()
+
"\n"
);
}
}
bw
.
write
(
"\nallow none\nproxy -p20004\nsocks
-p20005
"
);
bw
.
write
(
"\nallow none\nproxy -p20004\nsocks
-p20005\n
"
);
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");
long
nowtime
=
Instant
.
now
().
toEpochMilli
();
if
(
proxyConfigRepository
.
count
()
>
0
)
{
ProxyConfig
proxyConfig
=
proxyConfigRepository
.
findAll
().
get
(
0
);
if
(
nowtime
<
proxyConfig
.
getTimestamp
())
{
file
.
delete
();
return
;
}
else
{
proxyConfigRepository
.
updateProxy
(
file
,
nowtime
);
file
.
delete
();
}
}
else
{
proxyConfigRepository
.
updateProxy
(
file
,
nowtime
);
file
.
delete
();
}
}
catch
(
Exception
e
)
{
log
.
error
(
"出错了"
);
log
.
error
(
e
.
getMessage
());
...
...
src/main/java/com/edgec/browserbackend/common/commons/utils/RemoteShellExecutor.java
View file @
71f58f31
...
...
@@ -319,8 +319,8 @@ public class RemoteShellExecutor {
}
public
static
void
main
(
String
args
[])
throws
Exception
{
RemoteShellExecutor
executor
=
new
RemoteShellExecutor
(
"47.112.253.229"
,
"root"
,
"hIB4EbOcnkF5aA1"
);
executor
.
transferFile
(
"3proxy.cfg"
,
"/root"
);
executor
.
execCommand
(
"cd /root && sh restart.sh"
);
//
RemoteShellExecutor executor = new RemoteShellExecutor("47.112.253.229", "root", "hIB4EbOcnkF5aA1");
//
executor.transferFile("3proxy.cfg", "/root");
//
executor.execCommand("cd /root && sh restart.sh");
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment