Skip to content

Commit 2a3cab8

Browse files
committed
Implemented: FS#1324 - Add new file system path splitter for large installations
1 parent 66bc13d commit 2a3cab8

File tree

3 files changed

+69
-9
lines changed

3 files changed

+69
-9
lines changed

interface/lib/classes/auth.inc.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,9 @@ public function get_client_limit($userid, $limitname)
8989
if(!$this->client_limits)
9090
return -1;
9191

92-
if(isset($this->client_limits['limit_'.$limitname]))
92+
if(isset($this->client_limits['limit_'.$limitname])) {
9393
return $this->client_limits['limit_'.$limitname];
94-
else
95-
trigger_error('Wrong limit identifier');
94+
}
9695
}
9796

9897
//** This function removes a given group id from a given user.

interface/lib/plugins/sites_web_domain_plugin.inc.php

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,22 @@ class sites_web_domain_plugin {
99

1010
var $plugin_name = 'sites_web_domain_plugin';
1111
var $class_name = 'sites_web_domain_plugin';
12+
13+
// TODO: This function is a duplicate from the one in interface/web/sites/web_domain_edit.php
14+
// There should be a single "token replacement" function to be called from modules and
15+
// from the main code.
16+
// Returna a "3/2/1" path hash from a numeric id '123'
17+
function id_hash($id,$levels) {
18+
$hash = "" . $id % 10 ;
19+
$id /= 10 ;
20+
$levels -- ;
21+
while ( $levels > 0 ) {
22+
$hash .= "/" . $id % 10 ;
23+
$id /= 10 ;
24+
$levels-- ;
25+
}
26+
return $hash;
27+
}
1228

1329
/*
1430
This function is called when the plugin is loaded
@@ -39,6 +55,11 @@ function sites_web_domain_edit($event_name, $page_form) {
3955
$app->uses("getconf");
4056
$web_config = $app->getconf->get_server_config(intval($page_form->dataRecord['server_id']),'web');
4157
$document_root = str_replace("[website_id]",$page_form->id,$web_config["website_path"]);
58+
$document_root = str_replace("[website_idhash_1]",$this->id_hash($page_form->id,1),$document_root);
59+
$document_root = str_replace("[website_idhash_2]",$this->id_hash($page_form->id,1),$document_root);
60+
$document_root = str_replace("[website_idhash_3]",$this->id_hash($page_form->id,1),$document_root);
61+
$document_root = str_replace("[website_idhash_4]",$this->id_hash($page_form->id,1),$document_root);
62+
4263
// get the ID of the client
4364
if($_SESSION["s"]["user"]["typ"] != 'admin' && !$app->auth->has_clients($_SESSION['s']['user']['userid'])) {
4465
$client_group_id = $_SESSION["s"]["user"]["default_group"];
@@ -53,11 +74,20 @@ function sites_web_domain_edit($event_name, $page_form) {
5374
// Set the values for document_root, system_user and system_group
5475
$system_user = $app->db->quote('web'.$page_form->id);
5576
$system_group = $app->db->quote('client'.$client_id);
56-
$document_root = $app->db->quote(str_replace("[client_id]",$client_id,$document_root));
57-
$php_open_basedir = str_replace("[website_path]",$document_root,$web_config["php_open_basedir"]);
77+
78+
$document_root = str_replace("[client_id]",$client_id,$document_root);
79+
$document_root = str_replace("[client_idhash_1]",$this->id_hash($client_id,1),$document_root);
80+
$document_root = str_replace("[client_idhash_2]",$this->id_hash($client_id,2),$document_root);
81+
$document_root = str_replace("[client_idhash_3]",$this->id_hash($client_id,3),$document_root);
82+
$document_root = str_replace("[client_idhash_4]",$this->id_hash($client_id,4),$document_root);
83+
$document_root = $app->db->quote($document_root);
84+
85+
$php_open_basedir = str_replace("[website_path]",$document_root,$web_config["php_open_basedir"]);
5886
$php_open_basedir = $app->db->quote(str_replace("[website_domain]",$page_form->dataRecord['domain'],$php_open_basedir));
59-
$htaccess_allow_override = $app->db->quote($web_config["htaccess_allow_override"]);
60-
$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;
87+
88+
$htaccess_allow_override = $app->db->quote($web_config["htaccess_allow_override"]);
89+
90+
$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;
6191
$app->db->query($sql);
6292
}
6393
}

interface/web/sites/web_domain_edit.php

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,19 @@
5050

5151
class page_action extends tform_actions {
5252

53+
// Returna a "3/2/1" path hash from a numeric id '123'
54+
function id_hash($id,$levels) {
55+
$hash = "" . $id % 10 ;
56+
$id /= 10 ;
57+
$levels -- ;
58+
while ( $levels > 0 ) {
59+
$hash .= "/" . $id % 10 ;
60+
$id /= 10 ;
61+
$levels-- ;
62+
}
63+
return $hash;
64+
}
65+
5366
function onShowNew() {
5467
global $app, $conf;
5568

@@ -345,6 +358,10 @@ function onAfterInsert() {
345358
$web_rec = $app->tform->getDataRecord($this->id);
346359
$web_config = $app->getconf->get_server_config(intval($web_rec["server_id"]),'web');
347360
$document_root = str_replace("[website_id]",$this->id,$web_config["website_path"]);
361+
$document_root = str_replace("[website_idhash_1]",$this->id_hash($page_form->id,1),$document_root);
362+
$document_root = str_replace("[website_idhash_2]",$this->id_hash($page_form->id,1),$document_root);
363+
$document_root = str_replace("[website_idhash_3]",$this->id_hash($page_form->id,1),$document_root);
364+
$document_root = str_replace("[website_idhash_4]",$this->id_hash($page_form->id,1),$document_root);
348365

349366
// get the ID of the client
350367
if($_SESSION["s"]["user"]["typ"] != 'admin' && !$app->auth->has_clients($_SESSION['s']['user']['userid'])) {
@@ -360,7 +377,12 @@ function onAfterInsert() {
360377
// Set the values for document_root, system_user and system_group
361378
$system_user = $app->db->quote('web'.$this->id);
362379
$system_group = $app->db->quote('client'.$client_id);
363-
$document_root = $app->db->quote(str_replace("[client_id]",$client_id,$document_root));
380+
$document_root = str_replace("[client_id]",$client_id,$document_root);
381+
$document_root = str_replace("[client_idhash_1]",$this->id_hash($client_id,1),$document_root);
382+
$document_root = str_replace("[client_idhash_2]",$this->id_hash($client_id,2),$document_root);
383+
$document_root = str_replace("[client_idhash_3]",$this->id_hash($client_id,3),$document_root);
384+
$document_root = str_replace("[client_idhash_4]",$this->id_hash($client_id,4),$document_root);
385+
$document_root = $app->db->quote($document_root);
364386
$php_open_basedir = str_replace("[website_path]",$document_root,$web_config["php_open_basedir"]);
365387
$php_open_basedir = $app->db->quote(str_replace("[website_domain]",$web_rec['domain'],$php_open_basedir));
366388
$htaccess_allow_override = $app->db->quote($web_config["htaccess_allow_override"]);
@@ -426,6 +448,10 @@ function onAfterUpdate() {
426448
$web_rec = $app->tform->getDataRecord($this->id);
427449
$web_config = $app->getconf->get_server_config(intval($web_rec["server_id"]),'web');
428450
$document_root = str_replace("[website_id]",$this->id,$web_config["website_path"]);
451+
$document_root = str_replace("[website_idhash_1]",$this->id_hash($page_form->id,1),$document_root);
452+
$document_root = str_replace("[website_idhash_2]",$this->id_hash($page_form->id,1),$document_root);
453+
$document_root = str_replace("[website_idhash_3]",$this->id_hash($page_form->id,1),$document_root);
454+
$document_root = str_replace("[website_idhash_4]",$this->id_hash($page_form->id,1),$document_root);
429455

430456
// get the ID of the client
431457
if($_SESSION["s"]["user"]["typ"] != 'admin' && !$app->auth->has_clients($_SESSION['s']['user']['userid'])) {
@@ -442,7 +468,12 @@ function onAfterUpdate() {
442468
// Set the values for document_root, system_user and system_group
443469
$system_user = $app->db->quote('web'.$this->id);
444470
$system_group = $app->db->quote('client'.$client_id);
445-
$document_root = $app->db->quote(str_replace("[client_id]",$client_id,$document_root));
471+
$document_root = str_replace("[client_id]",$client_id,$document_root);
472+
$document_root = str_replace("[client_idhash_1]",$this->id_hash($client_id,1),$document_root);
473+
$document_root = str_replace("[client_idhash_2]",$this->id_hash($client_id,2),$document_root);
474+
$document_root = str_replace("[client_idhash_3]",$this->id_hash($client_id,3),$document_root);
475+
$document_root = str_replace("[client_idhash_4]",$this->id_hash($client_id,4),$document_root);
476+
$document_root = $app->db->quote($document_root);
446477

447478
$sql = "UPDATE web_domain SET system_user = '$system_user', system_group = '$system_group', document_root = '$document_root' WHERE domain_id = ".$this->id;
448479
//$sql = "UPDATE web_domain SET system_user = '$system_user', system_group = '$system_group' WHERE domain_id = ".$this->id;

0 commit comments

Comments
 (0)