| @@ -1,513 +0,0 @@ | |||
| <?php | |||
| /* | |||
| Copyright (c) 2008, Till Brehm, projektfarm Gmbh | |||
| All rights reserved. | |||
| Redistribution and use in source and binary forms, with or without modification, | |||
| are permitted provided that the following conditions are met: | |||
| * Redistributions of source code must retain the above copyright notice, | |||
| this list of conditions and the following disclaimer. | |||
| * Redistributions in binary form must reproduce the above copyright notice, | |||
| this list of conditions and the following disclaimer in the documentation | |||
| and/or other materials provided with the distribution. | |||
| * Neither the name of ISPConfig nor the names of its contributors | |||
| may be used to endorse or promote products derived from this software without | |||
| specific prior written permission. | |||
| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | |||
| ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | |||
| WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | |||
| IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, | |||
| INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | |||
| BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |||
| DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | |||
| OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | |||
| NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, | |||
| EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |||
| */ | |||
| /****************************************** | |||
| * Begin Form configuration | |||
| ******************************************/ | |||
| $tform_def_file = "form/database.tform.php"; | |||
| /****************************************** | |||
| * End Form configuration | |||
| ******************************************/ | |||
| require_once '../../lib/config.inc.php'; | |||
| require_once '../../lib/app.inc.php'; | |||
| //* Check permissions for module | |||
| $app->auth->check_module_permissions('sites'); | |||
| // Loading classes | |||
| $app->uses('tpl,tform,tform_actions'); | |||
| $app->load('tform_actions'); | |||
| class page_action extends tform_actions { | |||
| function onShowNew() { | |||
| global $app, $conf; | |||
| // we will check only users, not admins | |||
| if($_SESSION["s"]["user"]["typ"] == 'user') { | |||
| if(!$app->tform->checkClientLimit('limit_database')) { | |||
| $app->error($app->tform->wordbook["limit_database_txt"]); | |||
| } | |||
| if(!$app->tform->checkResellerLimit('limit_database')) { | |||
| $app->error('Reseller: '.$app->tform->wordbook["limit_database_txt"]); | |||
| } | |||
| } else { | |||
| $settings = $app->getconf->get_global_config('sites'); | |||
| $app->tform->formDef['tabs']['database']['fields']['server_id']['default'] = intval($settings['default_dbserver']); | |||
| } | |||
| parent::onShowNew(); | |||
| } | |||
| function onShowEnd() { | |||
| global $app, $conf, $interfaceConf; | |||
| if($_SESSION["s"]["user"]["typ"] != 'admin' && !$app->auth->has_clients($_SESSION['s']['user']['userid'])) { | |||
| // Get the limits of the client | |||
| $client_group_id = $_SESSION["s"]["user"]["default_group"]; | |||
| $client = $app->db->queryOneRecord("SELECT db_servers FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = ?", $client_group_id); | |||
| // Set the webserver to the default server of the client | |||
| $tmp = $app->db->queryAllRecords("SELECT server_id, server_name FROM server WHERE server_id IN ?", explode(',', $client['db_servers'])); | |||
| $only_one_server = count($tmp) === 1; | |||
| $app->tpl->setVar('only_one_server', $only_one_server); | |||
| if ($only_one_server) { | |||
| $app->tpl->setVar('server_id_value', $tmp[0]['server_id']); | |||
| } | |||
| foreach ($tmp as $db_server) { | |||
| $options_db_servers .= '<option value="'.$db_server['server_id'].'"'.($this->id > 0 && $this->dataRecord["server_id"] == $db_server['server_id'] ? ' selected="selected"' : '').'>'.$db_server['server_name'].'</option>'; | |||
| } | |||
| $app->tpl->setVar("server_id", $options_db_servers); | |||
| unset($tmp); | |||
| } elseif ($_SESSION["s"]["user"]["typ"] != 'admin' && $app->auth->has_clients($_SESSION['s']['user']['userid'])) { | |||
| // Get the limits of the client | |||
| $client_group_id = $_SESSION["s"]["user"]["default_group"]; | |||
| $client = $app->db->queryOneRecord("SELECT client.client_id, limit_web_domain, db_servers, contact_name FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = ?", $client_group_id); | |||
| // Set the webserver to the default server of the client | |||
| $tmp = $app->db->queryAllRecords("SELECT server_id, server_name FROM server WHERE server_id IN ?", explode(',', $client['db_servers'])); | |||
| $only_one_server = count($tmp) === 1; | |||
| $app->tpl->setVar('only_one_server', $only_one_server); | |||
| if ($only_one_server) { | |||
| $app->tpl->setVar('server_id_value', $tmp[0]['server_id']); | |||
| } | |||
| foreach ($tmp as $db_server) { | |||
| $options_db_servers .= '<option value="'.$db_server['server_id'].'"'.($this->id > 0 && $this->dataRecord["server_id"] == $db_server['server_id'] ? ' selected="selected"' : '').'>'.$db_server['server_name'].'</option>'; | |||
| } | |||
| $app->tpl->setVar("server_id", $options_db_servers); | |||
| unset($tmp); | |||
| } else { | |||
| // The user is admin | |||
| if($this->id > 0) { | |||
| $server_id = $this->dataRecord["server_id"]; | |||
| } else { | |||
| // Get the first server ID | |||
| $tmp = $app->db->queryOneRecord("SELECT server_id FROM server WHERE web_server = 1 ORDER BY server_name LIMIT 0,1"); | |||
| $server_id = $tmp['server_id']; | |||
| } | |||
| } | |||
| /* | |||
| * If the names are restricted -> remove the restriction, so that the | |||
| * data can be edited | |||
| */ | |||
| //* Get the database name and database user prefix | |||
| $app->uses('getconf,tools_sites'); | |||
| $global_config = $app->getconf->get_global_config('sites'); | |||
| $dbname_prefix = $app->tools_sites->replacePrefix($global_config['dbname_prefix'], $this->dataRecord); | |||
| if ($this->dataRecord['database_name'] != ""){ | |||
| /* REMOVE the restriction */ | |||
| $app->tpl->setVar("database_name", $app->tools_sites->removePrefix($this->dataRecord['database_name'], $this->dataRecord['database_name_prefix'], $dbname_prefix)); | |||
| } | |||
| if($this->dataRecord['database_name'] == "") { | |||
| $app->tpl->setVar("database_name_prefix", $dbname_prefix); | |||
| } else { | |||
| $app->tpl->setVar("database_name_prefix", $app->tools_sites->getPrefix($this->dataRecord['database_name_prefix'], $dbname_prefix, $global_config['dbname_prefix'])); | |||
| } | |||
| if($this->id > 0) { | |||
| //* we are editing a existing record | |||
| $edit_disabled = @($_SESSION["s"]["user"]["typ"] == 'admin')? 0 : 1; //* admin can change the database-name | |||
| $app->tpl->setVar("edit_disabled", $edit_disabled); | |||
| $app->tpl->setVar("server_id_value", $this->dataRecord["server_id"]); | |||
| $app->tpl->setVar("database_charset_value", $this->dataRecord["database_charset"]); | |||
| $app->tpl->setVar("limit_database_quota", $this->dataRecord["database_quota"]); | |||
| } else { | |||
| $app->tpl->setVar("edit_disabled", 0); | |||
| } | |||
| parent::onShowEnd(); | |||
| } | |||
| function onSubmit() { | |||
| global $app, $conf; | |||
| $parent_domain = $app->db->queryOneRecord("select * FROM web_domain WHERE domain_id = ? AND ".$app->tform->getAuthSQL('r'), @$this->dataRecord["parent_domain_id"]); | |||
| if(!$parent_domain || $parent_domain['domain_id'] != @$this->dataRecord['parent_domain_id']) $app->tform->errorMessage .= $app->tform->lng("no_domain_perm"); | |||
| if($_SESSION["s"]["user"]["typ"] != 'admin') { | |||
| // Get the limits of the client | |||
| $client_group_id = $_SESSION["s"]["user"]["default_group"]; | |||
| $client = $app->db->queryOneRecord("SELECT db_servers, limit_database, limit_database_quota, parent_client_id FROM sys_group, client WHERE sys_group.client_id = client.client_id AND sys_group.groupid = ?", $client_group_id); | |||
| // When the record is updated | |||
| if($this->id > 0) { | |||
| // restore the server ID if the user is not admin and record is edited | |||
| $tmp = $app->db->queryOneRecord("SELECT server_id FROM web_database WHERE database_id = ?", $app->functions->intval($this->id)); | |||
| $this->dataRecord["server_id"] = $tmp["server_id"]; | |||
| unset($tmp); | |||
| //* Check client quota | |||
| if ($client['limit_database_quota'] >= 0) { | |||
| //* get the database prefix | |||
| $app->uses('getconf,tools_sites'); | |||
| $global_config = $app->getconf->get_global_config('sites'); | |||
| $dbname_prefix = $app->tools_sites->replacePrefix($global_config['dbname_prefix'], $this->dataRecord); | |||
| //* get quota from other databases | |||
| $tmp = $app->db->queryOneRecord("SELECT sum(database_quota) as db_quota FROM web_database WHERE sys_groupid = ? AND database_name <> ?", $client_group_id, $dbname_prefix.$this->dataRecord['database_name']); | |||
| $used_quota = $app->functions->intval($tmp['db_quota']); | |||
| $new_db_quota = $app->functions->intval($this->dataRecord["database_quota"]); | |||
| if(($used_quota + $new_db_quota > $client['limit_database_quota']) || ($new_db_quota < 0 && $client['limit_database_quota'] >= 0)) { | |||
| $max_free_quota = floor($client['limit_database_quota'] - $used_quota); | |||
| if($max_free_quota < 0) { | |||
| $max_free_quota = 0; | |||
| } | |||
| $app->tform->errorMessage .= $app->tform->lng("limit_database_quota_free_txt").": ".$max_free_quota." MB<br>"; | |||
| $this->dataRecord['database_quota'] = $max_free_quota; | |||
| } | |||
| unset($tmp); | |||
| unset($global_config); | |||
| unset($dbname_prefix); | |||
| } | |||
| if($client['parent_client_id'] > 0) { | |||
| // Get the limits of the reseller | |||
| $reseller = $app->db->queryOneRecord("SELECT limit_database, limit_database_quota FROM client WHERE client_id = ?", $client['parent_client_id']); | |||
| //* Check the website quota of the client | |||
| if ($reseller['limit_database_quota'] >= 0) { | |||
| //* get the database prefix | |||
| $app->uses('getconf,tools_sites'); | |||
| $global_config = $app->getconf->get_global_config('sites'); | |||
| $dbname_prefix = $app->tools_sites->replacePrefix($global_config['dbname_prefix'], $this->dataRecord); | |||
| //* get quota from other databases | |||
| $tmp = $app->db->queryOneRecord("SELECT sum(database_quota) as db_quota FROM web_database, sys_group, client WHERE web_database.sys_groupid=sys_group.groupid AND sys_group.client_id=client.client_id AND ? IN (client.parent_client_id, client.client_id) AND database_name <> ?", $client['parent_client_id'], $dbname_prefix.$this->dataRecord['database_name']); | |||
| $used_quota = $app->functions->intval($tmp['db_quota']); | |||
| $new_db_quota = $app->functions->intval($this->dataRecord["database_quota"]); | |||
| if(($used_quota + $new_db_quota > $reseller["limit_database_quota"]) || ($new_db_quota < 0 && $reseller["limit_database_quota"] >= 0)) { | |||
| $max_free_quota = floor($reseller["limit_database_quota"] - $used_quota); | |||
| if($max_free_quota < 0) $max_free_quota = 0; | |||
| $app->tform->errorMessage .= $app->tform->lng("limit_database_quota_free_txt").": ".$max_free_quota." MB<br>"; | |||
| $this->dataRecord["database_quota"] = $max_free_quota; | |||
| } | |||
| unset($tmp); | |||
| unset($global_config); | |||
| unset($dbname_prefix); | |||
| } | |||
| } | |||
| // When the record is inserted | |||
| } else { | |||
| $client['db_servers_ids'] = explode(',', $client['db_servers']); | |||
| // Check if chosen server is in authorized servers for this client | |||
| if (!(is_array($client['db_servers_ids']) && in_array($this->dataRecord["server_id"], $client['db_servers_ids'])) && $_SESSION["s"]["user"]["typ"] != 'admin') { | |||
| $app->error($app->tform->wordbook['error_not_allowed_server_id']); | |||
| } | |||
| // Check if the user may add another database | |||
| if($client["limit_database"] >= 0) { | |||
| $tmp = $app->db->queryOneRecord("SELECT count(database_id) as number FROM web_database WHERE sys_groupid = ?", $client_group_id); | |||
| if($tmp["number"] >= $client["limit_database"]) { | |||
| $app->error($app->tform->wordbook["limit_database_txt"]); | |||
| } | |||
| } | |||
| //* Check client quota | |||
| if ($client['limit_database_quota'] >= 0) { | |||
| $tmp = $app->db->queryOneRecord("SELECT sum(database_quota) as db_quota FROM web_database WHERE sys_groupid = ?", $client_group_id); | |||
| $db_quota = $tmp['db_quota']; | |||
| $new_db_quota = $app->functions->intval($this->dataRecord["database_quota"]); | |||
| if(($db_quota + $new_db_quota > $client['limit_database_quota']) || ($new_db_quota < 0 && $client['limit_database_quota'] >= 0)) { | |||
| $max_free_quota = floor($client['limit_database_quota'] - $db_quota); | |||
| if($max_free_quota < 0) $max_free_quota = 0; | |||
| $app->tform->errorMessage .= $app->tform->lng("limit_database_quota_free_txt").": ".$max_free_quota." MB<br>"; | |||
| $this->dataRecord['database_quota'] = $max_free_quota; | |||
| } | |||
| unset($tmp); | |||
| } | |||
| } | |||
| } else { | |||
| // check if client of database parent domain is client of db user! | |||
| $web_group = $app->db->queryOneRecord("SELECT sys_groupid FROM web_domain WHERE domain_id = ?", $this->dataRecord['parent_domain_id']); | |||
| if($this->dataRecord['database_user_id']) { | |||
| $group = $app->db->queryOneRecord("SELECT sys_groupid FROM web_database_user WHERE database_user_id = ?", $this->dataRecord['database_user_id']); | |||
| if($group['sys_groupid'] != $web_group['sys_groupid']) { | |||
| $app->error($app->tform->wordbook['database_client_differs_txt']); | |||
| } | |||
| } | |||
| if($this->dataRecord['database_ro_user_id']) { | |||
| $group = $app->db->queryOneRecord("SELECT sys_groupid FROM web_database_user WHERE database_user_id = ?", $this->dataRecord['database_ro_user_id']); | |||
| if($group['sys_groupid'] != $web_group['sys_groupid']) { | |||
| $app->error($app->tform->wordbook['database_client_differs_txt']); | |||
| } | |||
| } | |||
| } | |||
| parent::onSubmit(); | |||
| } | |||
| function onBeforeUpdate() { | |||
| global $app, $conf, $interfaceConf; | |||
| //* Site shall not be empty | |||
| if($this->dataRecord['parent_domain_id'] == 0) $app->tform->errorMessage .= $app->tform->lng("database_site_error_empty").'<br />'; | |||
| //* Get the database name and database user prefix | |||
| $app->uses('getconf,tools_sites'); | |||
| $global_config = $app->getconf->get_global_config('sites'); | |||
| $dbname_prefix = $app->tools_sites->replacePrefix($global_config['dbname_prefix'], $this->dataRecord); | |||
| //* Prevent that the database name and charset is changed | |||
| $old_record = $app->tform->getDataRecord($this->id); | |||
| $dbname_prefix = $app->tools_sites->getPrefix($old_record['database_name_prefix'], $dbname_prefix); | |||
| $this->dataRecord['database_name_prefix'] = $dbname_prefix; | |||
| //* Only admin can change the database name | |||
| if ($_SESSION["s"]["user"]["typ"] != 'admin') { | |||
| if($old_record["database_name"] != $dbname_prefix . $this->dataRecord["database_name"]) { | |||
| $app->tform->errorMessage .= $app->tform->wordbook["database_name_change_txt"].'<br />'; | |||
| } | |||
| } | |||
| if($old_record["database_charset"] != $this->dataRecord["database_charset"]) { | |||
| $app->tform->errorMessage .= $app->tform->wordbook["database_charset_change_txt"].'<br />'; | |||
| } | |||
| if(!$this->dataRecord['database_user_id']) { | |||
| $app->tform->errorMessage .= $app->tform->wordbook["database_user_missing_txt"].'<br />'; | |||
| } | |||
| //* Database username and database name shall not be empty | |||
| if($this->dataRecord['database_name'] == '') $app->tform->errorMessage .= $app->tform->wordbook["database_name_error_empty"].'<br />'; | |||
| //* Check if the server has been changed | |||
| // We do this only for the admin or reseller users, as normal clients can not change the server ID anyway | |||
| if($_SESSION["s"]["user"]["typ"] == 'admin' || $app->auth->has_clients($_SESSION['s']['user']['userid'])) { | |||
| if($old_record["server_id"] != $this->dataRecord["server_id"]) { | |||
| //* Add a error message and switch back to old server | |||
| $app->tform->errorMessage .= $app->lng('The Server can not be changed.'); | |||
| $this->dataRecord["server_id"] = $rec['server_id']; | |||
| } | |||
| } | |||
| unset($old_record); | |||
| if(strlen($dbname_prefix . $this->dataRecord['database_name']) > 64) $app->tform->errorMessage .= str_replace('{db}', $dbname_prefix . $this->dataRecord['database_name'], $app->tform->wordbook["database_name_error_len"]).'<br />'; | |||
| //* Check database name and user against blacklist | |||
| $dbname_blacklist = array($conf['db_database'], 'mysql'); | |||
| if(in_array($dbname_prefix . $this->dataRecord['database_name'], $dbname_blacklist)) { | |||
| $app->tform->errorMessage .= $app->lng('Database name not allowed.').'<br />'; | |||
| } | |||
| if ($app->tform->errorMessage == ''){ | |||
| /* restrict the names if there is no error */ | |||
| /* crop user and db names if they are too long -> mysql: user: 16 chars / db: 64 chars */ | |||
| $this->dataRecord['database_name'] = substr($dbname_prefix . $this->dataRecord['database_name'], 0, 64); | |||
| } | |||
| //* Check for duplicates | |||
| $tmp = $app->db->queryOneRecord("SELECT count(database_id) as dbnum FROM web_database WHERE database_name = ? AND server_id = ? AND database_id != ?", $this->dataRecord['database_name'], $this->dataRecord["server_id"], $this->id); | |||
| if($tmp['dbnum'] > 0) $app->tform->errorMessage .= $app->lng('database_name_error_unique').'<br />'; | |||
| // get the web server ip (parent domain) | |||
| $tmp = $app->db->queryOneRecord("SELECT server_id FROM web_domain WHERE domain_id = ?", $this->dataRecord['parent_domain_id']); | |||
| if($tmp['server_id'] && $tmp['server_id'] != $this->dataRecord['server_id']) { | |||
| // we need remote access rights for this server, so get it's ip address | |||
| $server_config = $app->getconf->get_server_config($tmp['server_id'], 'server'); | |||
| if($server_config['ip_address']!='') { | |||
| if($this->dataRecord['remote_access'] != 'y'){ | |||
| $this->dataRecord['remote_ips'] = $server_config['ip_address']; | |||
| $this->dataRecord['remote_access'] = 'y'; | |||
| } else { | |||
| if($this->dataRecord['remote_ips'] != ''){ | |||
| if(preg_match('/(^|,)' . preg_quote($server_config['ip_address'], '/') . '(,|$)/', $this->dataRecord['remote_ips']) == false) { | |||
| $this->dataRecord['remote_ips'] .= ',' . $server_config['ip_address']; | |||
| } | |||
| $tmp = preg_split('/\s*,\s*/', $this->dataRecord['remote_ips']); | |||
| $tmp = array_unique($tmp); | |||
| $this->dataRecord['remote_ips'] = implode(',', $tmp); | |||
| unset($tmp); | |||
| } | |||
| } | |||
| } | |||
| } | |||
| if ($app->tform->errorMessage == '') { | |||
| // force update of the used database user | |||
| if($this->dataRecord['database_user_id']) { | |||
| $user_old_rec = $app->db->queryOneRecord('SELECT * FROM `web_database_user` WHERE `database_user_id` = ?', $this->dataRecord['database_user_id']); | |||
| if($user_old_rec) { | |||
| $user_new_rec = $user_old_rec; | |||
| $user_new_rec['server_id'] = $this->dataRecord['server_id']; | |||
| $app->db->datalogSave('web_database_user', 'UPDATE', 'database_user_id', $this->dataRecord['database_user_id'], $user_old_rec, $user_new_rec); | |||
| } | |||
| } | |||
| if($this->dataRecord['database_ro_user_id']) { | |||
| $user_old_rec = $app->db->queryOneRecord('SELECT * FROM `web_database_user` WHERE `database_user_id` = ?', $this->dataRecord['database_ro_user_id']); | |||
| if($user_old_rec) { | |||
| $user_new_rec = $user_old_rec; | |||
| $user_new_rec['server_id'] = $this->dataRecord['server_id']; | |||
| $app->db->datalogSave('web_database_user', 'UPDATE', 'database_user_id', $this->dataRecord['database_ro_user_id'], $user_old_rec, $user_new_rec); | |||
| } | |||
| } | |||
| } | |||
| parent::onBeforeUpdate(); | |||
| } | |||
| function onBeforeInsert() { | |||
| global $app, $conf, $interfaceConf; | |||
| //* Site shell not be empty | |||
| if($this->dataRecord['parent_domain_id'] == 0) $app->tform->errorMessage .= $app->tform->lng("database_site_error_empty").'<br />'; | |||
| //* Database username and database name shall not be empty | |||
| if($this->dataRecord['database_name'] == '') $app->tform->errorMessage .= $app->tform->wordbook["database_name_error_empty"].'<br />'; | |||
| //* Get the database name and database user prefix | |||
| $app->uses('getconf,tools_sites'); | |||
| $global_config = $app->getconf->get_global_config('sites'); | |||
| $dbname_prefix = $app->tools_sites->replacePrefix($global_config['dbname_prefix'], $this->dataRecord); | |||
| $this->dataRecord['database_name_prefix'] = $dbname_prefix; | |||
| if(strlen($dbname_prefix . $this->dataRecord['database_name']) > 64) $app->tform->errorMessage .= str_replace('{db}', $dbname_prefix . $this->dataRecord['database_name'], $app->tform->wordbook["database_name_error_len"]).'<br />'; | |||
| //* Check database name and user against blacklist | |||
| $dbname_blacklist = array($conf['db_database'], 'mysql'); | |||
| if(in_array($dbname_prefix . $this->dataRecord['database_name'], $dbname_blacklist)) { | |||
| $app->tform->errorMessage .= $app->lng('Database name not allowed.').'<br />'; | |||
| } | |||
| /* restrict the names */ | |||
| /* crop user and db names if they are too long -> mysql: user: 16 chars / db: 64 chars */ | |||
| if ($app->tform->errorMessage == ''){ | |||
| $this->dataRecord['database_name'] = substr($dbname_prefix . $this->dataRecord['database_name'], 0, 64); | |||
| } | |||
| //* Check for duplicates | |||
| $tmp = $app->db->queryOneRecord("SELECT count(database_id) as dbnum FROM web_database WHERE database_name = ? AND server_id = ?", $this->dataRecord['database_name'], $this->dataRecord["server_id"]); | |||
| if($tmp['dbnum'] > 0) $app->tform->errorMessage .= $app->tform->lng('database_name_error_unique').'<br />'; | |||
| // get the web server ip (parent domain) | |||
| $tmp = $app->db->queryOneRecord("SELECT server_id FROM web_domain WHERE domain_id = ?", $this->dataRecord['parent_domain_id']); | |||
| if($tmp['server_id'] && $tmp['server_id'] != $this->dataRecord['server_id']) { | |||
| // we need remote access rights for this server, so get it's ip address | |||
| $server_config = $app->getconf->get_server_config($tmp['server_id'], 'server'); | |||
| if($server_config['ip_address']!='') { | |||
| if($this->dataRecord['remote_access'] != 'y'){ | |||
| $this->dataRecord['remote_ips'] = $server_config['ip_address']; | |||
| $this->dataRecord['remote_access'] = 'y'; | |||
| } else { | |||
| if($this->dataRecord['remote_ips'] != ''){ | |||
| if(preg_match('/(^|,)' . preg_quote($server_config['ip_address'], '/') . '(,|$)/', $this->dataRecord['remote_ips']) == false) { | |||
| $this->dataRecord['remote_ips'] .= ',' . $server_config['ip_address']; | |||
| } | |||
| $tmp = preg_split('/\s*,\s*/', $this->dataRecord['remote_ips']); | |||
| $tmp = array_unique($tmp); | |||
| $this->dataRecord['remote_ips'] = implode(',', $tmp); | |||
| unset($tmp); | |||
| } | |||
| } | |||
| } | |||
| } | |||
| if ($app->tform->errorMessage == '') { | |||
| // force update of the used database user | |||
| if($this->dataRecord['database_user_id']) { | |||
| $user_old_rec = $app->db->queryOneRecord('SELECT * FROM `web_database_user` WHERE `database_user_id` = ?', $this->dataRecord['database_user_id']); | |||
| if($user_old_rec) { | |||
| $user_new_rec = $user_old_rec; | |||
| $user_new_rec['server_id'] = $this->dataRecord['server_id']; | |||
| $app->db->datalogSave('web_database_user', 'UPDATE', 'database_user_id', $this->dataRecord['database_user_id'], $user_old_rec, $user_new_rec); | |||
| } | |||
| } | |||
| if($this->dataRecord['database_ro_user_id']) { | |||
| $user_old_rec = $app->db->queryOneRecord('SELECT * FROM `web_database_user` WHERE `database_user_id` = ?', $this->dataRecord['database_ro_user_id']); | |||
| if($user_old_rec) { | |||
| $user_new_rec = $user_old_rec; | |||
| $user_new_rec['server_id'] = $this->dataRecord['server_id']; | |||
| $app->db->datalogSave('web_database_user', 'UPDATE', 'database_user_id', $this->dataRecord['database_ro_user_id'], $user_old_rec, $user_new_rec); | |||
| } | |||
| } | |||
| } | |||
| parent::onBeforeInsert(); | |||
| } | |||
| function onInsertSave($sql) { | |||
| global $app, $conf; | |||
| $app->db->query($sql); | |||
| if($app->db->errorMessage != '') die($app->db->errorMessage); | |||
| $new_id = $app->db->insertID(); | |||
| return $new_id; | |||
| } | |||
| function onUpdateSave($sql) { | |||
| global $app; | |||
| if(!empty($sql) && !$app->tform->isReadonlyTab($app->tform->getCurrentTab(), $this->id)) { | |||
| $app->db->query($sql); | |||
| if($app->db->errorMessage != '') die($app->db->errorMessage); | |||
| } | |||
| } | |||
| function onAfterInsert() { | |||
| global $app, $conf; | |||
| $app->uses('sites_database_plugin'); | |||
| $app->sites_database_plugin->processDatabaseInsert($this); | |||
| } | |||
| function onAfterUpdate() { | |||
| global $app, $conf; | |||
| $app->uses('sites_database_plugin'); | |||
| $app->sites_database_plugin->processDatabaseUpdate($this); | |||
| } | |||
| } | |||
| $page = new page_action; | |||
| $page->onLoad(); | |||
| ?> | |||
| @@ -1,249 +0,0 @@ | |||
| <?php | |||
| /* | |||
| Copyright (c) 2008, Till Brehm, projektfarm Gmbh | |||
| All rights reserved. | |||
| Redistribution and use in source and binary forms, with or without modification, | |||
| are permitted provided that the following conditions are met: | |||
| * Redistributions of source code must retain the above copyright notice, | |||
| this list of conditions and the following disclaimer. | |||
| * Redistributions in binary form must reproduce the above copyright notice, | |||
| this list of conditions and the following disclaimer in the documentation | |||
| and/or other materials provided with the distribution. | |||
| * Neither the name of ISPConfig nor the names of its contributors | |||
| may be used to endorse or promote products derived from this software without | |||
| specific prior written permission. | |||
| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | |||
| ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | |||
| WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | |||
| IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, | |||
| INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | |||
| BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |||
| DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | |||
| OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | |||
| NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, | |||
| EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |||
| */ | |||
| /****************************************** | |||
| * Begin Form configuration | |||
| ******************************************/ | |||
| $tform_def_file = "form/database_user.tform.php"; | |||
| /****************************************** | |||
| * End Form configuration | |||
| ******************************************/ | |||
| require_once '../../lib/config.inc.php'; | |||
| require_once '../../lib/app.inc.php'; | |||
| //* Check permissions for module | |||
| $app->auth->check_module_permissions('sites'); | |||
| // Loading classes | |||
| $app->uses('tpl,tform,tform_actions'); | |||
| $app->load('tform_actions'); | |||
| class page_action extends tform_actions { | |||
| function onShowNew() { | |||
| global $app; | |||
| // we will check only users, not admins | |||
| if($_SESSION['s']['user']['typ'] == 'user') { | |||
| if(!$app->tform->checkClientLimit('limit_database_user')) { | |||
| $app->error($app->tform->wordbook["limit_database_user_txt"]); | |||
| } | |||
| if(!$app->tform->checkResellerLimit('limit_database_user')) { | |||
| $app->error('Reseller: '.$app->tform->wordbook["limit_database_user_txt"]); | |||
| } | |||
| } | |||
| parent::onShowNew(); | |||
| } | |||
| function onShowEnd() { | |||
| global $app, $conf, $interfaceConf; | |||
| /* | |||
| * If the names are restricted -> remove the restriction, so that the | |||
| * data can be edited | |||
| */ | |||
| //* Get the database user prefix | |||
| $app->uses('getconf,tools_sites'); | |||
| $global_config = $app->getconf->get_global_config('sites'); | |||
| $dbuser_prefix = $app->tools_sites->replacePrefix($global_config['dbuser_prefix'], $this->dataRecord); | |||
| if ($_SESSION["s"]["user"]["typ"] != 'admin' && $app->auth->has_clients($_SESSION['s']['user']['userid'])) { | |||
| // Get the limits of the client | |||
| $client_group_id = $app->functions->intval($_SESSION["s"]["user"]["default_group"]); | |||
| $client = $app->db->queryOneRecord("SELECT client.company_name, client.contact_name, client.client_id FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = ?", $client_group_id); | |||
| // Fill the client select field | |||
| $sql = "SELECT sys_group.groupid, sys_group.name, CONCAT(IF(client.company_name != '', CONCAT(client.company_name, ' :: '), ''), client.contact_name, ' (', client.username, IF(client.customer_no != '', CONCAT(', ', client.customer_no), ''), ')') as contactname FROM sys_group, client WHERE sys_group.client_id = client.client_id AND client.parent_client_id = ? ORDER BY client.company_name, client.contact_name, sys_group.name"; | |||
| $records = $app->db->queryAllRecords($sql, $client['client_id']); | |||
| $tmp = $app->db->queryOneRecord("SELECT groupid FROM sys_group WHERE client_id = ?", $client['client_id']); | |||
| $client_select = '<option value="'.$tmp['groupid'].'">'.$client['contact_name'].'</option>'; | |||
| //$tmp_data_record = $app->tform->getDataRecord($this->id); | |||
| if(is_array($records)) { | |||
| foreach( $records as $rec) { | |||
| $selected = @(is_array($this->dataRecord) && ($rec["groupid"] == $this->dataRecord['client_group_id'] || $rec["groupid"] == $this->dataRecord['sys_groupid']))?'SELECTED':''; | |||
| $client_select .= "<option value='$rec[groupid]' $selected>$rec[contactname]</option>\r\n"; | |||
| } | |||
| } | |||
| $app->tpl->setVar("client_group_id", $client_select); | |||
| } elseif($_SESSION["s"]["user"]["typ"] == 'admin') { | |||
| // Fill the client select field | |||
| $sql = "SELECT sys_group.groupid, sys_group.name, CONCAT(IF(client.company_name != '', CONCAT(client.company_name, ' :: '), ''), client.contact_name, ' (', client.username, IF(client.customer_no != '', CONCAT(', ', client.customer_no), ''), ')') as contactname FROM sys_group, client WHERE sys_group.client_id = client.client_id AND sys_group.client_id > 0 ORDER BY client.company_name, client.contact_name, sys_group.name"; | |||
| $clients = $app->db->queryAllRecords($sql); | |||
| $client_select = "<option value='0'></option>"; | |||
| //$tmp_data_record = $app->tform->getDataRecord($this->id); | |||
| if(is_array($clients)) { | |||
| foreach( $clients as $client) { | |||
| //$selected = @($client["groupid"] == $tmp_data_record["sys_groupid"])?'SELECTED':''; | |||
| $selected = @(is_array($this->dataRecord) && ($client["groupid"] == $this->dataRecord['client_group_id'] || $client["groupid"] == $this->dataRecord['sys_groupid']))?'SELECTED':''; | |||
| $client_select .= "<option value='$client[groupid]' $selected>$client[contactname]</option>\r\n"; | |||
| } | |||
| } | |||
| $app->tpl->setVar("client_group_id", $client_select); | |||
| } | |||
| if ($this->dataRecord['database_user'] != ""){ | |||
| /* REMOVE the restriction */ | |||
| $app->tpl->setVar("database_user", $app->tools_sites->removePrefix($this->dataRecord['database_user'], $this->dataRecord['database_user_prefix'], $dbuser_prefix)); | |||
| } | |||
| if($this->dataRecord['database_user'] == "") { | |||
| $app->tpl->setVar("database_user_prefix", $dbuser_prefix); | |||
| } else { | |||
| $app->tpl->setVar("database_user_prefix", $app->tools_sites->getPrefix($this->dataRecord['database_user_prefix'], $dbuser_prefix, $global_config['dbuser_prefix'])); | |||
| } | |||
| parent::onShowEnd(); | |||
| } | |||
| function onSubmit() { | |||
| global $app; | |||
| if($_SESSION['s']['user']['typ'] != 'admin' && !$app->auth->has_clients($_SESSION['s']['user']['userid'])) unset($this->dataRecord["client_group_id"]); | |||
| parent::onSubmit(); | |||
| } | |||
| function onBeforeUpdate() { | |||
| global $app, $conf, $interfaceConf; | |||
| //* Get the database user prefix | |||
| $app->uses('getconf,tools_sites'); | |||
| $global_config = $app->getconf->get_global_config('sites'); | |||
| $dbuser_prefix = $app->tools_sites->replacePrefix($global_config['dbuser_prefix'], $this->dataRecord); | |||
| $this->oldDataRecord = $app->db->queryOneRecord("SELECT * FROM web_database_user WHERE database_user_id = ?", $this->id); | |||
| $dbuser_prefix = $app->tools_sites->getPrefix($this->oldDataRecord['database_user_prefix'], $dbuser_prefix); | |||
| $this->dataRecord['database_user_prefix'] = $dbuser_prefix; | |||
| //* Database username shall not be empty | |||
| if($this->dataRecord['database_user'] == '') $app->tform->errorMessage .= $app->tform->wordbook["database_user_error_empty"].'<br />'; | |||
| if(strlen($dbuser_prefix . $this->dataRecord['database_user']) > 16) $app->tform->errorMessage .= str_replace('{user}', htmlentities($dbuser_prefix . $this->dataRecord['database_user'], ENT_QUOTES, 'UTF-8'), $app->tform->wordbook["database_user_error_len"]).'<br />'; | |||
| //* Check database user against blacklist | |||
| $dbuser_blacklist = array($conf['db_user'], 'mysql', 'root'); | |||
| if(in_array($dbuser_prefix . $this->dataRecord['database_user'], $dbuser_blacklist)) { | |||
| $app->tform->errorMessage .= $app->lng('Database user not allowed.').'<br />'; | |||
| } | |||
| if ($app->tform->errorMessage == ''){ | |||
| /* restrict the names if there is no error */ | |||
| /* crop user and db names if they are too long -> mysql: user: 16 chars / db: 64 chars */ | |||
| $this->dataRecord['database_user'] = substr($dbuser_prefix . $this->dataRecord['database_user'], 0, 16); | |||
| } | |||
| /* prepare password for MongoDB */ | |||
| // TODO: this still doens't work as when only the username changes we have no database_password. | |||
| // taking the one from oldData doesn't work as it's encrypted...shit! | |||
| /* | |||
| $this->dataRecord['database_password_mongo'] = $this->dataRecord['database_user'].":mongo:".$this->dataRecord['database_password']; | |||
| $this->dataRecord['server_id'] = 0; // we need this on all servers | |||
| */ | |||
| parent::onBeforeUpdate(); | |||
| } | |||
| function onBeforeInsert() { | |||
| global $app, $conf, $interfaceConf; | |||
| //* Database username shall not be empty | |||
| if($this->dataRecord['database_user'] == '') $app->tform->errorMessage .= $app->tform->wordbook["database_user_error_empty"].'<br />'; | |||
| //* Database password shall not be empty | |||
| if($this->dataRecord['database_password'] == '') $app->tform->errorMessage .= $app->tform->wordbook["database_password_error_empty"].'<br />'; | |||
| //* Get the database name and database user prefix | |||
| $app->uses('getconf,tools_sites'); | |||
| $global_config = $app->getconf->get_global_config('sites'); | |||
| $dbuser_prefix = $app->tools_sites->replacePrefix($global_config['dbuser_prefix'], $this->dataRecord); | |||
| $this->dataRecord['database_user_prefix'] = $dbuser_prefix; | |||
| if(strlen($dbuser_prefix . $this->dataRecord['database_user']) > 16) $app->tform->errorMessage .= str_replace('{user}', htmlentities($dbuser_prefix . $this->dataRecord['database_user'], ENT_QUOTES, 'UTF-8'), $app->tform->wordbook["database_user_error_len"]).'<br />'; | |||
| //* Check database user against blacklist | |||
| $dbuser_blacklist = array($conf['db_user'], 'mysql', 'root'); | |||
| if(is_array($dbuser_blacklist) && in_array($dbuser_prefix . $this->dataRecord['database_user'], $dbuser_blacklist)) { | |||
| $app->tform->errorMessage .= $app->lng('Database user not allowed.').'<br />'; | |||
| } | |||
| /* restrict the names */ | |||
| /* crop user names if they are too long -> mysql: user: 16 chars / db: 64 chars */ | |||
| if ($app->tform->errorMessage == ''){ | |||
| $this->dataRecord['database_user'] = substr($dbuser_prefix . $this->dataRecord['database_user'], 0, 16); | |||
| } | |||
| $this->dataRecord['server_id'] = 0; // we need this on all servers | |||
| /* prepare password for MongoDB */ | |||
| // $this->dataRecord['database_password_mongo'] = $this->dataRecord['database_user'].":mongo:".$this->dataRecord['database_password']; | |||
| parent::onBeforeInsert(); | |||
| } | |||
| function onAfterInsert() { | |||
| global $app, $conf; | |||
| 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_database_user SET sys_groupid = ?, sys_perm_group = 'riud' WHERE database_user_id = ?", $client_group_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_database_user SET sys_groupid = ?, sys_perm_group = 'riud' WHERE database_user_id = ?", $client_group_id, $this->id); | |||
| } | |||
| } | |||
| function onAfterUpdate() { | |||
| global $app, $conf; | |||
| 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_database_user SET sys_groupid = ?, sys_perm_group = 'riud' WHERE database_user_id = ?", $client_group_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_database_user SET sys_groupid = ?, sys_perm_group = 'riud' WHERE database_user_id = ?", $client_group_id, $this->id); | |||
| } | |||
| } | |||
| } | |||
| $page = new page_action; | |||
| $page->onLoad(); | |||
| ?> | |||
| @@ -1,194 +0,0 @@ | |||
| <?php | |||
| /* | |||
| Form Definition | |||
| Tabledefinition | |||
| Datatypes: | |||
| - INTEGER (Forces the input to Int) | |||
| - DOUBLE | |||
| - CURRENCY (Formats the values to currency notation) | |||
| - VARCHAR (no format check, maxlength: 255) | |||
| - TEXT (no format check) | |||
| - DATE (Dateformat, automatic conversion to timestamps) | |||
| Formtype: | |||
| - TEXT (Textfield) | |||
| - TEXTAREA (Textarea) | |||
| - PASSWORD (Password textfield, input is not shown when edited) | |||
| - SELECT (Select option field) | |||
| - RADIO | |||
| - CHECKBOX | |||
| - CHECKBOXARRAY | |||
| - FILE | |||
| VALUE: | |||
| - Wert oder Array | |||
| Hint: | |||
| The ID field of the database table is not part of the datafield definition. | |||
| The ID field must be always auto incement (int or bigint). | |||
| Search: | |||
| - searchable = 1 or searchable = 2 include the field in the search | |||
| - searchable = 1: this field will be the title of the search result | |||
| - searchable = 2: this field will be included in the description of the search result | |||
| */ | |||
| $form["title"] = "Database"; | |||
| $form["description"] = ""; | |||
| $form["name"] = "database"; | |||
| $form["action"] = "database_edit.php"; | |||
| $form["db_table"] = "web_database"; | |||
| $form["db_table_idx"] = "database_id"; | |||
| $form["db_history"] = "yes"; | |||
| $form["tab_default"] = "database"; | |||
| $form["list_default"] = "database_list.php"; | |||
| $form["auth"] = 'yes'; // yes / no | |||
| $form["auth_preset"]["userid"] = 0; // 0 = id of the user, > 0 id must match with id of current user | |||
| $form["auth_preset"]["groupid"] = 0; // 0 = default groupid of the user, > 0 id must match with groupid of current user | |||
| $form["auth_preset"]["perm_user"] = 'riud'; //r = read, i = insert, u = update, d = delete | |||
| $form["auth_preset"]["perm_group"] = 'riud'; //r = read, i = insert, u = update, d = delete | |||
| $form["auth_preset"]["perm_other"] = ''; //r = read, i = insert, u = update, d = delete | |||
| $form["tabs"]['database'] = array ( | |||
| 'title' => "Database", | |||
| 'width' => 100, | |||
| 'template' => "templates/database_edit.htm", | |||
| 'fields' => array ( | |||
| //################################# | |||
| // Begin Datatable fields | |||
| //################################# | |||
| 'server_id' => array ( | |||
| 'datatype' => 'INTEGER', | |||
| 'formtype' => 'SELECT', | |||
| 'default' => '', | |||
| 'datasource' => array ( 'type' => 'SQL', | |||
| 'querystring' => 'SELECT server_id,server_name FROM server WHERE mirror_server_id = 0 AND {AUTHSQL} AND db_server = 1 ORDER BY server_name', | |||
| 'keyfield'=> 'server_id', | |||
| 'valuefield'=> 'server_name' | |||
| ), | |||
| 'value' => '' | |||
| ), | |||
| 'parent_domain_id' => array ( | |||
| 'datatype' => 'INTEGER', | |||
| 'formtype' => 'SELECT', | |||
| 'default' => '', | |||
| 'datasource' => array ( 'type' => 'SQL', | |||
| 'querystring' => "SELECT web_domain.domain_id, CONCAT(web_domain.domain, ' :: ', server.server_name) AS parent_domain FROM web_domain, server WHERE web_domain.type = 'vhost' AND web_domain.server_id = server.server_id AND {AUTHSQL::web_domain} ORDER BY web_domain.domain", | |||
| 'keyfield'=> 'domain_id', | |||
| 'valuefield'=> 'parent_domain' | |||
| ), | |||
| 'value' => array('0' => 'select_site_txt') | |||
| ), | |||
| 'type' => array ( | |||
| 'datatype' => 'VARCHAR', | |||
| 'formtype' => 'SELECT', | |||
| 'default' => 'mysql', | |||
| 'value' => array( | |||
| /*'mongo' => 'MongoDB',*/ | |||
| 'mysql' => 'MySQL' | |||
| ) | |||
| ), | |||
| 'database_name' => array ( | |||
| 'datatype' => 'VARCHAR', | |||
| 'formtype' => 'TEXT', | |||
| 'validators' => array ( 0 => array ( 'type' => 'NOTEMPTY', | |||
| 'errmsg'=> 'database_name_error_empty'), | |||
| 1 => array ( 'type' => 'REGEX', | |||
| 'regex' => '/^[a-zA-Z0-9_]{2,64}$/', | |||
| 'errmsg'=> 'database_name_error_regex'), | |||
| ), | |||
| 'default' => '', | |||
| 'value' => '', | |||
| 'width' => '30', | |||
| 'maxlength' => '255', | |||
| 'searchable' => 1 | |||
| ), | |||
| 'database_name_prefix' => array ( | |||
| 'datatype' => 'VARCHAR', | |||
| 'formtype' => 'TEXT', | |||
| 'default' => '', | |||
| 'value' => '', | |||
| 'width' => '30', | |||
| 'maxlength' => '25' | |||
| ), | |||
| 'database_quota' => array ( | |||
| 'datatype' => 'INTEGER', | |||
| 'formtype' => 'TEXT', | |||
| 'validators' => array ( 0 => array ( 'type' => 'ISINT', | |||
| 'errmsg'=> 'limit_database_quota_error_notint'), | |||
| ), | |||
| 'default' => '-1', | |||
| 'value' => '', | |||
| 'separator' => '', | |||
| 'width' => '10', | |||
| 'maxlength' => '10', | |||
| 'rows' => '', | |||
| 'cols' => '' | |||
| ), | |||
| 'database_user_id' => array ( | |||
| 'datatype' => 'INTEGER', | |||
| 'formtype' => 'SELECT', | |||
| 'default' => '', | |||
| 'datasource' => array ( 'type' => 'SQL', | |||
| 'querystring' => "SELECT database_user_id,database_user FROM web_database_user WHERE {AUTHSQL} ORDER BY database_user", | |||
| 'keyfield'=> 'database_user_id', | |||
| 'valuefield'=> 'database_user' | |||
| ), | |||
| 'value' => array('0' => 'select_dbuser_txt') | |||
| ), | |||
| 'database_ro_user_id' => array ( | |||
| 'datatype' => 'INTEGER', | |||
| 'formtype' => 'SELECT', | |||
| 'default' => '', | |||
| 'datasource' => array ( 'type' => 'SQL', | |||
| 'querystring' => "SELECT database_user_id,database_user FROM web_database_user WHERE {AUTHSQL} ORDER BY database_user", | |||
| 'keyfield'=> 'database_user_id', | |||
| 'valuefield'=> 'database_user' | |||
| ), | |||
| 'value' => array('0' => 'no_dbuser_txt') | |||
| ), | |||
| 'database_charset' => array ( | |||
| 'datatype' => 'VARCHAR', | |||
| 'formtype' => 'SELECT', | |||
| 'default' => '', | |||
| 'value' => array('' => 'DB-Default', 'latin1' => 'Latin 1', 'utf8' => 'UTF-8') | |||
| ), | |||
| 'remote_access' => array ( | |||
| 'datatype' => 'VARCHAR', | |||
| 'formtype' => 'CHECKBOX', | |||
| 'default' => 'n', | |||
| 'value' => array(0 => 'n', 1 => 'y') | |||
| ), | |||
| 'active' => array ( | |||
| 'datatype' => 'VARCHAR', | |||
| 'formtype' => 'CHECKBOX', | |||
| 'default' => 'y', | |||
| 'value' => array(0 => 'n', 1 => 'y') | |||
| ), | |||
| 'remote_ips' => array ( | |||
| 'datatype' => 'TEXT', | |||
| 'formtype' => 'TEXT', | |||
| 'validators' => array ( 0 => array ( 'type' => 'CUSTOM', | |||
| 'class' => 'validate_database', | |||
| 'function' => 'valid_ip_list', | |||
| 'errmsg' => 'database_remote_error_ips'), | |||
| ), | |||
| 'default' => '', | |||
| 'value' => '', | |||
| 'width' => '60', | |||
| 'searchable' => 2 | |||
| ), | |||
| //################################# | |||
| // ENDE Datatable fields | |||
| //################################# | |||
| ) | |||
| ); | |||
| ?> | |||
| @@ -1,134 +0,0 @@ | |||
| <?php | |||
| /* | |||
| Form Definition | |||
| Tabledefinition | |||
| Datatypes: | |||
| - INTEGER (Forces the input to Int) | |||
| - DOUBLE | |||
| - CURRENCY (Formats the values to currency notation) | |||
| - VARCHAR (no format check, maxlength: 255) | |||
| - TEXT (no format check) | |||
| - DATE (Dateformat, automatic conversion to timestamps) | |||
| Formtype: | |||
| - TEXT (Textfield) | |||
| - TEXTAREA (Textarea) | |||
| - PASSWORD (Password textfield, input is not shown when edited) | |||
| - SELECT (Select option field) | |||
| - RADIO | |||
| - CHECKBOX | |||
| - CHECKBOXARRAY | |||
| - FILE | |||
| VALUE: | |||
| - Wert oder Array | |||
| Hint: | |||
| The ID field of the database table is not part of the datafield definition. | |||
| The ID field must be always auto incement (int or bigint). | |||
| Search: | |||
| - searchable = 1 or searchable = 2 include the field in the search | |||
| - searchable = 1: this field will be the title of the search result | |||
| - searchable = 2: this field will be included in the description of the search result | |||
| */ | |||
| $form["title"] = "Database User"; | |||
| $form["description"] = ""; | |||
| $form["name"] = "database_user"; | |||
| $form["action"] = "database_user_edit.php"; | |||
| $form["db_table"] = "web_database_user"; | |||
| $form["db_table_idx"] = "database_user_id"; | |||
| $form["db_history"] = "yes"; | |||
| $form["tab_default"] = "database_user"; | |||
| $form["list_default"] = "database_user_list.php"; | |||
| $form["auth"] = 'yes'; // yes / no | |||
| $form["auth_preset"]["userid"] = 0; // 0 = id of the user, > 0 id must match with id of current user | |||
| $form["auth_preset"]["groupid"] = 0; // 0 = default groupid of the user, > 0 id must match with groupid of current user | |||
| $form["auth_preset"]["perm_user"] = 'riud'; //r = read, i = insert, u = update, d = delete | |||
| $form["auth_preset"]["perm_group"] = 'riud'; //r = read, i = insert, u = update, d = delete | |||
| $form["auth_preset"]["perm_other"] = ''; //r = read, i = insert, u = update, d = delete | |||
| $form["tabs"]['database_user'] = array ( | |||
| 'title' => "Database User", | |||
| 'width' => 100, | |||
| 'template' => "templates/new_service_webdns.htm", | |||
| 'fields' => array ( | |||
| //################################# | |||
| // Begin Datatable fields | |||
| //################################# | |||
| 'server_id' => array ( | |||
| 'datatype' => 'INTEGER', | |||
| 'formtype' => 'SELECT', | |||
| 'default' => '', | |||
| 'datasource' => array ( 'type' => 'SQL', | |||
| 'querystring' => 'SELECT server_id,server_name FROM server WHERE mirror_server_id = 0 AND {AUTHSQL} AND db_server = 1 ORDER BY server_name', | |||
| 'keyfield'=> 'server_id', | |||
| 'valuefield'=> 'server_name' | |||
| ), | |||
| 'value' => '' | |||
| ), | |||
| 'database_user' => array ( | |||
| 'datatype' => 'VARCHAR', | |||
| 'formtype' => 'TEXT', | |||
| 'validators' => array ( 0 => array ( 'type' => 'NOTEMPTY', | |||
| 'errmsg'=> 'database_user_error_empty'), | |||
| 1 => array ( 'type' => 'UNIQUE', | |||
| 'errmsg'=> 'database_user_error_unique'), | |||
| 2 => array ( 'type' => 'REGEX', | |||
| 'regex' => '/^[a-zA-Z0-9_]{2,64}$/', | |||
| 'errmsg'=> 'database_user_error_regex'), | |||
| ), | |||
| 'default' => '', | |||
| 'value' => '', | |||
| 'width' => '30', | |||
| 'maxlength' => '255', | |||
| 'searchable' => 1 | |||
| ), | |||
| 'database_user_prefix' => array ( | |||
| 'datatype' => 'VARCHAR', | |||
| 'formtype' => 'TEXT', | |||
| 'default' => '', | |||
| 'value' => '', | |||
| 'width' => '30', | |||
| 'maxlength' => '25' | |||
| ), | |||
| 'database_password' => array ( | |||
| 'datatype' => 'VARCHAR', | |||
| 'formtype' => 'PASSWORD', | |||
| 'validators' => array( | |||
| 0 => array( | |||
| 'type' => 'CUSTOM', | |||
| 'class' => 'validate_password', | |||
| 'function' => 'password_check', | |||
| 'errmsg' => 'weak_password_txt' | |||
| ) | |||
| ), | |||
| 'encryption' => 'MYSQL', | |||
| 'default' => '', | |||
| 'value' => '', | |||
| 'width' => '30', | |||
| 'maxlength' => '255' | |||
| ), | |||
| 'database_password_mongo' => array ( | |||
| 'datatype' => 'VARCHAR', | |||
| 'formtype' => 'PASSWORD', | |||
| 'default' => '', | |||
| 'value' => '', | |||
| 'width' => '30', | |||
| 'maxlength' => '255' | |||
| ), | |||
| //################################# | |||
| // ENDE Datatable fields | |||
| //################################# | |||
| ) | |||
| ); | |||
| ?> | |||
| @@ -1,303 +0,0 @@ | |||
| <?php | |||
| /* | |||
| Form Definition | |||
| Tabledefinition | |||
| Datatypes: | |||
| - INTEGER (Forces the input to Int) | |||
| - DOUBLE | |||
| - CURRENCY (Formats the values to currency notation) | |||
| - VARCHAR (no format check, maxlength: 255) | |||
| - TEXT (no format check) | |||
| - DATE (Dateformat, automatic conversion to timestamps) | |||
| Formtype: | |||
| - TEXT (Textfield) | |||
| - TEXTAREA (Textarea) | |||
| - PASSWORD (Password textfield, input is not shown when edited) | |||
| - SELECT (Select option field) | |||
| - RADIO | |||
| - CHECKBOX | |||
| - CHECKBOXARRAY | |||
| - FILE | |||
| VALUE: | |||
| - Wert oder Array | |||
| Hint: | |||
| The ID field of the database table is not part of the datafield definition. | |||
| The ID field must be always auto incement (int or bigint). | |||
| Search: | |||
| - searchable = 1 or searchable = 2 include the field in the search | |||
| - searchable = 1: this field will be the title of the search result | |||
| - searchable = 2: this field will be included in the description of the search result | |||
| */ | |||
| $form["title"] = "FTP User"; | |||
| $form["description"] = ""; | |||
| $form["name"] = "ftp_user"; | |||
| $form["action"] = "ftp_user_edit.php"; | |||
| $form["db_table"] = "ftp_user"; | |||
| $form["db_table_idx"] = "ftp_user_id"; | |||
| $form["db_history"] = "yes"; | |||
| $form["tab_default"] = "ftp"; | |||
| $form["list_default"] = "ftp_user_list.php"; | |||
| $form["auth"] = 'yes'; // yes / no | |||
| $form["auth_preset"]["userid"] = 0; // 0 = id of the user, > 0 id must match with id of current user | |||
| $form["auth_preset"]["groupid"] = 0; // 0 = default groupid of the user, > 0 id must match with groupid of current user | |||
| $form["auth_preset"]["perm_user"] = 'riud'; //r = read, i = insert, u = update, d = delete | |||
| $form["auth_preset"]["perm_group"] = 'riud'; //r = read, i = insert, u = update, d = delete | |||
| $form["auth_preset"]["perm_other"] = ''; //r = read, i = insert, u = update, d = delete | |||
| $form["tabs"]['ftp'] = array ( | |||
| 'title' => "FTP User", | |||
| 'width' => 100, | |||
| 'template' => "templates/ftp_user_edit.htm", | |||
| 'fields' => array ( | |||
| //################################# | |||
| // Begin Datatable fields | |||
| //################################# | |||
| 'server_id' => array ( | |||
| 'datatype' => 'INTEGER', | |||
| 'formtype' => 'SELECT', | |||
| 'default' => '', | |||
| 'datasource' => array ( 'type' => 'SQL', | |||
| 'querystring' => 'SELECT server_id,server_name FROM server WHERE mirror_server_id = 0 AND {AUTHSQL} ORDER BY server_name', | |||
| 'keyfield'=> 'server_id', | |||
| 'valuefield'=> 'server_name' | |||
| ), | |||
| 'value' => '' | |||
| ), | |||
| 'parent_domain_id' => array ( | |||
| 'datatype' => 'INTEGER', | |||
| 'formtype' => 'SELECT', | |||
| 'default' => '', | |||
| 'datasource' => array ( 'type' => 'SQL', | |||
| 'querystring' => "SELECT web_domain.domain_id, CONCAT(web_domain.domain, ' :: ', server.server_name) AS parent_domain FROM web_domain, server WHERE web_domain.type = 'vhost' AND web_domain.server_id = server.server_id AND {AUTHSQL::web_domain} ORDER BY web_domain.domain", | |||
| 'keyfield'=> 'domain_id', | |||
| 'valuefield'=> 'parent_domain' | |||
| ), | |||
| 'value' => '' | |||
| ), | |||
| 'username' => array ( | |||
| 'datatype' => 'VARCHAR', | |||
| 'formtype' => 'TEXT', | |||
| 'validators' => array ( 0 => array ( 'type' => 'UNIQUE', | |||
| 'errmsg'=> 'username_error_unique'), | |||
| 1 => array ( 'type' => 'REGEX', | |||
| 'regex' => '/^[\w\.\-@\+]{0,64}$/', | |||
| 'errmsg'=> 'username_error_regex'), | |||
| ), | |||
| 'default' => '', | |||
| 'value' => '', | |||
| 'width' => '30', | |||
| 'maxlength' => '255', | |||
| 'searchable' => 1 | |||
| ), | |||
| 'username_prefix' => array ( | |||
| 'datatype' => 'VARCHAR', | |||
| 'formtype' => 'TEXT', | |||
| 'default' => '', | |||
| 'value' => '', | |||
| 'width' => '30', | |||
| 'maxlength' => '25' | |||
| ), | |||
| 'password' => array ( | |||
| 'datatype' => 'VARCHAR', | |||
| 'validators' => array( | |||
| 0 => array( | |||
| 'type' => 'CUSTOM', | |||
| 'class' => 'validate_password', | |||
| 'function' => 'password_check', | |||
| 'errmsg' => 'weak_password_txt' | |||
| ) | |||
| ), | |||
| 'formtype' => 'PASSWORD', | |||
| 'encryption' => 'CRYPT', | |||
| 'default' => '', | |||
| 'value' => '', | |||
| 'width' => '30', | |||
| 'maxlength' => '255' | |||
| ), | |||
| 'quota_size' => array ( | |||
| 'datatype' => 'INTEGER', | |||
| 'formtype' => 'TEXT', | |||
| 'validators' => array ( 0 => array ( 'type' => 'NOTEMPTY', | |||
| 'errmsg'=> 'quota_size_error_empty'), | |||
| 1 => array ( 'type' => 'REGEX', | |||
| 'regex' => '/^(\-1|[0-9]{1,10})$/', | |||
| 'errmsg'=> 'quota_size_error_regex'), | |||
| ), | |||
| 'default' => '-1', | |||
| 'value' => '', | |||
| 'width' => '7', | |||
| 'maxlength' => '7' | |||
| ), | |||
| 'active' => array ( | |||
| 'datatype' => 'VARCHAR', | |||
| 'formtype' => 'CHECKBOX', | |||
| 'default' => 'y', | |||
| 'value' => array(0 => 'n', 1 => 'y') | |||
| ), | |||
| //################################# | |||
| // ENDE Datatable fields | |||
| //################################# | |||
| ) | |||
| ); | |||
| if($app->auth->is_admin()) { | |||
| $form["tabs"]['advanced'] = array ( | |||
| 'title' => "Options", | |||
| 'width' => 100, | |||
| 'template' => "templates/ftp_user_advanced.htm", | |||
| 'fields' => array ( | |||
| //################################# | |||
| // Begin Datatable fields | |||
| //################################# | |||
| 'uid' => array ( | |||
| 'datatype' => 'VARCHAR', | |||
| 'formtype' => 'TEXT', | |||
| 'validators' => array ( 0 => array ( 'type' => 'NOTEMPTY', | |||
| 'errmsg'=> 'uid_error_empty'), | |||
| 1 => array( | |||
| 'type' => 'CUSTOM', | |||
| 'class' => 'validate_systemuser', | |||
| 'function' => 'check_sysuser', | |||
| 'check_names' => true, | |||
| 'errmsg' => 'invalid_system_user_or_group_txt' | |||
| ), | |||
| ), | |||
| 'default' => '0', | |||
| 'value' => '', | |||
| 'width' => '30', | |||
| 'maxlength' => '255' | |||
| ), | |||
| 'gid' => array ( | |||
| 'datatype' => 'VARCHAR', | |||
| 'formtype' => 'TEXT', | |||
| 'validators' => array ( 0 => array ( 'type' => 'NOTEMPTY', | |||
| 'errmsg'=> 'gid_error_empty'), | |||
| 1 => array( | |||
| 'type' => 'CUSTOM', | |||
| 'class' => 'validate_systemuser', | |||
| 'function' => 'check_sysgroup', | |||
| 'check_names' => true, | |||
| 'errmsg' => 'invalid_system_user_or_group_txt' | |||
| ), | |||
| ), | |||
| 'default' => '0', | |||
| 'value' => '', | |||
| 'width' => '30', | |||
| 'maxlength' => '255' | |||
| ), | |||
| 'dir' => array ( | |||
| 'datatype' => 'VARCHAR', | |||
| 'formtype' => 'TEXT', | |||
| 'validators' => array ( 0 => array ( 'type' => 'NOTEMPTY', | |||
| 'errmsg'=> 'directory_error_empty'), | |||
| 1 => array ( 'type' => 'REGEX', | |||
| 'regex' => '/^\/[a-zA-Z0-9\ \.\-\_\/]{10,128}$/', | |||
| 'errmsg'=> 'directory_error_regex'), | |||
| 2 => array ( 'type' => 'CUSTOM', | |||
| 'class' => 'validate_ftpuser', | |||
| 'function' => 'ftp_dir', | |||
| 'errmsg' => 'directory_error_notinweb'), | |||
| ), | |||
| 'default' => '', | |||
| 'value' => '', | |||
| 'width' => '30', | |||
| 'maxlength' => '255' | |||
| ), | |||
| 'quota_files' => array ( | |||
| 'datatype' => 'INTEGER', | |||
| 'formtype' => 'TEXT', | |||
| 'default' => '0', | |||
| 'value' => '', | |||
| 'width' => '7', | |||
| 'maxlength' => '7' | |||
| ), | |||
| 'ul_ratio' => array ( | |||
| 'datatype' => 'INTEGER', | |||
| 'formtype' => 'TEXT', | |||
| 'default' => '0', | |||
| 'value' => '', | |||
| 'width' => '7', | |||
| 'maxlength' => '7' | |||
| ), | |||
| 'dl_ratio' => array ( | |||
| 'datatype' => 'INTEGER', | |||
| 'formtype' => 'TEXT', | |||
| 'default' => '0', | |||
| 'value' => '', | |||
| 'width' => '7', | |||
| 'maxlength' => '7' | |||
| ), | |||
| 'ul_bandwidth' => array ( | |||
| 'datatype' => 'INTEGER', | |||
| 'formtype' => 'TEXT', | |||
| 'default' => '0', | |||
| 'value' => '', | |||
| 'width' => '7', | |||
| 'maxlength' => '7' | |||
| ), | |||
| 'dl_bandwidth' => array ( | |||
| 'datatype' => 'INTEGER', | |||
| 'formtype' => 'TEXT', | |||
| 'default' => '0', | |||
| 'value' => '', | |||
| 'width' => '7', | |||
| 'maxlength' => '7' | |||
| ), | |||
| //################################# | |||
| // ENDE Datatable fields | |||
| //################################# | |||
| ) | |||
| ); | |||
| } else { | |||
| $form["tabs"]['advanced'] = array ( | |||
| 'title' => "Options", | |||
| 'width' => 100, | |||
| 'template' => "templates/ftp_user_advanced_client.htm", | |||
| 'fields' => array ( | |||
| //################################# | |||
| // Begin Datatable fields | |||
| //################################# | |||
| 'dir' => array ( | |||
| 'datatype' => 'VARCHAR', | |||
| 'formtype' => 'TEXT', | |||
| 'validators' => array ( 0 => array ( 'type' => 'NOTEMPTY', | |||
| 'errmsg'=> 'directory_error_empty'), | |||
| 1 => array ( 'type' => 'CUSTOM', | |||
| 'class' => 'validate_ftpuser', | |||
| 'function' => 'ftp_dir', | |||
| 'errmsg' => 'directory_error_notinweb'), | |||
| ), | |||
| 'default' => '', | |||
| 'value' => '', | |||
| 'width' => '30', | |||
| 'maxlength' => '255' | |||
| ), | |||
| //################################# | |||
| // ENDE Datatable fields | |||
| //################################# | |||
| ) | |||
| ); | |||
| } | |||
| $form['tabs']['advanced']['fields']['expires'] = array( | |||
| 'datatype' => 'DATETIME', | |||
| 'formtype' => 'DATETIME' | |||
| ); | |||
| ?> | |||
| @@ -1,221 +0,0 @@ | |||
| <?php | |||
| /* | |||
| Copyright (c) 2007, Till Brehm, projektfarm Gmbh | |||
| All rights reserved. | |||
| Redistribution and use in source and binary forms, with or without modification, | |||
| are permitted provided that the following conditions are met: | |||
| * Redistributions of source code must retain the above copyright notice, | |||
| this list of conditions and the following disclaimer. | |||
| * Redistributions in binary form must reproduce the above copyright notice, | |||
| this list of conditions and the following disclaimer in the documentation | |||
| and/or other materials provided with the distribution. | |||
| * Neither the name of ISPConfig nor the names of its contributors | |||
| may be used to endorse or promote products derived from this software without | |||
| specific prior written permission. | |||
| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | |||
| ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | |||
| WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | |||
| IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, | |||
| INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | |||
| BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |||
| DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | |||
| OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | |||
| NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, | |||
| EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |||
| */ | |||
| /****************************************** | |||
| * Begin Form configuration | |||
| ******************************************/ | |||
| $tform_def_file = "form/ftp_user.tform.php"; | |||
| /****************************************** | |||
| * End Form configuration | |||
| ******************************************/ | |||
| require_once '../../lib/config.inc.php'; | |||
| require_once '../../lib/app.inc.php'; | |||
| //* Check permissions for module | |||
| $app->auth->check_module_permissions('sites'); | |||
| // Loading classes | |||
| $app->uses('tpl,tform,tform_actions'); | |||
| $app->load('tform_actions'); | |||
| class page_action extends tform_actions { | |||
| function onShowNew() { | |||
| global $app, $conf; | |||
| // we will check only users, not admins | |||
| if($_SESSION["s"]["user"]["typ"] == 'user') { | |||
| if(!$app->tform->checkClientLimit('limit_ftp_user')) { | |||
| $app->error($app->tform->wordbook["limit_ftp_user_txt"]); | |||
| } | |||
| if(!$app->tform->checkResellerLimit('limit_ftp_user')) { | |||
| $app->error('Reseller: '.$app->tform->wordbook["limit_ftp_user_txt"]); | |||
| } | |||
| } | |||
| parent::onShowNew(); | |||
| } | |||
| function onShowEnd() { | |||
| global $app, $conf, $interfaceConf; | |||
| /* | |||
| * If the names are restricted -> remove the restriction, so that the | |||
| * data can be edited | |||
| */ | |||
| $app->uses('getconf,tools_sites'); | |||
| $global_config = $app->getconf->get_global_config('sites'); | |||
| $ftpuser_prefix = $app->tools_sites->replacePrefix($global_config['ftpuser_prefix'], $this->dataRecord); | |||
| if ($this->dataRecord['username'] != ""){ | |||
| /* REMOVE the restriction */ | |||
| $app->tpl->setVar("username", $app->tools_sites->removePrefix($this->dataRecord['username'], $this->dataRecord['username_prefix'], $ftpuser_prefix)); | |||
| } | |||
| if($this->dataRecord['username'] == "") { | |||
| $app->tpl->setVar("username_prefix", $ftpuser_prefix); | |||
| } else { | |||
| $app->tpl->setVar("username_prefix", $app->tools_sites->getPrefix($this->dataRecord['username_prefix'], $ftpuser_prefix, $global_config['ftpuser_prefix'])); | |||
| } | |||
| parent::onShowEnd(); | |||
| } | |||
| function onSubmit() { | |||
| global $app, $conf; | |||
| // Get the record of the parent domain | |||
| if(isset($this->dataRecord["parent_domain_id"])) { | |||
| $parent_domain = $app->db->queryOneRecord("select * FROM web_domain WHERE domain_id = ? AND ".$app->tform->getAuthSQL('r'), @$this->dataRecord["parent_domain_id"]); | |||
| if(!$parent_domain || $parent_domain['domain_id'] != @$this->dataRecord['parent_domain_id']) $app->tform->errorMessage .= $app->tform->lng("no_domain_perm"); | |||
| } else { | |||
| $tmp = $app->tform->getDataRecord($this->id); | |||
| $parent_domain = $app->db->queryOneRecord("select * FROM web_domain WHERE domain_id = ? AND ".$app->tform->getAuthSQL('r'), $tmp["parent_domain_id"]); | |||
| if(!$parent_domain) $app->tform->errorMessage .= $app->tform->lng("no_domain_perm"); | |||
| unset($tmp); | |||
| } | |||
| // Set a few fixed values | |||
| $this->dataRecord["server_id"] = $parent_domain["server_id"]; | |||
| //die(print_r($this->dataRecord)); | |||
| if(isset($this->dataRecord['username']) && trim($this->dataRecord['username']) == '') $app->tform->errorMessage .= $app->tform->lng('username_error_empty').'<br />'; | |||
| if(isset($this->dataRecord['username']) && empty($this->dataRecord['parent_domain_id'])) $app->tform->errorMessage .= $app->tform->lng('parent_domain_id_error_empty').'<br />'; | |||
| if(isset($this->dataRecord['dir']) && stristr($this->dataRecord['dir'], '..')) $app->tform->errorMessage .= $app->tform->lng('dir_dot_error').'<br />'; | |||
| if(isset($this->dataRecord['dir']) && stristr($this->dataRecord['dir'], './')) $app->tform->errorMessage .= $app->tform->lng('dir_slashdot_error').'<br />'; | |||
| parent::onSubmit(); | |||
| } | |||
| function onBeforeInsert() { | |||
| global $app, $conf, $interfaceConf; | |||
| $app->uses('getconf,tools_sites'); | |||
| $global_config = $app->getconf->get_global_config('sites'); | |||
| $ftpuser_prefix = $app->tools_sites->replacePrefix($global_config['ftpuser_prefix'], $this->dataRecord); | |||
| $this->dataRecord['username_prefix'] = $ftpuser_prefix; | |||
| if ($app->tform->errorMessage == '') { | |||
| $this->dataRecord['username'] = $ftpuser_prefix . $this->dataRecord['username']; | |||
| } | |||
| parent::onBeforeInsert(); | |||
| } | |||
| function onAfterInsert() { | |||
| global $app, $conf; | |||
| $web = $app->db->queryOneRecord("SELECT * FROM web_domain WHERE domain_id = ?", $this->dataRecord["parent_domain_id"]); | |||
| $server_id = $app->functions->intval($web["server_id"]); | |||
| $dir = $web["document_root"]; | |||
| $uid = $web["system_user"]; | |||
| $gid = $web["system_group"]; | |||
| // Check system user and group | |||
| if($app->functions->is_allowed_user($uid) == false || $app->functions->is_allowed_group($gid) == false) { | |||
| $app->error('Invalid system user or group'); | |||
| } | |||
| // The FTP user shall be owned by the same group then the website | |||
| $sys_groupid = $app->functions->intval($web['sys_groupid']); | |||
| $sql = "UPDATE ftp_user SET server_id = ?, dir = ?, uid = ?, gid = ?, sys_groupid = ? WHERE ftp_user_id = ?"; | |||
| $app->db->query($sql, $server_id, $dir, $uid, $gid, $sys_groupid, $this->id); | |||
| } | |||
| function onBeforeUpdate() { | |||
| global $app, $conf, $interfaceConf; | |||
| /* | |||
| * If the names should be restricted -> do it! | |||
| */ | |||
| $app->uses('getconf,tools_sites'); | |||
| $global_config = $app->getconf->get_global_config('sites'); | |||
| $ftpuser_prefix = $app->tools_sites->replacePrefix($global_config['ftpuser_prefix'], $this->dataRecord); | |||
| $old_record = $app->tform->getDataRecord($this->id); | |||
| $ftpuser_prefix = $app->tools_sites->getPrefix($old_record['username_prefix'], $ftpuser_prefix); | |||
| $this->dataRecord['username_prefix'] = $ftpuser_prefix; | |||
| /* restrict the names */ | |||
| if ($app->tform->errorMessage == '') { | |||
| $this->dataRecord['username'] = $ftpuser_prefix . $this->dataRecord['username']; | |||
| } | |||
| } | |||
| function onAfterUpdate() { | |||
| global $app, $conf; | |||
| //* When the site of the FTP user has been changed | |||
| if(isset($this->dataRecord['parent_domain_id']) && $this->oldDataRecord['parent_domain_id'] != $this->dataRecord['parent_domain_id']) { | |||
| $web = $app->db->queryOneRecord("SELECT * FROM web_domain WHERE domain_id = ?", $this->dataRecord["parent_domain_id"]); | |||
| $server_id = $app->functions->intval($web["server_id"]); | |||
| $dir = $web["document_root"]; | |||
| $uid = $web["system_user"]; | |||
| $gid = $web["system_group"]; | |||
| // The FTP user shall be owned by the same group then the website | |||
| $sys_groupid = $app->functions->intval($web['sys_groupid']); | |||
| $sql = "UPDATE ftp_user SET server_id = ?, dir = ?, uid = ?, gid = ?, sys_groupid = ? WHERE ftp_user_id = ?"; | |||
| $app->db->query($sql, $server_id, $dir, $uid, $gid, $sys_groupid, $this->id); | |||
| } | |||
| //* 2. check to ensure that the FTP user path is not changed to a path outside of the docroot by a normal user | |||
| if(isset($this->dataRecord['dir']) && $this->dataRecord['dir'] != $this->oldDataRecord['dir'] && !$app->auth->is_admin()) { | |||
| $vd = new validate_ftpuser; | |||
| $error_message = $vd->ftp_dir('dir', $this->dataRecord['dir'], ''); | |||
| //* This check should normally never be triggered | |||
| //* Set the path to a safe path (web doc root). | |||
| if($error_message != '') { | |||
| $ftp_data = $app->db->queryOneRecord("SELECT parent_domain_id FROM ftp_user WHERE ftp_user_id = ?", $app->tform->primary_id); | |||
| $web = $app->db->queryOneRecord("SELECT * FROM web_domain WHERE domain_id = ?", $ftp_data["parent_domain_id"]); | |||
| $dir = $web["document_root"]; | |||
| $sql = "UPDATE ftp_user SET dir = ? WHERE ftp_user_id = ?"; | |||
| $app->db->query($sql, $dir, $this->id); | |||
| $app->log("Error in FTP path settings of FTP user ".$this->dataRecord['username'], 1); | |||
| } | |||
| } | |||
| } | |||
| } | |||
| $page = new page_action; | |||
| $page->onLoad(); | |||
| ?> | |||
| @@ -811,7 +811,7 @@ class page_action extends tform_actions { | |||
| // client group id | |||
| $res = $app->db->queryOneRecord("SELECT groupid FROM sys_group WHERE client_id = ".$app->functions->intval($fields['client_group_id'])); | |||
| $client_group_id = $app->functions->intval($this->dataRecord["client_group_id"]);//$res['groupid']; | |||
| echo ('El group id ' . $client_group_id . " "); | |||
| //echo ('El group id ' . $client_group_id . " "); | |||
| //Carga del formulario dns_soa para guardar en base de datos | |||
| @@ -964,7 +964,7 @@ $dns_ip_servidor_ipv6 = $app->db->queryOneRecord("SELECT ip_type, ip_address FRO | |||
| $tform_def_file = "../sites/form/web_vhost_domain.tform.php"; | |||
| $app->tform->loadFormDef($tform_def_file); | |||
| print_r($fields); | |||
| //print_r($fields); | |||
| //echo('La sesión user id ' . $_SESSION['s']['user']['userid']); | |||
| // add site | |||
| $paramsite = array( | |||
| @@ -1012,7 +1012,7 @@ $dns_ip_servidor_ipv6 = $app->db->queryOneRecord("SELECT ip_type, ip_address FRO | |||
| ); | |||
| //print 'Valores: ' . $dns_ip_servidor_ipv6 . " " . $formulario . " Parametros: " ; | |||
| print "<pre>"; print_r($paramsite); print "</pre>\n"; | |||
| //print "<pre>"; print_r($paramsite); print "</pre>\n"; | |||
| /*print '<pre> cliente id ' . $fields['client_id']; | |||
| print "<pre>";print_r($fields);print "</pre>\n";*/ | |||
| @@ -1,157 +0,0 @@ | |||
| <div class='page-header'> | |||
| <h1><tmpl_var name="list_head_txt"></h1> | |||
| </div> | |||
| <p><tmpl_var name="list_desc_txt"></p> | |||
| <tmpl_if name="is_admin"> | |||
| <div class="form-group"> | |||
| <tmpl_if name="edit_disabled"> | |||
| <label for="server_id_disabled" class="col-sm-3 control-label">{tmpl_var name='server_id_txt'}</label> | |||
| <div class="col-sm-9"><select name="server_id_disabled" id="server_id_disabled" class="form-control" disabled="disabled"> | |||
| {tmpl_var name='server_id'} | |||
| </select></div> | |||
| <input type="hidden" name="server_id" value="{tmpl_var name='server_id_value'}" /> | |||
| <tmpl_else> | |||
| <label for="server_id" class="col-sm-3 control-label">{tmpl_var name='server_id_txt'}</label> | |||
| <div class="col-sm-9"><select name="server_id" id="server_id" class="form-control"> | |||
| {tmpl_var name='server_id'} | |||
| </select></div> | |||
| </tmpl_if> | |||
| </div> | |||
| <tmpl_else> | |||
| <tmpl_if name="only_one_server"> | |||
| <input type="hidden" id="server_id" name="server_id" value="{tmpl_var name='server_id_value'}" /> | |||
| <tmpl_else> | |||
| <div class="form-group"> | |||
| <tmpl_if name="edit_disabled"> | |||
| <label for="server_id_disabled" class="col-sm-3 control-label">{tmpl_var name='server_id_txt'}</label> | |||
| <div class="col-sm-9"><select name="server_id_disabled" id="server_id_disabled" class="form-control" disabled="disabled"> | |||
| {tmpl_var name='server_id'} | |||
| </select></div> | |||
| <input type="hidden" name="server_id" value="{tmpl_var name='server_id_value'}" /> | |||
| <tmpl_else> | |||
| <label for="server_id" class="col-sm-3 control-label">{tmpl_var name='server_id_txt'}</label> | |||
| <div class="col-sm-9"><select name="server_id" id="server_id" class="form-control"> | |||
| {tmpl_var name='server_id'} | |||
| </select></div> | |||
| </tmpl_if> | |||
| </div> | |||
| </tmpl_if> | |||
| </tmpl_if> | |||
| <div class="form-group"> | |||
| <label for="parent_domain_id" class="col-sm-3 control-label">{tmpl_var name='parent_domain_id_txt'}</label> | |||
| <div class="col-sm-9"><select name="parent_domain_id" id="parent_domain_id" class="form-control"> | |||
| {tmpl_var name='parent_domain_id'} | |||
| </select></div> | |||
| </div> | |||
| <div class="form-group"> | |||
| <label for="type" class="col-sm-3 control-label">{tmpl_var name='type_txt'}</label> | |||
| <div class="col-sm-9"><select name="type" id="type" class="form-control"> | |||
| {tmpl_var name='type'} | |||
| </select></div> | |||
| </div> | |||
| <div class="form-group"> | |||
| <label for="database_name" class="col-sm-3 control-label">{tmpl_var name='database_name_txt'}</label> | |||
| <div class="col-sm-9"> | |||
| <div class="input-group"> | |||
| <span class="input-group-addon" id="database_name-desc">{tmpl_var name='database_name_prefix'}</span> | |||
| <tmpl_if name="edit_disabled"> | |||
| <input type="text" name="database_name" id="database_name" value="{tmpl_var name='database_name'}" class="form-control" disabled="disabled" /><input name="database_name" type="hidden" value="{tmpl_var name='database_name'}" /> | |||
| <tmpl_else> | |||
| <input type="text" name="database_name" id="database_name" value="{tmpl_var name='database_name'}" class="form-control" aria-describedby="database_name-desc" /> | |||
| </tmpl_if> | |||
| </div> | |||
| </div> | |||
| </div> | |||
| <div class="form-group"> | |||
| <label for="database_quota" class="col-sm-3 control-label">{tmpl_var name='limit_database_quota_txt'}</label> | |||
| <div class="col-sm-9"><div class="input-group"><input type="text" name="database_quota" id="quota" value="{tmpl_var name='database_quota'}" class="form-control" aria-describedby="database_quota-desc" /><span class="input-group-addon" id="database_quota-desc">MB</span></div></div> | |||
| </div> | |||
| <div class="form-group"> | |||
| <label for="database_user_id" class="col-sm-3 control-label">{tmpl_var name='database_user_txt'}</label> | |||
| <div class="col-sm-9"><select name="database_user_id" id="database_user_id" class="form-control"> | |||
| {tmpl_var name='database_user_id'} | |||
| </select></div> | |||
| </div> | |||
| <div class="form-group"> | |||
| <label for="database_ro_user_id" class="col-sm-3 control-label">{tmpl_var name='database_ro_user_txt'}</label> | |||
| <div class="col-sm-9"><select name="database_ro_user_id" id="database_ro_user_id" class="form-control" aria-describedby="database_ro_user_id-help"> | |||
| {tmpl_var name='database_ro_user_id'} | |||
| </select> | |||
| <span id="database_ro_user_id-help" class="help-block">{tmpl_var name='optional_txt'}</span> | |||
| </div> | |||
| </div> | |||
| <div class="form-group"> | |||
| <tmpl_if name="edit_disabled"> | |||
| <label for="database_charset_disabled" class="col-sm-3 control-label">{tmpl_var name='database_charset_txt'}</label> | |||
| <div class="col-sm-9"><select name="database_charset_disabled" id="database_charset_disabled" class="form-control" disabled="disabled"> | |||
| {tmpl_var name='database_charset'} | |||
| </select></div> | |||
| <input type="hidden" name="database_charset" value="{tmpl_var name='database_charset_value'}" /> | |||
| <tmpl_else> | |||
| <label for="database_charset" class="col-sm-3 control-label">{tmpl_var name='database_charset_txt'}</label> | |||
| <div class="col-sm-9"><select name="database_charset" id="database_charset" class="form-control"> | |||
| {tmpl_var name='database_charset'} | |||
| </select></div> | |||
| </tmpl_if> | |||
| </div> | |||
| <div class="form-group"> | |||
| <label class="col-sm-3 control-label">{tmpl_var name='remote_access_txt'}</label> | |||
| <div class="col-sm-9"> | |||
| {tmpl_var name='remote_access'} | |||
| </div> | |||
| </div> | |||
| <div class="form-group"> | |||
| <label for="remote_ips" class="col-sm-3 control-label">{tmpl_var name='remote_ips_txt'}</label> | |||
| <div class="col-sm-9"><input type="text" name="remote_ips" id="remote_ips" value="{tmpl_var name='remote_ips'}" class="form-control" /></div></div> | |||
| <div class="form-group"> | |||
| <label class="col-sm-3 control-label">{tmpl_var name='active_txt'}</label> | |||
| <div class="col-sm-9"> | |||
| {tmpl_var name='active'} | |||
| </div> | |||
| </div> | |||
| <input type="hidden" name="id" value="{tmpl_var name='id'}"> | |||
| <div class="clear"><div class="right"> | |||
| <button class="btn btn-default formbutton-success" type="button" value="{tmpl_var name='btn_save_txt'}" data-submit-form="pageForm" data-form-action="sites/database_edit.php">{tmpl_var name='btn_save_txt'}</button> | |||
| <button class="btn btn-default formbutton-default" type="button" value="{tmpl_var name='btn_cancel_txt'}" data-load-content="sites/database_list.php">{tmpl_var name='btn_cancel_txt'}</button> | |||
| </div></div> | |||
| <script language="JavaScript" type="text/javascript"> | |||
| <tmpl_if name="is_admin"> | |||
| function reloadDatabaseUsers() { | |||
| var parentDomainId = jQuery('#parent_domain_id').val() | |||
| jQuery.getJSON('sites/ajax_get_json.php'+ '?' + Math.round(new Date().getTime()), {web_id : parentDomainId, 'type': 'getdatabaseusers'}, function(data) { | |||
| var options = '<option value=""></option>'; | |||
| $.each(data, function(key, val) { | |||
| options += '<option value="'+key+'"'+ ($('#database_user_id').val() == key ? ' selected="selected"' : '') +'>'+val+'</option>'; | |||
| }); | |||
| $('#database_user_id').html(options).change(); | |||
| options = '<option value=""></option>'; | |||
| $.each(data, function(key, val) { | |||
| options += '<option value="'+key+'"'+ ($('#database_ro_user_id').val() == key ? ' selected="selected"' : '') +'>'+val+'</option>'; | |||
| }); | |||
| $('#database_ro_user_id').html(options).change(); | |||
| }); | |||
| } | |||
| jQuery('#parent_domain_id').change(function() { reloadDatabaseUsers(); }); | |||
| reloadDatabaseUsers(); | |||
| </tmpl_if> | |||
| jQuery('#remote_ips').ispconfigSearch({ | |||
| dataSrc: '/sites/ajax_get_json.php?type=get_ipv4', | |||
| resultsLimit: '$ <tmpl_var name="globalsearch_resultslimit_of_txt"> % <tmpl_var name="globalsearch_resultslimit_results_txt">', | |||
| ResultsTextPrefix: '<tmpl_var name="globalsearch_suggestions_text_txt">', | |||
| noResultsText: '<tmpl_var name="globalsearch_noresults_text_txt">', | |||
| noResultsLimit: '<tmpl_var name="globalsearch_noresults_limit_txt">', | |||
| minChars: 0, | |||
| cssPrefix: 'df-', | |||
| fillSearchField: true, | |||
| fillSearchFieldWith: 'fill_text', | |||
| searchFieldWatermark: '', | |||
| resultBoxPosition: '' | |||
| }); | |||
| </script> | |||
| @@ -1,67 +0,0 @@ | |||
| <div class='page-header'> | |||
| <h1><tmpl_var name="list_head_txt"></h1> | |||
| </div> | |||
| <p><tmpl_var name="list_desc_txt"></p> | |||
| <div class="form-group"> | |||
| <label for="parent_domain_id" class="col-sm-3 control-label">{tmpl_var name='parent_domain_id_txt'}</label> | |||
| <div class="col-sm-9"><select name="parent_domain_id" id="parent_domain_id" class="form-control"> | |||
| {tmpl_var name='parent_domain_id'} | |||
| </select></div> | |||
| </div> | |||
| <div class="form-group"> | |||
| <label for="username" class="col-sm-3 control-label">{tmpl_var name='username_txt'}</label> | |||
| <div class="col-sm-9"> | |||
| <div class="input-group"> | |||
| <span class="input-group-addon" id="username-desc">{tmpl_var name='username_prefix'}</span> | |||
| <input type="text" name="username" id="username" value="{tmpl_var name='username'}" class="form-control" aria-describedby="username-desc" /> | |||
| </div> | |||
| </div> | |||
| </div> | |||
| <div class="form-group"> | |||
| <label for="password" class="col-sm-3 control-label">{tmpl_var name='password_txt'}</label> | |||
| <div class="col-sm-9"> | |||
| <div class="input-group"> | |||
| <input type="password" name="password" id="password" value="{tmpl_var name='password'}" class="form-control" autocomplete="off" onkeyup="pass_check(this.value);checkPassMatch('password','repeat_password');" /> | |||
| <span class="input-group-btn"> | |||
| <button class="btn btn-default" type="button" onclick="generatePassword('password','repeat_password');">{tmpl_var name='generate_password_txt'}</button> | |||
| </span> | |||
| </div> | |||
| </div> | |||
| </div> | |||
| <div class="form-group"> | |||
| <label class="col-sm-3 control-label">{tmpl_var name='password_strength_txt'}</label> | |||
| <div class="col-sm-9 checkbox"> | |||
| <div id="passBar"></div> | |||
| <span id="passText"> </span> | |||
| </div> | |||
| </div> | |||
| <div class="form-group"> | |||
| <label for="repeat_password" class="col-sm-3 control-label">{tmpl_var name='repeat_password_txt'}</label> | |||
| <div class="col-sm-9"><input type="password" name="repeat_password" id="repeat_password" value="" class="form-control" autocomplete="off" onkeyup="checkPassMatch('password','repeat_password');" /></div></div> | |||
| <div class="form-group"> | |||
| <div class="col-sm-offset-3 col-sm-9"> | |||
| <div id="confirmpasswordError" style="display:none;" class="confirmpassworderror">{tmpl_var name='password_mismatch_txt'}</div> | |||
| <div id="confirmpasswordOK" style="display:none;" class="confirmpasswordok">{tmpl_var name='password_match_txt'}</div> | |||
| </div> | |||
| </div> | |||
| <div class="form-group"> | |||
| <label for="quota_size" class="col-sm-3 control-label">{tmpl_var name='quota_size_txt'}</label> | |||
| <div class="col-sm-9"><div class="input-group"><input type="text" name="quota_size" id="quota_size" value="{tmpl_var name='quota_size'}" class="form-control" aria-describedby="quota_size-desc" /><span class="input-group-addon" id="quota_size-desc">MB</span></div></div> | |||
| </div> | |||
| <div class="form-group"> | |||
| <label class="col-sm-3 control-label">{tmpl_var name='active_txt'}</label> | |||
| <div class="col-sm-9"> | |||
| {tmpl_var name='active'} | |||
| </div> | |||
| </div> | |||
| <input type="hidden" name="id" value="{tmpl_var name='id'}"> | |||
| <div class="clear"><div class="right"> | |||
| <button class="btn btn-default formbutton-success" type="button" value="{tmpl_var name='btn_save_txt'}" data-submit-form="pageForm" data-form-action="sites/ftp_user_edit.php">{tmpl_var name='btn_save_txt'}</button> | |||
| <button class="btn btn-default formbutton-default" type="button" value="{tmpl_var name='btn_cancel_txt'}" data-load-content="sites/ftp_user_list.php">{tmpl_var name='btn_cancel_txt'}</button> | |||
| </div></div> | |||