/
rpc_set_threat_protection_lite.go
61 lines (51 loc) · 1.99 KB
/
rpc_set_threat_protection_lite.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
package daemon
import (
"context"
"log"
"github.com/NordSecurity/nordvpn-linux/config"
"github.com/NordSecurity/nordvpn-linux/daemon/pb"
"github.com/NordSecurity/nordvpn-linux/internal"
)
func (r *RPC) SetThreatProtectionLite(
ctx context.Context,
in *pb.SetThreatProtectionLiteRequest,
) (*pb.SetThreatProtectionLiteResponse, error) {
var cfg config.Config
if err := r.cm.Load(&cfg); err != nil {
log.Println(internal.ErrorPrefix, err)
}
threatProtectionLite := in.GetThreatProtectionLite()
if cfg.AutoConnectData.ThreatProtectionLite == threatProtectionLite {
return &pb.SetThreatProtectionLiteResponse{
Response: &pb.SetThreatProtectionLiteResponse_ErrorCode{ErrorCode: pb.SetErrorCode_ALREADY_SET},
}, nil
}
nameservers := r.nameservers.Get(threatProtectionLite, cfg.IPv6)
if err := r.netw.SetDNS(nameservers); err != nil {
log.Println(internal.ErrorPrefix, err)
return &pb.SetThreatProtectionLiteResponse{
Response: &pb.SetThreatProtectionLiteResponse_ErrorCode{ErrorCode: pb.SetErrorCode_CONFIG_ERROR},
}, nil
}
if err := r.cm.SaveWith(func(c config.Config) config.Config {
c.AutoConnectData.ThreatProtectionLite = threatProtectionLite
c.AutoConnectData.DNS = nil
return c
}); err != nil {
log.Println(internal.ErrorPrefix, err)
return &pb.SetThreatProtectionLiteResponse{
Response: &pb.SetThreatProtectionLiteResponse_ErrorCode{ErrorCode: pb.SetErrorCode_CONFIG_ERROR},
}, nil
}
r.events.Settings.ThreatProtectionLite.Publish(in.GetThreatProtectionLite())
if cfg.AutoConnectData.DNS != nil && threatProtectionLite {
return &pb.SetThreatProtectionLiteResponse{
Response: &pb.SetThreatProtectionLiteResponse_SetThreatProtectionLiteStatus{
SetThreatProtectionLiteStatus: pb.SetThreatProtectionLiteStatus_TPL_CONFIGURED_DNS_RESET},
}, nil
}
return &pb.SetThreatProtectionLiteResponse{
Response: &pb.SetThreatProtectionLiteResponse_SetThreatProtectionLiteStatus{
SetThreatProtectionLiteStatus: pb.SetThreatProtectionLiteStatus_TPL_CONFIGURED},
}, nil
}