back       next

Perl

IP range to CIDR conversion

I've often had to convert IP range with netmask to a CIDR notation. Below is a quick perl script to help with the conversion:

#!/usr/bin/perl -w
# range2cidr.pl

use Net::CIDR;
use Net::CIDR ':all';

if (@ARGV == 0) {
  die "Usage Example: $0 192.168.0.0-192.168.255.255 \n";
}

print join("\n", Net::CIDR::range2cidr("$ARGV[0]")) . "\n";

Installing Bugzilla on an ISPConfig site

These are some notes I had taken down during the installation of Bugzilla on a server with ISPConfig hosting control panel:

Requirements:

# yum install mysql-devel gd-devel libpng-devel libjpeg-devel freetype-devel libdbm-devel
# rpm -e mod_perl #else mod_perl2 does not install.

Create Site:

Site was created via the ISPConfig control panel with "web6_bugs" as the admin user and "web6" as the group.

Install:

$ cd /var/www/web6
$ wget http://ftp.mozilla.org/pub/mozilla.org/webtools/bugzilla-3.0.tar.gz
$ tar -xvzf buzilla-3.0.tar.gz
$ mv buzilla-3.0/* web
$ ./checksetup.pl --check-modules
# perl -MCPAN -e 'install AppConfig' #had to force install.
# perl -MCPAN -e 'install Bundle::Bugzilla'
# perl -MCPAN -e 'install GD'  #requires libpng-devel, libjpeg-devel, freetype-devel
$ ./checksetup.pl #Edit the localcofig with the correct database settings.
$ ./checksetup.pl #Re-run anytime if needed, specifically if the file permissions are not correct.
$ chgrp -R apache . #Had to make all files belong to the apache group after re-running checksetup.pl .

Apache with mod_perl need the below directives in httpd.conf:

    PerlSwitches -I/var/www/web6/web -w -T
    PerlConfigRequire /var/www/web6/web/mod_perl.pl

Runs a lot faster, but is a memory hog. Suggested to turn off KeepAlive in apache when running mod_perl.

Crontab Entry:

# Bugzilla
5 0 * * * web6_bugs cd /var/www/web6/web; ./collectstats.pl
55 0 * * * web6_bugs cd /var/www/web6/web; ./whineatnews.pl
*/45 * * * * web6_bugs cd /var/www/web6/web; ./whine.pl

Howto check and install missing perl modules...

  • Check if module is installed. Errors mean missing module.
    # perl -MModule::Name -e 1
    
  • See documentation of the module if installed.

    # perldoc Module::Name
    
  • Open CPAN shell:

    # perl -MCPAN -e shell
    
  • To reconfigure the shell if needed.

    cpan>o conf init
    
  • Install an available module.

    cpan> install Module::Name
    
  • Force install if test fails.

    cpan> force install Module::Name
    
  • To manual install perl modules.

    # perl Makefile.PL
    # make
    # make test
    # make install
    

Web Client Programming with Perl - Automating Tasks on the Web

An excellent free ebook which imparts knowledge on how the Web technically works and how to write software that is more flexible, dynamic, and powerful than the typical web browser using perl and perl tk. The goal is to give you the ability to retrieve, manipulate, and redistribute web-based information in an automated fashion.

Server Environment Variables

One of the methods that the web server uses to pass information to a cgi script is through environmental variables. These are created and assigned appropriate values within the environment that the server spawns for the cgi script. They can be accessed as any other environmental variable, like with %ENV{'VARIABLE_NAME'} (in Perl). Many of them, contain important information, that most cgi programs need to take into account.

To get a list of such environment variables, use the below script:

#!/usr/bin/perl
foreach $value(keys %ENV) {
  print "$value: $ENV{$value}\n";
}
exit;

Perl Compatible Regular Expressions Manual

PCRE was originally written for the Exim MTA, but is now used by many high-profile open source projects, including Python, Apache, PHP, KDE, Postfix, Analog, and nmap. Other interesting projects using PCRE include Ferite, Onyx, Hypermail, and Askemos.

CGI:IRC

CGI:IRC - is a Perl/CGI program that lets you access IRC from a web browser, it is designed to be flexible and has many uses such as an IRC gateway for an IRC network, a chat-room for a website or to access IRC when stuck behind a restrictive firewall.

ShopCMS Paypal Shopping Cart

ShopCMS Paypal Shopping Cart is a catalog manager and shopping cart that features two levels of categories, a collapsible navigation menu, full PayPal integration, customizable templates with detailed style sheets, a WYSIWYG HTML editor for product info, compatibility with most Web servers and operating systems, and support for mod_perl. It handles image uploading and cloning of existing Items, includes a browser-based administration control panel, and ranks popular products.

FuzzyMonkey's Web Scripts...

FuzzyMonkey.org - Great resource for free cgi scripts which includes: Photo Gallery, Classifieds, Address Book, Web Board, Survey etc...

Perl one liners...

Here are ten one liners in perl, illustrating the kinds of task one would use a script for under linux. All the scripts take some kind of argument after the final ' quote that signals the end of the program.

1. perl -p -i -e 's/this/that/g' filename

Search and replace the string 'this' with the string 'that' in the file filename. You can also say * or *.html or any valid wildcard expression instead of filename. The s/// command uses regular expressions. If you want to alter the 'this' and 'that', it's best to avoid .*?[ ]{}$^ and other odd characters which act as metacharacters in regular expressions. Or better still look at the perlre documentation page. You can do this by saying perldoc perlre. Perl has extensive online documentation, try perldoc perltoc for a list.

Syndicate content