start of adminpannel
This commit is contained in:
parent
4ad9814a84
commit
b19a32c569
@ -45,6 +45,7 @@
|
|||||||
<Reference Include="System.Xml" />
|
<Reference Include="System.Xml" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Compile Include="Model\Admin\AdminModel.cs" />
|
||||||
<Compile Include="Model\Marker.cs" />
|
<Compile Include="Model\Marker.cs" />
|
||||||
<Compile Include="Model\AlarmItem.cs" />
|
<Compile Include="Model\AlarmItem.cs" />
|
||||||
<Compile Include="Server.cs" />
|
<Compile Include="Server.cs" />
|
||||||
@ -179,5 +180,8 @@
|
|||||||
<Name>Utils</Name>
|
<Name>Utils</Name>
|
||||||
</ProjectReference>
|
</ProjectReference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Folder Include="admin\" />
|
||||||
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
</Project>
|
</Project>
|
29
Lora-Map/Model/Admin/Adminmodel.cs
Normal file
29
Lora-Map/Model/Admin/Adminmodel.cs
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -8,6 +8,7 @@ using BlubbFish.Utils.IoT.Bots;
|
|||||||
using BlubbFish.Utils.IoT.Connector;
|
using BlubbFish.Utils.IoT.Connector;
|
||||||
using BlubbFish.Utils.IoT.Events;
|
using BlubbFish.Utils.IoT.Events;
|
||||||
using Fraunhofer.Fit.IoT.LoraMap.Model;
|
using Fraunhofer.Fit.IoT.LoraMap.Model;
|
||||||
|
using Fraunhofer.Fit.IoT.LoraMap.Model.Admin;
|
||||||
using LitJson;
|
using LitJson;
|
||||||
|
|
||||||
namespace Fraunhofer.Fit.IoT.LoraMap {
|
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 SortedDictionary<String, AlarmItem> alarms = new SortedDictionary<String, AlarmItem>();
|
||||||
private readonly JsonData marker;
|
private readonly JsonData marker;
|
||||||
private readonly Dictionary<String, Marker> markertable = new Dictionary<String, 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"));
|
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 {
|
try {
|
||||||
if (cont.Request.Url.PathAndQuery.StartsWith("/loc")) {
|
if (cont.Request.Url.PathAndQuery.StartsWith("/loc")) {
|
||||||
this.SendJsonResponse(this.positions, cont);
|
return SendJsonResponse(this.positions, cont);
|
||||||
return;
|
|
||||||
} else if(cont.Request.Url.PathAndQuery.StartsWith("/panic")) {
|
} else if(cont.Request.Url.PathAndQuery.StartsWith("/panic")) {
|
||||||
this.SendJsonResponse(this.alarms, cont);
|
return SendJsonResponse(this.alarms, cont);
|
||||||
return;
|
|
||||||
} else if (cont.Request.Url.PathAndQuery.StartsWith("/icons/marker/Marker.svg") && cont.Request.Url.PathAndQuery.Contains("?")) {
|
} 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);
|
String hash = cont.Request.Url.PathAndQuery.Substring(cont.Request.Url.PathAndQuery.IndexOf('?') + 1);
|
||||||
if (!this.markertable.ContainsKey(hash)) {
|
if (!this.markertable.ContainsKey(hash)) {
|
||||||
@ -63,17 +63,18 @@ namespace Fraunhofer.Fit.IoT.LoraMap {
|
|||||||
cont.Response.ContentLength64 = buf.Length;
|
cont.Response.ContentLength64 = buf.Length;
|
||||||
cont.Response.OutputStream.Write(buf, 0, buf.Length);
|
cont.Response.OutputStream.Write(buf, 0, buf.Length);
|
||||||
Console.WriteLine("200 - " + cont.Request.Url.PathAndQuery);
|
Console.WriteLine("200 - " + cont.Request.Url.PathAndQuery);
|
||||||
return;
|
return true;
|
||||||
} else if(cont.Request.Url.PathAndQuery.StartsWith("/currenttime")) {
|
} else if(cont.Request.Url.PathAndQuery.StartsWith("/currenttime")) {
|
||||||
this.SendJsonResponse(new Dictionary<String, DateTime>() { { "utc", DateTime.UtcNow } }, cont);
|
return SendJsonResponse(new Dictionary<String, DateTime>() { { "utc", DateTime.UtcNow } }, cont);
|
||||||
return;
|
} else if(cont.Request.Url.PathAndQuery.StartsWith("/admin")) {
|
||||||
|
return this.admin.ParseReuqest(cont);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Helper.WriteError("500 - " + e.Message);
|
Helper.WriteError("500 - " + e.Message);
|
||||||
cont.Response.StatusCode = 500;
|
cont.Response.StatusCode = 500;
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
base.SendResponse(cont);
|
return SendFileResponse(cont, "resources");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user