diff options
Diffstat (limited to 'ShiftOS.Server')
| -rw-r--r-- | ShiftOS.Server/App.config | 10 | ||||
| -rw-r--r-- | ShiftOS.Server/Program.cs | 121 | ||||
| -rw-r--r-- | ShiftOS.Server/ShiftOS.Server.csproj | 13 | ||||
| -rw-r--r-- | ShiftOS.Server/WebAdmin.cs | 115 | ||||
| -rw-r--r-- | ShiftOS.Server/packages.config | 3 |
5 files changed, 11 insertions, 251 deletions
diff --git a/ShiftOS.Server/App.config b/ShiftOS.Server/App.config index cf88e98..efb416e 100644 --- a/ShiftOS.Server/App.config +++ b/ShiftOS.Server/App.config @@ -1,9 +1,15 @@ -<?xml version="1.0" encoding="utf-8" ?> +<?xml version="1.0" encoding="utf-8"?> <configuration> <startup> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" /> </startup> <runtime> - <loadFromRemoteSources enabled="true"/> + <loadFromRemoteSources enabled="true" /> + <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> + <dependentAssembly> + <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" /> + <bindingRedirect oldVersion="0.0.0.0-9.0.0.0" newVersion="9.0.0.0" /> + </dependentAssembly> + </assemblyBinding> </runtime> </configuration>
\ No newline at end of file diff --git a/ShiftOS.Server/Program.cs b/ShiftOS.Server/Program.cs index 3ef78ee..099df86 100644 --- a/ShiftOS.Server/Program.cs +++ b/ShiftOS.Server/Program.cs @@ -33,119 +33,10 @@ using System.IO; using Newtonsoft.Json; using System.Net; using System.Net.Sockets; -using Nancy.Hosting.Self; -using Nancy; -using Nancy.Authentication.Basic; -using Nancy.Security; -using Nancy.TinyIoc; -using Nancy.Bootstrapper; namespace ShiftOS.Server { - /// <summary> - /// user mapper. - /// </summary> - public interface IUserMapper - { - /// <summary> - /// Get the real username from an identifier - /// </summary> - /// <param name="identifier">User identifier</param> - /// <param name="context">The current NancyFx context</param> - /// <returns>Matching populated IUserIdentity object, or empty</returns> - IUserIdentity GetUserFromIdentifier(Guid identifier, NancyContext context); - } - - /// <summary> - /// MUD user validator. - /// </summary> - public class MUDUserValidator : IUserValidator - { - /// <summary> - /// Validate the specified username and password. - /// </summary> - /// <param name="username">Username.</param> - /// <param name="password">Password.</param> - public IUserIdentity Validate(string username, string password) - { - if(username == Program.AdminUsername && password == Program.AdminPassword) - { - return null; - } - else - { - return null; - } - } - } - - /// <summary> - /// MUD user identity. - /// </summary> - public class MUDUserIdentity : IUserIdentity - { - /// <summary> - /// The claims of the authenticated user. - /// </summary> - /// <value>The claims.</value> - public IEnumerable<string> Claims - { - get - { - return null; - } - } - - /// <summary> - /// The username of the authenticated user. - /// </summary> - /// <value>The name of the user.</value> - public string UserName - { - get - { - return uname; - } - } - - /// <summary> - /// The uname. - /// </summary> - public string uname = ""; - - /// <summary> - /// Initializes a new instance of the <see cref="ShiftOS.Server.MUDUserIdentity"/> class. - /// </summary> - /// <param name="username">Username.</param> - public MUDUserIdentity(string username) - { - uname = username; - } - } - - /// <summary> - /// Authentication bootstrapper. - /// </summary> - public class AuthenticationBootstrapper : DefaultNancyBootstrapper - { - /// <summary> - /// Initialise the bootstrapper - can be used for adding pre/post hooks and - /// any other initialisation tasks that aren't specifically container setup - /// related - /// </summary> - /// <param name="container">Container instance for resolving types if required.</param> - /// <returns>The startup.</returns> - /// <param name="pipelines">Pipelines.</param> - protected override void ApplicationStartup(TinyIoCContainer container, IPipelines pipelines) - { - base.ApplicationStartup(container, pipelines); - - pipelines.EnableBasicAuthentication(new BasicAuthenticationConfiguration( - container.Resolve<MUDUserValidator>(), - "MUD", UserPromptBehaviour.NonAjax)); - } - } - + /// <summary> /// Program. /// </summary> @@ -294,17 +185,11 @@ namespace ShiftOS.Server } - var hConf = new HostConfiguration(); - hConf.UrlReservations.CreateAutomatically = true; - - var nancy = new NancyHost(hConf, new Uri("http://localhost:13371/")); - server.OnStopped += (o, a) => { - nancy.Stop(); - }; + Console.WriteLine("Server stopping."); - nancy.Start(); + }; } /// <summary> diff --git a/ShiftOS.Server/ShiftOS.Server.csproj b/ShiftOS.Server/ShiftOS.Server.csproj index 8db678e..ae6248c 100644 --- a/ShiftOS.Server/ShiftOS.Server.csproj +++ b/ShiftOS.Server/ShiftOS.Server.csproj @@ -37,18 +37,6 @@ <HintPath>..\packages\DynamicLua.1.1.2.0\lib\net40-Client\DynamicLua.dll</HintPath> <Private>True</Private> </Reference> - <Reference Include="Nancy, Version=1.4.1.0, Culture=neutral, processorArchitecture=MSIL"> - <HintPath>..\packages\Nancy.1.4.1\lib\net40\Nancy.dll</HintPath> - <Private>True</Private> - </Reference> - <Reference Include="Nancy.Authentication.Basic, Version=1.4.1.0, Culture=neutral, processorArchitecture=MSIL"> - <HintPath>..\packages\Nancy.Authentication.Basic.1.4.1\lib\net40\Nancy.Authentication.Basic.dll</HintPath> - <Private>True</Private> - </Reference> - <Reference Include="Nancy.Hosting.Self, Version=1.4.1.0, Culture=neutral, processorArchitecture=MSIL"> - <HintPath>..\packages\Nancy.Hosting.Self.1.4.1\lib\net40\Nancy.Hosting.Self.dll</HintPath> - <Private>True</Private> - </Reference> <Reference Include="NetSockets"> <HintPath>..\Libraries\NetSockets.dll</HintPath> </Reference> @@ -73,7 +61,6 @@ <DesignTime>True</DesignTime> <DependentUpon>Resources.resx</DependentUpon> </Compile> - <Compile Include="WebAdmin.cs" /> </ItemGroup> <ItemGroup> <None Include="App.config" /> diff --git a/ShiftOS.Server/WebAdmin.cs b/ShiftOS.Server/WebAdmin.cs deleted file mode 100644 index c9ff94b..0000000 --- a/ShiftOS.Server/WebAdmin.cs +++ /dev/null @@ -1,115 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2017 Michael VanOverbeek and ShiftOS devs - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -using Nancy; -using Nancy.Security; -using NetSockets; -using Newtonsoft.Json; -using ShiftOS.Objects; -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Reflection; -using System.Text; -using System.Threading.Tasks; - -namespace ShiftOS.Server -{ - public class WebAdmin : NancyModule - { - private Guid thisGuid { get; set; } - - public WebAdmin() - { - this.RequiresAuthentication(); - - - client = new NetObjectClient(); - - client.OnReceived += (o, a) => - { - var msg = a.Data.Object as ServerMessage; - if (msg.Name == "Welcome") - { - thisGuid = new Guid(msg.Contents); - } - }; - - client.Connect(Program.server.Address.MapToIPv4().ToString(), 13370); - - string template = Properties.Resources.Home; - - Get["/"] = _ => { return GetPage(template, "index.html"); }; - Get["/{page}"] = parameters => - { - return GetPage(template, parameters.page); - }; - } - - public NetObjectClient client = new NetObjectClient(); - - public string GetPage(string template, string page) - { - string pageContents = File.ReadAllText("adm/" + page); - - string page_text = template.Replace("{BODY}", pageContents); - - page_text = page_text.Replace("{IP_ADDR}", client.RemoteHost.ToString()); - page_text = page_text.Replace("{PORT}", client.RemotePort.ToString()); - - return page_text; - } - - public string GrabResource(string page) - { - var type = this.GetType(); - foreach(var property in type.GetProperties(BindingFlags.Public | BindingFlags.Instance)) - { - foreach(var attr in property.GetCustomAttributes(false)) - { - if(attr is PageAttribute) - { - if(page == (attr as PageAttribute).Name) - { - return property.GetGetMethod().Invoke(this, null) as string; - } - } - } - } - - return Properties.Resources.NotFound; - } - } - - public class PageAttribute :Attribute - { - public PageAttribute(string name) - { - Name = name; - } - - public string Name { get; set; } - } -} diff --git a/ShiftOS.Server/packages.config b/ShiftOS.Server/packages.config index 3e07118..5fb0f8f 100644 --- a/ShiftOS.Server/packages.config +++ b/ShiftOS.Server/packages.config @@ -1,8 +1,5 @@ <?xml version="1.0" encoding="utf-8"?> <packages> <package id="DynamicLua" version="1.1.2.0" targetFramework="net452" /> - <package id="Nancy" version="1.4.1" targetFramework="net452" /> - <package id="Nancy.Authentication.Basic" version="1.4.1" targetFramework="net452" /> - <package id="Nancy.Hosting.Self" version="1.4.1" targetFramework="net452" /> <package id="Newtonsoft.Json" version="9.0.1" targetFramework="net452" /> </packages>
\ No newline at end of file |
