Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
magentix committed Jan 22, 2022
0 parents commit 80754af
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
cert.pem
key.pem
25 changes: 25 additions & 0 deletions LICENCE
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
BSD 2-Clause License

Copyright (c) 2022, Magentix
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Leo

Leo is the smallest Gemini server in the world.

# Requirements

- PHP >= 7.4
- OpenSSL >= 1.1.1

# Configuration

Generate a self-signed certificate with **gemini** as passphrase:

```bash
openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365
```

Start the server:

```bash
php leo.php &
```
3 changes: 3 additions & 0 deletions capsule/index.gmi
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Welcome

Hello world!
37 changes: 37 additions & 0 deletions leo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

$root = __DIR__ . '/';

$socket = stream_socket_server(
'tcp://127.0.0.1:1965',
$ec,
$em,
STREAM_SERVER_BIND|STREAM_SERVER_LISTEN,
stream_context_create(
[
'ssl' => [
'local_cert' => $root . 'cert.pem',
'local_pk' => $root . 'key.pem',
'passphrase' => 'gemini',
'allow_self_signed' => true,
'verify_peer' => false,
]
]
)
);

stream_socket_enable_crypto($socket, false);

while (true) {
$fSocket = stream_socket_accept($socket, '-1', $remote);

stream_set_blocking($fSocket, true);
stream_socket_enable_crypto($fSocket, true, STREAM_CRYPTO_METHOD_TLSv1_3_SERVER);
$url = parse_url(trim(fread($fSocket, 1024)));
stream_set_blocking($fSocket, false);

$file = $root . 'capsule' . str_replace('../', '', ($url['path'] ?? '/index.gmi'));

fwrite($fSocket, is_file($file) ? "20 text/gemini\r\n" . file_get_contents($file) : "51 Not found\r\n");
fclose($fSocket);
}

0 comments on commit 80754af

Please sign in to comment.