diff --git a/internal/controllers/webserver/handlers/computers.go b/internal/controllers/webserver/handlers/computers.go index f330231..6e7274c 100644 --- a/internal/controllers/webserver/handlers/computers.go +++ b/internal/controllers/webserver/handlers/computers.go @@ -2442,7 +2442,7 @@ func (h *Handler) CreateWindowsTaskConfig(t *openuem_ent.Task) (*wingetcfg.WinGe } cfg.AddResource(msiUninstall) case task.TypePowershellScript: - msiUninstall, err := wingetcfg.ExecutePowershellScript(taskID, t.Name, t.Script, t.ScriptRun.String()) + msiUninstall, err := wingetcfg.ExecutePowershellScript(taskID, t.Name, t.Script, t.ScriptRun.String(), t.ScriptExecutable) if err != nil { return nil, err } diff --git a/internal/controllers/webserver/handlers/tasks.go b/internal/controllers/webserver/handlers/tasks.go index 4540cc9..ec6d379 100644 --- a/internal/controllers/webserver/handlers/tasks.go +++ b/internal/controllers/webserver/handlers/tasks.go @@ -792,6 +792,12 @@ func validatePowerShellScript(c echo.Context) (*models.TaskConfig, error) { return nil, errors.New(i18n.T(c.Request().Context(), "tasks.shell_wrong_run_config")) } + taskConfig.ShellExecute = c.FormValue("powershell-executable") + validEngines := []string{"", "powershell", "pwsh", "auto"} + if taskType == "powershell_type" && !slices.Contains(validEngines, taskConfig.ShellExecute) { + return nil, errors.New(i18n.T(c.Request().Context(), "tasks.shell_wrong_run_config")) + } + return &taskConfig, nil } diff --git a/internal/models/tasks.go b/internal/models/tasks.go index 186ddc0..3d18691 100644 --- a/internal/models/tasks.go +++ b/internal/models/tasks.go @@ -235,7 +235,7 @@ func (m *Model) AddTaskToProfile(c echo.Context, profileID int, cfg TaskConfig) return query.Exec(context.Background()) case task.TypePowershellScript.String(): return query. - SetScript(cfg.ShellScript).SetScriptRun(task.ScriptRun(cfg.ShellRunConfig)).Exec(context.Background()) + SetScript(cfg.ShellScript).SetScriptRun(task.ScriptRun(cfg.ShellRunConfig)).SetScriptExecutable(cfg.ShellExecute).Exec(context.Background()) case task.TypeUnixScript.String(): return query. SetScript(cfg.ShellScript).SetScriptCreates(cfg.ShellCreates).SetScriptExecutable(cfg.ShellExecute).Exec(context.Background()) @@ -391,7 +391,7 @@ func (m *Model) UpdateProfileTask(c echo.Context, taskID int, cfg TaskConfig) er } return query.Exec(context.Background()) case task.TypePowershellScript.String(): - return query.SetScript(cfg.ShellScript).SetScriptRun(task.ScriptRun(cfg.ShellRunConfig)).Exec(context.Background()) + return query.SetScript(cfg.ShellScript).SetScriptRun(task.ScriptRun(cfg.ShellRunConfig)).SetScriptExecutable(cfg.ShellExecute).Exec(context.Background()) case task.TypeUnixScript.String(): return query.SetScript(cfg.ShellScript).SetScriptCreates(cfg.ShellCreates).SetScriptExecutable(cfg.ShellExecute).Exec(context.Background()) case task.TypeFlatpakInstall.String(), task.TypeFlatpakUninstall.String(): diff --git a/internal/views/locales/ca.yaml b/internal/views/locales/ca.yaml index 1031a69..bf3937f 100644 --- a/internal/views/locales/ca.yaml +++ b/internal/views/locales/ca.yaml @@ -1318,6 +1318,10 @@ ca: shell_run_once: "Executeu només una vegada si té èxit" shell_run_always: "Executeu cada vegada que s'aplica el perfil" shell_wrong_run_config: "La configuració d'execució no és vàlida" + powershell_executable: "Motor de PowerShell" + powershell_engine_51: "Windows PowerShell 5.1" + powershell_engine_7: "PowerShell 7+ (pwsh)" + powershell_engine_auto: "Auto (utilitza PowerShell 7+ si està disponible, si no 5.1)" task_agent: "OS de l'agent" task_agent_description: "Especifiqueu l'agent del sistema operatiu..." wrong_agenttype: "El tipus d'agent no és vàlid" diff --git a/internal/views/locales/de.yaml b/internal/views/locales/de.yaml index beca6f0..5884702 100644 --- a/internal/views/locales/de.yaml +++ b/internal/views/locales/de.yaml @@ -1318,6 +1318,10 @@ de: shell_run_once: "Nur einmal ausführen, wenn erfolgreich" shell_run_always: "Bei jeder Anwendung des Profils ausführen" shell_wrong_run_config: "Ungültige Ausführungskonfiguration" + powershell_executable: "PowerShell-Engine" + powershell_engine_51: "Windows PowerShell 5.1" + powershell_engine_7: "PowerShell 7+ (pwsh)" + powershell_engine_auto: "Auto (PowerShell 7+ verwenden, falls verfügbar, sonst 5.1)" task_agent: "Betriebssystem des Agents" task_agent_description: "Geben Sie das Betriebssystem des Agents an..." wrong_agenttype: "Ungültiger Agent-Typ" diff --git a/internal/views/locales/en.yaml b/internal/views/locales/en.yaml index 5297a06..284dfec 100644 --- a/internal/views/locales/en.yaml +++ b/internal/views/locales/en.yaml @@ -1318,6 +1318,10 @@ en: shell_run_once: "Run only once if successful" shell_run_always: "Run every time the profile is applied" shell_wrong_run_config: "Run configuration is not valid" + powershell_executable: "PowerShell engine" + powershell_engine_51: "Windows PowerShell 5.1" + powershell_engine_7: "PowerShell 7+ (pwsh)" + powershell_engine_auto: "Auto (use PowerShell 7+ if available, otherwise 5.1)" task_agent: "Agent's OS" task_agent_description: "Specify the OS agent..." wrong_agenttype: "Agent's type is not valid" diff --git a/internal/views/locales/es.yaml b/internal/views/locales/es.yaml index 58bce46..e345e1e 100644 --- a/internal/views/locales/es.yaml +++ b/internal/views/locales/es.yaml @@ -1318,6 +1318,10 @@ es: shell_run_once: "Ejecutar solo una vez si tiene éxito" shell_run_always: "Ejecutar cada vez que se aplique el perfil" shell_wrong_run_config: "La configuración de ejecución no es válida" + powershell_executable: "Motor de PowerShell" + powershell_engine_51: "Windows PowerShell 5.1" + powershell_engine_7: "PowerShell 7+ (pwsh)" + powershell_engine_auto: "Auto (usar PowerShell 7+ si está disponible, si no 5.1)" task_agent: "S.O del agente" task_agent_description: "Especifique el S.O del agente..." wrong_agenttype: "El tipo de agente no es válido" diff --git a/internal/views/locales/fr.yaml b/internal/views/locales/fr.yaml index 1b6f55f..402a078 100644 --- a/internal/views/locales/fr.yaml +++ b/internal/views/locales/fr.yaml @@ -1318,6 +1318,10 @@ fr: shell_run_once: "Exécuter une seule fois si réussi" shell_run_always: "Exécuter chaque fois que le profil est appliqué" shell_wrong_run_config: "La configuration d'exécution n'est pas valide" + powershell_executable: "Moteur PowerShell" + powershell_engine_51: "Windows PowerShell 5.1" + powershell_engine_7: "PowerShell 7+ (pwsh)" + powershell_engine_auto: "Auto (utiliser PowerShell 7+ si disponible, sinon 5.1)" task_agent: "Système d'exploitation de l'agent" task_agent_description: "Spécifier l'agent du système d'exploitation..." wrong_agenttype: "Le type d'agent n'est pas valide" diff --git a/internal/views/locales/no.yaml b/internal/views/locales/no.yaml index fc6def1..ced7884 100644 --- a/internal/views/locales/no.yaml +++ b/internal/views/locales/no.yaml @@ -1318,6 +1318,10 @@ no: shell_run_once: "Kjør bare én gang hvis vellykket" shell_run_always: "Kjør hver gang profilen brukes" shell_wrong_run_config: "Kjøringskonfigurasjon er ikke gyldig" + powershell_executable: "PowerShell-motor" + powershell_engine_51: "Windows PowerShell 5.1" + powershell_engine_7: "PowerShell 7+ (pwsh)" + powershell_engine_auto: "Auto (bruk PowerShell 7+ hvis tilgjengelig, ellers 5.1)" task_agent: "Agentens OS" task_agent_description: "Spesifiser OS-agenten..." wrong_agenttype: "Agenttype er ikke gyldig" diff --git a/internal/views/locales/pt.yaml b/internal/views/locales/pt.yaml index c220172..cb777bb 100644 --- a/internal/views/locales/pt.yaml +++ b/internal/views/locales/pt.yaml @@ -1318,6 +1318,10 @@ pt: shell_run_once: "Executar apenas uma vez se bem-sucedido" shell_run_always: "Executar toda vez que o perfil for aplicado" shell_wrong_run_config: "Configuração de execução não é válida" + powershell_executable: "Motor do PowerShell" + powershell_engine_51: "Windows PowerShell 5.1" + powershell_engine_7: "PowerShell 7+ (pwsh)" + powershell_engine_auto: "Auto (usar PowerShell 7+ se disponível, senão 5.1)" task_agent: "SO do Agente" task_agent_description: "Especifique o agente do SO..." wrong_agenttype: "Tipo de agente não é válido" diff --git a/internal/views/partials/powershell.partials.templ b/internal/views/partials/powershell.partials.templ index 5c20d08..cc1b142 100644 --- a/internal/views/partials/powershell.partials.templ +++ b/internal/views/partials/powershell.partials.templ @@ -41,5 +41,19 @@ templ PowerShellComponent(t *ent.Task) { +
+ + +
}