@echo off
rem //------------------------------------------------------------------------------
rem // リモートマイクロ交換(Setup Installer) ファイアウォール登録バッチファイル
rem //------------------------------------------------------------------------------
cd /d %~dp0

rem 引数：インストールパス
set INSDIR=%1

rem --------------- インストール後のセキュリティ警告画面表示対策 ---------------
rem apache HTTP Serverをファイアウォールでブロックしない

set samepath=0
rem "Apache HTTP Server"はすでに登録済？
netsh advfirewall firewall show rule name="Apache HTTP Server" > nul 2>&1
if %errorlevel%==0 (
	netsh advfirewall firewall show rule name="Apache HTTP Server" verbose > fwtmp.txt 2>&1

	rem 設定値(パス)チェック
	for /f "tokens=2" %%i in (fwtmp.txt) do (
		echo %%i | find "httpd.exe" >NUL
		if NOT ERRORLEVEL 1 (
			rem プログラムパス抽出
			rem 今からインストールするパスと違うパス？
			if /i %%i==%INSDIR%\oss\apache\bin\httpd.exe (
				set samepath=1
				goto break
			)
		)
	)
:break
	del fwtmp.txt
)
rem プログラムパスパスチェック
if %samepath%==0 (
	rem 新しいパスを追加
	netsh advfirewall firewall add rule name="Apache HTTP Server" dir=in action=allow program=%INSDIR%\oss\apache\bin\httpd.exe enable=yes profile=domain,private,public protocol=tcp edge=deferuser > nul
	netsh advfirewall firewall add rule name="Apache HTTP Server" dir=in action=allow program=%INSDIR%\oss\apache\bin\httpd.exe enable=yes profile=domain,private,public protocol=udp edge=deferuser > nul
)
exit /b 0

