Commit b50d36a3 authored by Marius Cramer's avatar Marius Cramer
Browse files

Merge branch 'master' into 'master'

Merge of domains, vhost subdomains and vhost aliasdomains to vhost domains
parents 29e1b0c9 73813a4b
<?php
/**
* sites_web_domain_plugin plugin
*
* @author Julio Montoya <gugli100@gmail.com> BeezNest 2010
*/
class sites_web_domain_plugin {
var $plugin_name = 'sites_web_domain_plugin';
var $class_name = 'sites_web_domain_plugin';
// TODO: This function is a duplicate from the one in interface/web/sites/web_domain_edit.php
// There should be a single "token replacement" function to be called from modules and
// from the main code.
// Returna a "3/2/1" path hash from a numeric id '123'
function id_hash($id, $levels) {
$hash = "" . $id % 10 ;
$id /= 10 ;
$levels -- ;
while ( $levels > 0 ) {
$hash .= "/" . $id % 10 ;
$id /= 10 ;
$levels-- ;
}
return $hash;
}
/*
This function is called when the plugin is loaded
*/
function onLoad() {
global $app;
//Register for the events
$app->plugin->registerEvent('sites:web_domain:on_after_insert', 'sites_web_domain_plugin', 'sites_web_domain_edit');
}
/*
Function to create the sites_web_domain rule and insert it into the custom rules
*/
function sites_web_domain_edit($event_name, $page_form) {
global $app, $conf;
// make sure that the record belongs to the clinet group and not the admin group when a dmin inserts it
// also make sure that the user can not delete domain created by a admin
if($_SESSION["s"]["user"]["typ"] == 'admin' && isset($page_form->dataRecord["client_group_id"])) {
$client_group_id = $app->functions->intval($page_form->dataRecord["client_group_id"]);
$app->db->query("UPDATE web_domain SET sys_groupid = $client_group_id, sys_perm_group = 'ru' WHERE domain_id = ".$page_form->id);
}
if($app->auth->has_clients($_SESSION['s']['user']['userid']) && isset($page_form->dataRecord["client_group_id"])) {
$client_group_id = $app->functions->intval($page_form->dataRecord["client_group_id"]);
$app->db->query("UPDATE web_domain SET sys_groupid = $client_group_id, sys_perm_group = 'riud' WHERE domain_id = ".$page_form->id);
}
// Get configuration for the web system
$app->uses("getconf");
$web_config = $app->getconf->get_server_config($app->functions->intval($page_form->dataRecord['server_id']), 'web');
$document_root = str_replace("[website_id]", $page_form->id, $web_config["website_path"]);
$document_root = str_replace("[website_idhash_1]", $this->id_hash($page_form->id, 1), $document_root);
$document_root = str_replace("[website_idhash_2]", $this->id_hash($page_form->id, 1), $document_root);
$document_root = str_replace("[website_idhash_3]", $this->id_hash($page_form->id, 1), $document_root);
$document_root = str_replace("[website_idhash_4]", $this->id_hash($page_form->id, 1), $document_root);
// get the ID of the client
if($_SESSION["s"]["user"]["typ"] != 'admin' && !$app->auth->has_clients($_SESSION['s']['user']['userid'])) {
$client_group_id = $_SESSION["s"]["user"]["default_group"];
$client = $app->db->queryOneRecord("SELECT client_id FROM sys_group WHERE sys_group.groupid = $client_group_id");
$client_id = $app->functions->intval($client["client_id"]);
} else {
//$client_id = $app->functions->intval($this->dataRecord["client_group_id"]);
$client = $app->db->queryOneRecord("SELECT client_id FROM sys_group WHERE sys_group.groupid = ".$app->functions->intval($page_form->dataRecord["client_group_id"]));
$client_id = $app->functions->intval($client["client_id"]);
}
// Set the values for document_root, system_user and system_group
$system_user = $app->db->quote('web'.$page_form->id);
$system_group = $app->db->quote('client'.$client_id);
$document_root = str_replace("[client_id]", $client_id, $document_root);
$document_root = str_replace("[client_idhash_1]", $this->id_hash($client_id, 1), $document_root);
$document_root = str_replace("[client_idhash_2]", $this->id_hash($client_id, 2), $document_root);
$document_root = str_replace("[client_idhash_3]", $this->id_hash($client_id, 3), $document_root);
$document_root = str_replace("[client_idhash_4]", $this->id_hash($client_id, 4), $document_root);
$document_root = $app->db->quote($document_root);
$php_open_basedir = str_replace("[website_path]", $document_root, $web_config["php_open_basedir"]);
$php_open_basedir = $app->db->quote(str_replace("[website_domain]", $page_form->dataRecord['domain'], $php_open_basedir));
$htaccess_allow_override = $app->db->quote($web_config["htaccess_allow_override"]);
$sql = "UPDATE web_domain SET system_user = '$system_user', system_group = '$system_group', document_root = '$document_root', allow_override = '$htaccess_allow_override', php_open_basedir = '$php_open_basedir' WHERE domain_id = ".$page_form->id;
$app->db->query($sql);
}
}
<?php
/**
* sites_web_vhost_aliasdomain_plugin plugin
*
* @author Marius Cramer <m.cramer@pixcept.de> pixcept KG 2012, copied and adapted from web_domain plugin by:
* @author Julio Montoya <gugli100@gmail.com> BeezNest 2010
*/
class sites_web_vhost_aliasdomain_plugin {
var $plugin_name = 'sites_web_vhost_aliasdomain_plugin';
var $class_name = 'sites_web_vhost_aliasdomain_plugin';
// TODO: This function is a duplicate from the one in interface/web/sites/web_vhost_aliasdomain_edit.php
// There should be a single "token replacement" function to be called from modules and
// from the main code.
// Returna a "3/2/1" path hash from a numeric id '123'
function id_hash($id, $levels) {
$hash = "" . $id % 10 ;
$id /= 10 ;
$levels -- ;
while ( $levels > 0 ) {
$hash .= "/" . $id % 10 ;
$id /= 10 ;
$levels-- ;
}
return $hash;
}
/*
This function is called when the plugin is loaded
*/
function onLoad() {
global $app;
//Register for the events
// both event call the same function as the things to do do not differ here
$app->plugin->registerEvent('sites:web_vhost_aliasdomain:on_after_insert', 'sites_web_vhost_aliasdomain_plugin', 'sites_web_vhost_aliasdomain_edit');
$app->plugin->registerEvent('sites:web_vhost_aliasdomain:on_after_update', 'sites_web_vhost_aliasdomain_plugin', 'sites_web_vhost_aliasdomain_edit');
}
/*
Function to create the sites_web_vhost_aliasdomain rule and insert it into the custom rules
*/
function sites_web_vhost_aliasdomain_edit($event_name, $page_form) {
global $app, $conf;
// Get configuration for the web system
$app->uses("getconf");
$web_config = $app->getconf->get_server_config($app->functions->intval($page_form->dataRecord['server_id']), 'web');
$parent_domain = $app->db->queryOneRecord("SELECT * FROM `web_domain` WHERE `domain_id` = '" . $app->functions->intval($page_form->dataRecord['parent_domain_id']) . "'");
// Set the values for document_root, system_user and system_group
$system_user = $app->db->quote($parent_domain['system_user']);
$system_group = $app->db->quote($parent_domain['system_group']);
$document_root = $app->db->quote($parent_domain['document_root']);
$php_open_basedir = str_replace("[website_path]/web", $document_root.'/'.$page_form->dataRecord['web_folder'], $web_config["php_open_basedir"]);
$php_open_basedir = str_replace("[website_domain]/web", $page_form->dataRecord['domain'].'/'.$page_form->dataRecord['web_folder'], $php_open_basedir);
$php_open_basedir = str_replace("[website_path]", $document_root, $php_open_basedir);
$php_open_basedir = $app->db->quote(str_replace("[website_domain]", $page_form->dataRecord['domain'], $php_open_basedir));
$htaccess_allow_override = $app->db->quote($parent_domain['allow_override']);
$sql = "UPDATE web_domain SET sys_groupid = ".$app->functions->intval($parent_domain['sys_groupid']).",system_user = '$system_user', system_group = '$system_group', document_root = '$document_root', allow_override = '$htaccess_allow_override', php_open_basedir = '$php_open_basedir' WHERE domain_id = ".$page_form->id;
$app->db->query($sql);
}
}
<?php
/**
* sites_web_vhost_domain_plugin plugin
*
* @author Julio Montoya <gugli100@gmail.com> BeezNest 2010
*/
class sites_web_vhost_domain_plugin {
var $plugin_name = 'sites_web_vhost_domain_plugin';
var $class_name = 'sites_web_vhost_domain_plugin';
// TODO: This function is a duplicate from the one in interface/web/sites/web_domain_edit.php
// There should be a single "token replacement" function to be called from modules and
// from the main code.
// Returna a "3/2/1" path hash from a numeric id '123'
function id_hash($id, $levels) {
$hash = "" . $id % 10 ;
$id /= 10 ;
$levels -- ;
while ( $levels > 0 ) {
$hash .= "/" . $id % 10 ;
$id /= 10 ;
$levels-- ;
}
return $hash;
}
/*
This function is called when the plugin is loaded
*/
function onLoad() {
global $app;
//Register for the events
$app->plugin->registerEvent('sites:web_vhost_domain:on_after_insert', 'sites_web_vhost_domain_plugin', 'sites_web_vhost_domain_edit');
$app->plugin->registerEvent('sites:web_vhost_domain:on_after_update', 'sites_web_vhost_domain_plugin', 'sites_web_vhost_domain_edit');
}
/*
Function to create the sites_web_domain rule and insert it into the custom rules
*/
function sites_web_vhost_domain_edit($event_name, $page_form) {
global $app, $conf;
$vhostdomain_type = 'domain';
if($page_form->dataRecord['type'] == 'vhostalias') $vhostdomain_type = 'aliasdomain';
elseif($page_form->dataRecord['type'] == 'vhostsubdomain') $vhostdomain_type = 'subdomain';
// make sure that the record belongs to the clinet group and not the admin group when a dmin inserts it
// also make sure that the user can not delete domain created by a admin
if($_SESSION["s"]["user"]["typ"] == 'admin' && isset($page_form->dataRecord["client_group_id"])) {
$client_group_id = $app->functions->intval($page_form->dataRecord["client_group_id"]);
$app->db->query("UPDATE web_domain SET sys_groupid = $client_group_id, sys_perm_group = 'ru' WHERE domain_id = ".$page_form->id);
}
if($app->auth->has_clients($_SESSION['s']['user']['userid']) && isset($page_form->dataRecord["client_group_id"])) {
$client_group_id = $app->functions->intval($page_form->dataRecord["client_group_id"]);
$app->db->query("UPDATE web_domain SET sys_groupid = $client_group_id, sys_perm_group = 'riud' WHERE domain_id = ".$page_form->id);
}
// Get configuration for the web system
$app->uses("getconf");
$web_config = $app->getconf->get_server_config($app->functions->intval($page_form->dataRecord['server_id']), 'web');
if(isset($app->tform) && is_object($app->tform)) $web_rec = $app->tform->getDataRecord($page_form->id);
else $web_rec = $app->remoting_lib->getDataRecord($page_form->id);
if($vhostdomain_type == 'domain') {
$document_root = str_replace("[website_id]", $page_form->id, $web_config["website_path"]);
$document_root = str_replace("[website_idhash_1]", $this->id_hash($page_form->id, 1), $document_root);
$document_root = str_replace("[website_idhash_2]", $this->id_hash($page_form->id, 1), $document_root);
$document_root = str_replace("[website_idhash_3]", $this->id_hash($page_form->id, 1), $document_root);
$document_root = str_replace("[website_idhash_4]", $this->id_hash($page_form->id, 1), $document_root);
// get the ID of the client
if($_SESSION["s"]["user"]["typ"] != 'admin' && !$app->auth->has_clients($_SESSION['s']['user']['userid'])) {
$client_group_id = $app->functions->intval($_SESSION["s"]["user"]["default_group"]);
$client = $app->db->queryOneRecord("SELECT client_id FROM sys_group WHERE sys_group.groupid = $client_group_id");
$client_id = $app->functions->intval($client["client_id"]);
} elseif (isset($page_form->dataRecord["client_group_id"])) {
$client_group_id = $page_form->dataRecord["client_group_id"];
$client = $app->db->queryOneRecord("SELECT client_id FROM sys_group WHERE sys_group.groupid = ".$app->functions->intval(@$page_form->dataRecord["client_group_id"]));
$client_id = $app->functions->intval($client["client_id"]);
} else {
$client = $app->db->queryOneRecord("SELECT client_id FROM sys_group WHERE sys_group.groupid = ".$app->functions->intval($page_form->dataRecord["client_group_id"]));
$client_id = $app->functions->intval($client["client_id"]);
}
// Set the values for document_root, system_user and system_group
$system_user = $app->db->quote('web'.$page_form->id);
$system_group = $app->db->quote('client'.$client_id);
$document_root = str_replace("[client_id]", $client_id, $document_root);
$document_root = str_replace("[client_idhash_1]", $this->id_hash($client_id, 1), $document_root);
$document_root = str_replace("[client_idhash_2]", $this->id_hash($client_id, 2), $document_root);
$document_root = str_replace("[client_idhash_3]", $this->id_hash($client_id, 3), $document_root);
$document_root = str_replace("[client_idhash_4]", $this->id_hash($client_id, 4), $document_root);
$document_root = $app->db->quote($document_root);
if($event_name == 'sites:web_vhost_domain:on_after_update') {
if(($_SESSION["s"]["user"]["typ"] == 'admin' || $app->auth->has_clients($_SESSION['s']['user']['userid'])) && isset($page_form->dataRecord["client_group_id"]) && $page_form->dataRecord["client_group_id"] != $page_form->oldDataRecord["sys_groupid"]) {
$sql = "UPDATE web_domain SET system_user = '$system_user', system_group = '$system_group', document_root = '$document_root' WHERE domain_id = ".$page_form->id;
$app->db->query($sql);
// Update the FTP user(s) too
$records = $app->db->queryAllRecords("SELECT ftp_user_id FROM ftp_user WHERE parent_domain_id = ".$page_form->id);
foreach($records as $rec) {
$app->db->datalogUpdate('ftp_user', "sys_userid = '".$app->functions->intval($web_rec['sys_userid'])."', sys_groupid = '".$app->functions->intval($web_rec['sys_groupid'])."', uid = '$system_user', gid = '$system_group', dir = '$document_root'", 'ftp_user_id', $app->functions->intval($rec['ftp_user_id']));
}
unset($records);
unset($rec);
// Update the Shell user(s) too
$records = $app->db->queryAllRecords("SELECT shell_user_id FROM shell_user WHERE parent_domain_id = ".$page_form->id);
foreach($records as $rec) {
$app->db->datalogUpdate('shell_user', "sys_userid = '".$web_rec['sys_userid']."', sys_groupid = '".$web_rec['sys_groupid']."', puser = '$system_user', pgroup = '$system_group', dir = '$document_root'", 'shell_user_id', $app->functions->intval($rec['shell_user_id']));
}
unset($records);
unset($rec);
//* Update all subdomains and alias domains
$records = $app->db->queryAllRecords("SELECT domain_id, `domain`, `type`, `web_folder` FROM web_domain WHERE parent_domain_id = ".$page_form->id);
foreach($records as $rec) {
$update_columns = "sys_userid = '".$web_rec['sys_userid']."', sys_groupid = '".$web_rec['sys_groupid']."'";
if($rec['type'] == 'vhostsubdomain' || $rec['type'] == 'vhostalias') {
$php_open_basedir = str_replace("[website_path]/web", $document_root.'/'.$rec['web_folder'], $web_config["php_open_basedir"]);
$php_open_basedir = str_replace("[website_domain]/web", $rec['domain'].'/'.$rec['web_folder'], $php_open_basedir);
$php_open_basedir = str_replace("[website_path]", $document_root, $php_open_basedir);
$php_open_basedir = $app->db->quote(str_replace("[website_domain]", $rec['domain'], $php_open_basedir));
$update_columns .= ", document_root = '".$document_root."', `php_open_basedir` = '".$php_open_basedir."'";
}
$app->db->datalogUpdate('web_domain', $update_columns, 'domain_id', $rec['domain_id']);
}
unset($records);
unset($rec);
//* Update all databases
$records = $app->db->queryAllRecords("SELECT database_id FROM web_database WHERE parent_domain_id = ".$page_form->id);
foreach($records as $rec) {
$app->db->datalogUpdate('web_database', "sys_userid = '".$app->functions->intval($web_rec['sys_userid'])."', sys_groupid = '".$app->functions->intval($web_rec['sys_groupid'])."'", 'database_id', $app->functions->intval($rec['database_id']));
}
unset($records);
unset($rec);
}
//* If the domain name has been changed, we will have to change all subdomains + APS instances
if(!empty($page_form->dataRecord["domain"]) && !empty($page_form->oldDataRecord["domain"]) && $page_form->dataRecord["domain"] != $page_form->oldDataRecord["domain"]) {
$records = $app->db->queryAllRecords("SELECT domain_id,domain FROM web_domain WHERE (type = 'subdomain' OR type = 'vhostsubdomain' OR type = 'vhostalias') AND domain LIKE '%.".$app->db->quote($page_form->oldDataRecord["domain"])."'");
foreach($records as $rec) {
$subdomain = $app->db->quote(str_replace($page_form->oldDataRecord["domain"], $page_form->dataRecord["domain"], $rec['domain']));
$app->db->datalogUpdate('web_domain', "domain = '".$subdomain."'", 'domain_id', $rec['domain_id']);
}
unset($records);
unset($rec);
unset($subdomain);
// Update APS instances
$records = $app->db->queryAllRecords("SELECT id, instance_id FROM aps_instances_settings WHERE name = 'main_domain' AND value = '".$app->db->quote($page_form->oldDataRecord["domain"])."'");
if(is_array($records) && !empty($records)){
foreach($records as $rec){
$app->db->datalogUpdate('aps_instances_settings', "value = '".$app->db->quote($page_form->dataRecord["domain"])."'", 'id', $rec['id']);
// Reinstall of package needed?
//$app->db->datalogUpdate('aps_instances', "instance_status = '1'", 'id', $rec['instance_id']);
}
}
unset($records);
unset($rec);
}
//* Set allow_override if empty
if($web_rec['allow_override'] == '') {
$sql = "UPDATE web_domain SET allow_override = '".$app->db->quote($web_config["htaccess_allow_override"])."' WHERE domain_id = ".$page_form->id;
$app->db->query($sql);
}
//* Set php_open_basedir if empty or domain or client has been changed
if(empty($web_rec['php_open_basedir']) ||
(!empty($page_form->dataRecord["domain"]) && !empty($page_form->oldDataRecord["domain"]) && $page_form->dataRecord["domain"] != $page_form->oldDataRecord["domain"])) {
$php_open_basedir = $web_rec['php_open_basedir'];
$php_open_basedir = $app->db->quote(str_replace($page_form->oldDataRecord['domain'], $web_rec['domain'], $php_open_basedir));
$sql = "UPDATE web_domain SET php_open_basedir = '$php_open_basedir' WHERE domain_id = ".$page_form->id;
$app->db->query($sql);
}
if(empty($web_rec['php_open_basedir']) ||
(isset($page_form->dataRecord["client_group_id"]) && $page_form->dataRecord["client_group_id"] != $page_form->oldDataRecord["sys_groupid"])) {
$document_root = $app->db->quote(str_replace("[client_id]", $client_id, $document_root));
$php_open_basedir = str_replace("[website_path]", $document_root, $web_config["php_open_basedir"]);
$php_open_basedir = $app->db->quote(str_replace("[website_domain]", $web_rec['domain'], $php_open_basedir));
$sql = "UPDATE web_domain SET php_open_basedir = '$php_open_basedir' WHERE domain_id = ".$page_form->id;
$app->db->query($sql);
}
//* Change database backup options when web backup options have been changed
if(isset($page_form->dataRecord['backup_interval']) && ($page_form->dataRecord['backup_interval'] != $page_form->oldDataRecord['backup_interval'] || $page_form->dataRecord['backup_copies'] != $page_form->oldDataRecord['backup_copies'])) {
//* Update all databases
$backup_interval = $app->functions->intval($page_form->dataRecord['backup_interval']);
$backup_copies = $app->functions->intval($page_form->dataRecord['backup_copies']);
$records = $app->db->queryAllRecords("SELECT database_id FROM web_database WHERE parent_domain_id = ".$page_form->id);
foreach($records as $rec) {
$app->db->datalogUpdate('web_database', "backup_interval = '$backup_interval', backup_copies = '$backup_copies'", 'database_id', $rec['database_id']);
}
unset($records);
unset($rec);
unset($backup_copies);
unset($backup_interval);
}
//* Change vhost subdomain and alias ip/ipv6 if domain ip/ipv6 has changed
if(isset($page_form->dataRecord['ip_address']) && ($page_form->dataRecord['ip_address'] != $page_form->oldDataRecord['ip_address'] || $page_form->dataRecord['ipv6_address'] != $page_form->oldDataRecord['ipv6_address'])) {
$records = $app->db->queryAllRecords("SELECT domain_id FROM web_domain WHERE (type = 'vhostsubdomain' OR type = 'vhostalias') AND parent_domain_id = ".$page_form->id);
foreach($records as $rec) {
$app->db->datalogUpdate('web_domain', "ip_address = '".$app->db->quote($web_rec['ip_address'])."', ipv6_address = '".$app->db->quote($web_rec['ipv6_address'])."'", 'domain_id', $rec['domain_id']);
}
unset($records);
unset($rec);
}
} else {
$php_open_basedir = str_replace("[website_path]", $document_root, $web_config["php_open_basedir"]);
$php_open_basedir = $app->db->quote(str_replace("[website_domain]", $page_form->dataRecord['domain'], $php_open_basedir));
$htaccess_allow_override = $app->db->quote($web_config["htaccess_allow_override"]);
$sql = "UPDATE web_domain SET system_user = '$system_user', system_group = '$system_group', document_root = '$document_root', allow_override = '$htaccess_allow_override', php_open_basedir = '$php_open_basedir' WHERE domain_id = ".$page_form->id;
$app->db->query($sql);
}
} else {
$parent_domain = $app->db->queryOneRecord("SELECT * FROM `web_domain` WHERE `domain_id` = '" . $app->functions->intval($page_form->dataRecord['parent_domain_id']) . "'");
// Set the values for document_root, system_user and system_group
$system_user = $app->db->quote($parent_domain['system_user']);
$system_group = $app->db->quote($parent_domain['system_group']);
$document_root = $app->db->quote($parent_domain['document_root']);
$php_open_basedir = str_replace("[website_path]/web", $document_root.'/'.$page_form->dataRecord['web_folder'], $web_config["php_open_basedir"]);
$php_open_basedir = str_replace("[website_domain]/web", $page_form->dataRecord['domain'].'/'.$page_form->dataRecord['web_folder'], $php_open_basedir);
$php_open_basedir = str_replace("[website_path]", $document_root, $php_open_basedir);
$php_open_basedir = $app->db->quote(str_replace("[website_domain]", $page_form->dataRecord['domain'], $php_open_basedir));
$htaccess_allow_override = $app->db->quote($parent_domain['allow_override']);
$sql = "UPDATE web_domain SET sys_groupid = ".$app->functions->intval($parent_domain['sys_groupid']).",system_user = '$system_user', system_group = '$system_group', document_root = '$document_root', allow_override = '$htaccess_allow_override', php_open_basedir = '$php_open_basedir' WHERE domain_id = ".$page_form->id;
$app->db->query($sql);
}
}
}
<?php
/**
* sites_web_domain_plugin plugin
*
* @author Marius Cramer <m.cramer@pixcept.de> pixcept KG 2012, copied and adapted from web_domain plugin by:
* @author Julio Montoya <gugli100@gmail.com> BeezNest 2010
*/
class sites_web_vhost_subdomain_plugin {
var $plugin_name = 'sites_web_vhost_subdomain_plugin';
var $class_name = 'sites_web_vhost_subdomain_plugin';
// TODO: This function is a duplicate from the one in interface/web/sites/web_vhost_subdomain_edit.php
// There should be a single "token replacement" function to be called from modules and
// from the main code.
// Returna a "3/2/1" path hash from a numeric id '123'
function id_hash($id, $levels) {
$hash = "" . $id % 10 ;
$id /= 10 ;
$levels -- ;
while ( $levels > 0 ) {
$hash .= "/" . $id % 10 ;
$id /= 10 ;
$levels-- ;
}
return $hash;
}
/*
This function is called when the plugin is loaded
*/
function onLoad() {
global $app;
//Register for the events
// both event call the same function as the things to do do not differ here
$app->plugin->registerEvent('sites:web_vhost_subdomain:on_after_insert', 'sites_web_vhost_subdomain_plugin', 'sites_web_vhost_subdomain_edit');
$app->plugin->registerEvent('sites:web_vhost_subdomain:on_after_update', 'sites_web_vhost_subdomain_plugin', 'sites_web_vhost_subdomain_edit');
}
/*
Function to create the sites_web_vhost_subdomain rule and insert it into the custom rules
*/
function sites_web_vhost_subdomain_edit($event_name, $page_form) {
global $app, $conf;
// Get configuration for the web system
$app->uses("getconf");
$web_config = $app->getconf->get_server_config($app->functions->intval($page_form->dataRecord['server_id']), 'web');
$parent_domain = $app->db->queryOneRecord("SELECT * FROM `web_domain` WHERE `domain_id` = '" . $app->functions->intval($page_form->dataRecord['parent_domain_id']) . "'");
// Set the values for document_root, system_user and system_group
$system_user = $app->db->quote($parent_domain['system_user']);
$system_group = $app->db->quote($parent_domain['system_group']);
$document_root = $app->db->quote($parent_domain['document_root']);
$php_open_basedir = str_replace("[website_path]/web", $document_root.'/'.$page_form->dataRecord['web_folder'], $web_config["php_open_basedir"]);
$php_open_basedir = str_replace("[website_domain]/web", $page_form->dataRecord['domain'].'/'.$page_form->dataRecord['web_folder'], $php_open_basedir);
$php_open_basedir = str_replace("[website_path]", $document_root, $php_open_basedir);
$php_open_basedir = $app->db->quote(str_replace("[website_domain]", $page_form->dataRecord['domain'], $php_open_basedir));
$htaccess_allow_override = $app->db->quote($parent_domain['allow_override']);
$sql = "UPDATE web_domain SET sys_groupid = ".$app->functions->intval($parent_domain['sys_groupid']).",system_user = '$system_user', system_group = '$system_group', document_root = '$document_root', allow_override = '$htaccess_allow_override', php_open_basedir = '$php_open_basedir' WHERE domain_id = ".$page_form->id;
$app->db->query($sql);
}
}
......@@ -38,15 +38,31 @@
*/
$form["title"] = "Web Domain";
$vhostdomain_type = 'domain';
$form_title = "Web Domain";
$validator_function = 'web_domain';
if(isset($_SESSION['s']['var']['vhostdomain_type'])) {
if($_SESSION['s']['var']['vhostdomain_type'] == 'subdomain') {
$vhostdomain_type = 'subdomain';
$form_title = "Subdomain";
$validator_function = 'sub_domain';
} elseif($_SESSION['s']['var']['vhostdomain_type'] == 'aliasdomain') {
$vhostdomain_type = 'aliasdomain';
$form_title = "Aliasdomain";
$validator_function = 'alias_domain';
}
}
$form["title"] = $form_title;
$form["description"] = "";
$form["name"] = "web_domain";
$form["action"] = "web_domain_edit.php";
$form["name"] = "web_vhost_domain";
$form["action"] = "web_vhost_domain_edit.php";
$form["db_table"] = "web_domain";
$form["db_table_idx"] = "domain_id";
$form["db_history"] = "yes";
$form["tab_default"] = "domain";
$form["list_default"] = "web_domain_list.php";
$form["list_default"] = "web_vhost_domain_list.php";
$form["auth"] = 'yes'; // yes / no
$form["auth_preset"]["userid"] = 0; // 0 = id of the user, > 0 id must match with id of current user
......@@ -55,14 +71,16 @@ $form["auth_preset"]["perm_user"] = 'riud'; //r = read, i = insert, u = update,
$form["auth_preset"]["perm_group"] = 'riud'; //r = read, i = insert, u = update, d = delete
$form["auth_preset"]["perm_other"] = ''; //r = read, i = insert, u = update, d = delete
$web_domain_edit_readonly = false;
// Clients may not change the website basic settings if they are not resellers
if($app->auth->has_clients($_SESSION['s']['user']['userid']) || $app->auth->is_admin()) {
$web_domain_edit_readonly = false;
} else {
$web_domain_edit_readonly = true;
if($vhostdomain_type == 'domain') $web_domain_edit_readonly = true;
}
$wildcard_available = true;
if($vhostdomain_type != 'domain') $wildcard_available = false;
$ssl_available = true;
if(!$app->auth->is_admin()) {
$client_group_id = $_SESSION["s"]["user"]["default_group"];
......@@ -78,7 +96,7 @@ $web_config = $app->getconf->get_global_config('sites');
$form["tabs"]['domain'] = array (
'title' => "Domain",
'width' => 100,
'template' => "templates/web_domain_edit.htm",
'template' => "templates/web_vhost_domain_edit.htm",
'readonly' => $web_domain_edit_readonly,
'fields' => array (
//#################################
......@@ -88,9 +106,6 @@ $form["tabs"]['domain'] = array (
'datatype' => 'INTEGER',
'formtype' => 'SELECT',
'default' => '',
'validators' => array ( 0 => array ( 'type' => 'NOTEMPTY',
'errmsg'=> 'no_server_error'),
),
'datasource' => array ( 'type' => 'SQL',
'querystring' => 'SELECT server_id,server_name FROM server WHERE mirror_server_id = 0 AND web_server = 1 AND {AUTHSQL} ORDER BY server_name',
'keyfield'=> 'server_id',
......@@ -134,7 +149,7 @@ $form["tabs"]['domain'] = array (
),
'validators' => array ( 0 => array ( 'type' => 'CUSTOM',
'class' => 'validate_domain',
'function' => 'web_domain',
'function' => $validator_function,