Add info on how to run
This commit is contained in:
parent
2e8b87103f
commit
df7267af48
4 changed files with 36 additions and 8 deletions
17
README.md
17
README.md
|
@ -1,2 +1,15 @@
|
||||||
# gmnd
|
# gMNd
|
||||||
My gemini server
|
gMNd is my gemini server, which is written in python.
|
||||||
|
|
||||||
|
Currently it only serves static files. You can build and run it from the supplied Dockerfile if you so whish
|
||||||
|
```
|
||||||
|
docker build -t gmnd:latest .
|
||||||
|
```
|
||||||
|
By just running it, it will create self signed certs and serve example content from this repo
|
||||||
|
```
|
||||||
|
docker run -p 1965:1965 gmnd
|
||||||
|
```
|
||||||
|
A slightly more interesting thing it can do is serve your own content, in this example from /tm/content on your host machine
|
||||||
|
```
|
||||||
|
docker run --mount type=bind,source="/tmp/content,target=/app/content" -p 1965:1965 gmnd
|
||||||
|
```
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
# Heading test
|
||||||
|
|
||||||
|
* item
|
||||||
|
* item 2
|
|
@ -0,0 +1,2 @@
|
||||||
|
# Text
|
||||||
|
Plain text me old son
|
|
@ -1,4 +1,5 @@
|
||||||
import logging
|
import logging
|
||||||
|
import mimetypes
|
||||||
import os
|
import os
|
||||||
import socket
|
import socket
|
||||||
import ssl
|
import ssl
|
||||||
|
@ -48,6 +49,11 @@ class gMNd:
|
||||||
header = get_header()
|
header = get_header()
|
||||||
body = b""
|
body = b""
|
||||||
if os.path.isfile(self.base_path + path):
|
if os.path.isfile(self.base_path + path):
|
||||||
|
if not path.endswith(".gmi"):
|
||||||
|
header = get_header(
|
||||||
|
'20',
|
||||||
|
mimetypes.guess_type(
|
||||||
|
self.base_path + path)[0].encode())
|
||||||
cfile = open(self.base_path + path)
|
cfile = open(self.base_path + path)
|
||||||
body = cfile.read().encode()
|
body = cfile.read().encode()
|
||||||
cfile.close()
|
cfile.close()
|
||||||
|
@ -71,7 +77,7 @@ class gMNd:
|
||||||
conn.shutdown(socket.SHUT_RDWR)
|
conn.shutdown(socket.SHUT_RDWR)
|
||||||
conn.close()
|
conn.close()
|
||||||
|
|
||||||
def get_dir_list(self,directory):
|
def get_dir_list(self, directory):
|
||||||
contents = b"#Contents:\r\n"
|
contents = b"#Contents:\r\n"
|
||||||
dirs = []
|
dirs = []
|
||||||
files = []
|
files = []
|
||||||
|
@ -90,20 +96,23 @@ class gMNd:
|
||||||
return contents
|
return contents
|
||||||
|
|
||||||
|
|
||||||
def get_header(status='20', meta = b""):
|
def get_header(status='20', meta=b"text/gemini"):
|
||||||
metadict = {}
|
metadict = {}
|
||||||
metadict['10'] = meta
|
metadict['10'] = meta
|
||||||
metadict['20'] = b"text/gemini"
|
metadict['20'] = meta
|
||||||
metadict['30'] = meta
|
metadict['30'] = meta
|
||||||
metadict['40'] = meta
|
metadict['40'] = meta
|
||||||
metadict['50'] = meta
|
metadict['50'] = meta
|
||||||
metadict['60'] = b"Client certificate required"
|
metadict['60'] = b"Client certificate required"
|
||||||
separator = b" "
|
separator = b" "
|
||||||
terminator = b"\r\n"
|
terminator = b"\r\n"
|
||||||
header = bytes(status.encode()) + separator + metadict[status] + terminator
|
header = bytes(status.encode()) + separator + metadict[status] + terminator
|
||||||
return header
|
return header
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
server = gMNd({'allow_dir_list': True, 'logg_level': logging.DEBUG, 'listen_addr': '0.0.0.0'})
|
server = gMNd({
|
||||||
|
'allow_dir_list': True,
|
||||||
|
'listen_addr': '0.0.0.0'
|
||||||
|
})
|
||||||
server.run()
|
server.run()
|
||||||
|
|
Loading…
Add table
Reference in a new issue