1
0
Fork 0
This commit is contained in:
Kekskurse 2021-03-08 00:51:33 +01:00
parent 74b1d52992
commit c998b2ec10
Signed by: kekskurse
GPG key ID: 728ACCB59341E7E4
60 changed files with 293 additions and 0 deletions

View file

@ -0,0 +1,13 @@
---
title: "Viktoriapark"
date: 2021-02-19T00:00:01+00:00
draft: false
categories: ["Images"]
description: "Viktoriapark"
startpage: false
lang: img
gallery: "/img/2021/02/viktoriapark/DSC08970.jpg"
cc: "by-nc-sa"
---
# Gallery
{{< gallery dir="/img/2021/02/viktoriapark" caption-position="none" caption-effect="fade" />}} {{< load-photoswipe >}}

View file

@ -0,0 +1,13 @@
---
title: "Oranienburg Lehnitz-Kanal"
date: 2021-02-24T00:00:01+00:00
draft: false
categories: ["Images"]
description: "Oranienburg Lehnitz-Kanal"
startpage: false
lang: img
gallery: "/img/2021/02/oranienburg-lehnitz-kanal/DSC09082.jpg"
cc: "by-nc-sa"
---
# Gallery
{{< gallery dir="/img/2021/02/oranienburg-lehnitz-kanal" caption-position="none" caption-effect="fade" />}} {{< load-photoswipe >}}

View file

@ -0,0 +1,14 @@
---
title: "SS-Brotfabrik Oranienburg"
date: 2021-02-24T00:00:01+00:00
draft: false
categories: ["Images"]
description: "SS-Brotfabrik Oranienburg"
startpage: false
lang: img
gallery: "/img/2021/02/ss-brotfabrik-oranienburg/DSC09147.jpg"
cc: "by-nc-sa"
---
In der 1939 geplanten und bis März 1941 gebaute Brotfabrik wurden bis zu 80 Häftlingen aus dem Hauptlager Sachsenhausen ab 1943 aus dem Klinkerwerk zur arbeit gezwungen. Das Gelände war von dem "Außenlager Klinkerwerk" durch einen Schießstand getrennt. Die Waren wurden für den Einsatz im Militär gebacken, eine versorgung der Zivilbevölkerung war nicht vorgesehen. Ab 1944 wurden auch andere Konzentrationslager mit Brot versorgt. Nach Kriegsende wurden die Maschienen demontiert und das Gelände von der Roten Arme zur medizinischen Versorgung der ehemaligen Häftlinge genutzt. Ab 1946 wurde der Backbetrieb als VEG wieder aufgenomme. Bis 1991 wurde in diesem Gebäude gebacken, danach wurde das Gelände verlassen.
# Gallery
{{< gallery dir="/img/2021/02/ss-brotfabrik-oranienburg" caption-position="none" caption-effect="fade" />}} {{< load-photoswipe >}}

View file

@ -0,0 +1,13 @@
---
title: "Von-der-Schulenburg-Park"
date: 2021-02-27T00:00:01+00:00
draft: false
categories: ["Images"]
description: "Von-der-Schulenburg-Park"
startpage: false
lang: img
gallery: "/img/2021/02/von-der-schulenburg-park/DSC09185.jpg"
cc: "by-nc-sa"
---
# Gallery
{{< gallery dir="/img/2021/02/von-der-schulenburg-park" caption-position="none" caption-effect="fade" />}} {{< load-photoswipe >}}

View file

@ -0,0 +1,13 @@
---
title: "Dorfkirche Tempelhof"
date: 2021-03-07T00:00:01+00:00
draft: false
categories: ["Images"]
description: "Dorfkirche Tempelhof"
startpage: false
lang: img
gallery: "/img/2021/03/dorfkirche-tempelhof/DSC09214.jpg"
cc: "by-nc-sa"
---
# Gallery
{{< gallery dir="/img/2021/03/dorfkirche-tempelhof" caption-position="none" caption-effect="fade" />}} {{< load-photoswipe >}}

View file

@ -0,0 +1,227 @@
---
title: "Using the signal-cli dbus interface in golang"
date: 2021-03-07T10:25:53+02:00
draft: false
description: "Using the signal-cli dbus interface in golang"
tags: ["Blog", "Go"]
categories: ["Programming"]
startpage: true
lang: en
---
The [signal-cli](https://github.com/AsamK/signal-cli) tool profieds a dbus interface to get and send messages from other programms. The Documentation for that is avalible in the [signal-cli wiki](https://github.com/AsamK/signal-cli/wiki/DBus-service) but that not so easy to understand if you never work with dbus before.
# Setup signal-cli
To setup signal-cli and pair it as secound device to an existing account you first need to install signal-cli, that steps based on your os. After you install it you can create a new "Pairing-Code" by runnuning `signal-cli link -n "mybot"`. The given code can used on the webpage [goqr.me](http://goqr.me/) to create an qr code, which you can scann with the signal app on your mobile device.
After that you can start signal-cli as deamon, for example with the following command with also print all incomming events as json on your cli:
```
signal-cli -u +49176XXXXXXX -o json daemon
```
# Getting Messages
First we need to connect to the DBus system, thats possible with the [godbus/dbus](https://github.com/godbus/dbus) package. The connection based on the example from the package is really easy:
```
conn, err := dbus.ConnectSessionBus()
if err != nil {
fmt.Fprintln(os.Stderr, "Failed to connect to session bus:", err)
return err
}
defer conn.Close()
```
After that we need to told the dbus package which messages we want to recive and create a channel where we can revice all signales. To got the signal messages the follwoing code works for me:
```
if err = conn.AddMatchSignal(
dbus.WithMatchInterface("org.asamk.Signal"),
); err != nil {
return err
}
c := make(chan *dbus.Signal, 10)
conn.Signal(c)
```
than we can "listen" to the channel and got the messages the signal-cli deamon sends:
```
for v := range c {
fmt.Println(v)
}
```
That will create mainly two signales im interested in, first getting a message from another conversation partner:
```
&{:1.34 /org/asamk/Signal org.asamk.Signal.MessageReceived [1615064176455 +49176XXXXXXXX [] Durchgefallen []] 11}
```
and secound getting a Sync Message, it will be send if yourself send a message from another device to a conversation partner:
```
&{:1.34 /org/asamk/Signal org.asamk.Signal.SyncMessageReceived [1615064055775 +49176XXXXXXXXX +49176XXXXXXX [] Ich bin ein test []] 8}
```
# Parsing Messages
If i just focus on 1:1 chats i could parse both kinds of events. Here two examples without error handling. First on the "Incomming Messages" :
```
type IncommingMessage struct {
Timestamp int64
Source string
Message string
Attachments []string
}
func parseMessageReceived(v *dbus.Signal) IncommingMessage {
msg := IncommingMessage{}
msg.Timestamp, _ = v.Body[0].(int64)
msg.Source = v.Body[1].(string)
msg.Message = v.Body[3].(string)
msg.Attachments = v.Body[4].([]string)
return msg
}
```
and for the Snyc Events:
```
type SyncMessage struct {
Timestamp int64
Source string
Destination string
Message string
Attachments []string
}
func parseSyncMessageReceived(v *dbus.Signal) SyncMessage {
msg := SyncMessage{}
msg.Timestamp, _ = v.Body[0].(int64)
msg.Source = v.Body[1].(string)
msg.Destination = v.Body[2].(string)
msg.Message = v.Body[4].(string)
msg.Attachments = v.Body[5].([]string)
return msg
}
```
That functions will return strucs you can easy use for your application.
# Sending Messages
For the sending we also need a dbus connection, but unlike in the receving message part we don't subscribe to the events we produse one which will be consumed by the signal-cli deamon and send as chat messages to the conversation. All other devices (like your mobile phone) will get a SyncMessage event and show that "new" message too.
First you need to create the connection like before:
```
conn, err := dbus.ConnectSessionBus()
if err != nil {
fmt.Fprintln(os.Stderr, "Failed to connect to session bus:", err)
os.Exit(1)
}
defer conn.Close()
```
after that just send a call like this:
```
obj := conn.Object("org.asamk.Signal", "/org/asamk/Signal")
call := obj.Call("org.asamk.Signal.sendMessage",0, "Your really cool message", []string{}, "+49176XXXXXXX")
if call.Err != nil {
panic(call.Err)
}
```
# Example
Here an "full" example of getting messages (without error handling)
```
func listenToDbus() error {
conn, err := dbus.ConnectSessionBus()
if err != nil {
fmt.Fprintln(os.Stderr, "Failed to connect to session bus:", err)
return err
}
defer conn.Close()
if err = conn.AddMatchSignal(
dbus.WithMatchInterface("org.asamk.Signal"),
); err != nil {
return err
}
c := make(chan *dbus.Signal, 10)
conn.Signal(c)
for v := range c {
if v.Name == "org.asamk.Signal.SyncMessageReceived" {
msg := parseSyncMessageReceived(v)
// do something with msg like a callback
}
if v.Name == "org.asamk.Signal.MessageReceived" {
msg := parseMessageReceived(v)
// do something with msg like a callback
}
}
return nil
}
type SyncMessage struct {
Timestamp int64
Source string
Destination string
Message string
Attachments []string
}
func parseSyncMessageReceived(v *dbus.Signal) SyncMessage {
msg := SyncMessage{}
msg.Timestamp, _ = v.Body[0].(int64)
msg.Source = v.Body[1].(string)
msg.Destination = v.Body[2].(string)
msg.Message = v.Body[4].(string)
msg.Attachments = v.Body[5].([]string)
return msg
}
type IncommingMessage struct {
Timestamp int64
Source string
Message string
Attachments []string
}
func parseMessageReceived(v *dbus.Signal) IncommingMessage {
msg := IncommingMessage{}
msg.Timestamp, _ = v.Body[0].(int64)
msg.Source = v.Body[1].(string)
msg.Message = v.Body[3].(string)
msg.Attachments = v.Body[4].([]string)
return msg
}
```
and another one to sending messages:
```
func SendMessage(to string, msg string) {
conn, err := dbus.ConnectSessionBus()
if err != nil {
fmt.Fprintln(os.Stderr, "Failed to connect to session bus:", err)
os.Exit(1)
}
defer conn.Close()
obj := conn.Object("org.asamk.Signal", "/org/asamk/Signal")
call := obj.Call("org.asamk.Signal.sendMessage",0, msg, []string{}, to)
if call.Err != nil {
panic(call.Err)
}
}
```

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 993 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1,014 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 969 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 926 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 916 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 906 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 949 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 950 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 775 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 838 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 941 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 909 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 762 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 836 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 780 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1,013 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 991 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 719 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 906 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 875 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1,016 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 MiB