@@ -56,6 +56,8 @@ var SuperdSocketPath = TEST_PREFIX + "/state/plugins/superd/socket"
56
56
// NOTE .Fire will dial, print to stdout/stderr if sprbus not started
57
57
var log = sprbus .NewLog ("log:api" )
58
58
59
+ var gSprbusClient * sprbus.Client
60
+
59
61
type InfluxConfig struct {
60
62
URL string
61
63
Org string
@@ -289,7 +291,7 @@ func getInfo(w http.ResponseWriter, r *http.Request) {
289
291
290
292
go func () {
291
293
defer stdin .Close ()
292
- io .WriteString (stdin , string (output ))
294
+ io .WriteString (stdin , strings . Replace ( string (output ), "0 user," , "0 users," , 1 ))
293
295
}()
294
296
295
297
data , err = cmd .Output ()
@@ -1162,7 +1164,7 @@ func saveDevicesJson(devices map[string]DeviceEntry) {
1162
1164
scrubbed_devices := convertDevicesPublic (devices )
1163
1165
savePublicDevicesJson (scrubbed_devices )
1164
1166
1165
- sprbus . Publish ("devices:save" , scrubbed_devices )
1167
+ SprbusPublish ("devices:save" , scrubbed_devices )
1166
1168
}
1167
1169
1168
1170
func getDevicesJson () map [string ]DeviceEntry {
@@ -1325,7 +1327,6 @@ func checkDeviceExpiries(devices map[string]DeviceEntry) {
1325
1327
lastTime , err := time .Parse ("2006-01-02 15:04:05.999999999 -0700 MST" , entry .DHCPLastTime )
1326
1328
if err != nil {
1327
1329
// Handle error
1328
- log .Printf ("Error parsing time: %v" , err )
1329
1330
return
1330
1331
}
1331
1332
@@ -1410,7 +1411,7 @@ func deleteDeviceLocked(devices map[string]DeviceEntry, identity string) {
1410
1411
}
1411
1412
1412
1413
//notify the bus
1413
- sprbus . Publish ("device:delete" , scrubDevice (val ))
1414
+ SprbusPublish ("device:delete" , scrubDevice (val ))
1414
1415
1415
1416
}
1416
1417
@@ -1648,7 +1649,7 @@ func updateDevice(w http.ResponseWriter, r *http.Request, dev DeviceEntry, ident
1648
1649
val .PSKEntry .Psk = "**"
1649
1650
}
1650
1651
1651
- sprbus . Publish ("device:update" , scrubDevice (val ))
1652
+ SprbusPublish ("device:update" , scrubDevice (val ))
1652
1653
1653
1654
w .Header ().Set ("Content-Type" , "application/json" )
1654
1655
json .NewEncoder (w ).Encode (val )
@@ -1706,7 +1707,7 @@ func updateDevice(w http.ResponseWriter, r *http.Request, dev DeviceEntry, ident
1706
1707
devices [identity ] = dev
1707
1708
saveDevicesJson (devices )
1708
1709
1709
- sprbus . Publish ("device:save" , scrubDevice (dev ))
1710
+ SprbusPublish ("device:save" , scrubDevice (dev ))
1710
1711
1711
1712
if pskModified {
1712
1713
//psks updated -- update hostapd
@@ -2152,7 +2153,7 @@ func reportPSKAuthFailure(w http.ResponseWriter, r *http.Request) {
2152
2153
return
2153
2154
}
2154
2155
2155
- sprbus . Publish ("wifi:auth:fail" , pskf )
2156
+ SprbusPublish ("wifi:auth:fail" , pskf )
2156
2157
2157
2158
if pskf .MAC == "" || (pskf .Type != "sae" && pskf .Type != "wpa" ) || (pskf .Reason != "noentry" && pskf .Reason != "mismatch" ) {
2158
2159
http .Error (w , "malformed data" , 400 )
@@ -2177,7 +2178,7 @@ func reportPSKAuthSuccess(w http.ResponseWriter, r *http.Request) {
2177
2178
return
2178
2179
}
2179
2180
2180
- sprbus . Publish ("wifi:auth:success" , pska )
2181
+ SprbusPublish ("wifi:auth:success" , pska )
2181
2182
2182
2183
if pska .Iface == "" || pska .Event != "AP-STA-CONNECTED" || pska .MAC == "" {
2183
2184
http .Error (w , "malformed data" , 400 )
@@ -2243,7 +2244,7 @@ func reportDisconnect(w http.ResponseWriter, r *http.Request) {
2243
2244
return
2244
2245
}
2245
2246
2246
- sprbus . Publish ("wifi:station:disconnect" , event )
2247
+ SprbusPublish ("wifi:station:disconnect" , event )
2247
2248
2248
2249
if event .Iface == "" || event .Event != "AP-STA-DISCONNECTED" || event .MAC == "" {
2249
2250
http .Error (w , "malformed data" , 400 )
@@ -2708,14 +2709,26 @@ func logRequest(handler http.Handler) http.Handler {
2708
2709
logs ["remoteaddr" ] = r .RemoteAddr
2709
2710
logs ["method" ] = r .Method
2710
2711
logs ["path" ] = r .URL .Path
2711
- sprbus . Publish ("log:www:access" , logs )
2712
+ SprbusPublish ("log:www:access" , logs )
2712
2713
2713
2714
handler .ServeHTTP (w , r )
2714
2715
})
2715
2716
}
2716
2717
2717
2718
var ServerEventSock = TEST_PREFIX + "/state/api/eventbus.sock"
2718
2719
2720
+ // SprbusPublish() using default socket, make sure bytes are json
2721
+ func SprbusPublish (topic string , bytes interface {}) error {
2722
+ value , err := json .Marshal (bytes )
2723
+
2724
+ if err != nil {
2725
+ return err
2726
+ }
2727
+
2728
+ _ , err = gSprbusClient .Publish (topic , string (value ))
2729
+ return err
2730
+ }
2731
+
2719
2732
func startEventBus () {
2720
2733
// make sure the client dont connect to the prev socket
2721
2734
os .Remove (ServerEventSock )
@@ -2730,6 +2743,16 @@ func startEventBus() {
2730
2743
// not reached
2731
2744
}
2732
2745
2746
+ func registerEventClient () {
2747
+ //tbd, sprbus needs an update to allow Publish from server
2748
+ // as pub/service are private and theres no method.
2749
+ client , err := sprbus .NewClient (ServerEventSock )
2750
+ if err != nil {
2751
+ log .Fatal (err )
2752
+ }
2753
+ gSprbusClient = client
2754
+ }
2755
+
2733
2756
func main () {
2734
2757
2735
2758
//update auth API
@@ -2743,6 +2766,7 @@ func main() {
2743
2766
2744
2767
// start eventbus
2745
2768
go startEventBus ()
2769
+ registerEventClient ()
2746
2770
2747
2771
unix_dhcpd_router := mux .NewRouter ().StrictSlash (true )
2748
2772
unix_wifid_router := mux .NewRouter ().StrictSlash (true )
@@ -2772,7 +2796,7 @@ func main() {
2772
2796
external_router_setup .HandleFunc ("/hostapd/restart" , restartWifi ).Methods ("PUT" )
2773
2797
external_router_setup .HandleFunc ("/hostapd/restart_setup" , restartSetupWifi ).Methods ("PUT" )
2774
2798
2775
- external_router_setup .HandleFunc ("/hostapd/calcChannel" , hostapdChannelCalc ).Methods ("PUT" )
2799
+ external_router_setup .HandleFunc ("/hostapd/calcChannel" , hostapdChannelCalc ).Methods ("PUT" )
2776
2800
external_router_setup .HandleFunc ("/link/config" , updateLinkConfig ).Methods ("PUT" )
2777
2801
2778
2802
external_router_setup .HandleFunc ("/iw/{command:.*}" , iwCommand ).Methods ("GET" )
0 commit comments