remoting api get_by_<string>

Discussion in 'Developers' Forum' started by ispcomm, Nov 1, 2013.

  1. ispcomm

    ispcomm Member

    I'm working with the remoting api to migrate a "few" accounts from another panel to ispconfig.

    To check if an account exists on ispconfig, I need to find it by it's name. For example, I need to check for an alias by it's name and not it's id. Same goes for a mailbox etc.

    Is there a way to do this via the remoting api, instead of resorting to query directly the ispconfig database?

    something like the 'mail_domain_get_by_domain' would be nice also for aliases and mailboxes.

    hints?
     
  2. ispcomm

    ispcomm Member

    remoting patch contribute

    Hi,

    I went forward and checked the remoting api. May I contribute the patches in the form of the following patch, for the requested functionality? I tried to follow your coding standards strictly. This is a patch against the last stable ispconfig.
    Code:
    # diff -u remoting.inc.org.php remoting.inc.php
    --- remoting.inc.org.php        2013-11-01 13:34:29.000000000 +0000
    +++ remoting.inc.php    2013-11-01 13:47:35.000000000 +0000
    @@ -353,6 +353,30 @@
                    $app->remoting_lib->loadFormDef('../mail/form/mail_user.tform.php');
                    return $app->remoting_lib->getDataRecord($primary_id);
            }
    +
    +    /**
    +    * Fetch the mail_user by email
    +    * @param int session_id
    +    * @param string the source address to look up
    +    * @return array array of arrays corresponding to the records in the mail_forwarding table
    +    * @author ispcomm, modded till, benlake code for get_domain_by_domain
    +    */
    +        public function mail_user_get_by_email($session_id, $email ) {
    +        global $app;
    +        if(!$this->checkPerm($session_id, 'mail_user_get')) {
    +                        $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
    +            return false;
    +        }
    +        if (!empty($email)) {
    +                $email         = $app->db->quote($email);
    +            $sql            = "SELECT * FROM mail_user WHERE email = '$email'";
    +                $result         = $app->db->queryAllRecords($sql);
    +                return          $result;
    +        }
    +        return false;
    +    }
    +
    +
    
    
            //* Add mail domain
    @@ -532,6 +556,30 @@
                            $affected_rows = $this->deleteQuery('../mail/form/mail_alias.tform.php', $primary_id);
                            return $affected_rows;
            }
    +
    +    /**
    +    * Fetch the mail_alias by source
    +    * @param int session_id
    +    * @param string the source address to look up
    +    * @return array array of arrays corresponding to the records in the mail_forwarding table
    +    * @author ispcomm, modded till, benlake code for get_domain_by_domain
    +    */
    +        public function mail_alias_get_by_source($session_id, $source ) {
    +        global $app;
    +        if(!$this->checkPerm($session_id, 'mail_alias_get')) {
    +                        $this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
    +            return false;
    +        }
    +        if (!empty($source)) {
    +                $source                = $app->db->quote($source);
    +            $sql            = "SELECT * FROM mail_forwarding WHERE source = '$source'";
    +                $result         = $app->db->queryAllRecords($sql);
    +                return          $result;
    +        }
    +        return false;
    +    }
    +
    +
    
            //* Get mail forwarding details
            public function mail_forward_get($session_id, $primary_id)
    
     
    Last edited: Nov 1, 2013
  3. till

    till Super Moderator Staff Member ISPConfig Developer

    The remote api supports searching for all fields by default, so the function you posted is not nescessary as it simply duplicates a function that is already available.

    To fetch a user by email, use the extended syntax of the mail_user_get function. Example:

    $mailuser = $client->mail_user_get($session_id, array('email' => '[email protected]'));
     
  4. ispcomm

    ispcomm Member

    Till,
    is there some "good" doc about the remote api, short of reading the source?
    I found a rar file with some examples, altough really really basic.

    Wouldn't have written a patch, had I known about the extended format
     
  5. till

    till Super Moderator Staff Member ISPConfig Developer

    The documentation of the remote api is in the remote_client directory of the ispconfig tar.gz file.
     

Share This Page