docs: update install.md
Some checks failed
Coverage CI / build (push) Has been cancelled
CodeQL / Analyze (go) (push) Has been cancelled
Ubuntu CI / build (push) Has been cancelled

This commit is contained in:
Daniel Ding
2025-04-24 17:03:41 +08:00
parent afe6255777
commit b025178053
10 changed files with 57 additions and 181 deletions

View File

@@ -2,11 +2,9 @@ package v5
import (
"fmt"
"path/filepath"
"github.com/luscis/openlan/cmd/api"
"github.com/luscis/openlan/pkg/config"
"github.com/luscis/openlan/pkg/libol"
"github.com/luscis/openlan/pkg/schema"
"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 {
name := c.String("network")
format := c.String("format")
if format == "yaml" {
cfg.FormatNetworks()
}
cfg.RemarshalNetworks(format)
if len(name) > 0 {
obj := cfg.GetNetwork(name)
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 {
url := u.Url(c.String("url"), "reload")
clt := u.NewHttp(c.String("token"))
@@ -201,15 +77,6 @@ func (u Config) Commands(app *api.App) {
},
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",
Usage: "Reload configuration",

View File

@@ -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.tmpl' -delete
if [ ! -e "/etc/openlan/switch/switch.json" ]; then
cat >> /etc/openlan/switch/switch.json << EOF
{
"crypt": {
"secret": "cb2ff088a34d"
}
}
if [ ! -e "/etc/openlan/switch/switch.yaml" ]; then
cat >> /etc/openlan/switch/switch.yaml << EOF
crypt
secret: cb2ff088a34d
EOF
fi

View File

@@ -64,10 +64,10 @@ Add three access users on central network:
```
[root@switch ~]# openlan us add --name admin@central --role admin
[root@switch ~]# openlan us add --name access1@central
[root@switch ~]# openlan us add --name access2@central
[root@switch ~]# openlan us add --name access3@central
[root@switch ~]# openlan user add --name admin@central --role admin
[root@switch ~]# openlan user add --name access1@central
[root@switch ~]# openlan user add --name access2@central
[root@switch ~]# openlan user add --name access3@central
```

View File

@@ -27,7 +27,7 @@ OpenLAN软件包含下面部分
```
$ cd /etc/openlan/switch
$ cp ./switch.yaml.example ./switch.yaml
$ vim ./switch.yaml ## 编辑switch.yaml配置文件
$ vim ./switch.yaml
protocol: tcp
crypt:
algorithm: aes-128
@@ -39,7 +39,7 @@ OpenLAN软件包含下面部分
$ cd ./network
$ cp ./network.yaml.example ./example.yaml
$ vim ./example.yaml
name: example,
name: example
bridge:
address: 172.32.10.10/24
subnet:
@@ -58,10 +58,8 @@ OpenLAN软件包含下面部分
```
3. 添加一个新的接入认证的用户;
```
$ openlan us add --name hi@example
$ openlan user add --name hi@example
hi@example l6llot97yx guest
$ openlan us rm --name hi@example
```
4. 导出OpenVPN的客户端配置文件
@@ -104,7 +102,7 @@ OpenLAN软件包含下面部分
3. 配置Access Point服务自启动
```
$ systemctl enable --now openlan-access@example
$ journalctl -u openlan-access@example ## 查看日志信息
$ journalctl -u openlan-access@example
```
4. 检测网络是否可达;
```

View File

@@ -106,9 +106,9 @@ EOF
Add three access users on private network:
```
[root@switch-sh ~]# openlan us add --name admin@private --role admin
[root@switch-sh ~]# openlan us add --name access3@private
[root@switch-sh ~]# openlan us add --name access4@private
[root@switch-sh ~]# openlan us add --name access5@private
[root@switch-sh ~]# openlan user add --name admin@private --role admin
[root@switch-sh ~]# openlan user add --name access3@private
[root@switch-sh ~]# openlan user add --name access4@private
[root@switch-sh ~]# openlan user add --name access5@private
```

View File

@@ -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# cat > proxy.yaml << EOF
tcp:
- listen: 192.168.1.66:11082,
- listen: 192.168.1.66:11082
target: [192.168.1.88:11082
EOF

View File

@@ -65,7 +65,7 @@ func (h Network) Post(w http.ResponseWriter, r *http.Request) {
return
}
cs.CorrectNetwork(obj)
cs.CorrectNetwork(obj, "json")
if obj := cs.GetNetwork(obj.Name); obj != nil {
h.Switcher.AddNetwork(obj.Name)
} else {

View File

@@ -158,7 +158,7 @@ func (s *Switch) Dir(elem0, elem1 string) string {
var file string
if elem1 == "" {
return filepath.Join(elem0)
return filepath.Join(s.ConfDir, elem0)
}
if s.IsYaml() {
@@ -170,16 +170,33 @@ func (s *Switch) Dir(elem0, elem1 string) string {
return filepath.Join(s.ConfDir, elem0, file)
}
func (s *Switch) formatNetwork(obj *Network) {
context := obj.Specifies
obj.NewSpecifies()
func (s *Switch) RemarshalNetwork(obj *Network, format string) {
if obj.Specifies == nil {
return
}
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)
context := obj.Specifies
obj.NewSpecifies()
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.LoadOutput()
obj.LoadFindHop()
s.Network[obj.Name] = obj
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 {
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() {
for _, obj := range s.Network {
s.CorrectNetwork(obj)
s.CorrectNetwork(obj, "")
}
}

View File

@@ -60,7 +60,7 @@ type Config struct {
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
type Server struct {
config *Config

View File

@@ -428,8 +428,8 @@ func (v *Switch) Stop() {
}
w.Stop()
}
v.out.Info("Switch.Stop left Accesss")
// notify leave to Access.
v.out.Info("Switch.Stop left access")
// notify leave to access.
for p := range cache.Access.List() {
if p == nil {
break