Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
antSword
Project
Project
Details
Activity
Releases
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
HuangJunbo
antSword
Commits
60e309b2
Commit
60e309b2
authored
Mar 23, 2016
by
Antoor
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #22 from Medicean/master
新增代理功能//Add Proxy Configuration
parents
9dd036a8
1f8654db
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
278 additions
and
14 deletions
+278
-14
CHANGELOG.md
CHANGELOG.md
+2
-1
request.js
modules/request.js
+44
-3
package.json
package.json
+1
-0
app.entry.jsx
source/app.entry.jsx
+24
-2
en.jsx
source/language/en.jsx
+36
-3
zh.jsx
source/language/zh.jsx
+35
-2
aproxy.jsx
source/modules/settings/aproxy.jsx
+131
-0
index.jsx
source/modules/settings/index.jsx
+5
-3
No files found.
CHANGELOG.md
View file @
60e309b2
...
@@ -9,6 +9,7 @@
...
@@ -9,6 +9,7 @@
### /22
### /22
1.
数据分类重命名
1.
数据分类重命名
2.
新增代理连接配置
### /21
### /21
1.
优化UI组建自适应,在调整窗口大小的时候不刷新就能调整UI尺寸
1.
优化UI组建自适应,在调整窗口大小的时候不刷新就能调整UI尺寸
...
@@ -43,4 +44,4 @@
...
@@ -43,4 +44,4 @@
*
中文开发文档
*
中文开发文档
*
英文说明+开发文档
*
英文说明+开发文档
*
nodejs服务端脚本支持
*
nodejs服务端脚本支持
*
python服务端脚本支持
*
python服务端脚本支持
\ No newline at end of file
modules/request.js
View file @
60e309b2
//
//
// Superagent发包模块
// Superagent发包模块
//
//
'use strict'
;
'use strict'
;
...
@@ -10,16 +10,57 @@ const superagent = require('superagent');
...
@@ -10,16 +10,57 @@ const superagent = require('superagent');
const
logger
=
log4js
.
getLogger
(
'Request'
);
const
logger
=
log4js
.
getLogger
(
'Request'
);
var
aproxymode
=
"noproxy"
;
var
aproxyuri
=
""
;
class
Request
{
class
Request
{
constructor
(
electron
)
{
constructor
(
electron
)
{
// 监听请求
// 监听请求
const
ipcMain
=
electron
.
ipcMain
;
const
ipcMain
=
electron
.
ipcMain
;
// 代理测试
ipcMain
.
on
(
'aproxytest'
,
(
event
,
opts
)
=>
{
var
_superagent
=
require
(
'superagent'
);
var
_aproxyuri
=
opts
[
'aproxyuri'
];
logger
.
debug
(
"[aProxy] Test Proxy - "
+
_aproxyuri
+
" - Connect to "
+
opts
[
'url'
]);
require
(
'superagent-proxy'
)(
superagent
);
_superagent
.
get
(
opts
[
'url'
])
.
proxy
(
_aproxyuri
)
.
timeout
(
5000
)
.
end
((
err
,
ret
)
=>
{
if
(
err
)
{
logger
.
debug
(
"[aProxy] Test Error"
);
return
event
.
sender
.
send
(
'aproxytest-error'
,
err
);
}
else
{
logger
.
debug
(
"[aProxy] Test Success"
);
return
event
.
sender
.
send
(
'aproxytest-success'
,
ret
);
}
});
});
// 加载代理设置
ipcMain
.
on
(
'aproxy'
,
(
event
,
opts
)
=>
{
aproxymode
=
opts
[
'aproxymode'
];
aproxyuri
=
opts
[
'aproxyuri'
];
logger
.
debug
(
"[aProxy] Set Proxy Mode - "
+
(
aproxymode
==
"manualproxy"
?
aproxyuri
:
" noproxy"
));
if
(
aproxymode
==
"noproxy"
)
{
superagent
.
Request
.
prototype
.
proxy
=
function
(
arg
)
{
return
this
;
};
}
else
{
require
(
'superagent-proxy'
)(
superagent
);
};
});
// 监听请求
ipcMain
.
on
(
'request'
,
(
event
,
opts
)
=>
{
ipcMain
.
on
(
'request'
,
(
event
,
opts
)
=>
{
logger
.
debug
(
"[aProxy] Connect mode - "
+
(
aproxymode
==
"manualproxy"
?
aproxyuri
:
" noproxy"
));
logger
.
debug
(
opts
[
'url'
]
+
'
\
n'
,
opts
[
'data'
]);
logger
.
debug
(
opts
[
'url'
]
+
'
\
n'
,
opts
[
'data'
]);
superagent
superagent
.
post
(
opts
[
'url'
])
.
post
(
opts
[
'url'
])
.
set
(
'User-Agent'
,
'antSword/1.0'
)
.
set
(
'User-Agent'
,
'antSword/1.0'
)
.
proxy
(
aproxyuri
)
.
type
(
'form'
)
.
type
(
'form'
)
.
timeout
(
5000
)
.
timeout
(
5000
)
.
send
(
opts
[
'data'
])
.
send
(
opts
[
'data'
])
...
@@ -89,4 +130,4 @@ class Request {
...
@@ -89,4 +130,4 @@ class Request {
}
}
module
.
exports
=
Request
;
module
.
exports
=
Request
;
\ No newline at end of file
package.json
View file @
60e309b2
...
@@ -14,6 +14,7 @@
...
@@ -14,6 +14,7 @@
"
log4js
"
:
"
^0.6.29
"
,
"
log4js
"
:
"
^0.6.29
"
,
"
nedb
"
:
"
^1.5.1
"
,
"
nedb
"
:
"
^1.5.1
"
,
"
superagent
"
:
"
^1.6.1
"
,
"
superagent
"
:
"
^1.6.1
"
,
"
superagent-proxy
"
:
"
^1.0.0
"
,
"
webpack
"
:
"
^1.12.14
"
"
webpack
"
:
"
^1.12.14
"
},
},
"scripts"
:
{
"scripts"
:
{
...
...
source/app.entry.jsx
View file @
60e309b2
...
@@ -3,7 +3,7 @@
...
@@ -3,7 +3,7 @@
// -------
// -------
// create: 2015/12/20
// create: 2015/12/20
// update: 2016/01/20
// update: 2016/01/20
//
//
'use strict'
;
'use strict'
;
...
@@ -32,6 +32,28 @@ let _lang = localStorage.getItem('language') || navigator.language;
...
@@ -32,6 +32,28 @@ let _lang = localStorage.getItem('language') || navigator.language;
_lang
=
[
'en'
,
'zh'
].
indexOf
(
_lang
)
===
-
1
?
'en'
:
_lang
;
_lang
=
[
'en'
,
'zh'
].
indexOf
(
_lang
)
===
-
1
?
'en'
:
_lang
;
antSword
[
'language'
]
=
require
(
`./language/
${
_lang
}
`
);
antSword
[
'language'
]
=
require
(
`./language/
${
_lang
}
`
);
// 加载代理
var
_aproxymode
=
localStorage
.
getItem
(
'aproxymode'
)
||
"noproxy"
;
var
_aproxyprotocol
=
localStorage
.
getItem
(
'aproxyprotocol'
);
var
_aproxyserver
=
localStorage
.
getItem
(
'aproxyserver'
);
var
_aproxyport
=
localStorage
.
getItem
(
'aproxyport'
);
var
_aproxyusername
=
localStorage
.
getItem
(
'aproxyusername'
);
var
_aproxypassword
=
localStorage
.
getItem
(
'aproxypassword'
);
antSword
[
'aproxymode'
]
=
_aproxymode
;
if
(
_aproxyusername
==
""
||
_aproxyusername
==
null
||
_aproxypassword
==
""
||
_aproxypassword
==
null
)
{
antSword
[
'aproxyauth'
]
=
""
;
}
else
{
antSword
[
'aproxyauth'
]
=
_aproxyusername
+
":"
+
_aproxypassword
;
}
antSword
[
'aproxyuri'
]
=
_aproxyprotocol
+
"://"
+
antSword
[
'aproxyauth'
]
+
"@"
+
_aproxyserver
+
":"
+
_aproxyport
;
ipcRenderer
.
send
(
'aproxy'
,
{
aproxymode
:
antSword
[
'aproxymode'
],
aproxyuri
:
antSword
[
'aproxyuri'
]
});
antSword
[
'ipcRenderer'
]
=
ipcRenderer
;
antSword
[
'ipcRenderer'
]
=
ipcRenderer
;
antSword
[
'CacheManager'
]
=
CacheManager
;
antSword
[
'CacheManager'
]
=
CacheManager
;
antSword
[
'menubar'
]
=
new
Menubar
();
antSword
[
'menubar'
]
=
new
Menubar
();
...
@@ -50,4 +72,4 @@ antSword['tabbar'] = new dhtmlXTabBar(document.body);
...
@@ -50,4 +72,4 @@ antSword['tabbar'] = new dhtmlXTabBar(document.body);
});
});
// 移除加载界面&&设置标题
// 移除加载界面&&设置标题
$
(
'#loading'
).
remove
();
$
(
'#loading'
).
remove
();
document
.
title
=
antSword
[
'language'
][
'title'
]
||
'AntSword'
;
document
.
title
=
antSword
[
'language'
][
'title'
]
||
'AntSword'
;
\ No newline at end of file
source/language/en.jsx
View file @
60e309b2
//
//
// language::en
// language::en
//
//
module
.
exports
=
{
module
.
exports
=
{
toastr
:
{
toastr
:
{
info
:
'Info'
,
info
:
'Info'
,
...
@@ -407,7 +407,40 @@ module.exports = {
...
@@ -407,7 +407,40 @@ module.exports = {
}
}
}
}
},
},
aproxy
:
{
title
:
'Proxy Configuration'
,
toolbar
:
{
save
:
'Save'
,
test
:
'Test Connection'
},
form
:
{
label
:
'Configuring proxy access to the Internet'
,
mode
:{
noproxy
:
'No Proxy'
,
manualproxy
:
'Set the proxy manually'
},
proxy
:
{
protocol
:
'Protocol'
,
server
:
'Server'
,
port
:
'Port'
,
username
:
'Username'
,
password
:
'Password'
,
authtip
:
'Leave blank if no authentication'
}
},
success
:
'Successfully save the Proxy Configuration!'
,
error
:
'Failed to save the Proxy Configuration!'
,
confirm
:
{
content
:
'Restart the application?'
,
title
:
'Proxy Configuration'
},
prompt
:{
title
:
'Input the target URL'
,
success
:
'Successfully connect to the proxy server'
,
error
:
'Failed to connect to the proxy server'
}
},
plugin
:
{
plugin
:
{
error
:
(
err
)
=>
antSword
.
noxss
(
`Load plugin center failed!<br/>
${
err
}
`
)
error
:
(
err
)
=>
antSword
.
noxss
(
`Load plugin center failed!<br/>
${
err
}
`
)
}
}
}
}
\ No newline at end of file
source/language/zh.jsx
View file @
60e309b2
//
//
// language::zh
// language::zh
//
//
module
.
exports
=
{
module
.
exports
=
{
title
:
'中国蚁剑'
,
title
:
'中国蚁剑'
,
toastr
:
{
toastr
:
{
...
@@ -406,9 +406,42 @@ module.exports = {
...
@@ -406,9 +406,42 @@ module.exports = {
toolbar
:
{
toolbar
:
{
check
:
'检查'
check
:
'检查'
}
}
},
aproxy
:
{
title
:
'代理设置'
,
toolbar
:
{
save
:
'保存'
,
test
:
'测试连接'
},
form
:
{
label
:
'配置访问互联网的代理'
,
mode
:{
noproxy
:
'不使用代理'
,
manualproxy
:
'手动设置代理'
},
proxy
:
{
protocol
:
'代理协议'
,
server
:
'代理服务器'
,
port
:
'端口'
,
username
:
'用户名'
,
password
:
'密码'
,
authtip
:
'如果无认证方式请留空'
}
},
success
:
'保存代理设置成功!'
,
error
:
'保存代理设置失败!'
,
confirm
:
{
content
:
'重启应用生效,是否重启?'
,
title
:
'更改代理设置'
},
prompt
:{
title
:
'输入测试的 URL'
,
success
:
'连接到代理服务器成功'
,
error
:
'连接到代理服务器失败'
}
}
}
},
},
plugin
:
{
plugin
:
{
error
:
(
err
)
=>
antSword
.
noxss
(
`加载插件中心失败!<br/>
${
err
}
`
)
error
:
(
err
)
=>
antSword
.
noxss
(
`加载插件中心失败!<br/>
${
err
}
`
)
}
}
}
}
\ No newline at end of file
source/modules/settings/aproxy.jsx
0 → 100644
View file @
60e309b2
//
// 代理设置
//
const
LANG
=
antSword
[
'language'
][
'settings'
][
'aproxy'
];
const
LANG_T
=
antSword
[
'language'
][
'toastr'
];
class
AProxy
{
constructor
(
sidebar
)
{
sidebar
.
addItem
({
id
:
'aproxy'
,
text
:
`<i class="fa fa-paper-plane"></i>
${
LANG
[
'title'
]}
`
});
const
cell
=
sidebar
.
cells
(
'aproxy'
);
// 代理数据
const
aproxymode
=
localStorage
.
getItem
(
'aproxymode'
)
||
'noproxy'
;
const
aproxyprotocol
=
localStorage
.
getItem
(
'aproxyprotocol'
)
||
'http'
;
const
aproxyserver
=
localStorage
.
getItem
(
'aproxyserver'
);
const
aproxyport
=
localStorage
.
getItem
(
'aproxyport'
);
const
aproxyusername
=
localStorage
.
getItem
(
'aproxyusername'
);
const
aproxypassword
=
localStorage
.
getItem
(
'aproxypassword'
);
// 工具栏
const
toolbar
=
cell
.
attachToolbar
();
toolbar
.
loadStruct
([
{
id
:
'save'
,
type
:
'button'
,
text
:
LANG
[
'toolbar'
][
'save'
],
icon
:
'save'
},
{
type
:
'separator'
},
{
id
:
'test'
,
name
:
'test'
,
type
:
'button'
,
text
:
LANG
[
'toolbar'
][
'test'
],
icon
:
'spinner'
,
disabled
:
aproxymode
===
'noproxy'
}
]);
// 表单
const
form
=
cell
.
attachForm
([
{
type
:
'settings'
,
position
:
'label-left'
,
labelWidth
:
150
,
inputWidth
:
100
},
{
type
:
'block'
,
inputWidth
:
'auto'
,
offsetTop
:
12
,
list
:
[
{
type
:
'label'
,
label
:
LANG
[
'form'
][
'label'
]
},
{
type
:
'radio'
,
position
:
'label-right'
,
label
:
LANG
[
'form'
][
'mode'
][
'noproxy'
],
name
:
'aproxymode'
,
value
:
'noproxy'
,
checked
:
aproxymode
===
'noproxy'
},
{
type
:
'radio'
,
position
:
'label-right'
,
label
:
LANG
[
'form'
][
'mode'
][
'manualproxy'
],
name
:
'aproxymode'
,
value
:
'manualproxy'
,
checked
:
aproxymode
===
'manualproxy'
,
list
:[
{
type
:
'combo'
,
label
:
LANG
[
'form'
][
'proxy'
][
'protocol'
],
readonly
:
true
,
name
:
'protocol'
,
options
:[
{
text
:
'HTTP'
,
value
:
'http'
,
selected
:
aproxyprotocol
===
'http'
},
{
text
:
'HTTPS'
,
value
:
'https'
,
selected
:
aproxyprotocol
===
'https'
},
{
text
:
'SOCKS5'
,
value
:
'socks'
,
selected
:
aproxyprotocol
===
'socks'
},
{
text
:
'SOCKS4'
,
value
:
'socks4'
,
selected
:
aproxyprotocol
===
'socks4'
},
]},
{
type
:
'input'
,
label
:
LANG
[
'form'
][
'proxy'
][
'server'
],
name
:
'server'
,
required
:
true
,
validate
:
"NotEmpty"
,
value
:
aproxyserver
},
{
type
:
'input'
,
label
:
LANG
[
'form'
][
'proxy'
][
'port'
],
name
:
'port'
,
required
:
true
,
validate
:
"NotEmpty,ValidInteger"
,
value
:
aproxyport
},
{
type
:
'input'
,
label
:
LANG
[
'form'
][
'proxy'
][
'username'
],
name
:
'username'
,
value
:
aproxyusername
},
{
type
:
'password'
,
label
:
LANG
[
'form'
][
'proxy'
][
'password'
],
name
:
'password'
,
value
:
aproxypassword
}
]}
]}
],
true
);
form
.
enableLiveValidation
(
true
);
form
.
attachEvent
(
"onChange"
,
function
(
name
,
value
,
is_checked
){
if
(
name
==
"aproxymode"
)
{
if
(
value
==
"manualproxy"
)
{
toolbar
.
enableItem
(
'test'
);
}
else
{
toolbar
.
disableItem
(
'test'
);
}
}
});
// 工具栏点击事件
toolbar
.
attachEvent
(
'onClick'
,
(
id
)
=>
{
switch
(
id
)
{
case
'save'
:
if
(
form
.
validate
()){
var
formvals
=
form
.
getValues
();
const
aproxymode
=
formvals
[
'aproxymode'
];
// 保存设置
localStorage
.
setItem
(
'aproxymode'
,
aproxymode
);
localStorage
.
setItem
(
'aproxyprotocol'
,
formvals
[
'protocol'
]);
localStorage
.
setItem
(
'aproxyserver'
,
formvals
[
'server'
].
replace
(
/.+:
\/\/
/
,
''
).
replace
(
/:.+/
,
''
));
localStorage
.
setItem
(
'aproxyport'
,
formvals
[
'port'
]);
localStorage
.
setItem
(
'aproxyusername'
,
formvals
[
'username'
]);
localStorage
.
setItem
(
'aproxypassword'
,
formvals
[
'password'
]);
toastr
.
success
(
LANG
[
'success'
],
LANG_T
[
'success'
]);
// 重启应用
layer
.
confirm
(
LANG
[
'confirm'
][
'content'
],
{
icon
:
2
,
shift
:
6
,
title
:
LANG
[
'confirm'
][
'title'
]
},
(
_
)
=>
{
location
.
reload
();
});
}
else
{
toastr
.
error
(
LANG
[
'error'
],
LANG_T
[
'error'
]);
}
break
;
case
'test'
:
if
(
form
.
validate
()){
layer
.
prompt
({
title
:
LANG
[
'prompt'
][
'title'
],
value
:
'http://uyu.us'
,
formType
:
0
},
function
(
testurl
,
index
){
layer
.
close
(
index
);
var
loadindex
=
layer
.
load
(
2
,
{
time
:
6
*
1000
});
var
_formvals
=
form
.
getValues
();
var
_server
=
_formvals
[
'server'
].
replace
(
/.+:
\/\/
/
,
''
).
replace
(
/:.+/
,
''
);
var
_aproxyauth
=
""
;
if
(
_formvals
[
'username'
]
==
""
||
_formvals
[
'password'
]
==
""
||
_formvals
[
'username'
]
==
null
||
_formvals
[
'password'
]
==
null
)
{
_aproxyauth
=
""
;
}
else
{
_aproxyauth
=
_formvals
[
'username'
]
+
":"
+
_formvals
[
'password'
];
}
var
_aproxyuri
=
_formvals
[
'protocol'
]
+
'://'
+
_aproxyauth
+
'@'
+
_server
+
':'
+
_formvals
[
'port'
];
antSword
[
'ipcRenderer'
]
.
on
(
'aproxytest-error'
,
(
event
,
err
)
=>
{
layer
.
close
(
loadindex
);
toastr
.
error
(
LANG
[
'prompt'
][
'error'
]
+
"
\n
"
+
err
[
'code'
],
LANG_T
[
'error'
]);
})
.
on
(
'aproxytest-success'
,
(
event
,
ret
)
=>
{
layer
.
close
(
loadindex
);
toastr
.
success
(
LANG
[
'prompt'
][
'success'
],
LANG_T
[
'success'
]);
})
.
send
(
'aproxytest'
,{
url
:
testurl
||
'http://uyu.us'
,
aproxyuri
:
_aproxyuri
});
});
}
break
;
}
});
}
}
export
default
AProxy
;
source/modules/settings/index.jsx
View file @
60e309b2
//
//
// 设置模块
// 设置模块
//
//
import
About
from
'./about'
;
import
About
from
'./about'
;
import
Update
from
'./update'
;
import
Update
from
'./update'
;
import
Language
from
'./language'
;
import
Language
from
'./language'
;
import
AProxy
from
'./aproxy'
class
Settings
{
class
Settings
{
...
@@ -35,6 +36,7 @@ class Settings {
...
@@ -35,6 +36,7 @@ class Settings {
new
About
(
sidebar
);
new
About
(
sidebar
);
new
Language
(
sidebar
);
new
Language
(
sidebar
);
new
Update
(
sidebar
);
new
Update
(
sidebar
);
new
AProxy
(
sidebar
);
this
.
cell
=
cell
;
this
.
cell
=
cell
;
this
.
sidebar
=
sidebar
;
this
.
sidebar
=
sidebar
;
...
@@ -49,4 +51,4 @@ class Settings {
...
@@ -49,4 +51,4 @@ class Settings {
}
}
export
default
Settings
;
export
default
Settings
;
\ 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