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
2f19284b
Commit
2f19284b
authored
Jun 13, 2020
by
jim
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
rollback
parent
e398eab0
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
45 additions
and
48 deletions
+45
-48
Set3proxyTask.java
.../com/edgec/browserbackend/browser/task/Set3proxyTask.java
+45
-48
No files found.
src/main/java/com/edgec/browserbackend/browser/task/Set3proxyTask.java
View file @
2f19284b
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,10 +19,8 @@ import org.springframework.stereotype.Component;
...
@@ -19,10 +19,8 @@ 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
{
...
@@ -44,21 +42,22 @@ public class Set3proxyTask {
...
@@ -44,21 +42,22 @@ public class Set3proxyTask {
@Autowired
@Autowired
private
ProxyConfigRepository
proxyConfigRepository
;
private
ProxyConfigRepository
proxyConfigRepository
;
@Scheduled
(
cron
=
"0 0/
2
* * * ?"
)
@Scheduled
(
cron
=
"0 0/
10
* * * ?"
)
@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
validTime
=
Instant
.
now
().
minusSeconds
(
43200
).
toEpochMilli
();
long
nowtime
=
Instant
.
now
().
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
());
// List<IpResource> ipResources = ipResourceRepository.findByOwnerInAndSpecialLine(accountParents, true);
List
<
IpResource
>
ipResources
=
ipResourceRepository
.
findByOwnerInAndSpecialLine
(
accountParents
,
true
);
List
<
IpResource
>
ipResources
=
ipResourceRepository
.
findBySpecialLineAndIsDeleted
(
true
,
false
);
// 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
);
...
@@ -67,55 +66,53 @@ public class Set3proxyTask {
...
@@ -67,55 +66,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"
);
// 写入 ipResources 相关信息
for
(
IpResource
ipResource
:
ipResources
)
{
if
(
ipResources
.
size
()
!=
0
)
{
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
.
info
(
"成功写入文件"
);
log
.
error
(
"成功写入文件"
);
long
nowtime
=
Instant
.
now
().
toEpochMilli
();
if
(
proxyConfigRepository
.
count
()
>
0
)
{
long
proxyConfigTimestamp
=
proxyConfigRepository
.
findAll
().
get
(
0
).
getTimestamp
();
ProxyConfig
proxyConfig
=
proxyConfigRepository
.
findAll
().
get
(
0
);
if
(
proxyConfigRepository
.
count
()
>
0
&&
nowtime
<
proxyConfigTimestamp
)
{
if
(
nowtime
<
proxyConfig
.
getTimestamp
())
{
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