Exemplo n.º 1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            // AspNetLib による設定を追加
            AspNetLib.ConfigureServices(StartupHelper, services);

            // 基本的な設定を追加
            StartupHelper.ConfigureServices(services);

            // リクエスト数制限機能を追加
            services.AddHttpRequestRateLimiter <HttpRequestRateLimiterHashKeys.SrcIPAddress>(_ => { });

            //// Cookie 認証機能を追加
            EasyCookieAuth.LoginFormMessage.TrySet("ログインが必要です。");
            EasyCookieAuth.AuthenticationPasswordValidator = StartupHelper.SimpleBasicAuthenticationPasswordValidator;
            EasyCookieAuth.ConfigureServices(services, !StartupHelper.ServerOptions.AutomaticRedirectToHttpsIfPossible);

            // LogBrowesr 機能を設定
            AspNetLib.SetupLogBrowser(services, new LogBrowserOptions(PP.Combine(Env.AppRootDir, "Log"), "DaemonCenter Server 本体ログブラウザ"));

            // MVC 機能を追加
            services.AddControllersWithViews()
            .ConfigureMvcWithAspNetLib(AspNetLib);

            this.DaemonCenterServer = new Server();

            // シングルトンサービスの注入
            services.AddSingleton(this.DaemonCenterServer);

            // Daemon Center RPC 独立ポートサーバーの作成
            this.DaemonCenterRpcHost = new DaemonCenterServerRpcHttpHost(this.DaemonCenterServer);

            // 全ページ共通コンテキストの注入
            services.AddScoped <PageContext>();
        }
Exemplo n.º 2
0
    public ThinDatabase(ThinController controller)
    {
        try
        {
            this.BackupFileName = PP.Combine(Env.AppLocalDir, "Config", "ThinControllerDatabaseBackupCache", "DatabaseBackupCache.json");

            this.Controller = controller;

            this.ReadMainLoopTask  = ReadMainLoopAsync(this.GrandCancel)._LeakCheck();
            this.WriteMainLoopTask = WriteMainLoopAsync(this.GrandCancel)._LeakCheck();
        }
        catch
        {
            this._DisposeSafe();
            throw;
        }
    }
Exemplo n.º 3
0
        public DaemonUtil(string daemonName, CancellationToken cancel = default) : base(cancel)
        {
            if (daemonName._IsEmpty())
            {
                throw new ArgumentNullException(nameof(daemonName));
            }

            daemonName = daemonName._NonNullTrim();

            try
            {
                // 起動パラメータ
                this.Params = new OneLineParams(GlobalDaemonStateManager.StartupArguments);

                if (Params._HasKey(Consts.DaemonArgKeys.StartLogFileBrowser))
                {
                    // Log Browser で利用されるべきポート番号の決定
                    int httpPort = Params._GetFirstValueOrDefault(Consts.DaemonArgKeys.LogFileBrowserPort, StrComparer.IgnoreCaseComparer)._ToInt();
                    if (httpPort == 0)
                    {
                        httpPort = Util.GenerateDynamicListenableTcpPortWithSeed(Env.DnsFqdnHostName + "_seed_daemonutil_logbrowser_http" + Env.AppRootDir + "@" + daemonName);
                    }

                    int httpsPort = Params._GetFirstValueOrDefault(Consts.DaemonArgKeys.LogFileBrowserPort, StrComparer.IgnoreCaseComparer)._ToInt();
                    if (httpsPort == 0)
                    {
                        httpsPort = Util.GenerateDynamicListenableTcpPortWithSeed(Env.DnsFqdnHostName + "_seed_daemonutil_logbrowser_https" + Env.AppRootDir + "@" + daemonName, excludePorts: httpPort._SingleArray());
                    }

                    // Log Browser 用の CertVault の作成
                    CertVault certVault = new CertVault(PP.Combine(Env.AppLocalDir, "Config/DaemonUtil_LogBrowser/CertVault"),
                                                        new CertVaultSettings(defaultSetting: EnsureSpecial.Yes)
                    {
                        UseAcme = false
                    });

                    DisposeList.Add(certVault);

                    // Log Browser の起動
                    HttpServerOptions httpServerOptions = new HttpServerOptions
                    {
                        UseStaticFiles = false,
                        UseSimpleBasicAuthentication = false,
                        HttpPortsList                      = httpPort._SingleList(),
                        HttpsPortsList                     = httpsPort._SingleList(),
                        DebugKestrelToConsole              = false,
                        UseKestrelWithIPACoreStack         = true,
                        AutomaticRedirectToHttpsIfPossible = false,
                        LocalHostOnly                      = false,
                        UseGlobalCertVault                 = false, // Disable Global CertVault
                        DisableHiveBasedSetting            = true,  // Disable Hive based settings
                        ServerCertSelector                 = certVault.X509CertificateSelectorForHttpsServerNoAcme,
                        DenyRobots = true,                          // Deny robots
                    };

                    LogBrowserOptions browserOptions = new LogBrowserOptions(
                        Env.AppRootDir,
                        systemTitle: $"{Env.DnsFqdnHostName}",
                        clientIpAcl: (ip) =>
                    {
                        // 接続元 IP アドレスの種類を取得
                        IPAddressType type = ip._GetIPAddressType();

                        if (type.Bit(IPAddressType.GlobalIp))
                        {
                            // 接続元がグローバル IP の場合
                            if (GlobalDaemonStateManager.IsDaemonClientLocalIpAddressGlobal == false)
                            {
                                // DaemonCenter との接続にプライベート IP を利用している場合: 接続拒否
                                return(false);
                            }
                        }

                        // それ以外の場合: 接続許可
                        return(true);
                    }
                        );

                    DisposeList.Add(LogBrowserHttpServerBuilder.StartServer(httpServerOptions, new LogBrowserHttpServerOptions(browserOptions, "/" + GlobalDaemonStateManager.DaemonSecret)));

                    GlobalDaemonStateManager.FileBrowserHttpsPortNumber = httpsPort;
                }
            }
            catch (Exception ex)
            {
                ex._Debug();

                this._DisposeSafe();

                throw;
            }
        }