-- Leo's gemini proxy

-- Connecting to bbs.geminispace.org:1965...

-- Connected

-- Sending request

-- Meta line: 20 text/gemini; charset=utf-8

Comment by 🚀 jsreed5


Re: "Now that Bubble supports Titan I'm interested in trying it..."

In: s/GmCapsule


I'd be interested to learn more about this too. My capsule runs JetForce and does not support Titan natively.


🚀 jsreed5

2023-06-09 ¡ 1 year ago


6 Later Comments ↓


🍀 gritty [OP] · 2023-06-09 at 20:36:

yeah, I think just a basic "hello world" example implementation would be quite useful, say in like Python.


🕹ī¸ skyjake [mod...] ¡ 2023-06-10 at 05:47:

I can put together a GmCapsule Titan hello world example for you.


Are you primarily interested in the CGI interface, or doing a Python extension module? The latter is more flexible/powerful since you're using Python, but the CGI one is pretty standard and easy, done via environment variables and stdin.


🕹ī¸ skyjake [mod...] ¡ 2023-06-10 at 06:19:

These examples assume gmcapsuled running on localhost.


Here is a simple CGI Python script that we'll use:

#!/usr/bin/python3
import os
import sys

titan_data = sys.stdin.read()

print("20 text/gemini\r")
print("Client cert hashes:", os.getenv('REMOTE_IDENT'))
print("Titan token:", os.getenv('TITAN_TOKEN'))
print("You uploaded %d bytes." % len(titan_data))

Method 1: CGI entry point in server config


Place the above script file anywhere you'd like, say "scripts/hello.py", and add this to the server config:

[cgi.hello]
protocol = titan
path = /hello-world
command = /usr/bin/python3 scripts/hello.py

(paths are relative to where you start gmcapsuled)


Then open "titan://localhost/hello-world" in the client to start an upload.


Method 2: CGI bin_root


The advantage of setting the `bin_root` is that you can add and remove scripts in your CGI directory without restarting the server.


Normally executables inside the bin_root are assumed to be Gemini CGI scripts. To make them use Titan, append ",titan" to the executable name. So, let's create a bin_root directory called "./cgi-bin", and your script should be named:


./cgi-bin/localhost/hello-world,titan


Don't forget to set the file as executable.


The bin_root is configured in the server config:

[cgi]
bin_root = ./cgi-bin

You can then open "titan://localhost/hello-world" in the client to start an upload.


Methods 1 and 2 are mutually exclusive, you can choose which one works best for you.


Method 3: Extension module


It's actually quite simple to create a simple Titan upload handler via a Python extension module. Add a custom modules directory in the server config:

[server]
modules = ./mymod

Create this Python source file as "./mymod/50_hello.py":

def titan_upload_handler(req):
    response = 'Client cert hash: ' + req.identity.fp_cert
    response += '\nYou uploaded %d bytes.\n' % len(req.content)
    return response


def init(capsule):
    """Extension module initialization."""
    capsule.add('/titan-hello',
                titan_upload_handler,
                protocol='titan')

Open "titan://localhost/titan-hello" to start the upload.


🍀 gritty [OP] · 2023-06-10 at 11:33:

@skyjake thank you! exactly what I was looking for, appreciate the detailed response. I was also wondering about extensions so that helps as well


🕹ī¸ skyjake [mod...] ¡ 2023-06-10 at 11:42:

No problem! I've been planning to write documentation like this and make it available on my capsule.


One more thing to note: the current version of GmCapsule requires that Titan uploads use a client certificate, i.e., no anonymous uploads are allowed. I need to add a config parameter for this.


— /s/GmCapsule-Issues/3


🍀 gritty [OP] · 2023-06-10 at 13:18:

@skyjake ah yes, I was wondering about the client cert prompts, makes sense now


Original Post


🌒 s/GmCapsule

Now that Bubble supports Titan I'm interested in trying it out on my capsule; however, the existing information on how to set it up server side isn't obvious to me. Anyone have some basic example on how to use Titan on your capsule? I'm using gmcapsule

đŸ’Ŧ gritty ¡ 7 comments ¡ 2 likes ¡ 2023-06-09 ¡ 1 year ago ¡ #python

-- Response ended

-- Page fetched on Sun Jun 2 14:58:31 2024