Skip to content

Commit 1a5608d

Browse files
author
Till Brehm
committed
Implemented #5330 Limit available PHP Handlers globally in ISPConfig UI
1 parent de0ecf8 commit 1a5608d

File tree

12 files changed

+94
-58
lines changed

12 files changed

+94
-58
lines changed

install/tpl/system.ini.master

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ vhost_aliasdomains=n
3333
client_username_web_check_disabled=n
3434
backups_include_into_web_quota=n
3535
reseller_can_use_options=n
36+
web_php_options=no,fast-cgi,mod,php-fpm
3637

3738

3839
[tools]

interface/lib/classes/tform_base.inc.php

Lines changed: 69 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -336,69 +336,84 @@ function getDatasourceData($field, $record) {
336336
}
337337

338338
//* If the parameter 'valuelimit' is set
339-
function applyValueLimit($limit, $values) {
339+
function applyValueLimit($limit, $values, $current_value = '') {
340340

341341
global $app;
342+
343+
// we mas have multiple limits, therefore we explode by ; first
344+
// Example: "system:sites:web_php_options;client:web_php_options"
345+
$limits = explode(';',$limit);
346+
347+
348+
foreach($limits as $limit) {
342349

343-
$limit_parts = explode(':', $limit);
350+
$limit_parts = explode(':', $limit);
344351

345-
//* values are limited to a comma separated list
346-
if($limit_parts[0] == 'list') {
347-
$allowed = explode(',', $limit_parts[1]);
348-
}
349-
350-
//* values are limited to a field in the client settings
351-
if($limit_parts[0] == 'client') {
352-
if($_SESSION["s"]["user"]["typ"] == 'admin') {
353-
return $values;
354-
} else {
355-
$client_group_id = $_SESSION["s"]["user"]["default_group"];
356-
$client = $app->db->queryOneRecord("SELECT ".$limit_parts[1]." as lm FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = ?", $client_group_id);
357-
$allowed = explode(',', $client['lm']);
352+
//* values are limited to a comma separated list
353+
if($limit_parts[0] == 'list') {
354+
$allowed = explode(',', $limit_parts[1]);
358355
}
359-
}
360356

361-
//* values are limited to a field in the reseller settings
362-
if($limit_parts[0] == 'reseller') {
363-
if($_SESSION["s"]["user"]["typ"] == 'admin') {
364-
return $values;
365-
} else {
366-
//* Get the limits of the client that is currently logged in
367-
$client_group_id = $_SESSION["s"]["user"]["default_group"];
368-
$client = $app->db->queryOneRecord("SELECT parent_client_id FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = ?", $client_group_id);
369-
//echo "SELECT parent_client_id FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = $client_group_id";
370-
//* If the client belongs to a reseller, we will check against the reseller Limit too
371-
if($client['parent_client_id'] != 0) {
372-
373-
//* first we need to know the groups of this reseller
374-
$tmp = $app->db->queryOneRecord("SELECT userid, groups FROM sys_user WHERE client_id = ?", $client['parent_client_id']);
375-
$reseller_groups = $tmp["groups"];
376-
$reseller_userid = $tmp["userid"];
377-
378-
// Get the limits of the reseller of the logged in client
379-
$client_group_id = $_SESSION["s"]["user"]["default_group"];
380-
$reseller = $app->db->queryOneRecord("SELECT ".$limit_parts[1]." as lm FROM client WHERE client_id = ?", $client['parent_client_id']);
381-
$allowed = explode(',', $reseller['lm']);
382-
} else {
357+
//* values are limited to a field in the client settings
358+
if($limit_parts[0] == 'client') {
359+
if($_SESSION["s"]["user"]["typ"] == 'admin') {
383360
return $values;
361+
} else {
362+
$client_group_id = $_SESSION["s"]["user"]["default_group"];
363+
$client = $app->db->queryOneRecord("SELECT ".$limit_parts[1]." as lm FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = ?", $client_group_id);
364+
$allowed = explode(',', $client['lm']);
384365
}
385-
} // end if admin
386-
} // end if reseller
387-
388-
//* values are limited to a field in the system settings
389-
if($limit_parts[0] == 'system') {
390-
$app->uses('getconf');
391-
$tmp_conf = $app->getconf->get_global_config($limit_parts[1]);
392-
$tmp_key = $limit_parts[2];
393-
$allowed = $tmp_conf[$tmp_key];
394-
}
366+
}
367+
368+
//* values are limited to a field in the reseller settings
369+
if($limit_parts[0] == 'reseller') {
370+
if($_SESSION["s"]["user"]["typ"] == 'admin') {
371+
return $values;
372+
} else {
373+
//* Get the limits of the client that is currently logged in
374+
$client_group_id = $_SESSION["s"]["user"]["default_group"];
375+
$client = $app->db->queryOneRecord("SELECT parent_client_id FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = ?", $client_group_id);
376+
//echo "SELECT parent_client_id FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = $client_group_id";
377+
//* If the client belongs to a reseller, we will check against the reseller Limit too
378+
if($client['parent_client_id'] != 0) {
379+
380+
//* first we need to know the groups of this reseller
381+
$tmp = $app->db->queryOneRecord("SELECT userid, groups FROM sys_user WHERE client_id = ?", $client['parent_client_id']);
382+
$reseller_groups = $tmp["groups"];
383+
$reseller_userid = $tmp["userid"];
384+
385+
// Get the limits of the reseller of the logged in client
386+
$client_group_id = $_SESSION["s"]["user"]["default_group"];
387+
$reseller = $app->db->queryOneRecord("SELECT ".$limit_parts[1]." as lm FROM client WHERE client_id = ?", $client['parent_client_id']);
388+
$allowed = explode(',', $reseller['lm']);
389+
} else {
390+
return $values;
391+
}
392+
} // end if admin
393+
} // end if reseller
394+
395+
//* values are limited to a field in the system settings
396+
if($limit_parts[0] == 'system') {
397+
$app->uses('getconf');
398+
$tmp_conf = $app->getconf->get_global_config($limit_parts[1]);
399+
$tmp_key = $limit_parts[2];
400+
$allowed = $allowed = explode(',',$tmp_conf[$tmp_key]);
401+
}
402+
403+
// add the current value to the allowed array
404+
$allowed[] = $current_value;
405+
406+
// remove all values that are not allowed
407+
$values_new = array();
408+
foreach($values as $key => $val) {
409+
if(in_array($key, $allowed)) $values_new[$key] = $val;
410+
}
411+
412+
$values = $values_new;
395413

396-
$values_new = array();
397-
foreach($values as $key => $val) {
398-
if(in_array($key, $allowed)) $values_new[$key] = $val;
399414
}
400415

401-
return $values_new;
416+
return $values;
402417
}
403418

404419

@@ -464,7 +479,7 @@ function getHTML($record, $tab, $action = 'NEW') {
464479

465480
// If a limitation for the values is set
466481
if(isset($field['valuelimit']) && is_array($field["value"])) {
467-
$field["value"] = $this->applyValueLimit($field['valuelimit'], $field["value"]);
482+
$field["value"] = $this->applyValueLimit($field['valuelimit'], $field["value"], $val);
468483
}
469484

470485
switch ($field['formtype']) {
@@ -599,7 +614,7 @@ function getHTML($record, $tab, $action = 'NEW') {
599614

600615
// If a limitation for the values is set
601616
if(isset($field['valuelimit']) && is_array($field["value"])) {
602-
$field["value"] = $this->applyValueLimit($field['valuelimit'], $field["value"]);
617+
$field["value"] = $this->applyValueLimit($field['valuelimit'], $field["value"], $field['default']);
603618
}
604619

605620
switch ($field['formtype']) {

interface/web/admin/form/system_config.tform.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,16 @@
200200
'value' => '',
201201
'name' => 'default_dbserver'
202202
),
203+
'web_php_options' => array (
204+
'datatype' => 'VARCHAR',
205+
'formtype' => 'CHECKBOXARRAY',
206+
'validators' => array ( 0 => array ( 'type' => 'NOTEMPTY',
207+
'errmsg'=> 'web_php_options_notempty'),
208+
),
209+
'default' => '',
210+
'separator' => ',',
211+
'value' => array('no' => 'Disabled', 'fast-cgi' => 'Fast-CGI', 'cgi' => 'CGI', 'mod' => 'Mod-PHP', 'suphp' => 'SuPHP', 'php-fpm' => 'PHP-FPM', 'hhvm' => 'HHVM')
212+
),
203213
//#################################
204214
// ENDE Datatable fields
205215
//#################################

interface/web/admin/lib/lang/de_system_config.lng

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,5 @@ $wb['ca_iodef_txt'] = 'iodef';
8989
$wb['active_txt'] = 'Aktiv';
9090
$wb['btn_save_txt'] = 'Speichern';
9191
$wb['btn_cancel_txt'] = 'Abbrechen';
92+
$wb['web_php_options_txt'] = 'PHP Handler (Nur Apache)';
9293
?>

interface/web/admin/lib/lang/en_system_config.lng

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,4 +92,5 @@ $wb['ca_iodef_txt'] = 'iodef';
9292
$wb['active_txt'] = 'Active';
9393
$wb['btn_save_txt'] = 'Save';
9494
$wb['btn_cancel_txt'] = 'Cancel';
95+
$wb['web_php_options_txt'] = 'PHP Handler (Apache only)';
9596
?>

interface/web/admin/lib/lang/es_system_config.lng

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,5 @@ $wb['ca_iodef_txt'] = 'iodef';
8989
$wb['active_txt'] = 'Aktive';
9090
$wb['btn_save_txt'] = 'Save';
9191
$wb['btn_cancel_txt'] = 'Cancel';
92+
$wb['web_php_options_txt'] = 'PHP Handler (Apache only)';
9293
?>

interface/web/admin/templates/server_config_web_edit.htm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ <h4 class="panel-title">
256256
<div id="collapsePHP" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingPHP">
257257
<div class="panel-body">
258258
<!-- Begin content -->
259-
<div class="form-group">
259+
<div class="form-group">
260260
<label for="php_default_name" class="col-sm-3 control-label">{tmpl_var name='php_default_name_txt'}</label>
261261
<div class="col-sm-9"><input type="text" name="php_default_name" id="php_default_name" value="{tmpl_var name='php_default_name'}" class="form-control" /></div></div>
262262
<div class="form-group apache">

interface/web/admin/templates/system_config_sites_edit.htm

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@ <h1><tmpl_var name="list_head_txt"></h1>
6363
{tmpl_var name='reseller_can_use_options'}
6464
</div>
6565
</div>
66+
<div class="form-group">
67+
<label class="col-sm-3 control-label">{tmpl_var name='web_php_options_txt'}</label>
68+
<div class="col-sm-9">
69+
{tmpl_var name='web_php_options'}
70+
</div>
71+
</div>
6672
<div class="form-group">
6773
<label for="default_webserver" class="col-sm-3 control-label">{tmpl_var name='default_webserver_txt'}</label>
6874
<div class="col-sm-9"><select name="default_webserver" id="default_webserver" class="form-control">

interface/web/client/form/client.tform.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1087,7 +1087,7 @@
10871087
),
10881088
'default' => '',
10891089
'separator' => ',',
1090-
'valuelimit' => 'client:web_php_options',
1090+
'valuelimit' => 'system:sites:web_php_options',
10911091
'value' => array('no' => 'Disabled', 'fast-cgi' => 'Fast-CGI', 'cgi' => 'CGI', 'mod' => 'Mod-PHP', 'suphp' => 'SuPHP', 'php-fpm' => 'PHP-FPM', 'hhvm' => 'HHVM')
10921092
),
10931093
'limit_cgi' => array (

interface/web/client/form/client_template.tform.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@
495495
'formtype' => 'CHECKBOXARRAY',
496496
'default' => '',
497497
'separator' => ',',
498-
'valuelimit' => 'client:web_php_options',
498+
'valuelimit' => 'system:sites:web_php_options',
499499
'value' => array('no' => 'Disabled', 'fast-cgi' => 'Fast-CGI', 'cgi' => 'CGI', 'mod' => 'Mod-PHP', 'suphp' => 'SuPHP', 'php-fpm' => 'PHP-FPM', 'hhvm' => 'HHVM')
500500
),
501501
'limit_cgi' => array (

0 commit comments

Comments
 (0)