-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathservice.go
142 lines (119 loc) · 2.32 KB
/
service.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
package connman
import (
"fmt"
"github.com/godbus/dbus"
)
type IPv4Config struct {
Method string
Address string
Netmask string
Gateway string
}
type IPv6Config struct {
Method string
Address string
PrefixLength uint8
Gateway string
Privacy string
}
type EthConfig struct {
Method string
Interface string
Address string
MTU uint16
}
type ProxyConfig struct {
Method string
URL string
Servers []string
Excludes []string
}
type Provider struct {
Host string
Domain string
Name string
Type string
}
type Service struct {
Path dbus.ObjectPath
Name string
Type string
State string
Error string
Security []string
Strength uint8
Favorite bool
AutoConnect bool
Immutable bool
Roaming bool
Ethernet EthConfig
IPv4 IPv4Config
IPv4Configuration IPv4Config
IPv6 IPv6Config
IPv6Configuration IPv6Config
Proxy ProxyConfig
ProxyConfiguration ProxyConfig
Provider Provider
Domains []string
DomainsConfiguration []string
Nameservers []string
NameserversConfiguration []string
Timeservers []string
TimeserversConfiguration []string
}
func (s *Service) Connect(psk string) error {
db, err := DBusService(s.Path)
if err != nil {
return err
}
secure := false
for _, s := range s.Security {
if s == "psk" || s == "wep" {
secure = true
break
}
}
if !secure {
_, err = db.Call("Connect")
return err
}
ag := NewAgent(psk)
if ag == nil {
return fmt.Errorf("Could not spawn a new agent\n")
}
if err := RegisterAgent(ag); err != nil {
return err
}
defer func() {
UnregisterAgent(ag)
ag.Destroy()
}()
_, err = db.Call("Connect")
return err
}
func (s *Service) Disconnect() error {
db, err := DBusService(s.Path)
if err != nil {
return err
}
_, err = db.Call("Disconnect")
return err
}
func (s *Service) ApplyIP() error {
db, err := DBusService(s.Path)
if err != nil {
return err
}
arg, err := structToDict(s.IPv4Configuration)
if err != nil {
return err
}
return db.Set("IPv4.Configuration", arg)
}
func (s *Service) ApplyDNS() error {
db, err := DBusService(s.Path)
if err != nil {
return err
}
return db.Set("Nameservers.Configuration", s.NameserversConfiguration)
}