mcramer
2012-08-22 cb1aa5f1b8ad3bd0d9584ed026f46fda0fb4a7f0
interface/lib/classes/remoting.inc.php
@@ -1330,6 +1330,26 @@
      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;
   }
   // ----------------------------------------------------------------------------------------------------------
   
   //* Get record details
@@ -1454,6 +1474,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
@@ -1550,6 +1639,112 @@
      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;
   }
   // -----------------------------------------------------------------------------------------------
   
   //* Get record details