Newer
Older
<?php
/*
Copyright (c) 2007 - 2009, Till Brehm, projektfarm Gmbh
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of ISPConfig nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/******************************************
* Begin Form configuration
******************************************/
$tform_def_file = "form/web_vhost_domain.tform.php";
/******************************************
* End Form configuration
******************************************/
require_once '../../lib/config.inc.php';
require_once '../../lib/app.inc.php';
//* Check permissions for module
$app->auth->check_module_permissions('sites');
// Loading classes
$app->uses('tpl,tform,tform_actions,tools_sites');
$app->load('tform_actions');
class page_action extends tform_actions {
var $_vhostdomain_type = 'domain';
//* 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;
}
function onLoad() {
$show_type = 'domain';
if(isset($_GET['type']) && $_GET['type'] == 'subdomain') {
$show_type = 'subdomain';
} elseif(isset($_GET['type']) && $_GET['type'] == 'aliasdomain') {
$show_type = 'aliasdomain';
} elseif(!isset($_GET['type']) && isset($_SESSION['s']['var']['vhostdomain_type']) && $_SESSION['s']['var']['vhostdomain_type'] == 'subdomain') {
$show_type = 'subdomain';
} elseif(!isset($_GET['type']) && isset($_SESSION['s']['var']['vhostdomain_type']) && $_SESSION['s']['var']['vhostdomain_type'] == 'aliasdomain') {
$show_type = 'aliasdomain';
}
$_SESSION['s']['var']['vhostdomain_type'] = $show_type;
$this->_vhostdomain_type = $show_type;
parent::onLoad();
}
function onShowNew() {
global $app, $conf;
// we will check only users, not admins
if($_SESSION["s"]["user"]["typ"] == 'user') {
if($this->_vhostdomain_type == 'domain') {
if(!$app->tform->checkClientLimit('limit_web_domain', "type = 'vhost'")) {
$app->error($app->tform->wordbook["limit_web_domain_txt"]);
}
if(!$app->tform->checkResellerLimit('limit_web_domain', "type = 'vhost'")) {
$app->error('Reseller: '.$app->tform->wordbook["limit_web_domain_txt"]);
}
} elseif($this->_vhostdomain_type == 'subdomain') {
if(!$app->tform->checkClientLimit('limit_web_subdomain', "(type = 'subdomain' OR type = 'vhostsubdomain')")) {
$app->error($app->tform->wordbook["limit_web_subdomain_txt"]);
}
if(!$app->tform->checkResellerLimit('limit_web_subdomain', "(type = 'subdomain' OR type = 'vhostsubdomain')")) {
$app->error('Reseller: '.$app->tform->wordbook["limit_web_subdomain_txt"]);
}
} elseif($this->_vhostdomain_type == 'aliasdomain') {
if(!$app->tform->checkClientLimit('limit_web_aliasdomain', "(type = 'alias' OR type = 'vhostalias')")) {
$app->error($app->tform->wordbook["limit_web_aliasdomain_txt"]);
}
if(!$app->tform->checkResellerLimit('limit_web_aliasdomain', "(type = 'alias' OR type = 'vhostalias')")) {
$app->error('Reseller: '.$app->tform->wordbook["limit_web_aliasdomain_txt"]);
}
}
// Get the limits of the client
$client_group_id = $_SESSION["s"]["user"]["default_group"];
$client = $app->db->queryOneRecord("SELECT client.web_servers FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = $client_group_id");
$web_servers = explode(',', $client['web_servers']);
$server_id = $web_servers[0];
$app->tpl->setVar("server_id_value", $server_id);
} else {
$settings = $app->getconf->get_global_config('sites');
$server_id = intval($settings['default_webserver']);
$app->tform->formDef['tabs']['domain']['fields']['server_id']['default'] = $server_id;
if(!$server_id){
$default_web_server = $app->db->queryOneRecord("SELECT server_id FROM server WHERE web_server = ? ORDER BY server_id LIMIT 0,1", 1);
$server_id = $default_web_server['server_id'];
}
$web_config = $app->getconf->get_server_config($server_id, 'web');
$app->tform->formDef['tabs']['domain']['fields']['php']['default'] = $web_config['php_handler'];
$app->tform->formDef['tabs']['domain']['readonly'] = false;
$app->tpl->setVar('vhostdomain_type', $this->_vhostdomain_type);
parent::onShowNew();
}
function onShowEnd() {
global $app, $conf;
Sergio
committed
$settings = $app->getconf->get_global_config('domains');
$read_limits = array('limit_cgi', 'limit_ssi', 'limit_perl', 'limit_ruby', 'limit_python', 'force_suexec', 'limit_hterror', 'limit_wildcard', 'limit_ssl');
if($this->_vhostdomain_type != 'domain') $parent_domain = $app->db->queryOneRecord("select * FROM web_domain WHERE domain_id = ".$app->functions->intval(@$this->dataRecord["parent_domain_id"]));
//* Client: If the logged in user is not admin and has no sub clients (no reseller)
if($_SESSION["s"]["user"]["typ"] != 'admin' && !$app->auth->has_clients($_SESSION['s']['user']['userid'])) {
// Get the limits of the client
$client_group_id = $app->functions->intval($_SESSION["s"]["user"]["default_group"]);
if($this->_vhostdomain_type == 'domain') {
$client = $app->db->queryOneRecord("SELECT client.limit_web_domain, client.web_servers, client." . implode(", client.", $read_limits) . " FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = $client_group_id");
} elseif($this->_vhostdomain_type == 'subdomain') {
$client = $app->db->queryOneRecord("SELECT client.limit_web_subdomain, client.web_servers, client.default_webserver, client." . implode(", client.", $read_limits) . " FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = $client_group_id");
} elseif($this->_vhostdomain_type == 'aliasdomain') {
$client = $app->db->queryOneRecord("SELECT client.limit_web_aliasdomain, client.web_servers, client.default_webserver, client." . implode(", client.", $read_limits) . " FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = $client_group_id");
}
$client['web_servers_ids'] = explode(',', $client['web_servers']);
$only_one_server = count($client['web_servers_ids']) === 1;
$app->tpl->setVar('only_one_server', $only_one_server);
foreach ($client['web_servers_ids'] as $web_server_id) {
$web_config[$web_server_id] = $app->getconf->get_server_config($web_server_id, 'web');
}
$sql = "SELECT server_id, server_name FROM server WHERE server_id IN (" . $client['web_servers'] . ");";
$web_servers = $app->db->queryAllRecords($sql);
$options_web_servers = "";
foreach ($web_servers as $web_server) {
$options_web_servers .= "<option value='$web_server[server_id]'>$web_server[server_name]</option>";
}
$app->tpl->setVar("server_id", $options_web_servers);
unset($options_web_servers);
if($this->id > 0) {
if(!isset($this->dataRecord["server_id"])){
$tmp = $app->db->queryOneRecord("SELECT server_id FROM web_domain WHERE domain_id = ".$app->functions->intval($this->id));
$this->dataRecord["server_id"] = $tmp["server_id"];
unset($tmp);
}
$server_id = intval(@$this->dataRecord["server_id"]);
} else {
$server_id = (isset($web_servers[0])) ? intval($web_servers[0]) : 0;
}
if($app->functions->intval($this->dataRecord["server_id"]) > 0) {
// check if server is in client's servers or add it.
$chk_sid = explode(',', $client['web_servers']);
Falko Timme
committed
if(in_array($this->dataRecord["server_id"], explode(',', $client['web_servers'])) == false) {
if($client['web_servers'] != '') $client['web_servers'] .= ',';
$client['web_servers'] .= $app->functions->intval($this->dataRecord["server_id"]);
}
}
//* Fill the IPv4 select field with the IP addresses that are allowed for this client
Loading full blame...