Beispiel #1
0
        public async Task <IActionResult> ChangeWanIp()
        {
            GatewayHelper.ChangeWanIp();
            if (ConfigHelper.Instance.HitWhenIpChanges.HasValue())
            {
                await _updateEndpointClient.GetAsync(ConfigHelper.Instance.HitWhenIpChanges);
            }

            _lastKnownIp = GatewayHelper.GetCurrentIp();
            return(RedirectToAction(nameof(Index)));
        }
Beispiel #2
0
        public async Task <IActionResult> UpdateEndpointIfChanged()
        {
            if (ConfigHelper.Instance.HitWhenIpChanges.IsNullOrEmpty())
            {
                return(new EmptyResult());
            }

            var currentIp = GatewayHelper.GetCurrentIp();

            if (currentIp == _lastKnownIp)
            {
                return(new EmptyResult());
            }

            _lastKnownIp = currentIp;
            var response = await _updateEndpointClient.GetAsync(ConfigHelper.Instance.HitWhenIpChanges);

            var content = await response.Content.ReadAsStringAsync();

            return(Content(content));
        }
Beispiel #3
0
        public IActionResult Index()
        {
            var status  = GatewayHelper.GetRedirectedIps();
            var builder = ImmutableArray.CreateBuilder <DeviceWitStatus>();

            foreach (var device in ConfigHelper.Instance.Devices.OrderBy(d => d.Name))
            {
                builder.Add(new DeviceWitStatus(device, status.ContainsKey(device.Ip)));
            }

            var currentIp = Request.HttpContext.Connection.RemoteIpAddress.ToString();

            if (!currentIp.Contains(":"))
            {
                builder.Add(new DeviceWitStatus(new Device($"This device ({currentIp})", currentIp),
                                                status.ContainsKey(currentIp)));
            }

            var model = new IndexModel(builder.ToImmutable(), GatewayHelper.GetCurrentIp());

            return(View(model));
        }