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.

cp includes: possible to include a php file?

Discussion in 'cPanel Developers' started by RSimoes, Oct 15, 2008.

  1. RSimoes

    RSimoes Member
    PartnerNOC

    Joined:
    Oct 9, 2008
    Messages:
    18
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Austin, TX
    I'm interesting in including PHP outputs in a branded cpanel index.html file. When inserting lines like the following in an html file:

    Code:
    <cpanel relinclude="foo.php">
    <cpanel Branding="include(foo.php)">
    the included php file doesn't get executed (the source is included). Is there any way to get the expected result; i.e., the php file getting executed, and the output getting included? This thread has a proposed solution, but it doesn't work.
     
    #1 RSimoes, Oct 15, 2008
    Last edited: Oct 15, 2008
  2. cPanelNick

    cPanelNick Administrator
    Staff Member

    Joined:
    Mar 9, 2015
    Messages:
    3,426
    Likes Received:
    2
    Trophy Points:
    38
    cPanel Access Level:
    DataCenter Provider
    Could use .cpphp so cpanel processes the file first and the php gets executed.

    You you have other options:

    You can just call your file

    .php
    .cpphp
    .phpcp
    .live.php

    Depending on what order you want the php engine to run and which engine you want to use.

    x3/test.live.php
    x3/test.php

    are good examples.

    The live one is inlined below:
    Code:
    <?php
    
    include("/usr/local/cpanel/php/cpanel.php");
    $cpanel = &new CPANEL();
    print_r  ( $cpanel->exec('<cpanel print="cow">') );
    print_r  ( $cpanel->exec('<cpanel Branding="file(local.css)">') );
    print_r  ( $cpanel->exec('<cpanel Branding="image(ftpaccounts)">') );
    print_r  ( $cpanel->api2('Email','listpopswithdisk',array ("acct"=>1) ) ) ;
    print_r  ( $cpanel->fetch('$CPDATA{\'DNS\'}') );
    print_r  ( $cpanel->api2('Ftp','listftpwithdisk',array ("skip_acct_types"=>'sub') ) ) ;
    
    $cpanel->end();
    
    ?>
    
     
  3. ispro

    ispro Well-Known Member

    Joined:
    Apr 8, 2004
    Messages:
    628
    Likes Received:
    1
    Trophy Points:
    18
    Nick, I'm trying hard to find a proper way to replace MX entries with my own (cPanel11 plugin in PHP) and still out of luck.

    I've renamed my index.php to index.live.php to be able to call cPanel via /usr/local/cpanel/php/cpanel.php (I may call listmxs via $cpanel->api2, but how may I set my own or remove existing?..) but I suffer from lack of documentation on cpanel.net. It looks to be OK from the first sight, but in fact there are too few entries, etc.

    Could you help me a little or forward to proper direction?
     
  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
    Given that documentation for these APIs is still a work in progress, one way I find the API calls I need is to look at the source code for the x3 theme. The x3 theme is stored at:

    /usr/local/cpanel/base/frontend/x3

    You will find the API2 call used for listing MX entries in the HTML page in the x3 interface that handles this functionality (.../frontend/x3/mail/mx.html) - which corresponds to the file: /usr/local/cpanel/base/frontend/x3/mail/mx.html

    The form at the top of the page calls a page for setting the MX entry when the form is submitted. In that file, you will find the following API1 call:

    Code:
    <cpanel Email="changemx($FORM{'domain'},$FORM{'mx'},$FORM{'priority'},$FORM{'alwaysaccept'})">
    Looking at the form and the parameters in this API1 call, it's fairly straightforward which parameters correspond to which portions of the form in the x3 interface:
    - The first parameter is simply the domain or subdomain you are setting the MX entry for.
    - The second parameter is what you are setting the MX entry to.
    - The third parameter is the priority number.
    - The final parameter is 1 if the server should always accept mail locally even if the primary mx does not point to this server - 0 otherwise.

    General rule of thumb is that :: indicates it's an API2 call and something="something" indicates it's an API1 call. In an API1 call, since the parameters aren't named - the order of the parameters is important.

    You can also analyze mx.html for the page that handles the removal of custom MX entries as well to see what API call it uses.
     
  5. ispro

    ispro Well-Known Member

    Joined:
    Apr 8, 2004
    Messages:
    628
    Likes Received:
    1
    Trophy Points:
    18
    I've looked at x3 theme already. But I was worried is it proper way to handle MX switch...
    The current call is still unoptimized but I will be required to use it as is...

    Dreaming about the day all (incl. internal!) WHM and cPanel actions will be done via API...
     
  6. cPanelNick

    cPanelNick Administrator
    Staff Member

    Joined:
    Mar 9, 2015
    Messages:
    3,426
    Likes Received:
    2
    Trophy Points:
    38
    cPanel Access Level:
    DataCenter Provider
    You can still call api1 functions thought he xml-api

    http://www.cpanel.net/plugins/xmlapi/cpanel.html


    /xml-api/cpanel?user=username&xmlin=<cpanelaction><module>Email</module><func>changemx</func><apiversion>1</apiversion><args>DOMAIN</args><args>MX</args><args>Priority</args></cpanelaction>

    or if 11.24+ you can do this (the above works on older versions as well)

    /xml-api/cpanel?cpanel_xmlapi_module=Email&cpanel_xmlapi_func=changemx&cpanel_xmlapi_apiversion=1&args-0=DOMAIN&args-1=MX&args-2=PRIORITY
     
Loading...

Share This Page