@echo off


setlocal enableextensions
if exist Pn\Config.cmd pushd . & goto cfg
if exist ..\Pn\Config.cmd pushd .. & goto cfg
goto :eof

:cfg
call Pn\Config.cmd

if "%1"=="x" if not "%2"=="" cmd /c "%2 %3 %4 %5 %6" & goto :eof
if not "%1"=="" (
call :%1
goto :eof
)

prompt -$g
title 控制面板
goto menu


:restart_apache
if not exist %apadir%\logs\httpd.pid goto :eof
echo.
echo  正在重启 Apache ...
pushd %apadir%
bin\httpd.exe -k restart -n %htd_svc% || %pause%
popd
goto :eof


:execmd
if exist %1 call %1 && goto :eof
if exist %cmdsdir%\%1 call %cmdsdir%\%1 && goto :eof
echo # 找不到 %1, 你把它放在哪了？
%pause%
goto :eof


:menu
echo.
cls
echo.
:chkport
%pl% chkport(%htd_port%);
if not errorlevel 1 echo   指定 httpd 端口 %htd_port% 没有被任何进程使用。
%pl% chkport(%my_port%);
if not errorlevel 1 echo   指定 MySQL 端口 %my_port% 没有被任何进程使用。
echo.
echo.
pause /s exit
goto end

:en_ea
if not exist %phpdir%\ext\eAccelerator*.dll if exist Pn\eAccelerator*.dll (
copy Pn\eAccelerator*.dll %phpdir%\ext /y>nul
) else ( echo # eAccelerator dll 没有找到 & %pause% & goto end )
for /f %%i in ('dir /b /o %phpdir%\ext\eAccelerator*.dll') do set ea_dll=%%i
%pl% conf(`$phpdir\php-apache2handler.ini`, '^[;]*(zend_extension_ts=).*eAccelerator.*\r?$', `$1\`..\..\\$phpdir\ext\%ea_dll%\``); || %pause% && goto end
if not exist %SystemRoot%\Temp\eaccelerator.cache md %SystemRoot%\Temp\eaccelerator.cache
call :restart_apache
goto end


:dis_ea
%pl% conf(`$phpdir\php-apache2handler.ini`, '^(zend_extension_ts=.*eAccelerator.*\r?$)', ';;$1'); || %pause% && goto end
call :restart_apache
if exist %SystemRoot%\Temp\eaccelerator.cache rd /S /Q %SystemRoot%\Temp\eaccelerator.cache
goto end


:en_index
%pl% "$s=rfile($htdcf); $s=regrpl('^##(Load.*autoindex.*\.so)', '$1', $s); $s=regrpl('^##?(Inc.*autoindex.*)', '$1', $s); $s=regrpl('Options -Indexes', 'Options Indexes', $s); wfile($htdcf, $s);
%pl% conf($vhcf, 'Options -Indexes', 'Options Indexes'); || %pause% && goto end
call :restart_apache
goto end


:dis_index
%pl% "$s=rfile($htdcf); $s=regrpl('^(Load.*autoindex.*\.so)', '##$1', $s); $s=regrpl('^(Inc.*autoindex.*)', '##$1', $s); $s=regrpl('Options Indexes', 'Options -Indexes', $s); wfile($htdcf, $s);
%pl% conf($vhcf, 'Options Indexes', 'Options -Indexes'); || %pause% && goto end
call :restart_apache
goto end


:pipelog
%pl% pipelog(1);
call :restart_apache
goto end


:unpipelog
%pl% pipelog(0);
call :restart_apache
goto end


:fstop
taskkill /fi "SERVICES eq %htd_svc%" /f /t
taskkill /fi "SERVICES eq %my_svc%" /f /t
net stop %my_svc%>nul 2>nul
net stop %htd_svc%>nul 2>nul
%apadir%\bin\httpd.exe -k uninstall -n %htd_svc%>nul 2>nul
%mysqldir%\bin\mysqld-nt.exe --remove %my_svc%>nul 2>nul
del %mysqldir%\data\%COMPUTERNAME%.pid %apadir%\logs\httpd.pid /q>nul 2>nul
%pause%
goto end


:end
prompt
popd
