Explorar el Código

Activadas las funciones propias de ispconfig para la creación de bases de datos su usuario y para usuarios ftp.

incidencia_1
David Ramos hace 8 años
padre
commit
204404edd5
Se han modificado 1 ficheros con 113 adiciones y 85 borrados
  1. +113
    -85
      new_service_webdns.php

+ 113
- 85
new_service_webdns.php Ver fichero

@@ -26,39 +26,84 @@ $app->load('tform_actions');

class page_action extends tform_actions {

public $estaLogeado;

function onShowNew() {
//global $app;
global $app;
//if($_SESSION['s']['user']['typ'] != 'admin' && !$app->auth->has_clients($_SESSION['s']['user']['userid'])) unset($this->dataRecord["client_group_id"]);
//unset($_SESSION['s_old']);
//echo('Data record '. $this->dataRecord["username_prefix"] . print_r($this->dataRecord));
//$sesion = $_SESSION;
/*$sesionDe = $_SESSION['s']['user']['typ'];
$grupo = $_SESSION["s"]["user"]["default_group"];
print_r('La session de ' . $sesionDe);
print(', su grupo es ' . $grupo);*/
//print_r($sesion);
//------LIMITES--------------------------------------------------------------------------------------------------
$this->estaLogeado = $_SESSION['s']['user']['typ'];
// we will check only users, not admins
if($_SESSION['s']['user']['typ'] == 'user') {

if($this->estaLogeado == 'user') {
$client_group_id = $_SESSION["s"]["user"]["default_group"];
$limitado = new limites($client_group_id);
$limitado->limitesLoad();
}
//------LIMITES--------------------------------------------------------------------------------------------------
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
$this->tratarVariablesPrefix();
$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);
$ftpuser_prefix = $app->tools_sites->replacePrefix($global_config['ftpuser_prefix'], $this->dataRecord);

if ($_SESSION["s"]["user"]["typ"] != 'admin' && $app->auth->has_clients($_SESSION['s']['user']['userid'])) {
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']));
}
//Get the database user prefix
$app->uses('getconf,tools_sites');
$global_config = $app->getconf->get_global_config('sites');
//$this->valor_prefix = $dbuser_prefix = $app->tools_sites->replacePrefix($global_config['dbuser_prefix'], $this->dataRecord);
//$this->valor_prefix_ftp = $ftpuser_prefix = $app->tools_sites->replacePrefix($global_config['ftpuser_prefix'], $this->dataRecord);
//echo('PRe antes ' . $ftpuser_prefix . ' DataRecord ' . print_r($this->dataRecord));
//echo('PRe antes2 ' . print_r($global_config));

//* Client: If the logged in user is not admin and has no sub clients (no reseller)
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);

//echo('PRe antes2 ' . print_r($global_config));
// 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);*/
//* Reseller: If the logged in user is not admin and has sub clients (reseller)
}elseif ($_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);
//echo('PRe antes2 ' . print_r($global_config));
// 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']);
@@ -87,16 +132,23 @@ class page_action extends tform_actions {
}
$app->tpl->setVar("client_group_id", $client_select);
}
// echo('Prefix Global ' . $this->valor_prefix);
if ($this->dataRecord['database_user'] != ""){
/* REMOVE the restriction */
//echo(' (1)Remove las restrinciones');
$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);
//echo(' (2)user DB vacío ');
} else {
//echo(' (3)user DB con algo ' . $this->dataRecord['database_user_prefix']);
$app->tpl->setVar("database_user_prefix", $app->tools_sites->getPrefix($this->dataRecord['database_user_prefix'], $dbuser_prefix, $global_config['dbuser_prefix']));
$app->tools_sites->getPrefix($this->dataRecord['database_user_prefix'], $dbuser_prefix, $global_config['dbuser_prefix']);
$datos_prefix = $app->tools_sites->getPrefix($this->dataRecord['database_user_prefix'], $dbuser_prefix, $global_config['dbuser_prefix']);
//echo(' Datos prefix ' . $datos_prefix);
$fields['database_user_prefix'] = $datos_prefix;
}

if ($this->dataRecord['username'] != ""){
@@ -109,6 +161,7 @@ class page_action extends tform_actions {
} else {
$app->tpl->setVar("username_prefix", $app->tools_sites->getPrefix($this->dataRecord['username_prefix'], $ftpuser_prefix, $global_config['ftpuser_prefix']));
}

parent::onShowEnd();
}

@@ -127,11 +180,13 @@ class page_action extends tform_actions {
$this->dataRecord['username_prefix'] = $ftpuser_prefix;
$this->dataRecord['database_user_prefix'] = $dbuser_prefix;
$valor2 = $this->dataRecord['database_user_prefix'] = $dbuser_prefix;
//$valor2 = $this->dataRecord['database_user_prefix'] = $dbuser_prefix;

$this->valor_prefix = $this->dataRecord['database_user_prefix'] = $dbuser_prefix;
$this->valor_prefix_ftp = $this->dataRecord['username_prefix'] = $ftpuser_prefix;

//echo('(1)Prefix ' . $this->valor_prefix . '(2)Prefix ftp ' . $this->valor_prefix_ftp );

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 />';
@@ -149,6 +204,22 @@ class page_action extends tform_actions {
}
$this->dataRecord['server_id'] = 0; // we need this on all servers
//echo('Usuarios ' .$this->dataRecord['database_user'] . ' Prefix ' . $this->dataRecord['database_user_prefix'] . ' Mas ' . $dbuser_prefix);
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']));
}
//* Reseller: If the logged in user is not admin and has sub clients (is a reseller)
if($_SESSION["s"]["user"]["typ"] != 'admin' && $app->auth->has_clients($_SESSION['s']['user']['userid'])) {
$this->valor_prefix = $dbuser_prefix;
}
}

@@ -171,35 +242,7 @@ class page_action extends tform_actions {

function generaNombreFTP(){
global $app, $conf, $interfaceConf;

//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);

$dbuser_prefix_valor = $app->tpl->setVar("database_name", $app->tools_sites->removePrefix($this->dataRecord['database_name'], $this->dataRecord['database_name_prefix'], $dbname_prefix));
//echo ('El prefix ' . $dbuser_prefix);
$this->dataRecord['database_user_prefix'] = $dbuser_prefix_valor;
//echo ('PreFIX ' . '{user}' . str_replace('{user}', htmlentities($dbuser_prefix . $this->dataRecord['database_user'], ENT_QUOTES, 'UTF-8')));
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
$this->tratarVariablesPrefix();

//echo ('PreFIX Valor ' . $dbuser_prefix_valor);
@@ -258,35 +301,7 @@ class page_action extends tform_actions {


function generaNombreBD(){
global $app, $conf, $interfaceConf;

//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);

$dbuser_prefix_valor = $app->tpl->setVar("database_name", $app->tools_sites->removePrefix($this->dataRecord['database_name'], $this->dataRecord['database_name_prefix'], $dbname_prefix));
//echo ('El prefix ' . $dbuser_prefix);
$this->dataRecord['database_user_prefix'] = $dbuser_prefix_valor;
//echo ('PreFIX ' . '{user}' . str_replace('{user}', htmlentities($dbuser_prefix . $this->dataRecord['database_user'], ENT_QUOTES, 'UTF-8')));
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
$this->tratarVariablesPrefix();

//echo ('PreFIX Valor ' . $dbuser_prefix_valor);
@@ -345,7 +360,7 @@ class page_action extends tform_actions {
}*/


function crearBaseDatosFtp($remoto){
function crearBaseDatosFtp($remoto){
global $app, $conf;

$fields = $app->tform->encode($this->dataRecord, $app->tform->getCurrentTab(), true);
@@ -357,21 +372,21 @@ class page_action extends tform_actions {
//print "<pre>"; print_r($generated_usernameBBDD); print "</pre>\n";
$sitio_id = $app->db->queryOneRecord(
'SELECT domain_id, domain FROM web_domain WHERE domain = "'.$fields['domain'].'"');
//print_r($fields);
//echo(' Campo en formulario ' . $fields['database_user_prefix']);
//print "<pre>"; print_r($camDnsRR); print "</pre>\n";
//$camDnsRR = $app->db->queryOneRecord('SELECT server_id, zone FROM dns_rr WHERE name LIKE "'.$this->dominio.'."');
//print "<pre>"; print_r($fields['client_id']); print "</pre>\n";

// echo(' El nuevo prefix ' . $this->valor_prefix_ftp);
$clavePass = $this->generaPass();
//*Recupero todos los prefix necesarios
$app->uses('getconf,tools_sites');
/*$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);
$ftpuser_prefix = $app->tools_sites->replacePrefix($global_config['ftpuser_prefix'], $this->dataRecord);*/

//echo('Mierda Clientes' . $this->valor_prefix . ' Mas mierda ' . $fields['database_user_prefix'] . ' Y mas ' . $this->dataRecord['database_user_prefix']);
//añado database user con su prefix
$db_user_params = array(
'server_id' => $this->bbdd_serv,
'sysgroup_id' => $this->sys_grupo_id,
'sysgroup_id' => $this->cli_grupo_id,//$this->sys_grupo_id,
'sys_userid' => $this->sys_usuario_id,
'sys_perm_other' => '-',
'database_user' => $generated_usernameBBDD,
@@ -388,12 +403,24 @@ class page_action extends tform_actions {
//print "<br>". $this->pass_db_txt;
//print "<pre>"; print_r($fields); print "</pre>\n";

$db_user_id = $remoto->insert_query('../sites/form/database_user.tform.php', $this->cli_id, $db_user_params, 'sites:web_database_user:on_after_insert');
$db_user_id = $remoto->insert_query('../sites/form/database_user.tform.php',
$this->cli_id, $db_user_params, 'sites:web_database_user:on_after_insert');
//echo('El id ' . $this->id);
// $remoto2 = new remote_actions;
// $remoto->sites_database_user_after_add($this->cli_grupo_id, $db_user_params);
//echo(' El cliente en webdns ' . $this->cli_id);
//$db_user_id = $remoto2->sites_database_user_add(1, $this->cli_id, $db_user_params, 'sites:web_database_user:on_after_insert');
/*$sql = "INSERT INTO web_database_user (dbtable,dbidx,server_id,action,tstamp,user,data) VALUES (?, ?, ?, ?, ?, ?, ?)";
$app->db->query($sql, $db_table, $dbidx, $server_id, $action, time(), $username, $diffstr);
*/
//$app->tform->datalogSave('INSERT', 'database_user_id', array(), $db_user_params);
//$app->db->datalogSave('web_database_user', 'INSERT', 'database_user_id', 1, array(), $db_user_params);
//$db_user_id = $app->db->datalogInsert('web_database_user', $db_user_params, 'database_user_id');

// add database
$paramsBD = array(
'server_id' => $this->bbdd_serv, //$camDnsRR['server_id'],
'sysgroup_id' => $this->sys_grupo_id, //$fields['client_group_id'],
'sysgroup_id' => $this->cli_grupo_id,//$this->sys_grupo_id, //$fields['client_group_id'],
'parent_domain_id' => $sitio_id['domain_id'],
'type' => 'mysql',
'database_quota' => '-1',
@@ -409,7 +436,7 @@ class page_action extends tform_actions {

$this->nombre_db_txt = $paramsBD['database_name'];

$db_id = $remoto->sites_database_add($this->cli_id,/*$fields['client_group_id'],*/ $paramsBD);
$db_id = $remoto->sites_database_add($this->cli_grupo_id, /*$this->cli_id,*//*$fields['client_group_id'],*/ $paramsBD);
$this->urlBBDD($db_id, $this->bbdd_serv);
//echo('Id de la BBDD ' . $db_id);
@@ -417,6 +444,7 @@ class page_action extends tform_actions {
//$app->uses('remoting_lib');
$app->remoting_lib->loadFormDef('../sites/form/web_vhost_domain.tform.php');
$site_data = $app->remoting_lib->getDataRecord($sitio_id);
// $site_data = $remoto->getDataRecordWebDNS($sitio_id);
$this->nombre_user_ftp = $this->generaNombreFTP();
// add ftp user
@@ -442,9 +470,9 @@ class page_action extends tform_actions {
$this->pass_ftp_txt = $ftp_params['password'];
//print "<pre> FTP "; print_r($ftp_params); print "</pre>\n";
//print "<pre>"; print_r($site_data); print "</pre>\n";
//echo('El usuario es ' . $fields['client_group_id']);
$remoto->insert_query('../sites/form/ftp_user.tform.php', $fields['client_group_id'], $ftp_params);
//echo('El grupo del usuario es ' . $this->cli_grupo_id);
$remoto->insert_query('../sites/form/ftp_user.tform.php', $this->cli_id,/*$fields['client_group_id'],*/ $ftp_params);
// $remoto->sites_ftp_user_after_insert();
echo '<br><div class="alert alert-success"><br>
Altas de BBDD y FTP, ¡Correctas!<br><br>
Usuario BBDD: <b>'. $this->usuario_db_txt .'</b><br>Contraseña: <b>' . $this->pass_db_txt . '


Cargando…
Cancelar
Guardar