예제 #1
0
        public CgiHttpServer(CgiHandlerBase handler, HttpServerOptions options, bool autoDisposeHandler = false)
        {
            try
            {
                this.Handler            = handler;
                this.AutoDisposeHandler = autoDisposeHandler;

                this.Handler.ShowDetailError.TrySet(options.ShowDetailError);

                HttpSvr = CgiHttpServerBuilder.StartServer(options, this);
            }
            catch (Exception ex)
            {
                this._DisposeSafe(ex);
                throw;
            }
        }
예제 #2
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;
            }
        }
예제 #3
0
 public static HttpServer <CgiHttpServerBuilder> StartServer(HttpServerOptions httpCfg, CgiHttpServer cgiHttpServer, CancellationToken cancel = default)
 => new HttpServer <CgiHttpServerBuilder>(httpCfg, cgiHttpServer, cancel);
 public static HttpServer <JsonRpcHttpServerBuilder> StartServer(HttpServerOptions httpCfg, JsonRpcServerConfig rpcServerCfg, JsonRpcServerApi rpcApi, CancellationToken cancel = default)
 => new HttpServer <JsonRpcHttpServerBuilder>(httpCfg, (rpcServerCfg, rpcApi), cancel);
예제 #5
0
        public HttpServer(HttpServerOptions options, object?param = null, CancellationToken cancel = default) : base(cancel)
        {
            try
            {
                this.Options = options;

                bool isDevelopmentMode = false;

                if (this.Options.DisableHiveBasedSetting == false)
                {
                    Hive.LocalAppSettingsEx[this.Options.HiveName].AccessData(true,
                                                                              k =>
                    {
                        isDevelopmentMode = k.GetBool("IsDevelopmentMode", false);

                        // Update options with the config file
                        string httpPortsList  = k.GetStr("HttpPorts", Str.PortsListToStr(Options.HttpPortsList));
                        Options.HttpPortsList = Str.ParsePortsList(httpPortsList).ToList();

                        string httpsPortsList  = k.GetStr("HttpsPorts", Str.PortsListToStr(Options.HttpsPortsList));
                        Options.HttpsPortsList = Str.ParsePortsList(httpsPortsList).ToList();

                        Options.LocalHostOnly = k.GetBool("LocalHostOnly", Options.LocalHostOnly);
                        Options.IPv4Only      = k.GetBool("IPv4Only", Options.IPv4Only);

                        string mustIncludeHostnameStr = k.GetStr("MustIncludeHostnameList", "");
                        string[] tokens = mustIncludeHostnameStr.Split(new char[] { ' ', ' ', ';', '/', ',' }, StringSplitOptions.RemoveEmptyEntries);
                        tokens._DoForEach(x => Options.MustIncludeHostnameStrList.Add(x));
                    });
                }

                Lfs.CreateDirectory(Options.WwwRoot);
                Lfs.CreateDirectory(Options.ContentsRoot);

                ParamToken  = GlobalObjectExchange.Deposit(param);
                CancelToken = GlobalObjectExchange.Deposit(this.GrandCancel);

                try
                {
                    var dict = new Dictionary <string, string>
                    {
                        { "coreutil_ServerBuilderConfig", this.Options._ObjectToJson() },
                        { "coreutil_param_token", ParamToken },
                        { "coreutil_cancel_token", CancelToken },
                    };

                    IConfiguration iconf = new ConfigurationBuilder()
                                           .AddInMemoryCollection(dict)
                                           .Build();

                    var host = Options.GetWebHostBuilder <THttpServerBuilder>(param)
                               .UseConfiguration(iconf)
                               .CaptureStartupErrors(true)
                               .UseSetting("detailedErrors", isDevelopmentMode.ToString())
                               .Build();

                    HostTask = host.RunAsync(this.CancelWatcher.CancelToken);
                }
                catch
                {
                    GlobalObjectExchange.TryWithdraw(ParamToken, out _);
                    ParamToken = null;

                    GlobalObjectExchange.TryWithdraw(CancelToken, out _);
                    CancelToken = null;
                    throw;
                }
            }
            catch
            {
                this._DisposeSafe();
                throw;
            }
        }
예제 #6
0
 public static HttpServer <LogBrowserHttpServerBuilder> StartServer(HttpServerOptions httpCfg, LogBrowserHttpServerOptions options, CancellationToken cancel = default)
 => new HttpServer <LogBrowserHttpServerBuilder>(httpCfg, options, cancel);
예제 #7
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;
            }
        }
        public EasyJsonRpcServer(HttpServerOptions httpConfig, CancellationToken cancel = default) : base(cancel)
        {
            JsonRpcServerConfig rpcCfg = new JsonRpcServerConfig();

            this.HttpServer = JsonRpcHttpServerBuilder.StartServer(httpConfig, rpcCfg, this, cancel);
        }