public async Task Disconnect(string id) { var vpnId = VpnId.Parse(id); var stats = await VpnCli.GetStats(); if (stats.Server == vpnId.Server) { await VpnCli.Disconnect(); } }
public async Task <IPAddress> GetIpAddress(string id) { var vpnId = VpnId.Parse(id); var stats = await VpnCli.GetStats(); if (stats.Server == vpnId.Server && IPAddress.TryParse(stats.Ip, out var ipaddress)) { return(ipaddress); } return(IPAddress.Any); }
public async Task <VpnStatus> GetStatus(string id) { var vpnId = VpnId.Parse(id); var stats = await VpnCli.GetStats(); if (stats.Server == vpnId.Server) { if (Enum.TryParse <VpnStatus>(stats.State, out var status)) { return(status); } return(VpnStatus.Unknown); } return(VpnStatus.Disconnected); }
public Task <Vpn[]> GetVpns() { var vpns = new List <Vpn>(); var profileFiles = Directory.GetFiles(PROFILES_PATH, "*.xml"); foreach (var file in profileFiles) { var document = XDocument.Load(file); var serverList = document.Root.Element(XName.Get("ServerList", XML_NAMESPACE)); var hosts = serverList.Elements(XName.Get("HostEntry", XML_NAMESPACE)); foreach (var entry in hosts) { var id = new VpnId { Name = entry.Element(XName.Get("HostName", XML_NAMESPACE)).Value, Server = entry.Element(XName.Get("HostAddress", XML_NAMESPACE)).Value }; vpns.Add(new Vpn(id.ToString(), id.Name)); } } return(Task.FromResult(vpns.ToArray())); }
public async Task Connect(string id) { var vpnId = VpnId.Parse(id); await VpnCli.Connect(vpnId.Name, $"CiscoAnyConnect\\{vpnId.Name}.txt"); }