async protected override void OnAppearing()
        {
            Console.WriteLine("Connected Client APPEARING");

            // Restore values.  Ensures config != null.
            if (!PersistenceSerializer.TryFetchConfig(out config))
            {
                config = new PiHoleConfig();
            }

            // Hide Radio Buttons if there is no backup server set
            if (config.BackupUri == "")
            {
                radioButtons.IsVisible = false;
            }
            else
            {
                radioButtons.IsVisible = true;
            }

            // Auto Refresh if we have a primary URL
            if ((isBackupSelected && config.BackupApiKey != "") || config.PrimaryApiKey != "")
            {
                await DoRefresh(showError : false);
            }
        }
        async protected override void OnAppearing()
        {
            base.OnAppearing();
            Console.WriteLine("DASHBOARD APPEARING!");

            // Restore values. Ensures config != null
            if (!PersistenceSerializer.TryFetchConfig(out config))
            {
                config = new PiHoleConfig();
            }

            DisplayRightCachedValue();

            // Refresh
            OnPropertyChanged(nameof(config));

            // Hide Radio Buttons if there is no backup server set
            if (config.BackupUri == "")
            {
                radioButtons.IsVisible = false;
            }
            else
            {
                radioButtons.IsVisible = true;
            }

            if ((isBackupSelected && config.BackupUri != "") || config.PrimaryUri != "")
            {
                await DoRefresh(showError : false);
            }
        }
        public static void SerializeAndSaveConfig(PiHoleConfig configObj)
        {
            var configJson = JsonSerializer.Serialize <PiHoleConfig>(configObj);

            if (App.Current.Properties.ContainsKey("config"))
            {
                App.Current.Properties["config"] = configJson;
            }
            else
            {
                App.Current.Properties.Add("config", configJson);
            }
        }
        public static bool TryFetchConfig(out PiHoleConfig config)
        {
            config = null;

            if (App.Current.Properties.ContainsKey("config"))
            {
                var json = (string)App.Current.Properties["config"];
                config = JsonSerializer.Deserialize <PiHoleConfig>(json);

                if (config == null)
                {
                    return(false);
                }

                return(true);
            }

            return(false);
        }
Ejemplo n.º 5
0
        protected override void OnAppearing()
        {
            Console.WriteLine("Settings APPEARING");

            // Restore values. Ensures non null.
            if (!PersistenceSerializer.TryFetchConfig(out config))
            {
                config = new PiHoleConfig();
            }

            // Hide Radio Buttons if there is no backup server set
            if (config.BackupUri == "")
            {
                radioButtons.IsVisible = false;
            }
            else
            {
                radioButtons.IsVisible = true;
            }
        }
Ejemplo n.º 6
0
        public NewItemPage()
        {
            InitializeComponent();
            BindingContext = this;

            // Restore values
            if (!PersistenceSerializer.TryFetchConfig(out config))
            {
                config = new PiHoleConfig();
            }

            UriLabel.Text    = config.PrimaryUri;
            ApiKeyLabel.Text = config.PrimaryApiKey;

            // Refresh Button
            var refresh = new TapGestureRecognizer();

            refresh.Tapped += async(s, e) => await Github_Clicked();

            github.GestureRecognizers.Add(refresh);
        }
Ejemplo n.º 7
0
        // Generic disable Pihole Helper.
        public static async Task <bool> ModifyHelper(string operation, string duration, bool isBackupSelected, PiHoleConfig config)
        {
            try
            {
                var dest          = isBackupSelected ? config.BackupUri : config.PrimaryUri;
                var auth          = isBackupSelected ? config.BackupApiKey : config.PrimaryApiKey;
                var maybeDuration = duration != "" ? $"={duration}" : "";
                var uri           = $"{dest}/admin/api.php?{operation}{maybeDuration}&auth={auth}";

                HttpClient _client = new HttpClient();
                _client.Timeout = TimeSpan.FromSeconds(5);
                var res = await _client.GetAsync(uri);

                // Even on auth failures, return code is 200...
                if (res.IsSuccessStatusCode)
                {
                    var content = await res.Content.ReadAsStringAsync();

                    // If return contains "status", we know we were successful.
                    if (content.Contains("status"))
                    {
                        return(true);
                    }
                }

                // If we get here, there's an error (maybe incorrect API key)
                string errStr = "Error toggling Pi-hole. Please check your WEBPASSWORD. (err=1)";
                Console.WriteLine($"Error with uri:{uri} ERR: {errStr}");
                return(false);
            }
            catch (Exception err)
            {
                string errStr = "Could not connect to Pi-Hole service (err=2)";
                Console.WriteLine($"{errStr}: {err}");
                return(false);
            }
        }