Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

CGI Programming

by vroom (Pope)
on May 25, 2000 at 22:01 UTC ( #14835=sourcecodesection: print w/ replies, xml ) Need Help??
Find installed Perl interpreters (shell script!)
on Aug 01, 2002 at 13:22 UTC
by crenz

Okay -- this is a shell script, so there's not much to be learned in terms of perl programming. However, I think it can be very helpful if you have an account at one of those cheap providers that allow CGI, but no shell, and you have trouble finding all the perl interpreters and their library paths.

See a demo at http://www.web42.com/software/findperl/findperl.cgi

(Note to Editor: If you deem it inappropriate for perlmonks.com, please feel free to delete).

Perl2SMS (for Vodafone Australia)
on May 25, 2002 at 12:21 UTC
by hagus
This is some code I whipped up to automate the tedious process of using Vodafone.com.au's web2sms facility. Given an account on this site, you can use my script to send SMSs from the command line.

It might also serve as quick template code for anyone contemplating similar types of things. It fetches several URLs, stores cookies, handles redirects on POSTs, etc.

Required modules: LWP::UserAgent and friends, plus Crypt::SSLeay

Updated: Incensed by graff's critique, I raged through the house smashing crockery and garden gnomes. When the plaster dust had settled, I refactored the code into a nightmarish perl structure state machine. Muahahaha. (as opposed to the nightmarish if/then/else it was before).

Updated again: An exercise for the reader would be to introduce hooks that parse the HTML. At the moment if you don't successfully login, it silently fails. Hint: subclass HTML::Parse.

Autosubmit
on May 01, 2002 at 16:22 UTC
by Mr. Muskrat

Okay, this was created as a custom script. It is designed to read lines from a data file and "auto-submit" the data in the line to a cold fusion app. It works as advertised when run as a CGI script.

When run as from the command line, the data cannot be sent to the cold fusion application. You will see the line read, and the extracted fields. It will cycle through until there is no more data.

You may now use, modify, distribute, trash and generally do whatever you want with this software. My apologies to the company that paid for the last version of this. (Wow! Was it really almost two years ago?) You will not be reimbursed as it worked as promised and saved untold thousands of man-hours.

Versions prior to 3.0 used here documents to produce the HTML.

Updated: new version! 2002-05-08 12:30 (GMT -0600)

Updated: fixed email address 2002-05-07 13:21 (GMT -0600)

http wrapper
on Apr 21, 2002 at 21:02 UTC
by dree
This script is a wrapper (or a proxy) for HTTP. Briefly it allows to redirect to the browser the content of a site target, masking the true address of the target.
-------------------------- | site with HTTP wrapper | -------------------------- / \ / \ --------------- ------------------ | site target | | user's browser | --------------- ------------------

As an example, if the site target is www.mysite.suffix and the HTTP wrapper is installed on www.perlmongers.it/cgi-bin/tools/http_wrapper.pl/ (<- notice the final slash) by calling this address, you are browsing the site target. If the site target has links and images indicated with *relative* addresses, the user will not be able to notice that the site target is masked by the wrapper. Of course, ALL will pass for the wrapper, that actually it browses the target page, returning the same page and the objects contained in this, to the user's browser. All that is obviously EXPENSIVE (in computational terms) for the site that executes the wrapper. Always, in presence of relative addresses, it works also with upload, form mail, etc :)))
Simple Feedback form.
on Mar 25, 2002 at 04:13 UTC
by DigitalKitty
Stores web form data in a file for later analysis. I am planning on a few improvements ( such as checking form entries for correct input type, etc. ) in the near future.
CGI::Upload - CGI class for handling browser file uploads
on Mar 10, 2002 at 14:27 UTC
by rob_au
This module has been written to provide a simple and secure manner by which to handle files uploaded in multipart/form-data requests through a web browser.

The following methods are exported upon request:

new($cgi)

This method creates a new CGI::Upload object. The only mandatory argument is a CGI.pm object - This is because only a single CGI.pm object can be initiated within a CGI script.
 

file_handle('field_name')

Returns the file handle to the uploaded file.
 

file_name('field_name')

Returns the filename of the uploaded file as supplied by the client web browser - This filename does not reflect the local temporary filename of the uploaded file.
 

file_type('field_name')

Returns the file type of the uploaded file as indicated by the file extension - This does not necessarily reflect the nature of the file uploaded, but allows CGI scripts to perform cursory validation on the file uploaded.
 

mime_magic('/path/to/mime.types')

This method sets and/or returns the external magic mime types file to be used for identification of files via the mime_type method. By default, identification is based upon internal mime types defined within the File::MMagic module.
 

mime_type('field_name')

Returns the file type of the uploaded file as indicated by the file magic numbers. This is the best means by which to validate the nature of the uploaded file.

 

Code updated to include Exporter - Thanks gellyfish++

Display all images in a given directory
on Feb 02, 2002 at 03:46 UTC
by cjf
Simple little script that reads through a directory, grabs all files with png/jpg/gif extensions and prints them to the browser.
Stand-Alone CGI Frame Chat
on Jan 23, 2002 at 06:27 UTC
by {NULE}
This is a stand-alone frame chat application for you to put on your own web page. (It has nothing to do with Perlmonks or the Chatterbox in other words.) I needed a quick little web app for work so we could chat when supporting things from home - sort of like a virtual white-board. This fits the bill and has a few features which I hope make it nice for others to use too.

I'm looking for feed back - mostly on security, but also in the "you could have done this better like this" tradition. You may not like my style, but I probably won't change it for you. {g} I try to make it as readable and maintainable as possible, while still avoiding all the pitfalls of bad Perl coding.

You will always be able to get the latest version at my home page and I even have a demo version running there for you to check out.

Well I hope someone finds it useful besides me. If there are major issues, I'll update it - otherwise I probably won't add much unless I need it.

Have fun!
{NULE}

Update:
2002-01-23 - Thanks to both Zaxo and crazyinsomniac for their sage advice. Documentation for the DB File modules is sketchy for how locking should or should not be accomplished and I really appreciate what they've said. For most people this should run fine as is, but I am probably going to implement locking using a lock file when I open the tables RDWR. I figure that it's a dumb web chat - it doesn't need to be bullet proof. Thanks again.

2002-01-26 - The version posted here now supports primitive locking, by locking a special file whenever RDWR access to the database is required. I also added a ton of new features, like help and its own specialized markup language.

2002-03-31 - There is a more feature-filled version of this on my web site. It is much larger in size, so I am leaving the one here alone, but if you want more features go download the latest and greatest. To-do:
- I might add the ability to block users based on names.
- Maybe password security and persistent user accounts.
- Perhaps support multiple chat rooms.
- Most likely - nothing! {g}

To setup Linux NIS, samba and shadow shadow passwords
on Jan 02, 2002 at 19:22 UTC
by tbo
CGI Script to setup NIS, samba and shadow passwords over web . I didn't want to use yppasswd because it doesn't use md5 passwords. (I want to keep md5 because one day I hope I will understand ldap, and then migrate to ldap). The HTML form gives login name, old passwd, and new password twice.
Image Gallery script
on Dec 25, 2001 at 01:08 UTC
by dmmiller2k

As a 'web-parent' at my sons' school, I came up with this little ditty for displaying the kids computer artwork. It is intended to populate a two-frame page, displaying an index with thumbnails on the left-hand side and the selected image on the right.

See it in action here (choose one of the '... Pics' links in the left-hand panel).

Sitesearch Lite
on Nov 12, 2001 at 17:59 UTC
by George_Sherston
This is a simple pair of scripts that caches a single directory web site and then searches the cache. I'm most grateful to pjf, demerphq and davorg for advice in the CB whilst I was running this up. As well as the two scripts (cache.pl and sitesearch.pl) I've included a snippet that needs to go into a template file that matches the look of the rest of your site. Filepaths: 'your_file_path' is the path on your server, whilst 'your_path' is the full web address of your site's root directory. If the scripts are kept somewhere other than in your_path/cgi-bin/, a little editing is necessary. You'll also need to choose two strings that always occur in your html just before and just after the bit of the page that has the page-specific text in it - these are 'unique_ident_1' and 'unique_ident_2'. If you don't want to use this, then there are a couple of lines in the cache.pl script you'll need to comment out.
Recursive CGI Dirlist
on Oct 24, 2001 at 12:55 UTC
by Ranna
I claimed that my site was just a bunch of general content, and...well, it is. No specific theme or anything. Because of this, I just sorted my public_html directory (sorta...still really messy) and let this thing loose on certain parts of it. The nice part is, it skips all those private directories that the world really would be better without. :o)

This is the final (I hope) version, but input is welcome. Example: Available code directory

virtual tabbing module for CGI
on Oct 19, 2001 at 15:31 UTC
by George_Sherston
update: I've altered this module in various ways to make it meet my needs better. The latest version is here

Reading this thread reminded me that often I don't want a particularly fancy table to display my lists of info, I just want the same functionality you get in a word-processor with the tab key. So I wrote this to provide just that functionality in an intuitive way. You kick it off with the start_tabs(100,250,400,450) function, for which you specify as many tab stops as you like, in pixels. Then you put in your text, with a t at each point you want a tab. The tabs wrap round, so that you go back to zero after you've used up all your tab stops, but if you want to wrap before, use r. Finally at the end end_tabs shuts everything down. It's important to use this function because the whole thing is translated into tables, and this is the function that provides the </table> tag. The only difference between this and the kind of tabbing you do in your word processor is that, because it's done with tables, your text wraps between tabs - which I think is an advantage.

Here's an example gobbet (you can see the output from this here:
#!/usr/bin/perl -w use strict; # path to my module library: use lib '/home/htdocs/hosted/thinweb/lib/'; use CGI qw(:standard); use CGI::tab; my %data = ( foo => ['bimble','bumble','wimble'], bar => ['nimble','numble','rumble'], baz => ['zimble','zumble','gomble'], ); print header, start_html, h1('CGI::tab demo'), hr, h2('print out text from a hash:'), start_tabs(150,300); for my $key (keys %data) { print $_,t for @{ $data{$key} }; } print end_tabs, hr, h2('arbitrary text to show wrapping capability:'), start_tabs(100,250,350,400,450), 'hello',t,'everyone',t,'are',r, t,t,t,t,t,'we',t, 'having',t,t,'fun',t,'yet?', end_tabs, end_html;
There's no rocket science here, but I find it a useful labour saver in a situation that often comes up. I'd value your comments on how to improve it, particularly from the point of view of making it efficient as a module.
Easy Pixel PNG Generator
on Sep 11, 2001 at 07:54 UTC
by bladx
This is based on a totally random programming idea from Vynce. All this does, is it is a CGI, that lets a user enter in some values for the name of the new generated png that will be created after filling the info. and the hex values for the color of the pixels. It then does the creating of the px png for you, and can be used for generating one color 1x1px png backgrounds as well, for those of you that may need something handy like this, (since I tend to do stuff like this as well.)

Overall, this is a very simple utility, but a fun one to use (or at least resourceful,) if you need to make some quick one color backgrounds ever.
CGI::Buildform
on Aug 30, 2001 at 04:35 UTC
by jryan

CGI::BuildForm lets the user build a form in OO style. The user can create any type of form element, and set any type of attribute to that. CGI::BuildForm also has the abilty to regenerate a form after the form has been submitted. Here's a quick sample:

# before the form is submitted my $foo = new CGI::BuildForm("meep"); $foo->set_property(action=>'/cgi-bin/meep.pl', method=>'post'); $foo->new_element("bar", "text"); $foo->new_element("meep", "textarea"); $foo->new_element("narf", "submit"); $foo->set_attribute("bar", value=>'a title here', size=>'10'); $foo->set_attribute("meep", rows=>'2', cols=>'50'); $foo->set_end("meep", "Sample text in a textarea"); print "Content-type: text/html\n\n"; $foo->print_all("\n", "<br>\n", "<br>"); # after the form is submitted my $foo = new CGI::BuildForm("meep"); $foo->rebuild_form; $foo->print_all("\n", "<br>\n", "<br>");

QUITE handy, I've already used it myself. Its especially good for spreading forms accross multiple pages. Save yourself hours of mundane typing and use this module! :)

I'd appreciate anyone reviewing, trying it out, improving it, etc.

File Upload and display back to browser using CGI
on Aug 22, 2001 at 00:13 UTC
by dga

This creates a form for a file upload, receieves the file and then puts the file back out to the browser.

Capturing and storing the file is left as an excersize for the reader.

It does capture the salient points about getting the file in and out.

CGI::Safe and easy file uploading
on Aug 14, 2001 at 03:26 UTC
by Ovid

Update: This module is now available from the CPAN. Go there for the latest and greatest update and be sure to read the docs for more information (quite a bit has changed).

The CGI::Safe module interits from CGI.pm but makes the environment a bit safer. POST_MAX is already set and DISABLE_UPLOADS is set to true. Of course, these may be overriden by the user. Also, as suggested by perlsec, the following keys are deleted from %ENV: qw/ IFS CDPATH ENV BASH_ENV /.

Further, even though this is not strictly related to safe CGI programming, I have added a generic file upload utility that will allow users to easily upload files, specify the file source and the allowed file formats.

Amusing side note: this module disables file uploading by default. While working on the upload capability, I had forgotten to re-enable file uploading and spent 15 minutes of debugging trying to figure out why I couldn't get any files to upload :)

Code review, good 'ol CGI.
on Jul 29, 2001 at 08:55 UTC
by meonkeys
The attached code is a CGI that allows someone to maintain the CSV used to generate a Web site for the University of Washington Men's Water Polo team. I seek help, comments, and criticism on: 1)security, 2)speed, 3)the general approach of using a CSV-driven Web site, 4)anything blatanly wrong or stupid, 5)other cool ways to do what I'm doing. My main goal was maintainability. It was easy for me to teach my Polo coach how to update CSV files, and CSV is relatively easy to deal with for the CGI.

I would REALLY appreciate feedback on the entire Web site (two CGIs and a few packages), as well. The entire codebase is viewable: every file has a ".txt" added to the end. The code_review/ dir is analagous to the document root for the actual working Web site.

The main CGI is in "code_review/", Perl modules are in "code_review/myperl/", the CSV updating tool is in "code_review/admin/", and the CSV datafiles are in "code_review/data/". codebase
midiplayer.pl
on Jul 08, 2001 at 04:16 UTC
by JSchmitz
Allows you to play midi files on your website.
Automatically generate form parsing code
on Jun 15, 2001 at 02:03 UTC
by Anonymous Monk

Run this code with an HTML file as the argument. It will create a series of files with one file created for each form in the HTML document(try it against a perlmonks page, you might be surprised). Each document will contain complete form-handling code to read in the data and even has generic untainting routines.

Read the POD for full documentation on its use. Very easy to use and moderately customizable.

CGI pie-graph Maker
on May 02, 2001 at 18:19 UTC
by BigJoe
This is very similar to the Bar graph maker. But this one will do a Pie chart. The same parameters apply.
  • cols are the names of the values
  • vals are the corrisponding values

title is optional on this.
CGI bar-graph maker
on May 01, 2001 at 23:53 UTC
by BigJoe
This is a quick little script I wrote up to generate a PNG graph. It is using the GD module. It is almost like a CGI wrapper for the GD::Graph::bars module. By using IFrames in your HTML you can send this script all the information it needs to generate a graph. You send the column names as param cols seperated by commas. This is also done with values through param vals. Optional params are title, xlabel, ylabel.
mySQL-driven Random Quote generator
on Mar 31, 2001 at 01:04 UTC
by Hero Zzyzzx

This script, zen.pl, allows you to create,edit, list and show random quotes. I originally wrote this to display a random buddhist koan (very entertaining short instructive stories) on my site(s), hence all the references to "koan."

This is partially a meditative exercise, I wanted to try "subroutining" everything so that it made sense to me, and using CGI.pm to generate all output. This is probably the first thing I've written that I'm proud of.

Zen.pl has a moderate amount of security for "administrator" type functions, and should be speedy because of it's use of mySQL. My idea is to enter several hundred (or as many as I can find) koans, which screamed "RDBMS!" to me.

I believe this should work OK with mod_perl, though that isn't tested yet.

  • Limitations / Errata:
  • Doesn't use HTML::Parser to strip tags. Sorry, I haven't figured out how to use this mod yet.
  • Assumes your cgi-bin directory is cgi-bin. Edit if you need to.
  • Wants all quotes to be sequential in the mySQL database.
  • The security is good (I think) but not perfect. See the notes in the code.

Please let me know what you think and if you get any use out of this.

VXML Book, CD & DVD Database (well, 1 out of 3)
on Mar 24, 2001 at 06:38 UTC
by jcwren

This is a VXML/TellMe.com book looker-upper. I have an innate ability to walk into a book, CD or DVD store, and completely forget every book, CD and DVD I own. I thought it would be cool to put them in a database, and be able to call into to TellMe with my cellphone, and find out if I already own it or not. So I wrote this. It only does books at the moment, but someday (real soon now) it'll handle the CDs and DVDs, too. It's a good simple demonstration of using VXML, CGI, and DBI.

To give it a try, call 1-800-555-TELL (8355), at the main menu say 'Extensions' or press 1. At the extensions menu, say 'five four five two nine' or press 5-4-5-2-9 (the letters spell K4JCW, my amateur callsign). The program should be able to step you through the rest. A known ISBN you can try is '0345260716' (Have Space Suit, Will Travel)

Like all Twitching Monk Software, there's a limited warranty. It's limited to assuring you that it won't get a cold beer from the 'fridge without your help, and if you drink too much, you'll fall down.

If you don't like the way I wrote something, fix it. I wrote it, I like it, I use it, it works for, see figure one.

Testing for JavaScript
on Mar 13, 2001 at 20:32 UTC
by akm2
I had a situation where I needed to know if my visitor's browers supported JavaScript. Here is the code I used.
rBuild hack
on Feb 26, 2001 at 04:28 UTC
by Intrepid

Need to install Perl Modules Using FTP Without Having Shell Access?

This script does it for me. My provider has only `tar' on the PATH (no other usual binutils, like `gzip'), so I upload a tarball (not gzipped) to a special dir on my server. Then I go and manually enter a url with a query string like

http://yourserver/cgi-bin/rBuild.pl?archive=Text-Autoformat-1_02.tar
and there it goes. I get no interesting display back in the browser (yet*) but a "journal" page is created with a log of what happened for that module installation.

THIS IS A HUGE POTENTIAL SECURITY RISK.

Anyone messing around with this code is asking to get burned if they don't take the time to study, ask questions of senior monks (Merlyn ;-) and develop understanding of what issues my poor code has left unaddressed. Come up with more secure code if you survey this offering and find it wanting. I post for discussion, not adulation. Nor do I claim that this will work satisfactorily for anyone other than myself -- although I have a hunch it might.

This system requires you to also install `pmake' (Nick Ing-Simmons, CPAN) and the accompanying library "<CITE>Make.pm</CITE>" to your server manually first. And a module called "<CITE>Tie::STDERR</CITE>" which is another thing that is just about the coolest invention since sliced bread. And it most likely requires other things that this first write-up is going to overlook (humble apologies if so).

Soren
P.S.: I have, since posting, worked further on this application a lot and it now uses a client-pull META tag in the head to automatically take the admin-user to the "journal" (build log) page. See below in the head of the script code itself for a link to a url to see the latest version of <CITE>rBuild</CITE>.

2001-03-03 Edit by Corion : Changed mixup of PRE and CODE tags

mySQL Based link list, with click-thru tracking
on Feb 20, 2001 at 04:46 UTC
by Hero Zzyzzx
Neat little program to create a categorized link list with click-thru tracking. It uses CSS for output formatting. I've only been perl programming for a couple of months, so please go easy on me. I know I need to learn the CGI module, etc., but all things in due time.
This works well included as SSI
The mySQL table was created with the command below, I added the indeces thinking I might use them down the road.
create table links (urllink varchar(120) not null, index urllink (urllink), urlcategory char(120) not null, index urlcategory (urlcategory), description tinytext not null, visits smallint unsigned not null);

I'm sure you could tweak the field definitions.

Comments?

UPDATE, 4/5/01

I fixed the code to run under strict and use CGI.pm for parameter parsing. If I had more time, I'd also fix it to use CGI.pm to output all the HTML, but I don't think it's worth fixing at this point.

CGIpack
on Jan 18, 2001 at 12:03 UTC
by jeroenes
CGIpack is a module I wrote in this response.

I came up with this solution. The encoder takes a list of data, together with a list with the desired number of bits to be saved. The bits are divided into chunks of 6 bits, that are encoded with the alphanumeric characters *and* % and - (64 characters in total). The resulting string is short, contains as little bits as possible and/or desired by the user.

See POD for further info.

Update:Version 0.02 has working 32 bit values now. Still pondering 64 bits.

Update2:Thanx to ChOas, I now know that perl 5.6 has another implementation of pack, *and* that 64 bits can be used only if you have a 64bit machine and 64 bit support is compiled in. I've chosen to comment that line in decode, you can uncomment it if your environment is right, otherwise there is a risk of a fatal error. Please let me know if you succesfully use 64 bits.

Wishlist:

  • Apply tye's quad for 57 bit integers
  • Add wrapper, to accomodate: characters, strings, signed integers.
GNS::Node
on Mar 06, 2001 at 22:49 UTC
by mr.nick
Okay folks, this is my Node class that I've been spewing about. Please take a look and see if it makes sense to you. If it does, and you have constructive criticism, please make them. Oh, and ignore the zillions of calls to GNS::User->new().
cgiparam
on Jan 16, 2001 at 23:04 UTC
by stephen
Sometimes I stumble into hard-to-trace bugs because I've misspelled the name of a CGI parameter-- I use
param('username')
in one place, and
param('user name')
in another. What I wind up doing is defining constants like so:
use constant USERNAME_PARAM => 'username'; print "User name is: ", param(USERNAME_PARAM);
This gets old pretty quickly, though. Recently I started to wonder: what if I could set up a way so that I could just set up subroutines automatically to return a named parameter, a la constant.pm?

So I wrote up cgiparam.pm. Using it, one could have a file like so:

use strict; use CGI ':cgi'; use cgiparam (FOO_PARAM => 'foo', BAR_PARAM => 'bar', BAZ_PARAM => 'baz'); print STDOUT "Foo is ", FOO_PARAM, "\n", "Bar is ", BAR_PARAM, "\n", "Baz is ", BAZ_PARAM, "\n";
And you'll get the values of the CGI parameters foo, bar, and baz in the printout. Plus, you're still using strict, so if you try to use an unspecified parameter, you'll get a compile-time error.

I've tested this once, but have no idea if it's useful...

UpdateWith help from tye, I've added lvalue capability to the code. So now you can do things like:

use CGI ':cgi'; use cgiparam FOO_PARAM => 'foo'; FOO_PARAM = 'blibble'; print STDOUT FOO_PARAM;
and out will come 'blibble'.

Further update Altered the module so that you can supply the names for your own routines, plus removed the direct reference to CGI.pm there so that one can use CGI::Fast. In the future, I'll have the thing check to see if CGI has been loaded (if possible) and load it as necessary.

random noise background generator
on Dec 08, 2000 at 02:12 UTC
by cogent

CGI to create a random "noise" PNG as a background image. Fully configurable through CGI parameters. As an example, see the background image at my own Web site. (Netscape 4 totally screws up my CSS, but that doesn't impact the background image. And Non-CSS-enabled browsers probably can't see it at all. Check out the raw image, instead.)

There are three parameters:

  • height: The height of the image (in a background image, set high enough so that the repeat doesn't look too bad).
  • widths: The widths of the left gutter, the left border, the primary "noise" section, the right border, and the right gutter, in that order, separated by commas.
  • colors: The colors available for each section. Each color within a section is separated by commas; each section is separated by underscores.

Colors are specified as hex triples, HTML-style.

CGI Random Quote Server
on Dec 02, 2000 at 09:45 UTC
by ailie

This is a small script (one of my first) that will display a random quote from a file on a webpage. It allows the use of HTML tags in the quotes.

I'd be interested in any constructive criticism people have to offer.

Mea culpa - I didn't use CGI. I must have had a brain bubble or somesuch when I posted this. Sigh...

Easy CGI variable debugging
on Oct 19, 2000 at 22:19 UTC
by Ovid
Update: The module is now fully object-oriented. The previous problem with the module overwriting POST data has been eliminated.

Routinely when I am working on large CGI scripts, I find that I need to monitor variables to see if they're functioning properly. Typically, I do this one of two ways:

  1. Use the Perl built-in debugger.

    This is often clumsy and unwieldy. Sometimes I need to see the page.

  2. Have print $foo; embedded in the code.

    This method is clumsy when examining large amounts of variables. When I think it works and don't want that to print, I often comment it out and come back to it later when needed. This isn't fun for large blocks of code.

Finally, I got fed up and looked for an alternative. CGI::Debug had similar functionality to what I wanted, but it didn't allow me to pass it arbitrary variables for display. I finally wrote CGI::DebugVars to allow me to quickly examine variables as the script runs. See the POD for full documentation.

While I've written a few modules before, this is my first of this type. I know I need to modularize the code more (shame on me!), but aside from that, any suggestions would be appreciated.

Having problems with POD2HTML rendering the POD correctly. Any pointers would be appreciated.

Update: Have added file logging capability. Use it with:

my $debug = CGI::DebugVars->new( -file => $log_file );
This will create a Web page with the debugging info. You can switch to a separate browser and just hit "refresh". Also, the normal method of using it returns a table instead of printing it. A friend is testing this out with Linux and when that's done, I'll update the POD and repost.

Chained Babelfish Translations
on Sep 07, 2000 at 07:22 UTC
by merlyn
The Babelfish service at Altavista is cool, but it's really fun to drag some random text to and from weird languages to see how much "it loses in the translation". So I wrote a nice short program for an upcoming Linux Magazine column to automate the chaining from one language to the next, showing the intermediate results. 95 lines (again {grin}).

This code is a review draft from a forthcoming Linux Magazine Perl column and is provided for review purposes only. Further copying and redistribution is not permitted. You can download this and put it on your site to use it for "evaluation purposes", but you cannot redistribute the source out of context. Once the magazine releases the code, in about three months, you can download it from my official site and do with it what you want. I'm sorry for being more restrictive than most open source stuff, but this is "work for hire", and I have to be careful.

WebChat in under 100 lines of Perl
on Sep 05, 2000 at 08:06 UTC
by merlyn
I was challenged by the fellow columnists of WebTechniques Magazine to write a nice decent WebChat in under 100 lines of Perl. I did it with 95. It works without JavaScript or Java, in all browsers that support frames and client-pull (meta refresh). Oh, and it even detects any URL-like strings in the messages, and auto links them to their target. In 95 lines. Yes.

This code is a review draft from a forthcoming WebTechniques Perl column and is provided for review purposes only. Further copying and redistribution is not permitted. Sorry, but that's the rules about the code I do for hire. (Clarification: You can download this and put it on your site to use it for "evaluation purposes", but you cannot redistribute the source out of context. Once the magazine releases the code, in about three months, you can download it from my official site and do with it what you want. I'm sorry for not being clearer about this, and sorry for being more restrictive than most open source stuff, but this is "work for hire", and I have to be careful.)

CGI::SQL.pm initial release
on Aug 13, 2000 at 10:38 UTC
by markjugg
CGI::SQL is a set of routines I find useful when working with CGI.pm and DBI.pm. To use these functions you must have an existing database handle which is used to create the CGI::SQL object. Documentation is included as POD.
Get those parameters without CGI.pm
on Jun 21, 2000 at 06:56 UTC
by j.a.p.h.
I don't use CGI.pm execpt to pull the params from the users request. I prefer to wrote my own raw HTML, so I never use that feture of CGI.pm. I'm sure there are more of you out there who do the same thing, so I'm posting what I use to pull params from a request. It pulls the users cookie, form (for either get or post) and puts them into 3 hashes: %cookie, %form and %params. %params contains %form and %cookie. If there's a param with the same name in the form and cookie, it's over-written by the form, but still accessable through %cookie. I've done a good amount of testing and it seems fool proof, so you just know someone will be making a better fool. Enjoy!
Cookie Maker
on Sep 09, 2000 at 01:51 UTC
by isotope
I use this CGI script every time I have to do some work with cookies. It can be used to set completely arbitrary cookies, and to renew, edit, or delete existing cookies. I wrote it a long time ago, so please excuse the newbie flavor to it. Maybe I'll work on an update soon. Consider it covered by the GPL.
Template
on Jun 16, 2000 at 00:29 UTC
by kayos

Sometimes we have to make websites for clients that don't know how to use the web. Usually there is a certain section of their website that must be updated often. For those spots, I use this script.

This script relies on ePerl for the templates.

In the directory with the script, I have a file called config.pl:

$config = { 'parents' => { file => 'data/parents.pl', name => "Parent Link", }, 'highlights' => { file => 'data/highlights.pl', name => 'Issue Highlights', input => "input/highlights.tmpl", output => 'output/highlights.tmpl', }, 'financial' => { file => 'data/financial.pl', name => 'Financial / Public', } };

Each section of this hash is for a file that the client needs to change. The sections specify where to store the data that is plugged into the template, a descriptive name, and which ePerl template to use.

My input/default.tmpl looks like:

<html> <body> <form method="POST"> <input type="hidden" name="file" value="<:= $::file :>"> <input type="hidden" name="action" value="save"> <textarea name="body" cols="70" rows="50" wrap="physical"><:=$body:></ +textarea> <br> <input type="submit" value="Save Changes"> </form> </body> </html>

My output/default.tmpl is below. I made a function in main to convert linebreaks into <br> and <p> tags.

<:= main::encode($body) :>

I can either use this script to generate pieces of webpages or entire webpages. Examples:

<!--#include virtual="/cgi-bin/template/admin.pl?file=parents" -->
Tie::Htpasswd
on Apr 25, 2000 at 21:04 UTC
by kayos

If you have a "membership" area that uses HTTP Basic Auth, then you probably have to edit the .htpasswd file pretty often. This module let's you treat the .htpasswd file as a Tied hash.

This module uses Apache::Htpasswd.

Example:

use Tie::Htpasswd; tie %htpasswd, 'Tie::Htpasswd', "/home/httpd/htdocs/.htpasswd"; $htpasswd{username} = "password"; # assignment automatically crypt() +s delete $htpasswd{username}; # removed from .htpasswd untie %htpasswd; # save the file
Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (4)
As of 2014-11-27 23:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (190 votes), past polls