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.

problems getting a custom cpanel script to work

Discussion in 'General Discussion' started by sceilig, Jul 4, 2005.

  1. sceilig

    sceilig Member

    Joined:
    Oct 1, 2004
    Messages:
    8
    Likes Received:
    0
    Trophy Points:
    1
    have written a perl script that adds info to the apache httpd.conf file on a linux server. It runs fine from the command line when logged in as root, but I want to be able to run this file from a web browser. I have Cpanel installed on the server - cpanel has its own way of "remotely" allowing you to Create and Delete Accounts etc from a web browser using its Accounting module.
    http://www.cpanel.net/remoteaccess-php.html

    I made a copy of the accounting module file, and added my own function to it, using the cpanel format as a test to just add a line of text to a sample file owned by root.

    Here is an example of one of Cpanels functions
    PHP:
    function createacct ($host,$user,$accesshash,$usessl,$acctdomain,$acctuser,$acctpass,$acctplan) {
         
    $result whmreq("/scripts/wwwacct?remote=1&nohtml=1&username=${acctuser}&password=${acctpass}&domain=${acctdomain}&plan=${acctplan}",$host,$user,$accesshash,$usessl);
         if (
    $cpanelaccterr != "") { return; }
         return 
    $result;
    }
    Here is mine:
    PHP:
    function testscript ($host,$user,$accesshash,$usessl) {
            
    $result whmreq("/scripts/testscript",$host,$user,$accesshash,$usessl);
            if (
    $cpanelaccterr != "") { return; }
            return 
    $result;
    }
    Both functions execute a perl script located in the scripts folder. Mine is executable and as i say, works fine from the command line. Also I can run their functions just fine like creating an account.

    Any ideas why it doesnt work? Do I need to register my script with cpanel, or do they have a list of authorized 3rd party scripts that can be run through port 2086 in their whmreq script? Or does anyone have another idea how to do what i want to do?

    This is all that is in my script
    ----------------------------------------------------------
    #!/usr/bin/perl

    system (`echo "hello world" >> "/etc/testfile"`);
    ----------------------------------------------------------
     
  2. lankyb

    lankyb Well-Known Member

    Joined:
    Sep 21, 2004
    Messages:
    99
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    Peterborough, UK
    i'm new to perl programming, but don't you need to use the command 'Print' instead of 'System'. Print will show it within HTML, but Sytem would make it print to the actually system; behind the scenes?

    It would make sense why you can see it SSH, and not from the WHM.

    ---------------------------------

    You also do not need to do any special to use your script, apart from having a license itself to run cPanel :)
     
  3. sceilig

    sceilig Member

    Joined:
    Oct 1, 2004
    Messages:
    8
    Likes Received:
    0
    Trophy Points:
    1
    Thanks for the response. What the system call is doing is executing a command - the command being an echo call of some text that then gets redirected to be appended as a line at the bottom of my test file. So there is nothing being printed to the screen. However, I have added a simple print "hello world"; to see if that shows up when I execute my custom function above, but it doesnt show up.....it does of course if I execute the script from SSH?

    Ive even tried to make this simpler by accessing the script thru a http call.

    http://SERVERIP:2086/scripts/testscript

    And in the test perl script to just have a print statement
    print "hello world";

    However, the browser returns a blank page (not a page not found)?

    I know that the url format is correct since this works
    http://SERVERIP:2086/scripts/editdnslist

    What do I need to do to make my script at least execute and print something to the browser?
     
  4. lankyb

    lankyb Well-Known Member

    Joined:
    Sep 21, 2004
    Messages:
    99
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    Peterborough, UK
    This is what i have found out, you do not need ANY of the remote access stuff IF you are making a module for/inside cPanel or WHM... that stuff is only needed when you are connecting outside cPanel's stuctures. (Does make sense, i should have caught onto that MUCH sooner!).

    Now i do not know that much about programming in php or perl, only very little. I could not find a way of running perl scripts and showing the results afterwards... i know its possible because i have seen scripts do it before.

    Instead i made a very simple php script that created a file called testfile.ini in the /var/ folder.

    PHP:
    <?php 

    $Handle 
    fopen '/var/testfile.ini' 'w' ) ;
              
    fputs $Handle "This is a test" ) ;
              
    fclose $Handle ) ;
    ?>

    <Html>
     <head>
     </head>
     <body>
      HELLO! <br><br> Please now check to see if a file has been called /var/testfile.ini, if so you have made for first POINTLESS script of WHM! <br><br>:-D
     </body>
    I placed this within the /usr/local/cpanel/whostmgr/docroot/ folder.... and it worked a treat. You simply went to http://SERVERIP:2086/testscript.php, and it did everything it was asked to do. And from looking at the fantastico coding (or from what i can see), you can collect variables from cPanel like this:

    PHP:
    $HomePath '<cpanel print="$homedir">';
    So pretty much the same way as the skins. Hopefully this would be some use to you :)
     
  5. sceilig

    sceilig Member

    Joined:
    Oct 1, 2004
    Messages:
    8
    Likes Received:
    0
    Trophy Points:
    1
    Thanks a million lankyb. That did the trick. I never thought of putting my script into the whm directory.

    Thanks again - saved me a bit of time in not having to figure out the other route I was going down.
     
Loading...

Share This Page