Advertisement
Guest User

Untitled

a guest
Mar 10th, 2018
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.79 KB | None | 0 0
  1. <?
  2.  
  3. // This can also be the reseller who owns the cPanel user.
  4. $whmusername = "root";
  5. $whmpassword = "password";
  6.  
  7. // The user on whose behalf the API call runs.
  8. // For webmaild sessions, use the cPanel user or their full email address
  9. $cpanel_user = "username";
  10.  
  11. $query = "https://10.0.0.1:2087/json-api/create_user_session?api.version=1&user=$cpanel_user&service=cpaneld";
  12.    
  13. $curl = curl_init();                                     // Create Curl Object.
  14. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);       // Allow self-signed certificates...
  15. curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);       // and certificates that don't match the hostname.
  16. curl_setopt($curl, CURLOPT_HEADER, false);               // Do not include header in output
  17. curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);        // Return contents of transfer on curl_exec.
  18. $header[0] = "Authorization: Basic " . base64_encode($whmusername.":".$whmpassword) . "\n\r";
  19. curl_setopt($curl, CURLOPT_HTTPHEADER, $header);         // Set the username and password.
  20. curl_setopt($curl, CURLOPT_URL, $query);                 // Execute the query.
  21. $result = curl_exec($curl);
  22. if ($result == false) {
  23.     error_log("curl_exec threw error \"" . curl_error($curl) . "\" for $query");
  24.                                                     // log error if curl exec fails
  25. }
  26.  
  27.  
  28. $decoded_response = json_decode( $result, true );
  29.  
  30. $session_url = $decoded_response['data']['url'];
  31. $cookie_jar = 'cookie.txt';
  32.  
  33. curl_setopt($curl, CURLOPT_HTTPHEADER, null);             // Unset the authentication header.
  34. curl_setopt($curl, CURLOPT_COOKIESESSION, true);          // Initiate a new cookie session.
  35. curl_setopt($curl, CURLOPT_COOKIEJAR, $cookie_jar);       // Set the cookie jar.
  36. curl_setopt($curl, CURLOPT_COOKIEFILE, $cookie_jar);      // Set the cookie file.
  37. curl_setopt($curl, CURLOPT_URL, $session_url);            // Set the query url to the session login url.
  38.  
  39. $result = curl_exec($curl);                               // Execute the session login call.
  40. if ($result == false) {
  41.     error_log("curl_exec threw error \"" . curl_error($curl) . "\" for $query");
  42.                                                     // Log an error if curl_exec fails.
  43. }
  44.  
  45. $session_url = preg_replace( '{/login(?:/)??.*}', '', $session_url );  // make $session_url = https://10.0.0.1/$session_key
  46.  
  47. $query = "$session_url/execute/Ftp/list_ftp";
  48.  
  49. curl_setopt($curl, CURLOPT_URL, $query);  // Change the query url to use the UAPI call.
  50. $result = curl_exec($curl);               // Execute the UAPI call.
  51. if ($result == false) {
  52.     error_log("curl_exec threw error \"" . curl_error($curl) . "\" for $query");
  53.                                                     // log error if curl exec fails
  54. }
  55.  
  56. curl_close($curl);
  57.    
  58. print $result;
  59.    
  60. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement