Skip to content

Commit 31f6ceb

Browse files
author
mcramer
committed
Changed: tools.inc.php removed from different places and converted to class where neccessary
Fixed: Subtemplates can now be given on client creation in remoting (i.e. 10/34/21 for multiple addons) Changed: template applying moved to separate class Fixed: force_suexec was not taken from templates
1 parent 36bb816 commit 31f6ceb

22 files changed

+858
-935
lines changed

interface/lib/classes/aps_guicontroller.inc.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,8 @@ public function createPackageInstance($settings, $packageid)
199199
{
200200
global $app;
201201

202-
include_once(ISPC_WEB_PATH.'/sites/tools.inc.php');
203-
202+
$app->uses('tools_sites');
203+
204204
$webserver_id = 0;
205205
$websrv = $this->db->queryOneRecord("SELECT * FROM web_domain WHERE domain = '".$this->db->quote($settings['main_domain'])."';");
206206
if(!empty($websrv)) $webserver_id = $websrv['server_id'];
@@ -231,8 +231,8 @@ public function createPackageInstance($settings, $packageid)
231231
$tmp = array();
232232
$tmp['parent_domain_id'] = $websrv['domain_id'];
233233
$tmp['sys_groupid'] = $websrv['sys_groupid'];
234-
$dbname_prefix = replacePrefix($global_config['dbname_prefix'], $tmp);
235-
$dbuser_prefix = replacePrefix($global_config['dbuser_prefix'], $tmp);
234+
$dbname_prefix = $app->tools_sites->replacePrefix($global_config['dbname_prefix'], $tmp);
235+
$dbuser_prefix = $app->tools_sites->replacePrefix($global_config['dbuser_prefix'], $tmp);
236236
unset($tmp);
237237

238238
//* get the default database server of the client
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
<?php
2+
/**
3+
* client_templates
4+
*
5+
* @author Marius Cramer <m.cramer@pixcept.de> pixcept KG
6+
* @author (original tools.inc.php) Till Brehm, projektfarm Gmbh
7+
* @author (original tools.inc.php) Oliver Vogel www.muv.com
8+
*/
9+
10+
class client_templates {
11+
12+
function apply_client_templates($clientId, $limits = array()) {
13+
global $app;
14+
15+
if(!is_array($limits)) $limits = array();
16+
17+
/*
18+
* Get the master-template for the client
19+
*/
20+
$sql = "SELECT template_master, template_additional FROM client WHERE client_id = " . intval($clientId);
21+
$record = $app->db->queryOneRecord($sql);
22+
$masterTemplateId = $record['template_master'];
23+
$additionalTemplateStr = $record['template_additional'];
24+
25+
/*
26+
* if the master-Template is custom there is NO changing
27+
*/
28+
if ($masterTemplateId > 0){
29+
$sql = "SELECT * FROM client_template WHERE template_id = " . intval($masterTemplateId);
30+
$limits = $app->db->queryOneRecord($sql);
31+
}
32+
33+
/*
34+
* Process the additional tempaltes here (add them to the limits
35+
* if != -1)
36+
*/
37+
$addTpl = explode('/', $additionalTemplateStr);
38+
foreach ($addTpl as $item){
39+
if (trim($item) != ''){
40+
$sql = "SELECT * FROM client_template WHERE template_id = " . intval($item);
41+
$addLimits = $app->db->queryOneRecord($sql);
42+
/* maybe the template is deleted in the meantime */
43+
if (is_array($addLimits)){
44+
foreach($addLimits as $k => $v){
45+
/* we can remove this condition, but it is easier to debug with it (don't add ids and other non-limit values) */
46+
if (strpos($k, 'limit') !== false){
47+
/* process the numerical limits */
48+
if (is_numeric($v)){
49+
/* switch for special cases */
50+
switch ($k){
51+
case 'limit_cron_frequency':
52+
if ($v < $limits[$k]) $limits[$k] = $v;
53+
/* silent adjustment of the minimum cron frequency to 1 minute */
54+
/* maybe this control test should be done via validator definition in tform.php file, but I don't know how */
55+
if ($limits[$k] < 1) $limits[$k] = 1;
56+
break;
57+
58+
default:
59+
if ($limits[$k] > -1){
60+
if ($v == -1){
61+
$limits[$k] = -1;
62+
}
63+
else {
64+
$limits[$k] += $v;
65+
}
66+
}
67+
}
68+
}
69+
/* process the string limits (CHECKBOXARRAY, SELECT etc.) */
70+
elseif (is_string($v)){
71+
switch ($app->tform->formDef["tabs"]["limits"]["fields"][$k]['formtype']){
72+
case 'CHECKBOXARRAY':
73+
if (!isset($limits[$k])){
74+
$limits[$k] = array();
75+
}
76+
77+
$limits_values = $limits[$k];
78+
if (is_string($limits[$k])){
79+
$limits_values = explode($app->tform->formDef["tabs"]["limits"]["fields"][$k]["separator"],$limits[$k]);
80+
}
81+
$additional_values = explode($app->tform->formDef["tabs"]["limits"]["fields"][$k]["separator"],$v);
82+
83+
/* unification of limits_values (master template) and additional_values (additional template) */
84+
$limits_unified = array();
85+
foreach($app->tform->formDef["tabs"]["limits"]["fields"][$k]["value"] as $key => $val){
86+
if (in_array($key,$limits_values) || in_array($key,$additional_values)) $limits_unified[] = $key;
87+
}
88+
$limits[$k] = implode($app->tform->formDef["tabs"]["limits"]["fields"][$k]["separator"],$limits_unified);
89+
break;
90+
91+
case 'SELECT':
92+
$limit_values = array_keys($app->tform->formDef["tabs"]["limits"]["fields"][$k]["value"]);
93+
/* choose the lower index of the two SELECT items */
94+
$limits[$k] = $limit_values[min(array_search($limits[$k], $limit_values), array_search($v, $limit_values))];
95+
break;
96+
}
97+
}
98+
}
99+
}
100+
}
101+
}
102+
}
103+
104+
/*
105+
* Write all back to the database
106+
*/
107+
$update = '';
108+
foreach($limits as $k => $v){
109+
if ((strpos($k, 'limit') !== false or $k == 'ssh_chroot' or $k == 'web_php_options' or $k == 'force_suexec') && !is_array($v)){
110+
if ($update != '') $update .= ', ';
111+
$update .= '`' . $k . "`='" . $v . "'";
112+
}
113+
}
114+
if($update != '') {
115+
$sql = 'UPDATE client SET ' . $update . " WHERE client_id = " . intval($clientId);
116+
$app->db->query($sql);
117+
}
118+
}
119+
}

interface/lib/classes/remoting.inc.php

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1063,7 +1063,7 @@ public function client_add($session_id, $reseller_id, $params)
10631063
$this->server->fault('permission_denied','You do not have the permissions to access this function.');
10641064
return false;
10651065
}
1066-
$affected_rows = $this->klientadd('../client/form/client.tform.php',$reseller_id, $params);
1066+
$affected_rows = $this->klientadd('../client/form/' . ($reseller_id ? 'reseller' : 'client') . '.tform.php',$reseller_id, $params);
10671067
return $affected_rows;
10681068

10691069
}
@@ -1077,7 +1077,7 @@ public function client_update($session_id, $client_id, $reseller_id, $params)
10771077
$this->server->fault('permission_denied','You do not have the permissions to access this function.');
10781078
return false;
10791079
}
1080-
$affected_rows = $this->updateQuery('../client/form/client.tform.php', $reseller_id, $client_id, $params);
1080+
$affected_rows = $this->updateQuery('../client/form/' . ($reseller_id ? 'reseller' : 'client') . '.tform.php', $reseller_id, $client_id, $params);
10811081

10821082
$app->remoting_lib->ispconfig_sysuser_update($params,$client_id);
10831083

@@ -2612,13 +2612,6 @@ protected function klientadd($formdef_file, $reseller_id, $params)
26122612
//* load the user profile of the client
26132613
$app->remoting_lib->loadUserProfile($reseller_id);
26142614

2615-
//* load the client template
2616-
if(isset($params['template_master']) and $params['template_master'] > 0)
2617-
{
2618-
$template=$app->db->queryOneRecord("SELECT * FROM client_template WHERE template_id=".intval($params['template_master']));
2619-
if(is_array($template)) $params=array_merge($params,$template);
2620-
}
2621-
26222615
//* Get the SQL query
26232616
$sql = $app->remoting_lib->getSQL($params,'INSERT',0);
26242617

@@ -2647,7 +2640,7 @@ protected function klientadd($formdef_file, $reseller_id, $params)
26472640
$this->id = $insert_id;
26482641
$this->dataRecord = $params;
26492642

2650-
$app->plugin->raiseEvent('client:client:on_after_insert',$this);
2643+
$app->plugin->raiseEvent('client:' . ($reseller_id ? 'reseller' : 'client') . ':on_after_insert',$this);
26512644

26522645
/*
26532646
if($app->db->errorMessage != '') {

0 commit comments

Comments
 (0)