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.

Custom Perl module - Access Mysql

Discussion in 'cPanel Developers' started by blaiseh, Oct 9, 2012.

  1. blaiseh

    blaiseh Registered

    Joined:
    Oct 9, 2012
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Root Administrator
    Hi,

    I'm currently trying to write a little module in perl (for use within my Cpanel template). It'll expose its function to API2.

    The module need to update datas in a MySQL table, but I can't figure out how to do this.. DBI is not available for custome perl module...

    Thanks for your help !
     
  2. cPanelDavidN

    cPanelDavidN Integration Developer
    Staff Member

    Joined:
    Dec 17, 2009
    Messages:
    571
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    correct. you will need to create your own solution.

    The simplest, most direct solution is to make a system call (i.e., open3, Cpanel::SafeRun::Full::run(), etc) that executes a standalone script. By doing that, you can execute a Perl script using the system Perl (which provides access to any module that happens to be installed).

    Depending on you exact situation, you might need/want to have an privilege escalation binary. This would provide the same thing as above: isolated process that can use system installed Perl and Perl modules.

    Regards,
    -DavidN
     
  3. blaiseh

    blaiseh Registered

    Joined:
    Oct 9, 2012
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Root Administrator
    Thanks for the advice ! Everything is not clear for me... I can call this function directly from template ? Or I have to create first an perl script that will be called from template and then call the Cpanel::SafeRun ?

    I tried this, without success:
    <?cp Cpanel::SafeRun::Full::run("perl test.pl") ?>
     
  4. cPanelDavidN

    cPanelDavidN Integration Developer
    Staff Member

    Joined:
    Dec 17, 2009
    Messages:
    571
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    you can not use that at the template level. If you create your own Perl module that exposes an API2 function, then you'd call your API2 function in the template...the Cpanel::SafeRun::Full::run() would be used somewhere in your module code.

    As documented in Full.pm, the input to run() is a hash, with several different keys. So the correct what to execute `perl test.pl` would be something like:
    Code:
    use Cpanel::SafeRun::Full ();
    
    my %input = (
        'program' => 'perl',
        'args'       => ['test.pl'],
    );
    
    my $result = Cpanel::SafeRun::Full::run(%input);
    
    
    Regards,
    -DavidN
     
  5. blaiseh

    blaiseh Registered

    Joined:
    Oct 9, 2012
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Root Administrator
    Thansk for your help David !
     
Loading...

Share This Page