Exemplo n.º 1
0
        /// <summary>
        /// Set Imagepath as default or custom
        /// </summary>
        /// <returns></returns>
        private object SetImagepath()
        {
            ImagePath imagepath = this.Bind();

            if (imagepath.isdefault)
            {
                ServerSettings.ImagesPath = ServerSettings.DefaultImagePath;
                return(APIStatus.statusOK());
            }
            else
            {
                if (!String.IsNullOrEmpty(imagepath.path) && imagepath.path != "")
                {
                    if (Directory.Exists(imagepath.path))
                    {
                        ServerSettings.ImagesPath = imagepath.path;
                        return(APIStatus.statusOK());
                    }
                    else
                    {
                        return(new APIMessage(404, "Directory Not Found on Host"));
                    }
                }
                else
                {
                    return(new APIMessage(400, "Path Missing"));
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Create user from Contract_JMMUser
        /// </summary>
        /// <returns></returns>
        private object CreateUser()
        {
            Request     request = this.Request;
            SVR_JMMUser _user   = (SVR_JMMUser)this.Context.CurrentUser;

            if (_user.IsAdmin == 1)
            {
                JMMUser user = this.Bind();
                user.Password       = Digest.Hash(user.Password);
                user.HideCategories = "";
                user.PlexUsers      = "";
                if (new ShokoServiceImplementation().SaveUser(user) == "")
                {
                    return(APIStatus.statusOK());
                }
                else
                {
                    return(APIStatus.internalError());
                }
            }
            else
            {
                return(APIStatus.adminNeeded());
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Create user from Contract_JMMUser
        /// </summary>
        /// <returns></returns>
        private object CreateUser()
        {
            Request request = this.Request;

            Entities.JMMUser _user = (Entities.JMMUser) this.Context.CurrentUser;
            if (_user.IsAdmin == 1)
            {
                Contract_JMMUser user = this.Bind();
                user.Password       = Digest.Hash(user.Password);
                user.HideCategories = new HashSet <string>(StringComparer.InvariantCultureIgnoreCase);
                user.PlexUsers      = new HashSet <string>(StringComparer.InvariantCultureIgnoreCase);
                if (new JMMServiceImplementation().SaveUser(user) == "")
                {
                    return(APIStatus.statusOK());
                }
                else
                {
                    return(APIStatus.internalError());
                }
            }
            else
            {
                return(APIStatus.adminNeeded());
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Upload Watched States to MAL
        /// </summary>
        /// <returns></returns>
        private object UploadToMAL()
        {
            CommandRequest_MALUploadStatusToMAL cmd = new CommandRequest_MALUploadStatusToMAL();

            cmd.Save();
            return(APIStatus.statusOK());
        }
Exemplo n.º 5
0
        /// <summary>
        /// Download Watched States from MAL
        /// </summary>
        /// <returns></returns>
        private object DownloadFromMAL()
        {
            CommandRequest_MALDownloadStatusFromMAL cmd = new CommandRequest_MALDownloadStatusFromMAL();

            cmd.Save();
            return(APIStatus.statusOK());
        }
Exemplo n.º 6
0
 /// <summary>
 /// Set given setting
 /// </summary>
 /// <param name="setting">parameter you want to write</param>
 /// <param name="value">value of the parameter</param>
 /// <returns></returns>
 private object SetSetting()
 {
     try
     {
         Settings setting = this.Bind();
         if (setting.setting != null & setting.value != null)
         {
             if (ServerSettings.Set(setting.setting, setting.value) == true)
             {
                 return(APIStatus.statusOK());
             }
             else
             {
                 return(APIStatus.badRequest("Setting not saved."));
             }
         }
         else
         {
             return(APIStatus.badRequest("Setting/Value was null."));
         }
     }
     catch
     {
         return(APIStatus.internalError());
     }
 }
Exemplo n.º 7
0
        /// <summary>
        /// Sync votes bettween Local and AniDB and only upload to MAL
        /// </summary>
        /// <returns></returns>
        private object SyncAniDBVotes()
        {
            //TODO APIv2: Command should be split into AniDb/MAL sepereate
            CommandRequest_SyncMyVotes cmdVotes = new CommandRequest_SyncMyVotes();

            cmdVotes.Save();
            return(APIStatus.statusOK());
        }
Exemplo n.º 8
0
 /// <summary>
 /// Test MAL Creditionals against MAL
 /// </summary>
 /// <returns></returns>
 private object TestMAL()
 {
     if (Providers.MyAnimeList.MALHelper.VerifyCredentials())
     {
         return(APIStatus.statusOK());
     }
     else
     {
         return(APIStatus.unauthorized());
     }
 }
Exemplo n.º 9
0
 /// <summary>
 /// Create AuthToken and RefreshToken from PIN
 /// </summary>
 /// <returns></returns>
 private object CreateTrakt()
 {
     if (Providers.TraktTV.TraktTVHelper.EnterTraktPIN(ServerSettings.Trakt_PIN) == "Success")
     {
         return(APIStatus.statusOK());
     }
     else
     {
         return(APIStatus.unauthorized());
     }
 }
Exemplo n.º 10
0
 /// <summary>
 /// Sync Trakt Collection
 /// </summary>
 /// <returns></returns>
 private object SyncTrakt()
 {
     if (ServerSettings.Trakt_IsEnabled && !string.IsNullOrEmpty(ServerSettings.Trakt_AuthToken))
     {
         CommandRequest_TraktSyncCollection cmd = new CommandRequest_TraktSyncCollection(true);
         cmd.Save();
         return(APIStatus.statusOK());
     }
     else
     {
         return(new APIMessage(204, "Trak is not enabled or you missing authtoken"));
     }
 }
Exemplo n.º 11
0
        /// <summary>
        /// Set Trakt PIN
        /// </summary>
        /// <returns></returns>
        private object SetTraktPIN()
        {
            Creditentials cred = this.Bind();

            if (!String.IsNullOrEmpty(cred.token) && cred.token != "")
            {
                ServerSettings.Trakt_PIN = cred.token;
                return(APIStatus.statusOK());
            }
            else
            {
                return(new APIMessage(400, "Token missing"));
            }
        }
Exemplo n.º 12
0
        /// <summary>
        /// Set JMMServer Port
        /// </summary>
        /// <returns></returns>
        private object SetPort()
        {
            Creditentials cred = this.Bind();

            if (cred.port != 0)
            {
                ServerSettings.JMMServerPort = cred.port.ToString();
                return(APIStatus.statusOK());
            }
            else
            {
                return(new APIMessage(400, "Port Missing"));
            }
        }
Exemplo n.º 13
0
        /// <summary>
        /// Set MAL account with login, password
        /// </summary>
        /// <returns></returns>
        private object SetMAL()
        {
            Creditentials cred = this.Bind();

            if (!String.IsNullOrEmpty(cred.login) && cred.login != "" && !String.IsNullOrEmpty(cred.password) && cred.password != "")
            {
                ServerSettings.MAL_Username = cred.login;
                ServerSettings.MAL_Password = cred.password;
                return(APIStatus.statusOK());
            }
            else
            {
                return(new APIMessage(400, "Login and Password missing"));
            }
        }
Exemplo n.º 14
0
        private object ImportConfig()
        {
            Contract_ServerSettings settings = this.Bind();
            string raw_settings = settings.ToJSON();
            string path         = Path.Combine(ServerSettings.ApplicationPath, "temp.json");

            File.WriteAllText(path, raw_settings, System.Text.Encoding.UTF8);
            try
            {
                ServerSettings.LoadSettingsFromFile(path, true);
                return(APIStatus.statusOK());
            }
            catch
            {
                return(APIStatus.internalError("Error while importing settings"));
            }
        }
Exemplo n.º 15
0
        /// <summary>
        /// Set AniDB account with login, password and client port
        /// </summary>
        /// <returns></returns>
        private object SetAniDB()
        {
            Creditentials cred = this.Bind();

            if (!String.IsNullOrEmpty(cred.login) && cred.login != "" && !String.IsNullOrEmpty(cred.password) && cred.password != "")
            {
                ServerSettings.AniDB_Username = cred.login;
                ServerSettings.AniDB_Password = cred.password;
                if (cred.port != 0)
                {
                    ServerSettings.AniDB_ClientPort = cred.port.ToString();
                }
                return(APIStatus.statusOK());
            }
            else
            {
                return(new APIMessage(400, "Login and Password missing"));
            }
        }
Exemplo n.º 16
0
        /// <summary>
        /// Set settings for LogRotator
        /// </summary>
        /// <returns></returns>
        private object SetRotateLogs()
        {
            Request     request = this.Request;
            SVR_JMMUser user    = (SVR_JMMUser)this.Context.CurrentUser;
            Logs        rotator = this.Bind();

            if (user.IsAdmin == 1)
            {
                ServerSettings.RotateLogs             = rotator.rotate;
                ServerSettings.RotateLogs_Zip         = rotator.zip;
                ServerSettings.RotateLogs_Delete      = rotator.delete;
                ServerSettings.RotateLogs_Delete_Days = rotator.days.ToString();

                return(APIStatus.statusOK());
            }
            else
            {
                return(APIStatus.adminNeeded());
            }
        }
Exemplo n.º 17
0
        public PlexWebhookAuthenticated() : base("/plex")
        {
            this.RequiresAuthentication();
            Get["/pin"] = o => CallPlexHelper(h => h.Authenticate());
            Get["/pin/authenticated"] = o => $"{CallPlexHelper(h => h.IsAuthenticated)}";
            Get["/token/invalidate"]  = o => CallPlexHelper(h =>
            {
                h.InvalidateToken();
                return(true);
            });
            Get["/sync", true] = async(x, ct) => await Task.Factory.StartNew(() =>
            {
                new CommandRequest_PlexSyncWatched((JMMUser)this.Context.CurrentUser).Save();
                return(APIStatus.statusOK());
            });

            Get["/sync/all", true] = async(x, ct) => await Task.Factory.StartNew(() =>
            {
                if (((JMMUser)this.Context.CurrentUser).IsAdmin != 1)
                {
                    return(APIStatus.adminNeeded());
                }
                ShokoServer.Instance.SyncPlex();
                return(APIStatus.statusOK());
            });

            Get["/sync/{id}", true] = async(x, ct) => await Task.Factory.StartNew(() =>
            {
                if (((JMMUser)this.Context.CurrentUser).IsAdmin != 1)
                {
                    return(APIStatus.adminNeeded());
                }
                JMMUser user = RepoFactory.JMMUser.GetByID(x.id);
                ShokoServer.Instance.SyncPlex();
                return(APIStatus.statusOK());
            });

#if DEBUG
            Get["/test/{id}"] = o => Response.AsJson(CallPlexHelper(h => h.GetPlexSeries((int)o.id)));
#endif
        }
Exemplo n.º 18
0
        /// <summary>
        /// Save webui settings as json converted into string inside .config file of jmmserver
        /// </summary>
        /// <returns></returns>
        private object SetWebUIConfig()
        {
            WebUI_Settings settings = this.Bind();

            if (settings.Valid())
            {
                try
                {
                    ServerSettings.WebUI_Settings = JsonConvert.SerializeObject(settings);
                    return(APIStatus.statusOK());
                }
                catch
                {
                    return(APIStatus.internalError("error at saving webui settings"));
                }
            }
            else
            {
                return(new APIMessage(400, "Config is not a Valid."));
            }
        }
Exemplo n.º 19
0
        /// <summary>
        /// Delete user from his ID
        /// </summary>
        /// <returns></returns>
        private object DeleteUser()
        {
            Request request = this.Request;
            JMMUser _user   = (JMMUser)this.Context.CurrentUser;

            if (_user.IsAdmin == 1)
            {
                JMMUser user = this.Bind();
                if (new JMMServiceImplementation().DeleteUser(user.JMMUserID) == "")
                {
                    return(APIStatus.statusOK());
                }
                else
                {
                    return(APIStatus.internalError());
                }
            }
            else
            {
                return(APIStatus.adminNeeded());
            }
        }
Exemplo n.º 20
0
        /// <summary>
        /// change given user (by uid) password
        /// </summary>
        /// <returns></returns>
        private object ChangePassword(int uid)
        {
            Request request = this.Request;

            Entities.JMMUser _user = (Entities.JMMUser) this.Context.CurrentUser;
            if (_user.IsAdmin == 1)
            {
                JMMUser user = this.Bind();
                if (new JMMServiceImplementation().ChangePassword(uid, user.Password) == "")
                {
                    return(APIStatus.statusOK());
                }
                else
                {
                    return(APIStatus.internalError());
                }
            }
            else
            {
                return(APIStatus.adminNeeded());
            }
        }
Exemplo n.º 21
0
        /// <summary>
        /// Test AniDB Creditentials
        /// </summary>
        /// <returns></returns>
        private object TestAniDB()
        {
            JMMService.AnidbProcessor.ForceLogout();
            JMMService.AnidbProcessor.CloseConnections();

            Thread.Sleep(1000);

            Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo(ServerSettings.Culture);

            JMMService.AnidbProcessor.Init(ServerSettings.AniDB_Username, ServerSettings.AniDB_Password,
                                           ServerSettings.AniDB_ServerAddress,
                                           ServerSettings.AniDB_ServerPort, ServerSettings.AniDB_ClientPort);

            if (JMMService.AnidbProcessor.Login())
            {
                JMMService.AnidbProcessor.ForceLogout();
                return(APIStatus.statusOK());
            }
            else
            {
                return(APIStatus.unauthorized());
            }
        }
Exemplo n.º 22
0
        /// <summary>
        /// Import config file that was sent to in API body - this act as import from backup
        /// </summary>
        /// <returns>APIStatus</returns>
        private object ImportConfig()
        {
            CL_ServerSettings settings     = this.Bind();
            string            raw_settings = settings.ToJSON();

            if (raw_settings.Length != new CL_ServerSettings().ToJSON().Length)
            {
                string path = Path.Combine(ServerSettings.ApplicationPath, "temp.json");
                File.WriteAllText(path, raw_settings, System.Text.Encoding.UTF8);
                try
                {
                    ServerSettings.LoadSettingsFromFile(path, true);
                    return(APIStatus.statusOK());
                }
                catch
                {
                    return(APIStatus.internalError("Error while importing settings"));
                }
            }
            else
            {
                return(APIStatus.badRequest("Empty settings are not allowed"));
            }
        }
Exemplo n.º 23
0
 /// <summary>
 /// Run LogRotator with current settings
 /// </summary>
 /// <returns></returns>
 private object StartRotateLogs()
 {
     MainWindow.logrotator.Start();
     return(APIStatus.statusOK());
 }
Exemplo n.º 24
0
 private object RunCloudImport()
 {
     MainWindow.RunImport();
     return(APIStatus.statusOK());
 }
Exemplo n.º 25
0
 /// <summary>
 /// Run LogRotator with current settings
 /// </summary>
 /// <returns></returns>
 private object StartRotateLogs()
 {
     ShokoServer.logrotator.Start();
     return(APIStatus.statusOK());
 }
Exemplo n.º 26
0
 /// <summary>
 /// Update all information from TvDB
 /// </summary>
 /// <returns></returns>
 private object UpdateAllTvDB()
 {
     Importer.RunImport_UpdateTvDB(false);
     return(APIStatus.statusOK());
 }
Exemplo n.º 27
0
 /// <summary>
 /// Update All information from Trakt
 /// </summary>
 /// <returns></returns>
 private object UpdateAllTrakt()
 {
     Providers.TraktTV.TraktTVHelper.UpdateAllInfo();
     return(APIStatus.statusOK());
 }
Exemplo n.º 28
0
        /// <summary>
        /// Update WebUI with version from given url
        /// </summary>
        /// <param name="url">direct link to version you want to install</param>
        /// <returns></returns>
        internal object WebUIUpdate(string url, string channel, string version)
        {
            //list all files from root /webui/ and all directories
            string[] files       = Directory.GetFiles("webui");
            string[] directories = Directory.GetDirectories("webui");

            try
            {
                //download latest version
                var client = new System.Net.WebClient();
                client.Headers.Add("User-Agent", "shokoserver");
                client.DownloadFile(url, "webui\\latest.zip");

                //create 'old' dictionary
                if (!Directory.Exists("webui\\old"))
                {
                    System.IO.Directory.CreateDirectory("webui\\old");
                }
                try
                {
                    //move all directories and files to 'old' folder as fallback recovery
                    foreach (string dir in directories)
                    {
                        if (Directory.Exists(dir) && dir != "webui\\old")
                        {
                            string n_dir = dir.Replace("webui", "webui\\old");
                            Directory.Move(dir, n_dir);
                        }
                    }
                    foreach (string file in files)
                    {
                        if (File.Exists(file))
                        {
                            string n_file = file.Replace("webui", "webui\\old");
                            File.Move(file, n_file);
                        }
                    }

                    try
                    {
                        //extract latest webui
                        System.IO.Compression.ZipFile.ExtractToDirectory("webui\\latest.zip", "webui");

                        //clean because we already have working updated webui
                        Directory.Delete("webui\\old", true);
                        File.Delete("webui\\latest.zip");

                        //save version type>version that was installed successful
                        if (File.Exists("webui\\index.ver"))
                        {
                            File.Delete("webui\\index.ver");
                        }
                        File.AppendAllText("webui\\index.ver", channel + ">" + version);

                        return(APIStatus.statusOK());
                    }
                    catch
                    {
                        //when extracting latest.zip failes
                        return(new APIMessage(405, "MethodNotAllowed"));
                    }
                }
                catch
                {
                    //when moving files to 'old' folder failed
                    return(new APIMessage(423, "Locked"));
                }
            }
            catch
            {
                //when download failed
                return(new APIMessage(499, "download failed"));
            }
        }
Exemplo n.º 29
0
 /// <summary>
 /// Sync AniDB List
 /// </summary>
 /// <returns></returns>
 private object SyncAniDBList()
 {
     MainWindow.SyncMyList();
     return(APIStatus.statusOK());
 }
Exemplo n.º 30
0
 /// <summary>
 /// Update all series infromation from AniDB
 /// </summary>
 /// <returns></returns>
 private object UpdateAllAniDB()
 {
     Importer.RunImport_UpdateAllAniDB();
     return(APIStatus.statusOK());
 }