Compare commits

..

2 Commits

Author SHA1 Message Date
Lukas f. Paluch
e3ae4dabed
Merge f27a3c5206fead40d77aebac4424397b58be7f94 into 57141615675e7000c700ba1e5eb38ecb5c7d6486 2025-12-29 16:10:10 +01:00
Bernhard B
5714161567 fixed bug in json-rpc mode
* handle 'trust-new-identities' setting in json-rpc mode

see #771
2025-12-08 22:40:03 +01:00
3 changed files with 24 additions and 8 deletions

View File

@ -156,3 +156,4 @@ There are a bunch of environmental variables that can be set inside the docker c
* `JSON_RPC_IGNORE_ATTACHMENTS`: When set to `true`, attachments are not automatically downloaded in json-rpc mode (default: `false`)
* `JSON_RPC_IGNORE_STORIES`: When set to `true`, stories are not automatically downloaded in json-rpc mode (default: `false`)
* `JSON_RPC_TRUST_NEW_IDENTITIES`: Choose how to trust new identities in json-rpc mode. Supported values: `on-first-use`, `always`, `never`. (default: `on-first-use`)

View File

@ -2296,8 +2296,12 @@ func (s *SignalClient) ListDevices(number string) ([]ListDevicesResponse, error)
}
func (s *SignalClient) SetTrustMode(number string, trustMode utils.SignalCliTrustMode) error {
if s.signalCliMode == JsonRpc {
return errors.New("Not supported in json-rpc mode, use the environment variable JSON_RPC_TRUST_NEW_IDENTITIES instead!")
} else {
s.signalCliApiConfig.SetTrustModeForNumber(number, trustMode)
return s.signalCliApiConfig.Persist()
}
}
func (s *SignalClient) GetTrustMode(number string) utils.SignalCliTrustMode {

View File

@ -2,18 +2,19 @@ package main
import (
"fmt"
"github.com/bbernhard/signal-cli-rest-api/utils"
log "github.com/sirupsen/logrus"
"io/ioutil"
"os"
"os/exec"
"strings"
"github.com/bbernhard/signal-cli-rest-api/utils"
log "github.com/sirupsen/logrus"
)
const supervisorctlConfigTemplate = `
[program:%s]
process_name=%s
command=bash -c "nc -l -p %d <%s | signal-cli --output=json --config %s jsonRpc%s%s >%s"
command=bash -c "nc -l -p %d <%s | signal-cli --output=json --config %s%s jsonRpc%s%s >%s"
autostart=true
autorestart=true
startretries=10
@ -77,17 +78,27 @@ func main() {
log.Fatal("Couldn't create log folder ", supervisorctlLogFolder, ": ", err.Error())
}
trustNewIdentities := ""
trustNewIdentitiesEnv := utils.GetEnv("JSON_RPC_TRUST_NEW_IDENTITIES", "")
if trustNewIdentitiesEnv == "on-first-use" {
trustNewIdentities = " --trust-new-identities on-first-use"
} else if trustNewIdentitiesEnv == "always" {
trustNewIdentities = " --trust-new-identities always"
} else if trustNewIdentitiesEnv == "never" {
trustNewIdentities = " --trust-new-identities never"
} else if trustNewIdentitiesEnv != "" {
log.Fatal("Invalid JSON_RPC_TRUST_NEW_IDENTITIES environment variable set!")
}
log.Info("Updated jsonrpc2.yml")
//write supervisorctl config
supervisorctlConfigFilename := "/etc/supervisor/conf.d/" + "signal-cli-json-rpc-1.conf"
supervisorctlConfig := fmt.Sprintf(supervisorctlConfigTemplate, supervisorctlProgramName, supervisorctlProgramName,
tcpPort, fifoPathname, signalCliConfigDir, signalCliIgnoreAttachments, signalCliIgnoreStories, fifoPathname,
tcpPort, fifoPathname, signalCliConfigDir, trustNewIdentities, signalCliIgnoreAttachments, signalCliIgnoreStories, fifoPathname,
supervisorctlProgramName, supervisorctlProgramName)
err = ioutil.WriteFile(supervisorctlConfigFilename, []byte(supervisorctlConfig), 0644)
if err != nil {
log.Fatal("Couldn't write ", supervisorctlConfigFilename, ": ", err.Error())