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
36848fd7
Commit
36848fd7
authored
Jun 12, 2020
by
xuxin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
生成登录用户的 proxy 日志
parent
1df5c6d9
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
49 additions
and
56 deletions
+49
-56
ProxyConfigRepositoryCustomImpl.java
...d/browser/repository/ProxyConfigRepositoryCustomImpl.java
+2
-10
Set3proxyTask.java
.../com/edgec/browserbackend/browser/task/Set3proxyTask.java
+47
-46
No files found.
src/main/java/com/edgec/browserbackend/browser/repository/ProxyConfigRepositoryCustomImpl.java
View file @
36848fd7
package
com
.
edgec
.
browserbackend
.
browser
.
repository
;
package
com
.
edgec
.
browserbackend
.
browser
.
repository
;
import
com.edgec.browserbackend.account.repository.FileRepository
;
import
com.edgec.browserbackend.account.repository.FileRepositoryImpl
;
import
com.edgec.browserbackend.account.repository.FileRepositoryImpl
;
import
com.edgec.browserbackend.browser.domain.ProxyConfig
;
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
com.mongodb.client.result.UpdateResult
;
import
org.bson.Document
;
import
org.bson.Document
;
import
org.springframework.beans.factory.annotation.Autowired
;
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.MongoTemplate
;
import
org.springframework.data.mongodb.core.query.BasicQuery
;
import
org.springframework.data.mongodb.core.query.BasicQuery
;
import
org.springframework.data.mongodb.core.query.Update
;
import
org.springframework.data.mongodb.core.query.Update
;
import
java.io.File
;
import
java.io.File
;
import
static
org
.
springframework
.
data
.
mongodb
.
core
.
query
.
Criteria
.
where
;
public
class
ProxyConfigRepositoryCustomImpl
implements
ProxyConfigRepositoryCustom
{
public
class
ProxyConfigRepositoryCustomImpl
implements
ProxyConfigRepositoryCustom
{
@Autowired
@Autowired
...
@@ -33,10 +27,8 @@ public class ProxyConfigRepositoryCustomImpl implements ProxyConfigRepositoryCus
...
@@ -33,10 +27,8 @@ public class ProxyConfigRepositoryCustomImpl implements ProxyConfigRepositoryCus
Update
update
=
new
Update
();
Update
update
=
new
Update
();
update
.
set
(
"configFileId"
,
fileId
).
set
(
"timestamp"
,
time
);
update
.
set
(
"configFileId"
,
fileId
).
set
(
"timestamp"
,
time
);
UpdateResult
operation
=
mongoTemplate
.
upsert
(
basicQuery
,
update
,
ProxyConfig
.
class
);
UpdateResult
operation
=
mongoTemplate
.
upsert
(
basicQuery
,
update
,
ProxyConfig
.
class
);
if
(
operation
.
getModifiedCount
()
<
1
)
return
false
;
return
operation
.
getModifiedCount
()
>=
1
;
else
return
true
;
}
}
}
}
src/main/java/com/edgec/browserbackend/browser/task/Set3proxyTask.java
View file @
36848fd7
package
com
.
edgec
.
browserbackend
.
browser
.
task
;
package
com
.
edgec
.
browserbackend
.
browser
.
task
;
import
com.edgec.browserbackend.account.repository.AccountRepository
;
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.auth.repository.mongo.MongoOAuth2AccessTokenRepository
;
import
com.edgec.browserbackend.browser.domain.IpResource
;
import
com.edgec.browserbackend.browser.domain.IpResource
;
import
com.edgec.browserbackend.browser.domain.IpType
;
import
com.edgec.browserbackend.browser.domain.IpType
;
import
com.edgec.browserbackend.browser.domain.ProxyConfig
;
import
com.edgec.browserbackend.browser.repository.IpResourceRepository
;
import
com.edgec.browserbackend.browser.repository.IpResourceRepository
;
import
com.edgec.browserbackend.browser.repository.ProxyConfigRepository
;
import
com.edgec.browserbackend.browser.repository.ProxyConfigRepository
;
import
com.edgec.browserbackend.browser.repository.SpecialLineRepository
;
import
com.edgec.browserbackend.browser.repository.SpecialLineRepository
;
...
@@ -19,8 +19,10 @@ import org.springframework.stereotype.Component;
...
@@ -19,8 +19,10 @@ import org.springframework.stereotype.Component;
import
java.io.BufferedWriter
;
import
java.io.BufferedWriter
;
import
java.io.File
;
import
java.io.File
;
import
java.io.FileWriter
;
import
java.io.FileWriter
;
import
java.io.IOException
;
import
java.time.Instant
;
import
java.time.Instant
;
import
java.util.List
;
import
java.util.List
;
import
java.util.stream.Collectors
;
@Component
@Component
public
class
Set3proxyTask
{
public
class
Set3proxyTask
{
...
@@ -42,22 +44,21 @@ public class Set3proxyTask {
...
@@ -42,22 +44,21 @@ public class Set3proxyTask {
@Autowired
@Autowired
private
ProxyConfigRepository
proxyConfigRepository
;
private
ProxyConfigRepository
proxyConfigRepository
;
@Scheduled
(
cron
=
"0 0/
10
* * * ?"
)
@Scheduled
(
cron
=
"0 0/
2
* * * ?"
)
@SchedulerLock
(
name
=
"proxyTask"
,
lockAtLeastFor
=
60
*
1000
*
5
,
lockAtMostFor
=
60
*
1000
*
9
)
@SchedulerLock
(
name
=
"proxyTask"
,
lockAtLeastFor
=
60
*
1000
*
5
,
lockAtMostFor
=
60
*
1000
*
9
)
public
void
set3proxy
()
{
public
void
set3proxy
()
{
long
nowtime
=
Instant
.
now
().
toEpochMilli
();
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
<
String
>
tokenUsernames
=
mongoOAuth2AccessTokenRepository
.
findByCreatedAtGreaterThan
(
validTime
).
stream
().
map
(
MongoOAuth2AccessToken:
:
getUsername
).
collect
(
Collectors
.
toList
());
// List<IpResource> ipResources = ipResourceRepository.findByOwnerInAndSpecialLine(accountParents, true);
List
<
String
>
accountParents
=
accountRepository
.
findByNameIn
(
tokenUsernames
).
stream
().
map
(
x
->
x
.
getParent
()
==
null
?
x
.
getName
()
:
x
.
getParent
()).
distinct
().
collect
(
Collectors
.
toList
());
List
<
IpResource
>
ipResources
=
ipResourceRepository
.
findBySpecialLineAndIsDeleted
(
true
,
false
);
List
<
IpResource
>
ipResources
=
ipResourceRepository
.
findByOwnerInAndSpecialLine
(
accountParents
,
true
);
// List<IpResource> ipResources = ipResourceRepository.findBySpecialLineAndIsDeleted(true, false);
File
file
=
new
File
(
"3proxy_"
+
Instant
.
now
().
toEpochMilli
());
File
file
=
new
File
(
"3proxy_"
+
Instant
.
now
().
toEpochMilli
());
try
{
try
{
try
{
file
.
delete
();
file
.
delete
();
file
.
createNewFile
();
file
.
createNewFile
();
}
catch
(
Exception
t1
)
{
log
.
error
(
t1
.
getMessage
(),
t1
);
}
FileWriter
fileWriter
=
new
FileWriter
(
file
,
true
);
FileWriter
fileWriter
=
new
FileWriter
(
file
,
true
);
BufferedWriter
bw
=
new
BufferedWriter
(
fileWriter
);
BufferedWriter
bw
=
new
BufferedWriter
(
fileWriter
);
...
@@ -66,53 +67,53 @@ public class Set3proxyTask {
...
@@ -66,53 +67,53 @@ public class Set3proxyTask {
bw
.
write
(
"config /root/3proxy.cfg\n"
);
bw
.
write
(
"config /root/3proxy.cfg\n"
);
bw
.
write
(
"monitor /root/3proxy.cfg\n"
);
bw
.
write
(
"monitor /root/3proxy.cfg\n"
);
for
(
IpResource
ipResource
:
ipResources
)
{
// 写入 ipResources 相关信息
if
(
StringUtils
.
isNotBlank
(
ipResource
.
getAddr
()))
bwWriteIpResources
(
ipResources
,
bw
);
bw
.
write
(
"users \""
+
ipResource
.
getProxyUsername
()
+
":CL:"
+
ipResource
.
getProxyPassword
()
+
"\"\n"
);
ipResource
.
setUsingSpecialLine
(
true
);
}
bw
.
write
(
"\nauth strong\n"
);
bw
.
write
(
"\nauth strong\n"
);
a:
for
(
IpResource
ipResource
:
ipResources
)
{
if
(
StringUtils
.
isNotBlank
(
ipResource
.
getAddr
()))
{
if
(
ipResource
.
getPort
()
==
null
||
ipResource
.
getPort
().
size
()
==
0
)
continue
a
;
bw
.
write
(
"allow "
+
ipResource
.
getProxyUsername
()
+
"\n"
);
if
(
ipResource
.
getIpType
()
!=
IpType
.
OWN
)
{
bw
.
write
(
"parent 1000 http "
+
ipResource
.
getAddr
()
+
" "
+
(
ipResource
.
getPort
().
size
()
>
1
?
ipResource
.
getPort
().
get
(
1
)
:
ipResource
.
getPort
().
get
(
0
))
+
" fangguanlianbrowser "
+
ipResource
.
getPassword
()
+
"\n"
);
}
else
{
bw
.
write
(
"parent 1000 http "
+
ipResource
.
getAddr
()
+
" "
+
(
ipResource
.
getPort
().
size
()
>
1
?
ipResource
.
getPort
().
get
(
1
)
:
ipResource
.
getPort
().
get
(
0
))
+
" "
+
ipResource
.
getUsername
()
+
" "
+
ipResource
.
getPassword
()
+
"\n"
);
}
}
}
bw
.
write
(
"\nallow none\nproxy -p20004\nsocks -p20005\n"
);
bw
.
write
(
"\nallow none\nproxy -p20004\nsocks -p20005\n"
);
bw
.
flush
();
bw
.
flush
();
bw
.
close
();
bw
.
close
();
log
.
error
(
"成功写入文件"
);
log
.
info
(
"成功写入文件"
);
if
(
proxyConfigRepository
.
count
()
>
0
)
{
long
nowtime
=
Instant
.
now
().
toEpochMilli
();
ProxyConfig
proxyConfig
=
proxyConfigRepository
.
findAll
().
get
(
0
);
long
proxyConfigTimestamp
=
proxyConfigRepository
.
findAll
().
get
(
0
).
getTimestamp
();
if
(
nowtime
<
proxyConfig
.
getTimestamp
())
{
if
(
proxyConfigRepository
.
count
()
>
0
&&
nowtime
<
proxyConfigTimestamp
)
{
file
.
delete
();
file
.
delete
();
return
;
}
else
{
proxyConfigRepository
.
updateProxy
(
file
,
nowtime
);
file
.
delete
();
}
}
else
{
}
else
{
proxyConfigRepository
.
updateProxy
(
file
,
nowtime
);
proxyConfigRepository
.
updateProxy
(
file
,
nowtime
);
file
.
delete
();
file
.
delete
();
}
}
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
log
.
error
(
"出错了"
);
log
.
error
(
e
.
getMessage
(),
e
);
log
.
error
(
e
.
getMessage
(),
e
);
}
}
}
}
private
void
bwWriteIpResources
(
List
<
IpResource
>
ipResources
,
BufferedWriter
bw
)
throws
IOException
{
for
(
IpResource
ipResource
:
ipResources
)
{
ipResource
.
setUsingSpecialLine
(
true
);
if
(
StringUtils
.
isNotBlank
(
ipResource
.
getAddr
()))
{
bw
.
write
(
"users \""
+
ipResource
.
getProxyUsername
()
+
":CL:"
+
ipResource
.
getProxyPassword
()
+
"\"\n"
);
if
(
ipResource
.
getPort
()
==
null
||
ipResource
.
getPort
().
size
()
==
0
)
{
continue
;
}
bw
.
write
(
"allow "
+
ipResource
.
getProxyUsername
()
+
"\n"
);
String
textStart
=
"parent 1000 http "
+
ipResource
.
getAddr
()
+
" "
;
String
textMiddle
=
ipResource
.
getPort
().
size
()
>
1
?
ipResource
.
getPort
().
get
(
1
)
:
ipResource
.
getPort
().
get
(
0
);
if
(
ipResource
.
getIpType
()
!=
IpType
.
OWN
)
{
bw
.
write
(
textStart
+
textMiddle
+
" fangguanlianbrowser "
+
ipResource
.
getPassword
()
+
"\n"
);
}
else
{
bw
.
write
(
textStart
+
textMiddle
+
" "
+
ipResource
.
getUsername
()
+
" "
+
ipResource
.
getPassword
()
+
"\n"
);
}
}
}
}
}
}
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