mirror of
https://github.com/luscis/openlan.git
synced 2025-10-14 04:43:52 +08:00
fix: output yaml not pretty
This commit is contained in:
@@ -73,6 +73,7 @@ func OutTable(data interface{}, tmpl string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func Out(data interface{}, format string, tmpl string) error {
|
func Out(data interface{}, format string, tmpl string) error {
|
||||||
|
libol.Debug("Out %s %s", format, tmpl)
|
||||||
switch format {
|
switch format {
|
||||||
case "json":
|
case "json":
|
||||||
return OutJson(data)
|
return OutJson(data)
|
||||||
|
@@ -7,7 +7,6 @@ import (
|
|||||||
"github.com/luscis/openlan/pkg/libol"
|
"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"
|
||||||
"gopkg.in/yaml.v2"
|
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -27,14 +26,13 @@ func (u Config) List(c *cli.Context) error {
|
|||||||
clt := u.NewHttp(c.String("token"))
|
clt := u.NewHttp(c.String("token"))
|
||||||
cfg := &config.Switch{}
|
cfg := &config.Switch{}
|
||||||
if err := clt.GetJSON(url, cfg); err == nil {
|
if err := clt.GetJSON(url, cfg); err == nil {
|
||||||
var data []byte
|
format := c.String("format")
|
||||||
if c.String("format") == "yaml" {
|
if format == "yaml" {
|
||||||
data, _ = yaml.Marshal(cfg)
|
cfg.Format()
|
||||||
} else {
|
} else {
|
||||||
data, _ = libol.Marshal(cfg, true)
|
format = "json"
|
||||||
}
|
}
|
||||||
fmt.Println(string(data))
|
return u.Out(cfg, format, "")
|
||||||
return nil
|
|
||||||
} else {
|
} else {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -165,9 +163,6 @@ func (u Config) Commands(app *api.App) {
|
|||||||
Name: "list",
|
Name: "list",
|
||||||
Usage: "Display all configuration",
|
Usage: "Display all configuration",
|
||||||
Aliases: []string{"ls"},
|
Aliases: []string{"ls"},
|
||||||
Flags: []cli.Flag{
|
|
||||||
&cli.StringFlag{Name: "format", Value: "json"},
|
|
||||||
},
|
|
||||||
Action: u.List,
|
Action: u.List,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
2
dist/resource/ipsec.json.example
vendored
2
dist/resource/ipsec.json.example
vendored
@@ -29,7 +29,7 @@
|
|||||||
"auth": "a263d01a96db11eb9",
|
"auth": "a263d01a96db11eb9",
|
||||||
"crypt": "9b73bc48e3864b3ebc"
|
"crypt": "9b73bc48e3864b3ebc"
|
||||||
},
|
},
|
||||||
"policy": [
|
"policies": [
|
||||||
{
|
{
|
||||||
"source": "192.168.1.0/24",
|
"source": "192.168.1.0/24",
|
||||||
"destination": "192.168.2.0/24"
|
"destination": "192.168.2.0/24"
|
||||||
|
4
dist/resource/point.json.example
vendored
4
dist/resource/point.json.example
vendored
@@ -3,5 +3,7 @@
|
|||||||
"connection": "who.openlan.net",
|
"connection": "who.openlan.net",
|
||||||
"username": "hi@default",
|
"username": "hi@default",
|
||||||
"password": "cb2ff088a34d",
|
"password": "cb2ff088a34d",
|
||||||
"cert": { "insecure": true }
|
"cert": {
|
||||||
|
"insecure": true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
3
dist/resource/point.json.full.example
vendored
3
dist/resource/point.json.full.example
vendored
@@ -1,12 +1,11 @@
|
|||||||
{
|
{
|
||||||
"network": "default",
|
|
||||||
"interface": {
|
"interface": {
|
||||||
"name": "tap0",
|
"name": "tap0",
|
||||||
"bridge": "br-default",
|
"bridge": "br-default",
|
||||||
"address": "172.32.100.10/24"
|
"address": "172.32.100.10/24"
|
||||||
},
|
},
|
||||||
"connection": "who.openlan.net",
|
"connection": "who.openlan.net",
|
||||||
"username": "hi",
|
"username": "hi@default",
|
||||||
"password": "1f4ee82b5eb6",
|
"password": "1f4ee82b5eb6",
|
||||||
"protocol": "tls",
|
"protocol": "tls",
|
||||||
"cert": {
|
"cert": {
|
||||||
|
2
dist/resource/switch.json.full.example
vendored
2
dist/resource/switch.json.full.example
vendored
@@ -29,7 +29,7 @@
|
|||||||
"ldap": {
|
"ldap": {
|
||||||
"server": "ldap-server.net:389",
|
"server": "ldap-server.net:389",
|
||||||
"bindDN": "cn=admin,dc=openlan,dc=com",
|
"bindDN": "cn=admin,dc=openlan,dc=com",
|
||||||
"password": "your-passowrd",
|
"bindPass": "your-passowrd",
|
||||||
"baseDN": "dc=openlan,dc=com",
|
"baseDN": "dc=openlan,dc=com",
|
||||||
"attribute": "cn",
|
"attribute": "cn",
|
||||||
"filter": "(cn=%s)"
|
"filter": "(cn=%s)"
|
||||||
|
@@ -7,8 +7,8 @@ type Bridge struct {
|
|||||||
IPMtu int `json:"mtu,omitempty" yaml:"mtu,omitempty"`
|
IPMtu int `json:"mtu,omitempty" yaml:"mtu,omitempty"`
|
||||||
Address string `json:"address,omitempty" yaml:"address,omitempty"`
|
Address string `json:"address,omitempty" yaml:"address,omitempty"`
|
||||||
Provider string `json:"provider,omitempty" yaml:"provider,omitempty"`
|
Provider string `json:"provider,omitempty" yaml:"provider,omitempty"`
|
||||||
Stp string `json:"stp,omitempty" yaml:"stpState,omitempty"`
|
Stp string `json:"stp,omitempty" yaml:"stp,omitempty"`
|
||||||
Delay int `json:"delay,omitempty" yaml:"forwardDelay,omitempty"`
|
Delay int `json:"delay,omitempty" yaml:"delay,omitempty"`
|
||||||
Mss int `json:"tcpMss,omitempty" yaml:"tcpMss,omitempty"`
|
Mss int `json:"tcpMss,omitempty" yaml:"tcpMss,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -30,11 +30,11 @@ func SetLocalUdp(port string) {
|
|||||||
|
|
||||||
type EspState struct {
|
type EspState struct {
|
||||||
Local string `json:"local,omitempty" yaml:"local,omitempty"`
|
Local string `json:"local,omitempty" yaml:"local,omitempty"`
|
||||||
LocalIp net.IP `json:"local_addr" yaml:"local_addr"`
|
LocalIp net.IP `json:"local_addr" yaml:"localAddr"`
|
||||||
Remote string `json:"remote,omitempty" yaml:"remote,omitempty"`
|
Remote string `json:"remote,omitempty" yaml:"remote,omitempty"`
|
||||||
RemotePort int `json:"remote_port" yaml:"remote_port"`
|
RemotePort int `json:"remote_port" yaml:"remotePort"`
|
||||||
RemoteIp net.IP `json:"remote_addr" yaml:"remote_addr"`
|
RemoteIp net.IP `json:"remote_addr" yaml:"remoteAddr"`
|
||||||
Encap string `json:"encap,omitempty" yaml:"encapsulation,omitempty"`
|
Encap string `json:"encapsulation" yaml:"encapsulation"`
|
||||||
Auth string `json:"auth,omitempty" yaml:"auth,omitempty"`
|
Auth string `json:"auth,omitempty" yaml:"auth,omitempty"`
|
||||||
Crypt string `json:"crypt,omitempty" yaml:"crypt,omitempty"`
|
Crypt string `json:"crypt,omitempty" yaml:"crypt,omitempty"`
|
||||||
}
|
}
|
||||||
@@ -90,7 +90,7 @@ func (s *EspState) Correct(obj *EspState) {
|
|||||||
|
|
||||||
type ESPPolicy struct {
|
type ESPPolicy struct {
|
||||||
Source string `json:"source,omitempty"`
|
Source string `json:"source,omitempty"`
|
||||||
Dest string `json:"destination,omitempty"`
|
Dest string `json:"destination,omitempty" yaml:"destination"`
|
||||||
Priority int `json:"priority"`
|
Priority int `json:"priority"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -107,7 +107,7 @@ type ESPMember struct {
|
|||||||
Peer string `json:"peer"`
|
Peer string `json:"peer"`
|
||||||
Spi int `json:"spi"`
|
Spi int `json:"spi"`
|
||||||
State EspState `json:"state"`
|
State EspState `json:"state"`
|
||||||
Policies []*ESPPolicy `json:"policies" yaml:"policies,omitempty"`
|
Policies []*ESPPolicy `json:"policies" yaml:"policies"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *ESPMember) Correct(state *EspState) {
|
func (m *ESPMember) Correct(state *EspState) {
|
||||||
@@ -178,9 +178,9 @@ func (m *ESPMember) RemovePolicy(dest string) bool {
|
|||||||
type ESPSpecifies struct {
|
type ESPSpecifies struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Address string `json:"address,omitempty"`
|
Address string `json:"address,omitempty"`
|
||||||
State EspState `json:"state" yaml:"state,omitempty"`
|
State EspState `json:"state,omitempty" yaml:"state,omitempty"`
|
||||||
Members []*ESPMember `json:"members"`
|
Members []*ESPMember `json:"members"`
|
||||||
Listen string `json:"listen,omitempty"`
|
Listen string `json:"listen,omitempty" yaml:"listen,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *ESPSpecifies) Correct() {
|
func (n *ESPSpecifies) Correct() {
|
||||||
|
@@ -3,9 +3,9 @@ package config
|
|||||||
type FabricSpecifies struct {
|
type FabricSpecifies struct {
|
||||||
Mss int `json:"tcpMss,omitempty"`
|
Mss int `json:"tcpMss,omitempty"`
|
||||||
Fragment bool `json:"fragment"`
|
Fragment bool `json:"fragment"`
|
||||||
Driver string `json:"driver,omitempty"`
|
Driver string `json:"driver,omitempty" yaml:"driver,omitempty"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Tunnels []*FabricTunnel `json:"tunnels"`
|
Tunnels []*FabricTunnel `json:"tunnels" yaml:"tunnels"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *FabricSpecifies) Correct() {
|
func (n *FabricSpecifies) Correct() {
|
||||||
@@ -53,7 +53,7 @@ func (n *FabricSpecifies) DelTunnel(remote string) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type FabricTunnel struct {
|
type FabricTunnel struct {
|
||||||
DstPort uint32 `json:"dport"`
|
DstPort uint32 `json:"dport" yaml:"destPort"`
|
||||||
Remote string `json:"remote"`
|
Remote string `json:"remote"`
|
||||||
Local string `json:"local,omitempty" yaml:"local,omitempty"`
|
Local string `json:"local,omitempty" yaml:"local,omitempty"`
|
||||||
Mode string `json:"mode,omitempty" yaml:"mode,omitempty"`
|
Mode string `json:"mode,omitempty" yaml:"mode,omitempty"`
|
||||||
|
@@ -12,7 +12,7 @@ type FlowRule struct {
|
|||||||
Comment string `json:"comment,omitempty" yaml:"comment,omitempty"`
|
Comment string `json:"comment,omitempty" yaml:"comment,omitempty"`
|
||||||
Proto string `json:"protocol,omitempty" yaml:"protocol,omitempty"`
|
Proto string `json:"protocol,omitempty" yaml:"protocol,omitempty"`
|
||||||
Match string `json:"match,omitempty" yaml:"match,omitempty"`
|
Match string `json:"match,omitempty" yaml:"match,omitempty"`
|
||||||
DstPort string `json:"dport,omitempty" yaml:"dstPort,omitempty"`
|
DstPort string `json:"dport,omitempty" yaml:"destPort,omitempty"`
|
||||||
SrcPort string `json:"sport,omitempty" yaml:"srcPort,omitempty"`
|
SrcPort string `json:"sport,omitempty" yaml:"sourcePort,omitempty"`
|
||||||
Jump string `json:"jump,omitempty" yaml:"jump,omitempty"` // SNAT/RETURN/MASQUERADE
|
Jump string `json:"jump,omitempty" yaml:"jump,omitempty"` // SNAT/RETURN/MASQUERADE
|
||||||
}
|
}
|
||||||
|
@@ -2,10 +2,10 @@ package config
|
|||||||
|
|
||||||
type LDAP struct {
|
type LDAP struct {
|
||||||
Server string `json:"server"`
|
Server string `json:"server"`
|
||||||
BindDN string `json:"bindDN"`
|
BindDN string `json:"bindDN" yaml:"bindDN"`
|
||||||
BindPass string `json:"bindPass"`
|
BindPass string `json:"bindPass" yaml:"bindPass"`
|
||||||
BaseDN string `json:"baseDN"`
|
BaseDN string `json:"baseDN" yaml:"baseDN"`
|
||||||
Attribute string `json:"attribute"`
|
Attribute string `json:"attribute"`
|
||||||
Filter string `json:"filter"`
|
Filter string `json:"filter"`
|
||||||
EnableTls bool `json:"enableTLS"`
|
Tls bool `json:"tLS"`
|
||||||
}
|
}
|
||||||
|
@@ -7,11 +7,11 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Network struct {
|
type Network struct {
|
||||||
ConfDir string `json:"-"`
|
ConfDir string `json:"-" yaml:"-"`
|
||||||
File string `json:"file"`
|
File string `json:"file"`
|
||||||
Alias string `json:"-" yaml:"-"`
|
Alias string `json:"-" yaml:"-"`
|
||||||
Name string `json:"name,omitempty" yaml:"name"`
|
Name string `json:"name" yaml:"name"`
|
||||||
Provider string `json:"provider,omitempty" yaml:"provider"`
|
Provider string `json:"provider,omitempty" yaml:"provider,omitempty"`
|
||||||
Bridge *Bridge `json:"bridge,omitempty" yaml:"bridge,omitempty"`
|
Bridge *Bridge `json:"bridge,omitempty" yaml:"bridge,omitempty"`
|
||||||
Subnet *IpSubnet `json:"subnet,omitempty" yaml:"subnet,omitempty"`
|
Subnet *IpSubnet `json:"subnet,omitempty" yaml:"subnet,omitempty"`
|
||||||
OpenVPN *OpenVPN `json:"openvpn,omitempty" yaml:"openvpn,omitempty"`
|
OpenVPN *OpenVPN `json:"openvpn,omitempty" yaml:"openvpn,omitempty"`
|
||||||
@@ -21,7 +21,7 @@ type Network struct {
|
|||||||
Acl string `json:"acl,omitempty" yaml:"acl,omitempty"`
|
Acl string `json:"acl,omitempty" yaml:"acl,omitempty"`
|
||||||
Specifies interface{} `json:"specifies,omitempty" yaml:"specifies,omitempty"`
|
Specifies interface{} `json:"specifies,omitempty" yaml:"specifies,omitempty"`
|
||||||
Dhcp string `json:"dhcp,omitempty" yaml:"dhcp,omitempty"`
|
Dhcp string `json:"dhcp,omitempty" yaml:"dhcp,omitempty"`
|
||||||
Outputs []Output `json:"outputs" yaml:"output,omitempty"`
|
Outputs []Output `json:"outputs" yaml:"outputs"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *Network) Correct() {
|
func (n *Network) Correct() {
|
||||||
|
@@ -16,18 +16,17 @@ type OpenVPN struct {
|
|||||||
Device string `json:"device"`
|
Device string `json:"device"`
|
||||||
Version int `json:"version"`
|
Version int `json:"version"`
|
||||||
Auth string `json:"auth"` // xauth or cert.
|
Auth string `json:"auth"` // xauth or cert.
|
||||||
DhPem string `json:"dhPem"`
|
DhPem string `json:"dhPem" yaml:"dhPem"`
|
||||||
RootCa string `json:"rootCa"`
|
RootCa string `json:"rootCa"`
|
||||||
ServerCrt string `json:"cert"`
|
ServerCrt string `json:"cert" yaml:"cert"`
|
||||||
ServerKey string `json:"key"`
|
ServerKey string `json:"key" yaml:"key"`
|
||||||
TlsAuth string `json:"tlsAuth"`
|
TlsAuth string `json:"tlsAuth" yaml:"tlsAuth"`
|
||||||
Cipher string `json:"cipher"`
|
Cipher string `json:"cipher"`
|
||||||
Routes []string `json:"-"`
|
Routes []string `json:"-" yaml:"-"`
|
||||||
Renego int `json:"renego,omitempty"`
|
Renego int `json:"renego,omitempty" yaml:"renego,omitempty"`
|
||||||
Script string `json:"-"`
|
Script string `json:"-" yaml:"-"`
|
||||||
Breed []*OpenVPN `json:"breed,omitempty"`
|
Push []string `json:"push,omitempty" yaml:"push,omitempty"`
|
||||||
Push []string `json:"push,omitempty"`
|
Clients []*OpenVPNClient `json:"clients,omitempty" yaml:"clients,omitempty"`
|
||||||
Clients []*OpenVPNClient `json:"clients,omitempty"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type OpenVPNClient struct {
|
type OpenVPNClient struct {
|
||||||
@@ -109,7 +108,4 @@ func (o *OpenVPN) Correct(obj *OpenVPN) {
|
|||||||
value, _ := strconv.Atoi(port)
|
value, _ := strconv.Atoi(port)
|
||||||
o.Subnet = fmt.Sprintf("%s.%d.0/24", pool, value&0xff)
|
o.Subnet = fmt.Sprintf("%s.%d.0/24", pool, value&0xff)
|
||||||
}
|
}
|
||||||
for _, ch := range o.Breed {
|
|
||||||
ch.Correct(o)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
package config
|
package config
|
||||||
|
|
||||||
type Password struct {
|
type Password struct {
|
||||||
Network string `json:"network,omitempty"`
|
Network string `json:"network,omitempty" yaml:"network,omitempty"`
|
||||||
Username string `json:"username"`
|
Username string `json:"username"`
|
||||||
Password string `json:"password"`
|
Password string `json:"password"`
|
||||||
}
|
}
|
||||||
|
@@ -10,7 +10,7 @@ import (
|
|||||||
|
|
||||||
type Interface struct {
|
type Interface struct {
|
||||||
Name string `json:"name,omitempty"`
|
Name string `json:"name,omitempty"`
|
||||||
IPMtu int `json:"mtu"`
|
IPMtu int `json:"mtu" yaml:"mtu"`
|
||||||
Address string `json:"address,omitempty"`
|
Address string `json:"address,omitempty"`
|
||||||
Bridge string `json:"bridge,omitempty"`
|
Bridge string `json:"bridge,omitempty"`
|
||||||
Provider string `json:"provider,omitempty"`
|
Provider string `json:"provider,omitempty"`
|
||||||
@@ -31,14 +31,14 @@ type Point struct {
|
|||||||
Http *Http `json:"http,omitempty"`
|
Http *Http `json:"http,omitempty"`
|
||||||
Crypt *Crypt `json:"crypt,omitempty"`
|
Crypt *Crypt `json:"crypt,omitempty"`
|
||||||
PProf string `json:"pprof,omitempty"`
|
PProf string `json:"pprof,omitempty"`
|
||||||
RequestAddr bool `json:"requestAddr,omitempty"`
|
RequestAddr bool `json:"requestAddr,omitempty" yaml:"requestAddr,omitempty"`
|
||||||
ByPass bool `json:"bypass,omitempty"`
|
ByPass bool `json:"bypass,omitempty"`
|
||||||
SaveFile string `json:"-"`
|
SaveFile string `json:"-" yaml:"-"`
|
||||||
Queue *Queue `json:"queue,omitempty"`
|
Queue *Queue `json:"queue,omitempty"`
|
||||||
Terminal string `json:"-"`
|
Terminal string `json:"-" yaml:"-"`
|
||||||
Cert *Cert `json:"cert,omitempty"`
|
Cert *Cert `json:"cert,omitempty"`
|
||||||
StatusFile string `json:"status,omitempty"`
|
StatusFile string `json:"status,omitempty" yaml:"status"`
|
||||||
PidFile string `json:"pid,omitempty"`
|
PidFile string `json:"pid,omitempty" yaml:"pid,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func DefaultPoint() *Point {
|
func DefaultPoint() *Point {
|
||||||
|
@@ -11,7 +11,7 @@ type ShadowProxy struct {
|
|||||||
Cipher string `json:"cipher,omitempty"`
|
Cipher string `json:"cipher,omitempty"`
|
||||||
Password string `json:"password,omitempty"`
|
Password string `json:"password,omitempty"`
|
||||||
Plugin string `json:"plugin,omitempty"`
|
Plugin string `json:"plugin,omitempty"`
|
||||||
PluginOpts string `json:"pluginOpts,omitempty"`
|
PluginOpts string `json:"pluginOpts,omitempty" yaml:"pluginOpts,omitempty"`
|
||||||
Protocol string `json:"protocol,omitempty"`
|
Protocol string `json:"protocol,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
package config
|
package config
|
||||||
|
|
||||||
type IpSubnet struct {
|
type IpSubnet struct {
|
||||||
Network string `json:"network,omitempty"`
|
Network string `json:"network,omitempty" yaml:"network,omitempty"`
|
||||||
Start string `json:"start,omitempty"`
|
Start string `json:"start,omitempty"`
|
||||||
End string `json:"end,omitempty"`
|
End string `json:"end,omitempty"`
|
||||||
Netmask string `json:"netmask,omitempty"`
|
Netmask string `json:"netmask,omitempty"`
|
||||||
@@ -13,17 +13,17 @@ type MultiPath struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type PrefixRoute struct {
|
type PrefixRoute struct {
|
||||||
File string `json:"file,omitempty"`
|
File string `json:"-" yaml:"-"`
|
||||||
Network string `json:"network,omitempty"`
|
Network string `json:"network,omitempty" yaml:"network,omitempty"`
|
||||||
Prefix string `json:"prefix"`
|
Prefix string `json:"prefix"`
|
||||||
NextHop string `json:"nexthop"`
|
NextHop string `json:"nexthop"`
|
||||||
MultiPath []MultiPath `json:"multipath,omitempty"`
|
MultiPath []MultiPath `json:"multipath,omitempty"`
|
||||||
Metric int `json:"metric"`
|
Metric int `json:"metric"`
|
||||||
Mode string `json:"mode" yaml:"forwardMode"` // route or snat
|
Mode string `json:"forward,omitempty" yaml:"forward,omitempty"` // route or snat
|
||||||
}
|
}
|
||||||
|
|
||||||
type HostLease struct {
|
type HostLease struct {
|
||||||
Network string `json:"network"`
|
Network string `json:"network,omitempty" yaml:"network,omitempty"`
|
||||||
Hostname string `json:"hostname"`
|
Hostname string `json:"hostname"`
|
||||||
Address string `json:"address"`
|
Address string `json:"address"`
|
||||||
}
|
}
|
||||||
|
@@ -73,14 +73,14 @@ type Switch struct {
|
|||||||
Log Log `json:"log"`
|
Log Log `json:"log"`
|
||||||
Cert *Cert `json:"cert,omitempty"`
|
Cert *Cert `json:"cert,omitempty"`
|
||||||
Crypt *Crypt `json:"crypt,omitempty"`
|
Crypt *Crypt `json:"crypt,omitempty"`
|
||||||
Network []*Network `json:"network,omitempty" yaml:"networks"`
|
Network []*Network `json:"network,omitempty" yaml:"network"`
|
||||||
Acl []*ACL `json:"acl,omitempty" yaml:"acl,omitempty"`
|
Acl []*ACL `json:"acl,omitempty" yaml:"acl,omitempty"`
|
||||||
FireWall []FlowRule `json:"firewall,omitempty" yaml:"firewall,omitempty"`
|
FireWall []FlowRule `json:"firewall,omitempty" yaml:"firewall,omitempty"`
|
||||||
Inspect []string `json:"inspect,omitempty" yaml:"inspect,omitempty"`
|
Inspect []string `json:"inspect,omitempty" yaml:"inspect,omitempty"`
|
||||||
Queue Queue `json:"queue" yaml:"queue"`
|
Queue Queue `json:"queue" yaml:"queue"`
|
||||||
PassFile string `json:"password" yaml:"passwordFile"`
|
PassFile string `json:"password" yaml:"password"`
|
||||||
Ldap *LDAP `json:"ldap,omitempty" yaml:"ldap,omitempty"`
|
Ldap *LDAP `json:"ldap,omitempty" yaml:"ldap,omitempty"`
|
||||||
AddrPool string `json:"pool,omitempty"`
|
AddrPool string `json:"pool,omitempty" yaml:"pool,omitempty"`
|
||||||
ConfDir string `json:"-" yaml:"-"`
|
ConfDir string `json:"-" yaml:"-"`
|
||||||
TokenFile string `json:"-" yaml:"-"`
|
TokenFile string `json:"-" yaml:"-"`
|
||||||
}
|
}
|
||||||
@@ -164,6 +164,29 @@ func (s *Switch) Dir(elem ...string) string {
|
|||||||
return filepath.Join(args...)
|
return filepath.Join(args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *Switch) Format() {
|
||||||
|
for _, obj := range s.Network {
|
||||||
|
libol.Debug("Switch.Format %s", obj)
|
||||||
|
context := obj.Specifies
|
||||||
|
switch obj.Provider {
|
||||||
|
case "esp":
|
||||||
|
obj.Specifies = &ESPSpecifies{}
|
||||||
|
case "vxlan":
|
||||||
|
obj.Specifies = &VxLANSpecifies{}
|
||||||
|
case "fabric":
|
||||||
|
obj.Specifies = &FabricSpecifies{}
|
||||||
|
default:
|
||||||
|
obj.Specifies = nil
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if data, err := libol.Marshal(context, true); err == nil {
|
||||||
|
if err := libol.Unmarshal(obj.Specifies, data); err != nil {
|
||||||
|
libol.Warn("Switch.Format %s", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (s *Switch) LoadNetwork() {
|
func (s *Switch) LoadNetwork() {
|
||||||
files, err := filepath.Glob(s.Dir("network", "*.json"))
|
files, err := filepath.Glob(s.Dir("network", "*.json"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -181,22 +204,9 @@ func (s *Switch) LoadNetwork() {
|
|||||||
}
|
}
|
||||||
obj.LoadLink()
|
obj.LoadLink()
|
||||||
obj.LoadRoute()
|
obj.LoadRoute()
|
||||||
switch obj.Provider {
|
|
||||||
case "esp":
|
|
||||||
obj.Specifies = &ESPSpecifies{}
|
|
||||||
case "vxlan":
|
|
||||||
obj.Specifies = &VxLANSpecifies{}
|
|
||||||
case "fabric":
|
|
||||||
obj.Specifies = &FabricSpecifies{}
|
|
||||||
}
|
|
||||||
if obj.Specifies != nil {
|
|
||||||
if err := libol.UnmarshalLoad(obj, k); err != nil {
|
|
||||||
libol.Error("Switch.LoadNetwork %s", err)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
}
|
|
||||||
s.Network = append(s.Network, obj)
|
s.Network = append(s.Network, obj)
|
||||||
}
|
}
|
||||||
|
s.Format()
|
||||||
for _, obj := range s.Network {
|
for _, obj := range s.Network {
|
||||||
for _, link := range obj.Links {
|
for _, link := range obj.Links {
|
||||||
link.Default()
|
link.Default()
|
||||||
|
@@ -133,6 +133,13 @@ func LoadWithoutAnn(file string) ([]byte, error) {
|
|||||||
return ScanAnn(fp)
|
return ScanAnn(fp)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Unmarshal(v interface{}, contents []byte) error {
|
||||||
|
if err := json.Unmarshal(contents, v); err != nil {
|
||||||
|
return NewErr("%s", err)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func UnmarshalLoad(v interface{}, file string) error {
|
func UnmarshalLoad(v interface{}, file string) error {
|
||||||
if err := FileExist(file); err != nil {
|
if err := FileExist(file); err != nil {
|
||||||
return NewErr("%s %s", file, err)
|
return NewErr("%s %s", file, err)
|
||||||
@@ -141,10 +148,7 @@ func UnmarshalLoad(v interface{}, file string) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return NewErr("%s %s", file, err)
|
return NewErr("%s %s", file, err)
|
||||||
}
|
}
|
||||||
if err := json.Unmarshal(contents, v); err != nil {
|
return Unmarshal(v, contents)
|
||||||
return NewErr("%s", err)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func FunName(i interface{}) string {
|
func FunName(i interface{}) string {
|
||||||
|
@@ -25,7 +25,7 @@ type OpenLANWorker struct {
|
|||||||
startTime int64
|
startTime int64
|
||||||
links *Links
|
links *Links
|
||||||
bridge network.Bridger
|
bridge network.Bridger
|
||||||
openVPN []*OpenVPN
|
vpn *OpenVPN
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewOpenLANWorker(c *co.Network) *OpenLANWorker {
|
func NewOpenLANWorker(c *co.Network) *OpenLANWorker {
|
||||||
@@ -69,18 +69,10 @@ func (w *OpenLANWorker) Initialize() {
|
|||||||
}
|
}
|
||||||
w.bridge = network.NewBridger(brCfg.Provider, brCfg.Name, brCfg.IPMtu)
|
w.bridge = network.NewBridger(brCfg.Provider, brCfg.Name, brCfg.IPMtu)
|
||||||
vCfg := w.cfg.OpenVPN
|
vCfg := w.cfg.OpenVPN
|
||||||
if vCfg != nil {
|
if !(vCfg == nil) {
|
||||||
obj := NewOpenVPN(vCfg)
|
obj := NewOpenVPN(vCfg)
|
||||||
obj.Initialize()
|
obj.Initialize()
|
||||||
w.openVPN = append(w.openVPN, obj)
|
w.vpn = obj
|
||||||
for _, _vCfg := range vCfg.Breed {
|
|
||||||
if _vCfg == nil {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
obj := NewOpenVPN(_vCfg)
|
|
||||||
obj.Initialize()
|
|
||||||
w.openVPN = append(w.openVPN, obj)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
w.WorkerImpl.Initialize()
|
w.WorkerImpl.Initialize()
|
||||||
}
|
}
|
||||||
@@ -230,15 +222,15 @@ func (w *OpenLANWorker) connectPeer(cfg *co.Bridge) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (w *OpenLANWorker) Start(v api.Switcher) {
|
func (w *OpenLANWorker) Start(v api.Switcher) {
|
||||||
|
w.uuid = v.UUID()
|
||||||
|
w.startTime = time.Now().Unix()
|
||||||
w.out.Info("OpenLANWorker.Start")
|
w.out.Info("OpenLANWorker.Start")
|
||||||
w.UpBridge(w.cfg.Bridge)
|
w.UpBridge(w.cfg.Bridge)
|
||||||
w.uuid = v.UUID()
|
|
||||||
w.LoadLinks()
|
w.LoadLinks()
|
||||||
w.LoadRoutes()
|
w.LoadRoutes()
|
||||||
for _, vpn := range w.openVPN {
|
if !(w.vpn == nil) {
|
||||||
vpn.Start()
|
w.vpn.Start()
|
||||||
}
|
}
|
||||||
w.startTime = time.Now().Unix()
|
|
||||||
w.WorkerImpl.Start(v)
|
w.WorkerImpl.Start(v)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -266,8 +258,8 @@ func (w *OpenLANWorker) closePeer(cfg *co.Bridge) {
|
|||||||
func (w *OpenLANWorker) Stop() {
|
func (w *OpenLANWorker) Stop() {
|
||||||
w.out.Info("OpenLANWorker.Close")
|
w.out.Info("OpenLANWorker.Close")
|
||||||
w.WorkerImpl.Stop()
|
w.WorkerImpl.Stop()
|
||||||
for _, vpn := range w.openVPN {
|
if !(w.vpn == nil) {
|
||||||
vpn.Stop()
|
w.vpn.Stop()
|
||||||
}
|
}
|
||||||
w.UnLoadRoutes()
|
w.UnLoadRoutes()
|
||||||
w.UnLoadLinks()
|
w.UnLoadLinks()
|
||||||
|
@@ -212,9 +212,6 @@ func (v *Switch) preWorkerVPN(w Networker, vCfg *co.OpenVPN) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
vCfg.Routes = routes
|
vCfg.Routes = routes
|
||||||
for _, _vCfg := range vCfg.Breed {
|
|
||||||
v.preWorkerVPN(w, _vCfg)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *Switch) preWorker(w Networker) {
|
func (v *Switch) preWorker(w Networker) {
|
||||||
@@ -261,9 +258,6 @@ func (v *Switch) preNetVPN0(nCfg *co.Network, vCfg *co.OpenVPN) {
|
|||||||
v.enableFwd(devName, "", vCfg.Subnet, rt)
|
v.enableFwd(devName, "", vCfg.Subnet, rt)
|
||||||
v.enableMasq(devName, "", vCfg.Subnet, rt)
|
v.enableMasq(devName, "", vCfg.Subnet, rt)
|
||||||
}
|
}
|
||||||
for _, _vCfg := range vCfg.Breed {
|
|
||||||
v.preNetVPN0(nCfg, _vCfg)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *Switch) preNetVPN1(bridge, prefix string, vCfg *co.OpenVPN) {
|
func (v *Switch) preNetVPN1(bridge, prefix string, vCfg *co.OpenVPN) {
|
||||||
@@ -273,9 +267,6 @@ func (v *Switch) preNetVPN1(bridge, prefix string, vCfg *co.OpenVPN) {
|
|||||||
// Enable MASQUERADE, and allowed forward.
|
// Enable MASQUERADE, and allowed forward.
|
||||||
v.enableFwd("", bridge, vCfg.Subnet, prefix)
|
v.enableFwd("", bridge, vCfg.Subnet, prefix)
|
||||||
v.enableMasq("", bridge, vCfg.Subnet, prefix)
|
v.enableMasq("", bridge, vCfg.Subnet, prefix)
|
||||||
for _, _vCfg := range vCfg.Breed {
|
|
||||||
v.preNetVPN1(bridge, prefix, _vCfg)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *Switch) preNets() {
|
func (v *Switch) preNets() {
|
||||||
@@ -383,9 +374,6 @@ func (v *Switch) preAllowVPN(cfg *co.OpenVPN) {
|
|||||||
} else {
|
} else {
|
||||||
v.enablePort("tcp", port)
|
v.enablePort("tcp", port)
|
||||||
}
|
}
|
||||||
for _, _cfg := range cfg.Breed {
|
|
||||||
v.preAllowVPN(_cfg)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *Switch) preAllow() {
|
func (v *Switch) preAllow() {
|
||||||
@@ -445,7 +433,7 @@ func (v *Switch) Initialize() {
|
|||||||
BaseDN: ldap.BaseDN,
|
BaseDN: ldap.BaseDN,
|
||||||
Attr: ldap.Attribute,
|
Attr: ldap.Attribute,
|
||||||
Filter: ldap.Filter,
|
Filter: ldap.Filter,
|
||||||
EnableTls: ldap.EnableTls,
|
EnableTls: ldap.Tls,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
// Enable cert verify for access
|
// Enable cert verify for access
|
||||||
|
Reference in New Issue
Block a user