示例#1
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;
            }
        }
示例#2
0
        public LogServerApp()
        {
            try
            {
                this.Settings.AccessData(true, k =>
                {
                    string logDestDir   = k.GetStr("DestDir", CoresConfig.LogServerApp.DefaultDestDirString);
                    string certVaultDir = k.GetStr("LogServerCertVaultDirString", CoresConfig.LogServerApp.DefaultLogServerCertVaultDirString);

                    string servicePortsStr = k.GetStr("LogServerPorts", CoresConfig.LogServerApp.DefaultLogServerPortsString);

                    string httpPortsStr  = k.GetStr("WebServerHttpPorts", CoresConfig.LogServerApp.DefaultHttpServerPortsString);
                    string httpsPortsStr = k.GetStr("WebServerHttpsPorts", CoresConfig.LogServerApp.DefaultHttpsServerPortsString);

                    string mustIncludeHostnameStr = k.GetStr("MustIncludeHostname", "*");

                    logDestDir   = Lfs.ConfigPathStringToPhysicalDirectoryPath(logDestDir);
                    certVaultDir = Lfs.ConfigPathStringToPhysicalDirectoryPath(certVaultDir);


                    // Start Log Server
                    this.CertVault = new CertVault(certVaultDir,
                                                   new CertVaultSettings(EnsureSpecial.Yes)
                    {
                        ReloadIntervalMsecs = 3600 * 1000,
                        UseAcme             = false,
                        NonAcmeEnableAutoGenerateSubjectNameCert = false,
                    });

                    Lfs.CreateDirectory(logDestDir, FileFlags.OnCreateSetCompressionFlag);

                    PalSslServerAuthenticationOptions sslOptions = new PalSslServerAuthenticationOptions(this.CertVault.X509CertificateSelector("dummy", true), true, null);

                    this.LogServer = new LogServer(new LogServerOptions(null, logDestDir,
                                                                        FileFlags.AutoCreateDirectory | FileFlags.OnCreateSetCompressionFlag | FileFlags.LargeFs_AppendWithoutCrossBorder | FileFlags.LargeFs_AppendNewLineForCrossBorder,
                                                                        setDestinationProc: null,
                                                                        sslAuthOptions: sslOptions,
                                                                        tcpIp: LocalNet,
                                                                        ports: Str.ParsePortsList(servicePortsStr),
                                                                        rateLimiterConfigName: "LogServer"
                                                                        ));

                    // Start HTTP Server-based Web log browser
                    HttpServerOptions httpServerOptions = new HttpServerOptions
                    {
                        UseStaticFiles = false,
                        UseSimpleBasicAuthentication = true,
                        HttpPortsList                      = Str.ParsePortsList(httpPortsStr).ToList(),
                        HttpsPortsList                     = Str.ParsePortsList(httpsPortsStr).ToList(),
                        DebugKestrelToConsole              = true,
                        UseKestrelWithIPACoreStack         = true,
                        AutomaticRedirectToHttpsIfPossible = true,
                        LocalHostOnly                      = false,
                    };

                    if (mustIncludeHostnameStr._IsFilled() && mustIncludeHostnameStr._IsSamei("*") == false)
                    {
                        string[] tokens = mustIncludeHostnameStr.Split(new char[] { ' ', ' ', ';', '/', ',' }, StringSplitOptions.RemoveEmptyEntries);
                        tokens._DoForEach(x => httpServerOptions.MustIncludeHostnameStrList.Add(x));
                    }

                    LogBrowserOptions browserOptions = new LogBrowserOptions(logDestDir);

                    this.LogBrowserHttpServer = LogBrowserHttpServerBuilder.StartServer(httpServerOptions, new LogBrowserHttpServerOptions(browserOptions, ""));
                });
            }
            catch
            {
                this._DisposeSafe();
                throw;
            }
        }