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.

WHM Plugin Integration (PHP)

Discussion in 'cPanel Developers' started by nickp666, May 31, 2007.

  1. nickp666

    nickp666 Well-Known Member

    Joined:
    Jan 28, 2005
    Messages:
    770
    Likes Received:
    2
    Trophy Points:
    18
    Location:
    /dev/null
    I'm working on a few scripts and interfaces for common (and quite often mundane) tasks such as editing the default page that shows up when users visit the hostname, the default suspended page etc & panels for editing the localdomains/staticroutes/alwaysrelay/secondaymx & remotedomains files which I will be launching as open source.

    I am a PHP developer and have no prior experience with perl, I've read webignitions HOWTO (Thank you - very informative) which works fine for running PHP scripts in WHM however there is one thing I cannot work out and was wondering if anyone could shed some light on it.

    I basically want to plug the PHP files straight into WHM's interface under the 'plugins' section, I had a dig around and couldnt find a way to do it, and thanks to looking at some of chirpys interfaces for his products I knocked up a stupidly simple perl interface (That simply writes out HTML) with buttons to launch the PHP files, but to be honest I think that it would be far better properly integrated straight into WHM rather than having to launch a perl script just to write out some HTML, is there a simple way to plug PHP plugins into WHM or shall I just stick with the perl launcher? TIA
     
  2. Spiral

    Spiral BANNED

    Joined:
    Jun 24, 2005
    Messages:
    2,023
    Likes Received:
    7
    Trophy Points:
    0
    nickp666, I was just wondering if you were aware that PHP is a shell scripting language
    just like Perl and can perform the exact same functions as Perl scripts?

    Many people forget or don't realize that PHP also has a command line side
    and is also a powerful shell scripting language above and beyond the web stuff
    that people are normally used to.

    I bring up this point because anywhere you can write a Perl script, you could just
    as easily write a PHP script and call the script directly with bang headers just
    like you would have in Perl or any other language.

    Code:
    #!/usr/bin/php
    <?php
      //whatever code
    ?>
    
    Related page that might be helpful ...

    http://us2.php.net/manual/en/features.commandline.php
     
  3. nickp666

    nickp666 Well-Known Member

    Joined:
    Jan 28, 2005
    Messages:
    770
    Likes Received:
    2
    Trophy Points:
    18
    Location:
    /dev/null
    Thankyou for the headsup but yeah I was aware of that and do use it in that context, this thread was litterally for integrating php scripts into WHM's plugins section, which I have no clue how to do without a perl script to present links to the user.
     
  4. twhiting9275

    twhiting9275 Well-Known Member

    Joined:
    Sep 26, 2002
    Messages:
    538
    Likes Received:
    15
    Trophy Points:
    18
    cPanel Access Level:
    Root Administrator
    Twitter:
    It's actually not that hard to do this. I'll provide an example of some code I was working on for an ASSP installer/updater/etc, you can tweak what you need to.

    Firstly, in /usr/local/cpanel/whostmgr/docroot/cgi , create a file called addon_youraddon.cgi , something like

    Code:
    #!/usr/local/bin/perl
    #change below  line for your actual title!
    #WHMADDON:ASSP:ASSP for CPanel
    BEGIN {
       push(@INC,"/usr/local/cpanel");
       push(@INC,"/usr/local/cpanel/whostmgr/docroot/cgi");
    }
    
    use File::Find;
    use whmlib;
    use Cpanel::PwCache qw(pwcheckos pwclearcache getpwent endpwent);
    use Sys::Hostname qw(hostname);
    use Cpanel;
    use Cpanel::Carp;
    use Cpanel::cPanelFunctions ();
    pwcheckos();
    
    require 'parseform.pl';
    
    ###############################################################################
    # start main
    use SafeFile;
    
    my %FORM = parseform();
    
    
    if (!$ACL{all}) {
    print "Content-type: text/html\r\n\r\n";
            print "You do not have access to modify ASSP. Shoo, go away.\n";
            exit();
    
    }
    else
    {
    print "Content-Type: text/html\n\n";
    print "<meta http-equiv=\"refresh\" content=\"0;url=/cgi/assp/index.php\"/>" ;
    }
    
    Save the file, make sure it's a+rx, and you're good to go
    Now, notice how the page is automatically redirected to /cgi/assp/index.php? Just call your own page from there, modify the rest of the perl script to do what you want it to.
     
  5. ackava

    ackava Registered

    Joined:
    Feb 8, 2008
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    1
    Well this looks like you have to code everything here, well can you tell me how do you reference the url? just straight to the cgi file?

    If i want to write down perl script in inline like...

    <?cp


    ... perl code


    ?>


    This isnt working, is there anyone who can tell me how can we embed perl script in it?
     
Loading...

Share This Page