loading/creating modules for cpanel

creos

Active Member
May 11, 2003
36
0
156
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:
 

tAzMaNiAc

Well-Known Member
Feb 16, 2003
558
0
166
Sachse, TX
Originally posted by creos
Anyone have any ideas?

Thanks

cPanel.net Support Ticket Number:
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:
 

rbrown

Active Member
Jun 11, 2003
35
0
156
Originally posted by creos
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:
[...]


Pretty straightforward...

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.

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.

[email protected] [~]# 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.
[email protected] [~]#

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?
 

rbrown

Active Member
Jun 11, 2003
35
0
156
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!