From b889edb33e4a09cc1f65d2fb9ad9f9ea16b1eae9 Mon Sep 17 00:00:00 2001 From: ftimme <ft@falkotimme.com> Date: Tue, 04 Sep 2012 11:42:42 -0400 Subject: [PATCH] - Ported changes from Apache plugin to nginx plugin. - Fixed errors in system.inc.php- --- interface/lib/classes/remoting.inc.php | 345 +++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 files changed, 322 insertions(+), 23 deletions(-) diff --git a/interface/lib/classes/remoting.inc.php b/interface/lib/classes/remoting.inc.php index 743b763..ae731d7 100644 --- a/interface/lib/classes/remoting.inc.php +++ b/interface/lib/classes/remoting.inc.php @@ -39,7 +39,7 @@ //* remote session timeout in seconds private $session_timeout = 600; - private $server; + protected $server; public $oldDataRecord; public $dataRecord; public $id; @@ -1063,7 +1063,8 @@ $this->server->fault('permission_denied','You do not have the permissions to access this function.'); return false; } - $affected_rows = $this->klientadd('../client/form/client.tform.php',$reseller_id, $params); + if(!isset($params['parent_client_id']) || $params['parent_client_id'] == 0) $params['parent_client_id'] = $reseller_id; + $affected_rows = $this->klientadd('../client/form/' . (isset($params['limit_client']) && $params['limit_client'] > 0 ? 'reseller' : 'client') . '.tform.php',$reseller_id, $params); return $affected_rows; } @@ -1077,7 +1078,8 @@ $this->server->fault('permission_denied','You do not have the permissions to access this function.'); return false; } - $affected_rows = $this->updateQuery('../client/form/client.tform.php', $reseller_id, $client_id, $params); + if(!isset($params['parent_client_id']) || $params['parent_client_id'] == 0) $params['parent_client_id'] = $reseller_id; + $affected_rows = $this->updateQuery('../client/form/' . (isset($params['limit_client']) && $params['limit_client'] > 0 ? 'reseller' : 'client') . '.tform.php', $reseller_id, $client_id, $params); $app->remoting_lib->ispconfig_sysuser_update($params,$client_id); @@ -1113,7 +1115,7 @@ $client_id = intval($client_id); $client_group = $app->db->queryOneRecord("SELECT groupid FROM sys_group WHERE client_id = $client_id"); - $tables = 'client,dns_rr,dns_soa,dns_slave,ftp_user,mail_access,mail_content_filter,mail_domain,mail_forwarding,mail_get,mail_user,mail_user_filter,shell_user,spamfilter_users,support_message,web_database,web_domain,web_traffic'; + $tables = 'client,dns_rr,dns_soa,dns_slave,ftp_user,mail_access,mail_content_filter,mail_domain,mail_forwarding,mail_get,mail_user,mail_user_filter,shell_user,spamfilter_users,support_message,web_database,web_database_user,web_domain,web_traffic'; $tables_array = explode(',',$tables); $client_group_id = intval($client_group['groupid']); @@ -1143,7 +1145,7 @@ $app->db->query("DELETE FROM sys_user WHERE client_id = $client_id"); // Delete all records (sub-clients, mail, web, etc....) of this client. - $tables = 'client,dns_rr,dns_soa,dns_slave,ftp_user,mail_access,mail_content_filter,mail_domain,mail_forwarding,mail_get,mail_user,mail_user_filter,shell_user,spamfilter_users,support_message,web_database,web_domain,web_traffic'; + $tables = 'client,dns_rr,dns_soa,dns_slave,ftp_user,mail_access,mail_content_filter,mail_domain,mail_forwarding,mail_get,mail_user,mail_user_filter,shell_user,spamfilter_users,support_message,web_database,web_database_user,web_domain,web_traffic'; $tables_array = explode(',',$tables); $client_group_id = intval($client_group['groupid']); if($client_group_id > 1) { @@ -1257,7 +1259,19 @@ $this->server->fault('permission_denied', 'You do not have the permissions to access this function.'); return false; } - return $this->insertQuery('../sites/form/database.tform.php',$client_id,$params); + + $sql = $this->insertQueryPrepare('../sites/form/database.tform.php', $client_id, $params); + if($sql !== false) { + $app->uses('sites_database_plugin'); + + $this->id = 0; + $this->dataRecord = $params; + $app->sites_database_plugin->processDatabaseInsert($this); + + return $this->insertQueryExecute($sql, $params); + } + + return false; } //* Update a record @@ -1267,8 +1281,18 @@ $this->server->fault('permission_denied', 'You do not have the permissions to access this function.'); return false; } - $affected_rows = $this->updateQuery('../sites/form/database.tform.php',$client_id,$primary_id,$params); - return $affected_rows; + + $sql = $this->updateQueryPrepare('../sites/form/database.tform.php', $client_id, $primary_id, $params); + if($sql !== false) { + $app->uses('sites_database_plugin'); + + $this->id = $primary_id; + $this->dataRecord = $params; + $app->sites_database_plugin->processDatabaseUpdate($this); + return $this->updateQueryExecute($sql, $primary_id, $params); + } + + return false; } //* Delete a record @@ -1278,7 +1302,61 @@ $this->server->fault('permission_denied', 'You do not have the permissions to access this function.'); return false; } + + $app->uses('sites_database_plugin'); + $app->sites_database_plugin->processDatabaseDelete($primary_id); + $affected_rows = $this->deleteQuery('../sites/form/database.tform.php',$primary_id); + return $affected_rows; + } + + // ---------------------------------------------------------------------------------------------------------- + + //* Get record details + public function sites_database_user_get($session_id, $primary_id) + { + global $app; + + if(!$this->checkPerm($session_id, 'sites_database_user_get')) { + $this->server->fault('permission_denied', 'You do not have the permissions to access this function.'); + return false; + } + $app->uses('remoting_lib'); + $app->remoting_lib->loadFormDef('../sites/form/database_user.tform.php'); + return $app->remoting_lib->getDataRecord($primary_id); + } + + //* Add a record + public function sites_database_user_add($session_id, $client_id, $params) + { + if(!$this->checkPerm($session_id, 'sites_database_user_add')) { + $this->server->fault('permission_denied', 'You do not have the permissions to access this function.'); + return false; + } + + return $this->insertQuery('../sites/form/database_user.tform.php', $client_id, $params); + } + + //* Update a record + public function sites_database_user_update($session_id, $client_id, $primary_id, $params) + { + if(!$this->checkPerm($session_id, 'sites_database_user_update')) { + $this->server->fault('permission_denied', 'You do not have the permissions to access this function.'); + return false; + } + + return $this->updateQuery('../sites/form/database_user.tform.php', $client_id, $primary_id, $params); + } + + //* Delete a record + public function sites_database_user_delete($session_id, $primary_id) + { + if(!$this->checkPerm($session_id, 'sites_database_user_delete')) { + $this->server->fault('permission_denied', 'You do not have the permissions to access this function.'); + return false; + } + + $affected_rows = $this->deleteQuery('../sites/form/database_user.tform.php',$primary_id); return $affected_rows; } @@ -1328,6 +1406,26 @@ } $affected_rows = $this->deleteQuery('../sites/form/ftp_user.tform.php',$primary_id); return $affected_rows; + } + + //* Get server for an ftp user + public function sites_ftp_user_server_get($session_id, $ftp_user) + { + global $app; + + if(!$this->checkPerm($session_id, 'sites_ftp_user_server_get')) { + $this->server->fault('permission_denied', 'You do not have the permissions to access this function.'); + return false; + } + + $data = $app->db->queryOneRecord("SELECT server_id FROM ftp_user WHERE username = '".$app->db->quote($ftp_user)."'"); + //file_put_contents('/tmp/test.txt', serialize($data)); + if(!isset($data['server_id'])) return false; + + $server = $this->server_get($session_id, $data['server_id'], 'server'); + //file_put_contents('/tmp/test2.txt', serialize($server)); + + return $server; } // ---------------------------------------------------------------------------------------------------------- @@ -1454,6 +1552,75 @@ return $affected_rows; } + // ---------------------------------------------------------------------------------------------------------- + + //* Get record details + public function sites_web_vhost_subdomain_get($session_id, $primary_id) + { + global $app; + + if(!$this->checkPerm($session_id, 'sites_web_subdomain_get')) { + $this->server->fault('permission_denied', 'You do not have the permissions to access this function.'); + return false; + } + $app->uses('remoting_lib'); + $app->remoting_lib->loadFormDef('../sites/form/web_vhost_subdomain.tform.php'); + return $app->remoting_lib->getDataRecord($primary_id); + } + + //* Add a record + public function sites_web_vhost_subdomain_add($session_id, $client_id, $params) + { + global $app; + if(!$this->checkPerm($session_id, 'sites_web_subdomain_add')) { + $this->server->fault('permission_denied', 'You do not have the permissions to access this function.'); + return false; + } + + //* Set a few params to "not empty" values which get overwritten by the sites_web_domain_plugin + if($params['document_root'] == '') $params['document_root'] = '-'; + if($params['system_user'] == '') $params['system_user'] = '-'; + if($params['system_group'] == '') $params['system_group'] = '-'; + + //* Set a few defaults for nginx servers + if($params['pm_max_children'] == '') $params['pm_max_children'] = 1; + if($params['pm_start_servers'] == '') $params['pm_start_servers'] = 1; + if($params['pm_min_spare_servers'] == '') $params['pm_min_spare_servers'] = 1; + if($params['pm_max_spare_servers'] == '') $params['pm_max_spare_servers'] = 1; + + $domain_id = $this->insertQuery('../sites/form/web_vhost_subdomain.tform.php',$client_id,$params, 'sites:web_vhost_subdomain:on_after_insert'); + return $domain_id; + } + + //* Update a record + public function sites_web_vhost_subdomain_update($session_id, $client_id, $primary_id, $params) + { + if(!$this->checkPerm($session_id, 'sites_web_subdomain_update')) { + $this->server->fault('permission_denied', 'You do not have the permissions to access this function.'); + return false; + } + + //* Set a few defaults for nginx servers + if($params['pm_max_children'] == '') $params['pm_max_children'] = 1; + if($params['pm_start_servers'] == '') $params['pm_start_servers'] = 1; + if($params['pm_min_spare_servers'] == '') $params['pm_min_spare_servers'] = 1; + if($params['pm_max_spare_servers'] == '') $params['pm_max_spare_servers'] = 1; + + $affected_rows = $this->updateQuery('../sites/form/web_vhost_subdomain.tform.php',$client_id,$primary_id,$params, 'sites:web_vhost_subdomain:on_after_insert'); + return $affected_rows; + } + + //* Delete a record + public function sites_web_vhost_subdomain_delete($session_id, $primary_id) + { + if(!$this->checkPerm($session_id, 'sites_web_subdomain_delete')) { + $this->server->fault('permission_denied', 'You do not have the permissions to access this function.'); + return false; + } + $affected_rows = $this->deleteQuery('../sites/form/web_vhost_subdomain.tform.php',$primary_id); + return $affected_rows; + } + // ----------------------------------------------------------------------------------------------- //* Get record details @@ -1547,6 +1714,112 @@ return false; } $affected_rows = $this->deleteQuery('../sites/form/web_subdomain.tform.php',$primary_id); + return $affected_rows; + } + + // ---------------------------------------------------------------------------------------------------------- + + //* Get record details + public function sites_web_folder_get($session_id, $primary_id) + { + global $app; + + if(!$this->checkPerm($session_id, 'sites_web_folder_get')) { + $this->server->fault('permission_denied', 'You do not have the permissions to access this function.'); + return false; + } + $app->uses('remoting_lib'); + $app->remoting_lib->loadFormDef('../sites/form/web_folder.tform.php'); + return $app->remoting_lib->getDataRecord($primary_id); + } + + //* Add a record + public function sites_web_folder_add($session_id, $client_id, $params) + { + if(!$this->checkPerm($session_id, 'sites_web_folder_add')) { + $this->server->fault('permission_denied', 'You do not have the permissions to access this function.'); + return false; + } + return $this->insertQuery('../sites/form/web_folder.tform.php',$client_id,$params); + } + + //* Update a record + public function sites_web_folder_update($session_id, $client_id, $primary_id, $params) + { + if(!$this->checkPerm($session_id, 'sites_web_folder_update')) { + $this->server->fault('permission_denied', 'You do not have the permissions to access this function.'); + return false; + } + $affected_rows = $this->updateQuery('../sites/form/web_folder.tform.php',$client_id,$primary_id,$params); + return $affected_rows; + } + + //* Delete a record + public function sites_web_folder_delete($session_id, $primary_id) + { + global $app; + if(!$this->checkPerm($session_id, 'sites_web_folder_delete')) { + $this->server->fault('permission_denied', 'You do not have the permissions to access this function.'); + return false; + } + + // Delete all users that belong to this folder. - taken from web_folder_delete.php + $records = $app->db->queryAllRecords("SELECT web_folder_user_id FROM web_folder_user WHERE web_folder_id = '".intval($primary_id)."'"); + foreach($records as $rec) { + $this->deleteQuery('../sites/form/web_folder_user.tform.php',$rec['web_folder_user_id']); + //$app->db->datalogDelete('web_folder_user','web_folder_user_id',$rec['web_folder_user_id']); + } + unset($records); + + $affected_rows = $this->deleteQuery('../sites/form/web_folder.tform.php',$primary_id); + return $affected_rows; + } + + // ----------------------------------------------------------------------------------------------- + + //* Get record details + public function sites_web_folder_user_get($session_id, $primary_id) + { + global $app; + + if(!$this->checkPerm($session_id, 'sites_web_folder_user_get')) { + $this->server->fault('permission_denied', 'You do not have the permissions to access this function.'); + return false; + } + $app->uses('remoting_lib'); + $app->remoting_lib->loadFormDef('../sites/form/web_folder_user.tform.php'); + return $app->remoting_lib->getDataRecord($primary_id); + } + + //* Add a record + public function sites_web_folder_user_add($session_id, $client_id, $params) + { + if(!$this->checkPerm($session_id, 'sites_web_folder_user_add')) { + $this->server->fault('permission_denied', 'You do not have the permissions to access this function.'); + return false; + } + return $this->insertQuery('../sites/form/web_folder_user.tform.php',$client_id,$params); + } + + //* Update a record + public function sites_web_folder_user_update($session_id, $client_id, $primary_id, $params) + { + if(!$this->checkPerm($session_id, 'sites_web_folder_user_update')) { + $this->server->fault('permission_denied', 'You do not have the permissions to access this function.'); + return false; + } + $affected_rows = $this->updateQuery('../sites/form/web_folder_user.tform.php',$client_id,$primary_id,$params); + return $affected_rows; + } + + //* Delete a record + public function sites_web_folder_user_delete($session_id, $primary_id) + { + if(!$this->checkPerm($session_id, 'sites_web_folder_user_delete')) { + $this->server->fault('permission_denied', 'You do not have the permissions to access this function.'); + return false; + } + $affected_rows = $this->deleteQuery('../sites/form/web_folder_user.tform.php',$primary_id); return $affected_rows; } @@ -2332,7 +2605,7 @@ protected function klientadd($formdef_file, $reseller_id, $params) { - global $app, $tform, $remoting_lib; + global $app; $app->uses('remoting_lib'); //* Load the form definition @@ -2340,13 +2613,6 @@ //* load the user profile of the client $app->remoting_lib->loadUserProfile($reseller_id); - - //* load the client template - if(isset($params['template_master']) and $params['template_master'] > 0) - { - $template=$app->db->queryOneRecord("SELECT * FROM client_template WHERE template_id=".intval($params['template_master'])); - if(is_array($template)) $params=array_merge($params,$template); - } //* Get the SQL query $sql = $app->remoting_lib->getSQL($params,'INSERT',0); @@ -2376,7 +2642,7 @@ $this->id = $insert_id; $this->dataRecord = $params; - $app->plugin->raiseEvent('client:client:on_after_insert',$this); + $app->plugin->raiseEvent('client:' . ($reseller_id ? 'reseller' : 'client') . ':on_after_insert',$this); /* if($app->db->errorMessage != '') { @@ -2404,9 +2670,16 @@ return $insert_id; } - protected function insertQuery($formdef_file, $client_id, $params,$event_identifier = '') + protected function insertQuery($formdef_file, $client_id, $params,$event_identifier = '') { - global $app, $tform, $remoting_lib; + $sql = $this->insertQueryPrepare($formdef_file, $client_id, $params); + if($sql !== false) return $this->insertQueryExecute($sql, $params,$event_identifier = ''); + else return false; + } + + protected function insertQueryPrepare($formdef_file, $client_id, $params) + { + global $app; $app->uses('remoting_lib'); @@ -2423,6 +2696,15 @@ return false; } + return $sql; + } + + protected function insertQueryExecute($sql, $params,$event_identifier = '') + { + global $app; + + $app->uses('remoting_lib'); + $app->db->query($sql); if($app->db->errorMessage != '') { @@ -2446,9 +2728,17 @@ } return $insert_id; } - - + protected function updateQuery($formdef_file, $client_id, $primary_id, $params, $event_identifier = '') + { + global $app; + + $sql = $this->updateQueryPrepare($formdef_file, $client_id, $primary_id, $params); + if($sql !== false) return $this->updateQueryExecute($sql, $primary_id, $params,$event_identifier = ''); + else return false; + } + + protected function updateQueryPrepare($formdef_file, $client_id, $primary_id, $params) { global $app; @@ -2467,6 +2757,15 @@ $this->server->fault('data_processing_error', $app->remoting_lib->errorMessage); return false; } + + return $sql; + } + + protected function updateQueryExecute($sql, $primary_id, $params, $event_identifier = '') + { + global $app; + + $app->uses('remoting_lib'); $old_rec = $app->remoting_lib->getDataRecord($primary_id); @@ -2494,7 +2793,7 @@ return $affected_rows; } - + protected function deleteQuery($formdef_file, $primary_id, $event_identifier = '') { global $app; @@ -2769,7 +3068,7 @@ return false; } $client_id = intval($client_id); - $sql = "SELECT d.database_id, d.database_name, d.database_user, d.database_password FROM web_database d INNER JOIN sys_user s on(d.sys_groupid = s.default_group) WHERE client_id = $client_id"; + $sql = "SELECT d.database_id, d.database_name, d.database_user_id, d.database_ro_user_id, du.database_user, du.database_password FROM web_database d LEFT JOIN web_database_user du ON (du.database_user_id = d.database_user_id) INNER JOIN sys_user s on(d.sys_groupid = s.default_group) WHERE client_id = $client_id"; $all = $app->db->queryAllRecords($sql); return $all; } -- Gitblit v1.9.1