Prototype Control.Modal widget

livepipeControl.Modal is a very high quality and easy to use widget that uses the Prototype javascript library to create various window, lightbox, dialog, and/or tooltips.  This is the second widget library that I have adopted in my arsenal of web widgets.  Thanks very much to Ryan Johnson for publishing this high quality widget and posting usage and API instructions on his web at http://livepipe.net.  The first time I used this widget, I needed to create a pop-up modal window that displayed detail lines about a particular row of data in a table.

Read more ...

How to insert or append text using a pattern match

There have been many times where I wanted to be able to insert or append new lines of text to a configuration and/or ini file based upon some pattern match. The challenge is inserting the text in the middle of the configuration file. It is rather simple to append to the end of the text file. You can do that simply by using cat or echo and redirecting the output using the >> to append it to the file of your choice. 

Using sed to insert/append text using a pattern match

Most recently I needed to do this to add the following two lines to the my.cnf MySQL configuration file:

user=mysqlbasedir=/opt/mysql

I needed these lines to be inserted into the my.cnf inside the [mysqld] section for two reasons:

  • force the mysqld server to be run as the user UNIX user 'mysql'
  • define the base directory for mysql since I installed in a non-standard directory.

Here is an example of the my.cnf configuration file:

# The following options will be passed to all MySQL clients
[client]
#password = your_password
port = 3306
socket = /tmp/mysql.sock

# Here follows entries for some specific programs

# The MySQL server
[mysqld]
port = 3306
socket = /tmp/mysql.sock
skip-locking

The best way for me to do this was to append the text just below that section heading. To do that, I used the following command sequence:

sed -e '/\[mysqld\]/a\
user=mysql\
basedir=\/opt\/mysql' my-large.cnf > my.cnf

This command "reads in" my-large.cnf and adds the text just below the [mysqld] section header and outputs the result to a new file called my.cnf. Below is the output of the new my.cnf file:

# The following options will be passed to all MySQL clients
[client]
#password = your_password
port = 3306
socket = /tmp/mysql.sock

# Here follows entries for some specific programs

# The MySQL server
[mysqld]
user=mysql
basedir=/opt/mysql
port = 3306
socket = /tmp/mysql.sock
skip-locking

That's all there is to that. This command sequence or snippet of code comes in handy when writing Solaris pkg postinstall scripts, where you frequently have to modify existing and/or default initialization scripts. You can also prepend text just above the pattern match my modifying the command slightly and using the i or insert command argument. So, to prepend the text just above the [mysqld] block the code would be:

sed -e '/\[mysqld\]/i\
user=mysql\
basedir=\/opt\/mysql' my-large.cnf > my.cnf

This command would yeild the following output:

# The following options will be passed to all MySQL clients
[client]
#password = your_password
port = 3306
socket = /tmp/mysql.sock

# Here follows entries for some specific programs

# The MySQL server
user=mysql
basedir=/opt/mysql
[mysqld]
port = 3306
socket = /tmp/mysql.sock
skip-locking

While there are many ways to do this in other scripting languages, I have always wanted to learn and remember how to do this with the simple sed editor. I hope this is useful to others.

IP Address conversions in perl

Here is a recipe for changing IPv4 addresses to decimal numbers using Perl.

#!/usr/bin/perl

# This is a simple script that interactively converts an IP address to
# its decimal equivalent. This can sometimes be used to bypass web content
# filtering devices as not all will convert the decimal to an IP and then a
# hostname.
#
# prompt for an IP
print "Enter an IP Address: ";

# get the users input
$_ = <STDIN>;

# remove the newline "\n" character
chomp($_);

# should validate the input, but this was a simple/quick program
$converteddecimal = ip2dec($_);
$convertedip = dec2ip($converteddecimal);

print "\nIP address: $_\n";
print "Decimal: $converteddecimal\n";

# print "IP: $convertedip\n";

# this sub converts a decimal IP to a dotted IP
sub dec2ip ($) {
    join '.', unpack 'C4', pack 'N', shift;
}

# this sub converts a dotted IP to a decimal IP
sub ip2dec ($) {
    unpack N => pack CCCC => split /\./ => shift;
}

Converting CIDR notation to decimal in perl

Recently I was given a file that contained a subnet address and CIDR mask, a decimal representing the number of Bits in the mask. I wanted to convert this to a pure decimal for facilitating in decimal comparisons to a different list of networks and/or subnets and masks. I used my dec2ip() function that was previously discussed in URL. To convert the # of bits in the CIDR mask, I needed to figure out how to do exponents in perl. The formula for converting a 32-bit mask for example is simply 2 to the 32nd power.

The Perl syntax for exponents is done through the use of the ** operator.

Thus for our example, suppose we need to get the decimal equivalent of a 24-bit mask, our formula would be as follows:

my $cidr_bits = 24;
my $mask_dec = 2 ** $cidr_bits;

# $mask_dec will be equal to 16777216

Building AMP stack on Solaris (part 2)

In this second part article, we make some suggestions on building some simple package files that will help in deploying the AMP stack that we have built. This article assumes that you have built all the packages in the first part of the article (with the exception of PHP). First, it is suggested that you create a packaging directory structure.

~/pkg
~/pkg/NLIlib
~/pkg/NLIsnmp
~/pkg/NLImysql
~/pkg/NLIhttp
~/pkg/NLIphp

Read more ...

Building the LAMP stack on Fedora

The purpose of this article is to document the steps taken to build the minimum LAMP stack for running Joomla. The first component of the LAMP stack is Linux, I started with Fedora 7, and upgraded it to Fedora 8 using Yum. So for the purposes of this exercise, use a Fedora 7 or newly installed Fedora 8 system. You should have the development tools, libraries, and headers installed as a prerequisite for the build process.

To build my system, I first build the latest and greatest openssl library so that we can build an Apache Httpd server that uses this most recent version of the library. At the time this article was written, Apache 2.2.6, OpenSSL 0.9.8g, MySQL v5.0.51, and PHP 5.2.5 were available.  Additionally, we’ll configure MySQL and PHP to use this newest version of the library.

OpenSSL 0.9.8g

Obtain the most recent version of the Openssl source tarball at http://www.openssl.org/source/

cd openssl*
./Configure –-prefix=/usr/local/openssl-0.9.8g shared zlib-dynamic linux-elf
make
make install
ln -s /usr/local/openssl-0.9.8g /usr/local/ssl 

Apache Httpd 2.2.6

Obtain the most recent version of the Apache httpd web server from http://httpd.apache.org. To compile the Apache web server to use our new openssl module, we pass it the --with-ssl=/usr/local/ssl directive. This points it to the symbolically linked version of the openssl package.

cd httpd*
./configure -–prefix=/usr/local/httpd-2.2.6 \
 --enable-modules=all \
 --enable-mods-shared=all \
 --enable-logio \
 --enable-proxy \
 --enable-deflate \
 --enable-ssl \
 --with-z=/usr/lib \
 --with-ssl=/usr/local/ssl 
make 
make install
ln -s /usr/local/httpd-2.2.6 /usr/local/apache2 

MySQL 5.0.51

Obtain the latest source code from http://www.mysql.com

cd mysql*
./configure --prefix=/usr/local/mysql-5.0.51 \
 --localstatedir=/usr/local/mysql-5.0.51/data \
 --disable-maintainer-mode \
 --with-mysqld-user=mysql \
 --with-unix-socket-path=/tmp/mysql.sock \
 --without-comment \
 --without-debug \
 --without-bench
make
make install
ln -s /usr/local/mysql-5.0.51 /usr/local/mysql 

PHP 5.2.5

Get the latest source from http://www.php.net

cd php*
./configure \
 --with-apxs2=/usr/local/httpd-2.2.6/bin/apxs \
 --with-mysqli=/usr/local/mysql-5.0.51/bin/mysql_config \
 --with-mysql=/usr/local/mysql-5.0.51 \
 --with-openssl=/usr/local/openssl-0.9.8g \
 --prefix=/usr/local/php-5.2.5 \
 --with-config-file-path=/usr/local/php-5.2.5/etc \
 --enable-force-cgi-redirect \
 --disable-cgi \
 --with-zlib \
 --with-gettext \
 --with-gdbm 
make
make install
ln -s /usr/local/php-5.2.5 /usr/local/php