Пример #1
0
 /// <summary>Initialize LibVLC</summary>
 private void InitializeVlcPlayer()
 {
     vlcControl.VlcMediaPlayer.Manager.SetAppId("FoxIPTV", Application.ProductVersion, "");
     vlcControl.VlcMediaPlayer.Manager.SetUserAgent("Fox IPTV", "");
     vlcControl.VlcMediaPlayer.AudioVolume += (sender, args) => { TvCore.LogInfo($"[Audio] Volume: {vlcControl.Audio.Volume}"); };
     vlcControl.VlcMediaPlayer.Log         += (s, a) => { TvCore.LogInfo($"[Media] {a.Message}"); };
 }
Пример #2
0
        private static async Task Main()
        {
            TvCore.LogInfo("[.NET] Main(): Starting Windows Application...");

            Application.ApplicationExit += (sender, args) => TvCore.LogInfo("[.NET] Main(): Quitting Windows Application...");

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            TvCore.LogDebug("[.NET] Main(): Begin Auth Check");

            if (!await TvCore.CurrentService.IsAuthenticated())
            {
                TvCore.LogDebug("[.NET] Main(): Not Already Authenticated");

retry:

                var loginForm = new LoginForm();

                var dResult = loginForm.ShowDialog();

                if (dResult != DialogResult.OK)
                {
                    return;
                }

                TvCore.ServiceSelected = loginForm.servicesComboBox.SelectedIndex;

                TvCore.CurrentService.Data = new JObject();

                foreach (var field in TvCore.CurrentService.Fields)
                {
                    var fieldControl = loginForm.Controls.Find(field.Key, false).FirstOrDefault();

                    if (fieldControl is null)
                    {
                        continue;
                    }

                    TvCore.CurrentService.Data.Add(field.Key, fieldControl.Text);
                }

                TvCore.CurrentService.SaveAuthentication = loginForm.rememberMeCheckBox.Checked;

                if (!await TvCore.CurrentService.IsAuthenticated())
                {
                    TvCore.LogDebug("[.NET] Main(): Authentication details incorrect, service rejected them, retrying.");

                    goto retry;
                }
            }

            Application.Run(new TvForm());
        }
Пример #3
0
        public async Task <bool> IsAuthenticated()
        {
            TvCore.LogDebug($"[{Title}] IsAuthenticated() called...");

            var authDataFile = Path.Combine(TvCore.UserStoragePath, ServiceDataFilename);

            Uri domainUri = null;

            Uri authUrl;

            if (!File.Exists(authDataFile))
            {
                TvCore.LogDebug($"[{Title}] IsAuthenticated(): No authentication file found...");

                if (string.IsNullOrWhiteSpace(Username) || string.IsNullOrWhiteSpace(Password) || string.IsNullOrWhiteSpace(Services))
                {
                    TvCore.LogError($"[{Title}] IsAuthenticated(): Username/Password/ServiceURL is empty");

                    return(false);
                }

                if (!Uri.IsWellFormedUriString(Services, UriKind.Absolute))
                {
                    TvCore.LogError($"[{Title}] IsAuthenticated(): ServiceURL is not a well formed link");

                    return(false);
                }

                domainUri = new Uri(Services);

                authUrl = new Uri($"http://{domainUri.DnsSafeHost}/{string.Format(AuthenticationUrl, Username, Password)}");

                SaveAuthentication = true;
            }
            else
            {
                _authData = JsonConvert.DeserializeObject <AuthResponse>(File.ReadAllText(authDataFile).Unprotect());

                authUrl = new Uri(BuildUri(AuthenticationUrl));
            }

            TvCore.LogDebug($"[{Title}] IsAuthenticated(): Checking server authentication...");

            using (var wc = new WebClient())
            {
                wc.Headers.Add("user-agent", TvCore.ServiceUserAgentString);

                try
                {
                    var data = await wc.DownloadStringTaskAsync(authUrl);

                    _authData = JsonConvert.DeserializeObject <AuthResponse>(data);

                    _authData.Server.UserUrl  = domainUri?.DnsSafeHost ?? string.Empty;
                    _authData.Server.UserPort = domainUri?.Port ?? 0;

                    TvCore.LogDebug($"[{Title}] IsAuthenticated(): Checking server connection SUCCESS! IsAuthenticated: {_authData.User.Authenticated}");
                }
                catch (Exception ex)
                {
                    TvCore.LogError($"[{Title}] IsAuthenticated(): Checking server authentication ERROR: {ex.Message}");

                    return(false);
                }
            }

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

            if (_authData.User.Authenticated != 1)
            {
                return(false);
            }

            TvCore.LogDebug($"[{Title}] IsAuthenticated(): Server authentication SUCCESS! Server address: {_authData.Server.Url}");

            if (!SaveAuthentication)
            {
                TvCore.LogDebug($"[{Title}] IsAuthenticated(): Not Saving User Authentication...");

                TvCore.LogInfo($"[{Title}] Log-in successful");

                return(true);
            }

            TvCore.LogDebug($"[{Title}] IsAuthenticated(): Saving auth data...");

            File.WriteAllText(authDataFile, JsonConvert.SerializeObject(_authData).Protect());

            TvCore.LogInfo($"[{Title}] Log-in successful");

            return(true);
        }