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.

trying to call shell script with plugin

Discussion in 'cPanel Developers' started by sime, Jul 30, 2007.

  1. sime

    sime Active Member

    Joined:
    Oct 16, 2005
    Messages:
    35
    Likes Received:
    0
    Trophy Points:
    6
    After a lot of general rambling, the only thing I need to do with my cPanel 11 plugin is have it (or a .pm) call my shell script.

    Just to summarize my goals:
    -- the script should run as same user that is logged into cpanel.
    -- user should not need normal shell access to execute plugin.

    Any guidance appreciated.
    Simon
     
    #1 sime, Jul 30, 2007
    Last edited: Jul 30, 2007
  2. sime

    sime Active Member

    Joined:
    Oct 16, 2005
    Messages:
    35
    Likes Received:
    0
    Trophy Points:
    6
    I'm going for the .pm approach now, getting my head around how this all fits together.

    foo.pm
    Code:
    #!/usr/bin/perl
    use strict;
    use Carp;
    use vars qw(@ISA @EXPORT $VERSION) ;
    require Exporter;
    require DynaLoader;
    @ISA = qw(Exporter DynaLoader) ;
    @EXPORT = qw(foo_init foo_test) ;
    $VERSION = '1.0' ;
    
    sub foo_init (
      return 1;
    )
    
    sub foo_test {
      print "HELLO WORLD";
    }
    
    foo_exec.html
    Code:
    <cpanel setvar="headerimg=../images/topsubdomains.gif">
    <cpanel setvar="dprefix=../">
    <cpanel Branding="include(stdheader.html)">
    <div class="body-content">
    
      <cpanel foo="test()">
    <cpanel Branding="include(stdfooter.html)">
    

    My current error
    Code:
    Undefined subroutine &Cpanel::emsdi::emsdi_create called at (eval 63) line 1.
    	eval 'Cpanel::emsdi::emsdi_create(@RARGS);' called at cpanel.pl line 1316
    	main::exectag('<cpanel emsdi="create()">') called at cpanel.pl line 4330
    	main::dotag(undef) called at cpanel.pl line 4219
    	main::cpanel_parseblock('SCALAR(0x8ed41a8)') called at cpanel.pl line 4173
    	main::cpanel_parse('GLOB(0x90dc210)') called at cpanel.pl line 990
     
  3. sime

    sime Active Member

    Joined:
    Oct 16, 2005
    Messages:
    35
    Likes Received:
    0
    Trophy Points:
    6
    OK, that crap above is based on cpanel 10 examples (I guess). I modified my .pm file based on other pm files on the server and managed to get something to happen. Will follow up with working code.
     
  4. sime

    sime Active Member

    Joined:
    Oct 16, 2005
    Messages:
    35
    Likes Received:
    0
    Trophy Points:
    6
    howto skeleton plugin for cp11

    OK. This is minimum chips here. Execute a shell script as the cpanel user. This doesn't do anything in particular, however it is end-to-end so that we can understand a little of what is going on.

    Step 1 - Theme

    -- Use cPanel11 with x3 theme.

    Step 2 - Plugin

    -- Follow create plugin instructions
    -- Note: Check your plugin file before installing. You might need to fix the path to your .html file. I had to change the url: line to be url:foo/foo.html

    Step 3 - cPanel page

    -- put this file in cpanel /usr/local/cpanel/base/frontend/x3/foo/foo.html
    Code:
    <cpanel setvar="headerimg=../images/topsubdomains.gif">
    <cpanel setvar="dprefix=../">
    <cpanel Branding="include(stdheader.html)">
    <div class="body-content">
    
      <cpanel foo="bar()">
    
    </div>
    <cpanel Branding="include(stdfooter.html)">
    
    Step 4 - cPanel module

    -- put this file in /usr/local/cpanel/Cpanel/foo.pm

    Code:
    package Cpanel::emsdi;
    use lib '/usr/local/cpanel';
    use strict;
    use Carp                 ();
    
    our $VERSION = '1.0';
    
    require 5.004;
    
    sub foo_init { return 1; }
    
    sub foo_bar {
      system ("/scripts/foo.sh");
      return 1;
    }
    
    Step 5 - Script to execute

    -- put this file in /scripts/foo.sh
    -- change the permissions to 755 (not sure if there is a more secure way).
    Code:
    echo "HELLO WORLD"
    
     
  5. sime

    sime Active Member

    Joined:
    Oct 16, 2005
    Messages:
    35
    Likes Received:
    0
    Trophy Points:
    6
    Note. I have had permissions issues with calling a shell script in /scripts

    I think because my /scripts/path/to/script was not fully readable. I'm not a shell expert, I just thought I'd mention it.
     
    #5 sime, Aug 2, 2007
    Last edited: Aug 2, 2007
Loading...

Share This Page