From 1e13c94ae4967b6676007027a922d7e88874a20c Mon Sep 17 00:00:00 2001

From: =?UTF-8?q?Jaakko=20Ker=C3=A4nen?= jaakko.keranen@iki.fi

Date: Fri, 6 Aug 2021 11:55:11 +0300

Subject: [PATCH 1/1] Configurable file locations in addition to Gemlog


README.md | 13 +++++++---

booster.py | 75 ++++++++++++++++++++++++++++++++++++++----------------

2 files changed, 63 insertions(+), 25 deletions(-)

diff --git a/README.md b/README.md

index 6c04597..fbccb70 100644

--- a/README.md

+++ b/README.md

@@ -7,7 +7,7 @@ This is a simple Python script that listens for Titan requests and then adds, up

The configuration file ~/.booster/config.json must exist:

-{

+{

 "python": "/usr/bin/python3",

 "git": {

     "exec": "/usr/bin/git",

@@ -18,8 +18,15 @@ The configuration file ~/.booster/config.json must exist:

 "cert": "/absolute-path/titan.crt",

 "key": "/absolute-path/titan.key",

 "authorized": "/absolute-path/titan-clients.pem",

 "site_url": "gemini://skyjake.fi",

}

diff --git a/booster.py b/booster.py

index d4e9d09..a2636da 100755

--- a/booster.py

+++ b/booster.py

@@ -30,11 +30,15 @@

ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE

POSSIBILITY OF SUCH DAMAGE.

-import os, sys, json, subprocess

+import os, sys, json, subprocess, time

import socket, ssl, OpenSSL.crypto, hashlib

from urllib.parse import urlparse

pjoin = os.path.join

+def append_slash(p):

#----------------------------------------------------------------------------#

CONFIGURATION

#----------------------------------------------------------------------------#

@@ -45,9 +49,8 @@ if not os.path.exists(CFG_PATH):

 print(f'ERROR: Configuration file {CFG_PATH} not found.')

 sys.exit(1)

CONFIG = json.loads(open(CFG_PATH, 'rt').read())

-if not CONFIG['root'].endswith('/'):

print(json.dumps(CONFIG, indent=2))

+FILES_ROOT = append_slash(CONFIG['files']['root'])

#----------------------------------------------------------------------------#

REQUEST HANDLING

@@ -75,6 +78,7 @@ def urlenc(q):

 return q

def handle_client(stream):

 data = bytes()

 incoming = stream.recv(1024)

 expected_size = -1

@@ -105,54 +109,81 @@ def handle_client(stream):

     if len(data) >= expected_size:

         break

     incoming = stream.recv(1024)

 print(f'URL   : {req_url}')

 print(f'Token : {req_token}')

 print(f'MIME  : {req_mime}')

 print(f'Data  : {len(data)} bytes')

 parts = urlparse(req_url)

 path = parts.path

     report_error(stream, 61, "access is not authorized")

     return

 response = '# Booster log\n'

 if not is_new and req_token == 'DELETE':

     response += f'* deleting file: {file_path}\n'

     os.remove(file_path)

 else:

     if is_new:

         response += f'* creating a new file: {file_path}\n'

     else:

         response += f'* updating file: {file_path}\n'

     # write the data

     response += f'* writing %d bytes\n' % len(data)

     dst = open(file_path, 'wb')

     dst.write(data)

     dst.close()

 response += f'* updating indices\n'

 response += run_command([CONFIG['python'], ".makeindex.py"])

 response += '* committing changes to Git repository\n'

 if is_new:

 response += "\n"

 response += f"=> {view_url} View the page\n"

 response += f"=> gemini://warmedal.se/~antenna/submit?%s Notify Antenna" %\

 stream.sendall(('20 text/gemini; charset=utf-8\r\n%s' %

                  response).encode('utf-8'))

--

2.25.1

Proxy Information
Original URL
gemini://git.skyjake.fi/booster/main/patch/1e13c94ae4967b6676007027a922d7e88874a20c.patch
Status Code
Success (20)
Meta
text/plain
Capsule Response Time
32.02752 milliseconds
Gemini-to-HTML Time
3.941262 milliseconds

This content has been proxied by September (3851b).