Please whitelist cPanel in your adblocker so that you’re able to see our version release promotions, thanks!

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.

Hiding JSON output

Discussion in 'cPanel Developers' started by KrasniyRus, Jan 20, 2018.

Tags:
  1. KrasniyRus

    KrasniyRus Member

    Joined:
    Dec 23, 2016
    Messages:
    20
    Likes Received:
    1
    Trophy Points:
    3
    Location:
    Russia
    cPanel Access Level:
    Root Administrator
    Yes, this is correct! @cPanelMichael is it possible to hide the output from the "--output=json" parameter? As far as, I can understand this is needed by the cPanel in order to create the database, but can the output be not displayed in the console output?

    According to the cPanel UAPI docs at:

    UAPI - Return Data - Software Development Kit - cPanel Documentation
    UAPI - Sort Output - Software Development Kit - cPanel Documentation
    UAPI - Filter Output - Software Development Kit - cPanel Documentation

    I have tried to hide the information but nothing worked. Once again any help will be highly appreciated!
     
  2. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    41,502
    Likes Received:
    1,616
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Hello,

    Can you let us know the specific command you used, and it's output?

    Thank you.
     
  3. KrasniyRus

    KrasniyRus Member

    Joined:
    Dec 23, 2016
    Messages:
    20
    Likes Received:
    1
    Trophy Points:
    3
    Location:
    Russia
    cPanel Access Level:
    Root Administrator
    Hello cPanelMichael,

    I am referring to the following database creating shell script:

    Code:
    #!/bin/bash
    
    cpprefix=$(uapi Mysql get_restrictions --output=json | sed -e 's/^.*"prefix":"\([^"]*\)".*$/\1/')
    rndm=`shuf -i 100-999 -n 1`
    password=`date +%s | sha256sum | base64 | head -c 12 ; echo`
    db="$cpprefix""$rndm"
    
    uapi --output=json Mysql create_database name="$db"
    uapi --output=json Mysql create_user name="$db" password="$password"
    uapi  Mysql set_privileges_on_database user="$db" database="$db" privileges=ALL%20PRIVILEGES
    
    clear
    
    ls -la
    
    printf "\n\e[33m=======Database details=======\e\n"
    printf "\e[36mDatabase & User:\e[0m $db\n"
    printf "\e[36mDatabase password:\e[0m $password\n"
    printf "\e[33m=======Database details=======\e[0m\n"
    
    And more specifically to the output of the "--output=json" part from each command. The output is:

    Code:
    {"func":"create_database","module":"Mysql","apiversion":3,"result":{"errors":null,"messages":null,"metadata":{},"data":null,"status":1}}
    {"module":"Mysql","func":"create_user","apiversion":3,"result":{"messages":null,"status":1,"data":null,"errors":null,"metadata":{}}}
    ---
    apiversion: 3
    func: set_privileges_on_database
    module: Mysql
    result:
      data: ~
      errors: ~
      messages: ~
      metadata: {}
    
      status: 1
    
    I would like to know if it is possible to hide this output. If I remove it from the code the script do not create database at all.
     
  4. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    41,502
    Likes Received:
    1,616
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
  5. KrasniyRus

    KrasniyRus Member

    Joined:
    Dec 23, 2016
    Messages:
    20
    Likes Received:
    1
    Trophy Points:
    3
    Location:
    Russia
    cPanel Access Level:
    Root Administrator
    Hi cPanelMichael,

    I have reviewed the provided link, however I am afraid that this will not work. If the script is executed via SSH with the following command:

    Code:
    ./db.sh > /dev/null
    
    There is no output at all, which is bad because the new database details are not shown, as well. If, I put the > /dev/null parameter on the same line as uapi --output=json the database and user are not created.

    Should, I open a ticket on this matter or you think, we will be able to resolve this here in the forum?
    Thank you :)
     
  6. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    41,502
    Likes Received:
    1,616
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Hello,

    Assistance with custom coding isn't typically something we offer. A support ticket is generally reserved for issues where the cPanel & WHM software isn't working as expected.

    From what I see, the issue is your custom script relies on the JSON output to print the database creation details. Thus, if you were to hide or disable that output, it won't provide the information for the "print" command to display what you want to see in the command line. Thus, it would require custom modifications to your script (e.g. perhaps the use of another bash script that runs the first one and outputs certain data only). StackOverflow is a useful resource for this type of coding question.

    Thank you.
     
  7. KrasniyRus

    KrasniyRus Member

    Joined:
    Dec 23, 2016
    Messages:
    20
    Likes Received:
    1
    Trophy Points:
    3
    Location:
    Russia
    cPanel Access Level:
    Root Administrator
    Hey,

    I have asked cPanel development related question is StackOverflow and the other users have guided me to this forum :D

    So, what I need to look for is if there is an option to pass the JSON information to the cPanel infrastructure in order for the database to be created, however in the same time it should be not displayed as output, is this correct?

    I understand that this is not in your scope of expertise and I am really grateful for the assistance so far!
     
  8. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    41,502
    Likes Received:
    1,616
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Hello,

    Yes, or a simple workaround would be to utilize two bash scripts. The first one is the one you have now, and the second one would be the one you actually use to create the database. The second one would include code that filters the output to your preference.

    You could also try sending an email to integration@cpanel.net for feedback on how to best achieve that functionality.

    Thank you.
     
Loading...

Share This Page