<? /*
// File: apache.wcp.phps
// Purpose: apache domain manipulation
// Author: Felix <hide@address.com>
*/
// Handle domains manipulation
if ($type == "domain") {
// Generate apache configuration
if ($data['action'] != 'remove') {
$httpdconf = "<VirtualHost ".$data['ip'].":".$cfg['apache']['port'].">\n";
$httpdconf .= "\tServerName ".$data['host'].".".$data['domain']."\n";
$httpdconf .= "\tServerAdmin ".$data['email']."\n";
// if the site is to be suspended, redirect the documentroot
if ($data['action'] == 'suspend' OR $data['suspended'] != 'false')
$path = $cfg['basedir']."/suspended";
// else set correct path
elseif ($data['type'] == "pointer")
$path = $data['path'];
else
$path = $data['path']."/".$data['host']."/".$cfg['webname'];
$httpdconf .= "\tDocumentRoot '$path'\n";
// Set correct error logs
if ($data['type'] == 'pointer') {
$ownerdata = fetchdata("id,host","domain",$data['owner']);
$log = $cfg['webdir']."/".$ownerdata['id']."/".$ownerdata['host']."/logs";
}
else
$log = $cfg['webdir']."/".$data['id']."/".$data['host']."/logs";
$httpdconf .= "\tErrorLog $log/error\n";
$httpdconf .= "\tCustomLog $log/access combined\n";
// If there are aliases
if ($data['nohost'] == 'true' OR $data['aliases'] OR $data['catchall'] == 'true'){
$httpdconf .= "\tServerAlias";
if ($data['aliases']) {
$tmp = explode(" ",$data['aliases']);
while (current($tmp)) {
$httpdconf .= " ".current($tmp).".".$data['domain'];
next($tmp);
}
}
// If nohost is supported
if ($data['nohost'] == 'true')
$httpdconf .= " ".$data['domain'];
// If catchall is supported
if ($data['catchall'] == 'true')
$httpdconf .= " *.".$data['domain'];
$httpdconf .= "\n";
}
// If domain redirect
if ($data['redirect'] == 'true') {
$httpdconf .= "\tRewriteEngine On\n\tRewriteCond %{HTTP_HOST}\t\t!^".$data['ip']."(:".$cfg['apache']['port'].")?$\n";
$httpdconf .= "\tRewriteCond %{HTTP_HOST}\t\t!^".$data['host'].".".$data['domain']."(:".$cfg['apache']['port'].")?$\n";
$httpdconf .= "\tRewriteRule ^/(.*)\t\thttp://".$data['host'].".".$data['domain']."/$1 [L,R]\n";
$httpdconf .= "\tRewriteOptions inherit\n";
}
// Check for ServerSide Options (PHP, Perl, ASP, Python, etc)
$cfgsslangarr = explode(',',$cfg['sslang']);
foreach ($cfgsslangarr as $ssoption) {
if ($data['serverside'][$ssoption] == 'on' AND $cfg['ss'][$ssoption])
$httpdconf .= $cfg['ss'][$ssoption]."\n";
}
// Parse %PATH% for real path. (used in php serverside config)
if ($data['type'] == 'pointer')
$httpdconf = str_replace("%PATH%",$cfg['webdir']."/".$data['owner'],$httpdconf);
else
$httpdconf = str_replace("%PATH%",$data['path'],$httpdconf);
// check if web.cp uses SSL or not
if ($cfg['ssl'])
$http = "https://";
else
$http = "http://";
// Set a correct port as well
if ($cfg['port'])
$port = ":".$cfg['port'];
else
$port = '';
// Add web://cp web redirections
$httpdconf .= "\tRewriteEngine On\n";
$httpdconf .= "\tRewriteCond %{HTTP_HOST}\t\t^([^:]+)\n";
$httpdconf .= "\tRewriteRule ^/personalcp/?$\t\t".$http.$cfg['sysname'].$port."/?cp=personal&number=".$data['id']." [L,R]\n";
$httpdconf .= "\tRewriteCond %{HTTP_HOST}\t\t^([^:]+)\n";
$httpdconf .= "\tRewriteRule ^/domaincp/?$\t\t".$http.$cfg['sysname'].$port."/?cp=domain&number=".$data['id']." [L,R]\n";
$httpdconf .= "\tRewriteCond %{HTTP_HOST}\t\t^([^:]+)\n";
$httpdconf .= "\tRewriteRule ^/resellercp/?$\t\t".$http.$cfg['sysname'].$port."/?cp=reseller&number=".$data['id']." [L,R]\n";
$httpdconf .= "\tRewriteCond %{HTTP_HOST}\t\t^([^:]+)\n";
$httpdconf .= "\tRewriteRule ^/servercp/?$\t\t".$http.$cfg['sysname'].$port."/?cp=server [L,R]\n";
$httpdconf .= "\tRewriteCond %{HTTP_HOST}\t\t^([^:]+)\n";
$httpdconf .= "\tRewriteRule ^/webcp/?$\t\t".$http.$cfg['sysname'].$port."/ [L,R]\n";
// Add custom httpd data if its there
if (trim($data['httpcustom']))
$httpdconf .= "\n".$data['httpcustom']."\n";
// If SSL is on and the appropriate .crt .key are present
if ($data['type'] == 'pointer') {
$ownerdata = fetchdata("id,host","domain",$data['owner']);
$ssl = $cfg['webdir']."/".$ownerdata['id']."/".$ownerdata['host']."/ssl/";
}
else
$ssl = $cfg['webdir']."/".$data['id']."/".$data['host']."/ssl/";
$servercrt = $ssl."server.crt";
$serverkey = $ssl."server.key";
if ($data['serverside']['ssl'] == "on" AND file_exists($servercrt) AND file_exists($serverkey)) {
$httpdsslconf = "NameVirtualHost ".$data['ip'].":443\n";
$httpdsslconf .= str_replace(":".$cfg['apache']['port'].">",":443>",$httpdconf)."\n";
$httpdsslconf .= "\tSSLEngine on\n";
$httpdsslconf .= "\tSSLCipherSuite ALL:!ADH:!EXP56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL\n";
$httpdsslconf .= "\tSSLCertificateFile $servercrt\n";
$httpdsslconf .= "\tSSLCertificateKeyFile $serverkey\n";
if (file_exists($ssl."intermediate.crt"))
$httpdsslconf .= "\tSSLCACertificateFile ".$ssl."intermediate.crt\n";
$httpdsslconf .= "\tSSLOptions +StdEnvVars\n";
$httpdsslconf .= "\tSetEnvIf User-Agent '.*MSIE.*' nokeepalive ssl-unclean-shutdown downgrade-1.0 force-response-1.0\n";
$httpdsslconf .= "</VirtualHost>\n";
}
// Close httpd conf file
$httpdconf .= "</VirtualHost>\n";
// Merge normal and SSL http config
$httpdconf .= $httpdsslconf;
}
// Handle Domain Creation :: expect *
if ($data['action'] == 'create') {
// Write the apache config file
$httpdinclude = $cfg['basedir']."/httpd/include/".$data['id'].".httpd";
$fp = fopen($httpdinclude,"w+");
fwrite($fp,$httpdconf,20480);
fclose($fp);
// Set permissions
chmod($httpdinclude,0644);
// Set HTTPD server restart
$restarthttp = TRUE;
}
// Handle Domain updates :: expect *
elseif ($data['action'] == 'update') {
// Compare old and newly generated apache config file, write if necessary
$httpdinclude = $cfg['basedir']."/httpd/include/".$data['id'].".httpd";
$oldconf = implode("",file($httpdinclude));
if ($oldconf != $httpdconf) {
// Write the apache config file
$fp = fopen($httpdinclude,"w+");
fwrite($fp,$httpdconf,20480);
fclose($fp);
// Set permissions
chmod($httpdinclude,0644);
// Set HTTPD server restart
$restarthttp = TRUE;
}
}
// Suspend Domain :: expect 'id'
elseif ($data['action'] == "suspend") {
if ($data['id']) {
// Write the apache config file
$httpdinclude = $cfg['basedir']."/httpd/include/".$data['id'].".httpd";
$fp = fopen($httpdinclude,"w+");
fwrite($fp,$httpdconf,20480);
fclose($fp);
// Set permissions
chmod($httpdinclude,0644);
// Set HTTPD server restart
$restarthttp = TRUE;
}
}
// Unsuspend Domain :: expect 'id',
elseif ($data['action'] == "unsuspend") {
if ($data['id']) {
// Write the apache config file
$httpdinclude = $cfg['basedir']."/httpd/include/".$data['id'].".httpd";
$fp = fopen($httpdinclude,"w+");
fwrite($fp,$httpdconf,20480);
fclose($fp);
// Set permissions
chmod($httpdinclude,0644);
// Set HTTPD server restart
$restarthttp = TRUE;
}
}
// Remove Domain :: expect *
elseif ($data['action'] == "remove") {
if ($data['id']) {
// Remove httpd config file
$httpdinclude = $cfg['basedir']."/httpd/include/".$data['id'].".httpd";
if (file_exists($httpdinclude))
unlink($httpdinclude);
}
}
}
?>