-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
53d03d2
commit 0fd0077
Showing
12 changed files
with
153 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
using System.Net; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using System.Windows; | ||
using Common; | ||
|
||
namespace MLock.Modules | ||
{ | ||
internal class WebServer | ||
{ | ||
private CancellationTokenSource cts; | ||
private HttpListener listener; | ||
|
||
public async Task Initialize() | ||
{ | ||
listener = new HttpListener(); | ||
listener.Prefixes.Add("http://+:4444/"); | ||
|
||
listener.Start(); | ||
|
||
while (listener.IsListening) | ||
{ | ||
var context = await listener.GetContextAsync(); | ||
ProcessRequest(context); | ||
} | ||
|
||
listener.Stop(); | ||
} | ||
|
||
private void ProcessRequest(HttpListenerContext context) | ||
{ | ||
var password = context.Request.QueryString.Get("password"); | ||
if (password == null || password != Config.INSTANCE.WebServerPassword) | ||
{ | ||
context.Response.StatusCode = (int)HttpStatusCode.Unauthorized; | ||
context.Response.Close(); | ||
return; | ||
} | ||
|
||
switch (context.Request.Url.AbsolutePath) | ||
{ | ||
case "/lock": | ||
Events.Lock(); | ||
break; | ||
case "/unlock": | ||
Events.Unlock(); | ||
break; | ||
} | ||
|
||
context.Response.StatusCode = (int)HttpStatusCode.OK; | ||
|
||
context.Response.Close(); | ||
} | ||
|
||
private void StopServer(object sender, RoutedEventArgs e) // I am guessing server gets closed automatically when the program closes | ||
{ | ||
cts?.Cancel(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,23 @@ | ||
namespace MLockUSBKeyGenerator | ||
using System.Windows; | ||
using System; | ||
|
||
namespace MLockUSBKeyGenerator | ||
{ | ||
/// <summary> | ||
/// Interaction logic for App.xaml | ||
/// </summary> | ||
public partial class App | ||
{ | ||
public App() | ||
{ | ||
if (!Utils.IsAdmin()) | ||
{ | ||
MessageBox.Show("Configurator requires administrative privileges to properly save the config file. Please run the program as an administrator.", "Admin Privileges Required", MessageBoxButton.OK, MessageBoxImage.Warning); | ||
Environment.Exit(0); | ||
return; | ||
} | ||
|
||
InitializeComponent(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters