in reply to Can't create file

In short, what you're doing is a bad, bad idea. You will need to sanitize the $domain input because otherwise, anybody can overwrite any file on your server that your webserver has write permissions to.

Variables are not magical under Perl CGI, so you best start off by reading CGI when writing a CGI script. You will need to accept the variables from the CGI module and then handle them in your program. But again, you shouldn't modify your system just by accepting input from a web page, even if that page is only accessible from a "secure network".

Replies are listed 'Best First'.
Re^2: Can't create file
by sluttysysadmin (Initiate) on Oct 05, 2009 at 15:50 UTC
    Hello Corion, I really appreciate your views. I am trying this in my home machine. Can you please help me out with pointing out what is wrong with the code ? I just want to create a zone file. I am learning Perl and do not know much about regex. The below is the entire code which I am using,
    #!/usr/local/bin/perl use strict; use CGI ':standard'; use Cwd; my $ipaddr = param('ipaddr'); my $domain = param('domain'); my $serial = `/bin/date +"%Y%m%d"00`; print header(), start_html('Zone created Successfully'), "Zone created Successfully", end_html(); open FILE, "+>", "/var/named/$domain.db"; print FILE "@ 86400 IN SOA ns1.eth1.in. ilugbelgaum.g +mail.com. ( $serial ; serial, todays date+todays 86400 ; refresh, seconds 7200 ; retry, seconds 3600000 ; expire, seconds 86400 ) ; minimum, seconds $domain. 86400 IN NS ns1.eth1.in. $domain. 86400 IN NS ns2.eth1.in. $domain. IN A $ipaddr localhost.$domain. IN A 127.0.0.1 $domain. IN MX 0 $domain. mail IN CNAME $domain. www IN CNAME $domain. ftp IN CNAME $domain. "; close FILE;
    Thanks !