#!/usr/local/bin/perl # editkphoto.cgi # # This file makes a nice HTML interface to edit the splashpage and # captions for kphoto.cgi. Symlink or copy it to the same directory # kphoto.cgi and the images are in, and make sure it can write to "kphoto.info" # file in the same directory print "Content-type: text/html\n\n"; chugCGI(*input); opendir(READ,"."); while($nextfile=readdir(READ)){ if($nextfile =~ /\.(jpg|jpeg|gif)$/i) { push @pixname, $nextfile; } } closedir READ; @sortpix = sort @pixname; readInfo(); if($input{"task"} eq "update"){ foreach $thispix (@sortpix) { updateInfo("caption:".$thispix); } updateInfo("splashpage"); updateInfo("title"); writeInfo(); } print <<__EOQ__;
\n splashpage:

title:

__EOQ__ print qq(
\n); foreach $thispix (@sortpix) { $safepix = $thispix; $safepix =~ s/ /%20/g; print qq(
\n); if(exists($info{"caption:".$thispix})) { $caption = htmlize($info{"caption:".$thispix}); } else { $caption = ""; } print qq(
); print "
"; } print qq(); sub htmlize { my($text) = @_; $text =~ s/&/&/g; $text =~ s/\"/"/g; $text =~ s/>/>/g; $text =~ s/)){ chomp $nextline; ($key,@rest)=split(/=/,$nextline); #break on first = $val=join("=",@rest); #glue the value together in case it also had =s $val =~ s/\\n/\n/g; $info{$key} = $val; } close READ; } #go through info hash, write all key=val pairs to info file sub writeInfo { open(WRITE,"> kphoto.info") || print "Couldn't Write kphoto.info: $!"; flock(WRITE, 2); #lockfor writing foreach $key(keys %info){ $val = $info{$key}; $val =~ s/\r//g; $val =~ s/\n/\\n/g; print WRITE "$key=$val\n"; } close WRITE; } sub chugCGI { local (*in) = @_ if @_; local ($i, $key, $val); if($ENV{'REQUEST_METHOD'}eq"POST") { read(STDIN,$in,$ENV{'CONTENT_LENGTH'}); }else {$in = $ENV{'QUERY_STRING'};} @in = split(/&/,$in); foreach $i (0 .. $#in) { $in[$i] =~ s/\+/ /g; ($key, $val) = split(/=/,$in[$i],2);$key =~ s/%(..)/pack("c",hex($1))/ge; $val =~ s/%(..)/pack("c",hex($1))/ge; $in{$key}.= $val;}return length($in);}