mcramer
2012-08-27 5a539802d8cbb781279c20dd6c557f82e91b3fa9
interface/lib/classes/remoting.inc.php
@@ -1113,7 +1113,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 +1143,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 +1257,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 +1279,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 +1300,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 +1404,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;
   }
   
   // ----------------------------------------------------------------------------------------------------------
@@ -1451,6 +1547,75 @@
         return false;
      }
      $affected_rows = $this->deleteQuery('../sites/form/web_domain.tform.php',$primary_id);
      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;
   }
   
@@ -2438,7 +2603,7 @@
   protected function klientadd($formdef_file, $reseller_id, $params)
    {
      global $app, $tform, $remoting_lib;
      global $app;
      $app->uses('remoting_lib');
         
      //* Load the form definition
@@ -2510,9 +2675,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');
      
@@ -2529,6 +2701,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 != '') {
@@ -2552,9 +2733,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;
      
@@ -2573,6 +2762,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);
      
@@ -2600,7 +2798,7 @@
      
      return $affected_rows;
   }
   protected function deleteQuery($formdef_file, $primary_id, $event_identifier = '')
    {
      global $app;
@@ -2875,7 +3073,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;
   }