The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

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:
    6
    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);
    }
    
     
  2. cPanelDavidN

    cPanelDavidN Integration Developer
    Staff Member

    Joined:
    Dec 17, 2009
    Messages:
    571
    Likes Received:
    1
    Trophy Points:
    18
    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>";
    }
    
     
  3. jj@24khost

    jj@24khost Well-Known Member

    Joined:
    May 27, 2009
    Messages:
    51
    Likes Received:
    0
    Trophy Points:
    6
Loading...

Share This Page