From 9145b164897acfdb97e214662a638b89081e0d08 Mon Sep 17 00:00:00 2001 From: David Ramos Date: Tue, 16 Jan 2018 18:22:30 +0100 Subject: [PATCH] =?UTF-8?q?Se=20han=20a=C3=B1adido=20funciones=20copiadas?= =?UTF-8?q?=20de=20las=20de=20ispconfig=20para=20solucionar=20el=20problem?= =?UTF-8?q?a=20del=20autologin=20como=20admin,=20se=20han=20modificado=20p?= =?UTF-8?q?ara=20no=20ejecutar=20la=20funci=C3=B3n=20loadUserProfile()=20q?= =?UTF-8?q?ue=20es=20la=20que=20nos=20da=20el=20problema.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/module.conf.php | 4 +- new_service_webdns.php | 149 ++++++++++++++++++++++++++++++++++++++--- version_webdns.php | 2 +- 3 files changed, 143 insertions(+), 12 deletions(-) diff --git a/lib/module.conf.php b/lib/module.conf.php index 519c8c3..233afc5 100755 --- a/lib/module.conf.php +++ b/lib/module.conf.php @@ -32,11 +32,11 @@ $items[] = array( 'title' => 'Nuevo servicio web', 'link' => 'webdns/new_service_webdns.php', 'html_id' => 'new_service_webdns' ); -$items[] = array( 'title' => 'Usuario DB', +/*$items[] = array( 'title' => 'Usuario DB', 'target' => 'content', 'link' => 'webdns/database_user_edit.php', //'html_id' =>'db_service' - ); + );*/ /* $items[] = array( 'title' => 'El FTP', 'target' => 'content', diff --git a/new_service_webdns.php b/new_service_webdns.php index 22b6631..53820e4 100755 --- a/new_service_webdns.php +++ b/new_service_webdns.php @@ -422,10 +422,11 @@ class page_action extends tform_actions { $this->urlBBDD($db_id, $this->bbdd_serv); //echo('Id de la BBDD ' . $db_id); - // get site data para usarlo en la creación de la cuenta ftp, otra forma de cargar una tupla dandole un id + // get site data para usarlo en la creación de la cuenta ftp, otra forma de cargar una tupla dandole un id //$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 = $app->remoting_lib->getDataRecord($sitio_id); + $site_data = $remoto->getDataRecordWebDNS($sitio_id); $this->nombre_user_ftp = $this->generaNombreFTP(); // add ftp user @@ -1578,6 +1579,7 @@ print "
IP6 WEB ";print_r($this->ip6_servidor_web);print "
\n";*/ } }*/ + class remote_actions extends remoting { public function insert_query($formdef_file, $client_id, $params, $event_identifier = '') { global $app; @@ -1588,18 +1590,147 @@ class remote_actions extends remoting { $app->remoting_lib->loadUserProfile();*/ //return $app->db->query($sql);//$this->insertQueryExecute($sql, $params, $event_identifier); //echo(' insertQueryPrepare ' . $this->insertQueryExecute($sql, $params, $event_identifier)); - return $this->insertQuery($formdef_file, $client_id, $params, $event_identifier); + return $this->insertQueryWebDNS($formdef_file, $client_id, $params, $event_identifier); + } + + function insertQueryWebDNS($formdef_file, $client_id, $params, $event_identifier = '') { + $sql = $this->insertQueryPrepareWebDNS($formdef_file, $client_id, $params); + if($sql !== false) return $this->insertQueryExecuteWebDNS($sql, $params, $event_identifier); + else return false; } - public function sites_database_user_add($session_id, $client_id, $params, $event_identifier = '') - { + function insertQueryPrepareWebDNS($formdef_file, $client_id, $params) { + global $app; + + $app->uses('remoting_lib'); + + //* load the user profile of the client + //$app->remoting_lib->loadUserProfile($client_id); + + //* Load the form definition + $app->remoting_lib->loadFormDef($formdef_file); + //echo(' Base de datos ' . $app->remoting_lib->loadFormDef($formdef_file)); + //* Get the SQL query + $sql = $app->remoting_lib->getSQL($params, 'INSERT', 0); + /*if($app->remoting_lib->errorMessage != '') { + throw new SoapFault('data_processing_error', $app->remoting_lib->errorMessage); + return false; + }*/ + $app->log('Executed insertQueryPrepareWebDNS', LOGLEVEL_DEBUG); + return $sql; + } + + function insertQueryExecuteWebDNS($sql, $params, $event_identifier = '') { + global $app; + + $app->uses('remoting_lib'); + + $app->db->query($sql); + + /*if($app->db->errorMessage != '') { + throw new SoapFault('database_error', $app->db->errorMessage . ' '.$sql); + return false; + }*/ + + if ( isset($params['_primary_id'] )) + $insert_id = $params['_primary_id']; + else + $insert_id = $app->db->insertID(); + + // set a few values for compatibility with tform actions, mostly used by plugins + $this->id = $insert_id; + $this->dataRecord = $params; + $app->log('Executed insertQueryExecute, raising events now if any: ' . $event_identifier, LOGLEVEL_DEBUG); + if($event_identifier != '') $app->plugin->raiseEvent($event_identifier, $this); + + //$app->uses('tform'); + //* Save changes to Datalog + if($app->remoting_lib->formDef["db_history"] == 'yes') { + //$new_rec = $app->remoting_lib->getDataRecord($insert_id); + $new_rec = $this->getDataRecordWebDNS($insert_id); + $app->remoting_lib->datalogSave('INSERT', $primary_id, array(), $new_rec); + } + return $insert_id; + } + + public function sites_database_user_add($session_id, $client_id, $params, $event_identifier = '') { global $app; /*if(!$this->checkPerm($session_id, 'sites_database_user_add')) { throw new SoapFault('permission_denied', 'You do not have the permissions to access this function.'); return false; }*/ - //echo(' el loadUserProfile ' . $app->remoting_lib->loadUserProfile($client_id)); - return $this->insertQuery('../sites/form/database_user.tform.php', $client_id, $params, $event_identifier); + //echo(' la tablita ' . $this->formDef['db_table']); + return $this->insertQueryWebDNS('../sites/form/database_user.tform.php', $client_id, $params, $event_identifier); + } + + function getDataRecordWebDNS($primary_id) { + global $app; + $escape = '`'; + //$this->loadUserProfile(); + if(@is_numeric($primary_id)) { + if($primary_id > 0) { + // Return a single record + return $this->getDataRecordPadreWebDNS($primary_id); + //return parent::getDataRecord($primary_id); + } elseif($primary_id == -1) { + // Return a array with all records + $sql = "SELECT * FROM ??"; + return $app->db->queryAllRecords($sql, $this->formDef['db_table']); + } else { + throw new SoapFault('invalid_id', 'The ID has to be > 0 or -1.'); + return array(); + } + } elseif (@is_array($primary_id) || @is_object($primary_id)) { + if(@is_object($primary_id)) $primary_id = get_object_vars($primary_id); // do not use cast (array)xxx because it returns private and protected properties! + $sql_offset = 0; + $sql_limit = 0; + $sql_where = ''; + $params = array($this->formDef['db_table']); + foreach($primary_id as $key => $val) { + if($key == '#OFFSET#') $sql_offset = $app->functions->intval($val); + elseif($key == '#LIMIT#') $sql_limit = $app->functions->intval($val); + elseif(stristr($val, '%')) { + $sql_where .= "?? like ? AND "; + } else { + $sql_where .= "?? = ? AND "; + } + $params[] = $key; + $params[] = $val; + } + $sql_where = substr($sql_where, 0, -5); + if($sql_where == '') $sql_where = '1'; + $sql = "SELECT * FROM ?? WHERE ".$sql_where. " AND " . $this->getAuthSQLWebDNS('r', $this->formDef['db_table']); + if($sql_offset >= 0 && $sql_limit > 0) $sql .= ' LIMIT ' . $sql_offset . ',' . $sql_limit; + return $app->db->queryAllRecords($sql, true, $params); + } else { + $this->errorMessage = 'The ID must be either an integer or an array.'; + return array(); + } + } + + function getDataRecordPadreWebDNS($primary_id) { + global $app; + $escape = '`'; + $sql = "SELECT * FROM ?? WHERE ?? = ? AND ".$this->getAuthSQLWebDNS('r', $this->formDef['db_table']); + return $app->db->queryOneRecord($sql, $this->formDef['db_table'], $this->formDef['db_table_idx'], $primary_id); + } + + function getAuthSQLWebDNS($perm, $table = '') { + if($_SESSION["s"]["user"]["typ"] == 'admin' || $_SESSION['s']['user']['mailuser_id'] > 0) { + return '1'; + } else { + if ($table != ''){ + $table = ' ' . $table . '.'; + } + $groups = ( $_SESSION["s"]["user"]["groups"] ) ? $_SESSION["s"]["user"]["groups"] : 0; + $sql = '('; + $sql .= "(" . $table . "sys_userid = ".$_SESSION["s"]["user"]["userid"]." AND " . $table . "sys_perm_user like '%$perm%') OR "; + $sql .= "(" . $table . "sys_groupid IN (".$groups.") AND " . $table ."sys_perm_group like '%$perm%') OR "; + $sql .= $table . "sys_perm_other like '%$perm%'"; + $sql .= ')'; + + return $sql; + } } public function sites_database_add($client_id, $params){ @@ -1607,7 +1738,7 @@ class remote_actions extends remoting { //$app->remoting_lib->loadFormDef('../sites/form/database.tform.php'); //$app->tform->formDef('../sites/form/database.tform.php'); - $sql = $this->insertQueryPrepare('../sites/form/database.tform.php', $client_id, $params); + $sql = $this->insertQueryPrepareWebDNS('../sites/form/database.tform.php', $client_id, $params); if($sql !== false) { $app->uses('sites_database_plugin'); @@ -1617,7 +1748,7 @@ class remote_actions extends remoting { //$app->uses('sites_database_plugin'); $app->sites_database_plugin->processDatabaseInsert($this); - $retval = $this->insertQueryExecute($sql, $params); + $retval = $this->insertQueryExecuteWebDNS($sql, $params); // set correct values for backup_interval and backup_copies if(isset($params['backup_interval']) || isset($params['backup_copies'])){ diff --git a/version_webdns.php b/version_webdns.php index a19bd62..4c40008 100755 --- a/version_webdns.php +++ b/version_webdns.php @@ -23,7 +23,7 @@ require_once '../../lib/app.inc.php'; //$app->auth->check_module_permissions('help'); //if($_SESSION['s']['user']['typ'] == 'admin') { - echo '

 

 

 

'.$app->lng('Versión de WebDNS:').' 1.2

'; + echo '

 

 

 

'.$app->lng('Versión de WebDNS:').' 2.0

'; //} ?>