
rGeoffrey
User
/ Moderator
Oct 27, 2001, 12:54 PM
Post #5 of 5
(638 views)
|
|
Re: Backup (.tar.gz) of a site through perl
[In reply to]
|
Can't Post
|
|
When you don't have telnet you can fake it through the web browser, but it does expose you to some potential security problems. One such system looks like... Write a script that will present a form where the user can give - username - password - a text area to type in what you would like to run in a shell script Have that script call itself with those three bits of information and do a system call on the script capturing the STDERR and STDOUT in two files. The script then redraws the form with the original input and two new text areas to show the files containing STDERR and STDOUT. And lastly you remove the three temporary files to cover your tracks. Then you are ready to go again. This method is also useful for those times where scripts running in the browser run as a different user than you are and you need to get in and do some things like delete a file and need to do it as that other user. But remember this is a dangerous thing to do. If you want to do this you might want to use this function...
sub interact { my ($script) = @_; my ($file, $results, $errors); $file = &Uniq_t_x (); open (DATA, ">$file") or die "While printing file $file"; print DATA ("#!/bin/sh\n", $script); close DATA; chmod (0744, $file); system ("/bin/sh $file > $file.txt 2> $file.errs"); if (open (DATA, "$file.txt")) { $results = join ('', <DATA>); close DATA; } if (open (DATA, "$file.errs")) { $errors = join ('', <DATA>); close DATA; } unlink ($file); unlink ("$file.txt"); unlink ("$file.errs"); return ($results, $errors); } #interact The three filenames (script, script.errs, and script.txt) use a "unique" filename that you can generate any way you want but I use this...
sub Uniq_t_x { my($job, $now, $uniq); $job = `echo \$\$`; $now = time(); $job = $job % 65536; $uniq = sprintf("% 08X% 04X", $now, $job) ; return ($uniq); } # Uniq_t_x This can be a very useful little script and it can be yours if you fill in a few missing pieces. PS. Did I mention that this is leaves you open to real security problems? Edited to add a space in the sprintf statement between the '%' and the '0' so it looks right on the screen. You will need to remove them to use the function.
|