用Vhost.map 实现APACHE虚拟主机方式的附加管理程序

时间:12-04-05 栏目:网站开发 作者:admin 评论:0 点击: 6,214 次

用Vhost.map 实现APACHE虚拟主机方式的好处就是定义简单,无需重启。

此处附管理程序:

<?php
include('auth.inc.php');
error_reporting(E_ALL ^ E_NOTICE);

//$filename = 'C:\servers\Apache2.2\conf\vhost.map';

$filename = 'd:\xampp\apache\conf\vhost.map'; //map文件地址
$welcome = 'd:\webroot\welcome';              //虚拟主机初始文件
$maps = read_map();
if ($_POST) {
$map = $_POST;
foreach($map as $value){
$somecontent .= trim($value[0])." ".trim($value[1])." ".trim($value[2])."\r\n";
if (!strstr($value[1],'http:') && !is_dir(dirname($value[1]))){

echo '建立目录'.dirname($value[1]).'<br />';
@mkdir($value[1],true);
//FileUtil::copyDir($welcome, $value[1]);//建立虚拟主要初始页面
}
}

write_map($filename,$somecontent);

$maps = read_map();
}

function read_map(){
global $filename;
$map = file($filename);
foreach($map as $value){
//$maps[] =spliti(" +", $value);
$value = preg_replace("/[\s]+/",' ', $value);
$maps[] =explode(" ", $value);

}
return $maps;
}

function write_map($filename,$somecontent){
$somecontent = str_replace('\\\\','\\',$somecontent);
$somecontent = str_replace('\\\\','\\',$somecontent);
//$somecontent = preg_replace( "@(\\+)@is", "", $somecontent );
if (is_writable($filename)) {
// 使用添加模式打开$filename,
// 文件指针将会在文件的开头,
// 那就是当我们使用fwrite()的时候,$somecontent将要写入的地方。
if (!$handle = fopen($filename, 'w')) {//写入方式
exit("不能打开文件 $filename");
}
if (fwrite($handle, $somecontent) === FALSE) {
exit("不能写入到文件 $filename");
}
echo "内容写入成功!";
fclose($handle);
} else {
echo "文件 $filename 不可写";
}
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<style type="text/css">
<!--
#SignFrame {
background-color: #00CCFF;
}
#SignFrame td{
background-color: #EEFBFD;
}
-->
</style>
<script language="javascript">// Example: obj = findObj("image1");
function findObj(theObj, theDoc)
{
var p, i, foundObj;
if(!theDoc) theDoc = document;
if( (p = theObj.indexOf("?")) > 0 && parent.frames.length)
{    theDoc = parent.frames[theObj.substring(p+1)].document;    theObj = theObj.substring(0,p);  }  if(!(foundObj = theDoc[theObj]) && theDoc.all) foundObj = theDoc.all[theObj];  for (i=0; !foundObj && i < theDoc.forms.length; i++)     foundObj = theDoc.forms[i][theObj];  for(i=0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++)     foundObj = findObj(theObj,theDoc.layers[i].document);  if(!foundObj && document.getElementById) foundObj = document.getElementById(theObj);    return foundObj;
}
//添加一个填写行
function AddSignRow(){ //读取最后一行的行号,存放在txtTRLastIndex文本框中
var txtTRLastIndex = findObj("txtTRLastIndex",document);
var rowID = parseInt(txtTRLastIndex.value);

var signFrame = findObj("SignFrame",document);
//添加行
var newTR = signFrame.insertRow(signFrame.rows.length);
newTR.id = "SignItem" + rowID;

//添加列:序号
var newNameTD=newTR.insertCell(0);
//添加列内容
newNameTD.innerHTML = newTR.rowIndex.toString()-1;

//添加列:主机头
var newNameTD=newTR.insertCell(1);
//添加列内容
newNameTD.innerHTML = "<input name='" + rowID + "[0]' id='" + rowID + "[0]'  type='text' size='30' />";

//添加列:映射
var newEmailTD=newTR.insertCell(2);
//添加列内容
newEmailTD.innerHTML = "<input name='" + rowID + "[1]'  id='" + rowID + "[1]'  type='text' size='50' />";

//添加列:映射
var newEmailTD2=newTR.insertCell(3);
//添加列内容
newEmailTD2.innerHTML = "<input name='" + rowID + "[2]'  id='" + rowID + "[2]'  type='text' size='50' />";

//添加列:删除按钮
var newDeleteTD=newTR.insertCell(4);
//添加列内容
newDeleteTD.innerHTML = "<input type=\"button\" name=\"del\" value=\"删除\"   onclick=\"DeleteSignRow('SignItem" + rowID + "')\" style=\"height:25px\"/>";

//将行号推进下一行
txtTRLastIndex.value = (rowID + 1).toString() ;
}
//删除指定行
function DeleteSignRow(rowid){
var signFrame = findObj("SignFrame",document);
var signItem = findObj(rowid,document);

//获取将要删除的行的Index
var rowIndex = signItem.rowIndex;

//删除指定Index的行
signFrame.deleteRow(rowIndex);

//重新排列序号,如果没有序号,这一步省略
for(i=rowIndex;i<signFrame.rows.length;i++){
signFrame.rows[i].cells[0].innerHTML = i.toString();
}
}//清空列表
function ClearAllSign(){
if(confirm('确定要清空所有吗?')){
var signFrame = findObj("SignFrame",document);
var rowscount = signFrame.rows.length;

//循环删除行,从最后一行往前删除
for(i=rowscount - 1;i > 0; i--){
signFrame.deleteRow(i);
}

//重置最后行号为1
var txtTRLastIndex = findObj("txtTRLastIndex",document);
txtTRLastIndex.value = "1";

//预添加一行
AddSignRow();
}
}
</script>
</head>
<body>
<div>
<div>编辑: 虚拟主机</div>
<form action="" method="post" name="vhost_form" id="vhost_form" >
<table width="100%" border="0" cellspacing="1" cellpadding="0"  id="SignFrame">
<tr id="trHeader">
<td>序号</td>
<td>主机头</td>
<td>映射</td>
<td>备注</td><td> </td>
</tr>
<?php foreach($maps as $key=>$value){
?>
<tr id="SignItem<?php echo $key ?>">
<td><?php echo $key ?></td>
<td><input name="<?php echo $key ?>[0]" type="text" id="<?php echo $key ?>[0]" value="<?php echo trim($value[0])?> " size="30" /></td>
<td><input name="<?php echo $key ?>[1]" type="text" id="<?php echo $key ?>[1]" value="<?php echo trim($value[1])?> " size="50" /></td>
<td>
<input name="<?php echo $key ?>[2]" type="text" id="<?php echo $key ?>[2]" value="<?php echo trim($value[2])?> " size="50" /></td>
<td>

<input type="button" name="Submit" value="删除"   onclick="DeleteSignRow('SignItem<?php echo $key ?>')" style="height:25px"/>
</td>

</tr>

<?php
}; ?>

</table>
</form>
</div>
<div>
<input type="button" name="Submit2" value="提交修改" onclick="vhost_form.submit()" style="height:25px"/>
<input type="button" name="Submit2" value="添加一行" onclick="AddSignRow()" style="height:25px" />
<input type="button" name="Submit2" value="清空" onclick="ClearAllSign()" style="height:25px" />
<input type="button" name="Submit2" value="返回" onclick="history.go(-1)" style="height:25px" />
<input name='txtTRLastIndex' type='hidden' id='txtTRLastIndex' value="<?php echo $key+1 ?>" style="height:25px" />
</div>
</BODY>
</HTML>

声明: 本文由( admin )原创编译,转载请保留链接: 用Vhost.map 实现APACHE虚拟主机方式的附加管理程序

用Vhost.map 实现APACHE虚拟主机方式的附加管理程序:等您坐沙发呢!

发表评论


------====== 本站公告 ======------
联系信息:
电话:19970108113(微信同号) QQ:3142401606
支付宝:https://me.alipay.com/lxq73061
相关插件程序等信息均会在站内发布,敬请关注。

读者排行