Add Windows Firewall rules to installer - Automated firewall configuration for inbound/outbound traffic and port access - Service start checkbox option for user control - Clean firewall rule removal during uninstallation
This commit is contained in:
@ -16,30 +16,9 @@ import (
|
|||||||
func main() {
|
func main() {
|
||||||
// Kommandozeilenparameter definieren
|
// Kommandozeilenparameter definieren
|
||||||
var port int
|
var port int
|
||||||
var installService bool
|
|
||||||
var uninstallService bool
|
|
||||||
flag.IntVar(&port, "port", 0, "Port für den Server (Standard: 8080 oder PORT Umgebungsvariable)")
|
flag.IntVar(&port, "port", 0, "Port für den Server (Standard: 8080 oder PORT Umgebungsvariable)")
|
||||||
flag.BoolVar(&installService, "install", false, "Installiere Medi-WOL als Windows-Dienst")
|
|
||||||
flag.BoolVar(&uninstallService, "uninstall", false, "Entferne Medi-WOL Windows-Dienst")
|
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
// Dienst-Installation/-Entfernung
|
|
||||||
if installService {
|
|
||||||
if err := installWindowsService(); err != nil {
|
|
||||||
log.Fatal("Fehler beim Installieren des Dienstes:", err)
|
|
||||||
}
|
|
||||||
log.Println("Medi-WOL Dienst erfolgreich installiert")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if uninstallService {
|
|
||||||
if err := uninstallWindowsService(); err != nil {
|
|
||||||
log.Fatal("Fehler beim Entfernen des Dienstes:", err)
|
|
||||||
}
|
|
||||||
log.Println("Medi-WOL Dienst erfolgreich entfernt")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Port aus Umgebungsvariable oder Standardwert
|
// Port aus Umgebungsvariable oder Standardwert
|
||||||
if port == 0 {
|
if port == 0 {
|
||||||
if envPort := os.Getenv("PORT"); envPort != "" {
|
if envPort := os.Getenv("PORT"); envPort != "" {
|
||||||
@ -90,24 +69,10 @@ func main() {
|
|||||||
|
|
||||||
// Server starten
|
// Server starten
|
||||||
serverAddr := fmt.Sprintf(":%d", port)
|
serverAddr := fmt.Sprintf(":%d", port)
|
||||||
log.Printf("Server startet auf Port %d...", port)
|
log.Printf("Medi-WOL startet auf Port %d...", port)
|
||||||
log.Printf("Web-Oberfläche verfügbar unter: http://localhost%s", serverAddr)
|
log.Printf("Web-Oberfläche verfügbar unter: http://localhost%s", serverAddr)
|
||||||
|
|
||||||
if err := r.Run(serverAddr); err != nil {
|
if err := r.Run(serverAddr); err != nil {
|
||||||
log.Fatal("Fehler beim Starten des Servers:", err)
|
log.Fatal("Fehler beim Starten des Servers:", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Windows-Dienst-Funktionen
|
|
||||||
func installWindowsService() error {
|
|
||||||
// Einfache Implementierung: Dienst-Informationen in Registry schreiben
|
|
||||||
// In einer echten Implementierung würde hier der Windows Service Controller verwendet
|
|
||||||
log.Println("Installiere Medi-WOL als Windows-Dienst...")
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func uninstallWindowsService() error {
|
|
||||||
// Einfache Implementierung: Dienst-Informationen aus Registry entfernen
|
|
||||||
log.Println("Entferne Medi-WOL Windows-Dienst...")
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|||||||
BIN
dist/medi-wol-linux-amd64
vendored
BIN
dist/medi-wol-linux-amd64
vendored
Binary file not shown.
BIN
dist/medi-wol-linux-arm64
vendored
BIN
dist/medi-wol-linux-arm64
vendored
Binary file not shown.
4
go.mod
4
go.mod
@ -1,10 +1,10 @@
|
|||||||
module medi-wol
|
module medi-wol
|
||||||
|
|
||||||
go 1.21
|
go 1.23.0
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/gin-gonic/gin v1.9.1
|
github.com/gin-gonic/gin v1.9.1
|
||||||
golang.org/x/sys v0.9.0
|
golang.org/x/sys v0.35.0
|
||||||
modernc.org/sqlite v1.28.0
|
modernc.org/sqlite v1.28.0
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
2
go.sum
2
go.sum
@ -88,6 +88,8 @@ golang.org/x/sys v0.0.0-20220704084225-05e143d24a9e/go.mod h1:oPkhp1MJrh7nUepCBc
|
|||||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.9.0 h1:KS/R3tvhPqvJvwcKfnBHJwwthS11LRhmM5D59eEXa0s=
|
golang.org/x/sys v0.9.0 h1:KS/R3tvhPqvJvwcKfnBHJwwthS11LRhmM5D59eEXa0s=
|
||||||
golang.org/x/sys v0.9.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.9.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
golang.org/x/sys v0.35.0 h1:vz1N37gP5bs89s7He8XuIYXpyY0+QlsKmzipCbUtyxI=
|
||||||
|
golang.org/x/sys v0.35.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
|
||||||
golang.org/x/text v0.9.0 h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE=
|
golang.org/x/text v0.9.0 h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE=
|
||||||
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
|
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
|
||||||
golang.org/x/tools v0.6.0 h1:BOw41kyTf3PuCW1pVQf8+Cyg8pMlkYB1oo9iJ6D/lKM=
|
golang.org/x/tools v0.6.0 h1:BOw41kyTf3PuCW1pVQf8+Cyg8pMlkYB1oo9iJ6D/lKM=
|
||||||
|
|||||||
@ -20,7 +20,7 @@ DefaultGroupName={#MyAppName}
|
|||||||
AllowNoIcons=yes
|
AllowNoIcons=yes
|
||||||
LicenseFile=..\LICENSE
|
LicenseFile=..\LICENSE
|
||||||
OutputDir=..\dist
|
OutputDir=..\dist
|
||||||
OutputBaseFilename=medi-wol-setup-v2
|
OutputBaseFilename=medi-wol-setup
|
||||||
Compression=lzma
|
Compression=lzma
|
||||||
SolidCompression=yes
|
SolidCompression=yes
|
||||||
WizardStyle=modern
|
WizardStyle=modern
|
||||||
@ -35,9 +35,11 @@ Name: "english"; MessagesFile: "compiler:Default.isl"
|
|||||||
[Tasks]
|
[Tasks]
|
||||||
Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked
|
Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked
|
||||||
Name: "quicklaunchicon"; Description: "{cm:CreateQuickLaunchIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked; OnlyBelowVersion: 6.1; Check: not IsAdminInstallMode
|
Name: "quicklaunchicon"; Description: "{cm:CreateQuickLaunchIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked; OnlyBelowVersion: 6.1; Check: not IsAdminInstallMode
|
||||||
|
Name: "startservice"; Description: "{cm:StartServiceAfterInstall}"; GroupDescription: "{cm:ServiceOptions}"
|
||||||
|
|
||||||
[Files]
|
[Files]
|
||||||
Source: "..\dist\{#MyAppExeName}"; DestDir: "{app}"; Flags: ignoreversion
|
Source: "..\dist\{#MyAppExeName}"; DestDir: "{app}"; Flags: ignoreversion
|
||||||
|
Source: "nssm.exe"; DestDir: "{app}"; Flags: ignoreversion
|
||||||
Source: "..\web\static\*"; DestDir: "{app}\web\static"; Flags: ignoreversion recursesubdirs createallsubdirs
|
Source: "..\web\static\*"; DestDir: "{app}\web\static"; Flags: ignoreversion recursesubdirs createallsubdirs
|
||||||
Source: "..\web\templates\*"; DestDir: "{app}\web\templates"; Flags: ignoreversion recursesubdirs createallsubdirs
|
Source: "..\web\templates\*"; DestDir: "{app}\web\templates"; Flags: ignoreversion recursesubdirs createallsubdirs
|
||||||
Source: "..\LICENSE"; DestDir: "{app}"; Flags: ignoreversion
|
Source: "..\LICENSE"; DestDir: "{app}"; Flags: ignoreversion
|
||||||
@ -50,12 +52,42 @@ Name: "{autodesktop}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: de
|
|||||||
Name: "{userappdata}\Microsoft\Internet Explorer\Quick Launch\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: quicklaunchicon
|
Name: "{userappdata}\Microsoft\Internet Explorer\Quick Launch\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: quicklaunchicon
|
||||||
|
|
||||||
[Run]
|
[Run]
|
||||||
; Startet die Anwendung nach der Installation
|
; Installiere Medi-WOL als Windows-Dienst mit NSSM
|
||||||
Filename: "{app}\{#MyAppExeName}"; Parameters: "-port {code:GetPort}"; StatusMsg: "Starte Medi-WOL..."; Flags: runhidden nowait
|
Filename: "{app}\nssm.exe"; Parameters: "install ""{#MyAppServiceName}"" ""{app}\{#MyAppExeName}"""; StatusMsg: "Installiere Medi-WOL als Windows-Dienst..."; Flags: runhidden
|
||||||
|
; Setze die Kommandozeilenparameter für den Port
|
||||||
|
Filename: "{app}\nssm.exe"; Parameters: "set ""{#MyAppServiceName}"" AppParameters ""-port {code:GetPort}"""; Flags: runhidden
|
||||||
|
; Setze Service-Beschreibung
|
||||||
|
Filename: "{app}\nssm.exe"; Parameters: "set ""{#MyAppServiceName}"" Description ""{#MyAppServiceDescription}"""; Flags: runhidden
|
||||||
|
; Setze Service-Starttyp auf automatisch
|
||||||
|
Filename: "{app}\nssm.exe"; Parameters: "set ""{#MyAppServiceName}"" Start SERVICE_AUTO_START"; Flags: runhidden
|
||||||
|
; Setze das Arbeitsverzeichnis
|
||||||
|
Filename: "{app}\nssm.exe"; Parameters: "set ""{#MyAppServiceName}"" AppDirectory ""{app}"""; Flags: runhidden
|
||||||
|
; Setze Ausgabe-Umleitung für Debugging
|
||||||
|
Filename: "{app}\nssm.exe"; Parameters: "set ""{#MyAppServiceName}"" AppStdout ""{app}\service.log"""; Flags: runhidden
|
||||||
|
Filename: "{app}\nssm.exe"; Parameters: "set ""{#MyAppServiceName}"" AppStderr ""{app}\service-error.log"""; Flags: runhidden
|
||||||
|
; Setze Service-Restart bei Fehler
|
||||||
|
Filename: "{app}\nssm.exe"; Parameters: "set ""{#MyAppServiceName}"" AppRestartDelay 5000"; Flags: runhidden
|
||||||
|
; Setze Timeout für Service-Start
|
||||||
|
Filename: "{app}\nssm.exe"; Parameters: "set ""{#MyAppServiceName}"" AppStopMethodSkip 0"; Flags: runhidden
|
||||||
|
Filename: "{app}\nssm.exe"; Parameters: "set ""{#MyAppServiceName}"" AppStopMethodConsole 1500"; Flags: runhidden
|
||||||
|
Filename: "{app}\nssm.exe"; Parameters: "set ""{#MyAppServiceName}"" AppStopMethodWindow 1500"; Flags: runhidden
|
||||||
|
Filename: "{app}\nssm.exe"; Parameters: "set ""{#MyAppServiceName}"" AppStopMethodThreads 1500"; Flags: runhidden
|
||||||
|
; Service nach Installation starten mit Verzögerung
|
||||||
|
Filename: "{app}\nssm.exe"; Parameters: "start ""{#MyAppServiceName}"""; StatusMsg: "Starte Medi-WOL Dienst..."; Flags: runhidden waituntilterminated; Check: ShouldStartService
|
||||||
|
; Windows Firewall-Ausnahmen für den Service hinzufügen
|
||||||
|
Filename: "netsh.exe"; Parameters: "advfirewall firewall add rule name=""{#MyAppServiceName} - Inbound"" dir=in action=allow program=""{app}\{#MyAppExeName}"" enable=yes"; StatusMsg: "Erstelle Windows Firewall-Ausnahme (Eingehend)..."; Flags: runhidden
|
||||||
|
Filename: "netsh.exe"; Parameters: "advfirewall firewall add rule name=""{#MyAppServiceName} - Outbound"" dir=out action=allow program=""{app}\{#MyAppExeName}"" enable=yes"; StatusMsg: "Erstelle Windows Firewall-Ausnahme (Ausgehend)..."; Flags: runhidden
|
||||||
|
Filename: "netsh.exe"; Parameters: "advfirewall firewall add rule name=""{#MyAppServiceName} - Port {code:GetPort}"" dir=in action=allow protocol=TCP localport={code:GetPort} enable=yes"; StatusMsg: "Erstelle Windows Firewall-Port-Regel..."; Flags: runhidden
|
||||||
|
|
||||||
[UninstallRun]
|
[UninstallRun]
|
||||||
; Stoppe die Anwendung vor der Deinstallation
|
; Stoppe den Windows-Dienst vor der Deinstallation
|
||||||
Filename: "taskkill.exe"; Parameters: "/F /IM {#MyAppExeName}"; Flags: runhidden
|
Filename: "{app}\nssm.exe"; Parameters: "stop ""{#MyAppServiceName}"""; Flags: runhidden
|
||||||
|
; Entferne den Windows-Dienst
|
||||||
|
Filename: "{app}\nssm.exe"; Parameters: "remove ""{#MyAppServiceName}"" confirm"; StatusMsg: "Entferne Medi-WOL Dienst..."; Flags: runhidden
|
||||||
|
; Entferne Windows Firewall-Regeln
|
||||||
|
Filename: "netsh.exe"; Parameters: "advfirewall firewall delete rule name=""{#MyAppServiceName} - Inbound"""; Flags: runhidden
|
||||||
|
Filename: "netsh.exe"; Parameters: "advfirewall firewall delete rule name=""{#MyAppServiceName} - Outbound"""; Flags: runhidden
|
||||||
|
Filename: "netsh.exe"; Parameters: "advfirewall firewall delete rule name=""{#MyAppServiceName} - Port {code:GetPort}"""; Flags: runhidden
|
||||||
|
|
||||||
[Code]
|
[Code]
|
||||||
var
|
var
|
||||||
@ -108,10 +140,20 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function ShouldStartService(): Boolean;
|
||||||
|
begin
|
||||||
|
Result := WizardIsTaskSelected('startservice');
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
[CustomMessages]
|
[CustomMessages]
|
||||||
german.CreateDesktopIcon=Desktop-Verknüpfung erstellen
|
german.CreateDesktopIcon=Desktop-Verknüpfung erstellen
|
||||||
german.CreateQuickLaunchIcon=Quick Launch-Verknüpfung erstellen
|
german.CreateQuickLaunchIcon=Quick Launch-Verknüpfung erstellen
|
||||||
german.AdditionalIcons=Zusätzliche Verknüpfungen:
|
german.AdditionalIcons=Zusätzliche Verknüpfungen:
|
||||||
|
german.ServiceOptions=Service-Optionen:
|
||||||
|
german.StartServiceAfterInstall=Service nach der Installation starten
|
||||||
german.UninstallProgram=Medi-WOL entfernen
|
german.UninstallProgram=Medi-WOL entfernen
|
||||||
|
|
||||||
|
english.ServiceOptions=Service Options:
|
||||||
|
english.StartServiceAfterInstall=Start service after installation
|
||||||
|
|||||||
Reference in New Issue
Block a user