www moved, change open_basedir

Discussion in 'Installation/Configuration' started by erosbk, Nov 9, 2011.

  1. erosbk

    erosbk New Member

    I need to add this to default open_base dir value:


    "/var/www" has been moved to "/userdata/www"

    "/var/www" is now a symlink to "/userdata/www/"

    So, I need to add "/userdata/" too in open_basedir, but I want to keep path as /var/www (with this, I can rollback always to original folders).

    As I could test, [client_id] and [website_id] are not available to be used to define paths in open_basedir box... so, how can I implement this variables? or it is something else that I could use?

    Thanks in advance!
  2. till

    till Super Moderator Staff Member ISPConfig Developer

    The placeholders [client_id] and [website_id] are replaced in the open_basedir string, so you can use them in the field under System > Server Config > Web to define the open_basedir path preset for the websites.
  3. erosbk

    erosbk New Member

    Thanks Till,

    I tried to use those variables in the path for open_basedir, but are not being replaced when writted to site file.. they are writted as \[client_id\].

    If you need, I will post here tonight the entire string that I am trying to use for open_basedir

    (I don't want to change sitepath option /var/www for /data/www, I want it to remain as /var/www/)
  4. till

    till Super Moderator Staff Member ISPConfig Developer

    There seem to be a misunderstanding. Placeholders can be used under System > server config > web as they get replaced when a new web gets created (and the filed is filled the first time) and not when the file gets written to disk. You can not use placeholders in the website options under Sites > Website > Options as this field contains the result of the replacement, so the string in that field is the final path which is written to disk after the placeholders have been replaced. So dont add any placeholders there.

    There is no need to change any openbasedir settings for existing sites for that. Just add a symlink in the filesystem.
  5. erosbk

    erosbk New Member

    Oh, I am using a symlink ln:/var/www pointing to dir:/data/www/

    So, I don't need to change anything? if a site use as path /data/www, open_basedir will allow everything if I don't specify /data/www as allowed path?

    thanks for all your help
  6. till

    till Super Moderator Staff Member ISPConfig Developer

    Yes, a symlink should be enough.
  7. erosbk

    erosbk New Member

    Till, in System > Server Config > Web, I am trying to use placeholders [client_id], [website_id] in "PHP open_basedir", but the only placeholders working are [website_path] and [website_domain], both of them are not usefull for what I need.

    As I could see, if I don't specify /userdata/clients/clientX/webY/web in php_openbasedir, sites doesn't work because path /userdata/.../ is not allowed by open_basedir... I have a symlink /var/www -> /userdata/www/. Sites works if I access them using /var/www...

    So, I need to add in PHP open_basedir the following path to default path:
    /userdata/clients/[client_id]/[website_id]/web and /userdata/clients/[client_id]/[website_id]/tmp

    Could you guide me how to work with this? which file do I have to change to allow client_id and website_id placeholders in PHP open_basedir under System > Server Config > Web ?

    As always, sorry for my bad english, and thanks in advance
  8. erosbk

    erosbk New Member

    Should be enough to modify interface/web/sites/web_domain_edit.php as below to add client_id and website_id as placeholders? do I have to modify too interface/lib/plugins/sites_web_domain_plugin.inc.php?

                    // Get configuration for the web system
                    $web_rec = $app->tform->getDataRecord($this->id);
                    $web_config = $app->getconf->get_server_config(intval($web_rec["server_id"]),'web');
                    $document_root = str_replace("[website_id]",$this->id,$web_config["website_path"]);
                    $document_root = str_replace("[website_idhash_1]",$this->id_hash($page_form->id,1),$document_root);
                    $document_root = str_replace("[website_idhash_2]",$this->id_hash($page_form->id,1),$document_root);
                    $document_root = str_replace("[website_idhash_3]",$this->id_hash($page_form->id,1),$document_root);
                    $document_root = str_replace("[website_idhash_4]",$this->id_hash($page_form->id,1),$document_root);
                    // get the ID of the client
                    if($_SESSION["s"]["user"]["typ"] != 'admin' && !$app->auth->has_clients($_SESSION['s']['user']['userid'])) {
                            $client_group_id = $_SESSION["s"]["user"]["default_group"];
                            $client = $app->db->queryOneRecord("SELECT client_id FROM sys_group WHERE sys_group.groupid = $client_group_id");
                            $client_id = intval($client["client_id"]);
                    } else {
                            //$client_id = intval($this->dataRecord["client_group_id"]);
                            $client = $app->db->queryOneRecord("SELECT client_id FROM sys_group WHERE sys_group.groupid = ".intval($this->dataRecord["client_group_id"]));
                            $client_id = intval($client["client_id"]);
                    // Set the values for document_root, system_user and system_group
                    $system_user = $app->db->quote('web'.$this->id);
                    $system_group = $app->db->quote('client'.$client_id);
                    $document_root = str_replace("[client_id]",$client_id,$document_root);
                    $document_root = str_replace("[client_idhash_1]",$this->id_hash($client_id,1),$document_root);
                    $document_root = str_replace("[client_idhash_2]",$this->id_hash($client_id,2),$document_root);
                    $document_root = str_replace("[client_idhash_3]",$this->id_hash($client_id,3),$document_root);
                    $document_root = str_replace("[client_idhash_4]",$this->id_hash($client_id,4),$document_root);
                    $document_root = $app->db->quote($document_root);
    # BOC
                    $php_open_basedir = str_replace("[client_id]",$client_id,$web_config["php_open_basedir"]);
                    $php_open_basedir = str_replace("[website_id]",$this->id,$web_config["php_open_basedir"]);
    # EOC
                    $php_open_basedir = str_replace("[website_path]",$document_root,$web_config["php_open_basedir"]);
                    $php_open_basedir = $app->db->quote(str_replace("[website_domain]",$web_rec['domain'],$php_open_basedir));
                    $htaccess_allow_override = $app->db->quote($web_config["htaccess_allow_override"]);
                    $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 dom$
    Thanks in advance
    Last edited: Dec 13, 2011

Share This Page