|
| 1 | +// |
| 2 | +// Daemon for IVPN Client Desktop |
| 3 | +// https://github.com/ivpn/desktop-app |
| 4 | +// |
| 5 | +// Created by Stelnykovych Alexandr. |
| 6 | +// Copyright (c) 2023 IVPN Limited. |
| 7 | +// |
| 8 | +// This file is part of the Daemon for IVPN Client Desktop. |
| 9 | +// |
| 10 | +// The Daemon for IVPN Client Desktop is free software: you can redistribute it and/or |
| 11 | +// modify it under the terms of the GNU General Public License as published by the Free |
| 12 | +// Software Foundation, either version 3 of the License, or (at your option) any later version. |
| 13 | +// |
| 14 | +// The Daemon for IVPN Client Desktop is distributed in the hope that it will be useful, |
| 15 | +// but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
| 16 | +// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
| 17 | +// details. |
| 18 | +// |
| 19 | +// You should have received a copy of the GNU General Public License |
| 20 | +// along with the Daemon for IVPN Client Desktop. If not, see <https://www.gnu.org/licenses/>. |
| 21 | +// |
| 22 | + |
| 23 | +package protocol |
| 24 | + |
| 25 | +import ( |
| 26 | + "runtime" |
| 27 | + "time" |
| 28 | + |
| 29 | + "github.com/ivpn/desktop-app/daemon/protocol/types" |
| 30 | + "github.com/ivpn/desktop-app/daemon/service/dns" |
| 31 | + "github.com/ivpn/desktop-app/daemon/service/platform" |
| 32 | + "github.com/ivpn/desktop-app/daemon/version" |
| 33 | + "github.com/ivpn/desktop-app/daemon/vpn" |
| 34 | +) |
| 35 | + |
| 36 | +func (p *Protocol) createSettingsResponse() *types.SettingsResp { |
| 37 | + prefs := p._service.Preferences() |
| 38 | + return &types.SettingsResp{ |
| 39 | + IsAutoconnectOnLaunch: prefs.IsAutoconnectOnLaunch, |
| 40 | + IsAutoconnectOnLaunchDaemon: prefs.IsAutoconnectOnLaunchDaemon, |
| 41 | + UserDefinedOvpnFile: platform.OpenvpnUserParamsFile(), |
| 42 | + UserPrefs: prefs.UserPrefs, |
| 43 | + WiFi: prefs.WiFiControl, |
| 44 | + IsLogging: prefs.IsLogging, |
| 45 | + AntiTracker: p._service.GetAntiTrackerStatus(), |
| 46 | + // TODO: implement the rest of daemon settings |
| 47 | + } |
| 48 | +} |
| 49 | + |
| 50 | +func (p *Protocol) createHelloResponse() *types.HelloResp { |
| 51 | + prefs := p._service.Preferences() |
| 52 | + |
| 53 | + disabledFuncs := p._service.GetDisabledFunctions() |
| 54 | + |
| 55 | + dnsOverHttps, dnsOverTls, err := dns.EncryptionAbilities() |
| 56 | + if err != nil { |
| 57 | + dnsOverHttps = false |
| 58 | + dnsOverTls = false |
| 59 | + log.Error(err) |
| 60 | + } |
| 61 | + |
| 62 | + // send back Hello message with account session info |
| 63 | + helloResp := types.HelloResp{ |
| 64 | + ParanoidMode: types.ParanoidModeStatus{IsEnabled: p._eaa.IsEnabled()}, |
| 65 | + Version: version.Version(), |
| 66 | + ProcessorArch: runtime.GOARCH, |
| 67 | + Session: types.CreateSessionResp(prefs.Session), |
| 68 | + Account: prefs.Account, |
| 69 | + SettingsSessionUUID: prefs.SettingsSessionUUID, |
| 70 | + DisabledFunctions: disabledFuncs, |
| 71 | + Dns: types.DnsAbilities{ |
| 72 | + CanUseDnsOverTls: dnsOverTls, |
| 73 | + CanUseDnsOverHttps: dnsOverHttps, |
| 74 | + }, |
| 75 | + DaemonSettings: *p.createSettingsResponse(), |
| 76 | + } |
| 77 | + return &helloResp |
| 78 | +} |
| 79 | + |
| 80 | +func (p *Protocol) createConnectedResponse(state vpn.StateInfo) *types.ConnectedResp { |
| 81 | + ipv6 := "" |
| 82 | + if state.ClientIPv6 != nil { |
| 83 | + ipv6 = state.ClientIPv6.String() |
| 84 | + } |
| 85 | + |
| 86 | + pausedTill := p._service.PausedTill() |
| 87 | + pausedTillStr := pausedTill.Format(time.RFC3339) |
| 88 | + if pausedTill.IsZero() { |
| 89 | + pausedTillStr = "" |
| 90 | + } |
| 91 | + |
| 92 | + manualDns := dns.GetLastManualDNS() |
| 93 | + |
| 94 | + ret := &types.ConnectedResp{ |
| 95 | + TimeSecFrom1970: state.Time, |
| 96 | + ClientIP: state.ClientIP.String(), |
| 97 | + ClientIPv6: ipv6, |
| 98 | + ServerIP: state.ServerIP.String(), |
| 99 | + ServerPort: state.ServerPort, |
| 100 | + VpnType: state.VpnType, |
| 101 | + ExitHostname: state.ExitHostname, |
| 102 | + Dns: types.DnsStatus{Dns: manualDns, AntiTrackerStatus: p._service.GetAntiTrackerStatus()}, |
| 103 | + IsTCP: state.IsTCP, |
| 104 | + Mtu: state.Mtu, |
| 105 | + V2RayProxy: state.V2RayProxy, |
| 106 | + Obfsproxy: state.Obfsproxy, |
| 107 | + IsPaused: p._service.IsPaused(), |
| 108 | + PausedTill: pausedTillStr, |
| 109 | + } |
| 110 | + |
| 111 | + return ret |
| 112 | +} |
0 commit comments