using Febe.App;
using Febe.Core.Library;
using Febe.Web.Connection;
namespace Febe.Server;
///
/// The checks made before anything starts (spec §8.2, §11): the interface password and the Data folder. With a problem
/// the engine and the browser do not start, and the interface shows only the page that explains it.
///
internal static class StartupChecks
{
public const string PasswordMissing = "password-mancante";
public const string DataNotWritable = DataFolderProblems.DataNotWritable;
public const string DataOnNetwork = DataFolderProblems.DataOnNetwork;
/// Every problem found, in the order the error page shows them.
public static IReadOnlyList Run(ServerOptions options, DataFolderCheck? check = null)
{
ArgumentNullException.ThrowIfNull(options);
var problems = new List();
if (string.IsNullOrEmpty(options.Password))
{
problems.Add(new ConfigurationProblem(
PasswordMissing,
"Manca la password dell'interfaccia",
"Il contenitore è partito senza la variabile FEBE_PASSWORD. Senza password l'interfaccia, e con lei la vista "
+ "remota del browser, sarebbe aperta a chiunque raggiunga il server: per questo Febe non ha avviato né il motore né il browser.",
"Imposta FEBE_PASSWORD (nel modello di Unraid o in compose.yml) con una frase lunga che usi solo qui, poi riavvia il contenitore."));
}
if (DataFolderProblems.Check(options.DataFolder, check) is { } data)
{
problems.Add(data);
}
return problems;
}
}