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.

loading/creating modules for cpanel

Discussion in 'General Discussion' started by creos, Jul 6, 2003.

  1. creos

    creos Active Member

    Joined:
    May 11, 2003
    Messages:
    36
    Likes Received:
    0
    Trophy Points:
    6
    Location:
    San Jose, CA
    http://www.cpanel.net/Modules-HOWTO.txt is great. Also /usr/local/cpanel/Cpanel/*

    I've created a simple module but for the life of me it doesn't work. I'm sure i'm overlooking something extremely simple.. & generally another set of eyes can spot this type of brain freeze pretty quickly.

    So, here's the module:

    netTools.pm

    #!/usr/bin/perl

    package Cpanel::netTools;

    use strict;
    use Carp;

    use vars qw(@ISA @EXPORT $VERSION);

    require Exporter;
    require DynaLoader;
    @ISA = qw(Exporter DynaLoader);
    @EXPORT = qw(netTools_init netTools_DomWhois);

    $VERSION = '1.0';

    require 5.004;

    sub netTools_init {
    return;
    }


    sub netTools_DomWhois {

    $whois = "/usr/bin/whois";

    my ($domain) = @_;
    $domain =~ s/[\|\\\/\!\@\#\$\%\^\&\*\(\)\[\]\{\}\;\:\'\"\+\=\_\?\,]//isg;

    $result = `$whois $domain`;

    print "$result\n";


    }

    1;


    Pretty straightforward... just doing a whois lookup on the domain (after some basic error checking to make sure $domain doesn't contain unwanted chars) and printing the results.

    From the control panel side, I've created a form that passes $domain to dowhois.html which should actually output the results in pre tags:

    <cpanel netTools="DomWhois($FORM{'domain'})">

    I've verified that $domain is being passed by adding a <cpanel print="$FORM{'domain'}">) to my page. It has got to be a problem with the script.

    Any ideas? My only thought is that Cpanel isn't loading the module for some reason... I infer from the docs that it loads module on startup (initial startup or when cpaneld launches for the user?) & I've tried /usr/local/cpanel/startup & /scripts/reswhosmgr to no avail.

    Thanks

    cPanel.net Support Ticket Number:
     
  2. creos

    creos Active Member

    Joined:
    May 11, 2003
    Messages:
    36
    Likes Received:
    0
    Trophy Points:
    6
    Location:
    San Jose, CA
    Anyone have any ideas?

    Thanks

    cPanel.net Support Ticket Number:
     
  3. tAzMaNiAc

    tAzMaNiAc Well-Known Member

    Joined:
    Feb 16, 2003
    Messages:
    559
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    Sachse, TX
    service cpanel3 restart ? :)

    I dunno, this is the first I've heard of this, and now I've got ideas. Oh boy. :)

    cPanel.net Support Ticket Number:
     
  4. rbrown

    rbrown Active Member

    Joined:
    Jun 11, 2003
    Messages:
    35
    Likes Received:
    0
    Trophy Points:
    6
    Whoa, you're way off.

    1) You never need to "restart" anything when dealing with cpanel modules, because everything is loaded automagically on every hit from the browser.

    2) You should probably try to make sure it at least compiles first before wondering why cpanel has trouble loading it.

    root@vpanel [~]# perl -I/usr/local/cpanel -MCpanel::netTools -e ''
    Global symbol "$whois" requires explicit package name at /usr/local/cpanel/Cpanel/netTools.pm line 25.
    Global symbol "$result" requires explicit package name at /usr/local/cpanel/Cpanel/netTools.pm line 30.
    Global symbol "$whois" requires explicit package name at /usr/local/cpanel/Cpanel/netTools.pm line 30.
    Global symbol "$result" requires explicit package name at /usr/local/cpanel/Cpanel/netTools.pm line 32.
    Compilation failed in require.
    BEGIN failed--compilation aborted.
    root@vpanel [~]#

    3) For security reasons, you should probably fix that domain regex to only keep what you DO want instead of trying to pick out possible offending characters. i.e.:

    $domain =~ s/[^a-z0-9\-\.]//i;

    Specifically, you shouldn't wipe the "\-" because many domain have a dash, eh?
     
  5. rbrown

    rbrown Active Member

    Joined:
    Jun 11, 2003
    Messages:
    35
    Likes Received:
    0
    Trophy Points:
    6
    Oops forgot the "g". What I meant was for security reasons you should use THIS instead:

    $domain =~ s/[^a-z0-9\-\.]//ig;

    BTW, the new cpanel 8.8.0-EDGE_132 now has excellent error reporting. Try this:

    tail -f /usr/local/cpanel/logs/error_log

    and you'll probably see exactly what the problem is. So easy to write your own modules now!
     
Loading...

Share This Page