Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
com.ccwangluo.accelerator
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
sheteng
com.ccwangluo.accelerator
Commits
390cb522
Commit
390cb522
authored
Aug 22, 2017
by
Max Lv
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix #1351
parent
b14fdcae
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
51 deletions
+34
-51
mobile/src/main/scala/com/github/shadowsocks/acl/Acl.scala
mobile/src/main/scala/com/github/shadowsocks/acl/Acl.scala
+17
-35
mobile/src/main/scala/com/github/shadowsocks/acl/CustomRulesFragment.scala
...cala/com/github/shadowsocks/acl/CustomRulesFragment.scala
+16
-16
project/build.properties
project/build.properties
+1
-0
No files found.
mobile/src/main/scala/com/github/shadowsocks/acl/Acl.scala
View file @
390cb522
...
@@ -19,20 +19,19 @@ import scala.io.Source
...
@@ -19,20 +19,19 @@ import scala.io.Source
class
Acl
{
class
Acl
{
@DatabaseField
(
generatedId
=
true
)
@DatabaseField
(
generatedId
=
true
)
var
id
:
Int
=
_
var
id
:
Int
=
_
val
bypassHostnames
=
new
mutable
.
SortedList
[
String
]()
val
proxyH
ostnames
=
new
mutable
.
SortedList
[
String
]()
val
h
ostnames
=
new
mutable
.
SortedList
[
String
]()
val
subnets
=
new
mutable
.
SortedList
[
Subnet
]()
val
subnets
=
new
mutable
.
SortedList
[
Subnet
]()
val
urls
=
new
mutable
.
SortedList
[
String
]()
val
urls
=
new
mutable
.
SortedList
[
String
]()
@DatabaseField
@DatabaseField
var
bypass
:
Boolean
=
_
var
bypass
:
Boolean
=
_
def
isUrl
(
url
:
String
)
:
Boolean
=
url
.
startsWith
(
"http://"
)
||
url
.
startsWith
(
"https://"
)
def
isUrl
(
url
:
String
)
:
Boolean
=
url
.
startsWith
(
"http://"
)
||
url
.
startsWith
(
"https://"
)
def
fromAcl
(
other
:
Acl
)
:
Acl
=
{
def
fromAcl
(
other
:
Acl
)
:
Acl
=
{
bypassHostnames
.
clear
()
hostnames
.
clear
()
bypassHostnames
++=
other
.
bypassHostnames
hostnames
++=
other
.
hostnames
proxyHostnames
.
clear
()
proxyHostnames
++=
other
.
proxyHostnames
subnets
.
clear
()
subnets
.
clear
()
subnets
++=
other
.
subnets
subnets
++=
other
.
subnets
urls
.
clear
()
urls
.
clear
()
...
@@ -40,16 +39,11 @@ class Acl {
...
@@ -40,16 +39,11 @@ class Acl {
bypass
=
other
.
bypass
bypass
=
other
.
bypass
this
this
}
}
def
fromSource
(
value
:
Source
,
defaultBypass
:
Boolean
=
true
)
:
Acl
=
{
def
fromSource
(
value
:
Source
,
defaultBypass
:
Boolean
=
true
)
:
Acl
=
{
bypassHostnames
.
clear
()
subnets
.
clear
()
proxyHostnames
.
clear
()
urls
.
clear
()
this
.
subnets
.
clear
()
this
.
urls
.
clear
()
bypass
=
defaultBypass
bypass
=
defaultBypass
lazy
val
bypassSubnets
=
new
mutable
.
SortedList
[
Subnet
]()
lazy
val
proxySubnets
=
new
mutable
.
SortedList
[
Subnet
]()
var
hostnames
:
mutable.SortedList
[
String
]
=
if
(
defaultBypass
)
proxyHostnames
else
bypassHostnames
var
subnets
:
mutable.SortedList
[
Subnet
]
=
if
(
defaultBypass
)
proxySubnets
else
bypassSubnets
var
in_urls
=
false
var
in_urls
=
false
for
(
line
<-
value
.
getLines
())
(
line
.
trim
.
indexOf
(
'#'
)
match
{
for
(
line
<-
value
.
getLines
())
(
line
.
trim
.
indexOf
(
'#'
)
match
{
case
0
=>
{
case
0
=>
{
...
@@ -65,17 +59,12 @@ class Acl {
...
@@ -65,17 +59,12 @@ class Acl {
}
}
case
index
=>
if
(!
in_urls
)
line
else
""
case
index
=>
if
(!
in_urls
)
line
else
""
}).
trim
match
{
}).
trim
match
{
// Ignore all section controls
case
"[outbound_block_list]"
=>
case
"[outbound_block_list]"
=>
hostnames
=
null
subnets
=
null
case
"[black_list]"
|
"[bypass_list]"
=>
case
"[black_list]"
|
"[bypass_list]"
=>
hostnames
=
bypassHostnames
subnets
=
bypassSubnets
case
"[white_list]"
|
"[proxy_list]"
=>
case
"[white_list]"
|
"[proxy_list]"
=>
hostnames
=
proxyHostnames
case
"[reject_all]"
|
"[bypass_all]"
=>
subnets
=
proxySubnets
case
"[accept_all]"
|
"[proxy_all]"
=>
case
"[reject_all]"
|
"[bypass_all]"
=>
bypass
=
true
case
"[accept_all]"
|
"[proxy_all]"
=>
bypass
=
false
case
input
if
subnets
!=
null
&&
input
.
nonEmpty
=>
try
subnets
+=
Subnet
.
fromString
(
input
)
catch
{
case
input
if
subnets
!=
null
&&
input
.
nonEmpty
=>
try
subnets
+=
Subnet
.
fromString
(
input
)
catch
{
case
_:
IllegalArgumentException
=>
if
(
isUrl
(
input
))
{
case
_:
IllegalArgumentException
=>
if
(
isUrl
(
input
))
{
urls
+=
input
urls
+=
input
...
@@ -85,7 +74,6 @@ class Acl {
...
@@ -85,7 +74,6 @@ class Acl {
}
}
case
_
=>
case
_
=>
}
}
this
.
subnets
++=
(
if
(
bypass
)
proxySubnets
else
bypassSubnets
)
this
this
}
}
final
def
fromId
(
id
:
String
)
:
Acl
=
fromSource
(
Source
.
fromFile
(
Acl
.
getFile
(
id
)))
final
def
fromId
(
id
:
String
)
:
Acl
=
fromSource
(
Source
.
fromFile
(
Acl
.
getFile
(
id
)))
...
@@ -103,21 +91,15 @@ class Acl {
...
@@ -103,21 +91,15 @@ class Acl {
}
}
result
.
append
(
"\n#NETWORK_ACL_END\n"
)
result
.
append
(
"\n#NETWORK_ACL_END\n"
)
}
}
result
.
append
(
"\n"
)
}
}
if
(
result
.
isEmpty
)
{
if
(
result
.
isEmpty
)
{
result
.
append
(
if
(
bypass
)
"[bypass_all]\n"
else
"[proxy_all]\n"
)
result
.
append
(
"[bypass_all]\n"
)
}
val
(
bypassList
,
proxyList
)
=
if
(
bypass
)
(
bypassHostnames
.
toStream
,
subnets
.
toStream
.
map
(
_
.
toString
)
#:::
proxyHostnames
.
toStream
)
else
(
subnets
.
toStream
.
map
(
_
.
toString
)
#:::
bypassHostnames
.
toStream
,
proxyHostnames
.
toStream
)
if
(
bypassList
.
nonEmpty
)
{
result
.
append
(
"[bypass_list]\n"
)
result
.
append
(
bypassList
.
mkString
(
"\n"
))
result
.
append
(
'\n'
)
}
}
if
(
proxyList
.
nonEmpty
)
{
val
list
=
subnets
.
toStream
.
map
(
_
.
toString
)
#:::
hostnames
.
toStream
if
(
list
.
nonEmpty
)
{
result
.
append
(
"[proxy_list]\n"
)
result
.
append
(
"[proxy_list]\n"
)
result
.
append
(
proxyL
ist
.
mkString
(
"\n"
))
result
.
append
(
l
ist
.
mkString
(
"\n"
))
result
.
append
(
'\n'
)
result
.
append
(
'\n'
)
}
}
result
.
toString
result
.
toString
...
@@ -127,7 +109,7 @@ class Acl {
...
@@ -127,7 +109,7 @@ class Acl {
getAclString
(
false
)
getAclString
(
false
)
}
}
def
isValidCustomRules
:
Boolean
=
bypass
&&
bypassH
ostnames
.
isEmpty
def
isValidCustomRules
:
Boolean
=
!
h
ostnames
.
isEmpty
// Don't change: dummy fields for OrmLite interaction
// Don't change: dummy fields for OrmLite interaction
...
...
mobile/src/main/scala/com/github/shadowsocks/acl/CustomRulesFragment.scala
View file @
390cb522
...
@@ -125,7 +125,7 @@ class CustomRulesFragment extends ToolbarFragment with Toolbar.OnMenuItemClickLi
...
@@ -125,7 +125,7 @@ class CustomRulesFragment extends ToolbarFragment with Toolbar.OnMenuItemClickLi
})
})
}
}
def
getItemCount
:
Int
=
acl
.
subnets
.
size
+
acl
.
proxyH
ostnames
.
size
+
acl
.
urls
.
size
def
getItemCount
:
Int
=
acl
.
subnets
.
size
+
acl
.
h
ostnames
.
size
+
acl
.
urls
.
size
def
onBindViewHolder
(
vh
:
AclRuleViewHolder
,
i
:
Int
)
:
Unit
=
{
def
onBindViewHolder
(
vh
:
AclRuleViewHolder
,
i
:
Int
)
:
Unit
=
{
val
j
=
i
-
acl
.
urls
.
size
val
j
=
i
-
acl
.
urls
.
size
val
k
=
i
-
acl
.
subnets
.
size
-
acl
.
urls
.
size
val
k
=
i
-
acl
.
subnets
.
size
-
acl
.
urls
.
size
...
@@ -134,7 +134,7 @@ class CustomRulesFragment extends ToolbarFragment with Toolbar.OnMenuItemClickLi
...
@@ -134,7 +134,7 @@ class CustomRulesFragment extends ToolbarFragment with Toolbar.OnMenuItemClickLi
else
if
(
k
<
0
)
else
if
(
k
<
0
)
vh
.
bind
(
acl
.
subnets
(
j
))
vh
.
bind
(
acl
.
subnets
(
j
))
else
else
vh
.
bind
(
acl
.
proxyH
ostnames
(
k
))
vh
.
bind
(
acl
.
h
ostnames
(
k
))
}
}
def
onCreateViewHolder
(
vg
:
ViewGroup
,
i
:
Int
)
=
new
AclRuleViewHolder
(
LayoutInflater
.
from
(
vg
.
getContext
)
def
onCreateViewHolder
(
vg
:
ViewGroup
,
i
:
Int
)
=
new
AclRuleViewHolder
(
LayoutInflater
.
from
(
vg
.
getContext
)
.
inflate
(
android
.
R
.
layout
.
simple_list_item_1
,
vg
,
false
))
.
inflate
(
android
.
R
.
layout
.
simple_list_item_1
,
vg
,
false
))
...
@@ -151,18 +151,18 @@ class CustomRulesFragment extends ToolbarFragment with Toolbar.OnMenuItemClickLi
...
@@ -151,18 +151,18 @@ class CustomRulesFragment extends ToolbarFragment with Toolbar.OnMenuItemClickLi
apply
()
apply
()
index
index
}
else
-
1
}
else
-
1
def
addHostname
(
hostname
:
String
)
:
Int
=
if
(
acl
.
proxyH
ostnames
.
add
(
hostname
))
{
def
addHostname
(
hostname
:
String
)
:
Int
=
if
(
acl
.
h
ostnames
.
add
(
hostname
))
{
val
index
=
acl
.
proxyH
ostnames
.
indexOf
(
hostname
)
+
acl
.
urls
.
size
+
acl
.
subnets
.
size
val
index
=
acl
.
h
ostnames
.
indexOf
(
hostname
)
+
acl
.
urls
.
size
+
acl
.
subnets
.
size
notifyItemInserted
(
index
)
notifyItemInserted
(
index
)
apply
()
apply
()
index
index
}
else
-
1
}
else
-
1
def
addToProxy
(
input
:
String
)
:
Int
=
{
def
addToProxy
(
input
:
String
)
:
Int
=
{
val
acl
=
new
Acl
().
fromSource
(
Source
.
fromString
(
input
)
,
defaultBypass
=
true
)
val
acl
=
new
Acl
().
fromSource
(
Source
.
fromString
(
input
))
var
result
=
-
1
var
result
=
-
1
for
(
url
<-
acl
.
urls
)
result
=
addUrl
(
url
)
for
(
url
<-
acl
.
urls
)
result
=
addUrl
(
url
)
for
(
hostname
<-
acl
.
proxyH
ostnames
)
result
=
addHostname
(
hostname
)
for
(
hostname
<-
acl
.
h
ostnames
)
result
=
addHostname
(
hostname
)
if
(
acl
.
bypass
)
for
(
subnet
<-
acl
.
subnets
)
result
=
addSubnet
(
subnet
)
for
(
subnet
<-
acl
.
subnets
)
result
=
addSubnet
(
subnet
)
result
result
}
}
def
addFromTemplate
(
template
:
Int
,
text
:
CharSequence
)
:
Int
=
template
match
{
def
addFromTemplate
(
template
:
Int
,
text
:
CharSequence
)
:
Int
=
template
match
{
...
@@ -186,8 +186,8 @@ class CustomRulesFragment extends ToolbarFragment with Toolbar.OnMenuItemClickLi
...
@@ -186,8 +186,8 @@ class CustomRulesFragment extends ToolbarFragment with Toolbar.OnMenuItemClickLi
undoManager
.
remove
((
i
,
acl
.
subnets
(
j
)))
undoManager
.
remove
((
i
,
acl
.
subnets
(
j
)))
acl
.
subnets
.
remove
(
j
)
acl
.
subnets
.
remove
(
j
)
}
else
{
}
else
{
undoManager
.
remove
((
i
,
acl
.
proxyH
ostnames
(
k
)))
undoManager
.
remove
((
i
,
acl
.
h
ostnames
(
k
)))
acl
.
proxyH
ostnames
.
remove
(
k
)
acl
.
h
ostnames
.
remove
(
k
)
}
}
notifyItemRemoved
(
i
)
notifyItemRemoved
(
i
)
apply
()
apply
()
...
@@ -202,9 +202,9 @@ class CustomRulesFragment extends ToolbarFragment with Toolbar.OnMenuItemClickLi
...
@@ -202,9 +202,9 @@ class CustomRulesFragment extends ToolbarFragment with Toolbar.OnMenuItemClickLi
acl
.
urls
.
remove
(
hostname
)
acl
.
urls
.
remove
(
hostname
)
apply
()
apply
()
}
else
{
}
else
{
notifyItemRemoved
(
acl
.
proxyH
ostnames
.
indexOf
(
hostname
)
notifyItemRemoved
(
acl
.
h
ostnames
.
indexOf
(
hostname
)
+
acl
.
urls
.
size
+
acl
.
subnets
.
size
)
+
acl
.
urls
.
size
+
acl
.
subnets
.
size
)
acl
.
proxyH
ostnames
.
remove
(
hostname
)
acl
.
h
ostnames
.
remove
(
hostname
)
apply
()
apply
()
}
}
}
}
...
@@ -221,8 +221,8 @@ class CustomRulesFragment extends ToolbarFragment with Toolbar.OnMenuItemClickLi
...
@@ -221,8 +221,8 @@ class CustomRulesFragment extends ToolbarFragment with Toolbar.OnMenuItemClickLi
apply
()
apply
()
}
}
}
else
{
}
else
{
if
(
acl
.
proxyH
ostnames
.
insert
(
hostname
))
{
if
(
acl
.
h
ostnames
.
insert
(
hostname
))
{
notifyItemInserted
(
acl
.
proxyH
ostnames
.
indexOf
(
hostname
)
+
acl
.
urls
.
size
+
acl
.
subnets
.
size
)
notifyItemInserted
(
acl
.
h
ostnames
.
indexOf
(
hostname
)
+
acl
.
urls
.
size
+
acl
.
subnets
.
size
)
apply
()
apply
()
}
}
}
}
...
@@ -236,7 +236,7 @@ class CustomRulesFragment extends ToolbarFragment with Toolbar.OnMenuItemClickLi
...
@@ -236,7 +236,7 @@ class CustomRulesFragment extends ToolbarFragment with Toolbar.OnMenuItemClickLi
selectedItems
.
clear
()
selectedItems
.
clear
()
selectedItems
++=
acl
.
urls
selectedItems
++=
acl
.
urls
selectedItems
++=
acl
.
subnets
selectedItems
++=
acl
.
subnets
selectedItems
++=
acl
.
proxyH
ostnames
selectedItems
++=
acl
.
h
ostnames
onSelectedItemsUpdated
()
onSelectedItemsUpdated
()
notifyDataSetChanged
()
notifyDataSetChanged
()
}
}
...
@@ -245,7 +245,7 @@ class CustomRulesFragment extends ToolbarFragment with Toolbar.OnMenuItemClickLi
...
@@ -245,7 +245,7 @@ class CustomRulesFragment extends ToolbarFragment with Toolbar.OnMenuItemClickLi
val
j
=
i
-
acl
.
subnets
.
size
val
j
=
i
-
acl
.
subnets
.
size
try
{
try
{
(
if
(
j
<
0
)
acl
.
subnets
(
i
).
address
.
getHostAddress
.
substring
(
0
,
1
)
else
{
(
if
(
j
<
0
)
acl
.
subnets
(
i
).
address
.
getHostAddress
.
substring
(
0
,
1
)
else
{
val
hostname
=
acl
.
proxyH
ostnames
(
i
)
val
hostname
=
acl
.
h
ostnames
(
i
)
PATTERN_DOMAIN
.
findFirstMatchIn
(
hostname
)
match
{
PATTERN_DOMAIN
.
findFirstMatchIn
(
hostname
)
match
{
case
Some
(
m
)
=>
m
.
matched
.
replaceAll
(
"\\\\."
,
"."
)
// don't convert IDN yet
case
Some
(
m
)
=>
m
.
matched
.
replaceAll
(
"\\\\."
,
"."
)
// don't convert IDN yet
case
None
=>
hostname
case
None
=>
hostname
...
@@ -341,7 +341,7 @@ class CustomRulesFragment extends ToolbarFragment with Toolbar.OnMenuItemClickLi
...
@@ -341,7 +341,7 @@ class CustomRulesFragment extends ToolbarFragment with Toolbar.OnMenuItemClickLi
case
R
.
id
.
action_import_gfwlist
=>
case
R
.
id
.
action_import_gfwlist
=>
val
acl
=
new
Acl
().
fromId
(
Acl
.
GFWLIST
)
val
acl
=
new
Acl
().
fromId
(
Acl
.
GFWLIST
)
acl
.
subnets
.
foreach
(
adapter
.
addSubnet
)
acl
.
subnets
.
foreach
(
adapter
.
addSubnet
)
acl
.
proxyH
ostnames
.
foreach
(
adapter
.
addHostname
)
acl
.
h
ostnames
.
foreach
(
adapter
.
addHostname
)
true
true
case
_
=>
false
case
_
=>
false
}
}
...
...
project/build.properties
0 → 100644
View file @
390cb522
sbt.version
=
0.13.16
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