#!/usr/bin/perl ### make: http://YOURDOMAIN/setSitemap.cgi?(password) ### view: http://YOURDOMAIN/ror.xml ################################################## ### password my $pwd = "abcd1234"; # set your original password. ### ROR file name my $ror = "ror.xml"; ### noindex files or directory, from root path. my @no = ( "/secret.html", "/member/", ); ### updatePeriod: ### always,hourly,daily,weekly,monthly,yearly,never my $up = "monthly"; ################################################## use Jcode; &viewXML if ($ENV{'QUERY_STRING'} ne $pwd); my $no = ",." . join(",.",@no) . ","; my(@html,$xml); &getHTML("./"); &setXML; print qq|Content-type: text/xml; charset="UTF-8"\n\n$xml|; exit; sub viewXML { print "Location: http://$ENV{'HTTP_HOST'}/$ror\n\n"; exit; } sub getHTML { my $dir = $_[0]; my @file = &getDir($dir); foreach my $file (@file) { my $path = "$dir$file"; next if ($no =~ /,\Q$path\E\/?,/); &getHTML("$path/") if (-d $path); next if ($file !~ /\.html?$/i); my $last = (stat($path))[9]; $path =~ s/^\.+|(\/)index\.html?$/$1/ig; push(@html,"$last\t$path\t$up\t\n"); } } sub setXML { @html = reverse sort @html; foreach (@html) { my($last,$path,$up) = split(/\t/,$_); my($year,$mon,$day,$hour,$min,$sec) = &getTime($last); $last = "$year-$mon-$day" . "T$hour:$min:$sec+09:00"; $xml .= <<"EOF"; http://$ENV{'HTTP_HOST'}$path $last $up 0 sitemap EOF } $xml = <<"EOF"; ROR Sitemap for $ENV{'HTTP_HOST'} http://$ENV{'HTTP_HOST'}/ $xml EOF &setFile("./$ror",Jcode->new($xml)->utf8); } sub getDir { my $dir = $_[0]; opendir(DIR,$dir) || return (); @_ = sort readdir DIR; closedir(DIR); splice(@_,0,2); return @_; } sub setFile { my($file,@data) = @_; open(OUT,"> $file"); seek(OUT,0,0); print OUT @data; truncate(OUT, tell(OUT)); close(OUT); chmod(0666,$file); } sub getTime { my $time = $_[0]; $ENV{'TZ'} = "JST-9"; my($sec,$min,$hour,$day,$mon,$year,$week) = localtime($time); $year += 1900; $mon = sprintf("%02d",$mon+1); $day = sprintf("%02d",$day); $hour = sprintf("%02d",$hour); $min = sprintf("%02d",$min); $sec = sprintf("%02d",$sec); $week = ('Sun','Mon','Tue','Wed','Thu','Fri','Sat')[$week]; return ($year,$mon,$day,$hour,$min,$sec,$week); }