Tag Archives: perl

How to enable shell access for a user with perl.

Here is a quick script to rewrite a passwd file to enable shell access for a given user. my $user = $someuser; my $found_user; my $passwd_path = "/etc/passwd"; open(my $fh_pw, "<", $passwd_path) or die "can’t open $passwd_path: $!\n"; open(my $fh_pw_w, ">", "$passwd_path.temp") or die "can’t open $passwd_path.temp: $!\n"; while (<$fh_pw>) { my $cur_line = $_; [...]

Posted in Programming, Webhosting | Tagged | Leave a comment

Using Perl and LWP::UserAgent to POST to a HTML/PHP form.

Here is the original HTML form that you would see if you were navigating to the page to fill out the form: <form name="input" action="form_rec.php" method="post"> Ye giveth:<input type="text" name="in"> <input type="submit" value="Go"> </form> Notice that we’re posting to the file form_rec.php, not the file that actually contains this form code.  If you try posting [...]

Posted in Programming, Webhosting | Also tagged , , | Leave a comment

My most used Perl regular expressions.

Match full path of image and extention and store in an array. my @arr = ($string =~ m/([\/A-Za-z0-9_\-]+\.(?:jpg|png))/g); Add something to the end of a line. $string =~ s/(.*)/$1 something/; Add something to the beginning of a line. $string =~ s/(.*)/something $1/; Match an HTML <img> tag. $string =~ m/(<img.*?>)/;

Posted in Programming, Webhosting | Also tagged | Leave a comment