The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

How to check if login details are correct?

Discussion in 'cPanel Developers' started by kgp43, May 2, 2012.

  1. kgp43

    kgp43 Active Member

    Joined:
    Aug 25, 2004
    Messages:
    31
    Likes Received:
    0
    Trophy Points:
    6
    Hi,

    I'm using the API1 to do remote backups for a couple of my clients.
    I would like to check if they username/password is correct before I try to create the backups.

    How do I do that?

    This is my current code to create the backups (using the xmlapi.php provided by cpanel).

    PHP:
        function start() {

            
    $xmlapi = new xmlapi($this->host);
            
    $xmlapi->password_auth($this->cpuser,$this->cppass);
            
    $xmlapi->set_http_client($this->http_client); // Default: cURL
            
    $xmlapi->set_port($this->port);
            
    $xmlapi->set_debug(1);

            
    $api_args = array( 
                
    'ftp'// destination type
                
    $this->ftphost// destination address
                
    $this->ftpuser// ftp user
                
    $this->ftppass// ftp password
                
    $this->notify// email to notify
                
    21// port
                
    '/'.$this->ftpfolder // remote path to put file
            
    );

            return 
    $xmlapi->api1_query($this->cpuser,'Fileman','fullbackup',$api_args);
        }
     
  2. kgp43

    kgp43 Active Member

    Joined:
    Aug 25, 2004
    Messages:
    31
    Likes Received:
    0
    Trophy Points:
    6
    I tried to do a "dummy query", to see if it's possible to use the output for anything, but it's empty.

    PHP:
    function check_login() {

        
    $xmlapi = new xmlapi($this->host);
        
    $xmlapi->password_auth($this->cpuser,$this->cppass);
        
    $xmlapi->set_http_client($this->http_client); // Default: cURL
        
    $xmlapi->set_port($this->port);
        
    $xmlapi->set_debug(1);
            
        return 
    $xmlapi->api1_query($this->cpuser,'Serverinfo','servicestatus');
    }
     
  3. kgp43

    kgp43 Active Member

    Joined:
    Aug 25, 2004
    Messages:
    31
    Likes Received:
    0
    Trophy Points:
    6
    No one knows what to do?
     
  4. charsleysa

    charsleysa Active Member

    Joined:
    Jul 18, 2011
    Messages:
    41
    Likes Received:
    0
    Trophy Points:
    6
    Location:
    Palmerston North, New Zealand
    cPanel Access Level:
    Root Administrator
    Why do you require the XMLAPI to check your Username and Password? If its just you using it then hardcode in the correct login details and just secure the script.
    Usually the XMLAPI will return an object telling you that access is denied, try multiple queries with correct and incorrect login details and print_r the results to the browser. Thats the best way to find out what you are working with.
     
  5. kgp43

    kgp43 Active Member

    Joined:
    Aug 25, 2004
    Messages:
    31
    Likes Received:
    0
    Trophy Points:
    6
    If it's just me using it, then I would probably not even bother using the xmlapi in the first place :p
    it's for my clients.
     
  6. charsleysa

    charsleysa Active Member

    Joined:
    Jul 18, 2011
    Messages:
    41
    Likes Received:
    0
    Trophy Points:
    6
    Location:
    Palmerston North, New Zealand
    cPanel Access Level:
    Root Administrator
    Well the best way is to dump all the variables on screen and see what you get, that way you know whats happening at every step.
     
Loading...

Share This Page