|
PnCp.cmd
@echo off
rem -- http://PHPnow.org
rem -- By Yinz ( MSN / QQ / Email : Cwood@qq.com )
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 "%pause%"=="" exit /b
if "%1"=="x" if not "%2"=="" cmd /c "%2 %3 %4 %5 %6" & goto :eof
if not "%1"=="" (
call :%1 %2
goto :eof
)
prompt -$g
title PHPnow %pn_ver% 控制面板 (Apache %htd_ver%)
goto menu
:restart_apache
if not exist %apadir%\logs\httpd.pid goto :eof
echo.
echo 正在重启 Apache ...
pushd %apadir%
bin\%htd_exe% -k restart -n %htd_svc% || set errno=1
popd
if "%errno%"=="1" %pause%
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 ______________________________________________________________
echo ^| ^|
echo ^| PHPnow - 绿色 PHP + MySQL 套件 - 控制面板 ^|
echo ^| ^|
echo ^| 0 - vhs 添加 虚拟主机 10 - 设置 代理虚拟主机 ^|
echo ^| 1 - vhs 删除 虚拟主机 11 - 取消 代理虚拟主机 ^|
echo ^| 2 - vhs 修改 虚拟主机 12 - 复位 MySQL root 密码 ^|
echo ^| 3 - 开启 eAccelerator 13 - 更改 Apache 端口 ^|
echo ^| 4 - 禁用 eAccelerator * 14 - 导出 MySQL 数据库 ^|
echo ^| 5 - 开启 网站目录索引 15 - 导入 MySQL 数据库 ^|
echo ^| 6 - 禁用 网站目录索引 * 16 - 端口使用状态检测 ^|
echo ^| 7 - 日志分卷(会有多个进程) 17 - ----------------- ^|
echo ^| 8 - 取消 日志分卷 * 18 - ----------------- ^|
echo ^| 9 - 设置 error_reporting 19 - Pn 目录命令提示符 ^|
echo ^| (带 * 号的为默认选项) ^|
echo ^| ^|
echo ^| 20 - Start.cmd 30 - Stop.cmd ^|
echo ^| 21 - Apa_Start.cmd 31 - Apa_Stop.cmd ^|
echo ^| 22 - My_Start.cmd 32 - My_Stop.cmd ^|
echo ^| 23 - Apa_Restart.cmd 33 - 强行终止进程并卸载 ^|
echo ^|______________________________________________________________^|
set /p input=-^> 请选择:
cls
if "%input%"=="20" call :execmd Start.cmd
if "%input%"=="21" call :execmd Apa_Start.cmd
if "%input%"=="22" call :execmd My_Start.cmd
if "%input%"=="23" call :execmd Apa_Restart.cmd
if "%input%"=="30" call :execmd Stop.cmd
if "%input%"=="31" call :execmd Apa_Stop.cmd
if "%input%"=="32" call :execmd My_Stop.cmd
echo.
if "%input%"=="0" goto add_vhost
if "%input%"=="1" goto del_vhost
if "%input%"=="2" goto mod_vhost
if "%input%"=="3" goto en_ea
if "%input%"=="4" goto dis_ea
if "%input%"=="5" goto en_index
if "%input%"=="6" goto dis_index
if "%input%"=="7" goto pipelog
if "%input%"=="8" goto unpipelog
if "%input%"=="9" goto err_report
if "%input%"=="10" goto set_proxy
if "%input%"=="11" goto un_proxy
if "%input%"=="12" goto reset_mypwd
if "%input%"=="13" goto chg_port
if "%input%"=="14" goto my_dump
if "%input%"=="15" goto my_import
if "%input%"=="16" goto chkport
if "%input%"=="17" goto --
if "%input%"=="18" goto --
if "%input%"=="19" cmd /K echo # 当前目录 [ %CD% ]
if "%input%"=="33" goto fstop
goto end
:chg_port
set /p nport=-^> 输入新端口(1-65535):
if "%nport%"=="" goto end
%pl% $p='%nport%';$p=abs($p);if(is_int($p)^&^&$p^>0^&^&$p^<65536)exit(0);else exit(1); || goto end
%pl% chg_port('%nport%'); || %pause% && goto end
if "%1"=="nors" goto end
call :restart_apache
goto end
:add_vhost
echo # 现有虚拟主机列表 #
%pl% showvhs(); || %pause% && goto end
echo.
echo [ 主机名用于识别不同虚拟主机. 例 abc.com 或 www.abc.com ]
set /p hname=-^> 添加主机名:
if "%hname%"=="" goto end
echo.
echo [ 别名用于绑定主机名外的多个域名. 如 www.abc.com 或 *.abc.com(泛解析)
echo 多个请用空格间开, 如 www.abc.com 51lvse.cn *.phpnow.org ]
set /p alias=-^> 主机别名(可选):
:add_vhost_1
echo.
echo [ 指定网站目录. 留空则默认为 vhosts\%hname%]
set htdocs=
set /p htdocs=-^> 网站目录(可选):
if "%htdocs%"=="" goto add_vhost_2
%pl% exit(strpos('%htdocs%#',':')); && ( echo # 请使用绝对路径。如 D:\www & %pause% & goto add_vhost_1 )
if exist %htdocs% goto add_vhost_2
md %htdocs%>nul 2>nul || ( echo # 指定目录不存在。自动创建失败!& %pause% & goto add_vhost_1 )
:add_vhost_2
echo.
echo [ 如果分配此主机给其他用户, 并限制其权限, 请输入 "y";
echo 否则, 请输入 "n". 默认 Y ]
set /p p=-^> 限制虚拟主机权限? (Y/n):
%pl% addvhost('%hname%', '%htdocs% ', %htd_port%, '%alias%', '%p%'); || %pause% && goto end
call :restart_apache
goto end
:del_vhost
echo # 现有虚拟主机列表 #
%pl% showvhs(); || %pause% && goto end
echo.
set /p hname=-^> 要删除的主机名或序号:
if "%hname%"=="" goto end
%pl% delvhost('%hname%'); || %pause% && goto end
call :restart_apache
goto end
:mod_vhost
echo # 现有虚拟主机列表 #
%pl% showvhs(); || %pause% && goto end
echo.
set /p hname=-^> 要修改的主机名或序号:
if "%hname%"=="" goto end
echo.
echo [ 请输入新的主机别名, 原有数据将被覆盖! ]
echo [ 可使用 + 代替原有数据. 要在原基础上添加, 输入 +phpnow.org ]
set /p alias=-^> 主机别名:
if "%alias%"=="" goto end
:mod_vhost_1
echo.
echo [ 将 %hname% 主机别名改为 "%alias%" ]
echo.
set /p sure=-^> 确认? (y/n)
if /i "%sure%"=="n" goto end
if /i "%sure%"=="y" goto mod_vhost_2
goto mod_vhost_1
:mod_vhost_2
%pl% modvhost('%hname%', '%alias%'); || %pause% && goto end
call :restart_apache
goto end
:set_proxy
echo [ 设置 Apache 虚拟主机代理其他端口, 实现与其他 http 服务共用 80 端口 ]
echo.
echo # 现有虚拟主机列表 #
%pl% showvhs(); || %pause% && goto end
echo.
echo [ 添加新的主机名. 如 abc.com 或 bbs.abc.com ]
set /p hname=-^> 主机名:
if "%hname%"=="" goto end
echo.
echo [ 绑定其他域名. 如 www.abc.com 或 *.abc.com(泛解析); 多个请用空格隔开 ]
set /p alias=-^> 主机别名(可选):
if "%alias%"=="" set alias=*.%hname%
echo.
echo [ 例: localhost:8080,192.168.0.100 或 google.com]
echo [ 跳过将默认为: localhost:8080 ]
set /p pryto=-^> 代理目标:
if "%pryto%"=="" set pryto=localhost:8080
%pl% conf($htdcf, '^#(Load.*proxy_mod.*)$', '$1'); conf($htdcf, '^#(Load.*proxy_http.*)$', '$1'); || %pause% && goto end
echo.>>%vh%
echo ^<VirtualHost *^>>>%vh%
echo ServerName %hname%:%htd_port%>>%vh%
echo ServerAlias %alias%>>%vh%
echo ProxyPass / http://%pryto%/>>%vh%
echo ProxyPassReverse / http://%pryto%/>>%vh%
echo ^</VirtualHost^>>>%vh%
call :restart_apache
goto end
:un_proxy
echo [ 继续将删除所有代理主机记录! ]
echo.
set /p sure=-^> 确认? (y/n)
if /i "%sure%"=="n" goto end
if /i "%sure%"=="y" goto un_proxy_1
goto un_proxy
:un_proxy_1
%pl% conf($htdcf,'^(Load.*proxy_mod.*)$', '#$1');conf($htdcf, '^(Load.*proxy_http.*)$', '#$1'); || %pause% && goto end
%pl% "$s=rfile($vhcf);$s=regrpl('\r\n<VirtualHost \*>[^<]*ProxyPass [^<]*<\/VirtualHost>\r\n','',$s);wfile($vhcf,$s);" || %pause% && goto end
call :restart_apache
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
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
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
:err_report
echo ______________________________________________________________
echo ^| ^|
echo ^| 设置 php error_reporting (错误报告) 选项 ^|
echo ^| ^|
echo ^| 0 - E_ALL ^& ~E_NOTICE ^& ~E_WARNING [ 默认; 推荐 ] ^|
echo ^| 1 - E_ALL [ 编程模式 ] ^|
echo ^|______________________________________________________________^|
set /p input=-^> 请选择:
if "%input%"=="0" %pl% conf(`$phpdir\php-apache2handler.ini`, '^^(error_reporting =) .+(\r?)', '$1 E_ALL ^& ~E_NOTICE ^& ~E_WARNING$2');
if "%input%"=="1" %pl% conf(`$phpdir\php-apache2handler.ini`, '^^(error_reporting =) .+(\r?)', '$1 E_ALL$2');
call :restart_apache
goto end
:reset_mypwd
set /p newpwd=-^> 重设 root 密码:
if "%newpwd%"=="" goto reset_mypwd
echo.
set tmpsql=%SystemRoot%\Temp\%RANDOM%.sql
echo SET PASSWORD FOR 'root'@'localhost' = PASSWORD('%newpwd%');>%tmpsql%
if exist %mysqldir%\data\%COMPUTERNAME%.pid net stop %my_svc%
set myini=%CD%\%mysqldir%\my.ini
start /b %mysqldir%\bin\mysqld-nt --defaults-file="%myini%" --init-file=%tmpsql%
%mysqldir%\bin\mysqladmin.exe shutdown -uroot -p"%newpwd%"
echo 等待 MySQL 结束...
echo.
%pl% while(@file_exists('%mysqldir%\data\%COMPUTERNAME%.pid')) usleep(50000);
echo.>%tmpsql%
del %tmpsql% /Q
net start %my_svc% || %pause%
goto end
:my_dump
set /p dbn=-^> 导出数据库名:
if "%dbn%"=="" goto my_dump
:my_dump_u
set /p u=-^> 用户名:
if "%u%"=="" goto my_dump_u
set /p p=-^> 密码:
:my_dump_fn
set /p fn=-^> 导出文件名:
if "%fn%"=="" goto my_dump_fn
%mysqldir%\bin\mysqldump.exe -u%u% -p%p% %dbn%>%fn% || %pause% && del %fn% /Q
goto end
:my_import
set /p dbn=-^> 导入数据库名(请手动创建空的):
if "%dbn%"=="" goto my_import
:my_import_u
set /p u=-^> 用户名:
if "%u%"=="" goto my_import_u
set /p p=-^> 密码:
:my_import_fn
set /p fn=-^> 导入文件名:
if "%fn%"=="" goto my_import_fn
%mysqldir%\bin\mysql.exe -u%u% -p%p% -D%dbn%<%fn% || %pause%
goto end
: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.
%pause% & 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\%htd_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 |
|