Skip to content

Commit

Permalink
fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
longxboy committed Apr 23, 2017
1 parent 6f5d372 commit b8617b6
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 47 deletions.
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Lunnel
Lunnel 是一款简单易用的内网NAT穿越、反向代理软件,支持 http, https, udp, tcp、unix socket 等协议
lunnel 是一款简单易用的内网NAT穿越、反向代理软件,支持 HTTP, HTTPS, UDP, TCP、Unix socket 协议

## Feature

Expand All @@ -9,7 +9,7 @@ Lunnel 是一款简单易用的内网NAT穿越、反向代理软件,支持 htt

## QuickStart

### 为 docker daemon 配置 http api 访问
### 为 docker daemon 配置 HTTP API 访问

1. 修改服务端配置:

Expand Down Expand Up @@ -64,21 +64,21 @@ server_name: example.com

## Q&A

> **Q: 在示例配置中客户端使用的是 tls 加密方式,需要 CA 签发的 SSL 证书,如果没有的话怎么办?**
> <br>**A: 可以使用 openssl 自签名证书,请参考:[基于 OpenSSL 自建 CA 和颁发 SSL 证书](http://seanlook.com/2015/01/18/openssl-self-sign-ca/)、[openssl 生成 ssl 证书](http://blog.sina.com.cn/s/blog_4fd50c390101891c.html);<br>或者您也可以在客户端以及服务端配置文件中指定 `aes.secret_key` 从而使用 aes 加密。**
> **Q: 在示例配置中客户端使用的是 TLS 加密方式,需要 CA 签发的 SSL 证书,如果没有的话怎么办?**
> <br>**A: 可以使用 OpenSSL 自签名证书,请参考:[基于 OpenSSL 自建 CA 和颁发 SSL 证书](http://seanlook.com/2015/01/18/openssl-self-sign-ca/)、[OpenSSL 生成 SSL 证书](http://blog.sina.com.cn/s/blog_4fd50c390101891c.html);<br>或者您也可以在客户端以及服务端配置文件中指定 `aes.secret_key` 从而使用 aes 加密。**

> **Q: 启动程序的时候为何报错 `found character that cannot start any token`?**
> <br>**A: YAML 格式的配置文件每一行的开头不允许出现 tab 字符,请将所有的 tab 换成空格。**

## 完整配置说明
## Config Reference

- [客户端配置](https://github.com/longXboy/lunnel/blob/master/cmd/lunnelCli/config-full-example.yml)
- [服务端配置](https://github.com/longXboy/lunnel/blob/master/cmd/lunnelSer/config-full-example.yml)
- [客户端配置说明](https://github.com/longXboy/lunnel/blob/master/cmd/lunnelCli/config-full-example.yml)
- [服务端配置说明](https://github.com/longXboy/lunnel/blob/master/cmd/lunnelSer/config-full-example.yml)

## TODO

- [x] 持久化客户端获得的远公开访问地址,不再因为暂时失联而重新分配公开访问地址
- [x] 使用 http api 实时修改客户端的代理隧道支持,不需要重启客户端
- [x] 使用 HTTP API 实时修改客户端的代理隧道支持,不需要重启客户端
- [ ] 优化隧道连接池算法
- [ ] 底层传输协议支持 QUIC
- [ ] 提供 dashboard 管理界面,开放 http 接口
- [ ] 提供 Dashboard 管理界面,开放 HTTP 接口
7 changes: 2 additions & 5 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"crypto/tls"
"crypto/x509"
"encoding/pem"
"flag"
"fmt"
"io"
"io/ioutil"
Expand Down Expand Up @@ -154,10 +153,8 @@ func dialAndRun(transportMode string) {
ctl.Run()
}

func Main() {
configFile := flag.String("c", "./config.yml", "path of config file")
flag.Parse()
err := LoadConfig(*configFile)
func Main(configDetail []byte, configType string) {
err := LoadConfig(configDetail, configType)
if err != nil {
rawLog.Fatalf("load config failed!err:=%v", err)
}
Expand Down
17 changes: 6 additions & 11 deletions client/clientConfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@ package client
import (
"crypto/sha1"
"encoding/json"
"io/ioutil"
"net"
"os"
"strings"

"github.com/longXboy/lunnel/log"
"github.com/longXboy/lunnel/util"
Expand Down Expand Up @@ -79,19 +77,16 @@ type Config struct {

var cliConf Config

func LoadConfig(configFile string) error {
if configFile != "" {
content, err := ioutil.ReadFile(configFile)
if err != nil {
return errors.Wrap(err, "read config file")
}
if strings.HasSuffix(configFile, "json") {
err = json.Unmarshal(content, &cliConf)
func LoadConfig(configDetail []byte, configType string) error {
var err error
if len(configDetail) > 0 {
if configType == "json" {
err = json.Unmarshal(configDetail, &cliConf)
if err != nil {
return errors.Wrap(err, "unmarshal config file using json decode")
}
} else {
err = yaml.Unmarshal(content, &cliConf)
err = yaml.Unmarshal(configDetail, &cliConf)
if err != nil {
return errors.Wrap(err, "unmarshal config file using yaml decode")
}
Expand Down
29 changes: 27 additions & 2 deletions cmd/lunnelCli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,33 @@

package main

import "github.com/longXboy/lunnel/client"
import (
"flag"
"io/ioutil"
"log"
"strings"

"github.com/longXboy/lunnel/client"
)

func main() {
client.Main()
configFile := flag.String("c", "./config.yml", "path of config file")
flag.Parse()
var configDetail []byte
var err error
configType := ""
if *configFile != "" {
configDetail, err = ioutil.ReadFile(*configFile)
if err != nil {
log.Fatalf("read configfile failed!err:=%v\n", err)
return
}
if strings.HasSuffix(*configFile, "json") {
configType = "json"
} else {
configType = "yaml"
}
}

client.Main(configDetail, configType)
}
29 changes: 27 additions & 2 deletions cmd/lunnelSer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,33 @@

package main

import "github.com/longXboy/lunnel/server"
import (
"flag"
"io/ioutil"
"log"
"strings"

"github.com/longXboy/lunnel/server"
)

func main() {
server.Main()
configFile := flag.String("c", "./config.yml", "path of config file")
flag.Parse()
var configDetail []byte
var err error
configType := ""
if *configFile != "" {
configDetail, err = ioutil.ReadFile(*configFile)
if err != nil {
log.Fatalf("read configfile failed!err:=%v\n", err)
return
}
if strings.HasSuffix(*configFile, "json") {
configType = "json"
} else {
configType = "yaml"
}
}

server.Main(configDetail, configType)
}
17 changes: 6 additions & 11 deletions server/serConfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ package server
import (
"crypto/sha1"
"encoding/json"
"io/ioutil"
"strings"

"github.com/longXboy/lunnel/log"
"github.com/pkg/errors"
Expand Down Expand Up @@ -62,19 +60,16 @@ type Config struct {

var serverConf Config

func LoadConfig(configFile string) error {
if configFile != "" {
content, err := ioutil.ReadFile(configFile)
if err != nil {
return errors.Wrap(err, "read config file")
}
if strings.HasSuffix(configFile, "json") {
err = json.Unmarshal(content, &serverConf)
func LoadConfig(configDetail []byte, configType string) error {
var err error
if len(configDetail) > 0 {
if configType == "json" {
err = json.Unmarshal(configDetail, &serverConf)
if err != nil {
return errors.Wrap(err, "unmarshal config file using json decode")
}
} else {
err = yaml.Unmarshal(content, &serverConf)
err = yaml.Unmarshal(configDetail, &serverConf)
if err != nil {
return errors.Wrap(err, "unmarshal config file using yaml decode")
}
Expand Down
4 changes: 2 additions & 2 deletions server/serControl.go
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ func (c *Control) ServerAddTunnels(sstm *msg.AddTunnels) {
}

if tunnel.Public.Schema == "tcp" || tunnel.Public.Schema == "udp" {
if tunnel.Public.Port == 0 && oldTunnel != nil && tunnel.Public.Schema == oldTunnel.tunnelConfig.Public.Schema {
if tunnel.Public.Port == 0 && oldTunnel != nil && tunnel.Public.Schema == oldTunnel.tunnelConfig.Public.Schema && tunnel.LocalAddr() == oldTunnel.tunnelConfig.LocalAddr() {
tunnel.Public.AllowReallocate = true
tunnel.Public.Port = oldTunnel.tunnelConfig.Public.Port
}
Expand Down Expand Up @@ -541,7 +541,7 @@ func (c *Control) ServerAddTunnels(sstm *msg.AddTunnels) {
tunnel.Public.Host = serverConf.ServerDomain
} else if tunnel.Public.Schema == "http" || tunnel.Public.Schema == "https" {
if tunnel.Public.Host == "" {
if oldTunnel != nil && tunnel.Public.Schema == oldTunnel.tunnelConfig.Public.Schema {
if oldTunnel != nil && tunnel.Public.Schema == oldTunnel.tunnelConfig.Public.Schema && tunnel.LocalAddr() == oldTunnel.tunnelConfig.LocalAddr() {
tunnel.Public.AllowReallocate = true
tunnel.Public.Host = oldTunnel.tunnelConfig.Public.Host
} else {
Expand Down
7 changes: 2 additions & 5 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package server
import (
"crypto/tls"
"encoding/json"
"flag"
"fmt"
"io"
"io/ioutil"
Expand All @@ -37,10 +36,8 @@ import (
"github.com/longXboy/smux"
)

func Main() {
configFile := flag.String("c", "./config.yml", "path of config file")
flag.Parse()
err := LoadConfig(*configFile)
func Main(configDetail []byte, configType string) {
err := LoadConfig(configDetail, configType)
if err != nil {
rawLog.Fatalf("load config failed!err:=%v", err)
}
Expand Down

0 comments on commit b8617b6

Please sign in to comment.