#!/usr/bin/perl
use strict;
use CGI::Carp qw(fatalsToBrowser);
my $data_dir_name = q[data/];
my $path = $ENV{PATH_INFO};
sub htescape ($) {
my $s = shift;
$s =~ s/&/&/g;
$s =~ s/</g;
$s =~ s/"/"/g;
return $s;
} # htescape
if ($path =~ m[^/(_?[0-9a-z-]+)$]) {
my $name = $1;
my $file_name = $data_dir_name . $name . '.dat';
if (-f $file_name) {
if ($ENV{REQUEST_METHOD} eq 'GET') {
my $data;
{
open my $file, '<:utf8', $file_name or die "$0: $file_name: $!";
local $/ = undef;
$data = <$file>;
}
print qq[Content-Type: text/html; charset=utf-8
Edit — @{[htescape ($name)]}
Edit — @{[htescape ($name)]}
];
exit;
} elsif ($ENV{REQUEST_METHOD} eq 'POST') {
eval q{ use CGI qw(param) };
my $data = param ('data');
open my $file, '>', $file_name or die "$0: $file_name: $!";
print $file $data;
close $file;
my $user = $ENV{REMOTE_USER};
$user =~ s/[^0-9A-Za-z_-]/_/g;
(system "cvs commit -m \"by remote user \'$user\'\" data > /dev/null") == 0 or die "$0: $?";
print q[Status: 204 Saved; No Content];
exit;
} else {
print q[Status: 405 Method Not Allowed
Content-Type: text/plain ; charset=us-ascii
Allow: GET, POST
405];
exit;
}
}
} elsif ($path eq '/') {
opendir my $data_dir, $data_dir_name or die "$0: $data_dir_name: $!";
print q[Content-Type: text/html; charset=utf-8
English-Japanese Data Files
English-Japanese Data Files
Old data files
These files are obsolete and no longer used, except for
_mapping
, which is the data file for the
English-Japanese mapping table.
];
for (sort {$a cmp $b} grep {/\.dat$/} readdir $data_dir) {
my $name = $_;
$name =~ s/\.dat$//;
print qq[@{[htescape ($name)]}
];
}
print q[
License of data files
Texts from HTML5 and Web Workers specs :
© Copyright 2004-2008 Apple Computer, Inc.,
Mozilla Foundation, and Opera Software ASA.
You are granted a license to use, reproduce and create
derivative works of this document.
For contributors : You have to agree that your
contributions are licensed under the terms quoted above.
];
exit;
}
print q[Content-Type: text/plain ; charset=us-ascii
Status: 404 Not Found
404];
## Author: Wakaba .
## License: Copyright 2008 Wakaba. You are granted a license to use,
## reproduce and create derivative works of this script.
## $Date: 2008/10/27 05:00:33 $