Some tweaks to get it running right
This commit is contained in:
parent
621794f0b3
commit
c63be78a08
@ -25,9 +25,9 @@
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
|
@ -1,9 +1,9 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web;
|
||||
|
||||
namespace BlubbFish.BosMon.Webserver {
|
||||
class POCSAG {
|
||||
@ -52,7 +52,7 @@ namespace BlubbFish.BosMon.Webserver {
|
||||
internal String ToXML() {
|
||||
String ret = "<telegram>\r\n";
|
||||
ret += "<function>"+this.Function+ "</function>\r\n";
|
||||
ret += "<message>"+ HttpUtility.HtmlEncode(this.Message) + "</message>\r\n";
|
||||
ret += "<message>"+ WebUtility.HtmlEncode(this.Message) + "</message>\r\n";
|
||||
ret += "<type>3</type>\r\n";
|
||||
ret += "<address>"+this.Address.ToString("D7")+ "</address>\r\n";
|
||||
ret += "<timestamp>"+((DateTimeOffset)this.Time).ToUnixTimeMilliseconds()+ "</timestamp>\r\n";
|
||||
|
@ -38,7 +38,7 @@ namespace BlubbFish.BosMon.Webserver {
|
||||
ctx.Response.OutputStream.Close();
|
||||
ctx.Response.Close();
|
||||
} catch(Exception e) {
|
||||
Helper.WriteError("Context Exception: " + e.Message +""+e.Source+ "\n\n" + e.StackTrace);
|
||||
Helper.WriteError("Context Exception: " + e.Message + " " + e.Source + "\n" + e.StackTrace);
|
||||
}
|
||||
}, this._listener.GetContext());
|
||||
}
|
||||
@ -49,35 +49,40 @@ namespace BlubbFish.BosMon.Webserver {
|
||||
}
|
||||
|
||||
private void SendResponse(HttpListenerContext ctx) {
|
||||
if (this.CheckAuth(ctx.Request)) {
|
||||
ctx.Response.ContentType = "text/xml";
|
||||
ctx.Response.Headers.Add(HttpResponseHeader.Server, "BM Webserver 1.3");
|
||||
ctx.Response.SendChunked = true;
|
||||
ctx.Response.Headers.Add(HttpResponseHeader.Date, DateTime.Now.ToString("ddd, dd MMM yyy HH':'mm':'ss 'GMT'"));
|
||||
ctx.Response.Headers.Add(HttpResponseHeader.Connection, "close");
|
||||
Byte[] start = Encoding.UTF8.GetBytes("<?xml version=\"1.0\" encoding=\"UTF - 8\" standalone=\"yes\"?>\r\n<telegrams>\r\n");
|
||||
ctx.Response.OutputStream.Write(start, 0, start.Length);
|
||||
ctx.Response.OutputStream.Flush();
|
||||
start = Encoding.UTF8.GetBytes("<live>" + ((DateTimeOffset)DateTime.Now).ToUnixTimeMilliseconds() + "</live>\r\n");
|
||||
ctx.Response.OutputStream.Write(start, 0, start.Length);
|
||||
ctx.Response.OutputStream.Flush();
|
||||
while (true) {
|
||||
List<POCSAG> submit = new List<POCSAG>();
|
||||
while (this.pOCSAGs.Count > 0) {
|
||||
submit.Add(this.pOCSAGs.Dequeue());
|
||||
try {
|
||||
if (this.CheckAuth(ctx.Request)) {
|
||||
ctx.Response.ContentType = "text/xml";
|
||||
ctx.Response.Headers.Add(HttpResponseHeader.Server, "BM Webserver 1.3");
|
||||
ctx.Response.SendChunked = true;
|
||||
ctx.Response.Headers.Add(HttpResponseHeader.Date, DateTime.Now.ToString("ddd, dd MMM yyy HH':'mm':'ss 'GMT'"));
|
||||
ctx.Response.Headers.Add(HttpResponseHeader.Connection, "close");
|
||||
Byte[] start = Encoding.UTF8.GetBytes("<?xml version=\"1.0\" encoding=\"UTF - 8\" standalone=\"yes\"?>\r\n<telegrams>\r\n");
|
||||
ctx.Response.OutputStream.Write(start, 0, start.Length);
|
||||
ctx.Response.OutputStream.Flush();
|
||||
start = Encoding.UTF8.GetBytes("<live>" + ((DateTimeOffset)DateTime.Now).ToUnixTimeMilliseconds() + "</live>\r\n");
|
||||
ctx.Response.OutputStream.Write(start, 0, start.Length);
|
||||
ctx.Response.OutputStream.Flush();
|
||||
while (true) {
|
||||
List<POCSAG> submit = new List<POCSAG>();
|
||||
while (this.pOCSAGs.Count > 0) {
|
||||
submit.Add(this.pOCSAGs.Dequeue());
|
||||
}
|
||||
if (submit.Count > 0) {
|
||||
Console.WriteLine("<- Send " + submit.Count + " Items");
|
||||
}
|
||||
foreach (POCSAG item in submit) {
|
||||
Byte[] buf = Encoding.UTF8.GetBytes(item.ToXML());
|
||||
ctx.Response.OutputStream.Write(buf, 0, buf.Length);
|
||||
ctx.Response.OutputStream.Flush();
|
||||
}
|
||||
Thread.Sleep(100);
|
||||
}
|
||||
if (submit.Count > 0) {
|
||||
Console.WriteLine("<- Send " + submit.Count + " Items");
|
||||
}
|
||||
foreach (POCSAG item in submit) {
|
||||
Byte[] buf = Encoding.UTF8.GetBytes(item.ToXML());
|
||||
ctx.Response.OutputStream.Write(buf, 0, buf.Length);
|
||||
ctx.Response.OutputStream.Flush();
|
||||
}
|
||||
Thread.Sleep(100);
|
||||
}
|
||||
ctx.Response.StatusCode = 403;
|
||||
}
|
||||
catch(Exception e) {
|
||||
Helper.WriteError("Send Response Exception: " + e.Message + " " + e.Source + "\n" + e.StackTrace);
|
||||
}
|
||||
ctx.Response.StatusCode = 403;
|
||||
}
|
||||
|
||||
private void ParseInput(HttpListenerContext request) {
|
||||
@ -91,7 +96,7 @@ namespace BlubbFish.BosMon.Webserver {
|
||||
foreach (String item in items) {
|
||||
String[] kv = item.Split('=');
|
||||
if (kv.Length == 2) {
|
||||
kv[1] = HttpUtility.UrlDecode(kv[1]);
|
||||
kv[1] = WebUtility.UrlDecode(kv[1]);
|
||||
input.Add(kv[0], kv[1]);
|
||||
}
|
||||
}
|
||||
|
Binary file not shown.
Binary file not shown.
@ -13,7 +13,7 @@ ExecStartPre=/bin/rm /var/log/bmweb.log
|
||||
ExecStartPre=/bin/touch /var/log/bmweb.log
|
||||
ExecStartPre=/bin/chown bmweb:bmweb /var/log/bmweb.log
|
||||
ExecStartPre=/bin/chmod 644 /var/log/bmweb.log
|
||||
ExecStart=/usr/bin/mono /usr/local/bin/bmweb/BosMon-Webserver.exe
|
||||
ExecStart=/usr/bin/mono --debug /usr/local/bin/bmweb/BosMon-Webserver.exe
|
||||
KillMode=control-group
|
||||
TimeoutStopSec=5
|
||||
Restart=on-failure
|
||||
|
@ -3,7 +3,7 @@ Version: x.x-x
|
||||
Section: base
|
||||
Priority: optional
|
||||
Architecture: any
|
||||
Depends: mono-runtime (>= 5.16.0), libmono-system-web4.0-cil (>= 5.16.0)
|
||||
Depends: mono-runtime (>= 5.16.0)
|
||||
Maintainer: BlubbFish <dev@blubbfish.net>
|
||||
Description: Bosmon-Webserver
|
||||
A Webserver for Bosmon Telegrafs
|
||||
|
Loading…
Reference in New Issue
Block a user