예제 #1
0
파일: Startup.cs 프로젝트: stijni/ruckzuck
        private void OnStartup()
        {
            Console.WriteLine("loading RZ.Software-Providers:");
            Plugins.loadPlugins(Path.Combine(Path.Combine(Env.ContentRootPath, "wwwroot"), "plugins"));

            Console.Write("loading SW-Catalog...");
            Base.GetCatalog("", true);
            Console.WriteLine(" done.");
        }
예제 #2
0
            public void ConfigureServices(IFunctionsHostBuilder builder)
            {
                _loggerFactory = new LoggerFactory();
                var logger = _loggerFactory.CreateLogger("Startup");

                //logger.LogInformation("Got Here in Startup");

                if (Base._cache == null)
                {
                    Base._cache = new MemoryCache(new MemoryCacheOptions());
                }

                var    binDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
                string ResourcePath = Path.GetFullPath(Path.Combine(binDirectory, ".."));

                Console.WriteLine("loading RZ.Software-Providers:");
                Plugins.loadPlugins(Path.Combine(Path.Combine(ResourcePath, "wwwroot"), "plugins"));

                Console.Write("loading SW-Catalog...");
                Base.GetCatalog("", true);
                Console.WriteLine(" done.");
            }
예제 #3
0
        public static async Task <IActionResult> GetCatalog([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req, ILogger log)
        {
            string customerid = req.Query["customerid"];

            customerid = customerid ?? "";
            string snocache = req.Query["cnocache"];
            bool   nocache  = false;

            if ((snocache ?? "").ToLower() == "true")
            {
                nocache = true;
            }

            string ClientIP = req.HttpContext.Connection.RemoteIpAddress.ToString();


            //if (!Base.ValidateIP(ClientIP))
            //{
            //    if (Environment.GetEnvironmentVariable("EnforceGetURL") == "true")
            //        return new OkObjectResult("[]");
            //}

            if (string.IsNullOrEmpty(Base.localURL))
            {
                Base.localURL = req.GetEncodedUrl().ToLower().Split("/rest/v2/getcatalog")[0];
            }

            if (customerid.ToLower() == "--new--")
            {
                JArray oRes    = Base.GetCatalog("", true);
                JArray jsorted = new JArray(oRes.OrderByDescending(x => (DateTimeOffset?)x["ModifyDate"]));
                JArray jTop    = JArray.FromObject(jsorted.Take(30));
                return(new OkObjectResult(jTop));
            }

            if (customerid.ToLower() == "--old--")
            {
                Base.ResetMemoryCache();
                JArray oRes    = Base.GetCatalog("");
                JArray jsorted = new JArray(oRes.OrderBy(x => (DateTimeOffset?)x["Timestamp"]));
                JArray jTop    = JArray.FromObject(jsorted.Take(30));
                return(new OkObjectResult(jTop));
            }

            Base.WriteLog($"Get Catalog", ClientIP, 1200, customerid);
            log.LogInformation("GetCatalog from ClientIP: " + ClientIP + " CustomerID: " + customerid);

            JArray aRes = Base.GetCatalog(customerid, nocache);

            //Cleanup
            foreach (JObject jObj in aRes)
            {
                //remove quality
                if (jObj["Quality"] != null)
                {
                    jObj.Remove("Quality");
                }

                //remove Image
                if (jObj["IconId"] != null)
                {
                    jObj.Remove("IconId");
                }

                //remove Image
                if (jObj["Image"] != null)
                {
                    jObj.Remove("Image");
                }
            }

            return(new OkObjectResult(aRes));
        }
예제 #4
0
        public static async Task <IActionResult> GetSoftwares([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req, ILogger log)
        {
            string customerid = req.Query["customerid"];

            customerid = customerid ?? "";
            string shortname = req.Query["shortname"];

            shortname = shortname ?? "";
            string name = req.Query["name"];

            name = name ?? "";
            string ver = req.Query["ver"];

            ver = ver ?? "";
            string man = req.Query["man"];

            man = man ?? "";

            bool image = false;

            bool.TryParse(req.Query["image"], out image);

            string ClientIP = req.HttpContext.Connection.RemoteIpAddress.ToString();


            //if (ClientIP == "88.157.220.241" && string.IsNullOrEmpty(customerid))
            //    return Content("[]");

            if (string.IsNullOrEmpty(Base.localURL))
            {
                Base.localURL = req.GetEncodedUrl().ToLower().Split("/rest/v2/getsoftwares")[0];
                Base.WriteLog($"Set localURL: {Base.localURL}", ClientIP, 1000, customerid);
            }



            JArray jSW;

            if (!string.IsNullOrEmpty(shortname))
            {
                if (!Base.ValidateIP(ClientIP))
                {
                    if (Environment.GetEnvironmentVariable("EnforceGetURL") == "true")
                    {
                        return(new OkObjectResult("[]"));
                    }
                }
                else
                {
                    Base.WriteLog($"Get Definition for: {shortname}", ClientIP, 1500, customerid);
                }

                jSW = Base.GetSoftwares(shortname, customerid);
            }
            else
            {
                if (!Base.ValidateIP(ClientIP))
                {
                    if (Environment.GetEnvironmentVariable("EnforceGetURL") == "true")
                    {
                        return(new OkObjectResult("[]"));
                    }
                }
                else
                {
                    Base.WriteLog($"Get Definition for: {name}", ClientIP, 1500, customerid);
                }

                jSW = Base.GetSoftwares(name, ver, man, customerid);
            }
            //Cleanup
            foreach (JObject jObj in jSW)
            {
                try
                {
                    if (jObj["IconHash"] != null)
                    {
                        //Get SWId from Catalog if missing
                        if (string.IsNullOrEmpty(jObj["IconHash"].ToString()))
                        {
                            try
                            {
                                jObj["IconHash"] = Base.GetCatalog().SelectToken("$..[?(@.ShortName =='" + jObj["ShortName"] + "')]")["IconHash"];
                            }
                            catch { }
                        }
                    }

                    //generate IconURL if missing
                    if (jObj["IconURL"] == null)
                    {
                        if (jObj["IconHash"] != null)
                        {
                            jObj.Add("IconURL", Base.localURL + "/rest/v2/geticon?iconhash=" + jObj["IconHash"].ToString());
                        }
                    }
                    else
                    {
                        if (string.IsNullOrEmpty(jObj["IconURL"].ToString()) && jObj["IconHash"] != null)
                        {
                            //switch to cdn for icons
                            string sBase = Base.localURL;
                            if (sBase.ToLower().StartsWith("https://ruckzuck.tools"))
                            {
                                sBase = "https://cdn.ruckzuck.tools";
                            }

                            jObj["IconURL"] = Base.localURL + "/rest/v2/geticon?iconhash=" + jObj["IconHash"].ToString();
                        }
                    }

                    if (jObj["IconId"] != null)
                    {
                        jObj.Remove("IconId"); //No IconID on V2!! only SWId
                    }

                    //rename Shortname to ShortName on V2
                    if (jObj["Shortname"] != null)
                    {
                        string sShortName = jObj["Shortname"].ToString();

                        jObj.Remove("Shortname");

                        if (jObj["ShortName"] == null)
                        {
                            jObj.Add("ShortName", sShortName);
                        }
                    }

                    if (jObj["SWId"] != null)
                    {
                        //Get SWId from Catalog if missing
                        if (jObj["SWId"].ToString() == "0")
                        {
                            try
                            {
                                jObj["SWId"] = Base.GetCatalog().SelectToken("$..[?(@.ShortName =='" + jObj["ShortName"] + "')]")["SWId"];
                            }
                            catch { }
                        }
                    }

                    //remove Image if not requested to reduce size
                    if (!image)
                    {
                        try
                        {
                            if (jObj["Image"] != null)
                            {
                                jObj.Remove("Image");
                            }
                        }
                        catch { }
                    }

                    //remove Author as there are no RuckZuck users anymore
                    if (jObj["Author"] != null)
                    {
                        jObj.Remove("Author");
                    }
                }
                catch { }
            }

            if (jSW != null)
            {
                return(new OkObjectResult(jSW));
            }
            else
            {
                return(new OkObjectResult("{[]}")); //return empty json array
            }
        }
예제 #5
0
            public void ConfigureServices(IFunctionsHostBuilder builder, IConfiguration config)
            {
                _loggerFactory = new LoggerFactory();
                var logger = _loggerFactory.CreateLogger("Startup");

                if (Base._cache == null)
                {
                    Base._cache = new MemoryCache(new MemoryCacheOptions());
                }

                try
                {
                    //Get Settings from KeyVault
                    if (string.IsNullOrEmpty(Environment.GetEnvironmentVariable("SAS:Cat")))
                    {
                        Environment.SetEnvironmentVariable("SAS:Cat", _keyVaultClient.GetSecretAsync(vaultBaseUrl: config["VaultUri"], secretName: "cat").Result.Value);
                    }
                    if (string.IsNullOrEmpty(Environment.GetEnvironmentVariable("SAS:Cont")))
                    {
                        Environment.SetEnvironmentVariable("SAS:Cont", _keyVaultClient.GetSecretAsync(vaultBaseUrl: config["VaultUri"], secretName: "cont").Result.Value);
                    }
                    if (string.IsNullOrEmpty(Environment.GetEnvironmentVariable("SAS:Icon")))
                    {
                        Environment.SetEnvironmentVariable("SAS:Icon", _keyVaultClient.GetSecretAsync(vaultBaseUrl: config["VaultUri"], secretName: "icon").Result.Value);
                    }
                    if (string.IsNullOrEmpty(Environment.GetEnvironmentVariable("SAS:Repo")))
                    {
                        Environment.SetEnvironmentVariable("SAS:Repo", _keyVaultClient.GetSecretAsync(vaultBaseUrl: config["VaultUri"], secretName: "repo").Result.Value);
                    }
                    if (string.IsNullOrEmpty(Environment.GetEnvironmentVariable("SAS:Wait")))
                    {
                        Environment.SetEnvironmentVariable("SAS:Wait", _keyVaultClient.GetSecretAsync(vaultBaseUrl: config["VaultUri"], secretName: "wait").Result.Value);
                    }
                    if (string.IsNullOrEmpty(Environment.GetEnvironmentVariable("SAS:Look")))
                    {
                        Environment.SetEnvironmentVariable("SAS:Look", _keyVaultClient.GetSecretAsync(vaultBaseUrl: config["VaultUri"], secretName: "look").Result.Value);
                    }
                    if (string.IsNullOrEmpty(Environment.GetEnvironmentVariable("SAS:Map")))
                    {
                        Environment.SetEnvironmentVariable("SAS:Map", _keyVaultClient.GetSecretAsync(vaultBaseUrl: config["VaultUri"], secretName: "map").Result.Value);
                    }
                    if (string.IsNullOrEmpty(Environment.GetEnvironmentVariable("SAS:Feedback")))
                    {
                        Environment.SetEnvironmentVariable("SAS:Feedback", _keyVaultClient.GetSecretAsync(vaultBaseUrl: config["VaultUri"], secretName: "feedback").Result.Value);
                    }
                    if (string.IsNullOrEmpty(Environment.GetEnvironmentVariable("SAS:Dlq")))
                    {
                        Environment.SetEnvironmentVariable("SAS:Dlq", _keyVaultClient.GetSecretAsync(vaultBaseUrl: config["VaultUri"], secretName: "dlq").Result.Value);
                    }
                    if (string.IsNullOrEmpty(Environment.GetEnvironmentVariable("SAS:Suq")))
                    {
                        Environment.SetEnvironmentVariable("SAS:Suq", _keyVaultClient.GetSecretAsync(vaultBaseUrl: config["VaultUri"], secretName: "suq").Result.Value);
                    }
                    if (string.IsNullOrEmpty(Environment.GetEnvironmentVariable("SAS:Faq")))
                    {
                        Environment.SetEnvironmentVariable("SAS:Faq", _keyVaultClient.GetSecretAsync(vaultBaseUrl: config["VaultUri"], secretName: "faq").Result.Value);
                    }
                    if (string.IsNullOrEmpty(Environment.GetEnvironmentVariable("SAS:Swq")))
                    {
                        Environment.SetEnvironmentVariable("SAS:Swq", _keyVaultClient.GetSecretAsync(vaultBaseUrl: config["VaultUri"], secretName: "swq").Result.Value);
                    }
                    if (string.IsNullOrEmpty(Environment.GetEnvironmentVariable("SAS:Ip")))
                    {
                        Environment.SetEnvironmentVariable("SAS:Ip", _keyVaultClient.GetSecretAsync(vaultBaseUrl: config["VaultUri"], secretName: "ip").Result.Value);
                    }
                    if (string.IsNullOrEmpty(Environment.GetEnvironmentVariable("sbConnection")))
                    {
                        Environment.SetEnvironmentVariable("sbConnection", _keyVaultClient.GetSecretAsync(vaultBaseUrl: config["VaultUri"], secretName: "sbConnection").Result.Value);
                    }
                }
                catch { }

                var    binDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
                string ResourcePath = Path.GetFullPath(Path.Combine(binDirectory, ".."));

                Console.WriteLine("loading RZ.Software-Providers:");
                Plugins.loadPlugins(Path.Combine(Path.Combine(ResourcePath, "wwwroot"), "plugins"));

                Console.Write("loading SW-Catalog...");
                Base.GetCatalog("", true);
                Console.WriteLine(" done.");

                RZ.ServerFN.IP2Location.Settings    = Plugins.dSettings;
                RZ.ServerFN.UpdateCounters.Settings = Plugins.dSettings;
                sbconnection = Environment.GetEnvironmentVariable("sbConnection");
            }