I would like to create some sites using the remoting api. In the sites_web_domain_add soap call, there is a lot of parameters, some of which are specific to the server where the domain is being created. For example document_root, php_open_basedir, fastcgi_php_version contain the client and other webserver specific variables (which are by the way configurable on a per-server basis). Is there a way to create a site on a predefined web server controlled by ispconfig, and have ispconfig assign these variables automatically? thank you.
Till, so how do I calculate the webX / clientY parameters for the web server I want to use ? the Y in client is the client_id the X in web is the next web + 1 ? ouch... very raw this remoting is
The remoting api is a low level api, which allos to change more parameters then the web interface. yes. Here is the code from web interface: Code: function onAfterInsert() { global $app, $conf; // make sure that the record belongs to the clinet group and not the admin group when admin inserts it // also make sure that the user can not delete domain created by a admin if($_SESSION["s"]["user"]["typ"] == 'admin' && isset($this->dataRecord["client_group_id"])) { $client_group_id = $app->functions->intval($this->dataRecord["client_group_id"]); $app->db->query("UPDATE web_domain SET sys_groupid = $client_group_id, sys_perm_group = 'ru' WHERE domain_id = ".$this->id); } if($app->auth->has_clients($_SESSION['s']['user']['userid']) && isset($this->dataRecord["client_group_id"])) { $client_group_id = $app->functions->intval($this->dataRecord["client_group_id"]); $app->db->query("UPDATE web_domain SET sys_groupid = $client_group_id, sys_perm_group = 'riud' WHERE domain_id = ".$this->id); } // Get configuration for the web system $app->uses("getconf"); $web_rec = $app->tform->getDataRecord($this->id); $web_config = $app->getconf->get_server_config($app->functions->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 = $app->functions->intval($_SESSION["s"]["user"]["default_group"]); $client = $app->db->queryOneRecord("SELECT client_id FROM sys_group WHERE sys_group.groupid = $client_group_id"); $client_id = $app->functions->intval($client["client_id"]); } else { //$client_id = $app->functions->intval($this->dataRecord["client_group_id"]); $client = $app->db->queryOneRecord("SELECT client_id FROM sys_group WHERE sys_group.groupid = ".$app->functions->intval($this->dataRecord["client_group_id"])); $client_id = $app->functions->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); $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"]); $added_date = date($app->lng('conf_format_dateshort')); $added_by = $app->db->quote($_SESSION['s']['user']['username']); $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', added_date = '$added_date', added_by = '$added_by' WHERE domain_id = ".$this->id; $app->db->query($sql); }
just for future reference to whoever interested, I'd like to say that all the relevant information and server settings can be retrieved in the server_get remoting call.
I see a problem with the webid and substitution required in the site path parameters, unless I foresee something. Here's the clue: I need to web_id to be able to set the proper path (substitute the path template variables with the correct values for the site instance). However, I don't have the next ID in the remoting api (well... not until I call the api). The problem I see is a possible race condition, where the site is created with bad values (on disk) before I have the opportunity to fix the values with a second remote-api call. This is (supposedly) solved in the onafterinsert event of the web application where the ID of the new site is available immediately after the SQL insert and before the site is created on disk. In the remoting this is not guaranteed. Am I missing something? thank you.
I'am sorry, my answer in #2 was not quite corect. for the web domains, the system fills out the following fields autmatically when a site is added by the remote api: $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; So you xan leve them empty in the params array. This is done by the interface plugin sites_web_domain_plugin.inc.php which attaches itself to the event "sites:web_domainn_after_insert" thats is raised by the api and the interface as well.
Till I'm coming back to the issue as I found some problems. If you leave 'allow_override' empty, they you get a soap error allow_override_error_empty Another problem is with documentation. You need 'pm_process_idle_timeout_error' and 'pm_max_requests' set or you get a pm_process_idle_timeout_error_regex and pm_max_requests_error_regex As you might guess I am a very lazy sysadmin, which will rather make a million lines program to do stuff instead of doing it myself