mirror of
https://github.com/bbernhard/signal-cli-rest-api.git
synced 2026-05-17 13:20:16 +00:00
Compare commits
4 Commits
10d7a8d4ce
...
e3ae4dabed
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e3ae4dabed | ||
|
|
5714161567 | ||
|
|
f27a3c5206 | ||
|
|
1be5684ae3 |
@ -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`)
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
@ -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 {
|
||||
|
||||
@ -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 {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user