in reply to Re^5: INSERT file contents inside a table
in thread INSERT file contents inside a table

Hi, thnaks for your reply. I am doing it with a front end html code.

Here's my front end html code. it's release.html

<html> <head> <title>Release your email</title> </head> <body bgcolor="#95B8DB" onload="parent.adjustMyFrameHeight();"> <form action="/cgi-bin/release.pl" method="post"> <h1>Release your email</h1> <div style="height:500px; dispaly:block;">Pls input the Mail ID: <inpu +t name="release" size="20" style="height:30px"> <input type="submit" +value="Release" style="height:30px"></div> </form> </body> </html>

Here's the release.pl code. It works. Remember I still am a Novice. Pls don't blame my perl code. I don't feel shy. Everyone learns little by little. any way, This code works.

#!/usr/bin/perl use CGI qw(:standard); $ENV{"PATH"} = "/usr/sbin:/usr/bin:/sbin:/bin"; $release = param('release') || '<i>(No input)</i>'; print "Content-type: text/html\n\n"; print "<body bgcolor=\"#95B8DB\">"; print "<h1>You are releasing: $release</h1>"; system("/bin/echo > /tmp/releaseme"); system("sudo /bin/chmod 777 /tmp/releaseme"); system("sudo /usr/bin/amavisd-release $release 2> /tmp/releaseme"); if (system("less /tmp/releaseme |grep Ok > /dev/null") == 0) { print "<h2>Your Mail ID $release was released.\n</h2>"; print "<br />"; } else { print "<h2>Error!!! Wrong Mail ID, Pls Input the Right Mail ID +.\n</h2>"; print "<br />"; } print "</body>";

Anyway, I had to change the code since it gave an error due to below line in that release.pl code

$release = param('release') || '<i>(No input)</i>';

I changed it in this way. Pls see the below release.pl code. THIS IS the code I now use. But does NOT work

#!/usr/bin/perl use CGI qw(:standard); $ENV{"PATH"} = "/usr/sbin:/usr/bin:/sbin:/bin"; #$release = param('release') || '<i>(No input)</i>'; print "Content-type: text/html\n\n"; print "<body bgcolor=\"#95B8DB\">"; #print "<h1>You are releasing: $release</h1>"; print "<h1>You are releasing: $id</h1>"; system("/bin/echo > /tmp/releaseme"); system("sudo /bin/chmod 777 /tmp/releaseme"); system("sudo /usr/bin/amavisd-release $id 2> /tmp/releaseme"); if (system("less /tmp/releaseme |grep Ok > /dev/null") == 0) { print "<h2>Your Mail ID $id was released.\n</h2>"; print "<br />"; } else { print "<h2>Error!!! Wrong Mail ID, Pls Input the Right Mail ID +.\n</h2>"; print "<br />"; } print "</body>";

Many thanks for your reply. Your INPUTS r welcome. Thanks a lot

Replies are listed 'Best First'.
Re^7: INSERT file contents inside a table
by poj (Abbot) on Jun 06, 2018 at 19:34 UTC

    Try this and post the result. Be aware of the security risk of user provided data, see Calling External Commands More Safely for better solutions.

    #!/usr/bin/perl use strict; use CGI qw(:standard); use CGI::Carp 'fatalsToBrowser' ; # only for test my $id = param('release'); my $cmd = "sudo /usr/bin/amavisd-release $id 2"; my $result; if ($id =~ /^spam-[a-zA-Z0-9-]+\.gz$/) { $result = qx/ $cmd /; } else { $result = "ERROR : Invalid id '$id'"; } print "Content-type: text/plain\n\n"; print "$cmd\n\n$result";
    poj

      Thanks once again for your effort to rewrite the code.

      Anyway, Why I need below line. NOW, I DON'T want to use front end HTML release.html code ANYMORE. Instead, I want to release directly by clicking.

      my $id = param('release');

      This is the ERROR

      sudo /usr/bin/amavisd-release 2 ERROR : Invalid id ''

      the above error does NOT show the ID. Hope to hear from you. Meanwhile I am also trying to resolve the issue.

        If you mean by clicking this link

        <td><a href=/cgi-bin/release.pl>$id</a></td>

        then you need to add the id as parameter

        <td><a href=/cgi-bin/release.pl?release=$id>$id</a></td>
        poj