App-Phoebe
view release on metacpan or search on metacpan
lib/App/Phoebe/StaticFiles.pm view on Meta::CPAN
}
return;
}
# being paranoid about directory traversal
sub is_in {
my ($parent, $child) = map { $_->to_abs } @_;
return substr($child, 0, length($parent)) eq $parent;
}
# cheap MIME type guessing; alternatively, use File::MimeInfo
sub mime_type {
$_ = shift;
return 'text/gemini' if /\.gmi$/i;
return 'text/plain' if /\.te?xt$/i;
return 'text/markdown' if /\.md$/i;
return 'text/html' if /\.html?$/i;
return 'image/png' if /\.png$/i;
return 'image/jpeg' if /\.jpe?g$/i;
return 'image/gif' if /\.gif$/i;
return 'text/plain'; # or application/octet-stream?
lib/App/Phoebe/WebDAV.pm view on Meta::CPAN
my $d = substr($resource, -1) eq "/";
$href .= join("/", map { uri_escape_utf8($_) } split (/\//, $resource));
$href .= "/" if $d;
return $href;
}
sub put {
my ($stream, $host, $space, $path, $id, $headers, $buffer) = @_;
return unless authorize($stream, $host, $space, $headers);
return remove($stream, $host, $space, $path, $id, $headers) if length($buffer) == 0;
my $mime = $headers->{"content-type"} // guess_mime_type(\$buffer);
return webdav_error($stream, "Content type not known") unless $mime;
return webdav_error($stream, "Page name is missing") unless $id;
return webdav_error($stream, "Page names must not control characters") if $id =~ /[[:cntrl:]]/;
# We don't need to close the stream because this is called via process_gemini
# which always closes the stream in the end.
if ($path eq "/file/$id") {
with_lock($stream, $host, $space, sub { write_file($stream, $host, $space, $id, $buffer, $mime) } );
} else {
my $text = decode_utf8 $buffer // "";
$text =~ s/\r\n/\n/g; # fix DOS EOL convention
lib/App/Phoebe/WebDAV.pm view on Meta::CPAN
if (not grep(/^$token$/, @tokens)) {
$log->info("Wrong token ($token)");
$stream->write("HTTP/1.1 401 Unauthorized\r\n");
$stream->write("WWW-Authenticate: Basic realm=\"Phoebe\"\r\n");
$stream->write("\r\n");
return;
}
return 1;
}
sub guess_mime_type {
my $SH = new IO::Scalar shift;
return mimetype($SH);
}
1;
script/phoebe view on Meta::CPAN
titan --url=titan://localhost:1965/jupiter.jpg \
--token=hello Pictures/Planets/Juno.jpg
You should get back a redirect to the uploaded image:
30 gemini://localhost:1965/file/jupiter.jpg
How did the C<titan> script know the MIME-type to use for the upload? If you
don't specify a MIME-type using C<--mime>, the C<file> utility is called to
guess the MIME type of the file.
Test it:
file --mime-type --brief Pictures/Planets/Juno.jpg
The result is the MIME-type we enabled for our wiki:
image/jpeg
Here's what happens when you're trying to upload an unsupported MIME-type:
script/phoebe view on Meta::CPAN
leave the project, you just remove the token from the options and restart
Phoebe. They will no longer be able to edit the site.
=head2 Privacy
The server only actively logs changes to pages. It calculates a "code" for every
contribution: it is a four digit octal code. The idea is that you could colour
every digit using one of the eight standard terminal colours and thus get little
four-coloured flags.
This allows you to make a pretty good guess about edits made by the same person,
without telling you their IP numbers.
The code is computed as follows: the IP numbers is turned into a 32bit number
using a hash function, converted to octal, and the first four digits are the
code. Thus all possible IP numbers are mapped into 8â´=4096 codes.
If you increase the log level, the server will produce more output, including
information about the connections happening, like C<2020/06/29-15:35:59 CONNECT
SSL Peer: "[::1]:52730" Local: "[::1]:1965"> and the like (in this case C<::1>
is my local address so that isn't too useful but it could also be your visitor's
( run in 0.527 second using v1.01-cache-2.11-cpan-748bfb374f4 )