http://qs321.pair.com?node_id=14835
Convert SQL queries to XLS files
on Nov 06, 2008 at 14:00 UTC
by dpavlin
Wouldn't it be nice to have a CGI script which would convert bunch of SQL queries into XLS file on-the-fly? And while we are at it, have multiple reports, each in it's own directory?

If you are interested in history of changes you can see them in subversion repository.

member availability entry and display script
on Dec 12, 2007 at 11:43 UTC
by andyselby
A script (two actually) that is used to display the availability of members on each weekday so that a date may be decided on when the maximum amount of memebers are available. see it in action at webplus.andy.abel.co.uk/cgi-bin/entry.cgi Split the code into two files at the line of hashes. Done with a lot of help from batman on #miltonkeynes.pm
Threaded forum with single DB table
on Sep 08, 2007 at 08:37 UTC
by Your Mother
While this is a demo, it works and shows how to add lineage to a single table as well as recursively call it in TT2. There is a module + a cgi that uses it. There is a bit of POD with the cgi. (Update: cleaned up lines/comments in a couple places; and now with fewer Toolkites! Update: 22 July 2008, updated Pod a bit.)
Attachment Search for TWiki
on Oct 11, 2006 at 15:43 UTC
by Melly

We have several internal twikis, and one of the problems we are now dealing with is that users have been uploading word documents and other attachments without describing them on a twiki page, or adding suitable key-words.

The consequence is that we often can't find useful docs since twiki doesn't search attachments... so I wrote this program to allow users to search inside attachments (or just their filenames) for useful content.

A few parameters need setting in the code, but hopefully they are clear enough as to what values they need (basically, $searchpath, $doc_url, $twiki_url, $return_url and @twikis). One final note - if you want the option to search all Twikis, make 'All' the first elemement of @twikis, otherwise leave it out.

I suspect that the code would run against other wikis as well, but I haven't tested.

Runs under warn and taint without problems.

Another Server Info Snooper (AsIs) ;)
on Jun 26, 2006 at 17:32 UTC
by Alexander
Snoops some useful information which I have not normally seen included in other such utilities. It can be handy to web developers to have such system summaries. Particularly to those of us on shared hosting accounts or virtual private servers that sometimes can require configuring certain things to operate properly within the account user's $HOME. I personally find myself needing to do that sometimes. In doing it recently, I wrote this utility, and then ran it past the CB before posting it here. (See credits, line 3.) It's summary is intended to be customizable by the user to have the values they need at a glance. Because it will accept ANY shell command, it is potentially dangerous to those unfamiliar with a Bourne-like shell. Beware the commands you choose to query! In order to accept user determined commands into the summary list, commands could not be translated into their perl equivalents and so the commands are literally being entered into the shell. Again, this was intended to suplement the information provided by the great many utilities already used by many of you. Use this to "fill in the blanks" like "perl -V". If you do not like the options, just change them (at your own peril mwahaha). This is populated by the values I was needing at the time I wrote the first sloppy version. Use them as a starting point and add, remove, and rearrange as much as you want. I would be interested to know what other "uncommon" values the rest of you find yourselves needing yet frequently absent from other such summary utilities.
Serve image from file
on Apr 28, 2006 at 21:33 UTC
by ruzam
Here's snip of script I use to dump images from private (non-document path) file folders.

The source of the file path varies from application to application. Sometimes it comes from the cgi parms, othertimes it comes from a database, so I've simply included a path variable for reference.

Is there a leaner (performance wise, not elegant code wise) way to do this?
BBC News Reader
on Mar 23, 2006 at 13:12 UTC
by ssuresh83
BBc New RSS Reader
GigDates
on Jul 14, 2005 at 16:29 UTC
by nerfherder
This is a small CGI app designed to retrieve a band's gig dates from a formatted text file, sort them by date, and display either Upcoming Shows or Previous Shows (based on the current date). Much more extensible version of gigdates.pl Uses CGI::Application.
perlMan: web interface to man, perldoc, and info pages
on May 27, 2005 at 06:41 UTC
by Elijah
This application was designed to be a web interface for the Linux/Unix/BSD/MAC man, perldoc and info pages. Most the appearance is controlled by the CSS settings in the <head></head> tag.
gigdates.pl
on Apr 06, 2005 at 04:01 UTC
by nerfherder
Currently in use on a band website:

Takes as input a text file ("gigdates.txt", server side), formatted with entries 1 per line, like the following:

1/22 @ Some Smokin Dive - Bumfunk, ID - 9pm

... and sorts them by date into "upcoming shows" and "previous shows", outputting whichever you choose by specifying $listingtype in the query string.

UPDATE: Fixed the 'Previous Shows' listing so that it lists most recent gigs first, and added a check for whether there is a show today. An admin script for easily adding the gigdates to the text file exists - let me know if you need it.

UPDATE: Much better version including admin section and based on CGI::Application can be found here: http://www.perlmonks.org/?node_id=474945
Winamp Playlist Queuing via httpQ Interaction
on Dec 04, 2004 at 01:07 UTC
by All_Star25
This code takes a filename as a parameter, and attempts to interact with the Winamp httpQ plugin (http://httpq.sf.net/), assumed to be listening on a local port.
Discussion Section / Office Hours Poll Taker
on Sep 14, 2004 at 05:14 UTC
by hossman

This is a CGI for gathering personal info from students, and what times of the day are convinient for them to have Discussion Sections (or Office hours). The DATA section shows an example of what the HTML form that posts to it should look like.

I've also written a script to parse the output into an Excel file

XML-RPC in a CGI::Application
on Aug 31, 2004 at 05:17 UTC
by jaldhar

While a traditional CGI program is a good way for users to interact with your website, they include a lot of extra interface simply to accomodate human frailties. A web service on the other hand is designed to provide programs with access to the functionality of your site with as little overhead as possible.

You don't have to choose between the two. In this example I show you how to implement both CGI and XML-RPC access to a single script. It uses Frontier::RPC HTML::Template and CGI::Application and provides the ability to get the square of a number you input. It has four files:

  • An XML-RPC client you can run from the command line.
  • A subclass of CGI::Application called Square.pm
  • A driver script called index.cgi which uses Square.pm
  • An HTML::Template called view used by Square.pm

Put these files into a subdirectory called square off the root directory of your webserver. You can call the script as a CGI by accessing http://localhost/square/index.cgi or as an XML-RPC based web service by using the client program.

Webserver-in-a-Webpage
on Aug 26, 2004 at 13:35 UTC
by dragonchild
ActivePerl has a version of Perl called PerlScript, which behaves like JavaScript does under IE. (Something to do with ActiveX registration or whatnot.) So, you now have the full power of Perl as a client-side programming language, usable wherever you could use JavaScript.

Now, this isn't that useful for standard CGI programming, because every person that visits your site would have to have a specific minimum version of ActivePerl installed. But, it could be useful as a client-side only development environment.

Microsoft has also created an extension called .hta, or HTml Application. Doubleclicking on this will tell Windows to call IE with a number of standard things (like toolbars) intially disabled. (You can re-enable them with a few right-clicks, but most people don't know that.)

The example I've given uses CGI::Application as the method for generating pages. It's certainly not the only way, but I like it.

awlcheck
on Jun 10, 2004 at 17:15 UTC
by solri
This is a CGI app to compare a text against the Academic Word List to give an idea of how academic/technical it is. It will work for uploaded plain text or HTML files, or with URLs, and could be adapted to use any set of word lists. There is a working version here. Note: it uses humungous arrays and is thus rather slow.
iPhoto CGI Thumbnail gallery
on Nov 13, 2003 at 14:21 UTC
by tfrayner
If, like me, you're a complete control freak who doesn't like the way Apple's iPhoto application exports web page thumbnail galleries, this script could be for you. It can be dropped into existing iPhoto web galleries where it parses out information from the relevant pages and builds thumbnail galleries with full navigation links between photos. Instead of having to edit the page for every photo to change the overall look of a gallery, now everything is in one place. Maintaining a consistent 'look' across your photo gallery web site now becomes trivial. The script generates XHTML-compliant pages (thanks to CGI.pm) which can be arranged using CSS. Personally I like to use this script with the CSS scheme described here:

Tableless layout HOWTO

The DIV tags are set up with appropriate ID and CLASS attributes to allow this layout to be used.

N.B. This script has currently only been tested with iPhoto 2 exported galleries (the current version at the time of posting). Also note that the script has been designed to work with the pages that iPhoto generates and so you shouldn't delete them.

Comments, particularly regarding the security or otherwise of this script, are always welcomed.

Updated: Minor amendment to the documentation.

Update 2: Minor bug fix.

CGI Poll Generator / Tracker
on Sep 29, 2003 at 08:26 UTC
by davido

poll.cgi

poll.cgi is a self-contained web poll script. It doesn't require any external HTML to work. Just install it per the instructions below, and you're off to the races. The interface is plain vanilla, but the implementation is fairly complete and (I think) well thought out. Only one caviet: Not for win32.

The following script runs a basic web poll. The Q&A format is pretty flexible, allowing for true/false, or any number of multiple choice poll responses. Here's what you need to know:

  • This script reads the poll's questions and possible answers from its own __DATA__ section. However, if you wish, at the top of the script change $question_file from its current empty string to the actual relative path to an alternate question file. The script will detect that change and will try to read the questions and answers in from the alternate question file.
  • The Q&A file (or <DATA> section) format is as follows:

    • First line of the file must be the poll's title. After that.......
    • Lines starting with # will be ignored.
    • Blank lines or lines with nothing but whitespace will be ignored.
    • Start a question off with a 'Qn: ' at the start of the line, where 'n' is the question number or ID, followed by the actual question text.
    • Each line containing an answer should start with 'A: ', followed by the answer's ID (must be unique within the current question, but it's not necessary that it be unique within the entire poll), followed by the answer's text, each segment delimited by whitespace. The answer text, of course, may contain whitespace as part of the text. In general, useless whitespace (extra spaces between fields, etc.) will be eliminated when the questions and answers are read in.
    • Each question/answer set must end with a line containing 'E' as the first (preferably only) character on that line.
    • See the __DATA__ section of the script for an example.
  • To use the script you must create an empty file, world read/writeable somewhere where the script may access it. The default path is "../polldata/poll.dat". You may edit the variable, $poll_data_path, located at the top of the script to change the relative location of the poll datafile. For security through obscurity (not terribly secure) I recommend making the ../polldata/ directory unreadable to the outside world (and unwritable, of course). The script knows where the file is within that directory, no need to let others see too.
  • The poll's output data file (poll.dat) will grow with each poll submission. Keep that in mind. This script is fine for a couple thousand respondents, but if you get into tens of thousands this script is not terribly efficient of either time or disk space. For heavy duty applications you'll have to rework how the results are stored. If you look at the inline comments you'll understand why I did it the way I did.
  • By entering a valid userID and password and clicking the "Enter" button, you will gain access to the page that displays the poll results. While in testing the userID is 'Guest' and the password is also 'Guest'. Note, this security is not really all that secure. It is intended to deter casual snoopers. You may edit the variables $userid and $adminpass at the top of the script to use your own username/password.

That's about it.

You can see a live version of this poll at: http://davido.perlmonk.org/cgi-bin/poll.cgi

Please let me know what you think of it... especially if it's suggestions for improvement. Here's the source....

taint::CGI
on Sep 06, 2003 at 07:56 UTC
by BrentDax

This little chunk of code untaints the things in the environment that should be safe in CGI work, like the PATH.

I'm not quite sure why, but something about this seems...wrong somehow. I'm not sure I should release it to CPAN--any opinions are welcome.

[untitled node, ID 285917]
on Aug 22, 2003 at 21:05 UTC
by eweaverp
Read form values
on Jul 23, 2003 at 15:47 UTC
by ast
I use this script for parsing values from URL without using CGI module. This is very usefull when you have some small CGI scripts and only want to get the values from a html form. All values will be stored in a hash %INPUT.
Makegif
on Mar 31, 2003 at 10:48 UTC
by Anonymous Monk
Make gif takes some text and makes a gif from it using the hetpbm suite, it has a fair few options for image generation and is quite simple to use.
CGI - Zip tree archiver backup thing
on Feb 27, 2003 at 07:59 UTC
by Vennis
I created this script to play around with Archive::Zip.

Tested on win32, but could work on X systems too.

The script creates and sends a Zip archive to the client. It will add a full dir tree and you can suggest a downloadname for the zipfile.

Might be handy to backup/mirror sites that have slow FTP but good HTTP.

It uses a simple config file with two entries:
file: 'getbackup.conf'
root=c:/temp
name=Tempdir

Ordered Directory Listing CGI
on Feb 19, 2003 at 20:42 UTC
by hiseldl

Creates an HTML Table with a direcotry listing with sorted sub-directories first, followed by sorted file names, and they are all linked to their respective directories and files.

Use the "cols=X" GET parameter to change the number of columns.

Update: added description of splice. 2003-02-20. Thanks Aristotle for the suggestion.

Quick-n-dirty Photo Album
on Feb 14, 2003 at 18:44 UTC
by newrisedesigns
An online photo album that's easy to set up and use. Nothing elaborate, just a simple way to display the images (JPGs) in a directory on your website. Feel free to download, use, and modify as you see fit.
Image Server - Multi-functional
on Feb 12, 2003 at 09:50 UTC
by Coruscate

A script that allows you to serve images to html pages based on catagory. A catagory simply consists of one or more directories which contain related images. The two required parameters to the script are 'm' and 'c'. 'm' is the method of invocation, 'c' is the catagory. The script currently supports 3 methods of invocation:

The Ultimate Rediector CGI Script
on Nov 27, 2002 at 10:15 UTC
by dingus
Redirects the browser to different places.

You can use this to redirect to servers running on other ports of the same computer or to any specified URI.

You can either show the redirected location or you can hide it in a FRAME which has the title of your choice and the location of the script.

XML files should go somewhere in your webpages diretory tree (i.e. anywhere below $ENV{"DOCUMENT_ROOT"} ) and you get redirected nicely using the url:
http://yourserver/cgi-bin/relo.cgi/path/file
the file name itself is $ENV{"DOCUMENT_ROOT"}/path/file.xml.

Note that if you use the Frame method to a URI which isn't yours, you are guilty of deception if not copyright violation.

Dynamic HTML::Template Database Template
on Oct 02, 2002 at 16:04 UTC
by jeffa
Have you ever wanted to write an HTML::Template script that would display any database query without having to change the template file? Well, this bit of code attempts to do just that. Just supply a query and optional place holders and the code will do the rest. Of course, changing the layout of the table is a manual process, but the number and names of the columns are dynamically supplied.

NULL characters and HTML encodings are taken care of (via HTML::Entities for the latter), but i have only tested this code with the MySQL relational database server. Comments and suggestions are always welcome.

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.
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().
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.
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.

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.
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!
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
Convert SQL queries to XLS files
on Nov 06, 2008 at 14:00 UTC
by dpavlin
Wouldn't it be nice to have a CGI script which would convert bunch of SQL queries into XLS file on-the-fly? And while we are at it, have multiple reports, each in it's own directory?

If you are interested in history of changes you can see them in subversion repository.

member availability entry and display script
on Dec 12, 2007 at 11:43 UTC
by andyselby
A script (two actually) that is used to display the availability of members on each weekday so that a date may be decided on when the maximum amount of memebers are available. see it in action at webplus.andy.abel.co.uk/cgi-bin/entry.cgi Split the code into two files at the line of hashes. Done with a lot of help from batman on #miltonkeynes.pm
Threaded forum with single DB table
on Sep 08, 2007 at 08:37 UTC
by Your Mother
While this is a demo, it works and shows how to add lineage to a single table as well as recursively call it in TT2. There is a module + a cgi that uses it. There is a bit of POD with the cgi. (Update: cleaned up lines/comments in a couple places; and now with fewer Toolkites! Update: 22 July 2008, updated Pod a bit.)
Attachment Search for TWiki
on Oct 11, 2006 at 15:43 UTC
by Melly

We have several internal twikis, and one of the problems we are now dealing with is that users have been uploading word documents and other attachments without describing them on a twiki page, or adding suitable key-words.

The consequence is that we often can't find useful docs since twiki doesn't search attachments... so I wrote this program to allow users to search inside attachments (or just their filenames) for useful content.

A few parameters need setting in the code, but hopefully they are clear enough as to what values they need (basically, $searchpath, $doc_url, $twiki_url, $return_url and @twikis). One final note - if you want the option to search all Twikis, make 'All' the first elemement of @twikis, otherwise leave it out.

I suspect that the code would run against other wikis as well, but I haven't tested.

Runs under warn and taint without problems.

Another Server Info Snooper (AsIs) ;)
on Jun 26, 2006 at 17:32 UTC
by Alexander
Snoops some useful information which I have not normally seen included in other such utilities. It can be handy to web developers to have such system summaries. Particularly to those of us on shared hosting accounts or virtual private servers that sometimes can require configuring certain things to operate properly within the account user's $HOME. I personally find myself needing to do that sometimes. In doing it recently, I wrote this utility, and then ran it past the CB before posting it here. (See credits, line 3.) It's summary is intended to be customizable by the user to have the values they need at a glance. Because it will accept ANY shell command, it is potentially dangerous to those unfamiliar with a Bourne-like shell. Beware the commands you choose to query! In order to accept user determined commands into the summary list, commands could not be translated into their perl equivalents and so the commands are literally being entered into the shell. Again, this was intended to suplement the information provided by the great many utilities already used by many of you. Use this to "fill in the blanks" like "perl -V". If you do not like the options, just change them (at your own peril mwahaha). This is populated by the values I was needing at the time I wrote the first sloppy version. Use them as a starting point and add, remove, and rearrange as much as you want. I would be interested to know what other "uncommon" values the rest of you find yourselves needing yet frequently absent from other such summary utilities.
Serve image from file
on Apr 28, 2006 at 21:33 UTC
by ruzam
Here's snip of script I use to dump images from private (non-document path) file folders.

The source of the file path varies from application to application. Sometimes it comes from the cgi parms, othertimes it comes from a database, so I've simply included a path variable for reference.

Is there a leaner (performance wise, not elegant code wise) way to do this?
BBC News Reader
on Mar 23, 2006 at 13:12 UTC
by ssuresh83
BBc New RSS Reader
GigDates
on Jul 14, 2005 at 16:29 UTC
by nerfherder
This is a small CGI app designed to retrieve a band's gig dates from a formatted text file, sort them by date, and display either Upcoming Shows or Previous Shows (based on the current date). Much more extensible version of gigdates.pl Uses CGI::Application.
perlMan: web interface to man, perldoc, and info pages
on May 27, 2005 at 06:41 UTC
by Elijah
This application was designed to be a web interface for the Linux/Unix/BSD/MAC man, perldoc and info pages. Most the appearance is controlled by the CSS settings in the <head></head> tag.
gigdates.pl
on Apr 06, 2005 at 04:01 UTC
by nerfherder
Currently in use on a band website:

Takes as input a text file ("gigdates.txt", server side), formatted with entries 1 per line, like the following:

1/22 @ Some Smokin Dive - Bumfunk, ID - 9pm

... and sorts them by date into "upcoming shows" and "previous shows", outputting whichever you choose by specifying $listingtype in the query string.

UPDATE: Fixed the 'Previous Shows' listing so that it lists most recent gigs first, and added a check for whether there is a show today. An admin script for easily adding the gigdates to the text file exists - let me know if you need it.

UPDATE: Much better version including admin section and based on CGI::Application can be found here: http://www.perlmonks.org/?node_id=474945
Winamp Playlist Queuing via httpQ Interaction
on Dec 04, 2004 at 01:07 UTC
by All_Star25
This code takes a filename as a parameter, and attempts to interact with the Winamp httpQ plugin (http://httpq.sf.net/), assumed to be listening on a local port.
Discussion Section / Office Hours Poll Taker
on Sep 14, 2004 at 05:14 UTC
by hossman

This is a CGI for gathering personal info from students, and what times of the day are convinient for them to have Discussion Sections (or Office hours). The DATA section shows an example of what the HTML form that posts to it should look like.

I've also written a script to parse the output into an Excel file

XML-RPC in a CGI::Application
on Aug 31, 2004 at 05:17 UTC
by jaldhar

While a traditional CGI program is a good way for users to interact with your website, they include a lot of extra interface simply to accomodate human frailties. A web service on the other hand is designed to provide programs with access to the functionality of your site with as little overhead as possible.

You don't have to choose between the two. In this example I show you how to implement both CGI and XML-RPC access to a single script. It uses Frontier::RPC HTML::Template and CGI::Application and provides the ability to get the square of a number you input. It has four files:

  • An XML-RPC client you can run from the command line.
  • A subclass of CGI::Application called Square.pm
  • A driver script called index.cgi which uses Square.pm
  • An HTML::Template called view used by Square.pm

Put these files into a subdirectory called square off the root directory of your webserver. You can call the script as a CGI by accessing http://localhost/square/index.cgi or as an XML-RPC based web service by using the client program.

Webserver-in-a-Webpage
on Aug 26, 2004 at 13:35 UTC
by dragonchild
ActivePerl has a version of Perl called PerlScript, which behaves like JavaScript does under IE. (Something to do with ActiveX registration or whatnot.) So, you now have the full power of Perl as a client-side programming language, usable wherever you could use JavaScript.

Now, this isn't that useful for standard CGI programming, because every person that visits your site would have to have a specific minimum version of ActivePerl installed. But, it could be useful as a client-side only development environment.

Microsoft has also created an extension called .hta, or HTml Application. Doubleclicking on this will tell Windows to call IE with a number of standard things (like toolbars) intially disabled. (You can re-enable them with a few right-clicks, but most people don't know that.)

The example I've given uses CGI::Application as the method for generating pages. It's certainly not the only way, but I like it.

awlcheck
on Jun 10, 2004 at 17:15 UTC
by solri
This is a CGI app to compare a text against the Academic Word List to give an idea of how academic/technical it is. It will work for uploaded plain text or HTML files, or with URLs, and could be adapted to use any set of word lists. There is a working version here. Note: it uses humungous arrays and is thus rather slow.
iPhoto CGI Thumbnail gallery
on Nov 13, 2003 at 14:21 UTC
by tfrayner
If, like me, you're a complete control freak who doesn't like the way Apple's iPhoto application exports web page thumbnail galleries, this script could be for you. It can be dropped into existing iPhoto web galleries where it parses out information from the relevant pages and builds thumbnail galleries with full navigation links between photos. Instead of having to edit the page for every photo to change the overall look of a gallery, now everything is in one place. Maintaining a consistent 'look' across your photo gallery web site now becomes trivial. The script generates XHTML-compliant pages (thanks to CGI.pm) which can be arranged using CSS. Personally I like to use this script with the CSS scheme described here:

Tableless layout HOWTO

The DIV tags are set up with appropriate ID and CLASS attributes to allow this layout to be used.

N.B. This script has currently only been tested with iPhoto 2 exported galleries (the current version at the time of posting). Also note that the script has been designed to work with the pages that iPhoto generates and so you shouldn't delete them.

Comments, particularly regarding the security or otherwise of this script, are always welcomed.

Updated: Minor amendment to the documentation.

Update 2: Minor bug fix.

CGI Poll Generator / Tracker
on Sep 29, 2003 at 08:26 UTC
by davido

poll.cgi

poll.cgi is a self-contained web poll script. It doesn't require any external HTML to work. Just install it per the instructions below, and you're off to the races. The interface is plain vanilla, but the implementation is fairly complete and (I think) well thought out. Only one caviet: Not for win32.

The following script runs a basic web poll. The Q&A format is pretty flexible, allowing for true/false, or any number of multiple choice poll responses. Here's what you need to know:

  • This script reads the poll's questions and possible answers from its own __DATA__ section. However, if you wish, at the top of the script change $question_file from its current empty string to the actual relative path to an alternate question file. The script will detect that change and will try to read the questions and answers in from the alternate question file.
  • The Q&A file (or <DATA> section) format is as follows:

    • First line of the file must be the poll's title. After that.......
    • Lines starting with # will be ignored.
    • Blank lines or lines with nothing but whitespace will be ignored.
    • Start a question off with a 'Qn: ' at the start of the line, where 'n' is the question number or ID, followed by the actual question text.
    • Each line containing an answer should start with 'A: ', followed by the answer's ID (must be unique within the current question, but it's not necessary that it be unique within the entire poll), followed by the answer's text, each segment delimited by whitespace. The answer text, of course, may contain whitespace as part of the text. In general, useless whitespace (extra spaces between fields, etc.) will be eliminated when the questions and answers are read in.
    • Each question/answer set must end with a line containing 'E' as the first (preferably only) character on that line.
    • See the __DATA__ section of the script for an example.
  • To use the script you must create an empty file, world read/writeable somewhere where the script may access it. The default path is "../polldata/poll.dat". You may edit the variable, $poll_data_path, located at the top of the script to change the relative location of the poll datafile. For security through obscurity (not terribly secure) I recommend making the ../polldata/ directory unreadable to the outside world (and unwritable, of course). The script knows where the file is within that directory, no need to let others see too.
  • The poll's output data file (poll.dat) will grow with each poll submission. Keep that in mind. This script is fine for a couple thousand respondents, but if you get into tens of thousands this script is not terribly efficient of either time or disk space. For heavy duty applications you'll have to rework how the results are stored. If you look at the inline comments you'll understand why I did it the way I did.
  • By entering a valid userID and password and clicking the "Enter" button, you will gain access to the page that displays the poll results. While in testing the userID is 'Guest' and the password is also 'Guest'. Note, this security is not really all that secure. It is intended to deter casual snoopers. You may edit the variables $userid and $adminpass at the top of the script to use your own username/password.

That's about it.

You can see a live version of this poll at: http://davido.perlmonk.org/cgi-bin/poll.cgi

Please let me know what you think of it... especially if it's suggestions for improvement. Here's the source....

taint::CGI
on Sep 06, 2003 at 07:56 UTC
by BrentDax

This little chunk of code untaints the things in the environment that should be safe in CGI work, like the PATH.

I'm not quite sure why, but something about this seems...wrong somehow. I'm not sure I should release it to CPAN--any opinions are welcome.

[untitled node, ID 285917]
on Aug 22, 2003 at 21:05 UTC
by eweaverp
Read form values
on Jul 23, 2003 at 15:47 UTC
by ast
I use this script for parsing values from URL without using CGI module. This is very usefull when you have some small CGI scripts and only want to get the values from a html form. All values will be stored in a hash %INPUT.
Makegif
on Mar 31, 2003 at 10:48 UTC
by Anonymous Monk
Make gif takes some text and makes a gif from it using the hetpbm suite, it has a fair few options for image generation and is quite simple to use.
CGI - Zip tree archiver backup thing
on Feb 27, 2003 at 07:59 UTC
by Vennis
I created this script to play around with Archive::Zip.

Tested on win32, but could work on X systems too.

The script creates and sends a Zip archive to the client. It will add a full dir tree and you can suggest a downloadname for the zipfile.

Might be handy to backup/mirror sites that have slow FTP but good HTTP.

It uses a simple config file with two entries:
file: 'getbackup.conf'
root=c:/temp
name=Tempdir

Ordered Directory Listing CGI
on Feb 19, 2003 at 20:42 UTC
by hiseldl

Creates an HTML Table with a direcotry listing with sorted sub-directories first, followed by sorted file names, and they are all linked to their respective directories and files.

Use the "cols=X" GET parameter to change the number of columns.

Update: added description of splice. 2003-02-20. Thanks Aristotle for the suggestion.

Quick-n-dirty Photo Album
on Feb 14, 2003 at 18:44 UTC
by newrisedesigns
An online photo album that's easy to set up and use. Nothing elaborate, just a simple way to display the images (JPGs) in a directory on your website. Feel free to download, use, and modify as you see fit.
Image Server - Multi-functional
on Feb 12, 2003 at 09:50 UTC
by Coruscate

A script that allows you to serve images to html pages based on catagory. A catagory simply consists of one or more directories which contain related images. The two required parameters to the script are 'm' and 'c'. 'm' is the method of invocation, 'c' is the catagory. The script currently supports 3 methods of invocation:

The Ultimate Rediector CGI Script
on Nov 27, 2002 at 10:15 UTC
by dingus
Redirects the browser to different places.

You can use this to redirect to servers running on other ports of the same computer or to any specified URI.

You can either show the redirected location or you can hide it in a FRAME which has the title of your choice and the location of the script.

XML files should go somewhere in your webpages diretory tree (i.e. anywhere below $ENV{"DOCUMENT_ROOT"} ) and you get redirected nicely using the url:
http://yourserver/cgi-bin/relo.cgi/path/file
the file name itself is $ENV{"DOCUMENT_ROOT"}/path/file.xml.

Note that if you use the Frame method to a URI which isn't yours, you are guilty of deception if not copyright violation.

Dynamic HTML::Template Database Template
on Oct 02, 2002 at 16:04 UTC
by jeffa
Have you ever wanted to write an HTML::Template script that would display any database query without having to change the template file? Well, this bit of code attempts to do just that. Just supply a query and optional place holders and the code will do the rest. Of course, changing the layout of the table is a manual process, but the number and names of the columns are dynamically supplied.

NULL characters and HTML encodings are taken care of (via HTML::Entities for the latter), but i have only tested this code with the MySQL relational database server. Comments and suggestions are always welcome.

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