Re: configurable variables in own file?




I did not write the constitution, so wondering about OP intent seems
funny. :-) Thanks everyone.

As pointed out, I do not worry about an end user injecting code.
Users of my program download it and have full access to it. If they
want to inject, let them.

Yes, I may be schizophrenic in assuming some ability of my users to
read and change my perl. By laying configuration out to a
'makechangeshere.pm' file, I hope this is a little easier than reading
my entire program. As to CPAN, I just don't want to worry about users
ending up having to do deep installs with many dependencies. They may
also not have root access. My view may be wrong. Maybe I should just
go this route.

As to my code, I am thinking that a user may have to change one sub:

sub http2file {
my $httpname= $_[0]; # the http://www.domain.com/file.html
(defined($httpname)) or htmldie("You cannot call http2file without
an http name.\n");
($httpname =~ /^http:\/\//) or htmldie("You cannot call http2file
with '$httpname'.\n");
$httpname=~ s/^http:\/\///; # eliminate the http
$httpname =~ /([^\/]+)\/(.*)/; # separate the domain name
and the filename
my $hostname= $1;
my $fname= $2 || "index.html"; # default; could be made
smarter
my $filename = "/var/www/$hostname/htdocs/$fname"; # rewrite the
filename
$filename=~ s/\?.*//; # kill everything after the
'?'
return $filename;
}

For standard cases, this should work fine. (Probably some bugs in the
code, too, but as I said, for standard cases, it should work.) It's
the only routine that my user needs to change---and yes, it may be
painful. The rest of the configuration are just variables, that I
could have laid out into a configuration file.

(My application is a lightweight wiki that can be easily bolted onto
existing web pages, is less than 300 lines of real code, and requires
very little for its installation. In case anyone is interested,
http://welch.econ.brown.edu/computers/MiniWiki.tgz . There are
probably better alternatives elsewhere, though. I am not a pro,
programming is just a hobby.)

Thanks again, everyone.

/iaw

.



Relevant Pages