diff --git a/build.nsi b/build.nsi index 5c77fb233e..58a98d6417 100755 --- a/build.nsi +++ b/build.nsi @@ -42,13 +42,10 @@ InstallDirRegKey HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\YaCy" !define RecommendSpace "30" ; some string for Firewall -!define WinXPAddFwRulePort 'netsh firewall add portopening protocol=tcp port=8090 name=YaCy mode=enable' -!define WinXPDelFwRulePort 'netsh firewall del portopening protocol=tcp port=8090' -!define WinVistaAddFwRulePort 'netsh advfirewall firewall add rule name="YaCy" program="%SystemRoot%\System32\javaw.exe" dir=in action=allow protocol=tcp localport=8090' -!define WinVistaDelFwRulePort 'netsh advfirewall firewall del rule name="YaCy"' -var WinAddFwRulePort -var WinDelFwRulePort - +!define WinAddYaCyPort 'netsh advfirewall firewall add rule name="YaCy" program="%SystemRoot%\System32\javaw.exe" dir=in action=allow protocol=tcp localport=8090' +!define WinDelYaCyPort 'netsh advfirewall firewall del rule name="YaCy"' +!define WinAdduPnpPort 'netsh advfirewall firewall add rule name="YaCy uPnp" program="%SystemRoot%\System32\javaw.exe" dir=in action=allow protocol=udp remoteip=defaultgateway remoteport=1900' +!define WinDeluPnpPort 'netsh advfirewall firewall del rule name="YaCy uPnp"' ;requested execution level on Vista / 7 RequestExecutionLevel admin @@ -186,7 +183,7 @@ Section "Desktop Icon" CreateShortCut "$DESKTOP\YaCy.lnk" "$INSTDIR\startYACY.bat" "" "$INSTDIR\addon\YaCy.ico" "" SW_SHOWMINIMIZED SectionEnd -Section "Open Firewall (Port 8090)" Sec_Firewall_id +Section "Open Firewall (Port 8090 for YaCy and 1900 for uPnP)" Sec_Firewall_id SectionIn 1 SetShellVarContext current call OpenFirewall @@ -268,18 +265,9 @@ Function .onInit ${If} ${IsWinVista} ${OrIf} ${IsWin7} - StrCpy $WinAddFwRulePort '${WinVistaAddFwRulePort}' - StrCpy $WinDelFwRulePort '${WinVistaDelFwRulePort}' - ReadRegDWORD $FirewallServiceStart HKLM "SYSTEM\CurrentControlSet\services\MpsSvc" "Start" + ReadRegDWORD $FirewallServiceStart HKLM "SYSTEM\CurrentControlSet\services\MpsSvc" "Start" ${EndIf} - ${If} ${IsWinXP} - ${AndIf} ${AtLeastServicePack} 2 - StrCpy $WinAddFwRulePort '${WinXPAddFwRulePort}' - StrCpy $WinDelFwRulePort '${WinXPDelFwRulePort}' - ReadRegDWORD $FirewallServiceStart HKLM "SYSTEM\CurrentControlSet\services\SharedAccess" "Start" - ${EndIf} - ;need Admin for firewall-config ${IfNot} $0 = "Admin" IntOp $FirewallServiceStart 3 + 0 @@ -386,12 +374,22 @@ FunctionEnd Function OpenFirewall var /global ExecErrorCode - ; run netsh - nsExec::ExecToStack '$WinAddFwRulePort' + ; run netsh for Port 8090 + nsExec::ExecToStack '${WinAddYaCyPort}' pop $ExecErrorCode ; if run without error register for uninstall and clear finish page ${If} $ExecErrorCode = "0" - WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\YaCy" "DelFwRulePort" '$WinDelFwRulePort' + WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\YaCy" "DelFwYaCyPort" '${WinDelYaCyPort}' + IntOp $FirewallServiceStart 0 + 0 + ${Else} + IntOp $FirewallServiceStart 3 + 0 + ${EndIf} + ; run netsh for Port 1900 - uPnP + nsExec::ExecToStack '${WinAdduPnpPort}' + pop $ExecErrorCode + ; if run without error register for uninstall and clear finish page + ${If} $ExecErrorCode = "0" + WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\YaCy" "DelFwuPnpPort" '${WinDeluPnpPort}' IntOp $FirewallServiceStart 0 + 0 ${Else} IntOp $FirewallServiceStart 3 + 0 @@ -402,15 +400,22 @@ Function SHOW_PageFinish_custom ; hide and disable firewall info from wiki if firewall is open ${If} $FirewallServiceStart = 0 SendMessage $mui.FinishPage.ShowReadme ${BM_SETCHECK} 0 0 - ShowWindow $mui.FinishPage.ShowReadme ${SW_HIDE} + ShowWindow $mui.FinishPage.ShowReadme ${SW_HIDE} ${EndIf} FunctionEnd Function un.CloseFirewall ; get string for closing port from registy - ReadRegStr '$WinDelFwRulePort' HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\YaCy" "DelFwRulePort" + var /global UninstallCmd + ; close YaCy-Port 8090 + ReadRegStr '$UninstallCmd' HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\YaCy" "DelFwYaCyPort" ; if found > run netsh to close port - ${IfNot} '$WinDelFwRulePort' == '' - nsExec::ExecToStack '$WinDelFwRulePort' + ${IfNot} '$UninstallCmd' == '' + nsExec::ExecToStack '$UninstallCmd' + ${EndIf} + ; close uPnp-Port 1900 + ReadRegStr '$UninstallCmd' HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\YaCy" "DelFwuPnPPort" + ${IfNot} '$UninstallCmd' == '' + nsExec::ExecToStack '$UninstallCmd' ${EndIf} FunctionEnd