Compare commits

...

4 Commits

Author SHA1 Message Date
Lukas f. Paluch
2dcbbfbc1c
Merge f27a3c5206fead40d77aebac4424397b58be7f94 into 40232de0d0c4059c7594b1ae7bb29481176502b1 2026-04-21 21:18:33 +02:00
Bernhard B
40232de0d0 handle InvalidTransportModeException error
see #837
2026-04-20 23:33:19 +02: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 47 additions and 6 deletions

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

@ -324,8 +324,14 @@ func (a *Api) RegisterNumber(c *gin.Context) {
err = a.signalClient.RegisterNumber(number, req.UseVoice, req.Captcha)
if err != nil {
c.JSON(400, gin.H{"error": err.Error()})
return
switch err.(type) {
case *client.InvalidTransportError:
c.JSON(400, Error{Msg: "Couldn't use SMS verification to register the specified number. Wait 60 seconds and try again with {\"use_voice\": true}"})
return
default:
c.JSON(400, Error{Msg: err.Error()})
return
}
}
c.Writer.WriteHeader(201)
}

View File

@ -749,6 +749,8 @@ func (s *SignalClient) About() About {
}
func (s *SignalClient) RegisterNumber(number string, useVoice bool, captcha string) error {
var err error
var jsonRpc2Client *JsonRpc2Client
if s.signalCliMode == JsonRpc {
type Request struct {
UseVoice bool `json:"voice,omitempty"`
@ -765,12 +767,11 @@ func (s *SignalClient) RegisterNumber(number string, useVoice bool, captcha stri
request.Captcha = captcha
}
jsonRpc2Client, err := s.getJsonRpc2Client()
jsonRpc2Client, err = s.getJsonRpc2Client()
if err != nil {
return err
}
_, err = jsonRpc2Client.getRaw("register", nil, request)
return err
} else {
command := []string{"--config", s.signalCliConfig, "-a", number, "register"}
@ -782,9 +783,16 @@ func (s *SignalClient) RegisterNumber(number string, useVoice bool, captcha stri
command = append(command, []string{"--captcha", captcha}...)
}
_, err := s.cliClient.Execute(true, command, "")
return err
_, err = s.cliClient.Execute(true, command, "")
}
if err != nil {
if !useVoice && strings.Contains(err.Error(), "StatusCode: 400 (InvalidTransportModeException)") {
return &InvalidTransportError{Description: "Couldn't use SMS verification to register number."}
}
}
return err
}
func (s *SignalClient) UnregisterNumber(number string, deleteAccount bool, deleteLocalData bool) error {

View File

@ -23,3 +23,11 @@ type InternalError struct {
func (e *InternalError) Error() string {
return e.Description
}
type InvalidTransportError struct {
Description string
}
func (e *InvalidTransportError) Error() string {
return e.Description
}