Please whitelist cPanel in your adblocker so that you’re able to see our version release promotions, thanks!

The Community Forums

Interact with an entire community of cPanel & WHM users!

Working with forms in whm

Discussion in 'cPanel Developers' started by jj@24khost, Nov 15, 2011.

  1. jj@24khost

    jj@24khost Well-Known Member

    Joined:
    May 27, 2009
    Messages:
    51
    Likes Received:
    0
    Trophy Points:
    56
    I am working on creating an apf addon for whm and creating it in perl.

    I have 2 fields the besides the hidden input.

    What is the correct way to call thesese in the actuall processing script?
    am i doing it correct with the $form{reason}?
    Code:
    		<form action="addon_apf_add_ip.cgi">
    			<input type=hidden name=deny value=save>
    			<br>
    			Deny IP: <input type=text name=ipaddy size=20><br>
    			<br>
    			Reason: <input type=text name=reason size=20><br>
    			<br>
    			<font color="red">
    			<b>Warning</b>: Inserting an invalid or malformed rule can cause your firewall to malfunction!
    			</font>
    			<br>
    			<br>
    			<input type=submit value="Add Rule / Restart">
    		</form>
    
    The code that process is.
    Code:
    if ( $FORM{'deny'} =~ m/save/i ) {
        delete $FORM{'allow'};
        open( APFCONF, ">>", $denyfile );
        foreach my $var ( sort values %FORM ) {
    		if ($var =~ /^[a-zA-Z].*?$/) {
    			print APFCONF "# added ".$var." on ".$dttime{mon}."/".$dttime{mday}."/".$dttime{year} $dttime{hour }":".$dttime{min  }.":".$dttime{sec  }."with comment: ".$FORM{'reason'}."\n";
    			print APFCONF "h=".$var."\n";
    			print '<div class="readout">';
    			print "The ip you has been added, and APF is being restarted";
    			print "<br><br>";
    			print "<a href=\"addon_apf_add_ip.cgi\" target=\"_self\">[Add another IP or block]</a>";
    			print "<pre>";
    			exec ('/etc/init.d/apf restart') or print STDERR "There was an error restarting APF: $!";
    			print "<br><br>";
    			print "</pre>";
    			print "</div>";
    		}
    		else 
    		{
    			print '<div class="readout">';
    			print "There was an error in the entry.";
    			print "<br><br>";
    			print "<a href=\"addon_apf_add_ip.cgi\" target=\"_self\">[Add another IP or block]</a>";
    			print "<pre>";
    			print '</div>';
    		}
    	}
        close(APFCONF);
    }
    
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  2. cPanelDavidN

    cPanelDavidN Integration Developer

    Joined:
    Dec 17, 2009
    Messages:
    571
    Likes Received:
    3
    Trophy Points:
    68
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    Hi

    Try using the Perl CGI module

    Code:
    #!/usr/bin/perl
    #WHMADDON:test:Dave Test
    
    use CGI;
    
    print "Content-type: text/html\r\n\r\n";
    
    my $v = CGI::param('foo');
    if (!$v) {
        print "<form action='addon_test.cgi'><input type='text' name='foo'/><input type='submit' value='Send Foo'/></form>";
    }
    else {
       print "<p>Foo is: $v</p>";
       print "<form action='addon_test.cgi'><input type='submit' value='Reset Foo'/></form>";
    }
    
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  3. jj@24khost

    jj@24khost Well-Known Member

    Joined:
    May 27, 2009
    Messages:
    51
    Likes Received:
    0
    Trophy Points:
    56
    we actually got it working.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
Loading...

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice