Skip to content

Commit

Permalink
fixed starting multiple instances of extraQL
Browse files Browse the repository at this point in the history
  • Loading branch information
PredatH0r committed Nov 1, 2015
1 parent f4635b4 commit 5a2919b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 16 deletions.
3 changes: 3 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ c:\program files (x86)\Steam\SteamApps\workshop\content\282440\539252269
Changelog
=========

Version 2.4.1
- fixed starting multiple instances of extraQL

Version 2.4
- better error logging in case steam_api.dll could not be initialized
- added /sn_suffix to append a text to the steam nickname
Expand Down
31 changes: 16 additions & 15 deletions source/HttpServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -266,19 +266,6 @@ private void HandleClientConnection(Stream stream)
string conn;
keepAlive = header.TryGetValue("Connection", out conn) && conn == "keep-alive";

// Check that the user agent is Awesomium and not a regular browser
// This should prevent abuse of extraQL URLs embedded in regular web pages
if (!bindToAllInterfaces)
{
string userAgent;
if (!header.TryGetValue("User-Agent", out userAgent) || !userAgent.Contains("Awesomium"))
{
var b = enc.GetBytes("HTTP/1.1 401 Unauthorized\r\n\r\nextraQL URLs may only be called from within QuakeLive scripts");
stream.Write(b, 0, b.Length);
continue;
}
}

if (!data.StartsWith("POST ") && !data.StartsWith("GET "))
{
var b = enc.GetBytes("HTTP/1.1 405 Method Not Allowed\r\n\r\n");
Expand All @@ -296,7 +283,7 @@ private void HandleClientConnection(Stream stream)
Log(url.ToString()); // ToString() displays the query string url-decoded, OriginalString doesn't

string urlPath = url.AbsolutePath;
if (!ExecuteServlet(stream, urlPath, url, data))
if (!ExecuteServlet(stream, urlPath, url, data, header))
{
var buff = enc.GetBytes("HTTP/1.1 404 Not Found\r\n\r\n");
stream.Write(buff, 0, buff.Length);
Expand All @@ -319,8 +306,22 @@ private void HandleClientConnection(Stream stream)
#endregion

#region ExecuteServlet()
private bool ExecuteServlet(Stream stream, string urlPath, Uri url, string data)
private bool ExecuteServlet(Stream stream, string urlPath, Uri url, string data, Dictionary<string,string> header)
{
var unprotectedServlets = new[] { "/", "/version", "/bringToFront", "/scripts", "/repository.json" };
// Check that the user agent is Awesomium and not a regular browser
// This should prevent abuse of extraQL URLs embedded in regular web pages
if (!bindToAllInterfaces && Array.IndexOf(unprotectedServlets, urlPath) < 0)
{
string userAgent;
if (!header.TryGetValue("User-Agent", out userAgent) || !userAgent.Contains("Awesomium"))
{
var b = enc.GetBytes("HTTP/1.1 401 Unauthorized\r\n\r\nextraQL URLs may only be called from within QuakeLive scripts");
stream.Write(b, 0, b.Length);
return true;
}
}

foreach (var entry in servlets)
{
if (entry.Key == urlPath || urlPath.StartsWith(entry.Key + "/"))
Expand Down
2 changes: 1 addition & 1 deletion source/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace ExtraQL
{
public partial class MainForm : Form
{
public const string Version = "2.4";
public const string Version = "2.4.1";

private readonly Config config;
private readonly HttpServer server;
Expand Down

0 comments on commit 5a2919b

Please sign in to comment.