4.主机列表及其负载情况
因为主机列表分布在不同的服务器上,分别由不同的服务器来维护,因此在登录时要从虚拟主机网络中的服务器取回主机列表信息,包括用户名、用户信息、磁盘配额等(这一步通过数据库连接进行)。
5.系统消息列表的维护
每一台服务器都维护一个消息列表,读取通知时只需在本地读取即可。但在发布通知和修改删除通知时,需要在所有服务器上推送消息,保证消息列表的可靠性。
6.添加虚拟主机
添加虚拟主机时首先需要选取服务器,服务器接收到表单,判断服务器是本地服务器还是远程服务器,若是本地服务器,则在本地新建虚拟主机,若是远程服务器,则在远程服务器进行远程过程调用RPC来新建虚拟主机。在主机新建时,要调用到Apache控制模块来完成Apache配置。
新建虚拟主机时需要配置v s f t p d、Apache、MySQL和 Quota,这是由过程调用产生的。
部分代码实现:
my $str = $gt->get("Node");
my $str1 = $gt->get("posting");
print "<font color='blue'>$str $myhost $str1...</font>";
print $q->br();
foreach $cuHost(@hosts)
{
my $db0;
print "Post on host:<font color='red'>$cuHost</font> ...";
if($cuHost ne $myhost)
{
my $tempdb = DBI->connect("DBI:mysql:database=vhms;
host=localhost",$dbuser,$dbpasswd,{'RaiseError'=>1});
my $tempsth = $tempdb->prepare("select dbuser,dbpasswd from
hostList where host='$cuHost'");
$tempsth->execute();
my @tempref = $tempsth->fetchrow_array();
my $tgdbu = $tempref[0];
my $tgdbp = $tempref[1];
$db0 = DBI->connect("DBI:mysql:database=vhms;host=$cuHost",
"$tgdbu","$tgdbp",{'RaiseError'=>1});
print "Connected RemoteHost.";
print $q->br();
}else{
$db0 = DBI->connect("DBI:mysql:database=vhms;
host=localhost",$dbuser,$dbpasswd,{'RaiseError'=>1});
print "Connected localhost.";
print $q->br();
}
my $sth = $db0->prepare("INSERT INTO msg values('$idx',
'$msgTitle','$msgContent')");
#my $sth = $db0->prepare("INSERT INTO msg values('$idx',
'$str1','$str2')");
$sth->execute();
print "Posted.";
print $q->br();
$db0->disconnect();
print "Disconnected;";
print $q->br();
}
7.配置Apache控制模块
该模块完成Apache的配置、修改、删除、重启工作,在连接远程主机完成工作时,需要进行加密连接,远程调用。
部分代码实现:
#List All Hosts and vhosts
#Offer Restert and Edit VHost Func.
print $q->h1($gt->get("Control Apache"));
my $str0 = $gt->get("Hosts");
my $str1 = $gt->get("Allocated to:");
my $str2 = $gt->get("Edit");
print qq{<TABLE border=1>
<TD>$str0</TD>
<TD></TD>
<TD>$str1</TD>
<TD>$str2</TD><TR>};
foreach $cuHost(@hosts)
{
my $islocal = 1;
if($cuHost eq $myhost)
{
$islocal = 1;
print "<td>*$cuHost</td>";
}else
{
$islocal = 0;
print "<td>$cuHost</td>";
}
my $str0 = $gt->get("Restrt Service");
print "<td><a href='apachebn.pl?cmd=restart&host=$cuHost'>
$str0</a></td>";
print "<td></td><td></td><tr>";
my $sth;
my $lrdb;
if($islocal)
{
$lrdb = DBI->connect("DBI:mysql:database=vhms;host=localhost",
$dbuser,$dbpasswd,{'RaiseError'=>1});
$sth = $lrdb->prepare("select name,contactor,url from vhuser");
$sth->execute();
}else
{
my $tempdb = DBI->connect("DBI:mysql:database=vhms;
host=localhost",$dbuser,$dbpasswd,{'RaiseError'=>1});
my $tempsth = $tempdb->prepare("select dbuser,dbpasswd from
hostList where host='$cuHost'");
$tempsth->execute();
my @tempref = $tempsth->fetchrow_array();
my $tgdbu = $tempref[0];
my $tgdbp = $tempref[1];
$lrdb = DBI->connect("DBI:mysql:database=vhms;host=$cuHost",
"$tgdbu","$tgdbp",{'RaiseError'=>1});
$sth = $lrdb->prepare("select name,contactor,url from vhuser");
$sth->execute();
}
my $count = 1;
while(my @ref = $sth->fetchrow_array())
{
if($count ne $sth->rows)
{
print "<td align=right>|----</td>";
}else
{
print "<td align=right>`----</td>";
}
$count++;
print "<td><a href='http://$ref[2]' target='_blank'>$ref[2]</
a></td>";
print "<td>$ref[1]</td>";
my $str0 = $gt->get("Edit");
p r i n t " < t d > < a h r e f = ' a p a c h e b n . p l ?
cmd=edit&host=$cuHost&vhost=$ref[0]'>$str0</td></tr>";
}
$lrdb->disconnect();
8.查看FTP日志
用户从查看FTP日志的页面上选择一个要查看FTP日志的主机或者用户,FTP日志模块就会读取本地或者远程日志,返回给用户,在远程读取时进行加密连接。
9.系统附加功能
为了更好地完善虚拟主机管理系统的功能,添加照片墙和访问管理等开源软件的支持以方便用户的使用。
(1)照片墙
照片墙后台选用Qt库来实现,Cutycapt生成页面快照,genSnapWall来调用xvfb和Cutycapt共同完成快照,将结果存于服务器上,照片墙可方便地展现网站快照,直观地显示管理虚拟主机的现状。
(2)Awstats
Awstats是一个免费、简洁、强大、有个性的统计工具。它可以统计站点中的如下信息:访问量、访问次数、页面浏览量、点击数、数据流量等;精确到每月、每日、每小时的数据;访问者国家;访问者IP;Robots/Spiders的统计;访客持续时间;对不同Files type 的统计信息;Pages-URL的统计;访客操作系统浏览器等信息;其他信息(搜索关键字等等)。
(作者单位为山东大学网络与信息中心)