Пример #1
0
        private static LaunchData GetLaunchDataFromPost(HttpRequest request)
        {
            var ld = new LaunchData();

            if (request.Form?.TryGetValue("file", out StringValues file) == true)
            {
                ld.File = file;
            }
            if (request.Form?.TryGetValue("password", out StringValues pass) == true)
            {
                ld.Password = pass;
            }
            if (request.Form?.TryGetValue("html", out StringValues html) == true)
            {
                ld.AddHtmlCode = html == "1";
            }
            if (request.Form?.TryGetValue("nocopy", out StringValues noCopy) == true)
            {
                ld.AddCopyProtection = noCopy == "1";
            }
            if (request.Form?.TryGetValue("multi", out StringValues multi) == true)
            {
                ld.RenderMultiTo = multi.ToString().ToInt();
            }
            T setProp <T>(TaskSettingProp prop, T defaultValue) => ReadPropFromForm(request, ld, "", prop, defaultValue);

            ld.Settings.ItemsCount            = TaskLoader.LoadItemsCount(setProp(TaskSettingProp.ItemsCount, ""));
            ld.Settings.Level                 = setProp(TaskSettingProp.Level, "").Split(',');
            ld.Settings.RandomOrder           = setProp(TaskSettingProp.RandomOrder, ld.Settings.RandomOrder);
            ld.Settings.Round                 = setProp(TaskSettingProp.Round, ld.Settings.Round);
            ld.Settings.SeparatePreviousPairs = setProp(TaskSettingProp.SeparatePreviousPairs, ld.Settings.SeparatePreviousPairs);
            ld.Settings.Seed = setProp(TaskSettingProp.Seed, ld.Settings.Seed);
            return(ld);
        }
Пример #2
0
        private static T ReadPropFromForm <T>(HttpRequest request, LaunchData ld, string propKeyPrefix, TaskSettingProp prop, T defaultValue)
        {
            string key = propKeyPrefix + TaskSetting.ShorPropNames[prop];

            if (request.Form.TryGetValue(key, out StringValues sVal))
            {
                if (!String.IsNullOrEmpty(sVal))
                {
                    var val = TaskExtensions.ConvertValue(defaultValue.GetType(), sVal, null);
                    if (val != null && val is T)
                    {
                        ld.Settings.SetProps |= prop;
                        return((T)val);
                    }
                }
            }
            return(defaultValue);
        }
Пример #3
0
        private static LaunchData GetLaunchDataFromMoodle(HttpRequest request)
        {
            // TODO: chceck OAuth hash
            var ld = new LaunchData();

            if (request.Form?.TryGetValue("custom_file", out StringValues file) == true)
            {
                ld.File = file;
            }
            if (request.Form?.TryGetValue("oauth_consumer_key", out StringValues pass) == true)
            {
                ld.Password = pass;
            }
            if (request.Form?.TryGetValue("custom_html", out StringValues html) == true)
            {
                ld.AddHtmlCode = html == "1";
            }
            if (request.Form?.TryGetValue("custom_nocopy", out StringValues noCopy) == true)
            {
                ld.AddCopyProtection = noCopy == "1";
            }
            if (request.Form?.TryGetValue("custom_multi", out StringValues multi) == true)
            {
                ld.RenderMultiTo = multi.ToString().ToInt();
            }
            T setProp <T>(TaskSettingProp prop, T defaultValue) => ReadPropFromForm(request, ld, "custom_", prop, defaultValue);

            ld.Settings.ItemsCount            = TaskLoader.LoadItemsCount(setProp(TaskSettingProp.ItemsCount, ""));
            ld.Settings.Level                 = setProp(TaskSettingProp.Level, "").Split(',');
            ld.Settings.RandomOrder           = setProp(TaskSettingProp.RandomOrder, ld.Settings.RandomOrder);
            ld.Settings.Round                 = setProp(TaskSettingProp.Round, ld.Settings.Round);
            ld.Settings.SeparatePreviousPairs = setProp(TaskSettingProp.SeparatePreviousPairs, ld.Settings.SeparatePreviousPairs);
            ld.Settings.Seed = setProp(TaskSettingProp.Seed, ld.Settings.Seed);
            if (request.Form?.TryGetValue("lis_person_contact_email_primary", out StringValues email) == true)
            {
                ld.Settings.Seed += email;
            }
            return(ld);
        }
Пример #4
0
        private static LaunchData GetLaunchDataFromGet(HttpRequest request)
        {
            var ld = new LaunchData();

            ld.File              = request.Query["file"];
            ld.Password          = request.Query["password"];
            ld.AddHtmlCode       = request.Query["html"] == "1";
            ld.AddCopyProtection = request.Query["nocopy"] == "1";
            ld.RenderMultiTo     = request.Query["multi"].ToString().ToInt();
            T setProp <T>(TaskSettingProp prop, T defaultValue)
            {
                string key  = TaskSetting.ShorPropNames[prop];
                string sVal = request.Query[key];

                if (String.IsNullOrEmpty(sVal))
                {
                    return(defaultValue);
                }
                var val = TaskExtensions.ConvertValue(defaultValue.GetType(), sVal, null);

                if (val == null || !(val is T))
                {
                    return(defaultValue);
                }
                ld.Settings.SetProps |= prop;
                return((T)val);
            }

            ld.Settings.ItemsCount            = TaskLoader.LoadItemsCount(setProp(TaskSettingProp.ItemsCount, ""));
            ld.Settings.Level                 = setProp(TaskSettingProp.Level, "").Split(',');
            ld.Settings.RandomOrder           = setProp(TaskSettingProp.RandomOrder, ld.Settings.RandomOrder);
            ld.Settings.Round                 = setProp(TaskSettingProp.Round, ld.Settings.Round);
            ld.Settings.SeparatePreviousPairs = setProp(TaskSettingProp.SeparatePreviousPairs, ld.Settings.SeparatePreviousPairs);
            ld.Settings.Seed = setProp(TaskSettingProp.Seed, ld.Settings.Seed);
            return(ld);
        }
Пример #5
0
        public LaunchData GetLaunchDataFromGetData(HttpRequest request)
        {
            try
            {
                string data64 = request.Query["data"];
                string hash   = request.Query["hash"];
                if (String.IsNullOrEmpty(data64) || String.IsNullOrEmpty(hash))
                {
                    return(null);
                }

                string data     = Encoding.UTF8.GetString(Convert.FromBase64String(data64));
                string hashCals = GetHash(data);

                if (hashCals != hash)
                {
                    return(null);
                }

                var prms = data.Split('&').Select(x => x.Split('=')).ToDictionary(k => k[0], v => v[1]);

                string timeOut = prms.GetValueOrDefault("timeout", "");
                if (!String.IsNullOrEmpty(timeOut))
                {
                    var limit = DateTime.Parse(timeOut);
                    if (DateTime.Now > limit)
                    {
                        return(null);
                    }
                }

                var ld = new LaunchData();

                T setProp <T>(TaskSettingProp prop, T defaultValue)
                {
                    string key  = TaskSetting.ShorPropNames[prop];
                    string sVal = "";

                    if (prms.ContainsKey(key))
                    {
                        sVal = prms[key];
                    }
                    if (String.IsNullOrEmpty(sVal))
                    {
                        return(defaultValue);
                    }
                    var val = TaskExtensions.ConvertValue(defaultValue.GetType(), sVal, null);

                    if (val == null || !(val is T))
                    {
                        return(defaultValue);
                    }
                    ld.Settings.SetProps |= prop;
                    return((T)val);
                }

                ld.Settings.ItemsCount            = TaskLoader.LoadItemsCount(setProp(TaskSettingProp.ItemsCount, ""));
                ld.Settings.Level                 = setProp(TaskSettingProp.Level, "").Split(',');
                ld.Settings.RandomOrder           = setProp(TaskSettingProp.RandomOrder, ld.Settings.RandomOrder);
                ld.Settings.Round                 = setProp(TaskSettingProp.Round, ld.Settings.Round);
                ld.Settings.SeparatePreviousPairs = setProp(TaskSettingProp.SeparatePreviousPairs, ld.Settings.SeparatePreviousPairs);
                ld.Settings.Seed = setProp(TaskSettingProp.Seed, ld.Settings.Seed);

                ld.Password          = prms.GetValueOrDefault("password", ld.File);
                ld.File              = prms.GetValueOrDefault("file", ld.File);
                ld.AddHtmlCode       = prms.GetValueOrDefault("html", ld.File) == "1";
                ld.AddCopyProtection = prms.GetValueOrDefault("nocopy", ld.File) == "1";

                return(ld);
            }
            catch
            {
                return(null);
            }
        }