Skip to content

Commit

Permalink
Accept API server connection from any host. Updated version to 2.8.
Browse files Browse the repository at this point in the history
  • Loading branch information
sabaatworld committed Jan 8, 2022
1 parent fbb0e96 commit 596c8ee
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 11 deletions.
10 changes: 8 additions & 2 deletions HyperionScreenCap.sln
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30011.22
# Visual Studio Version 17
VisualStudioVersion = 17.0.32014.148
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HyperionScreenCap", "HyperionScreenCap\HyperionScreenCap.csproj", "{9EC68860-AE7E-413F-A5A4-AC31B93912C2}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|x86 = Debug|x86
Release|Any CPU = Release|Any CPU
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{9EC68860-AE7E-413F-A5A4-AC31B93912C2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9EC68860-AE7E-413F-A5A4-AC31B93912C2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9EC68860-AE7E-413F-A5A4-AC31B93912C2}.Debug|x86.ActiveCfg = Debug|x86
{9EC68860-AE7E-413F-A5A4-AC31B93912C2}.Debug|x86.Build.0 = Debug|x86
{9EC68860-AE7E-413F-A5A4-AC31B93912C2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9EC68860-AE7E-413F-A5A4-AC31B93912C2}.Release|Any CPU.Build.0 = Release|Any CPU
{9EC68860-AE7E-413F-A5A4-AC31B93912C2}.Release|x86.ActiveCfg = Release|x86
{9EC68860-AE7E-413F-A5A4-AC31B93912C2}.Release|x86.Build.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
66 changes: 66 additions & 0 deletions HyperionScreenCap/ApiServer.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
using System.Diagnostics;
using System.Security.Principal;
using Grapevine.Interfaces.Server;
using Grapevine.Server;
using Grapevine.Server.Attributes;
Expand All @@ -23,6 +25,13 @@ public void StartServer(string hostname, string port)
{
try
{
LOG.Info("Checking if ACL URL is reserved");
if (!IsAclUrlReserved(hostname, port))
{
LOG.Info("ACL URL not reserved. Attempting to reserve.");
ReserveAclUrl(hostname, port);
}

if ( _server == null )
{
LOG.Info($"Starting API server: {hostname}:{port}");
Expand Down Expand Up @@ -115,5 +124,62 @@ private IHttpContext API(IHttpContext context)
context.Response.SendResponse(responseText);
return context;
}

private string GetAclUrl(string hostname, string port)
{
return "http://" + hostname + ":" + port + "/";
}

private bool IsAclUrlReserved(string hostname, string port)
{
var aclUrl = GetAclUrl(hostname, port);
ProcessStartInfo processStartInfo = new ProcessStartInfo
{
FileName = "netsh.exe",
UseShellExecute = false,
Arguments = $"http show urlacl url={aclUrl}",
WindowStyle = ProcessWindowStyle.Hidden,
RedirectStandardOutput = true
};
LOG.Info($"Starting process: {processStartInfo.FileName} {processStartInfo.Arguments}");
var process = Process.Start(processStartInfo);
process.WaitForExit();
var output = process.StandardOutput.ReadToEnd();
/*
* Sample output:
*
* ACL URL Not Reserved:
* URL Reservations:
* -----------------
*
* ACL URL Reserved:
* URL Reservations:
* -----------------
*
* Reserved URL : http://+:9191/
* User: DOMAIN\user
* Listen: Yes
* Delegate: No
* SDDL: D:(A;;GX;;;S-1-5-21-566402754-1856570991-3730105997-1001)
*/
return output.Contains(aclUrl);
}

private void ReserveAclUrl(string hostname, string port)
{
var aclUrl = GetAclUrl(hostname, port);
var user = WindowsIdentity.GetCurrent().Name;
ProcessStartInfo processStartInfo = new ProcessStartInfo
{
FileName = "netsh.exe",
UseShellExecute = true,
Arguments = $"http add urlacl url={aclUrl} user={user}",
WindowStyle = ProcessWindowStyle.Hidden,
Verb = "runas",
};
LOG.Info($"Starting elevated process: {processStartInfo.FileName} {processStartInfo.Arguments}");
var process = Process.Start(processStartInfo);
process.WaitForExit();
}
}
}
8 changes: 3 additions & 5 deletions HyperionScreenCap/Form/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,13 @@ public void Init(bool reInit = false, bool forceOn = false)
ToggleCapture(CaptureCommand.ON);
}

_apiServer?.StopServer(); // Always stop current server before starting again
if ( SettingsManager.ApiEnabled )
{
_apiServer = new ApiServer(this);
_apiServer.StartServer("localhost", SettingsManager.ApiPort.ToString());
}
else
{
_apiServer?.StopServer();
_apiServer.StartServer("+", SettingsManager.ApiPort.ToString());
}

_initLock = false;
LOG.Info("Initialization lock unset");
}
Expand Down
21 changes: 21 additions & 0 deletions HyperionScreenCap/HyperionScreenCap.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,27 @@
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x86\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x86</PlatformTarget>
<LangVersion>7.3</LangVersion>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
<OutputPath>bin\x86\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x86</PlatformTarget>
<LangVersion>7.3</LangVersion>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="Costura, Version=4.1.0.0, Culture=neutral, PublicKeyToken=9919ef960d84173d, processorArchitecture=MSIL">
<HintPath>..\packages\Costura.Fody.4.1.0\lib\net40\Costura.dll</HintPath>
Expand Down
6 changes: 3 additions & 3 deletions HyperionScreenCap/Installation Files/InstallScript.iss
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!

#define MyAppName "Hyperion Screen Capture"
#define MyAppVersion "2.7"
#define MyAppVersion "2.8"
#define MyAppPublisher "@sabaatworld"
#define MyAppURL "https://github.com/sabaatworld/HyperionScreenCap"
#define MyAppUpdatesURL "https://github.com/sabaatworld/HyperionScreenCap/releases"
Expand Down Expand Up @@ -67,8 +67,8 @@ Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{
Name: "quicklaunchicon"; Description: "{cm:CreateQuickLaunchIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked; OnlyBelowVersion: 0,6.1

[Files]
Source: "..\bin\Release\HyperionScreenCap.exe"; DestDir: "{app}"; Flags: ignoreversion
Source: "..\bin\Release\HyperionScreenCap.exe.config"; DestDir: "{app}"; Flags: ignoreversion
Source: "..\bin\x86\Release\HyperionScreenCap.exe"; DestDir: "{app}"; Flags: ignoreversion
Source: "..\bin\x86\Release\HyperionScreenCap.exe.config"; DestDir: "{app}"; Flags: ignoreversion
; NOTE: Don't use "Flags: ignoreversion" on any shared system files

[Icons]
Expand Down
Binary file not shown.
2 changes: 1 addition & 1 deletion HyperionScreenCap/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2.7.0.0")]
[assembly: AssemblyVersion("2.8.0.0")]
//[assembly: AssemblyFileVersion("2.0.0.0")] Commented out so that it will be generated automatically

0 comments on commit 596c8ee

Please sign in to comment.