Ejemplo n.º 1
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());
            }
        }
Ejemplo 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());
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Get url for update and start update
        /// </summary>
        /// <param name="tag_name"></param>
        /// <returns></returns>
        internal object WebUIGetUrlAndUpdate(string tag_name, string channel)
        {
            try
            {
                var client = new System.Net.WebClient();
                client.Headers.Add("Accept: application/vnd.github.v3+json");
                client.Headers.Add("User-Agent", "jmmserver");
                var response = client.DownloadString(new Uri("https://api.github.com/repos/japanesemediamanager/shokoserver-webui/releases/tags/" + tag_name));

                dynamic result = Newtonsoft.Json.JsonConvert.DeserializeObject(response);
                string  url    = "";
                foreach (dynamic obj in result.assets)
                {
                    if (obj.name == "latest.zip")
                    {
                        url = obj.browser_download_url;
                        break;
                    }
                }

                //check if tag was parsed corrently as it make the url
                if (url != "")
                {
                    return(WebUIUpdate(url, channel, tag_name));
                }
                else
                {
                    return(new APIMessage(204, "Content is missing"));
                }
            }
            catch
            {
                return(APIStatus.internalError());
            }
        }
Ejemplo n.º 4
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());
     }
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Return given setting
 /// </summary>
 /// <param name="setting">parameter you want to read</param>
 /// <returns></returns>
 private object GetSetting()
 {
     try
     {
         Settings setting = this.Bind();
         if (setting != null)
         {
             var config = ServerSettings.Get(setting.setting);
             if (config != null)
             {
                 Settings return_setting = new Settings();
                 return_setting.setting = setting.setting;
                 return_setting.value   = config;
                 return(return_setting);
             }
             else
             {
                 return(APIStatus.notFound404("Parameter not found."));
             }
         }
         else
         {
             return(APIStatus.badRequest("Setting was null."));
         }
     }
     catch
     {
         return(APIStatus.internalError());
     }
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Return body of current working settings.json - this could act as backup
 /// </summary>
 /// <returns></returns>
 private object ExportConfig()
 {
     try
     {
         return(ServerSettings.appSettings);
     }
     catch
     {
         return(APIStatus.internalError("Error while reading settings."));
     }
 }
Ejemplo n.º 7
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"));
            }
        }
Ejemplo n.º 8
0
 /// <summary>
 /// Read json file that is converted into string from .config file of jmmserver
 /// </summary>
 /// <returns></returns>
 private object GetWebUIConfig()
 {
     if (!String.IsNullOrEmpty(ServerSettings.WebUI_Settings))
     {
         try
         {
             WebUI_Settings settings = JsonConvert.DeserializeObject <WebUI_Settings>(ServerSettings.WebUI_Settings);
             return(settings);
         }
         catch
         {
             return(APIStatus.internalError("error while reading webui settings"));
         }
     }
     else
     {
         return(APIStatus.notFound404());
     }
 }
Ejemplo n.º 9
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."));
            }
        }
Ejemplo n.º 10
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());
            }
        }
Ejemplo n.º 11
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());
            }
        }
Ejemplo n.º 12
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"));
            }
        }