start of adminpannel

This commit is contained in:
BlubbFish 2019-04-01 18:15:50 +02:00
parent 4ad9814a84
commit b19a32c569
3 changed files with 44 additions and 10 deletions

View File

@ -45,6 +45,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Model\Admin\AdminModel.cs" />
<Compile Include="Model\Marker.cs" />
<Compile Include="Model\AlarmItem.cs" />
<Compile Include="Server.cs" />
@ -179,5 +180,8 @@
<Name>Utils</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Folder Include="admin\" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

View File

@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using BlubbFish.Utils.IoT.Bots;
namespace Fraunhofer.Fit.IoT.LoraMap.Model.Admin {
class AdminModel {
public Boolean ParseReuqest(HttpListenerContext cont) {
//cont.Request.Url.PathAndQuery =
if(!this.CheckAuth(cont)) {
return false;
}
return Webserver.SendFileResponse(cont, "admin");
}
private Boolean CheckAuth(HttpListenerContext cont) {
if(cont.Request.Url.PathAndQuery.StartsWith("/admin/login")) {
return true;
} else if(cont.Request.Url.PathAndQuery.StartsWith("/admin/logout")) {
} else {
cont.Response.StatusCode = 403;
}
return false;
}
}
}

View File

@ -8,6 +8,7 @@ using BlubbFish.Utils.IoT.Bots;
using BlubbFish.Utils.IoT.Connector;
using BlubbFish.Utils.IoT.Events;
using Fraunhofer.Fit.IoT.LoraMap.Model;
using Fraunhofer.Fit.IoT.LoraMap.Model.Admin;
using LitJson;
namespace Fraunhofer.Fit.IoT.LoraMap {
@ -17,6 +18,7 @@ namespace Fraunhofer.Fit.IoT.LoraMap {
private readonly SortedDictionary<String, AlarmItem> alarms = new SortedDictionary<String, AlarmItem>();
private readonly JsonData marker;
private readonly Dictionary<String, Marker> markertable = new Dictionary<String, Marker>();
private readonly AdminModel admin = new AdminModel();
public Server(ADataBackend backend, Dictionary<String, String> settings, InIReader requests) : base(backend, settings, requests) => this.marker = JsonMapper.ToObject(File.ReadAllText("names.json"));
@ -45,14 +47,12 @@ namespace Fraunhofer.Fit.IoT.LoraMap {
}
}
protected override void SendResponse(HttpListenerContext cont) {
protected override Boolean SendWebserverResponse(HttpListenerContext cont) {
try {
if (cont.Request.Url.PathAndQuery.StartsWith("/loc")) {
this.SendJsonResponse(this.positions, cont);
return;
return SendJsonResponse(this.positions, cont);
} else if(cont.Request.Url.PathAndQuery.StartsWith("/panic")) {
this.SendJsonResponse(this.alarms, cont);
return;
return SendJsonResponse(this.alarms, cont);
} else if (cont.Request.Url.PathAndQuery.StartsWith("/icons/marker/Marker.svg") && cont.Request.Url.PathAndQuery.Contains("?")) {
String hash = cont.Request.Url.PathAndQuery.Substring(cont.Request.Url.PathAndQuery.IndexOf('?') + 1);
if (!this.markertable.ContainsKey(hash)) {
@ -63,17 +63,18 @@ namespace Fraunhofer.Fit.IoT.LoraMap {
cont.Response.ContentLength64 = buf.Length;
cont.Response.OutputStream.Write(buf, 0, buf.Length);
Console.WriteLine("200 - " + cont.Request.Url.PathAndQuery);
return;
return true;
} else if(cont.Request.Url.PathAndQuery.StartsWith("/currenttime")) {
this.SendJsonResponse(new Dictionary<String, DateTime>() { { "utc", DateTime.UtcNow } }, cont);
return;
return SendJsonResponse(new Dictionary<String, DateTime>() { { "utc", DateTime.UtcNow } }, cont);
} else if(cont.Request.Url.PathAndQuery.StartsWith("/admin")) {
return this.admin.ParseReuqest(cont);
}
} catch (Exception e) {
Helper.WriteError("500 - " + e.Message);
cont.Response.StatusCode = 500;
return;
return false;
}
base.SendResponse(cont);
return SendFileResponse(cont, "resources");
}
}
}