Skip to main content

Set database user privileges from bash or API1 or API2

Comments

6 comments

  • cPanelMichael
    Hello :) We recommend you use our newer UAPI functions for this action: UAPI Functions - Mysql::set_privileges_on_database - Software Development Kit - cPanel Documentation Please let us know if any issues when using UAPI. Thank you.
    0
  • ITGabs
    how can I log as root in the UAPI from bash? I tried before opening this thread, this is a server level application never accessible to users, I am using curl to log as root in the API1 and API2. Simple is better this is already bloated for something that need 1 query in mysql
    0
  • cPanelMichael
    I am using curl to log as root in the API1 and API2.

    Hello :) You may find this thread helpful if you are using cURL: Accessing CPanel UAPI from command line on Linux / Mac OS Thank you.
    0
  • cPanelMichael
    Hello :) Also, to note, internal case CPANEL-4218 is open to address an issue where the MysqlFE setdbuserprivileges function for cPanel API 2 fails in cPanel versions 54 and newer. Please monitor our change log to see when this case has been addressed:
    0
  • ITGabs
    Ok cool, I was right about the version 54 I will update the API tomorrow, just 1 more question, in the API1 and API2 i am not using the root password to login, instead a hash, this is a fragment of the code that I am using to login using curl [code=php] $whmusername='root'; $hash=' 56435ed0b3eb38a428270492f6ffb6ad55f04753370f0fa9fec716cf3748f28fa79fed752040eb22c... ...16166c8f0bfcf1c650f37b32cf30e0fbd6220dd60deed349a1a69bc3614c20066587e3f7b0ab64 ' $query = "https://127.0.0.1:2087/json-api/cpanel?cpanel_jsonapi_user=$cpuser&cpanel_jsonapi_apiversion=2&cpanel_jsonapi_module=MysqlFE&cpanel_jsonapi_func=setdbuserprivileges&db=$cpdbname&dbuser=$cpdbuser&privileges=ALL%20PRIVILEGES"; $curl = curl_init(); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST,0); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER,0); curl_setopt($curl, CURLOPT_RETURNTRANSFER,1); $header[0] = "Authorization: WHM $whmusername:" . preg_replace("'(\r|\n)'","",$hash); curl_setopt($curl,CURLOPT_HTTPHEADER,$header); curl_setopt($curl, CURLOPT_URL, $query); $result = curl_exec($curl); if ($result == false) { error_log("curl_exec threw error \"" . curl_error($curl) . "\" for $query"); } echo $result;

    I really like to use hashs instead of raw passwords, is there a option similar? can you check for me? Thanks!
    0
  • cPanelMichael
    I really like to use hashs instead of raw passwords, is there a option similar? can you check for me?

    Have you considered using the "Single Sign On" feature? It's documented at: Guide to API Authentication - Software Development Kit - cPanel Documentation Thank you.
    0

Please sign in to leave a comment.