Bootleg bot: Difference between revisions

From XPUB & Lens-Based wiki
No edit summary
 
(11 intermediate revisions by 2 users not shown)
Line 1: Line 1:
This page is prepared for the prototyping class on 3 March 2026 as part of SI29 and follows a Special Issue day with Doriane and Simon fully on topic of [[The bootleg library]].
''This page is prepared for the prototyping class on 3 March 2026 as part of SI29 and follows a Special Issue day with Doriane and Simon fully on topic of [[The bootleg library]].''


==Networking==
https://git.xpub.nl/kamo/bot-magic-words


🟣 = a device (server/laptop/phone/...)
🟡 = a network


We will go through the following commands from 🟣 sergio.
==the zulip bot==


So the first step is to log into 🟣 sergio:
First install the requirements listed on this page:  


ssh sergio
https://zulip.com/help/writing-bots


To which networks is 🟣 sergio connected right now?
You can run the bot with:


  ip a
  zulip-run-bot --config-file bootlegbot.zuliprc bootlegbot.py


To which networks is 🟣 the bootleg library connected right now?
(or <code>uv run zulip-run-bot --config-file bootlegbot.zuliprc bootlegbot.py</code> if you are using uv)


<pre>
===bootlegbot.py===
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
      valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
      valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether dc:a6:32:54:34:1c brd ff:ff:ff:ff:ff:ff
    inet 145.24.153.55/23 brd 145.24.153.255 scope global dynamic noprefixroute eth0
      valid_lft 207029sec preferred_lft 174629sec
    inet6 fe80::9e59:5f86:ee6:e86d/64 scope link
      valid_lft forever preferred_lft forever
3: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether dc:a6:32:54:34:1e brd ff:ff:ff:ff:ff:ff
    inet 10.9.8.1/24 brd 10.9.8.255 scope global noprefixroute wlan0
      valid_lft forever preferred_lft forever
    inet6 fe80::9724:36ee:d995:558e/64 scope link
      valid_lft forever preferred_lft forever
4: hub: <POINTOPOINT,MULTICAST,NOARP,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UNKNOWN group default qlen 500
    link/none
    inet 10.0.0.103/24 scope global hub
      valid_lft forever preferred_lft forever
    inet6 fe80::6fce:6106:9b56:33db/64 scope link stable-privacy
      valid_lft forever preferred_lft forever
</pre>


Is 🟣 sergio part of the same network as 🟣 the bootleg library is?
<syntaxhighlight lang="python">
class BootlegBot(object):
    '''
    This is a small zulip bot to interact with the 👢🦵 library
    '''


...
    def usage(self):
        return '''Ask the bot about a book and they will search for it in the 👢🦵 library'''


How can we check if we can communicate with 🟣 the bootleg library through this network?
    def handle_message(self, message, bot_handler):
        # This happens when someone write to the bot


ping ip-address
        sender = message['sender_full_name']
        content = message['content']
        print(f'{sender} wrote to the bot: "{content}"')


Let's first check 🟡 the XPUB HUB (see all HUB servers listed [[HUB|here]])
handler_class = BootlegBot
</syntaxhighlight>


ping 10.0.0.103
===bootlegbot.zuliprc===


Who else is on 🟡 the HUB network right now?
<pre>
 
[api]
nmap 10.0.0.*
email=bootleg-bot@zulip.xpub.nl
 
key=XXXXXXXX
And who else is on 🟡 eduroam right now? (in the same subnet)
site=https://zulip.xpub.nl
 
</pre>
nmap 145.24.152.*
 
Can we reach 🟣 the bootleg library through 🟡 eduroam?
 
ping 145.24.153.55
 
We can make such a mapping because we are part of the same LAN network.
 
LAN = local area network
 
Let's take a short side step.
 
We want to make a zulip bot. Which network do we use everyday to connect to 🟣 the XPUB zulip server?
 
ping zulip.xpub.nl
<check your ip address from your device>
 
How does such a zulip connection travel?
 
traceroute zulip.xpub.nl
 
We can trace this route because all the "hops" are done on 🟡 the public internet (the WAN).
 
WAN = wider area network, aka the internet
 
So to summarize, these devices are part of the following networks:
 
🟣 bootleg library: 🟡 10.0.0.103 + 🟡 145.24.153.55
🟣 sergio:
🟣 your laptop:
🟣 XPUB zulip server:
 
With an important footnote: we're not sure if it was intentional to have 🟣 the bootleg library on 🟡 eduroam. So let's keep in mind that we will most likely loose this connection.
 
Which 🟣 device can we use to run a bot that connects the 🟣 XPUB zulip server to 🟣 the bootleg library (on 🟡 the HUB), keeping in mind that the whole goal of this is to connect to 🟣 the bootleg library from 🟡 the WAN?
 
...
 
How can we connect 🟣 our device (on 🟡 WAN) to 🟣 sergio (on 🟡 eduroam + 🟡 HUB) to connect to 🟣 the bootleg library (on 🟡 eduroam + 🟡 HUB)?
 
in many ways...
 
But which option will we focus on today?
 
SSH tunnelling!
 
==SSH tunnelling==
 
https://ittavern.com/visual-guide-to-ssh-tunneling-and-port-forwarding/
 
(After having written this... I think we need to simplify this step and only use the xpub user on sergio...)


From your device, ssh into the bootleg library using a SSH tunnel:
We need to share the key with each other somehow.


ssh -J sergio pi@10.0.0.103
===Zulip bot API===


From $ man ssh:
https://zulip.com/help/interactive-bots-api


-J destination
==hello Python!==
 
Connect to the target host by first making a ssh connection to the jump host described by destination and then establishing a TCP forwarding to the ultimate destination from there. Multiple jump hops may be specified separated by comma characters. This is a shortcut to specify a ProxyJump configuration directive.


===Install your SSH key on the bootleg library===
see: [[Hello Python]]


If you get a "publickey denied" error, you need to install a SSH key of your user on sergio to the bootleg library.
==SSH to bootleg library==


First generate a SSH key.  
There are two ways in which we can do this.


ssh-keygen -t ed25519
===laptop > sergio > bootleg library (from outside the school)===
 
Find the public key:
 
cd .ssh
cat id_ed25519.pub
 
Copy the output.
 
Log in to the bootleg library with the xpub user on sergio:


  ssh sergio
  ssh sergio
  sudo su - xpub
  sudo su - xpub
  sudo pi@10.0.0.103
  ssh pi@10.0.0.103


This works, and without password, because the SSH keys of xpub@sergio are already installed at pi@bootleglibrary.
===laptop > bootleg library (on eduroam)===
ssh pi@145.24.153.55


Move to the .ssh folder:
==read database==


cd .ssh
* Simon and Luke made this Python script in 2021, to make the temporary index cards: https://git.vvvvvvaria.org/simoon/temporary-indexing
* documentation of sqlite module in Python: https://docs.python.org/3/library/sqlite3.html


Open the authorized keys file:
==write to database==


nano authorized_keys
* a standalone webform for file uploads
* using the bootleg library upload URLs
* hosted on sergio (but can be hosted on another sandbox too in the future)


Paste your public key!
==See also==


Now try the tunnel again.
* [[The bootleg library]] main documentation page of the bootleg library project
 
* https://cc.practices.tools/etherdot/bootleg-library/ graph based story of the bootleg library project
 
==Writing the zulip bot==
 
<syntaxhighlight lang="python">
class BootlegBot(object):
    '''
    This is a small zulip bot to interact with the 👢🦵 library
    '''
 
    def usage(self):
        return '''Ask the bot about a book and they will search for it in the 👢🦵 library'''
 
    def handle_message(self, message, bot_handler):
        # This happens when someone write to the bot
 
        sender = message['sender_full_name']
        content = message['content']
        print(f'{sender} wrote to the bot: "{content}"')
 
handler_class = BootlegBot
</syntaxhighlight>


[[Category:Workbooks]]
[[Category:Workbooks]]

Latest revision as of 11:20, 24 March 2026

This page is prepared for the prototyping class on 3 March 2026 as part of SI29 and follows a Special Issue day with Doriane and Simon fully on topic of The bootleg library.

https://git.xpub.nl/kamo/bot-magic-words


the zulip bot

First install the requirements listed on this page:

https://zulip.com/help/writing-bots

You can run the bot with:

zulip-run-bot --config-file bootlegbot.zuliprc bootlegbot.py

(or uv run zulip-run-bot --config-file bootlegbot.zuliprc bootlegbot.py if you are using uv)

bootlegbot.py

class BootlegBot(object):
    '''
    This is a small zulip bot to interact with the 👢🦵 library
    '''

    def usage(self):
        return '''Ask the bot about a book and they will search for it in the 👢🦵 library'''

    def handle_message(self, message, bot_handler):
        # This happens when someone write to the bot

        sender = message['sender_full_name']
        content = message['content']
        print(f'{sender} wrote to the bot: "{content}"')

handler_class = BootlegBot

bootlegbot.zuliprc

[api]
email=bootleg-bot@zulip.xpub.nl
key=XXXXXXXX
site=https://zulip.xpub.nl

We need to share the key with each other somehow.

Zulip bot API

https://zulip.com/help/interactive-bots-api

hello Python!

see: Hello Python

SSH to bootleg library

There are two ways in which we can do this.

laptop > sergio > bootleg library (from outside the school)

ssh sergio
sudo su - xpub
ssh pi@10.0.0.103

laptop > bootleg library (on eduroam)

ssh pi@145.24.153.55

read database

write to database

  • a standalone webform for file uploads
  • using the bootleg library upload URLs
  • hosted on sergio (but can be hosted on another sandbox too in the future)

See also