Hi Monks! I have a problem with one of my Scripts i code for my group house. Its an DNAT Webgui where a User can put in a port and an ip-adress on the local network and add this as a DNAT Rule to iptables (ie. if my co-inhabitants need a forward for ie. their p2p Client(s)). Befor i will try to explain my Problem, i will post two code snippets. the Form using CGI.pm:
$q->default_dtd('-//W3C//DTD HTML 4.01 Transitional//EN'); print $q->header(), $q->start_html("DNAT"), $q->br(), $q->br(), $q->start_form(), $q->start_table({ -boarder => '0' }), $q->Tr($q->td($q->radio_group(-name => 'proto', -values => ['tcp','udp'], -rows => 2, -columns => 1)), $q->td('Port: ', $q->textfield(-name => 'port')), $q->td('IP-Adresse: ', $q->textfield(-name => 'ip')), $q->td($q->submit(-name => 'add', -value => 'apply'))), $q->end_table(), $q->end_form(); $q->br(), $q->br();
and The "add Rule" Part:
if ($q->param('add')) { # seems that user has requested a new rule my $proto = $q->param('proto'); my $port = $q->param('port'); my $ip = $q->param('ip'); # set up rule hash's for NAT and FILTER Tables my %addrule_nat = ( protocol => "$proto", "destination-port" => "$port", jump => "DNAT", "to-destination" => "$ip", ); my %addrule_for = ( protocol => $proto, "in-interface" => 'eth0', "out-interface" => 'eth1', "destination-port" => $port, jump => "ACCEPT", ); my %addrule_inp = ( protocol => $proto, "destination-port" => $port, jump => "ACCEPT", ); my $erfolg_nat = $nat->append_entry('PREROUTING', \%addrule_nat) || d +ie "NAT: $!"; my $erfolg_for = $filter->insert_entry('FORWARD', \%addrule_for, 0) | +| die "FORWARD: $!"; my $erfolg_inp = $filter->insert_entry('INPUT', \%addrule_inp, 0) || +die "INPUT: $!"; # now commit our work my $commit_nat = $nat->commit(); my $commit_filter = $filter->commit(); # tell the user it is done an refresh in 5sec _cut_ }
In short, the Problem is, everytime i call the script to add a rule, i get an error from the append_entry() methode, telling me that "protocol: Must be passed as integer or string at ..." Ok i know this fact, but i thought i'd alredy do so. So i added a debug output to check the value of $proto ... its a scalar with "tcp" (or "udp") as its value. But why IPTables::IPv4 still tells me that its "not a string"?? Next Test i did was to add "tcp" as a static element of the %addrule Hash ... and woow suddenly append_entry() seems to have no more problems with the protocol, instead now its throws me the same error for the IP-Adress :(. What is wrong with this code?? I'm a realy CGI newb so - imho - i think the problem is somewhere at:
my $proto = $q->param('proto'); my $port = $q->param('port'); my $ip = $q->param('ip');
Can anybody help me with this issue?

Thanks and sorry for my bad english
nermd

In reply to IPTables::IPv4 and parameters from CGI.pm by nermd

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.