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.

Script no longer works

Discussion in 'cPanel Developers' started by Data 1, May 25, 2008.

  1. Data 1

    Data 1 Well-Known Member

    Joined:
    May 25, 2008
    Messages:
    113
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    Columbus Ohio
    cPanel Access Level:
    DataCenter Provider
    Hi all, I don't usually dump problems on people but you might be able to save me hours of research in 10 seconds, so here goes.

    I run a small hosting company, 3 dedicated servers so far, cpanel on all of them. Very easy to manage, incredible product you have at any price.

    I had a PHP script running on a server with php4 and mysql4, moved the entire site to php5 Mysql5. Script worked fine before, it's obviously not connecting to the cpanel now. Basically it creates a MySQL db, creates a user, and adds the user to the database. I'm open to any alternate method of doing this. Thank you!

    Pertinent portions:
    Code:
    function execCommand($command) {
      global $curl_path;
    
      if (!empty($curl_path)) {
        return exec("$curl_path '$command'");
      }
      else {
        return file_get_contents($command);
      }
    }
    And the previously working portion:
    Code:
    if(isset($board_name) && !empty($board_name)) {
      $db_name = strtolower($board_name);
      $result = execCommand("http://$cpanel_user:$cpanel_password@$cpanel_host:2082/frontend/$cpanel_skin/sql/adddb.html?db=$db_name");
      }
    
      if(isset($board_name) && !empty($board_name)) {
        $db_username = substr($db_name, 0, 7);
        $db_userpass = $_GET['pass'];
        $user_name   = $_GET['user'];
        $user_email  = $_GET['email'];
      }
    
      if (!empty($db_username)) {
        $result .= execCommand("http://$cpanel_user:$cpanel_password@$cpanel_host:2082/frontend/$cpanel_skin/sql/adduser.html?user=$db_username&pass=$db_userpass");
        $result .= execCommand("http://$cpanel_user:$cpanel_password@$cpanel_host:2082/frontend/$cpanel_skin/sql/addusertodb.html?user=wowultra_$db_username&db=wowultra_$db_name&ALL=ALL");
            }
     
  2. cPanelDavidG

    cPanelDavidG Technical Product Specialist

    Joined:
    Nov 29, 2006
    Messages:
    11,279
    Likes Received:
    8
    Trophy Points:
    38
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    Looking at this, a couple of things jump out:

    1. exec(), commonly this function is disabled for security reasons. Is this your own server or is this a shared hosting server?

    2. Curl. It seems you are calling Curl directly rather than compiling it into PHP. Try to run the command manually via shell and see if it works or not. May not be a coding issue so much as a configuration issue. Personally, I prefer to just compile Curl support into PHP (it's very easy using WHM -> Software -> Apache Update) and call Curl that way.

    One thing you may consider long-term, especially if this is your own server, is just to call the cPanel APIs directly rather than doing some kludges with the GUI. Look at the source code of /usr/local/cpanel/base/frontend/x3 (the x3 theme), look at the APIs it calls for certain functions and call those yourself from your PHP scripts via our XML-API. There's some posts around here covering that stuff, but if you need help with that, just ask :).
     
  3. Data 1

    Data 1 Well-Known Member

    Joined:
    May 25, 2008
    Messages:
    113
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    Columbus Ohio
    cPanel Access Level:
    DataCenter Provider
    Thank you for the response.

    It is my server and if there is a way to do it directly I would rather.

    I'll look at the x3 routines but I am using X as the default theme (branded) for customers. I saw a post about looking there but assumed that since I was using x I should look in that folder instead shame on me.

    Thank you
     
  4. cPanelDavidG

    cPanelDavidG Technical Product Specialist

    Joined:
    Nov 29, 2006
    Messages:
    11,279
    Likes Received:
    8
    Trophy Points:
    38
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    The APIs will work regardless of which theme you use. I recommend X3 just because it's actively maintained and its codebase was designed to make use of the newer APIs. Also, you'll never need to force a specific theme just to ensure your scripts work if you call the APIs directly :).

    X3 also has some really nifty branding capabilities that can be employed without customizing the theme's code itself. This has the benefit of a customized appearance while the underlying code is up-to-date.

    There was a brief overview of this in last year's Customizing cPanel(pdf) presentation. However, we are covering it in further depth with a couple of presentations at this year's conference. You can find more information about the conference on our website at: http://conference.cPanel.net
     
    #4 cPanelDavidG, May 26, 2008
    Last edited: May 26, 2008
  5. Data 1

    Data 1 Well-Known Member

    Joined:
    May 25, 2008
    Messages:
    113
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    Columbus Ohio
    cPanel Access Level:
    DataCenter Provider
    It's sad as much html and php as I have done that I can't figure this out. I don't quite understand the format or what the variables are looking for as far as input.

    While I study it I will need to enable curl so I can get the thing going again. I have done the easyapache thing but only in the beginning when there isn't anyone on the server. Now with 50 plus customers what happens to their access while cpanel is kerchunking apache and php to include curl?
     
  6. cPanelDavidG

    cPanelDavidG Technical Product Specialist

    Joined:
    Nov 29, 2006
    Messages:
    11,279
    Likes Received:
    8
    Trophy Points:
    38
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    With EasyApache, we keep downtime to an absolute minimum. I would say that a general rule of thumb would be that 30 seconds of downtime would be considered abnormally long.

    As for the APIs, I'll be happy to take time to slowly walk you through everything if you just drop me an email to sales@cpanel.net. Tickets tend to get my attention before forum posts, so I'll be able to more consistently assist you there than I would be able to assist you via this forum.
     
Loading...

Share This Page