aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Server/Base/HttpServerBase.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Server/Base/HttpServerBase.cs')
-rw-r--r--OpenSim/Server/Base/HttpServerBase.cs152
1 files changed, 152 insertions, 0 deletions
diff --git a/OpenSim/Server/Base/HttpServerBase.cs b/OpenSim/Server/Base/HttpServerBase.cs
new file mode 100644
index 0000000..44ef124
--- /dev/null
+++ b/OpenSim/Server/Base/HttpServerBase.cs
@@ -0,0 +1,152 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Collections.Generic;
30using System.Threading;
31using System.Reflection;
32using OpenSim.Framework;
33using OpenSim.Framework.Console;
34using OpenSim.Framework.Servers;
35using OpenSim.Framework.Servers.HttpServer;
36using log4net;
37using Nini.Config;
38
39namespace OpenSim.Server.Base
40{
41 public class HttpServerBase : ServicesServerBase
42 {
43// private static readonly ILog m_Log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
44
45 private uint m_consolePort;
46
47 // Handle all the automagical stuff
48 //
49 public HttpServerBase(string prompt, string[] args) : base(prompt, args)
50 {
51 }
52
53 protected override void ReadConfig()
54 {
55 IConfig networkConfig = Config.Configs["Network"];
56
57 if (networkConfig == null)
58 {
59 System.Console.WriteLine("ERROR: Section [Network] not found, server can't start");
60 Environment.Exit(1);
61 }
62
63 uint port = (uint)networkConfig.GetInt("port", 0);
64
65 if (port == 0)
66 {
67 System.Console.WriteLine("ERROR: No 'port' entry found in [Network]. Server can't start");
68 Environment.Exit(1);
69 }
70
71 bool ssl_main = networkConfig.GetBoolean("https_main",false);
72 bool ssl_listener = networkConfig.GetBoolean("https_listener",false);
73
74 m_consolePort = (uint)networkConfig.GetInt("ConsolePort", 0);
75
76 BaseHttpServer httpServer = null;
77
78 //
79 // This is where to make the servers:
80 //
81 //
82 // Make the base server according to the port, etc.
83 // ADD: Possibility to make main server ssl
84 // Then, check for https settings and ADD a server to
85 // m_Servers
86 //
87 if (!ssl_main)
88 {
89 httpServer = new BaseHttpServer(port);
90 }
91 else
92 {
93 string cert_path = networkConfig.GetString("cert_path",String.Empty);
94 if (cert_path == String.Empty)
95 {
96 System.Console.WriteLine("ERROR: Path to X509 certificate is missing, server can't start.");
97 Environment.Exit(1);
98 }
99
100 string cert_pass = networkConfig.GetString("cert_pass",String.Empty);
101 if (cert_pass == String.Empty)
102 {
103 System.Console.WriteLine("ERROR: Password for X509 certificate is missing, server can't start.");
104 Environment.Exit(1);
105 }
106
107 httpServer = new BaseHttpServer(port, ssl_main, cert_path, cert_pass);
108 }
109
110 MainServer.AddHttpServer(httpServer);
111 MainServer.Instance = httpServer;
112
113 // If https_listener = true, then add an ssl listener on the https_port...
114 if (ssl_listener == true)
115 {
116 uint https_port = (uint)networkConfig.GetInt("https_port", 0);
117
118 string cert_path = networkConfig.GetString("cert_path",String.Empty);
119 if (cert_path == String.Empty)
120 {
121 System.Console.WriteLine("ERROR: Path to X509 certificate is missing, server can't start.");
122 Environment.Exit(1);
123 }
124
125 string cert_pass = networkConfig.GetString("cert_pass",String.Empty);
126 if (cert_pass == String.Empty)
127 {
128 System.Console.WriteLine("ERROR: Password for X509 certificate is missing, server can't start.");
129 Environment.Exit(1);
130 }
131
132 MainServer.AddHttpServer(new BaseHttpServer(https_port, ssl_listener, cert_path, cert_pass));
133 }
134 }
135
136 protected override void Initialise()
137 {
138 foreach (BaseHttpServer s in MainServer.Servers.Values)
139 s.Start();
140
141 MainServer.RegisterHttpConsoleCommands(MainConsole.Instance);
142
143 if (MainConsole.Instance is RemoteConsole)
144 {
145 if (m_consolePort == 0)
146 ((RemoteConsole)MainConsole.Instance).SetServer(MainServer.Instance);
147 else
148 ((RemoteConsole)MainConsole.Instance).SetServer(MainServer.GetHttpServer(m_consolePort));
149 }
150 }
151 }
152}