Compare commits

...

4 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
Lukas Paluch
f27a3c5206
fix rootless entrypoint - clarify and append jsonrpc
- rework statemant to be more clear
    - append check of json-rpc mode to rootless part
2024-02-27 08:54:33 +01:00
Lukas f. Paluch
1be5684ae3
enable rootless start
fixes bbernhard/signal-cli-rest-api#490
2024-02-23 15:10:57 +01:00
4 changed files with 43 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

@ -3,8 +3,27 @@
set -x
set -e
[ -d /etc/docker ] && echo "$FILE is a directory."
[ -z "${SIGNAL_CLI_CONFIG_DIR}" ] && echo "SIGNAL_CLI_CONFIG_DIR environmental variable needs to be set! Aborting!" && exit 1;
if [ "$(id -u)" -eq "${SIGNAL_CLI_UID}" ] && [ "$(id -g)" -eq "${SIGNAL_CLI_GID}" ]]
then
echo "UID and GID are already correct. Trying to start Signal Api"
# TODO: check mode
if [ "$MODE" = "json-rpc" ]
then
/usr/bin/jsonrpc2-helper
if [ -n "$JAVA_OPTS" ] ; then
echo "export JAVA_OPTS='$JAVA_OPTS'" >> /etc/default/supervisor
fi
service supervisor start
supervisorctl start all
fi
signal-cli-rest-api -signal-cli-config=${SIGNAL_CLI_CONFIG_DIR};
fi
usermod -u ${SIGNAL_CLI_UID} signal-api
groupmod -o -g ${SIGNAL_CLI_GID} signal-api

View File

@ -2296,8 +2296,12 @@ func (s *SignalClient) ListDevices(number string) ([]ListDevicesResponse, error)
}
func (s *SignalClient) SetTrustMode(number string, trustMode utils.SignalCliTrustMode) error {
s.signalCliApiConfig.SetTrustModeForNumber(number, trustMode)
return s.signalCliApiConfig.Persist()
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,16 +78,26 @@ 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 {