Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/Launch/Options.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,8 @@ public class Options : IVerb

[Option('p', "preview", Required = false, HelpText = "Show me what will launch, but dont run it. This will also report the token values and show the contents of the generated file, if applicable.")]
public bool Preview { get; set; }

[Option("debug", Required = false, HelpText = "Keep the console window visible for troubleshooting.")]
public bool Debug { get; set; }
}
}
14 changes: 7 additions & 7 deletions src/OneIdentity.Scalus.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace>OneIdentity.Scalus</RootNamespace>
<AssemblyName>scalus</AssemblyName>
<StartupObject>OneIdentity.Scalus.Program</StartupObject>
<SignAssembly>false</SignAssembly>
<AssemblyOriginatorKeyFile>signer.pfx</AssemblyOriginatorKeyFile>
<TypeScriptToolsVersion>Latest</TypeScriptToolsVersion>
<RuntimeIdentifiers>linux-x64;osx-x64;win10-x64</RuntimeIdentifiers>
<RuntimeIdentifiers>linux-x64;osx-x64;win-x64</RuntimeIdentifiers>
<UserSecretsId>dc8f57ba-8a9d-40c4-bf34-a2ffba1ff687</UserSecretsId>
<Company>One Identity LLC</Company>
<Copyright>Copyright 2021 One Identity LLC</Copyright>
Expand All @@ -38,11 +38,11 @@

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DefineConstants>$(DefineConstants);TRACE</DefineConstants>
<NoWarn>1701;1702;CA1416</NoWarn>
<NoWarn>1701;1702;CA1416;CA1854;CA1860;CA1865;SYSLIB1045;SYSLIB1054</NoWarn>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<NoWarn>1701;1702;CA1416</NoWarn>
<NoWarn>1701;1702;CA1416;CA1854;CA1860;CA1865;SYSLIB1045;SYSLIB1054</NoWarn>
</PropertyGroup>

<ItemGroup>
Expand Down Expand Up @@ -116,9 +116,9 @@
<PackageReference Include="Autofac" Version="6.4.0" />
<PackageReference Include="Autofac.Extensions.DependencyInjection" Version="8.0.0" />
<PackageReference Include="CommandLineParser" Version="2.9.1" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="6.0.9" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="8.0.12" />
<PackageReference Include="Microsoft.Win32.Registry" Version="5.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Serilog" Version="2.12.0" />
<PackageReference Include="Serilog.AspNetCore" Version="6.0.1" />
<PackageReference Include="Serilog.Sinks.Console" Version="4.1.0" />
Expand All @@ -131,7 +131,7 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="System.Reactive" Version="5.0.0" />
<PackageReference Include="System.Security.Cryptography.ProtectedData" Version="6.0.0" />
<PackageReference Include="System.Security.Cryptography.ProtectedData" Version="8.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
63 changes: 60 additions & 3 deletions src/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="Program.cs" company="One Identity Inc.">
// This software is licensed under the Apache 2.0 open source license.
// https://github.com/OneIdentity/SCALUS/blob/master/LICENSE
Expand All @@ -24,6 +24,7 @@ namespace OneIdentity.Scalus
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Threading;
Expand All @@ -37,8 +38,28 @@ namespace OneIdentity.Scalus

internal class Program
{
private static bool consoleHidden;

[DllImport("kernel32.dll", SetLastError = true)]
private static extern bool FreeConsole();

private static int Main(string[] args)
{
// On Windows, detach from the console for 'launch' and 'ui' verbs so no console
// window is visible. When launched from a browser/Explorer, the console window
// (which was created just for this process) is destroyed. (GitHub issue #131)
// CLI commands (info, register, --help, etc.) keep the console as normal.
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && ShouldHideConsole(args))
{
FreeConsole();
consoleHidden = true;

// Redirect stdout/stderr to nowhere so that subsequent Console.WriteLine
// and Serilog console sinks don't throw on the invalid handle.
Console.SetOut(TextWriter.Null);
Console.SetError(TextWriter.Null);
}
Comment on lines +52 to +61

bool community = false;
#if COMMUNITY_EDITION
community = true;
Expand All @@ -51,7 +72,13 @@ private static int Main(string[] args)
try
{
// Register components with autofac
var logger = new LoggerConfiguration().WriteTo.Console(theme: ConsoleTheme.None).CreateLogger();
var logConfig = new LoggerConfiguration().WriteTo.File(ConfigurationManager.LogFile, shared: true);
if (!consoleHidden)
{
logConfig.WriteTo.Console(theme: ConsoleTheme.None);
}

var logger = logConfig.CreateLogger();
using var container = Ioc.RegisterApplication(logger);
using var lifetimeScope = container.BeginLifetimeScope();
services = lifetimeScope.Resolve<IOsServices>();
Expand Down Expand Up @@ -117,6 +144,36 @@ private static void ReleaseLaunchSemaphore()
}
}

private static bool ShouldHideConsole(string[] args)
{
if (args.Length == 0)
{
// No verb defaults to 'ui'
return true;
}

// --debug or -p/--preview flags keep the console visible for troubleshooting
if (args.Any(a => string.Equals(a, "--debug", StringComparison.OrdinalIgnoreCase) ||
string.Equals(a, "--preview", StringComparison.OrdinalIgnoreCase) ||
string.Equals(a, "-p", StringComparison.OrdinalIgnoreCase)))
{
return false;
}

// Don't hide the console when the user explicitly requests help/version output.
if (args.Any(a =>
string.Equals(a, "--help", StringComparison.OrdinalIgnoreCase) ||
string.Equals(a, "-h", StringComparison.OrdinalIgnoreCase) ||
string.Equals(a, "--version", StringComparison.OrdinalIgnoreCase) ||
string.Equals(a, "-v", StringComparison.OrdinalIgnoreCase)))
{
return false;
}

return string.Equals(args[0], "launch", StringComparison.OrdinalIgnoreCase) ||
string.Equals(args[0], "ui", StringComparison.OrdinalIgnoreCase);
}

private static void HandleUnexpectedError(Exception ex)
{
Serilog.Log.Error($"Unexpected error: {ex.Message}", ex);
Expand Down Expand Up @@ -186,7 +243,7 @@ private static void ConfigureLogging()
config.MinimumLevel.ControlledBy(new Serilog.Core.LoggingLevelSwitch(ConfigurationManager.MinLogLevel.Value));
}

if (ConfigurationManager.LogToConsole)
if (!consoleHidden && ConfigurationManager.LogToConsole)
{
config.WriteTo.Console();
}
Expand Down
2 changes: 2 additions & 0 deletions src/Ui/Options.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,7 @@ namespace OneIdentity.Scalus.Ui
[Verb("ui", isDefault: true, HelpText = "Run the configuration UI")]
public class Options : IVerb
{
[Option("debug", Required = false, HelpText = "Keep the console window visible for troubleshooting.")]
public bool Debug { get; set; }
}
}
12 changes: 3 additions & 9 deletions src/UrlParser/DefaultRdpUrlParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -292,15 +292,9 @@ private static X509Certificate2 CreateScalusSigningCert(IOsServices services)
var res = services.Execute("powershell",
new List<string>
{
"New-SelfSignedCertificate",
"-Subject",
"SCALUS",
"-NotAfter",
"(Get-Date).AddYears(5)",
"-KeyUsage",
"DigitalSignature",
"-CertStoreLocation",
"Cert:\\CurrentUser\\My",
"-NoProfile",
"-Command",
"Import-Module PKI; New-SelfSignedCertificate -Subject SCALUS -NotAfter (Get-Date).AddYears(5) -KeyUsage DigitalSignature -CertStoreLocation Cert:\\CurrentUser\\My",
},
out output,
out err);
Expand Down
6 changes: 3 additions & 3 deletions test/OneIdentity.Scalus.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
</PropertyGroup>

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<IsPackable>false</IsPackable>
<SignAssembly>false</SignAssembly>
<AssemblyOriginatorKeyFile>signer.pfx</AssemblyOriginatorKeyFile>
<DelaySign>false</DelaySign>
<OutputType>WinExe</OutputType>
<RootNamespace>OneIdentity.Scalus.Test</RootNamespace>
<RuntimeIdentifiers>linux-x64;osx-x64;win10-x64</RuntimeIdentifiers>
<RuntimeIdentifiers>linux-x64;osx-x64;win-x64</RuntimeIdentifiers>
<EnableWindowsTargeting>true</EnableWindowsTargeting>
</PropertyGroup>

Expand All @@ -29,7 +29,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<PrivateAssets>all</PrivateAssets>
Expand Down
Loading