Results 1 to 10 of 10

Thread: create custom UI page

  1. #1
    Registered Member B12Org's Avatar
    Join Date
    Jul 2003
    Location
    Seattle Washington
    Posts
    694

    Default create custom UI page

    Hello,

    I want to create a custom page that is in the cpanel customer root screen that when clicked will allow me to call an external web service and based on that external call, display a form to the user to fill out and post, which then posts back to the original web service and then displays the results.

    I have the php code that will connect to the remote web service but I dont know how to get the cpanel variables to send to the web service:

    For example I need to know
    - which user they are logged in as
    - which domains that user has in their account

    I need to know those items before I can make the initial web service call as those items are used to retrieve the initial data set.

    TIA
    Enom ETP - If you need a reseller account (or retail) contact me!

  2. #2
    Integration Developer cPanelDavidN's Avatar
    Join Date
    Dec 2009
    Location
    Houston, TX
    Posts
    570

    Default

    Hi TIA,

    You're probably looking for Expression Variables (used in cpanel tags), ExpVarRef < DeveloperResources < TWiki. cPanel tags get parsed before the HTML, so it will be rendered as plain text. You can see their use scatter throughout the cPanel html pages (/usr/local/cpanel/base/frontend/x3 ; x3 is the default theme, yours may differ). You could use that when generating your links. I'm thinking specifically the $user variable and the $CPDATA{'DNS'} variable for the account username and the primary domain respectively.

    For more information about front-end development, head over to the Developer Resources page, Developer Resources

    If you require a list of all domain information(like subdomains, parks and addons), then you can include that information within your link or you could have your remote web app get the info from the cPanel system (provide you have root or proper reseller privileges).

    A) If you want to get the info and include in link:
    - you'll have to perform three different API2 calls to get the various types of domains possible within cPanel:
    ApiAddonDomain < ApiDocs/Api2 < TWiki
    ApiPark < ApiDocs/Api2 < TWiki
    ApiSubDomain < ApiDocs/Api2 < TWiki

    B) If you want to remotely fetch the data for the particular user, use the xml-api:
    -You'll make the same API2 calls above, but using the xml-api HTTP query mechanism, CallingAPIFunctions < AllDocumentation/AutomationIntegration < TWiki . This type of polling is very common; we have a PHP client class that simplifies the authentication and formatting the query string. It's use is heavy documented in the forums, but feel free to ask specific questions.

    ALTERNATIVELY:
    You could use CpanelPHP for you cPanel custom page, which has some basic documentation here, CpanelPhp < AllDocumentation/AutomationIntegration < TWiki . One thing the document is not clear on is you must have your files in a theme directory (or any descending directory within a theme). Probably the best way to explain how CpanelPHP is by example. You can look at /usr/local/cpanel/base/frontend/x3/test.cpphp and then example what it renders by logging into a cPanel account and navigating to $yourserver:2083/frontend/x3/test.cpphp . And like the document says, you can have just the .php extension and the behavior is the same

    Regards,
    -DavidN
    David Neimeyer
    Integration Developer

    sdk.cpanel.net
    APIs: XML-API API1 & API2
    Check Out: Developer Downloads Integration Blog
    Need Support? Support Ticket Developer Forum Feature Requests

  3. #3
    Registered Member B12Org's Avatar
    Join Date
    Jul 2003
    Location
    Seattle Washington
    Posts
    694

    Default

    Hi,

    So if I wanted to get the logged in username and pass that to a php function I would do:

    <?php

    $username = "<cpanel print="$user"> ";

    ?>

    is that right?


    How would I access package variables - such as how many pop accounts or email forwarding accounts they can have?
    Enom ETP - If you need a reseller account (or retail) contact me!

  4. #4
    Integration Developer cPanelDavidN's Avatar
    Join Date
    Dec 2009
    Location
    Houston, TX
    Posts
    570

    Default

    TIA,

    Yes, you're correct, you can do that. Remember, for that info to be parse prior to PHP parsing, your file will need to live in some place like /usr/local/cpanel/base/frontend/x3/youfilehere.php

    Only theme directories and their descendant directories get parsed like this. I've seen some suggestions to make symbolically link in the theme directory to those files (where ever they exist on the file system). If you do that it will still parse correctly, BUT if that directory happens to be served path in its self, say the /usr/local/cpanel/base/3rdparty/, someone could manually hit the CpanelPHP style page and it will either not parse correctly or possibly render the file's code as text. So, keep that caveat in mind.

    As for obtaining stats info on pop and forwarders, you can use the API2 StatsBar::stat, documented here.

    If you plan to get that info on the cPanel/CpanelPHP page, the you should use a <?cp ?> tag, documented here, or a <?cptt ?> tag, documented here.

    Below are the results, but I just used the xml-api to source the data; The data is the same, if you use the cp or cptt your data will be in a hash instead of XML (you will parse the hash with template directives as outlined in the documentation).
    My example account has unlimited pop and forwarders and it currently has 2 pop and 1 forwarder in use.
    Code:
    URL: https://10.1.1.1:2083/xml-api/cpanel
    DATA: display=emailaccounts%7Cemailforwarders&cpanel_xmlapi_user=dave&cpanel_xmlapi_module=StatsBar&cpanel_xmlapi_func=stat&cpanel_xmlapi_apiversion=2
    
    RESPONSE:
       <cpanelresult>
        <apiversion>2</apiversion>
        <data>
          <name>emailaccounts</name>
          <_count>2</_count>
          <_max>unlimited</_max>
          <_maxed>1</_maxed>
          <count>2</count>
          <feature>popaccts</feature>
          <id>emailaccounts</id>
          <item>Email Accounts</item>
          <langkey>INDXEmailAccounts</langkey>
          <max>unlimited </max>
          <module>Email</module>
          <percent>0</percent>
          <percent10>0</percent10>
          <percent20>0</percent20>
          <percent5>0</percent5>
          <zeroisunlimited>0</zeroisunlimited>
        </data>
        <data>
          <name>emailforwarders</name>
          <_count>1</_count>
          <_max>unlimited</_max>
          <_maxed>1</_maxed>
          <count>1</count>
          <id>emailforwarders</id>
          <item>Email Forwarders</item>
          <langkey>INDXEmailFowarders</langkey>
          <max>unlimited </max>
          <module>Email</module>
          <percent>0</percent>
          <percent10>0</percent10>
          <percent20>0</percent20>
          <percent5>0</percent5>
          <zeroisunlimited>1</zeroisunlimited>
        </data>
        <event>
          <result>1</result>
        </event>
        <func>stat</func>
        <module>StatsBar</module>
        <postevent>
          <result>1</result>
        </postevent>
        <preevent>
          <result>1</result>
        </preevent>
      </cpanelresult>
    Regards,
    -DavidN
    David Neimeyer
    Integration Developer

    sdk.cpanel.net
    APIs: XML-API API1 & API2
    Check Out: Developer Downloads Integration Blog
    Need Support? Support Ticket Developer Forum Feature Requests

  5. #5
    Registered Member B12Org's Avatar
    Join Date
    Jul 2003
    Location
    Seattle Washington
    Posts
    694

    Default

    David,

    What did you run in order to get that Xml data in your page?

    I did this basic test

    PHP Code:
    <cpanel setvar="dprefix=../">
    <cpanel Branding="include(stdheader.html)">

        <?php

            $username 
    "<cpanel print=\"$user\">"
            echo 
    "user = " $username "<br /><br /><br />";

            if(isset(
    $_POST["action"]) && $_POST["action"] == "go")
            {
                
    $html $_POST["html"];
                echo 
    "You posted!<br />" $html
            
    }
        
    ?>

        <FORM action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
            <input type="hidden" name="action" value="go" />
            <textarea name="html"></textarea><br />
            <input type="submit" name="Submit" value="Submit" />
            <br />
         </FORM>

    <cpanel Branding="include(stdfooter.html)">
    and put it in
    /usr/local/cpanel/base/frontend/x3/test2.php

    then going to
    http://10.10.10.10:2082/cpsess798783...d/x3/test2.php

    just shows a blank page.
    How do I get it to actually write the data?

    Additionally if I only enter a single echo line

    PHP Code:
    <?php
    echo "AAA";
    ?>
    it still displays an empty page, so I think something isnt quite right.
    Last edited by B12Org; 08-20-2010 at 05:46 PM.
    Enom ETP - If you need a reseller account (or retail) contact me!

  6. #6
    Registered Member mbd5882's Avatar
    Join Date
    Apr 2005
    Location
    Manchester, United Kingdom
    Posts
    60
    cPanel/WHM Access Level

    Root Administrator

    Default

    I don't know anything about cpanel UI and stuff, but I know a lot about PHP. Could the blank page be cpanels way of saying there is a PHP error? You missed out a ; in your code.
    Code:
    <cpanel setvar="dprefix=../">
    <cpanel Branding="include(stdheader.html)">
    
    	<?php
    
    		$username = "<cpanel print=\"$user\">"; 
    		echo "user = " . $username . "<br /><br /><br />";
    
    		if(isset($_POST["action"]) && $_POST["action"] == "go")
    		{
    			$html = $_POST["html"];
    			echo "You posted!<br />" . $html;
    		}
    	?>
    
    	<FORM action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
    		<input type="hidden" name="action" value="go" />
    		<textarea name="html"></textarea><br />
    		<input type="submit" name="Submit" value="Submit" />
    		<br />
    	 </FORM>
    
    <cpanel Branding="include(stdfooter.html)">

  7. #7
    Integration Developer cPanelDavidN's Avatar
    Join Date
    Dec 2009
    Location
    Houston, TX
    Posts
    570

    Default

    Hi TIA,

    That's curious that a simple, lone, echo statement in a PHP file doesn't render for you. Do you get any messages in /usr/local/cpanel/logs/error_log ?

    And mbd5882 is right. You're missing a semi-colon line terminator. Also, you don't need to escape you double quotes that demarcate the value being passed into the cpanel functions (in the cpanel tag). The reason why: the page will be parsed for the cpanel tag, the tag will be evaluated all on it's own and the quotes that encompass the cpanel tag are not relevant at that point. Once the tag is evaluated the result literally replaces the whole cpanel tag. After that, Apache will parse the page (with the PHP engine).

    Here's the refined example that rendered properly for me:
    Code:
    <cpanel setvar="dprefix=../">
    <cpanel Branding="include(stdheader.html)">
    
        <?php
    
            $username = "<cpanel print="$user">";
            echo "user = " . $username . "<br /><br /><br />";
    
            if(isset($_POST["action"]) && $_POST["action"] == "go")
            {
                $html = $_POST["html"];
                echo "You posted!<br />" . $html;
            }
      
      ?>
    
        <FORM action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
            <input type="hidden" name="action" value="go" />
            <textarea name="html"></textarea><br />
            <input type="submit" name="Submit" value="Submit" />
            <br />
         </FORM>
    
    <cpanel Branding="include(stdfooter.html)">

    Regards,
    -DavidN
    David Neimeyer
    Integration Developer

    sdk.cpanel.net
    APIs: XML-API API1 & API2
    Check Out: Developer Downloads Integration Blog
    Need Support? Support Ticket Developer Forum Feature Requests

  8. #8
    Registered Member B12Org's Avatar
    Join Date
    Jul 2003
    Location
    Seattle Washington
    Posts
    694

    Default

    /usr/local/cpanel/base/frontend/x3/test2.php
    now contains

    PHP Code:

    <cpanel setvar="dprefix=../">
    <cpanel Branding="include(stdheader.html)">

        <?php

            $username 
    "<cpanel print="$user">";
            echo 
    "user = " $username "<br /><br /><br />";

            if(isset(
    $_POST["action"]) && $_POST["action"] == "go")
            {
                
    $html $_POST["html"];
                echo 
    "You posted!<br />" $html;
            }
      
      
    ?>

        <FORM action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
            <input type="hidden" name="action" value="go" />
            <textarea name="html"></textarea><br />
            <input type="submit" name="Submit" value="Submit" />
            <br />
         </FORM>

    <cpanel Branding="include(stdfooter.html)">
    I also copied that file into
    /usr/local/cpanel/base/frontend/x3/test2.html

    The php page renders as blank page from the URL
    https://10.10.10.10:2083/cpsess78474...d/x3/test2.php

    The html version does render correctly, however when you click submit it fails badly
    https://10.10.10.10:2083/cpsess78474.../x3/test2.html
    when posted redirects to
    https://10.10.10.10:2083/cpsess78474...end/x3/%3C?php echo $_SERVER['PHP_SELF']; ?>

    I do notice that the rendered page looks like this
    PHP Code:

    <!-- END stdheader.html -->

        <?php

            $username 
    "muuser1";
            echo 
    "user = " $username "<br /><br /><br />";

            if(isset(
    $_POST["action"]) && $_POST["action"] == "go")
            {
                
    $html $_POST["html"];
                echo 
    "You posted!<br />" $html;
            }
      
      
    ?>

        <FORM action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
            <input type="hidden" name="action" value="go" />
            <textarea name="html"></textarea><br />
            <input type="submit" name="Submit" value="Submit" />
            <br />
         </FORM>

    <!-- START stdfooter.html -->
    So it doesnt seem that the php tags are pre-processed but are just directly rendered as text - both in .php or in .html version of the page.

    Am i missing something simple here??
    Enom ETP - If you need a reseller account (or retail) contact me!

  9. #9
    Registered Member B12Org's Avatar
    Join Date
    Jul 2003
    Location
    Seattle Washington
    Posts
    694

    Default

    Fixed this, apparently php itself wasnt working becuse it was missing the mysqlclient15 libs - installing the RPM package mysqlclient15 solved the problem.
    Enom ETP - If you need a reseller account (or retail) contact me!

  10. #10
    Registered Member cPanelKevin's Avatar
    Join Date
    Jan 2008
    Posts
    47

    Default

    Great, glad you got it working.
    cPanel University:cPanel Technical Certification
    For hands-on assistance please reference our support information center: Where should I go for support?
    cPResources: Support Options - Extra Support Options - Forums Search - Mailing Lists - Documentation

Similar Threads

  1. Replies: 2
    Last Post: 06-07-2011, 11:26 PM
  2. Custom suspension page
    By broncha in forum cPanel & WHM Discussions
    Replies: 3
    Last Post: 05-11-2009, 11:31 AM
  3. custom login page...
    By dipp02 in forum cPanel Developers
    Replies: 14
    Last Post: 11-01-2008, 10:25 AM
  4. Custom page for new accounts
    By Wicked in forum cPanel & WHM Discussions
    Replies: 3
    Last Post: 01-20-2007, 06:54 AM
  5. Custom 401 page
    By teammpp in forum cPanel & WHM Discussions
    Replies: 4
    Last Post: 12-18-2005, 06:39 PM
bargain