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.

Add to Stats

Discussion in 'cPanel Developers' started by famerdave, Mar 20, 2012.

  1. famerdave

    famerdave Member

    Joined:
    Oct 29, 2011
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Root Administrator
    Hello - I need to add a few things on the side of cPanel. In the "Stats" area. I really need to add the stuff up under "Mailing Lists"

    Can anyone help redirect me of where I need to look in cPanel to find this? I have a basic knowledge of this stuff, and I already have the code and stuff for what I need added. I also need it to match the same style. (Using the progress meter)


    Thanks
     
  2. KostonConsulting

    KostonConsulting Well-Known Member

    Joined:
    Jun 17, 2010
    Messages:
    255
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    San Francisco, CA
    cPanel Access Level:
    Root Administrator
    The Stats output is done through cPanel's API2 call: <?cp StatsBar::stat() ?>. In order to modify this, you'd have to edit the Cpanel::StatsBar perl module which is not advised as your changes will be overwritten upon the next cPanel update.

    As cPanel does not currently have a way to add additional items to the StatsBar, I've used a hook and javascript to insert the code. You'll need to hook into one of the API functions that load on cPanel's index page (/usr/local/cpanel/base/frontend/x3/branding/index.html) and then use javascript to build and render a stats bar table row and append it to the table.

    Here's some info on their hooks system: cPanel's Standardized Hooks

    You can see what API calls you may want to hook into by looking at the source of the index page.
     
  3. famerdave

    famerdave Member

    Joined:
    Oct 29, 2011
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Root Administrator
    Alright, do you know of any example software that may be open source? So I can get some ideas on how I can do this simple and easy? I already have the code for what I need (it's a inode counter) its just adding that's confusing me some.
     
  4. KostonConsulting

    KostonConsulting Well-Known Member

    Joined:
    Jun 17, 2010
    Messages:
    255
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    San Francisco, CA
    cPanel Access Level:
    Root Administrator
    The only sample code I have belongs to clients so I cannot post that.

    Adding to the stats table is the same as appending to any other table with javascript. This is a generic example of how to add an additional row to the top table div id 'stats'. You'll have to consider how adding a row will change the row colors and then go back and modify their classes with JavaScript as well.

    Sorry to say it but if you're looking to copy and paste something to get this working, you're probably out of luck. You'll need to modify the code to suit your specific needs.

    Code:
    <script type="text/javascript">
    //Get stats table element
    var statsTable = YAHOO.util.Dom.get("stats");
    //Get the table body element
    var tBody = statsTable.childNodes[1];
    
    //Create a new <tr> to add to the table body
    var newTR = document.createElement("tr");
    newTR.setAttribute('class', 'row-odd');
    newTR.setAttribute('id', 'inode_stats_row');
    
    //Create a new label <td> to add to the <tr>
    var newTD1 = document.createElement("td");
    newTD1.setAttribute('class','stats_left')
    newTD1.innerHTML = 'inode count';
    //Add the <td> to the <tr>
    newTR.appendChild(newTD1);
    
    //Create a new stats bar <td> to add to the <tr>
    var newTD2 = document.createElement("td");
    newTD2.setAttribute('class','stats_right');
    
    //Create the counter <span>
    var newTD2COUNTER = document.createElement("span");
    newTD2COUNTER.setAttribute('id', 'inode_counter');
    newTD2COUNTER.innerHTML = data.count + ' / ' + data.max;  
    // data.count and data.max are example variable that need to be replaced with your count and max
    
    //Add the counter <span> to the <td> 
    newTD2.appendChild(newTD2COUNTER);
    
    //Add a <br />
    var br = document.createElement('br');
    newTD2.appendChild(br);
    
    //Create a progress bar element
    var newTD2PBAR = document.createElement("div");
    newTD2PBAR.setAttribute('class', 'stats_progress_bar');
    
    //Create the progress bar bar element
    var newTD2PBARBAR = document.createElement("div");
    newTD2PBARBAR.setAttribute('id', 'inode_progress_bar');
    newTD2PBARBAR.setAttribute('title', data.percent + '%'); //data.percent is your calculated percent variable
    newTD2PBARBAR.setAttribute('class', 'cpanel_widget_progress_bar');
    newTD2PBARBAR.innerHTML = data.count + ' / ' + data.max; //again use your vars for data.count and data.max
    newTD2PBARBAR.style.position = 'relative';
    newTD2PBARBAR.style.width = '100%';
    newTD2PBARBAR.style.height = '100%';
    newTD2PBARBAR.style.padding = '0px';
    newTD2PBARBAR.style.margin = '0px';
    newTD2PBARBAR.style.border = '0px';
    
    //Add progress bar bar element to progress bar div
    newTD2PBAR.appendChild(newTD2PBARBAR);
    
    //Create percent div
    var newTD2PBARPERCENT = document.createElement("div");
    newTD2PBARPERCENT.setAttribute('class','cpanel_widget_progress_bar_percent');
    newTD2PBARPERCENT.style.display = 'none';
    newTD2PBARPERCENT.innerHTML = data.percent;
    
    //Add percent to progress bar <div>
    newTD2PBAR.appendChild(SSTD2PBARPERCENT);
    
    //Add progress bar <div> to <td>
    newTD2.appendChild(newTD2PBAR);
    
    //Add <td> to <tr>
    newTR.appendChild(SSTD2);
    
    //Add <tr> to table body
    tBody.appendChild(newTR);
    
    //render progress bar
    CPANEL.widgets.progress_bar(YAHOO.util.Dom.get('inode_progress_bar'), data.percent , '', '{"inverse_colors":"true"}');
    </script>
    

    If you incorporate the above code with your inode count (data.count), inode limit (data.max) and percent (data.percent), it will create the progress bar. To put the code in the page, either create a custom branded index.html in the Branding Editor and add the JavaScript or hook into one of the API functions on index.html using cPanel's Standardized Hooks
     
  5. famerdave

    famerdave Member

    Joined:
    Oct 29, 2011
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Root Administrator
    Well, thanks! That should help me a lot. I think I have found how I am going to do it. Earlier, I was actually on a mobile device, so I couldn't really look at the Hooks page easily.

    One thing - if I DONT get this working, do you have a ready-made inode counter I could purchase, or would it have to be rebuilt?
     
  6. KostonConsulting

    KostonConsulting Well-Known Member

    Joined:
    Jun 17, 2010
    Messages:
    255
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    San Francisco, CA
    cPanel Access Level:
    Root Administrator
    I do not. You'd have to write one or find one.
     
  7. famerdave

    famerdave Member

    Joined:
    Oct 29, 2011
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Root Administrator
    Alright - I am going to be trying out this code tonight, but If I cannot do it, I would like to get a developer to help me create this. Are there any developers willing to help me add a Inode's counter to my cPanel?

    Thanks,
    David
     
Loading...

Share This Page