mirror of
https://github.com/luscis/openlan.git
synced 2025-09-26 20:41:29 +08:00
docs: update install.md
This commit is contained in:
@@ -2,11 +2,9 @@ package v5
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"path/filepath"
|
|
||||||
|
|
||||||
"github.com/luscis/openlan/cmd/api"
|
"github.com/luscis/openlan/cmd/api"
|
||||||
"github.com/luscis/openlan/pkg/config"
|
"github.com/luscis/openlan/pkg/config"
|
||||||
"github.com/luscis/openlan/pkg/libol"
|
|
||||||
"github.com/luscis/openlan/pkg/schema"
|
"github.com/luscis/openlan/pkg/schema"
|
||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
)
|
)
|
||||||
@@ -29,9 +27,7 @@ func (u Config) List(c *cli.Context) error {
|
|||||||
if err := clt.GetJSON(url, cfg); err == nil {
|
if err := clt.GetJSON(url, cfg); err == nil {
|
||||||
name := c.String("network")
|
name := c.String("network")
|
||||||
format := c.String("format")
|
format := c.String("format")
|
||||||
if format == "yaml" {
|
cfg.RemarshalNetworks(format)
|
||||||
cfg.FormatNetworks()
|
|
||||||
}
|
|
||||||
if len(name) > 0 {
|
if len(name) > 0 {
|
||||||
obj := cfg.GetNetwork(name)
|
obj := cfg.GetNetwork(name)
|
||||||
return u.Out(obj, format, "")
|
return u.Out(obj, format, "")
|
||||||
@@ -43,126 +39,6 @@ func (u Config) List(c *cli.Context) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u Config) Check(c *cli.Context) error {
|
|
||||||
out := u.Log()
|
|
||||||
dir := c.String("dir")
|
|
||||||
// Check proxy configurations.
|
|
||||||
out.Info("%15s: %s", "check", "proxy")
|
|
||||||
file := filepath.Join(dir, "proxy.json")
|
|
||||||
if err := libol.FileExist(file); err == nil {
|
|
||||||
obj := &config.Proxy{}
|
|
||||||
if err := libol.UnmarshalLoad(obj, file); err != nil {
|
|
||||||
out.Warn("%15s: %s", filepath.Base(file), err)
|
|
||||||
} else {
|
|
||||||
out.Info("%15s: %s", filepath.Base(file), "success")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Check OLAP configurations.
|
|
||||||
out.Info("%15s: %s", "check", "access")
|
|
||||||
file = filepath.Join(dir, "access", "access.json")
|
|
||||||
if err := libol.FileExist(file); err == nil {
|
|
||||||
obj := &config.Access{}
|
|
||||||
if err := libol.UnmarshalLoad(obj, file); err != nil {
|
|
||||||
out.Warn("%15s: %s", filepath.Base(file), err)
|
|
||||||
} else {
|
|
||||||
out.Info("%15s: %s", filepath.Base(file), "success")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Check OLSW configurations.
|
|
||||||
out.Info("%15s: %s", "check", "switch")
|
|
||||||
file = filepath.Join(dir, "switch", "switch.json")
|
|
||||||
if err := libol.FileExist(file); err == nil {
|
|
||||||
obj := &config.Switch{}
|
|
||||||
if err := libol.UnmarshalLoad(obj, file); err != nil {
|
|
||||||
out.Warn("%15s: %s", filepath.Base(file), err)
|
|
||||||
} else {
|
|
||||||
out.Info("%15s: %s", filepath.Base(file), "success")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Check network configurations.
|
|
||||||
out.Info("%15s: %s", "check", "network")
|
|
||||||
pattern := filepath.Join(dir, "switch", "network", "*.json")
|
|
||||||
if files, err := filepath.Glob(pattern); err == nil {
|
|
||||||
for _, file := range files {
|
|
||||||
obj := &config.Network{}
|
|
||||||
if err := libol.UnmarshalLoad(obj, file); err != nil {
|
|
||||||
out.Warn("%15s: %s", filepath.Base(file), err)
|
|
||||||
} else {
|
|
||||||
out.Info("%15s: %s", filepath.Base(file), "success")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
out.Info("%15s: %s", "check", "qos")
|
|
||||||
pattern = filepath.Join(dir, "switch", "qos", "*.json")
|
|
||||||
if files, err := filepath.Glob(pattern); err == nil {
|
|
||||||
for _, file := range files {
|
|
||||||
obj := &config.Qos{}
|
|
||||||
if err := libol.UnmarshalLoad(obj, file); err != nil {
|
|
||||||
out.Warn("%15s: %s", filepath.Base(file), err)
|
|
||||||
} else {
|
|
||||||
out.Info("%15s: %s", filepath.Base(file), "success")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check ACL configurations.
|
|
||||||
out.Info("%15s: %s", "check", "acl")
|
|
||||||
pattern = filepath.Join(dir, "switch", "acl", "*.json")
|
|
||||||
if files, err := filepath.Glob(pattern); err == nil {
|
|
||||||
for _, file := range files {
|
|
||||||
obj := &config.ACL{}
|
|
||||||
if err := libol.UnmarshalLoad(obj, file); err != nil {
|
|
||||||
out.Warn("%15s: %s", filepath.Base(file), err)
|
|
||||||
} else {
|
|
||||||
out.Info("%15s: %s", filepath.Base(file), "success")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Check links configurations.
|
|
||||||
out.Info("%15s: %s", "check", "link")
|
|
||||||
pattern = filepath.Join(dir, "switch", "link", "*.json")
|
|
||||||
if files, err := filepath.Glob(pattern); err == nil {
|
|
||||||
for _, file := range files {
|
|
||||||
var obj []config.Access
|
|
||||||
if err := libol.UnmarshalLoad(&obj, file); err != nil {
|
|
||||||
out.Warn("%15s: %s", filepath.Base(file), err)
|
|
||||||
} else {
|
|
||||||
out.Info("%15s: %s", filepath.Base(file), "success")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Check routes configurations.
|
|
||||||
out.Info("%15s: %s", "check", "route")
|
|
||||||
pattern = filepath.Join(dir, "switch", "route", "*.json")
|
|
||||||
if files, err := filepath.Glob(pattern); err == nil {
|
|
||||||
for _, file := range files {
|
|
||||||
var obj []config.PrefixRoute
|
|
||||||
if err := libol.UnmarshalLoad(&obj, file); err != nil {
|
|
||||||
out.Warn("%15s: %s", filepath.Base(file), err)
|
|
||||||
} else {
|
|
||||||
out.Info("%15s: %s", filepath.Base(file), "success")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check output config
|
|
||||||
out.Info("%15s: %s", "check", "output")
|
|
||||||
pattern = filepath.Join(dir, "switch", "output", "*.json")
|
|
||||||
if files, err := filepath.Glob(pattern); err == nil {
|
|
||||||
for _, file := range files {
|
|
||||||
var obj []config.Output
|
|
||||||
if err := libol.UnmarshalLoad(&obj, file); err != nil {
|
|
||||||
out.Warn("%15s: %s", filepath.Base(file), err)
|
|
||||||
} else {
|
|
||||||
out.Info("%15s: %s", filepath.Base(file), "success")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (u Config) Reload(c *cli.Context) error {
|
func (u Config) Reload(c *cli.Context) error {
|
||||||
url := u.Url(c.String("url"), "reload")
|
url := u.Url(c.String("url"), "reload")
|
||||||
clt := u.NewHttp(c.String("token"))
|
clt := u.NewHttp(c.String("token"))
|
||||||
@@ -201,15 +77,6 @@ func (u Config) Commands(app *api.App) {
|
|||||||
},
|
},
|
||||||
Action: u.List,
|
Action: u.List,
|
||||||
},
|
},
|
||||||
{
|
|
||||||
Name: "check",
|
|
||||||
Usage: "Check all configuration",
|
|
||||||
Aliases: []string{"co"},
|
|
||||||
Flags: []cli.Flag{
|
|
||||||
&cli.StringFlag{Name: "dir", Value: "/etc/openlan"},
|
|
||||||
},
|
|
||||||
Action: u.Check,
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
Name: "reload",
|
Name: "reload",
|
||||||
Usage: "Reload configuration",
|
Usage: "Reload configuration",
|
||||||
|
11
dist/rootfs/var/openlan/script/switch.sh
vendored
11
dist/rootfs/var/openlan/script/switch.sh
vendored
@@ -14,13 +14,10 @@ sysctl -p /etc/sysctl.d/90-openlan.conf
|
|||||||
/usr/bin/env find /var/openlan/openvpn -name '*client.ovpn' -delete
|
/usr/bin/env find /var/openlan/openvpn -name '*client.ovpn' -delete
|
||||||
/usr/bin/env find /var/openlan/openvpn -name '*client.tmpl' -delete
|
/usr/bin/env find /var/openlan/openvpn -name '*client.tmpl' -delete
|
||||||
|
|
||||||
if [ ! -e "/etc/openlan/switch/switch.json" ]; then
|
if [ ! -e "/etc/openlan/switch/switch.yaml" ]; then
|
||||||
cat >> /etc/openlan/switch/switch.json << EOF
|
cat >> /etc/openlan/switch/switch.yaml << EOF
|
||||||
{
|
crypt
|
||||||
"crypt": {
|
secret: cb2ff088a34d
|
||||||
"secret": "cb2ff088a34d"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
EOF
|
EOF
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@@ -64,10 +64,10 @@ Add three access users on central network:
|
|||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
[root@switch ~]# openlan us add --name admin@central --role admin
|
[root@switch ~]# openlan user add --name admin@central --role admin
|
||||||
[root@switch ~]# openlan us add --name access1@central
|
[root@switch ~]# openlan user add --name access1@central
|
||||||
[root@switch ~]# openlan us add --name access2@central
|
[root@switch ~]# openlan user add --name access2@central
|
||||||
[root@switch ~]# openlan us add --name access3@central
|
[root@switch ~]# openlan user add --name access3@central
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
@@ -27,7 +27,7 @@ OpenLAN软件包含下面部分:
|
|||||||
```
|
```
|
||||||
$ cd /etc/openlan/switch
|
$ cd /etc/openlan/switch
|
||||||
$ cp ./switch.yaml.example ./switch.yaml
|
$ cp ./switch.yaml.example ./switch.yaml
|
||||||
$ vim ./switch.yaml ## 编辑switch.yaml配置文件
|
$ vim ./switch.yaml
|
||||||
protocol: tcp
|
protocol: tcp
|
||||||
crypt:
|
crypt:
|
||||||
algorithm: aes-128
|
algorithm: aes-128
|
||||||
@@ -39,7 +39,7 @@ OpenLAN软件包含下面部分:
|
|||||||
$ cd ./network
|
$ cd ./network
|
||||||
$ cp ./network.yaml.example ./example.yaml
|
$ cp ./network.yaml.example ./example.yaml
|
||||||
$ vim ./example.yaml
|
$ vim ./example.yaml
|
||||||
name: example,
|
name: example
|
||||||
bridge:
|
bridge:
|
||||||
address: 172.32.10.10/24
|
address: 172.32.10.10/24
|
||||||
subnet:
|
subnet:
|
||||||
@@ -58,10 +58,8 @@ OpenLAN软件包含下面部分:
|
|||||||
```
|
```
|
||||||
3. 添加一个新的接入认证的用户;
|
3. 添加一个新的接入认证的用户;
|
||||||
```
|
```
|
||||||
$ openlan us add --name hi@example
|
$ openlan user add --name hi@example
|
||||||
hi@example l6llot97yx guest
|
hi@example l6llot97yx guest
|
||||||
|
|
||||||
$ openlan us rm --name hi@example
|
|
||||||
```
|
```
|
||||||
4. 导出OpenVPN的客户端配置文件;
|
4. 导出OpenVPN的客户端配置文件;
|
||||||
|
|
||||||
@@ -104,7 +102,7 @@ OpenLAN软件包含下面部分:
|
|||||||
3. 配置Access Point服务自启动;
|
3. 配置Access Point服务自启动;
|
||||||
```
|
```
|
||||||
$ systemctl enable --now openlan-access@example
|
$ systemctl enable --now openlan-access@example
|
||||||
$ journalctl -u openlan-access@example ## 查看日志信息
|
$ journalctl -u openlan-access@example
|
||||||
```
|
```
|
||||||
4. 检测网络是否可达;
|
4. 检测网络是否可达;
|
||||||
```
|
```
|
||||||
|
@@ -106,9 +106,9 @@ EOF
|
|||||||
Add three access users on private network:
|
Add three access users on private network:
|
||||||
|
|
||||||
```
|
```
|
||||||
[root@switch-sh ~]# openlan us add --name admin@private --role admin
|
[root@switch-sh ~]# openlan user add --name admin@private --role admin
|
||||||
[root@switch-sh ~]# openlan us add --name access3@private
|
[root@switch-sh ~]# openlan user add --name access3@private
|
||||||
[root@switch-sh ~]# openlan us add --name access4@private
|
[root@switch-sh ~]# openlan user add --name access4@private
|
||||||
[root@switch-sh ~]# openlan us add --name access5@private
|
[root@switch-sh ~]# openlan user add --name access5@private
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@@ -34,7 +34,7 @@ root@openlan::/opt/openlan/etc/openlan# docker restart openlan_proxy_1
|
|||||||
root@openlan:/opt/openlan/etc/openlan# cd /opt/openlan/etc/openlan
|
root@openlan:/opt/openlan/etc/openlan# cd /opt/openlan/etc/openlan
|
||||||
root@openlan:/opt/openlan/etc/openlan# cat > proxy.yaml << EOF
|
root@openlan:/opt/openlan/etc/openlan# cat > proxy.yaml << EOF
|
||||||
tcp:
|
tcp:
|
||||||
- listen: 192.168.1.66:11082,
|
- listen: 192.168.1.66:11082
|
||||||
target: [192.168.1.88:11082
|
target: [192.168.1.88:11082
|
||||||
|
|
||||||
EOF
|
EOF
|
||||||
|
@@ -65,7 +65,7 @@ func (h Network) Post(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
cs.CorrectNetwork(obj)
|
cs.CorrectNetwork(obj, "json")
|
||||||
if obj := cs.GetNetwork(obj.Name); obj != nil {
|
if obj := cs.GetNetwork(obj.Name); obj != nil {
|
||||||
h.Switcher.AddNetwork(obj.Name)
|
h.Switcher.AddNetwork(obj.Name)
|
||||||
} else {
|
} else {
|
||||||
|
@@ -158,7 +158,7 @@ func (s *Switch) Dir(elem0, elem1 string) string {
|
|||||||
var file string
|
var file string
|
||||||
|
|
||||||
if elem1 == "" {
|
if elem1 == "" {
|
||||||
return filepath.Join(elem0)
|
return filepath.Join(s.ConfDir, elem0)
|
||||||
}
|
}
|
||||||
|
|
||||||
if s.IsYaml() {
|
if s.IsYaml() {
|
||||||
@@ -170,16 +170,33 @@ func (s *Switch) Dir(elem0, elem1 string) string {
|
|||||||
return filepath.Join(s.ConfDir, elem0, file)
|
return filepath.Join(s.ConfDir, elem0, file)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Switch) formatNetwork(obj *Network) {
|
func (s *Switch) RemarshalNetwork(obj *Network, format string) {
|
||||||
context := obj.Specifies
|
|
||||||
obj.NewSpecifies()
|
|
||||||
if obj.Specifies == nil {
|
if obj.Specifies == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if data, err := libol.Marshal(context, true); err != nil {
|
|
||||||
libol.Warn("Switch.Format %s", err)
|
context := obj.Specifies
|
||||||
} else if err := libol.Unmarshal(obj.Specifies, data); err != nil {
|
obj.NewSpecifies()
|
||||||
libol.Warn("Switch.Format %s", err)
|
|
||||||
|
if format == "" {
|
||||||
|
format = "json"
|
||||||
|
if s.IsYaml() {
|
||||||
|
format = "yaml"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if format == "yaml" {
|
||||||
|
if data, err := libol.MarshalYaml(context); err != nil {
|
||||||
|
libol.Warn("Switch.Format %s", err)
|
||||||
|
} else if err := libol.UnmarshalYaml(obj.Specifies, data); err != nil {
|
||||||
|
libol.Warn("Switch.Format %s", err)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if data, err := libol.Marshal(context, true); err != nil {
|
||||||
|
libol.Warn("Switch.Format %s", err)
|
||||||
|
} else if err := libol.Unmarshal(obj.Specifies, data); err != nil {
|
||||||
|
libol.Warn("Switch.Format %s", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -210,11 +227,19 @@ func (s *Switch) UnmarshalNetwork(data []byte) (*Network, error) {
|
|||||||
obj.LoadRoute()
|
obj.LoadRoute()
|
||||||
obj.LoadOutput()
|
obj.LoadOutput()
|
||||||
obj.LoadFindHop()
|
obj.LoadFindHop()
|
||||||
|
|
||||||
s.Network[obj.Name] = obj
|
s.Network[obj.Name] = obj
|
||||||
return obj, nil
|
return obj, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Switch) correctNetwork(obj *Network) {
|
func (s *Switch) RemarshalNetworks(format string) {
|
||||||
|
for _, obj := range s.Network {
|
||||||
|
s.RemarshalNetwork(obj, format)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Switch) CorrectNetwork(obj *Network, format string) {
|
||||||
|
s.RemarshalNetwork(obj, format)
|
||||||
for _, link := range obj.Links {
|
for _, link := range obj.Links {
|
||||||
link.Correct()
|
link.Correct()
|
||||||
}
|
}
|
||||||
@@ -239,20 +264,9 @@ func (s *Switch) correctNetwork(obj *Network) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Switch) FormatNetworks() {
|
|
||||||
for _, obj := range s.Network {
|
|
||||||
s.formatNetwork(obj)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *Switch) CorrectNetwork(obj *Network) {
|
|
||||||
s.formatNetwork(obj)
|
|
||||||
s.correctNetwork(obj)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *Switch) CorrectNetworks() {
|
func (s *Switch) CorrectNetworks() {
|
||||||
for _, obj := range s.Network {
|
for _, obj := range s.Network {
|
||||||
s.CorrectNetwork(obj)
|
s.CorrectNetwork(obj, "")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -60,7 +60,7 @@ type Config struct {
|
|||||||
TlsConfig *tls.Config
|
TlsConfig *tls.Config
|
||||||
}
|
}
|
||||||
|
|
||||||
// Server is reponsible for accepting connections and handling
|
// Server is responsible for accepting connections and handling
|
||||||
// the details of the SOCKS5 protocol
|
// the details of the SOCKS5 protocol
|
||||||
type Server struct {
|
type Server struct {
|
||||||
config *Config
|
config *Config
|
||||||
|
@@ -428,8 +428,8 @@ func (v *Switch) Stop() {
|
|||||||
}
|
}
|
||||||
w.Stop()
|
w.Stop()
|
||||||
}
|
}
|
||||||
v.out.Info("Switch.Stop left Accesss")
|
v.out.Info("Switch.Stop left access")
|
||||||
// notify leave to Access.
|
// notify leave to access.
|
||||||
for p := range cache.Access.List() {
|
for p := range cache.Access.List() {
|
||||||
if p == nil {
|
if p == nil {
|
||||||
break
|
break
|
||||||
|
Reference in New Issue
Block a user