Skip to content

Commit c8cf71f

Browse files
committed
made php open_basdir configurable per website.
Added a global default for the .htaccess allow_override setting.
1 parent 812f6e9 commit c8cf71f

File tree

12 files changed

+95
-23
lines changed

12 files changed

+95
-23
lines changed

install/sql/ispconfig3.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1057,8 +1057,9 @@ CREATE TABLE `web_domain` (
10571057
`ssl_bundle` mediumtext NULL,
10581058
`ssl_action` varchar(16) NULL,
10591059
`stats_password` varchar(255) default NULL,
1060-
`allow_override` varchar(32) NOT NULL default 'All',
1060+
`allow_override` varchar(255) NOT NULL default 'All',
10611061
`apache_directives` text,
1062+
`php_open_basedir` text,
10621063
`active` enum('n','y') NOT NULL default 'y',
10631064
PRIMARY KEY (`domain_id`)
10641065
) ENGINE=MyISAM AUTO_INCREMENT=1;

install/tpl/server.ini.master

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ group=www-data
4444
apps_vhost_port=8081
4545
apps_vhost_ip=_default_
4646
apps_vhost_servername=
47+
php_open_basedir=[website_path]/web:[website_path]/tmp:/usr/share/php5:/tmp:/usr/share/phpmyadmin
48+
htaccess_allow_override=All
4749

4850
[dns]
4951
bind_user=root

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,28 @@
387387
'width' => '40',
388388
'maxlength' => '255'
389389
),
390+
'php_open_basedir' => array (
391+
'datatype' => 'VARCHAR',
392+
'formtype' => 'TEXT',
393+
'default' => '',
394+
'validators' => array ( 0 => array ( 'type' => 'NOTEMPTY',
395+
'errmsg'=> 'php_open_basedir_error_empty'),
396+
),
397+
'value' => '',
398+
'width' => '40',
399+
'maxlength' => '255'
400+
),
401+
'htaccess_allow_override' => array (
402+
'datatype' => 'VARCHAR',
403+
'formtype' => 'TEXT',
404+
'default' => '',
405+
'validators' => array ( 0 => array ( 'type' => 'NOTEMPTY',
406+
'errmsg'=> 'htaccess_allow_override_error_empty'),
407+
),
408+
'value' => '',
409+
'width' => '40',
410+
'maxlength' => '255'
411+
),
390412
'apps_vhost_port' => array (
391413
'datatype' => 'VARCHAR',
392414
'formtype' => 'TEXT',

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,8 @@ $wb["named_conf_path_error_empty"] = 'BIND named.conf path is empty.';
6161
$wb["named_conf_local_path_error_empty"] = 'BIND named.conf.local path is empty.';
6262
$wb["mail_filter_syntax_txt"] = 'Mailfilter Syntax';
6363
$wb["pop3_imap_daemon_txt"] = 'POP3/IMAP Daemon';
64+
$wb["php_open_basedir_txt"] = 'PHP open_basedir';
65+
$wb["php_open_basedir_error_empty"] = 'PHP open_basedir is empty.';
66+
$wb["htaccess_allow_override_txt"] = '.htaccess AllowOverride';
67+
$wb["htaccess_allow_override_error_empty"] = '.htaccess AllowOverride is empty.';
6468
?>

interface/web/admin/templates/server_config_web_edit.htm

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ <h2><tmpl_var name="list_head_txt"></h2>
1616
<div class="ctrlHolder">
1717
<label for="website_symlinks">{tmpl_var name='website_symlinks_txt'}</label>
1818
<input name="website_symlinks" id="website_symlinks" value="{tmpl_var name='website_symlinks'}" size="40" maxlength="255" type="text" class="textInput" />
19-
</div>
19+
</div>
2020
<div class="ctrlHolder">
2121
<label for="vhost_conf_dir">{tmpl_var name='vhost_conf_dir_txt'}</label>
2222
<input name="vhost_conf_dir" id="vhost_conf_dir" value="{tmpl_var name='vhost_conf_dir'}" size="40" maxlength="255" type="text" class="textInput" />
@@ -42,6 +42,14 @@ <h2><tmpl_var name="list_head_txt"></h2>
4242
<input name="group" id="group" value="{tmpl_var name='group'}" size="40" maxlength="255" type="text" class="textInput" />
4343
</div>
4444
<div class="ctrlHolder">
45+
<label for="php_open_basedir">{tmpl_var name='php_open_basedir_txt'}</label>
46+
<input name="php_open_basedir" id="php_open_basedir" value="{tmpl_var name='php_open_basedir'}" size="40" maxlength="255" type="text" class="textInput" />
47+
</div>
48+
<div class="ctrlHolder">
49+
<label for="htaccess_allow_override">{tmpl_var name='htaccess_allow_override_txt'}</label>
50+
<input name="htaccess_allow_override" id="htaccess_allow_override" value="{tmpl_var name='htaccess_allow_override'}" size="40" maxlength="255" type="text" class="textInput" />
51+
</div>
52+
<div class="ctrlHolder">
4553
<label for="apps_vhost_port">{tmpl_var name='apps_vhost_port_txt'}</label>
4654
<input name="apps_vhost_port" id="apps_vhost_port" value="{tmpl_var name='apps_vhost_port'}" size="40" maxlength="255" type="text" class="textInput" />
4755
</div>

interface/web/sites/form/web_domain.tform.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,18 @@
403403
'datatype' => 'VARCHAR',
404404
'formtype' => 'TEXT',
405405
'validators' => array ( 0 => array ( 'type' => 'NOTEMPTY',
406-
'errmsg'=> 'documentroot_error_empty'),
406+
'errmsg'=> 'allow_override_error_empty'),
407+
),
408+
'default' => 'All',
409+
'value' => '',
410+
'width' => '30',
411+
'maxlength' => '255'
412+
),
413+
'php_open_basedir' => array (
414+
'datatype' => 'VARCHAR',
415+
'formtype' => 'TEXT',
416+
'validators' => array ( 0 => array ( 'type' => 'NOTEMPTY',
417+
'errmsg'=> 'php_open_basedir_error_empty'),
407418
),
408419
'default' => 'All',
409420
'value' => '',

interface/web/sites/templates/web_domain_advanced.htm

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@ <h2><tmpl_var name="list_head_txt"></h2>
1919
<div class="ctrlHolder">
2020
<label for="allow_override">{tmpl_var name='allow_override_txt'}</label>
2121
<input name="allow_override" id="allow_override" value="{tmpl_var name='allow_override'}" size="30" maxlength="255" type="text" class="textInput" />
22-
</div
22+
</div>
23+
<div class="ctrlHolder">
24+
<label for="php_open_basedir">{tmpl_var name='php_open_basedir_txt'}</label>
25+
<input name="php_open_basedir" id="php_open_basedir" value="{tmpl_var name='php_open_basedir'}" size="30" maxlength="255" type="text" class="textInput" />
26+
</div>
2327
<div class="ctrlHolder">
2428
<label for="apache_directives">{tmpl_var name='apache_directives_txt'}</label>
2529
<textarea name="apache_directives" id="apache_directives" rows='10' cols='30'>{tmpl_var name='apache_directives'}</textarea>

interface/web/sites/web_domain_edit.php

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -293,11 +293,13 @@ function onAfterInsert() {
293293
}
294294

295295
// Set the values for document_root, system_user and system_group
296-
$system_user = 'web'.$this->id;
297-
$system_group = 'client'.$client_id;
298-
$document_root = str_replace("[client_id]",$client_id,$document_root);
296+
$system_user = $app->db->quote('web'.$this->id);
297+
$system_group = $app->db->quote('client'.$client_id);
298+
$document_root = $app->db->quote(str_replace("[client_id]",$client_id,$document_root));
299+
$php_open_basedir = $app->db->quote(str_replace("[website_path]",$document_root,$web_config["php_open_basedir"]));
300+
$htaccess_allow_override = $app->db->quote($web_config["htaccess_allow_override"]);
299301

300-
$sql = "UPDATE web_domain SET system_user = '$system_user', system_group = '$system_group', document_root = '$document_root' WHERE domain_id = ".$this->id;
302+
$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 = ".$this->id;
301303
$app->db->query($sql);
302304
}
303305

@@ -372,9 +374,9 @@ function onAfterUpdate() {
372374

373375
if(($_SESSION["s"]["user"]["typ"] == 'admin' || $app->auth->has_clients($_SESSION['s']['user']['userid'])) && isset($this->dataRecord["client_group_id"]) && $this->dataRecord["client_group_id"] != $this->oldDataRecord["client_group_id"]) {
374376
// Set the values for document_root, system_user and system_group
375-
$system_user = 'web'.$this->id;
376-
$system_group = 'client'.$client_id;
377-
$document_root = str_replace("[client_id]",$client_id,$document_root);
377+
$system_user = $app->db->quote('web'.$this->id);
378+
$system_group = $app->db->quote('client'.$client_id);
379+
$document_root = $app->db->quote(str_replace("[client_id]",$client_id,$document_root));
378380

379381
$sql = "UPDATE web_domain SET system_user = '$system_user', system_group = '$system_group', document_root = '$document_root' WHERE domain_id = ".$this->id;
380382
//$sql = "UPDATE web_domain SET system_user = '$system_user', system_group = '$system_group' WHERE domain_id = ".$this->id;
@@ -393,6 +395,17 @@ function onAfterUpdate() {
393395
unset($subdomain);
394396
}
395397

398+
//* Set allow_override and php_open_basedir if empty
399+
if($web_rec['allow_override'] == '') {
400+
$sql = "UPDATE web_domain SET allow_override = '".$app->db->quote($web_config["htaccess_allow_override"])."' WHERE domain_id = ".$this->id;
401+
$app->db->query($sql);
402+
}
403+
if($web_rec['php_open_basedir'] == '') {
404+
$php_open_basedir = $app->db->quote(str_replace("[website_path]",$document_root,$web_config["php_open_basedir"]));
405+
$sql = "UPDATE web_domain SET php_open_basedir = '$php_open_basedir' WHERE domain_id = ".$this->id;
406+
$app->db->query($sql);
407+
}
408+
396409
}
397410

398411
function onAfterDelete() {

server/conf/php-cgi-starter.master

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
exec <tmpl_var name='php_cgi_bin'> \
44
-d open_basedir=<tmpl_var name='open_basedir'> \
5-
-d upload_tmp_dir=<tmpl_var name='open_basedir'>/tmp \
6-
-d session.save_path=<tmpl_var name='open_basedir'>/tmp
5+
-d upload_tmp_dir=<tmpl_var name='document_root'>/tmp \
6+
-d session.save_path=<tmpl_var name='document_root'>/tmp
77
# -d safe_mode=${SAFE_MODE}

server/conf/php-fcgi-starter.master

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export PHP_DOCUMENT_ROOT
1010
PHP_FCGI_MAX_REQUESTS=<tmpl_var name='php_fcgi_max_requests'>
1111
export PHP_FCGI_MAX_REQUESTS
1212
exec <tmpl_var name='php_fcgi_bin'> \
13-
<tmpl_if name="security_level" op="==" value="20"> -d open_basedir="<tmpl_var name='document_root'>:/usr/share/php5:/tmp:/usr/share/phpmyadmin" \
13+
<tmpl_if name="security_level" op="==" value="20"> -d open_basedir="<tmpl_var name='open_basedir'>" \
1414
-d upload_tmp_dir=<tmpl_var name='document_root'>/tmp \
1515
-d session.save_path=<tmpl_var name='document_root'>/tmp \
1616
</tmpl_if> $1

0 commit comments

Comments
 (0)