[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6. Scripting

Developing Perl scripts for Impost

Impost uses Perl as a scripting engine. Perl is very common on most systems and is very easy to learn. When making a script to control Impost's behaviour for client / server communication, every script is required to have these 2 sub routines:


Without these sub routines, Impost will not function properly!

The 'on_server_accept' sub routine is called everytime a new connection is established. The function receives two arguments, $_[0] is the I.P. address of the connecting client, and $_[1] is the file descriptor pointing to the socket the connection is on.

This sub routine is mainly for telling Impost what to say to the client when the client first connects. Impost reads the array @welcome_message after the sub routine is evaluated by Perl and sends each item, if any, from @welcome_message to the newly connected client.

The 'on_server_read' sub routine is called everytime Impost receives data from the client. This function also receives only two arguments. The first, $_[0] is the data that has been received, and $_[1] is the file descriptor of the socket in which Impost received the data from. Impost will then read the array @reply_data from this routine after it is evaluated and sends the items from that array to the socket in which the data was received similar to the @welcome_message in the on_server_accept routine.

After the @reply_data array is read by Impost and all the data from the array is sent to the client, Impost checks if the variable $close_connection exists. If it does exist and the value is "1", Impost will close the socket disconnecting the client from the Impost server.

Any data outside of these two sub routines will be evaluated when the perl script is loaded, which is when Impost starts.

You can include as many sub routines as you please, however they will never be called directly from Impost. You'll only be able to call them from either 'on_server_accept' or 'on_server_read' or via the code which is evaluated when the script is loaded.

I have included a well documented example script, example1.pl, which is located in the scripts/ directory. There are several other scripts also included which mimic several popular daemons, these scripts could be useful for sitting ducks or they could provide you with ideas for your own scripts.

[ << ] [ >> ]           [Top] [Contents] [Index] [ ? ]

This document was generated by ziplock on August, 13 2004 using texi2html