ssport 0.1.9 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +70 -22
- data/lib/ssport/config.rb +3 -3
- data/lib/ssport/profile.rb +59 -0
- data/lib/ssport/remote.rb +73 -0
- data/lib/ssport/version.rb +1 -1
- data/lib/ssport.rb +70 -23
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 858bc1dec0c69355534c02d5a8637fd2644ba6a29176af078815b5d6d30eaf53
|
4
|
+
data.tar.gz: 1cca30caf55e621e3daa37d1ffb9bafce82fc26845436471faa1681275f1ed13
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aee8f274d207456a7b61b8003c0610b6249533fe9862693e116dd23405b0900671145c79b19fdc8e299a5a4b238d76cbcade6660303d141b491d6913dc8d5905
|
7
|
+
data.tar.gz: 2e94ad21c11606ce691fe917697db9352d53c24980f81cf0ed8b6416442e2629cc01456f4945cd9fb5ea263f1c9a0c4336ebfa166bb082ecc3c49186746f174d
|
data/README.md
CHANGED
@@ -1,34 +1,82 @@
|
|
1
1
|
# Ssport
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
TODO: Delete this and the text above, and describe your gem
|
3
|
+
由于Shadowsocket时不时端口就被墙了。每次都要经过一下步骤`登录服务器` -> `修改配置文件` -> `重启SS服务` 来换端口号或者加密方式。虽然步骤不多,每次及密码修改重启这些命令和密码记忆起来也麻烦,毕竟都是不常用的命令。为节省大家时间,于是写了一个命令行工具,可以一个命令行解决所有,省去繁杂操作。
|
6
4
|
|
7
5
|
## Installation
|
8
6
|
|
9
|
-
Add this line to your application's Gemfile:
|
10
|
-
|
11
|
-
```ruby
|
12
|
-
gem 'ssport'
|
13
|
-
```
|
14
|
-
|
15
|
-
And then execute:
|
16
|
-
|
17
|
-
$ bundle
|
18
|
-
|
19
|
-
Or install it yourself as:
|
20
|
-
|
21
7
|
$ gem install ssport
|
22
8
|
|
23
9
|
## Usage
|
24
10
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
11
|
+
由于该工具使用ruby写的,请确保服务器上安装了`ruby`环境和`gems`。
|
12
|
+
|
13
|
+
##### 帮助: `ssport -h` 查看。
|
14
|
+
|
15
|
+
Usage: change shadowsocket port
|
16
|
+
-S host ssh server host
|
17
|
+
-A, --server aliasName ssh server alia name, eg: ssport -a ramnode -b 724
|
18
|
+
-L, --list list available server alia name
|
19
|
+
-U, --username username ssh server username
|
20
|
+
-P, --pass password ssh server password
|
21
|
+
-b, --bind port shadowsocket server bind port
|
22
|
+
-p, --password password shadowsocket password
|
23
|
+
-m, --method method shadowsocket encry method
|
24
|
+
-c, --config filepath shadowsocket config file path
|
25
|
+
|
26
|
+
|
27
|
+
* S 服务器地址
|
28
|
+
* A 服务器别名,记录之后下次直接用别名不用每次都输入`服务器地址`,`服务器用户名`和`服务器密码`。例如: `ssport -S 119.44.97.96:9090 -U root -P 123456 -A bandwagon`。 下次直接用`ssport -A bandwagon -b 8970` 就可以修改端口号了。
|
29
|
+
* L 显示所有的服务器别名
|
30
|
+
* U 服务器SSH登录的用户名,因为需要读写权限,请确保用户有权限。或者直接用root更方便。
|
31
|
+
* P SSH登录的密码
|
32
|
+
* b 设置SS需要绑定的端口号
|
33
|
+
* p 设置SS需要修改的新密码
|
34
|
+
* m 设置SS需要修改的加密方法
|
35
|
+
* c 指定SS服务的配置文件位置
|
36
|
+
|
37
|
+
如果您遇到需要修改SS配置的情况,可以尝试使用该命令行来解决您的问题。
|
38
|
+
|
39
|
+
##### 查看配置
|
40
|
+
|
41
|
+
如何只查看SS的配置呢。 很简单,只要不加修改的选项就可以了。例如:`ssport -A bandwagon`, 显示内容如下:
|
42
|
+
|
43
|
+
---------Bengin Deal /etc/shadowsocks.json ------------
|
44
|
+
-------------Old Config---------------
|
45
|
+
{
|
46
|
+
"server": "47.192.99.110",
|
47
|
+
"server_port": "8081",
|
48
|
+
"local_address": "127.0.0.1",
|
49
|
+
"local_port": 1080,
|
50
|
+
"password": "ssport",
|
51
|
+
"timeout": 300,
|
52
|
+
"method": "rc4-md5",
|
53
|
+
"fast_open": false,
|
54
|
+
"workers": 1
|
55
|
+
}
|
56
|
+
-------------New Config---------------
|
57
|
+
{
|
58
|
+
"server": "47.192.99.110",
|
59
|
+
"server_port": "8081",
|
60
|
+
"local_address": "127.0.0.1",
|
61
|
+
"local_port": 1080,
|
62
|
+
"password": "ssport",
|
63
|
+
"timeout": 300,
|
64
|
+
"method": "rc4-md5",
|
65
|
+
"fast_open": false,
|
66
|
+
"workers": 1
|
67
|
+
}
|
68
|
+
|
69
|
+
原本的配置和新的配置一模一样,也就是任何内容都未曾改变。用于方便的查看SS配置。
|
70
|
+
|
71
|
+
|
72
|
+
###### 修改配置
|
73
|
+
|
74
|
+
* 修改端口号并添加主机别名为ramnode: `ssport -S 47.192.99.110 -P 123456 -U root -c /etc/shadowsocks.json -b 805 -A ramnode`
|
75
|
+
* 修改端口号: `ssport -A ramnode -b 903`
|
76
|
+
* 修改加密方法: `ssport -A ramnode -m rc4-md5`
|
77
|
+
* 修改端口号、加密方法、密码:`ssport -A ramnode -b 900 -m rc4-md5 -p 123456`
|
78
|
+
|
79
|
+
以上内容都是虚构的地址和用户名密码,请替换成你自己的进行操作。
|
32
80
|
|
33
81
|
## Contributing
|
34
82
|
|
data/lib/ssport/config.rb
CHANGED
@@ -21,11 +21,11 @@ class Config
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def parseConfig
|
24
|
-
puts "---------
|
24
|
+
puts "---------Bengin Deal #{@config_file} ------------".colorize(:yellow)
|
25
25
|
if File.exist? @config_file
|
26
26
|
file_content = File.read @config_file
|
27
27
|
@config_json = JSON.parse file_content
|
28
|
-
puts "-------------
|
28
|
+
puts "-------------Old Config---------------".colorize(:yellow)
|
29
29
|
puts JSON.pretty_generate(@config_json)
|
30
30
|
else
|
31
31
|
puts "Config 文件不存在".colorize(:red)
|
@@ -44,7 +44,7 @@ class Config
|
|
44
44
|
changeField @@PASSWORD , :password
|
45
45
|
changeField @@METHOD , :method
|
46
46
|
final_config = JSON.pretty_generate(@config_json)
|
47
|
-
puts "-------------
|
47
|
+
puts "-------------New Config---------------".colorize(:yellow)
|
48
48
|
puts final_config
|
49
49
|
File.write @config_file , final_config
|
50
50
|
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'colorize'
|
3
|
+
|
4
|
+
class Profile
|
5
|
+
|
6
|
+
def initialize(options)
|
7
|
+
@options = options
|
8
|
+
@alias_name = @options[:alias]
|
9
|
+
end
|
10
|
+
|
11
|
+
def genrc(alias_name)
|
12
|
+
if !File.directory?(File.expand_path("~/.ssport"))
|
13
|
+
`mkdir ~/.ssport`
|
14
|
+
end
|
15
|
+
File.expand_path "~/.ssport/#{alias_name}.rc"
|
16
|
+
end
|
17
|
+
|
18
|
+
def list
|
19
|
+
alias_names = Dir[File.expand_path "~/.ssport/*"].select{ |f| File.file? f }.map{ |f| File.basename f, ".rc"}.join "\n"
|
20
|
+
puts '----------Alias Name----------'.colorize(:yellow)
|
21
|
+
puts alias_names.colorize(:green)
|
22
|
+
end
|
23
|
+
|
24
|
+
def dealrc
|
25
|
+
if @alias_name
|
26
|
+
server = @options[:server]
|
27
|
+
username = @options[:username]
|
28
|
+
pass = @options[:pass]
|
29
|
+
if server || username || pass
|
30
|
+
return saverc
|
31
|
+
else
|
32
|
+
return loadrc
|
33
|
+
end
|
34
|
+
end
|
35
|
+
return nil
|
36
|
+
end
|
37
|
+
|
38
|
+
def saverc
|
39
|
+
if @alias_name
|
40
|
+
rc = JSON.pretty_generate(@options)
|
41
|
+
File.write genrc(@alias_name), rc
|
42
|
+
return @options
|
43
|
+
end
|
44
|
+
return nil
|
45
|
+
end
|
46
|
+
|
47
|
+
def loadrc
|
48
|
+
if @alias_name
|
49
|
+
rc_content = File.read genrc(@alias_name)
|
50
|
+
rc = JSON.parse(rc_content)
|
51
|
+
final_rc = rc.collect{|k,v| [k.to_sym, v]}.to_h
|
52
|
+
return final_rc
|
53
|
+
else
|
54
|
+
puts "Don't find server alias name profile.".colorize(:red)
|
55
|
+
end
|
56
|
+
return nil
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'colorize'
|
3
|
+
require 'net/ssh'
|
4
|
+
require 'ssport/version'
|
5
|
+
|
6
|
+
class Remote
|
7
|
+
|
8
|
+
def initialize(options)
|
9
|
+
@options = options
|
10
|
+
end
|
11
|
+
|
12
|
+
def check?(keys)
|
13
|
+
keys.each do |key|
|
14
|
+
if !@options[key]
|
15
|
+
puts "#! Please set :server".colorize(:red)
|
16
|
+
return false
|
17
|
+
end
|
18
|
+
end
|
19
|
+
return true
|
20
|
+
end
|
21
|
+
|
22
|
+
def genCommand(keys)
|
23
|
+
command = "ssport -c #{@options[:config]}"
|
24
|
+
keys.each do |key|
|
25
|
+
if @options[key]
|
26
|
+
if key == :port
|
27
|
+
command += " -b #{@options[key]}"
|
28
|
+
else
|
29
|
+
command += " --#{key} #{@options[key]}"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
return command
|
34
|
+
end
|
35
|
+
|
36
|
+
def genScript
|
37
|
+
command = genCommand [:password , :method, :port, :config]
|
38
|
+
script = %Q{
|
39
|
+
if ! [ -x "$(command -v ssport)" ]; then
|
40
|
+
gem install ssport
|
41
|
+
else
|
42
|
+
if [ `ssport -v` != "#{Ssport::VERSION}" ]; then
|
43
|
+
gem update ssport
|
44
|
+
fi
|
45
|
+
fi
|
46
|
+
#{command}
|
47
|
+
ssserver -c #{@options[:config]} -d restart
|
48
|
+
}
|
49
|
+
script
|
50
|
+
end
|
51
|
+
|
52
|
+
def ssh
|
53
|
+
if !check?([:server, :username, :pass, :config])
|
54
|
+
return
|
55
|
+
end
|
56
|
+
|
57
|
+
puts "Begin Connect #{@options[:server]}".colorize(:yellow)
|
58
|
+
|
59
|
+
output = ""
|
60
|
+
script = genScript
|
61
|
+
|
62
|
+
Net::SSH.start(@options[:server], @options[:username], :password => @options[:pass]) do |ssh|
|
63
|
+
# capture all stderr and stdout output from a remote process
|
64
|
+
output = ssh.exec!(script)
|
65
|
+
end
|
66
|
+
|
67
|
+
puts '----------------Remote---------------'.colorize(:yellow)
|
68
|
+
puts output
|
69
|
+
puts '------------------End------------------'.colorize(:yellow)
|
70
|
+
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
data/lib/ssport/version.rb
CHANGED
data/lib/ssport.rb
CHANGED
@@ -1,16 +1,41 @@
|
|
1
1
|
require "ssport/version"
|
2
2
|
require "ssport/config"
|
3
|
+
require "ssport/profile"
|
4
|
+
require "ssport/remote"
|
3
5
|
require "colorize"
|
4
6
|
require 'fileutils'
|
5
7
|
require 'optparse'
|
6
|
-
require '
|
8
|
+
require 'json'
|
7
9
|
|
8
10
|
module Ssport
|
9
11
|
|
10
12
|
def self.run
|
11
13
|
|
14
|
+
methods_des = %Q{
|
15
|
+
Sodium:
|
16
|
+
chacha20-poly1305, chacha20-ietf-poly1305,
|
17
|
+
xchacha20-ietf-poly1305,
|
18
|
+
sodium:aes-256-gcm,
|
19
|
+
salsa20, chacha20, chacha20-ietf.
|
20
|
+
Sodium 1.0.12:
|
21
|
+
xchacha20
|
22
|
+
OpenSSL:
|
23
|
+
aes-{128|192|256}-gcm, aes-{128|192|256}-cfb,
|
24
|
+
aes-{128|192|256}-ofb, aes-{128|192|256}-ctr,
|
25
|
+
camellia-{128|192|256}-cfb,
|
26
|
+
bf-cfb, cast5-cfb, des-cfb, idea-cfb,
|
27
|
+
rc2-cfb, seed-cfb,
|
28
|
+
rc4, rc4-md5, table.
|
29
|
+
OpenSSL 1.1:
|
30
|
+
aes-{128|192|256}-ocb
|
31
|
+
mbedTLS:
|
32
|
+
mbedtls:aes-{128|192|256}-cfb128,
|
33
|
+
mbedtls:aes-{128|192|256}-ctr,
|
34
|
+
mbedtls:camellia-{128|192|256}-cfb128,
|
35
|
+
mbedtls:aes-{128|192|256}-gcm
|
36
|
+
}
|
37
|
+
|
12
38
|
options = {}
|
13
|
-
options[:config] = "shadowsocks.json"
|
14
39
|
OptionParser.new do |opts|
|
15
40
|
opts.banner = "Usage: change shadowsocket port"
|
16
41
|
|
@@ -18,6 +43,14 @@ module Ssport
|
|
18
43
|
options[:server] = v
|
19
44
|
end
|
20
45
|
|
46
|
+
opts.on("-A", "--server aliasName", "ssh server alia name, eg: ssport -a ramnode -b 724") do |v|
|
47
|
+
options[:alias] = v
|
48
|
+
end
|
49
|
+
|
50
|
+
opts.on("-L", "--list", "list available server alia name") do |v|
|
51
|
+
options[:list] = true
|
52
|
+
end
|
53
|
+
|
21
54
|
opts.on("-U", "--username username", "ssh server username") do |v|
|
22
55
|
options[:username] = v
|
23
56
|
end
|
@@ -34,7 +67,7 @@ module Ssport
|
|
34
67
|
options[:password] = v
|
35
68
|
end
|
36
69
|
|
37
|
-
opts.on("-m", "--method method","shadowsocket encry method") do |v|
|
70
|
+
opts.on("-m", "--method method","shadowsocket encry method. methods: \n #{methods_des}") do |v|
|
38
71
|
options[:method] = v
|
39
72
|
end
|
40
73
|
|
@@ -42,10 +75,38 @@ module Ssport
|
|
42
75
|
options[:config] = v
|
43
76
|
end
|
44
77
|
|
78
|
+
opts.on("-v", "--version","ssport version") do |v|
|
79
|
+
options[:version] = true
|
80
|
+
end
|
81
|
+
|
45
82
|
end.parse!
|
46
83
|
|
84
|
+
if options[:version]
|
85
|
+
puts Ssport::VERSION
|
86
|
+
return
|
87
|
+
end
|
88
|
+
|
89
|
+
if options[:list]
|
90
|
+
profile = Profile.new(options)
|
91
|
+
profile.list
|
92
|
+
return
|
93
|
+
end
|
94
|
+
|
95
|
+
alias_name = options[:alias]
|
96
|
+
if alias_name
|
97
|
+
profile = Profile.new(options)
|
98
|
+
rc = profile.dealrc
|
99
|
+
if rc
|
100
|
+
changeOption options, rc, :server
|
101
|
+
changeOption options, rc, :username
|
102
|
+
changeOption options, rc, :pass
|
103
|
+
changeOption options, rc, :config
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
47
107
|
if options[:server]
|
48
|
-
|
108
|
+
remote = Remote.new(options)
|
109
|
+
remote.ssh
|
49
110
|
elsif options[:config]
|
50
111
|
config = Config.new(options)
|
51
112
|
config.run
|
@@ -53,26 +114,12 @@ module Ssport
|
|
53
114
|
|
54
115
|
end
|
55
116
|
|
56
|
-
def self.
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
# capture all stderr and stdout output from a remote process
|
62
|
-
script = %Q{
|
63
|
-
if ! [ -x "$(command -v ssport)" ]; then
|
64
|
-
gem install ssport
|
65
|
-
fi
|
66
|
-
ssport -b #{options[:port]} -c #{options[:config]}
|
67
|
-
ssserver -c #{options[:config]}
|
68
|
-
}
|
69
|
-
output = ssh.exec!(script)
|
117
|
+
def self.changeOption(options, rc, key)
|
118
|
+
opt_value = options[key]
|
119
|
+
rc_value = rc[key]
|
120
|
+
if !opt_value && rc_value
|
121
|
+
options[key] = rc_value
|
70
122
|
end
|
71
|
-
|
72
|
-
puts '----------------Remote---------------'.colorize(:yellow)
|
73
|
-
puts output
|
74
|
-
puts '------------------End------------------'.colorize(:yellow)
|
75
|
-
|
76
123
|
end
|
77
124
|
|
78
125
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ssport
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- kaich
|
@@ -97,6 +97,8 @@ files:
|
|
97
97
|
- bin/ssport
|
98
98
|
- lib/ssport.rb
|
99
99
|
- lib/ssport/config.rb
|
100
|
+
- lib/ssport/profile.rb
|
101
|
+
- lib/ssport/remote.rb
|
100
102
|
- lib/ssport/version.rb
|
101
103
|
- ssport.gemspec
|
102
104
|
homepage: ''
|