geosters
11-29-2003, 03:45 PM
O.k i need the below translated to php, i need this for a project i am going to make, this is the only part i am having problems in. Can you PLEASE help?
#!/usr/local/bin/perl
# apache.pl was used to export apache related config file for Apache from Database
# You need to add follow line in httpd.conf:
#
# include "pvirthostas.conf"
#
# This program will create a pvirthostas.conf
# p.s. The code is little bit dirty~ I will clean it up :-)
use strict;
use DBI;
use lib ("../lib");
require "config.inc.pl";
my $conf_content;
my @row;
my @row2;
my @row3;
my %val;
my $dbh = DBI->connect("DBI:mysql:$config::sql_root_database", $config::sql_root_username, $config::sql_root_password);
my $sth = $dbh->prepare("select domain, hostip, email_admin, doc_root, log_dir from http");
$sth->execute();
while(@row = $sth->fetchrow_array) {
$conf_content = $conf_content."include \"".$config::apache_conf_path."\/$row[0]\"\n";
if(!open(HOST_CONF, ">$config::apache_conf_path\/$row[0]"))
{ print("$row[0] open failed"); die;}
if(!flock(HOST_CONF, 2))
{ print("File Lock failed"); die;}
if(!is_file_exist($row[3])){write_to_log("apache", "Directory $row[3] not exist so $row[0] will forward to $config::doc_root");$row[3]=$config::doc_root;}
print HOST_CONF "<VirtualHost $row[1]>\n";
print HOST_CONF "\tServerName $row[0]\n";
print HOST_CONF "\tServerAlias $row[0]\n";
print HOST_CONF "\tServerAdmin $row[2]\n";
print HOST_CONF "\tDocumentRoot $row[3]\n";
print HOST_CONF "\tErrorLog $row[4]/$config::apache_error_log\n";
print HOST_CONF "\tCustomLog $row[4]/$config::apache_access_log common\n";
print HOST_CONF "</VirtualHost>\n";
my $sth2 = $dbh->prepare("select vhost, dir_name , host_ip from subdomain where domain=\"$row[0]\"");
$sth2->execute();
while(@row2 = $sth2->fetchrow_array) {
if($row2[1]) {
if(!is_file_exist($row2[1])){write_to_log("apache", "Directory $row2[1] not exist so $row2[0]\.$row[0] will forward to $config::doc_root");$row2[1]=$config::doc_root;}
if($row2[2]) {
print HOST_CONF "<VirtualHost $row[2]>\n";
}
else {
print HOST_CONF "<VirtualHost $config::apache_host_ip>\n";
}
print HOST_CONF "\tServerName $row2[0]\.$row[0]\n";
print HOST_CONF "\tServerAlias $row2[0]\.$row[0]\n";
print HOST_CONF "\tServerAdmin $row[2]\n";
print HOST_CONF "\tDocumentRoot $row2[1]\n";
print HOST_CONF "\tErrorLog $row[4]/$config::apache_error_log\n";
print HOST_CONF "\tCustomLog $row[4]/$config::apache_access_log common\n";
print HOST_CONF "</VirtualHost>\n";
}
}
flock(HOST_CONF, 8);
close(HOST_CONF);
}
$sth->finish();
$dbh->disconnect();
write_to_file($config::apache_conf_path."/pvirthostas.conf", $conf_content);
if(system($config::apache_restart) != 0)
{print("\nApache Restart Error");die;}
#!/usr/local/bin/perl
# apache.pl was used to export apache related config file for Apache from Database
# You need to add follow line in httpd.conf:
#
# include "pvirthostas.conf"
#
# This program will create a pvirthostas.conf
# p.s. The code is little bit dirty~ I will clean it up :-)
use strict;
use DBI;
use lib ("../lib");
require "config.inc.pl";
my $conf_content;
my @row;
my @row2;
my @row3;
my %val;
my $dbh = DBI->connect("DBI:mysql:$config::sql_root_database", $config::sql_root_username, $config::sql_root_password);
my $sth = $dbh->prepare("select domain, hostip, email_admin, doc_root, log_dir from http");
$sth->execute();
while(@row = $sth->fetchrow_array) {
$conf_content = $conf_content."include \"".$config::apache_conf_path."\/$row[0]\"\n";
if(!open(HOST_CONF, ">$config::apache_conf_path\/$row[0]"))
{ print("$row[0] open failed"); die;}
if(!flock(HOST_CONF, 2))
{ print("File Lock failed"); die;}
if(!is_file_exist($row[3])){write_to_log("apache", "Directory $row[3] not exist so $row[0] will forward to $config::doc_root");$row[3]=$config::doc_root;}
print HOST_CONF "<VirtualHost $row[1]>\n";
print HOST_CONF "\tServerName $row[0]\n";
print HOST_CONF "\tServerAlias $row[0]\n";
print HOST_CONF "\tServerAdmin $row[2]\n";
print HOST_CONF "\tDocumentRoot $row[3]\n";
print HOST_CONF "\tErrorLog $row[4]/$config::apache_error_log\n";
print HOST_CONF "\tCustomLog $row[4]/$config::apache_access_log common\n";
print HOST_CONF "</VirtualHost>\n";
my $sth2 = $dbh->prepare("select vhost, dir_name , host_ip from subdomain where domain=\"$row[0]\"");
$sth2->execute();
while(@row2 = $sth2->fetchrow_array) {
if($row2[1]) {
if(!is_file_exist($row2[1])){write_to_log("apache", "Directory $row2[1] not exist so $row2[0]\.$row[0] will forward to $config::doc_root");$row2[1]=$config::doc_root;}
if($row2[2]) {
print HOST_CONF "<VirtualHost $row[2]>\n";
}
else {
print HOST_CONF "<VirtualHost $config::apache_host_ip>\n";
}
print HOST_CONF "\tServerName $row2[0]\.$row[0]\n";
print HOST_CONF "\tServerAlias $row2[0]\.$row[0]\n";
print HOST_CONF "\tServerAdmin $row[2]\n";
print HOST_CONF "\tDocumentRoot $row2[1]\n";
print HOST_CONF "\tErrorLog $row[4]/$config::apache_error_log\n";
print HOST_CONF "\tCustomLog $row[4]/$config::apache_access_log common\n";
print HOST_CONF "</VirtualHost>\n";
}
}
flock(HOST_CONF, 8);
close(HOST_CONF);
}
$sth->finish();
$dbh->disconnect();
write_to_file($config::apache_conf_path."/pvirthostas.conf", $conf_content);
if(system($config::apache_restart) != 0)
{print("\nApache Restart Error");die;}
