mirror of
https://github.com/bbernhard/signal-cli-rest-api.git
synced 2026-05-22 14:04:28 +00:00
Compare commits
11 Commits
a5a4fa4ac4
...
396c30f75a
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
396c30f75a | ||
|
|
d11faf3714 | ||
|
|
a15e6ef409 | ||
|
|
76511ae14f | ||
|
|
fcc62a7fe7 | ||
|
|
05235bd7ae | ||
|
|
d7ffe54883 | ||
|
|
2760fe0b70 | ||
|
|
4fb1be6657 | ||
|
|
877bc9e845 | ||
|
|
a6b4392fd7 |
@ -1,6 +1,6 @@
|
|||||||
ARG SIGNAL_CLI_VERSION=0.14.0
|
ARG SIGNAL_CLI_VERSION=0.14.1
|
||||||
ARG LIBSIGNAL_CLIENT_VERSION=0.87.4
|
ARG LIBSIGNAL_CLIENT_VERSION=0.87.4
|
||||||
ARG SIGNAL_CLI_NATIVE_PACKAGE_VERSION=0.14.0+morph027+5
|
ARG SIGNAL_CLI_NATIVE_PACKAGE_VERSION=0.14.1+morph027+1
|
||||||
|
|
||||||
ARG SWAG_VERSION=1.16.4
|
ARG SWAG_VERSION=1.16.4
|
||||||
ARG GRAALVM_VERSION=25.0.2
|
ARG GRAALVM_VERSION=25.0.2
|
||||||
@ -210,8 +210,6 @@ ENV SIGNAL_CLI_UID=1000
|
|||||||
ENV SIGNAL_CLI_GID=1000
|
ENV SIGNAL_CLI_GID=1000
|
||||||
ENV SIGNAL_CLI_CHOWN_ON_STARTUP=true
|
ENV SIGNAL_CLI_CHOWN_ON_STARTUP=true
|
||||||
|
|
||||||
RUN chown -R 1000:1000 /var/log/
|
|
||||||
|
|
||||||
ENTRYPOINT ["/entrypoint.sh"]
|
ENTRYPOINT ["/entrypoint.sh"]
|
||||||
|
|
||||||
HEALTHCHECK --interval=20s --timeout=10s --retries=3 \
|
HEALTHCHECK --interval=20s --timeout=10s --retries=3 \
|
||||||
|
|||||||
@ -156,4 +156,6 @@ 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_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_IGNORE_STORIES`: When set to `true`, stories are not automatically downloaded in json-rpc mode (default: `false`)
|
||||||
|
* `JSON_RPC_IGNORE_AVATARS`: When set to `true`, avatars are not automatically downloaded in json-rpc mode (default: `false`)
|
||||||
|
* `JSON_RPC_IGNORE_STICKERS`: When set to `true`, sticker packs 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`)
|
* `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`)
|
||||||
|
|||||||
@ -1,22 +1,11 @@
|
|||||||
services:
|
services:
|
||||||
signal-cli-rest-api:
|
signal-cli-rest-api:
|
||||||
#image: bbernhard/signal-cli-rest-api:latest-dev
|
image: bbernhard/signal-cli-rest-api:latest
|
||||||
build: "."
|
|
||||||
environment:
|
environment:
|
||||||
- MODE=normal #supported modes: json-rpc, json-rpc-native, native, normal
|
- MODE=normal #supported modes: json-rpc, native, normal
|
||||||
- ENABLE_PLUGINS=true
|
|
||||||
- DEFAULT_SIGNAL_TEXT_MODE=styled
|
|
||||||
- SWAGGER_IP=127.0.0.1
|
|
||||||
- PODMAN_USERNS=keep-id
|
|
||||||
#- JSON_RPC_IGNORE_ATTACHMENTS=true
|
|
||||||
#- JSON_RPC_IGNORE_STORIES=true
|
|
||||||
#- RECEIVE_WEBHOOK_URL=http://127.0.0.1:8089/webhook
|
|
||||||
#- JSON_RPC_TRUST_NEW_IDENTITIES=always
|
|
||||||
#- RECEIVE_WEBHOOK_URL=http://127.0.0.1:8080/v1/plugins/abc
|
|
||||||
#- AUTO_RECEIVE_SCHEDULE=0 22 * * * #enable this parameter on demand (see description below)
|
#- AUTO_RECEIVE_SCHEDULE=0 22 * * * #enable this parameter on demand (see description below)
|
||||||
#network_mode: host
|
|
||||||
ports:
|
ports:
|
||||||
- "8080:8080" #map docker port 8080 to host port 8080.
|
- "8080:8080" #map docker port 8080 to host port 8080.
|
||||||
volumes:
|
volumes:
|
||||||
- "./signal-cli-config:/home/.local/share/signal-cli" #map "signal-cli-config" folder on host system into docker container. the folder contains the password and cryptographic keys when a new number is registered
|
- "./signal-cli-config:/home/.local/share/signal-cli" #map "signal-cli-config" folder on host system into docker container. the folder contains the password and cryptographic keys when a new number is registered
|
||||||
- "./plugins:/plugins"
|
|
||||||
|
|||||||
@ -4,40 +4,57 @@ set -x
|
|||||||
set -e
|
set -e
|
||||||
|
|
||||||
[ -z "${SIGNAL_CLI_CONFIG_DIR}" ] && echo "SIGNAL_CLI_CONFIG_DIR environmental variable needs to be set! Aborting!" && exit 1;
|
[ -z "${SIGNAL_CLI_CONFIG_DIR}" ] && echo "SIGNAL_CLI_CONFIG_DIR environmental variable needs to be set! Aborting!" && exit 1;
|
||||||
|
[ -z "${SIGNAL_CLI_UID}" ] && echo "SIGNAL_CLI_UID environmental variable needs to be set! Aborting!" && exit 1;
|
||||||
|
[ -z "${SIGNAL_CLI_GID}" ] && echo "SIGNAL_CLI_GID environmental variable needs to be set! Aborting!" && exit 1;
|
||||||
|
|
||||||
usermod -u ${SIGNAL_CLI_UID} signal-api
|
# Check if we are already running as the target user and group
|
||||||
groupmod -o -g ${SIGNAL_CLI_GID} signal-api
|
RUNNING_AS_TARGET_USER=false
|
||||||
|
if [ "$(id -u)" -eq "${SIGNAL_CLI_UID}" ] && [ "$(id -g)" -eq "${SIGNAL_CLI_GID}" ]; then
|
||||||
# Fix permissions to ensure backward compatibility if SIGNAL_CLI_CHOWN_ON_STARTUP is not set to "false"
|
RUNNING_AS_TARGET_USER=true
|
||||||
if [ "$SIGNAL_CLI_CHOWN_ON_STARTUP" != "false" ]; then
|
|
||||||
echo "Changing ownership of ${SIGNAL_CLI_CONFIG_DIR} to ${SIGNAL_CLI_UID}:${SIGNAL_CLI_GID}"
|
|
||||||
chown ${SIGNAL_CLI_UID}:${SIGNAL_CLI_GID} -R ${SIGNAL_CLI_CONFIG_DIR}
|
|
||||||
else
|
|
||||||
echo "Skipping chown on startup since SIGNAL_CLI_CHOWN_ON_STARTUP is set to 'false'"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Show warning on docker exec
|
if [ "$RUNNING_AS_TARGET_USER" = "true" ]; then
|
||||||
cat <<EOF >> /root/.bashrc
|
echo "Already running as UID ${SIGNAL_CLI_UID} and GID ${SIGNAL_CLI_GID}. Skipping privileged operations."
|
||||||
|
else
|
||||||
|
echo "Adjusting user and group IDs to ${SIGNAL_CLI_UID}:${SIGNAL_CLI_GID}"
|
||||||
|
usermod -u "${SIGNAL_CLI_UID}" signal-api
|
||||||
|
groupmod -o -g "${SIGNAL_CLI_GID}" signal-api
|
||||||
|
|
||||||
|
# Fix permissions to ensure backward compatibility if SIGNAL_CLI_CHOWN_ON_STARTUP is not set to "false"
|
||||||
|
if [ "$SIGNAL_CLI_CHOWN_ON_STARTUP" != "false" ]; then
|
||||||
|
echo "Changing ownership of ${SIGNAL_CLI_CONFIG_DIR} to ${SIGNAL_CLI_UID}:${SIGNAL_CLI_GID}"
|
||||||
|
chown "${SIGNAL_CLI_UID}":"${SIGNAL_CLI_GID}" -R "${SIGNAL_CLI_CONFIG_DIR}"
|
||||||
|
else
|
||||||
|
echo "Skipping chown on startup since SIGNAL_CLI_CHOWN_ON_STARTUP is set to 'false'"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Show warning on docker exec
|
||||||
|
cat <<EOF >> /root/.bashrc
|
||||||
echo "WARNING: signal-cli-rest-api runs as signal-api (not as root!)"
|
echo "WARNING: signal-cli-rest-api runs as signal-api (not as root!)"
|
||||||
echo "Run 'su signal-api' before using signal-cli!"
|
echo "Run 'su signal-api' before using signal-cli!"
|
||||||
echo "If you want to use signal-cli directly, don't forget to specify the config directory. e.g: \"signal-cli --config ${SIGNAL_CLI_CONFIG_DIR}\""
|
echo "If you want to use signal-cli directly, don't forget to specify the config directory. e.g: \"signal-cli --config ${SIGNAL_CLI_CONFIG_DIR}\""
|
||||||
EOF
|
EOF
|
||||||
|
fi
|
||||||
cap_prefix="-cap_"
|
|
||||||
caps="$cap_prefix$(seq -s ",$cap_prefix" 0 $(cat /proc/sys/kernel/cap_last_cap))"
|
|
||||||
|
|
||||||
# TODO: check mode
|
# TODO: check mode
|
||||||
if [ "$MODE" = "json-rpc" ]
|
if [ "$MODE" = "json-rpc" ]; then
|
||||||
then
|
/usr/bin/jsonrpc2-helper
|
||||||
/usr/bin/jsonrpc2-helper
|
if [ -n "$JAVA_OPTS" ]; then
|
||||||
if [ -n "$JAVA_OPTS" ] ; then
|
echo "export JAVA_OPTS='$JAVA_OPTS'" >> /etc/default/supervisor
|
||||||
echo "export JAVA_OPTS='$JAVA_OPTS'" >> /etc/default/supervisor
|
fi
|
||||||
fi
|
service supervisor start
|
||||||
service supervisor start
|
supervisorctl start all
|
||||||
supervisorctl start all
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
export HOST_IP=$(hostname -I | awk '{print $1}')
|
export HOST_IP=$(hostname -I | awk '{print $1}')
|
||||||
|
|
||||||
# Start API as signal-api user
|
# Start API as signal-api user
|
||||||
exec setpriv --reuid=${SIGNAL_CLI_UID} --regid=${SIGNAL_CLI_GID} --init-groups --inh-caps=$caps signal-cli-rest-api -signal-cli-config=${SIGNAL_CLI_CONFIG_DIR}
|
if [ "$RUNNING_AS_TARGET_USER" = "true" ]; then
|
||||||
|
# Already running as the target user, start directly
|
||||||
|
exec signal-cli-rest-api -signal-cli-config="${SIGNAL_CLI_CONFIG_DIR}"
|
||||||
|
else
|
||||||
|
# Use setpriv to switch to target user
|
||||||
|
cap_prefix="-cap_"
|
||||||
|
caps="$cap_prefix$(seq -s ",$cap_prefix" 0 $(cat /proc/sys/kernel/cap_last_cap))"
|
||||||
|
exec setpriv --reuid="${SIGNAL_CLI_UID}" --regid="${SIGNAL_CLI_GID}" --init-groups --inh-caps="$caps" signal-cli-rest-api -signal-cli-config="${SIGNAL_CLI_CONFIG_DIR}"
|
||||||
|
fi
|
||||||
|
|||||||
@ -670,6 +670,8 @@ func StringToBool(input string) bool {
|
|||||||
// @Param timeout query string false "Receive timeout in seconds (default: 1)"
|
// @Param timeout query string false "Receive timeout in seconds (default: 1)"
|
||||||
// @Param ignore_attachments query string false "Specify whether the attachments of the received message should be ignored" (default: false)"
|
// @Param ignore_attachments query string false "Specify whether the attachments of the received message should be ignored" (default: false)"
|
||||||
// @Param ignore_stories query string false "Specify whether stories should be ignored when receiving messages" (default: false)"
|
// @Param ignore_stories query string false "Specify whether stories should be ignored when receiving messages" (default: false)"
|
||||||
|
// @Param ignore_avatars query string false "Specify whether avatar downloads should be ignored when receiving messages" (default: false)"
|
||||||
|
// @Param ignore_stickers query string false "Specify whether sticker pack downloads should be ignored when receiving messages" (default: false)"
|
||||||
// @Param max_messages query string false "Specify the maximum number of messages to receive (default: unlimited)". Not available in json-rpc mode.
|
// @Param max_messages query string false "Specify the maximum number of messages to receive (default: unlimited)". Not available in json-rpc mode.
|
||||||
// @Param send_read_receipts query string false "Specify whether read receipts should be sent when receiving messages" (default: false)"
|
// @Param send_read_receipts query string false "Specify whether read receipts should be sent when receiving messages" (default: false)"
|
||||||
// @Router /v1/receive/{number} [get]
|
// @Router /v1/receive/{number} [get]
|
||||||
@ -718,13 +720,25 @@ func (a *Api) Receive(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ignoreAvatars := c.DefaultQuery("ignore_avatars", "false")
|
||||||
|
if ignoreAvatars != "true" && ignoreAvatars != "false" {
|
||||||
|
c.JSON(400, Error{Msg: "Couldn't process request - ignore_avatars parameter needs to be either 'true' or 'false'"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
ignoreStickers := c.DefaultQuery("ignore_stickers", "false")
|
||||||
|
if ignoreStickers != "true" && ignoreStickers != "false" {
|
||||||
|
c.JSON(400, Error{Msg: "Couldn't process request - ignore_stickers parameter needs to be either 'true' or 'false'"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
sendReadReceipts := c.DefaultQuery("send_read_receipts", "false")
|
sendReadReceipts := c.DefaultQuery("send_read_receipts", "false")
|
||||||
if sendReadReceipts != "true" && sendReadReceipts != "false" {
|
if sendReadReceipts != "true" && sendReadReceipts != "false" {
|
||||||
c.JSON(400, Error{Msg: "Couldn't process request - send_read_receipts parameter needs to be either 'true' or 'false'"})
|
c.JSON(400, Error{Msg: "Couldn't process request - send_read_receipts parameter needs to be either 'true' or 'false'"})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
jsonStr, err := a.signalClient.Receive(number, timeoutInt, StringToBool(ignoreAttachments), StringToBool(ignoreStories), maxMessagesInt, StringToBool(sendReadReceipts))
|
jsonStr, err := a.signalClient.Receive(number, timeoutInt, StringToBool(ignoreAttachments), StringToBool(ignoreStories), StringToBool(ignoreAvatars), StringToBool(ignoreStickers), maxMessagesInt, StringToBool(sendReadReceipts))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.JSON(400, Error{Msg: err.Error()})
|
c.JSON(400, Error{Msg: err.Error()})
|
||||||
return
|
return
|
||||||
@ -843,7 +857,6 @@ func (a *Api) AddMembersToGroup(c *gin.Context) {
|
|||||||
|
|
||||||
err = a.signalClient.AddMembersToGroup(number, groupId, req.Members)
|
err = a.signalClient.AddMembersToGroup(number, groupId, req.Members)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Info("ERR NOT NULL")
|
|
||||||
switch err.(type) {
|
switch err.(type) {
|
||||||
case *client.NotFoundError:
|
case *client.NotFoundError:
|
||||||
c.JSON(404, Error{Msg: err.Error()})
|
c.JSON(404, Error{Msg: err.Error()})
|
||||||
|
|||||||
@ -993,7 +993,7 @@ func (s *SignalClient) SendV2(number string, message string, recps []string, bas
|
|||||||
return ×tamps, nil
|
return ×tamps, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *SignalClient) Receive(number string, timeout int64, ignoreAttachments bool, ignoreStories bool, maxMessages int64, sendReadReceipts bool) (string, error) {
|
func (s *SignalClient) Receive(number string, timeout int64, ignoreAttachments bool, ignoreStories bool, ignoreAvatars bool, ignoreStickers bool, maxMessages int64, sendReadReceipts bool) (string, error) {
|
||||||
if s.signalCliMode == JsonRpc {
|
if s.signalCliMode == JsonRpc {
|
||||||
return "", errors.New("Not implemented")
|
return "", errors.New("Not implemented")
|
||||||
} else {
|
} else {
|
||||||
@ -1007,6 +1007,14 @@ func (s *SignalClient) Receive(number string, timeout int64, ignoreAttachments b
|
|||||||
command = append(command, "--ignore-stories")
|
command = append(command, "--ignore-stories")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ignoreAvatars {
|
||||||
|
command = append(command, "--ignore-avatars")
|
||||||
|
}
|
||||||
|
|
||||||
|
if ignoreStickers {
|
||||||
|
command = append(command, "--ignore-stickers")
|
||||||
|
}
|
||||||
|
|
||||||
if maxMessages > 0 {
|
if maxMessages > 0 {
|
||||||
command = append(command, "--max-messages")
|
command = append(command, "--max-messages")
|
||||||
command = append(command, strconv.FormatInt(maxMessages, 10))
|
command = append(command, strconv.FormatInt(maxMessages, 10))
|
||||||
|
|||||||
@ -2043,6 +2043,18 @@ const docTemplate = `{
|
|||||||
"name": "ignore_stories",
|
"name": "ignore_stories",
|
||||||
"in": "query"
|
"in": "query"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"type": "string",
|
||||||
|
"description": "Specify whether avatar downloads should be ignored when receiving messages",
|
||||||
|
"name": "ignore_avatars",
|
||||||
|
"in": "query"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "string",
|
||||||
|
"description": "Specify whether sticker pack downloads should be ignored when receiving messages",
|
||||||
|
"name": "ignore_stickers",
|
||||||
|
"in": "query"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"description": "Specify the maximum number of messages to receive (default: unlimited)",
|
"description": "Specify the maximum number of messages to receive (default: unlimited)",
|
||||||
|
|||||||
@ -2040,6 +2040,18 @@
|
|||||||
"name": "ignore_stories",
|
"name": "ignore_stories",
|
||||||
"in": "query"
|
"in": "query"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"type": "string",
|
||||||
|
"description": "Specify whether avatar downloads should be ignored when receiving messages",
|
||||||
|
"name": "ignore_avatars",
|
||||||
|
"in": "query"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "string",
|
||||||
|
"description": "Specify whether sticker pack downloads should be ignored when receiving messages",
|
||||||
|
"name": "ignore_stickers",
|
||||||
|
"in": "query"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"description": "Specify the maximum number of messages to receive (default: unlimited)",
|
"description": "Specify the maximum number of messages to receive (default: unlimited)",
|
||||||
|
|||||||
@ -1916,6 +1916,16 @@ paths:
|
|||||||
in: query
|
in: query
|
||||||
name: ignore_stories
|
name: ignore_stories
|
||||||
type: string
|
type: string
|
||||||
|
- description: Specify whether avatar downloads should be ignored when receiving
|
||||||
|
messages
|
||||||
|
in: query
|
||||||
|
name: ignore_avatars
|
||||||
|
type: string
|
||||||
|
- description: Specify whether sticker pack downloads should be ignored when
|
||||||
|
receiving messages
|
||||||
|
in: query
|
||||||
|
name: ignore_stickers
|
||||||
|
type: string
|
||||||
- description: 'Specify the maximum number of messages to receive (default:
|
- description: 'Specify the maximum number of messages to receive (default:
|
||||||
unlimited)'
|
unlimited)'
|
||||||
in: query
|
in: query
|
||||||
|
|||||||
@ -395,6 +395,8 @@ func main() {
|
|||||||
autoReceiveScheduleReceiveTimeout := utils.GetEnv("AUTO_RECEIVE_SCHEDULE_RECEIVE_TIMEOUT", "10")
|
autoReceiveScheduleReceiveTimeout := utils.GetEnv("AUTO_RECEIVE_SCHEDULE_RECEIVE_TIMEOUT", "10")
|
||||||
autoReceiveScheduleIgnoreAttachments := utils.GetEnv("AUTO_RECEIVE_SCHEDULE_IGNORE_ATTACHMENTS", "false")
|
autoReceiveScheduleIgnoreAttachments := utils.GetEnv("AUTO_RECEIVE_SCHEDULE_IGNORE_ATTACHMENTS", "false")
|
||||||
autoReceiveScheduleIgnoreStories := utils.GetEnv("AUTO_RECEIVE_SCHEDULE_IGNORE_STORIES", "false")
|
autoReceiveScheduleIgnoreStories := utils.GetEnv("AUTO_RECEIVE_SCHEDULE_IGNORE_STORIES", "false")
|
||||||
|
autoReceiveScheduleIgnoreAvatars := utils.GetEnv("AUTO_RECEIVE_SCHEDULE_IGNORE_AVATARS", "false")
|
||||||
|
autoReceiveScheduleIgnoreStickers := utils.GetEnv("AUTO_RECEIVE_SCHEDULE_IGNORE_STICKERS", "false")
|
||||||
autoReceiveScheduleSendReadReceipts := utils.GetEnv("AUTO_RECEIVE_SCHEDULE_SEND_READ_RECEIPTS", "false")
|
autoReceiveScheduleSendReadReceipts := utils.GetEnv("AUTO_RECEIVE_SCHEDULE_SEND_READ_RECEIPTS", "false")
|
||||||
|
|
||||||
c := cron.New()
|
c := cron.New()
|
||||||
@ -424,6 +426,8 @@ func main() {
|
|||||||
q.Add("timeout", autoReceiveScheduleReceiveTimeout)
|
q.Add("timeout", autoReceiveScheduleReceiveTimeout)
|
||||||
q.Add("ignore_attachments", autoReceiveScheduleIgnoreAttachments)
|
q.Add("ignore_attachments", autoReceiveScheduleIgnoreAttachments)
|
||||||
q.Add("ignore_stories", autoReceiveScheduleIgnoreStories)
|
q.Add("ignore_stories", autoReceiveScheduleIgnoreStories)
|
||||||
|
q.Add("ignore_avatars", autoReceiveScheduleIgnoreAvatars)
|
||||||
|
q.Add("ignore_stickers", autoReceiveScheduleIgnoreStickers)
|
||||||
q.Add("send_read_receipts", autoReceiveScheduleSendReadReceipts)
|
q.Add("send_read_receipts", autoReceiveScheduleSendReadReceipts)
|
||||||
req.URL.RawQuery = q.Encode()
|
req.URL.RawQuery = q.Encode()
|
||||||
|
|
||||||
|
|||||||
@ -3,7 +3,6 @@ package main
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@ -14,7 +13,7 @@ import (
|
|||||||
const supervisorctlConfigTemplate = `
|
const supervisorctlConfigTemplate = `
|
||||||
[program:%s]
|
[program:%s]
|
||||||
process_name=%s
|
process_name=%s
|
||||||
command=signal-cli --output=json --config %s%s daemon %s%s --tcp 127.0.0.1:%d
|
command=signal-cli --output=json --config %s%s daemon %s%s%s%s --tcp 127.0.0.1:%d
|
||||||
autostart=true
|
autostart=true
|
||||||
autorestart=true
|
autorestart=true
|
||||||
startretries=10
|
startretries=10
|
||||||
@ -41,23 +40,8 @@ func main() {
|
|||||||
jsonRpc2ClientConfig := utils.NewJsonRpc2ClientConfig()
|
jsonRpc2ClientConfig := utils.NewJsonRpc2ClientConfig()
|
||||||
|
|
||||||
var tcpPort int64 = 6001
|
var tcpPort int64 = 6001
|
||||||
fifoPathname := "/tmp/sigsocket1"
|
|
||||||
|
|
||||||
jsonRpc2ClientConfig.AddEntry(utils.MULTI_ACCOUNT_NUMBER, utils.JsonRpc2ClientConfigEntry{TcpPort: tcpPort, FifoPathname: fifoPathname})
|
jsonRpc2ClientConfig.AddEntry(utils.MULTI_ACCOUNT_NUMBER, utils.JsonRpc2ClientConfigEntry{TcpPort: tcpPort})
|
||||||
|
|
||||||
os.Remove(fifoPathname) //remove any existing named pipe
|
|
||||||
|
|
||||||
_, err := exec.Command("mkfifo", fifoPathname).Output()
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal("Couldn't create fifo with name ", fifoPathname, ": ", err.Error())
|
|
||||||
}
|
|
||||||
|
|
||||||
uid := utils.GetEnv("SIGNAL_CLI_UID", "1000")
|
|
||||||
gid := utils.GetEnv("SIGNAL_CLI_GID", "1000")
|
|
||||||
_, err = exec.Command("chown", uid+":"+gid, fifoPathname).Output()
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal("Couldn't change permissions of fifo with name ", fifoPathname, ": ", err.Error())
|
|
||||||
}
|
|
||||||
|
|
||||||
signalCliIgnoreAttachments := ""
|
signalCliIgnoreAttachments := ""
|
||||||
ignoreAttachments := utils.GetEnv("JSON_RPC_IGNORE_ATTACHMENTS", "")
|
ignoreAttachments := utils.GetEnv("JSON_RPC_IGNORE_ATTACHMENTS", "")
|
||||||
@ -71,9 +55,21 @@ func main() {
|
|||||||
signalCliIgnoreStories = " --ignore-stories"
|
signalCliIgnoreStories = " --ignore-stories"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
signalCliIgnoreAvatars := ""
|
||||||
|
ignoreAvatars := utils.GetEnv("JSON_RPC_IGNORE_AVATARS", "")
|
||||||
|
if ignoreAvatars == "true" {
|
||||||
|
signalCliIgnoreAvatars = " --ignore-avatars"
|
||||||
|
}
|
||||||
|
|
||||||
|
signalCliIgnoreStickers := ""
|
||||||
|
ignoreStickers := utils.GetEnv("JSON_RPC_IGNORE_STICKERS", "")
|
||||||
|
if ignoreStickers == "true" {
|
||||||
|
signalCliIgnoreStickers = " --ignore-stickers"
|
||||||
|
}
|
||||||
|
|
||||||
supervisorctlProgramName := "signal-cli-json-rpc-1"
|
supervisorctlProgramName := "signal-cli-json-rpc-1"
|
||||||
supervisorctlLogFolder := "/var/log/" + supervisorctlProgramName
|
supervisorctlLogFolder := "/var/log/" + supervisorctlProgramName
|
||||||
_, err = exec.Command("mkdir", "-p", supervisorctlLogFolder).Output()
|
_, err := exec.Command("mkdir", "-p", supervisorctlLogFolder).Output()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal("Couldn't create log folder ", supervisorctlLogFolder, ": ", err.Error())
|
log.Fatal("Couldn't create log folder ", supervisorctlLogFolder, ": ", err.Error())
|
||||||
}
|
}
|
||||||
@ -96,7 +92,8 @@ func main() {
|
|||||||
supervisorctlConfigFilename := "/etc/supervisor/conf.d/" + "signal-cli-json-rpc-1.conf"
|
supervisorctlConfigFilename := "/etc/supervisor/conf.d/" + "signal-cli-json-rpc-1.conf"
|
||||||
|
|
||||||
supervisorctlConfig := fmt.Sprintf(supervisorctlConfigTemplate, supervisorctlProgramName, supervisorctlProgramName,
|
supervisorctlConfig := fmt.Sprintf(supervisorctlConfigTemplate, supervisorctlProgramName, supervisorctlProgramName,
|
||||||
signalCliConfigDir, trustNewIdentities, signalCliIgnoreAttachments, signalCliIgnoreStories, tcpPort,
|
signalCliConfigDir, trustNewIdentities, signalCliIgnoreAttachments, signalCliIgnoreStories,
|
||||||
|
signalCliIgnoreAvatars, signalCliIgnoreStickers, tcpPort,
|
||||||
supervisorctlProgramName, supervisorctlProgramName)
|
supervisorctlProgramName, supervisorctlProgramName)
|
||||||
|
|
||||||
err = ioutil.WriteFile(supervisorctlConfigFilename, []byte(supervisorctlConfig), 0644)
|
err = ioutil.WriteFile(supervisorctlConfigFilename, []byte(supervisorctlConfig), 0644)
|
||||||
|
|||||||
@ -2,15 +2,15 @@ package utils
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"gopkg.in/yaml.v2"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
|
||||||
|
"gopkg.in/yaml.v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
const MULTI_ACCOUNT_NUMBER string = "<multi-account>"
|
const MULTI_ACCOUNT_NUMBER string = "<multi-account>"
|
||||||
|
|
||||||
type JsonRpc2ClientConfigEntry struct {
|
type JsonRpc2ClientConfigEntry struct {
|
||||||
TcpPort int64 `yaml:"tcp_port"`
|
TcpPort int64 `yaml:"tcp_port"`
|
||||||
FifoPathname string `yaml:"fifo_pathname"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type JsonRpc2ClientConfigEntries struct {
|
type JsonRpc2ClientConfigEntries struct {
|
||||||
@ -47,14 +47,6 @@ func (c *JsonRpc2ClientConfig) GetTcpPortForNumber(number string) (int64, error)
|
|||||||
return 0, errors.New("Number " + number + " not found in local map")
|
return 0, errors.New("Number " + number + " not found in local map")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *JsonRpc2ClientConfig) GetFifoPathnameForNumber(number string) (string, error) {
|
|
||||||
if val, ok := c.config.Entries[number]; ok {
|
|
||||||
return val.FifoPathname, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
return "", errors.New("Number " + number + " not found in local map")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *JsonRpc2ClientConfig) GetTcpPortsForNumbers() map[string]int64 {
|
func (c *JsonRpc2ClientConfig) GetTcpPortsForNumbers() map[string]int64 {
|
||||||
mapping := make(map[string]int64)
|
mapping := make(map[string]int64)
|
||||||
for number, val := range c.config.Entries {
|
for number, val := range c.config.Entries {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user