Beispiel #1
0
        private async Task <Response> SavePlex()
        {
            var plexSettings = this.Bind <PlexSettings>();
            var valid        = this.Validate(plexSettings);

            if (!valid.IsValid)
            {
                return(Response.AsJson(valid.SendJsonError()));
            }

            //Lookup identifier
            var server = PlexApi.GetServer(plexSettings.PlexAuthToken);

            plexSettings.MachineIdentifier = server.Server.FirstOrDefault(x => x.AccessToken == plexSettings.PlexAuthToken)?.MachineIdentifier;

            var result = await PlexService.SaveSettingsAsync(plexSettings);

            return(Response.AsJson(result
                ? new JsonResponseModel {
                Result = true, Message = "Successfully Updated the Settings for Plex!"
            }
                : new JsonResponseModel {
                Result = false, Message = "Could not update the settings, take a look at the logs."
            }));
        }
Beispiel #2
0
        private Response RequestAuthToken()
        {
            var user = this.Bind <PlexAuth>();

            if (string.IsNullOrEmpty(user.username) || string.IsNullOrEmpty(user.password))
            {
                return(Response.AsJson(new { Result = false, Message = "Please provide a valid username and password" }));
            }

            var model = PlexApi.SignIn(user.username, user.password);

            if (model?.user == null)
            {
                return(Response.AsJson(new { Result = false, Message = "Incorrect username or password!" }));
            }

            var oldSettings = PlexService.GetSettings();

            if (oldSettings != null)
            {
                oldSettings.PlexAuthToken = model.user.authentication_token;
                PlexService.SaveSettings(oldSettings);
            }
            else
            {
                var newModel = new PlexSettings
                {
                    PlexAuthToken = model.user.authentication_token
                };
                PlexService.SaveSettings(newModel);
            }

            return(Response.AsJson(new { Result = true, AuthToken = model.user.authentication_token }));
        }
Beispiel #3
0
        private async Task <Response> SaveLandingPage()
        {
            var settings = this.Bind <LandingPageSettings>();

            Analytics.TrackEventAsync(Category.Admin, Action.Update, "Update Landing Page", Username, CookieHelper.GetAnalyticClientId(Cookies));
            var plexSettings = await PlexService.GetSettingsAsync();

            if (string.IsNullOrEmpty(plexSettings.Ip))
            {
                return(Response.AsJson(new JsonResponseModel {
                    Result = false, Message = "We cannot enable the landing page if Plex is not setup!"
                }));
            }

            if (settings.Enabled && settings.EnabledNoticeTime && string.IsNullOrEmpty(settings.NoticeMessage))
            {
                return(Response.AsJson(new JsonResponseModel {
                    Result = false, Message = "If you are going to enabled the notice, then we need a message!"
                }));
            }

            var result = await LandingSettings.SaveSettingsAsync(settings);

            return(Response.AsJson(result
                ? new JsonResponseModel {
                Result = true
            }
                : new JsonResponseModel {
                Result = false, Message = "Could not save to Db Please check the logs"
            }));
        }
        private Response SavePlex()
        {
            var plexSettings = this.Bind <PlexSettings>();
            var valid        = this.Validate(plexSettings);

            if (!valid.IsValid)
            {
                return(Response.AsJson(valid.SendJsonError()));
            }


            var result = PlexService.SaveSettings(plexSettings);

            return(Response.AsJson(result
                ? new JsonResponseModel {
                Result = true, Message = "Successfully Updated the Settings for Plex!"
            }
                : new JsonResponseModel {
                Result = false, Message = "Could not update the settings, take a look at the logs."
            }));
        }
Beispiel #5
0
        private Response GetUsers()
        {
            var settings = PlexService.GetSettings();

            var token = settings?.PlexAuthToken;

            if (token == null)
            {
                return(Response.AsJson(new { Result = true, Users = string.Empty }));
            }

            try
            {
                var users = PlexApi.GetUsers(token);
                if (users == null)
                {
                    return(Response.AsJson(string.Empty));
                }
                if (users.User == null || users.User?.Length == 0)
                {
                    return(Response.AsJson(string.Empty));
                }

                var usernames = users.User.Select(x => x.Title);
                return(Response.AsJson(new { Result = true, Users = usernames }));
            }
            catch (Exception ex)
            {
                Log.Error(ex);
                if (ex is WebException || ex is ApiRequestException)
                {
                    return(Response.AsJson(new { Result = false, Message = "Could not load the user list! We have connectivity problems connecting to Plex, Please ensure we can access Plex.Tv, The error has been logged." }));
                }

                return(Response.AsJson(new { Result = false, Message = ex.Message }));
            }
        }
        private Negotiator Plex()
        {
            var settings = PlexService.GetSettings();

            return(View["Plex", settings]);
        }
Beispiel #7
0
        // GET: Layout
        public ActionResult ApplicationMenu()
        {
            var model = new List <LayoutModel>();

            foreach (var app in Enum.GetValues(typeof(Applications)))
            {
                switch ((Applications)app)
                {
                case Applications.SabNZBD:
                    var sabService = SabService.GetSettings();
                    if (sabService.Enabled)
                    {
                        model.Add(
                            new LayoutModel {
                            Name = "SabNzbd", Url = "/SabNzbd"
                        });
                    }
                    break;

                case Applications.Sickbeard: break;

                case Applications.CouchPotato:
                    var cpService = CpService.GetSettings();
                    if (cpService.Enabled)
                    {
                        model.Add(
                            new LayoutModel {
                            Name = "CouchPotato", Url = "/CouchPotato"
                        });
                    }
                    break;

                case Applications.Kodi: break;

                case Applications.Sonarr:
                    var sonarrService = SonarrService.GetSettings();
                    if (sonarrService.Enabled)
                    {
                        model.Add(
                            new LayoutModel {
                            Name = "Sonarr", Url = "/Sonarr"
                        });
                    }
                    break;

                case Applications.Plex:
                    var plexService = PlexService.GetSettings();
                    if (plexService.Enabled)
                    {
                        model.Add(
                            new LayoutModel {
                            Name = "Plex", Url = "/Plex"
                        });
                    }
                    break;

                case Applications.NzbGet:
                    var nzbgetService = NzbService.GetSettings();
                    if (nzbgetService.Enabled)
                    {
                        model.Add(
                            new LayoutModel {
                            Name = "NzbGet", Url = "/NzbGet"
                        });
                    }
                    break;

                case Applications.Headphones: break;

                default:
                    throw new ArgumentOutOfRangeException("application");
                }
            }

            return(PartialView("NavBarItems", model));
        }