Skip to content

Commit cb1aa5f

Browse files
author
mcramer
committed
- Added remoting functions for vhost subdomains
- Added plugin for vhost subdomains to catch onafterinsert/update
1 parent aadcccb commit cb1aa5f

File tree

2 files changed

+136
-0
lines changed

2 files changed

+136
-0
lines changed

interface/lib/classes/remoting.inc.php

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1474,6 +1474,75 @@ public function sites_web_domain_delete($session_id, $primary_id)
14741474
return $affected_rows;
14751475
}
14761476

1477+
// ----------------------------------------------------------------------------------------------------------
1478+
1479+
//* Get record details
1480+
public function sites_web_vhost_subdomain_get($session_id, $primary_id)
1481+
{
1482+
global $app;
1483+
1484+
if(!$this->checkPerm($session_id, 'sites_web_subdomain_get')) {
1485+
$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
1486+
return false;
1487+
}
1488+
$app->uses('remoting_lib');
1489+
$app->remoting_lib->loadFormDef('../sites/form/web_vhost_subdomain.tform.php');
1490+
return $app->remoting_lib->getDataRecord($primary_id);
1491+
}
1492+
1493+
//* Add a record
1494+
public function sites_web_vhost_subdomain_add($session_id, $client_id, $params)
1495+
{
1496+
global $app;
1497+
if(!$this->checkPerm($session_id, 'sites_web_subdomain_add')) {
1498+
$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
1499+
return false;
1500+
}
1501+
1502+
//* Set a few params to "not empty" values which get overwritten by the sites_web_domain_plugin
1503+
if($params['document_root'] == '') $params['document_root'] = '-';
1504+
if($params['system_user'] == '') $params['system_user'] = '-';
1505+
if($params['system_group'] == '') $params['system_group'] = '-';
1506+
1507+
//* Set a few defaults for nginx servers
1508+
if($params['pm_max_children'] == '') $params['pm_max_children'] = 1;
1509+
if($params['pm_start_servers'] == '') $params['pm_start_servers'] = 1;
1510+
if($params['pm_min_spare_servers'] == '') $params['pm_min_spare_servers'] = 1;
1511+
if($params['pm_max_spare_servers'] == '') $params['pm_max_spare_servers'] = 1;
1512+
1513+
$domain_id = $this->insertQuery('../sites/form/web_vhost_subdomain.tform.php',$client_id,$params, 'sites:web_vhost_subdomain:on_after_insert');
1514+
return $domain_id;
1515+
}
1516+
1517+
//* Update a record
1518+
public function sites_web_vhost_subdomain_update($session_id, $client_id, $primary_id, $params)
1519+
{
1520+
if(!$this->checkPerm($session_id, 'sites_web_subdomain_update')) {
1521+
$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
1522+
return false;
1523+
}
1524+
1525+
//* Set a few defaults for nginx servers
1526+
if($params['pm_max_children'] == '') $params['pm_max_children'] = 1;
1527+
if($params['pm_start_servers'] == '') $params['pm_start_servers'] = 1;
1528+
if($params['pm_min_spare_servers'] == '') $params['pm_min_spare_servers'] = 1;
1529+
if($params['pm_max_spare_servers'] == '') $params['pm_max_spare_servers'] = 1;
1530+
1531+
$affected_rows = $this->updateQuery('../sites/form/web_vhost_subdomain.tform.php',$client_id,$primary_id,$params, 'sites:web_vhost_subdomain:on_after_insert');
1532+
return $affected_rows;
1533+
}
1534+
1535+
//* Delete a record
1536+
public function sites_web_vhost_subdomain_delete($session_id, $primary_id)
1537+
{
1538+
if(!$this->checkPerm($session_id, 'sites_web_subdomain_delete')) {
1539+
$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
1540+
return false;
1541+
}
1542+
$affected_rows = $this->deleteQuery('../sites/form/web_vhost_subdomain.tform.php',$primary_id);
1543+
return $affected_rows;
1544+
}
1545+
14771546
// -----------------------------------------------------------------------------------------------
14781547

14791548
//* Get record details
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?php
2+
/**
3+
* sites_web_domain_plugin plugin
4+
*
5+
* @author Marius Cramer <m.cramer@pixcept.de> pixcept KG 2012, copied and adapted from web_domain plugin by:
6+
* @author Julio Montoya <gugli100@gmail.com> BeezNest 2010
7+
*/
8+
9+
class sites_web_vhost_subdomain_plugin {
10+
11+
var $plugin_name = 'sites_web_vhost_subdomain_plugin';
12+
var $class_name = 'sites_web_vhost_subdomain_plugin';
13+
14+
// TODO: This function is a duplicate from the one in interface/web/sites/web_vhost_subdomain_edit.php
15+
// There should be a single "token replacement" function to be called from modules and
16+
// from the main code.
17+
// Returna a "3/2/1" path hash from a numeric id '123'
18+
function id_hash($id,$levels) {
19+
$hash = "" . $id % 10 ;
20+
$id /= 10 ;
21+
$levels -- ;
22+
while ( $levels > 0 ) {
23+
$hash .= "/" . $id % 10 ;
24+
$id /= 10 ;
25+
$levels-- ;
26+
}
27+
return $hash;
28+
}
29+
30+
/*
31+
This function is called when the plugin is loaded
32+
*/
33+
function onLoad() {
34+
global $app;
35+
//Register for the events
36+
// both event call the same function as the things to do do not differ here
37+
$app->plugin->registerEvent('sites:web_vhost_subdomain:on_after_insert','sites_web_vhost_subdomain_plugin','sites_web_vhost_subdomain_edit');
38+
$app->plugin->registerEvent('sites:web_vhost_subdomain:on_after_update','sites_web_vhost_subdomain_plugin','sites_web_vhost_subdomain_edit');
39+
}
40+
41+
/*
42+
Function to create the sites_web_vhost_subdomain rule and insert it into the custom rules
43+
*/
44+
function sites_web_vhost_subdomain_edit($event_name, $page_form) {
45+
global $app, $conf;
46+
47+
// Get configuration for the web system
48+
$app->uses("getconf");
49+
$web_rec = $app->tform->getDataRecord($page_form->id);
50+
$web_config = $app->getconf->get_server_config(intval($web_rec['server_id']),'web');
51+
52+
$parent_domain = $app->db->queryOneRecord("SELECT * FROM `web_domain` WHERE `domain_id` = '" . intval($web_rec['parent_domain_id']) . "'");
53+
54+
// Set the values for document_root, system_user and system_group
55+
$system_user = $app->db->quote($parent_domain['system_user']);
56+
$system_group = $app->db->quote($parent_domain['system_group']);
57+
$document_root = $app->db->quote($parent_domain['document_root']);
58+
$php_open_basedir = str_replace("[website_path]/web",$document_root.'/'.$web_rec['web_folder'],$web_config["php_open_basedir"]);
59+
$php_open_basedir = str_replace("[website_domain]/web",$web_rec['domain'].'/'.$web_rec['web_folder'],$php_open_basedir);
60+
$php_open_basedir = str_replace("[website_path]",$document_root,$php_open_basedir);
61+
$php_open_basedir = $app->db->quote(str_replace("[website_domain]",$web_rec['domain'],$php_open_basedir));
62+
$htaccess_allow_override = $app->db->quote($parent_domain['allow_override']);
63+
64+
$sql = "UPDATE web_domain SET sys_groupid = ".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;
65+
$app->db->query($sql);
66+
}
67+
}

0 commit comments

Comments
 (0)