Download SSL Certificates
Sort Subtasks of Markdown files
This commit is contained in:
parent
aa6a3405fd
commit
440b0d2290
19
.vscode/launch.json
vendored
19
.vscode/launch.json
vendored
@ -13,15 +13,16 @@
|
||||
"args": [
|
||||
"s",
|
||||
"X",
|
||||
"L:/",
|
||||
"Day-Helper-2024-07-11",
|
||||
"config",
|
||||
"refs/remotes/gitea",
|
||||
"http",
|
||||
"gitea",
|
||||
"https://51f44975c8734522b2dec36c6d9a116276c6bded@gitea.ddns.net/phares3757/",
|
||||
".git",
|
||||
"master"
|
||||
"D:/5-Other-Small/Proxmox/Day-Helper-2024-07-28",
|
||||
"Day-Helper-2024-07-28",
|
||||
"ddns.net",
|
||||
"dashkiosk,gitea,ha,immich,music,odoo,pihole,phares,pgadmin,quartz,slideshow,umbrel,vaultwarden",
|
||||
"C:/Program Files/Git/mingw64/bin/openssl.exe",
|
||||
"12345",
|
||||
"-----BEGIN CERTIFICATE",
|
||||
"END CERTIFICATE-----",
|
||||
"certutil -addstore",
|
||||
"Root"
|
||||
],
|
||||
"cwd": "${workspaceFolder}",
|
||||
"console": "integratedTerminal",
|
||||
|
@ -6,6 +6,7 @@ namespace File_Folder_Helper.Day;
|
||||
internal static partial class Helper20240623
|
||||
{
|
||||
|
||||
private record SubTaskLine(string Text, bool Done, long? Ticks, int? Line);
|
||||
private record Record(int? CodeInsidersLine, string File, string[] Lines, int? StopLine, int? SubTasksLine);
|
||||
|
||||
private static List<Record> GetRecords(string sourceDirectory, string searchPattern, string codeInsiders, string subTasks)
|
||||
@ -53,15 +54,18 @@ internal static partial class Helper20240623
|
||||
return results;
|
||||
}
|
||||
|
||||
private static ReadOnlyCollection<string> GetSubTasks(string subTasks, string[] tasks, bool? foundDone, string fallbackLine, string checkFile)
|
||||
private static ReadOnlyCollection<SubTaskLine> GetSubTasks(string subTasks, string[] tasks, bool? foundDone, string fallbackLine, FileInfo fileInfo)
|
||||
{
|
||||
List<string> results = [];
|
||||
List<SubTaskLine> results = [];
|
||||
string line;
|
||||
bool doneValue;
|
||||
string? h1 = null;
|
||||
bool foundSubTasks = false;
|
||||
int tasksZeroLength = tasks[0].Length;
|
||||
string[] lines = File.ReadAllLines(checkFile);
|
||||
foreach (string line in lines)
|
||||
string[] lines = File.ReadAllLines(fileInfo.FullName);
|
||||
for (int i = 0; i < lines.Length; i++)
|
||||
{
|
||||
line = lines[i];
|
||||
if (line.StartsWith("# "))
|
||||
h1 = line[2..];
|
||||
if (!foundSubTasks && line == subTasks)
|
||||
@ -70,36 +74,40 @@ internal static partial class Helper20240623
|
||||
continue;
|
||||
if (line.Length <= tasksZeroLength || !line.StartsWith(tasks[0]) || line[tasksZeroLength] is not ' ' and not 'x' || line[tasksZeroLength + 1] != ']')
|
||||
continue;
|
||||
results.Add($" {line}");
|
||||
doneValue = foundDone is not null && foundDone.Value;
|
||||
results.Add(new($" {line}", doneValue, fileInfo.LastWriteTime.Ticks, i));
|
||||
}
|
||||
doneValue = foundDone is not null && foundDone.Value;
|
||||
if (h1 is null)
|
||||
results.Insert(0, fallbackLine);
|
||||
results.Add(new(fallbackLine, doneValue, fileInfo.LastWriteTime.Ticks, Line: null));
|
||||
else
|
||||
results.Insert(0, foundDone is null || !foundDone.Value ? $"- [ ] {h1}" : $"- [x] {h1}");
|
||||
results.Add(new(foundDone is null || !foundDone.Value ? $"- [ ] {fileInfo.LastWriteTime.Ticks} ~~~ {h1}" : $"- [x] {fileInfo.LastWriteTime.Ticks} ~~~ {h1}", doneValue, fileInfo.LastWriteTime.Ticks, Line: 0));
|
||||
return new(results);
|
||||
}
|
||||
|
||||
internal static void UpdateSubTasksInMarkdownFiles(ILogger<Worker> logger, List<string> args)
|
||||
{
|
||||
int lineCheck;
|
||||
bool doneValue;
|
||||
bool? foundDone;
|
||||
string checkFile;
|
||||
FileInfo fileInfo;
|
||||
string[] newLines;
|
||||
string[] segments;
|
||||
List<string> lines;
|
||||
string[] indexLines;
|
||||
string fallbackLine;
|
||||
string[] indexLines;
|
||||
string checkDirectory;
|
||||
string done = args[7];
|
||||
List<string> indexFiles;
|
||||
string subTasks = args[3];
|
||||
List<string> newLines = [];
|
||||
List<string> oldLines = [];
|
||||
string indexFile = args[5];
|
||||
string searchPattern = args[2];
|
||||
string directoryFilter = args[8];
|
||||
ReadOnlyCollection<string> useLines;
|
||||
string[] tasks = args[6].Split(',');
|
||||
string codeInsiders = $"{args[4]} \"";
|
||||
List<SubTaskLine> allSubTaskLines = [];
|
||||
ReadOnlyCollection<SubTaskLine> subTaskLines;
|
||||
string sourceDirectory = Path.GetFullPath(args[0]);
|
||||
List<Record> records = GetRecords(sourceDirectory, searchPattern, codeInsiders, subTasks);
|
||||
foreach (Record record in from l in records orderby l.SubTasksLine is null, l.CodeInsidersLine is null select l)
|
||||
@ -136,8 +144,8 @@ internal static partial class Helper20240623
|
||||
}
|
||||
}
|
||||
foundDone = null;
|
||||
newLines.Clear();
|
||||
oldLines.Clear();
|
||||
allSubTaskLines.Clear();
|
||||
indexLines = File.ReadAllLines(indexFiles[0]);
|
||||
checkDirectory = Path.GetDirectoryName(indexFiles[0]) ?? throw new Exception();
|
||||
for (int i = 0; i < indexLines.Length; i++)
|
||||
@ -145,33 +153,38 @@ internal static partial class Helper20240623
|
||||
if (indexLines[i] == done)
|
||||
foundDone = true;
|
||||
segments = indexLines[i].Split(tasks[1]);
|
||||
doneValue = foundDone is not null && foundDone.Value;
|
||||
if (segments.Length > 2 || !segments[0].StartsWith(tasks[0]))
|
||||
continue;
|
||||
fallbackLine = foundDone is null || !foundDone.Value ? $"- [ ] {segments[0][tasks[0].Length..]}" : $"- [x] {segments[0][tasks[0].Length..]}";
|
||||
checkFile = Path.GetFullPath(Path.Combine(checkDirectory, segments[1][..^1]));
|
||||
if (!File.Exists(checkFile))
|
||||
fileInfo = new(Path.GetFullPath(Path.Combine(checkDirectory, segments[1][..^1])));
|
||||
if (!fileInfo.Exists)
|
||||
{
|
||||
newLines.Add(fallbackLine);
|
||||
allSubTaskLines.Add(new(fallbackLine, doneValue, Ticks: null, Line: null));
|
||||
continue;
|
||||
}
|
||||
useLines = GetSubTasks(subTasks, tasks, foundDone, fallbackLine, checkFile);
|
||||
newLines.AddRange(useLines);
|
||||
subTaskLines = GetSubTasks(subTasks, tasks, doneValue, fallbackLine, fileInfo);
|
||||
for (int j = subTaskLines.Count - 1; j >= 0; j--)
|
||||
allSubTaskLines.Add(subTaskLines[j]);
|
||||
}
|
||||
if (newLines.Count == 0)
|
||||
if (allSubTaskLines.Count == 0)
|
||||
continue;
|
||||
lineCheck = 0;
|
||||
newLines.Insert(0, string.Empty);
|
||||
for (int i = record.SubTasksLine.Value + 1; i < record.StopLine.Value - 1; i++)
|
||||
oldLines.Add(record.Lines[i]);
|
||||
if (newLines.Count == oldLines.Count)
|
||||
if (allSubTaskLines.Any(l => l.Ticks is null))
|
||||
newLines = (from l in allSubTaskLines select l.Text).ToArray();
|
||||
else
|
||||
newLines = (from l in allSubTaskLines orderby l.Done descending, l.Ticks, l.Line select l.Text).ToArray();
|
||||
if (newLines.Length == oldLines.Count)
|
||||
{
|
||||
for (int i = 0; i < newLines.Count; i++)
|
||||
for (int i = 0; i < newLines.Length; i++)
|
||||
{
|
||||
if (newLines[i] != record.Lines[record.SubTasksLine.Value + 1 + i])
|
||||
continue;
|
||||
lineCheck++;
|
||||
}
|
||||
if (lineCheck == newLines.Count)
|
||||
if (lineCheck == newLines.Length)
|
||||
continue;
|
||||
}
|
||||
checkDirectory = Path.Combine(checkDirectory, DateTime.Now.Ticks.ToString());
|
||||
@ -183,8 +196,9 @@ internal static partial class Helper20240623
|
||||
lines.RemoveAt(i);
|
||||
if (record.StopLine.Value == record.Lines.Length && lines[^1].Length == 0)
|
||||
lines.RemoveAt(lines.Count - 1);
|
||||
for (int i = 0; i < newLines.Count; i++)
|
||||
for (int i = 0; i < newLines.Length; i++)
|
||||
lines.Insert(record.SubTasksLine.Value + 1 + i, newLines[i]);
|
||||
lines.Insert(record.SubTasksLine.Value + 1, string.Empty);
|
||||
File.WriteAllLines(record.File, lines);
|
||||
}
|
||||
}
|
||||
|
64
Day/2024-Q3/Helper-2024-07-28.cs
Normal file
64
Day/2024-Q3/Helper-2024-07-28.cs
Normal file
@ -0,0 +1,64 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace File_Folder_Helper.Day;
|
||||
|
||||
internal static partial class Helper20240728
|
||||
{
|
||||
|
||||
internal static void DownloadSslCertificates(ILogger<Worker> logger, List<string> args)
|
||||
{
|
||||
string file;
|
||||
Process? process;
|
||||
string[] segments;
|
||||
string standardError;
|
||||
string standardOutput;
|
||||
string argumentSegment;
|
||||
string store = args[9];
|
||||
string domain = args[2];
|
||||
List<string> lines = [];
|
||||
string logSegment = args[8];
|
||||
string endCertificate = args[7];
|
||||
string beginCertificate = args[6];
|
||||
int waitForExit = int.Parse(args[5]);
|
||||
string[] subdomains = args[3].Split(',');
|
||||
string sourceDirectory = Path.GetFullPath(args[0]);
|
||||
ProcessStartInfo processStartInfo = new()
|
||||
{
|
||||
CreateNoWindow = true,
|
||||
RedirectStandardError = true,
|
||||
RedirectStandardOutput = true,
|
||||
UseShellExecute = false,
|
||||
FileName = args[4],
|
||||
WorkingDirectory = sourceDirectory
|
||||
};
|
||||
foreach (string subdomain in subdomains)
|
||||
{
|
||||
argumentSegment = $"{subdomain}.{domain}:443 -servername {subdomain}.{domain}";
|
||||
processStartInfo.Arguments = $"s_client -connect {subdomain}.{domain}:443 -servername {subdomain}.{domain}";
|
||||
process = Process.Start(processStartInfo);
|
||||
if (process is null)
|
||||
continue;
|
||||
_ = process.WaitForExit(waitForExit);
|
||||
process.Kill(entireProcessTree: true);
|
||||
standardOutput = process.StandardOutput.ReadToEnd();
|
||||
if (!standardOutput.Contains(beginCertificate) || !standardOutput.Contains(endCertificate))
|
||||
{
|
||||
standardError = process.StandardError.ReadToEnd();
|
||||
logger.LogWarning($"Error: {subdomain}{Environment.NewLine}{standardOutput}{Environment.NewLine}{standardError}");
|
||||
continue;
|
||||
}
|
||||
segments = standardOutput.Split(beginCertificate);
|
||||
if (segments.Length != 2)
|
||||
break;
|
||||
segments = segments[1].Split(endCertificate);
|
||||
if (segments.Length != 2)
|
||||
break;
|
||||
lines.Add($"{logSegment} \"{store}\" {subdomain}.{domain}.cert");
|
||||
file = Path.Combine(sourceDirectory, $"{subdomain}.{domain}.cert");
|
||||
File.WriteAllText(file, $"{beginCertificate}{segments[0]}{endCertificate}{Environment.NewLine}");
|
||||
}
|
||||
File.WriteAllLines(Path.Combine(sourceDirectory, $"{DateTime.Now.Ticks}.txt"), lines);
|
||||
}
|
||||
|
||||
}
|
@ -83,6 +83,8 @@ internal static class HelperDay
|
||||
Day.Helper20240718.JsonToMarkdown(logger, args);
|
||||
else if (args[1] == "Day-Helper-2024-07-24")
|
||||
Day.Helper20240724.CopyDirectories(logger, args);
|
||||
else if (args[1] == "Day-Helper-2024-07-28")
|
||||
Day.Helper20240728.DownloadSslCertificates(logger, args);
|
||||
else
|
||||
throw new Exception(appSettings.Company);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user