obfssh_client: add configure file support
parent
70604852cf
commit
901e087e01
@ -0,0 +1,37 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/go-yaml/yaml"
|
||||||
|
"io/ioutil"
|
||||||
|
)
|
||||||
|
|
||||||
|
type config struct {
|
||||||
|
Host string `yaml:"host"`
|
||||||
|
Port int `yaml:"port"`
|
||||||
|
PrivateKey string `yaml:"private_key"`
|
||||||
|
ObfsMethod string `yaml:"obfs_method"`
|
||||||
|
ObfsKey string `yaml:"obfs_key"`
|
||||||
|
Username string `yaml:"username"`
|
||||||
|
Password string `yaml:"password"`
|
||||||
|
KeepaliveInterval int `yaml:"keepalive_interval"`
|
||||||
|
KeepaliveMax int `yaml:"keepalive_max"`
|
||||||
|
Debug bool `yaml:"debug"`
|
||||||
|
DisableObfsAfterHandshake bool `yaml:"disable_obfs_after_handshake"`
|
||||||
|
NotRunCmd bool `yaml:"not_run_cmd"`
|
||||||
|
LocalForward []string `yaml:"local_forward"`
|
||||||
|
RemoteForward []string `yaml:"remote_forward"`
|
||||||
|
DynamicForward []string `yaml:"dynamic_forward"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func loadConfig(f string) (*config, error) {
|
||||||
|
buf, err := ioutil.ReadFile(f)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
var c config
|
||||||
|
err = yaml.Unmarshal(buf, &c)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &c, nil
|
||||||
|
}
|
@ -0,0 +1,54 @@
|
|||||||
|
|
||||||
|
# vim: set ft=yaml:
|
||||||
|
|
||||||
|
# the server address
|
||||||
|
host: ssh.example.com
|
||||||
|
|
||||||
|
# the server port
|
||||||
|
port: 2223
|
||||||
|
|
||||||
|
# obfs encrypt method, rc4, aes or none, same as server
|
||||||
|
obfs_method: rc4
|
||||||
|
|
||||||
|
# obfs encrypt key, same as server
|
||||||
|
obfs_key: some_keyword
|
||||||
|
|
||||||
|
# ssh username at remote
|
||||||
|
username: user1
|
||||||
|
|
||||||
|
# ssh password
|
||||||
|
password: 1234
|
||||||
|
|
||||||
|
# keep alive interval
|
||||||
|
keepalive_interval: 15
|
||||||
|
|
||||||
|
# max error on keep alive
|
||||||
|
# when error meet max count, will close the connection
|
||||||
|
keepalive_max: 5
|
||||||
|
|
||||||
|
# private key to auth user on remote
|
||||||
|
private_key: /home/user1/.ssh/id_rsa
|
||||||
|
|
||||||
|
# debug
|
||||||
|
debug: false
|
||||||
|
|
||||||
|
# not run cmd or start shell on remote
|
||||||
|
not_run_cmd: true
|
||||||
|
|
||||||
|
# disable obfs after ssh handshake
|
||||||
|
disable_obfs_after_handshake: true
|
||||||
|
|
||||||
|
# local port forward, forword local port to remote host
|
||||||
|
local_forward:
|
||||||
|
- :3311:127.0.0.1:3121
|
||||||
|
- 127.0.0.1:3121:10.0.0.1:1223
|
||||||
|
|
||||||
|
# remote port forward, forward remote port to local host
|
||||||
|
remote_forward:
|
||||||
|
- :3123:127.0.0.1:4322
|
||||||
|
- :3124:10.0.0.1:2212
|
||||||
|
|
||||||
|
# dynamic forward port to remote host
|
||||||
|
dynamic_forward:
|
||||||
|
- :3224
|
||||||
|
- 127.0.0.1:9883
|
@ -0,0 +1,14 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestConfig(t *testing.T) {
|
||||||
|
c, err := loadConfig("config_example.yaml")
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
fmt.Printf("%+v\n", c)
|
||||||
|
}
|
Loading…
Reference in New Issue