Add system extensions
This commit is contained in:
parent
61f4a0abac
commit
694e4ea311
|
@ -42,12 +42,4 @@
|
|||
<ProjectReference Include="..\CodeLiturgy.Domain\CodeLiturgy.Domain.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Include="appsettings.json">
|
||||
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
@ -1,22 +0,0 @@
|
|||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*",
|
||||
"ConnectionStringDocker": {
|
||||
"MySQL": "server=db;user=blueuser;password=dXjw127124dJ;database=bluedb;"
|
||||
},
|
||||
"ConnectionStringNoDocker": {
|
||||
"MySQL": "server=localhost;user=blueuser;password=dXjw127124dJ;database=bluedb;"
|
||||
},
|
||||
"AuthSettings": {
|
||||
"SecretKey": "iJWHDmHLpUA283sqsfhqGbMRdRj1PVkH"
|
||||
},
|
||||
"JwtIssuerOptions": {
|
||||
"Issuer": "SomeIssuer",
|
||||
"Audience": "http://localhost:5000"
|
||||
}
|
||||
}
|
|
@ -5,6 +5,7 @@
|
|||
<Nullable>disable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
|
||||
<PublishTrimmed>true</PublishTrimmed>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
@ -14,6 +15,7 @@
|
|||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting.Systemd" Version="7.0.0" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\CodeLiturgy.Data.Auth\CodeLiturgy.Data.Auth.csproj" />
|
||||
|
|
|
@ -32,7 +32,7 @@ namespace BlueWest.WebApi
|
|||
|
||||
private static IHostBuilder CreateHostBuilder(string[] args) =>
|
||||
Host.CreateDefaultBuilder(args)
|
||||
|
||||
.UseSystemd()
|
||||
.ConfigureWebHostDefaults(webBuilder =>
|
||||
{
|
||||
webBuilder.UseStartup<Startup>();
|
||||
|
|
|
@ -0,0 +1,56 @@
|
|||
using System.Diagnostics;
|
||||
|
||||
namespace CodeLiturgy.Views
|
||||
{
|
||||
public static class SystemExtensions
|
||||
{
|
||||
public static void ExecuteCommand(string command)
|
||||
{
|
||||
Process proc = new();
|
||||
proc.StartInfo.FileName = "/bin/bash";
|
||||
proc.StartInfo.Arguments = "-c \" " + command + " \"";
|
||||
proc.StartInfo.UseShellExecute = false;
|
||||
proc.StartInfo.RedirectStandardOutput = true;
|
||||
proc.Start ();
|
||||
while (!proc.StandardOutput.EndOfStream) {
|
||||
Console.WriteLine (proc.StandardOutput.ReadLine ());
|
||||
}
|
||||
}
|
||||
|
||||
public static void AddUser(
|
||||
string username,
|
||||
bool createHome,
|
||||
bool useSudo)
|
||||
{
|
||||
var sudoStr = useSudo ? "sudo" : "";
|
||||
var createHomeStr = createHome ? "-m" : "";
|
||||
var addUser = $"{sudoStr} useradd {createHomeStr} {username}";
|
||||
var deletePass = $"{sudoStr} passwd -d {username}";
|
||||
var lockPass = $"{sudoStr} passwd -l {username} ";
|
||||
|
||||
ExecuteCommand(addUser);
|
||||
ExecuteCommand(deletePass);
|
||||
ExecuteCommand(lockPass);
|
||||
}
|
||||
|
||||
|
||||
public static void DeleteUser(
|
||||
string username,
|
||||
bool deleteHome,
|
||||
bool useSudo)
|
||||
{
|
||||
var sudo = useSudo ? "sudo" : "";
|
||||
var rmUser = $"{sudo} userdel {username}";
|
||||
ExecuteCommand(rmUser);
|
||||
|
||||
if (deleteHome)
|
||||
{
|
||||
var delHome = $"{sudo} rm -rf /home/{username}";
|
||||
ExecuteCommand(delHome);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue