url_gen/Program.cs
2025-06-10 21:13:00 -05:00

77 lines
No EOL
1.9 KiB
C#

using System;
using System.Security.Cryptography;
using System.Text;
while (true)
{
Console.WriteLine("Select a server type:");
Console.WriteLine("1. PostgreSQL (psql)");
Console.WriteLine("2. Redis (redis)");
Console.WriteLine("3. RabbitMQ (rabbitmq)");
Console.WriteLine("4. Sandbox Web Server (sandbox)");
Console.WriteLine("5. Staging Web Server (staging)");
Console.WriteLine("q. Exit");
Console.WriteLine();
Console.Write(
"Enter a number (1-5) to select a server type, or 'q' to quit: "
);
string choice = Console.ReadLine();
if (choice?.ToLower() == "q")
{
break;
}
string prefix = choice switch
{
"1" => "psql",
"2" => "redis",
"3" => "rabbitmq",
"4" => "sandbox",
"5" => "staging",
_ => null
};
if (prefix == null)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.Write("Invalid choice. Please try again: ");
Console.ResetColor();
Console.WriteLine();
continue;
}
string randomUrl = GenerateRandomUrl(prefix);
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine($"Generated URL: {randomUrl}");
Console.ResetColor();
Console.WriteLine();
Console.WriteLine("Generate another URL? (y/n)");
string another = Console.ReadLine();
if (another?.ToLower() != "y")
{
break;
}
Console.WriteLine();
}
static string GenerateRandomUrl(string prefix, int length = 12)
{
const string alphabet = "abcdefghijklmnopqrstuvqxyz123456789";
var resultBuilder = new StringBuilder(length);
byte[] randomBytes = new byte[length];
RandomNumberGenerator.Fill(randomBytes);
foreach (byte b in randomBytes)
{
resultBuilder.Append(alphabet[b % alphabet.Length]);
}
string randomString = resultBuilder.ToString();
return $"{prefix}-{randomString}.rideaware.org";
}