leocharre has asked for the wisdom of the Perl Monks concerning the following question:

I'm working in an office environment. Bunch a people scan things and need to move documents from place to place, access hardware accross the network, etc.

One of the things we have, is an old scanner/printer.. one of those four bajillion dollar chunks of mountain.. you know.. those cannon printers that scan, print, collate, make coffee, etc.
We have it set up so that when you scan, you can choose from a list of places to send to. The software is set up on this machine to read from a text file (yeah.. you see where this is going? :) ) a list of directories etc that are valid options. Everytime a user scans and selects from the list, the text file is loaded by the orinter hardware.
There are about 400 directories, they change sometimes. Some poor bastard was entering and keeping them up to date manually. So, now we have a perl script that makes the list. When something changes, the script can be re-run.
Another option is to put it on cron.. And then... What I really really like... And what this post is about - and i need opinions.. is...

I was thinking..
I want to have list.txt - which is really a perl script that spits out list.txt- you know? spits out mime type, and content.
And I was also thinking of doing this in other things.. for example, having a image.png file.. that's really a perl script, that is accessed being called by html liks <img src="image.png">, and when called, something happens- a notice is sent, the image is generated from scratch, whatever..

So I would end up with files like list.txt and image.png, whatever.doc which output that expected content... but the file itself is really a program.

Now, I know how to do this- nothing crazy. What I want to know is. Should I do this, regularly?
Is this looking for trouble? Am I potentially going to cause problems? I want to use this in websites, office networking hacks.. Is this bad juju? Am I breaking some unspoken *ix rule about being clever?
What if I die and someone else takes this job.. Would I be leaving a legacy of insanity or would this be a regular common *ix hack that someone should figure out ?

Replies are listed 'Best First'.
Re: scripts posing as data files, nitch nitch or uber cool?
by samizdat (Vicar) on Apr 12, 2006 at 17:22 UTC
    Apache can make anything act like anything else... All you have to do is ask it to. See mod_rewrite for 'rewrite rules', that's generally easier to deal with and maintain than making individual programs named, f.e., 'image.png' that have perl shebang lines in them.

    Don Wilde
    "There's more than one level to any answer."
Re: scripts posing as data files, nitch nitch or uber cool?
by davidrw (Prior) on Apr 12, 2006 at 16:46 UTC
    what about <img src="get_image.cgi"> instead? makes it pretty obvious that it's dynamically created by a script .. though of course anyone taking this over would also see in the web server config that there's some sort of handler set up for .png files that runs a script ..

      see.. it's just.. this is a multi platform networked environment.. we have windows machines also- yup.
      So.. A windows machine may make a call to say; list.txt - it won't like list.cgi- The printer software is looking for a flat file- (residing on a linux box). So the other option would be a cron or a manual call to regenerate the list.txt file, something like [user:cli]$  make_list.pl > list.txt

      actually that idea is great for webstuffs.. the browser seems to have no problems interpreting <img src="image.cgi">
      Won't this cause any freakies , i mean, doesn't that attract unwated attention to what i'm doing? If this is a sensitive site, for example.

        A windows machine may make a call to say; list.txt - it won't like list.cgi

        What does the client have to do with how the server handles a given resource? Names don't matter. URIs don't matter. All that matters is that the server does something for a given request and returns something that the client can handle.

        actually that idea is great for webstuffs.. the browser seems to have no problems interpreting
        right .. cause it's the mime-type that matters, not the extension ..

        Won't this cause any freakies , i mean, doesn't that attract unwated attention to what i'm doing? If this is a sensitive site, for example.
        Well, your concern was that if there was a behind-the-scenes handler for image.png that a future maintainer wouldn't realize it. That aside, if you think that naming it "image.png" vs "image.cgi" is going to protect you, you're relying on security-through-obfuscation and that's a Bad Thing (TM). Either you trust that your script is secure or you don't (and since there's no user input here, shouldn't be that hard to secure it... might want to worry about throttling though) ..