Exemplo n.º 1
0
        public JToken ToJson(IProtectionService ps, bool forDisplay = true)
        {
            var items  = GetItems(forDisplay);
            var jArray = new JArray();

            foreach (var item in items)
            {
                var jObject = new JObject();
                jObject["id"]   = item.ID;
                jObject["type"] = item.ItemType.ToString().ToLower();
                jObject["name"] = item.Name;
                switch (item.ItemType)
                {
                case ItemType.Recaptcha:
                    jObject["sitekey"] = ((RecaptchaItem)item).SiteKey;
                    jObject["version"] = ((RecaptchaItem)item).Version;
                    break;

                case ItemType.InputString:
                case ItemType.HiddenData:
                case ItemType.DisplayInfo:
                    var value = ((StringItem)item).Value;
                    if (string.Equals(item.Name, "password", StringComparison.InvariantCultureIgnoreCase))
                    {
                        if (string.IsNullOrEmpty(value))
                        {
                            value = string.Empty;
                        }
                        else if (forDisplay)
                        {
                            value = PASSWORD_REPLACEMENT;
                        }
                        else if (ps != null)
                        {
                            value = ps.Protect(value);
                        }
                    }
                    jObject["value"] = value;
                    break;

                case ItemType.InputBool:
                    jObject["value"] = ((BoolItem)item).Value;
                    break;

                case ItemType.DisplayImage:
                    string dataUri = DataUrlUtils.BytesToDataUrl(((ImageItem)item).Value, "image/jpeg");
                    jObject["value"] = dataUri;
                    break;
                }
                jArray.Add(jObject);
            }
            return(jArray);
        }
Exemplo n.º 2
0
        public Uri ConvertToProxyLink(Uri link, string serverUrl, string indexerId, string action = "dl", string file = "t.torrent")
        {
            if (link == null || (link.IsAbsoluteUri && link.Scheme == "magnet"))
            {
                return(link);
            }

            var    encryptedLink  = protectionService.Protect(link.ToString());
            var    encodedLink    = HttpServerUtility.UrlTokenEncode(Encoding.UTF8.GetBytes(encryptedLink));
            string urlEncodedFile = WebUtility.UrlEncode(file);
            var    proxyLink      = string.Format("{0}{1}/{2}/?jackett_apikey={3}&path={4}&file={5}", serverUrl, action, indexerId, config.APIKey, encodedLink, urlEncodedFile);

            return(new Uri(proxyLink));
        }
Exemplo n.º 3
0
        public Uri ConvertToProxyLink(Uri link, string serverUrl, string indexerId, string action = "dl", string file = "t")
        {
            if (link == null || (link.IsAbsoluteUri && link.Scheme == "magnet" && action != "bh")) // no need to convert a magnet link to a proxy link unless it's a blackhole link
            {
                return(link);
            }

            var encryptedLink  = _protectionService.Protect(link.ToString());
            var encodedLink    = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(encryptedLink));
            var urlEncodedFile = WebUtility.UrlEncode(file);
            var proxyLink      = string.Format("{0}{1}/{2}/?jackett_apikey={3}&path={4}&file={5}", serverUrl, action, indexerId, config.APIKey, encodedLink, urlEncodedFile);

            return(new Uri(proxyLink));
        }
        public Uri ConvertToProxyLink(Uri link, string serverUrl, int indexerId, string file = "t")
        {
            var urlBase = _configFileProvider.UrlBase;

            if (urlBase.IsNotNullOrWhiteSpace() && !urlBase.StartsWith("/"))
            {
                urlBase = "/" + urlBase;
            }

            var encryptedLink  = _protectionService.Protect(link.ToString());
            var encodedLink    = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(encryptedLink));
            var urlEncodedFile = WebUtility.UrlEncode(file);
            var proxyLink      = $"{serverUrl}{urlBase}/{indexerId}/download?apikey={_configFileProvider.ApiKey}&link={encodedLink}&file={urlEncodedFile}";

            return(new Uri(proxyLink));
        }
Exemplo n.º 5
0
            public JObject ToJson(IProtectionService protectionService = null)
            {
                var jObject = CreateJObject();

                if (string.Equals(Name, "password", StringComparison.InvariantCultureIgnoreCase))
                {
                    var password = Value;
                    if (string.IsNullOrEmpty(password))
                    {
                        password = string.Empty;
                    }
                    else if (protectionService != null)
                    {
                        password = protectionService.Protect(password);
                    }
                    jObject["value"] = password;
                }
                else
                {
                    jObject["value"] = Value;
                }
                return(jObject);
            }
Exemplo n.º 6
0
 public JToken ToJson(IProtectionService ps, bool forDisplay = true)
 {
     var items = GetItems(forDisplay);
     var jArray = new JArray();
     foreach (var item in items)
     {
         var jObject = new JObject();
         jObject["id"] = item.ID;
         jObject["type"] = item.ItemType.ToString().ToLower();
         jObject["name"] = item.Name;
         switch (item.ItemType)
         {
             case ItemType.Recaptcha:
                 jObject["sitekey"] = ((RecaptchaItem)item).SiteKey;
                 jObject["version"] = ((RecaptchaItem)item).Version;
                 break;
             case ItemType.InputString:
             case ItemType.HiddenData:
             case ItemType.DisplayInfo:
                 var value = ((StringItem)item).Value;
                 if (string.Equals(item.Name, "password", StringComparison.InvariantCultureIgnoreCase))
                 {
                     if (string.IsNullOrEmpty(value))
                         value = string.Empty;
                     else if (forDisplay)
                         value = PASSWORD_REPLACEMENT;
                     else if (ps != null)
                         value = ps.Protect(value);
                 }
                 jObject["value"] = value;
                 break;
             case ItemType.InputBool:
                 jObject["value"] = ((BoolItem)item).Value;
                 break;
             case ItemType.DisplayImage:
                 string dataUri = DataUrlUtils.BytesToDataUrl(((ImageItem)item).Value, "image/jpeg");
                 jObject["value"] = dataUri;
                 break;
         }
         jArray.Add(jObject);
     }
     return jArray;
 }
Exemplo n.º 7
0
        public JToken ToJson(IProtectionService ps, bool forDisplay = true)
        {
            var items  = GetItems(forDisplay);
            var jArray = new JArray();

            foreach (var item in items)
            {
                var jObject = new JObject
                {
                    ["id"]   = item.ID,
                    ["type"] = item.ItemType.ToString().ToLower(),
                    ["name"] = item.Name
                };
                switch (item.ItemType)
                {
                case ItemType.Recaptcha:
                    jObject["sitekey"] = ((RecaptchaItem)item).SiteKey;
                    jObject["version"] = ((RecaptchaItem)item).Version;
                    break;

                case ItemType.InputString:
                case ItemType.HiddenData:
                case ItemType.DisplayInfo:
                    var value = ((StringItem)item).Value;
                    if (string.Equals(item.Name, "password", StringComparison.InvariantCultureIgnoreCase))     // if we chagne this logic we've to change the MigratedFromDPAPI() logic too, #2114 is realted
                    {
                        if (string.IsNullOrEmpty(value))
                        {
                            value = string.Empty;
                        }
                        else if (forDisplay)
                        {
                            value = PASSWORD_REPLACEMENT;
                        }
                        else if (ps != null)
                        {
                            value = ps.Protect(value);
                        }
                    }
                    jObject["value"] = value;
                    break;

                case ItemType.InputBool:
                    jObject["value"] = ((BoolItem)item).Value;
                    break;

                case ItemType.InputCheckbox:
                    jObject["values"]  = new JArray(((CheckboxItem)item).Values);
                    jObject["options"] = new JObject();

                    foreach (var option in ((CheckboxItem)item).Options)
                    {
                        jObject["options"][option.Key] = option.Value;
                    }
                    break;

                case ItemType.InputSelect:
                    jObject["value"]   = ((SelectItem)item).Value;
                    jObject["options"] = new JObject();

                    foreach (var option in ((SelectItem)item).Options)
                    {
                        jObject["options"][option.Key] = option.Value;
                    }
                    break;

                case ItemType.DisplayImage:
                    var dataUri = DataUrlUtils.BytesToDataUrl(((ImageItem)item).Value, "image/jpeg");
                    jObject["value"] = dataUri;
                    break;
                }
                jArray.Add(jObject);
            }
            return(jArray);
        }
Exemplo n.º 8
0
        public JToken ToJson(IProtectionService ps, bool forDisplay = true)
        {
            var items  = GetItems(forDisplay);
            var jArray = new JArray();

            foreach (var item in items)
            {
                var jObject = new JObject
                {
                    ["id"]   = item.ID,
                    ["name"] = item.Name
                };
                switch (item)
                {
                case RecaptchaItem recaptcha:
                    jObject["sitekey"] = recaptcha.SiteKey;
                    jObject["version"] = recaptcha.Version;
                    break;

                case StringItem stringItem:
                    var value = stringItem.Value;
                    // if we change this logic we've to change the MigratedFromDPAPI() logic too, #2114 is realted
                    if (string.Equals(stringItem.Name, "password", StringComparison.InvariantCultureIgnoreCase))
                    {
                        if (string.IsNullOrEmpty(value))
                        {
                            value = string.Empty;
                        }
                        else if (forDisplay)
                        {
                            value = _PasswordReplacement;
                        }
                        else if (ps != null)
                        {
                            value = ps.Protect(value);
                        }
                    }

                    jObject["value"] = value;
                    break;

                case BoolItem boolItem:
                    jObject["value"] = boolItem.Value;
                    break;

                case CheckboxItem checkboxItem:
                    jObject["values"]  = new JArray(checkboxItem.Values);
                    jObject["options"] = new JObject();
                    foreach (var option in checkboxItem.Options)
                    {
                        jObject["options"][option.Key] = option.Value;
                    }
                    break;

                case SelectItem selectItem:
                    jObject["value"]   = selectItem.Value;
                    jObject["options"] = new JObject();
                    foreach (var option in selectItem.Options)
                    {
                        jObject["options"][option.Key] = option.Value;
                    }
                    break;

                case ImageItem imageItem:
                    var dataUri = DataUrlUtils.BytesToDataUrl(imageItem.Value, "image/jpeg");
                    jObject["value"] = dataUri;
                    break;
                }

                jArray.Add(jObject);
            }

            return(jArray);
        }