-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Lukasz Zajaczkowski
committed
Jan 2, 2017
0 parents
commit 57cdf60
Showing
20 changed files
with
1,225 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# ws-vpn |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
[default] | ||
# server or client | ||
mode = client | ||
|
||
[client] | ||
server = 192.168.30.128 | ||
# server port | ||
port = 40100 | ||
# MTU | ||
mtu = 1400 |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
* Author: Lukasz Zajaczkowski <[email protected]> | ||
* | ||
*/ | ||
|
||
package main | ||
|
||
import ( | ||
"flag" | ||
"os" | ||
"runtime" | ||
|
||
. "github.com/zreigz/ws-vpn/utils" | ||
server "github.com/zreigz/ws-vpn/vpn" | ||
client "github.com/zreigz/ws-vpn/vpn" | ||
) | ||
|
||
var debug bool | ||
var cfgFile string | ||
|
||
|
||
func main() { | ||
flag.BoolVar(&debug, "debug", false, "Provide debug info") | ||
flag.StringVar(&cfgFile, "config", "", "configfile") | ||
flag.Parse() | ||
|
||
|
||
InitLogger(debug) | ||
logger := GetLogger() | ||
|
||
checkerr := func(err error) { | ||
if err != nil { | ||
logger.Error(err.Error()) | ||
os.Exit(1) | ||
} | ||
} | ||
|
||
if cfgFile == "" { | ||
cfgFile = flag.Arg(0) | ||
} | ||
|
||
logger.Info("using config file: ", cfgFile) | ||
|
||
icfg, err := ParseConfig(cfgFile) | ||
logger.Debug(icfg) | ||
checkerr(err) | ||
|
||
maxProcs := runtime.GOMAXPROCS(0) | ||
if maxProcs < 2 { | ||
runtime.GOMAXPROCS(2) | ||
} | ||
|
||
switch cfg := icfg.(type) { | ||
case ServerConfig: | ||
err := server.NewServer(cfg) | ||
checkerr(err) | ||
case ClientConfig: | ||
err := client.NewClient(cfg) | ||
checkerr(err) | ||
default: | ||
logger.Error("Invalid config file") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
[default] | ||
# server or client | ||
mode = server | ||
|
||
[server] | ||
# port range to listen | ||
port = 40100 | ||
# server addr | ||
vpnaddr = 10.1.1.1/24 | ||
mtu = 1400 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
* Author: Lukasz Zajaczkowski <[email protected]> | ||
* | ||
*/ | ||
package utils | ||
|
||
import ( | ||
"errors" | ||
|
||
"github.com/scalingdata/gcfg" | ||
) | ||
|
||
// Server Config | ||
type ServerConfig struct { | ||
Port int | ||
ListenAddr string | ||
VpnAddr string | ||
MTU int | ||
} | ||
|
||
// Client Config | ||
type ClientConfig struct { | ||
Server string | ||
Port int | ||
MTU int | ||
} | ||
|
||
type VpnConfig struct { | ||
Default struct { | ||
Mode string | ||
} | ||
Server ServerConfig | ||
Client ClientConfig | ||
} | ||
|
||
func ParseConfig(filename string) (interface{}, error) { | ||
cfg := new(VpnConfig) | ||
err := gcfg.ReadFileInto(cfg, filename) | ||
if err != nil { | ||
return nil, err | ||
} | ||
switch cfg.Default.Mode { | ||
case "server": | ||
return cfg.Server, nil | ||
case "client": | ||
return cfg.Client, nil | ||
default: | ||
return nil, errors.New("Wrong config data") | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
* Author: Lukasz Zajaczkowski <[email protected]> | ||
* | ||
*/ | ||
package utils | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/op/go-logging" | ||
) | ||
|
||
var Logger = logging.MustGetLogger("ws-vpn") | ||
|
||
func InitLogger(debug bool) { | ||
fmt_string := "\r%{color}[%{time:06-01-02 15:04:05}][%{level:.6s}]%{color:reset} %{message}" | ||
format := logging.MustStringFormatter(fmt_string) | ||
logging.SetFormatter(format) | ||
logging.SetBackend(logging.NewLogBackend(os.Stdout, "", 0)) | ||
|
||
if debug { | ||
logging.SetLevel(logging.DEBUG, "ws-vpn") | ||
} else { | ||
logging.SetLevel(logging.INFO, "ws-vpn") | ||
} | ||
} | ||
|
||
func GetLogger() *logging.Logger { | ||
return Logger | ||
} |
Submodule websocket
added at
3ab3a8
Submodule go-logging
added at
970db5
Submodule gcfg
added at
37aaba
Submodule water
added at
98078a
Submodule x
added at
45e771
Oops, something went wrong.