App-phoebe
view release on metacpan or search on metacpan
script/phoebe view on Meta::CPAN
TLS. Gemtext is a very simple markup language, a bit like Markdown, but line
oriented. See L</GEMTEXT>.
To take a look for yourself, check out the test wiki via the web or via the web.
=over
=item * L<What is Gemini?|https://gemini.circumlunar.space/>
=item * L<Gemini link collection|https://git.sr.ht/~kr1sp1n/awesome-gemini>
=item * L<Test site, via the web|https://transjovian.org:1965/test>
=item * L<Test site, via Gemini|gemini://transjovian.org/test>
=back
=head1 GEMTEXT
Pages are written in gemtext, a lightweight hypertext format. You can use your
favourite text editor to write them.
A text line is a paragraph of text.
This is a paragraph.
This is another paragraph.
A link line starts with "=>", a space, a URL, optionally followed by whitespace
and some text; the URL can be absolute or relative.
=> http://transjovian.org/ The Transjovian Council on the web
=> Welcome Welcome to The Transjovian Council
A line starting with "```" toggles preformatting on and off.
Example:
```
./phoebe
```
A line starting with "#", "##", or "###", followed by a space and some text is a
heading.
## License
The GNU Affero General Public License.
A line starting with "*", followed by a space and some text is a list item.
* one item
* another item
A line starting with ">", followed by a space and some text is a quote.
The monologue at the end is fantastic, with the city lights and the rain.
> I've seen things you people wouldn't believe.
=head1 EDITING THE WIKI
How do you edit a Phoebe wiki? You need to use a Titan-enabled client.
Titan is a companion protocol to Gemini: it allows clients to upload files to
Gemini sites, if servers allow this. On Phoebe, you can edit "raw" pages. That
is, at the bottom of a page you'll see a link to the "raw" page. If you follow
it, you'll see the page content as plain text. You can submit a changed version
of this text to the same URL using Titan. There is more information for
developers available on Community Wiki. L<https://communitywiki.org/wiki/Titan>
Known clients:
This repository comes with a Perl script called F<titan> to upload files.
L<https://alexschroeder.ch/cgit/phoebe/plain/titan>
I<Gemini Write> is an extension for the Emacs Gopher and Gemini client
I<Elpher>. L<https://alexschroeder.ch/cgit/gemini-write/>
L<https://thelambdalab.xyz/elpher/>
Gemini & Titan for Bash are two shell functions that allow you to download and
upload files. L<https://alexschroeder.ch/cgit/gemini-titan/about/>
=head2 Editing via the web
The Configuration section of the Phoebe space on I<The Transjovian Council> has
an example config on how to enable editing via the web.
=over
=item * L<https://transjovian.org:1965/phoebe/page/Configuration>
=item * L<gemini://transjovian.org/phoebe/page/Configuration>
=back
=head1 INSTALLATION
Using C<cpan>:
cpan App::phoebe
Manual install:
perl Makefile.PL
make
make install
=head2 Dependencies
If you are not using C<cpan> or C<cpanm> to install Phoebe, you'll need to
install the following dependencies:
=over
=item * L<Algorithm::Diff>, or C<libalgorithm-diff-xs-perl>
=item * L<File::ReadBackwards>, or C<libfile-readbackwards-perl>
=item * L<File::Slurper>, or C<libfile-slurper-perl>
=item * L<Mojolicious>, or C<libmojolicious-perl>
=item * L<IO::Socket::SSL>, or C<libio-socket-ssl-perl>
=item * L<Modern::Perl>, or C<libmodern-perl-perl>
=item * L<URI::Escape>, or C<liburi-escape-xs-perl>
=item * L<Net::IDN::Encode>, or C<libnet-idn-encode-perl>
=item * L<Encode::Locale>, or C<libencode-locale-perl>
=back
I'm going to be using F<curl> and F<openssl> in the L</Quickstart> instructions,
so you'll need those tools as well. And finally, when people download their
data, the code calls C<tar> (available from packages with the same name on
Debian derived systems).
The F<update-readme.pl> script I use to generate F<README.md> also requires some
libraries:
script/phoebe view on Meta::CPAN
=item * L<Text::Slugify>, which has no Debian package, apparently ð
=back
=head2 Quickstart
I'm going to assume that you're going to create a new user just to be safe.
sudo adduser --disabled-login --disabled-password phoebe
sudo su phoebe --shell=/bin/bash
cd
Now you're in your home directory, F</home/phoebe>. We're going to install
things right here.
cpan App::phoebe
Start Phoebe. It's going to prompt you for a hostname and create certificates
for you. If in doubt, answer C<localhost>. The certificate and a private key are
stored in the F<cert.pem> and F<key.pem> files, using elliptic curves, valid for
five years, without password protection.
perl5/bin/phoebe
This starts the server in the foreground. If it aborts, see the
L</Troubleshooting> section below. If it runs, open a second terminal and test
it:
perl5/bin/gemini gemini://localhost/
You should see a Gemini page starting with the following:
20 text/gemini; charset=UTF-8
Welcome to Phoebe!
Success!! ð ðð
Let's create a new page using the Titan protocol, from the command line:
echo "Welcome to the wiki!" > test.txt
echo "Please be kind." >> test.txt
perl5/bin/titan --url=titan://localhost/raw/Welcome --token=hello test.txt
You should get a nice redirect message, with an appropriate date.
30 gemini://localhost:1965/page/Welcome
You can check the page, now (replacing the appropriate date):
perl5/bin/gemini gemini://localhost:1965/page/Welcome
You should get back a page that starts as follows:
20 text/gemini; charset=UTF-8
Welcome to the wiki!
Please be kind.
Yay! ðð ðð
If you have a bunch of Gemtext files in a directory, you can upload them all in
one go:
titan --url=titan://localhost/ --token=hello *.gmi
=head2 Image uploads
OK, how do image uploads work? First, we need to specify which MIME types Phoebe
accepts. The files are going to be served back with that MIME type, so even if
somebody uploads an executable and claim it's an image, other people's clients
will treat it as an image instead of executing it (one hopes!) â so let's start
with a list of common MIME types.
=over
=item * C<image/jpeg> is for photos (usually with the C<jpg> extension)
=item * C<image/png> is for graphics (usually with the C<png> extension)
=item * C<audio/mpeg> is for sound (usually with the C<mp3> extension)
=back
Let's continue using the setup we used for the L</Quickstart> section. Restart
the server and allow photos:
perl5/bin/phoebe --wiki_mime_type=image/jpeg
Upload the image using the C<titan> script:
perl5/bin/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:
titan --url=titan://localhost:1965/earth.png \
--token=hello Pictures/Planets/Earth.png
What you get back explains the problem:
59 This wiki does not allow image/png
In order to allow such graphics as well, you need to restart Phoebe:
phoebe --wiki_mime_type=image/jpeg --wiki_mime_type=image/png
Except that in my case, the image is too big:
59 This wiki does not allow more than 100000 bytes per page
I could scale it down before I upload the image, using C<convert> (which is part
of ImageMagick):
convert -scale 20% Pictures/Planets/Earth.png earth-small.png
Try again:
titan --url=titan://localhost:1965/earth.png \
--token=hello earth-small.png
Alternatively, you can increase the size limit using the
C<--wiki_page_size_limit> option, but you need to restart Phoebe:
phoebe --wiki_page_size_limit=10000000 \
--wiki_mime_type=image/jpeg --wiki_mime_type=image/png
Now you can upload about 10MBâ¦
=head2 Using systemd
Systemd is going to handle daemonisation for us. There's more documentation
available online.
L<https://www.freedesktop.org/software/systemd/man/systemd.service.html>.
Basically, this is the template for our service:
[Unit]
Description=Phoebe
After=network.target
[Service]
Type=simple
WorkingDirectory=/home/phoebe
ExecStart=/home/phoebe/phoebe
Restart=always
User=phoebe
Group=phoebe
MemoryMax=100M
MemoryHigh=90M
[Install]
WantedBy=multi-user.target
Save this as F<phoebe.service>, and then link it:
sudo ln -s /home/phoebe/phoebe.service /etc/systemd/system/
Reload systemd:
sudo systemctl daemon-reload
Start Phoebe:
sudo systemctl start phoebe
Check the log output:
sudo journalctl --unit phoebe
=head2 Troubleshooting
ð¥ B<1408A0C1:SSL routines:ssl3_get_client_hello:no shared cipher> ð¥ If you
created a new certificate and key using elliptic curves using an older OpenSSL,
you might run into this. Try to create a RSA key instead. It is larger, but at
least it'll work.
openssl req -new -x509 -newkey rsa \
-days 1825 -nodes -out cert.pem -keyout key.pem
=head1 FILES
Your home directory should now also contain a wiki directory called F<wiki>,
your wiki directory. In it, you'll find a few more files:
F<page> is the directory with all the page files in it; each file has the C<gmi>
extension and should be written in Gemtext format
F<index> is a file containing all the files in your F<page> directory for quick
access; if you create new files in the F<page> directory, you should delete the
F<index> file â it will get regenerated when needed; the format is one page name
(without the C<.gmi> extension) per line, with lines separated from each other
by a single C<\n>
F<keep> is the directory with all the old revisions of pages in it â if you've
only made one change, then it won't exist; if you don't care about the older
revisions, you can delete them; assuming you have a page called C<Welcome> and
edit it once, you have the current revision as F<page/Welcome.gmi>, and the old
revision in F<keep/Welcome/1.gmi> (the page name turns into a subdirectory and
each revision gets an apropriate number)
F<file> is the directory with all the uploaded files in it â if you haven't
uploaded any files, then it won't exist; you must explicitly allow MIME types
for upload using the C<--wiki_mime_type> option (see I<Options> below)
F<meta> is the directory with all the meta data for uploaded files in it â there
should be a file here for every file in the F<file> directory; if you create new
files in the F<file> directory, you should create a matching file here; if you
have a file F<file/alex.jpg> you want to create a file F<meta/alex.jpg>
containing the line C<content-type: image/jpeg>
F<changes.log> is a file listing all the pages made to the wiki; if you make
changes to the files in the F<page> or F<file> directory, they aren't going to
be listed in this file and thus people will be confused by the changes you made
â your call (but in all fairness, if you're collaborating with others you
probably shouldn't do this); the format is one change per line, with lines
separated from each other by a single C<\n>, and each line consisting of time
stamp, pagename or filename, revision number if a page or 0 if a file, and the
numeric code of the user making the edit (see L</Privacy> below), all separated
from each other with a C<\x1f>
F<config> probably doesn't exist, yet; it is an optional file containing Perl
code where you can add new features and change how Phoebe works (see
L</Configuration> below)
F<conf.d> probably doesn't exist, either; it is an optional directory containing
even more Perl files where you can add new features and change how Phoebe works
(see L</Configuration> below); the idea is that people can share stand-alone
configurations that you can copy into this directory without having to edit your
own F<config> file.
=head1 OPTIONS
=over
=item * C<--wiki_token> is for the token that users editing pages have to
provide; the default is "hello"; you can use this option multiple times
and give different users different passwords, if you want
=item * C<--wiki_page> is an extra page to show in the main menu; you can use
this option multiple times; this is ideal for general items like I<About>
or I<Contact>
=item * C<--wiki_main_page> is the page containing your header for the main
page; that's were you would put your ASCII art header, your welcome
message, and so on, see L</Main Page and Title> below
=item * C<--wiki_mime_type> is a MIME type to allow for uploads; text/plain is
always allowed and doesn't need to be listed; you can also just list the
type without a subtype, eg. C<image> will allow all sorts of images (make
sure random people can't use your server to exchange images â set a
password using C<--wiki_token>)
=item * C<--wiki_page_size_limit> is the number of bytes to allow for uploads,
both for pages and for files; the default is 10000 (10kB)
=item * C<--host> is the hostname to serve; the default is C<localhost> â you
probably want to pick the name of your machine, if it is reachable from
the Internet; if you use it multiple times, each host gets its own wiki
space (see C<--wiki_space> below)
=item * C<--port> is the port to use; the default is 1965
=item * C<--wiki_dir> is the wiki data directory to use; the default is either
the value of the C<PHOEBE_DATA_DIR> environment variable, or the "./wiki"
subdirectory
=item * C<--wiki_space> adds an extra space that acts as its own wiki; a
subdirectory with the same name gets created in your wiki data directory
and thus you shouldn't name spaces like any of the files and directories
already there (see L</FILES>); not that settings such as
C<--wiki_page> and C<--wiki_main_page> apply to all spaces, but the page
content will be different for every wiki space
=item * C<--cert_file> is the certificate PEM file to use; the default is
F<cert.pem>
=item * C<--key_file> is the private key PEM file to use; the default is
F<key.pem>
=item * C<--log_level> is the log level to use (C<fatal>, C<error>, C<warn>,
C<info>, C<debug>); the default is C<warn>
=item * C<--log_file> is the log file to use; the default is undefined, which
means that STDERR is used
=back
=head2 UPLOADS
If you allow uploads of binary files, these are stored separately from the
regular pages; the wiki doesn't keep old revisions of files around. If somebody
overwrites a file, the old revision is gone.
You definitely don't want random people uploading all sorts of images, videos
and binaries to your server. Make sure you set up those L<tokens|/Security>
using C<--wiki_token>!
=head1 NOTES
=head2 Security
The server uses "access tokens" to check whether people are allowed to edit
files. You could also call them "passwords", if you want. They aren't associated
with a username. You set them using the C<--wiki_token> option. By default, the
only password is "hello". That's why the Titan command above contained
"token=hello". ð
If you're going to check up on your wiki often (daily!), you could just tell
people about the token on a page of your wiki. Spammers would at least have to
read the instructions and in my experience the hardly ever do.
You could also create a separate password for every contributor and when they
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
IP numbers, in which case you will need to tell them about it using in order to
comply with the
L<GDPR|https://en.wikipedia.org/wiki/General_Data_Protection_Regulation>.
=head1 EXAMPLE
Here's an example for how to start Phoebe. It listens on C<localhost> port 1965,
adds the "Welcome" and the "About" page to the main menu, and allows editing
using one of two tokens.
phoebe \
--wiki_token=Elrond \
--wiki_token=Thranduil \
--wiki_page=Welcome \
--wiki_page=About
Here's what my F<phoebe.service> file actually looks like:
[Unit]
Description=Phoebe
After=network.target
( run in 1.718 second using v1.01-cache-2.11-cpan-b16cb0d3907 )