Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

secure file viewing

by Anonymous Monk
on Feb 27, 2006 at 16:14 UTC ( [id://533061]=perlquestion: print w/replies, xml ) Need Help??

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

Not sure if this is the right place to ask this but here goes.
I have a perl script that creates output log files. I wish to allow the script user to view these log files if certain pre-determined conditions are met. e.g. an error occurs. Essentially being able to use an editor or have the same sort of functions as an editor (like vi) but not be able to break out of it to the operating system command line level.
Is there a way of allowing secure file viewing from within Perl ?

Replies are listed 'Best First'.
Re: secure file viewing
by derby (Abbot) on Feb 27, 2006 at 16:37 UTC

    You don't really give enough information on how your app is structured (gui, cmdline, web, windows or *nix, etc). So I'll just assume it's a normal script running under *nix. Rather than doing something within perl, I would suggest you just fork/exec rview (a restricted, read only version mode of vim).

    -derby
Re: secure file viewing
by trammell (Priest) on Feb 27, 2006 at 16:16 UTC
    Sounds like something ideally handled by the OS's file permissions.
Re: secure file viewing
by bowei_99 (Friar) on Feb 27, 2006 at 18:28 UTC
    I wish to allow the script user to view these log files if certain pre-determined conditions are met. e.g. an error occurs.
    -----------------------------------
    So, I assume you want to test if the files are readable by the user and give a userfriendly error message or prompt the user for another set of files to read if it fails? Like another poster said, you would want to make sure the permissions are correct on the file itself, i.e. at the operating system level, then use the -r test on the filehandle to see if it's readable. Does that make sense?

    Essentially being able to use an editor or have the same sort of functions as an editor (like vi) but not be able to break out of it to the operating system command line level. Is there a way of allowing secure file viewing from within Perl ?

    ===================================

    Burvil * http://www.burvil.org *

      So, for example, you could use the following code to test if the file is readable:

      if (-r $filename) { #do stuff here with the file } else { carp "Cannot read file $filename\n"; }

      However, it sounds like you may be essentially trying to write a text editor in perl. Why? If userfriendliness is an issue and people don't know how to use emacs/vi, there are plenty of other editors out there that are more userfriendly, like joe. If you have a GUI available, there are gui versions of vi (gvim) or emacs available.

      ===================================

      Burvil * http://www.burvil.org *

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://533061]
Approved by kutsu
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2024-04-20 01:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found