@@ -39,6 +39,14 @@ type GroupEntry struct {
3939 InviteLink string `json:"invite_link"`
4040}
4141
42+ type LoggingConfiguration struct {
43+ Level string `json:"Level"`
44+ }
45+
46+ type Configuration struct {
47+ Logging LoggingConfiguration `json:"logging"`
48+ }
49+
4250type SignalCliGroupEntry struct {
4351 Name string `json:"name"`
4452 Id string `json:"id"`
@@ -127,6 +135,19 @@ func cleanupTmpFiles(paths []string) {
127135 }
128136}
129137
138+ func getContainerId () (string , error ) {
139+ data , err := ioutil .ReadFile ("/proc/1/cpuset" )
140+ if err != nil {
141+ return "" , err
142+ }
143+ lines := strings .Split (string (data ), "\n " )
144+ if len (lines ) == 0 {
145+ return "" , errors .New ("Couldn't get docker container id (empty)" )
146+ }
147+ containerId := strings .Replace (lines [0 ], "/docker/" , "" , - 1 )
148+ return containerId , nil
149+ }
150+
130151func send (c * gin.Context , attachmentTmpDir string , signalCliConfig string , number string , message string ,
131152 recipients []string , base64Attachments []string , isGroup bool ) {
132153 cmd := []string {"--config" , signalCliConfig , "-u" , number , "send" }
@@ -280,6 +301,17 @@ func getGroups(number string, signalCliConfig string) ([]GroupEntry, error) {
280301}
281302
282303func runSignalCli (wait bool , args []string , stdin string ) (string , error ) {
304+ containerId , err := getContainerId ()
305+
306+ log .Debug ("If you want to run this command manually, run the following steps on your host system:" )
307+ if err == nil {
308+ log .Debug ("*) docker exec -it " , containerId , " /bin/bash" )
309+ } else {
310+ log .Debug ("*) docker exec -it <container id> /bin/bash" )
311+ }
312+ log .Debug ("*) su signal-api" )
313+ log .Debug ("*) signal-cli " , strings .Join (args , " " ))
314+
283315 cmd := exec .Command ("signal-cli" , args ... )
284316 if stdin != "" {
285317 cmd .Stdin = strings .NewReader (stdin )
@@ -311,6 +343,7 @@ func runSignalCli(wait bool, args []string, stdin string) (string, error) {
311343 return "" , errors .New (errBuffer .String ())
312344 }
313345 }
346+
314347 return outBuffer .String (), nil
315348 } else {
316349 stdout , err := cmd .StdoutPipe ()
@@ -1006,3 +1039,58 @@ func (a *Api) TrustIdentity(c *gin.Context) {
10061039 }
10071040 c .Status (http .StatusNoContent )
10081041}
1042+
1043+ // @Summary Set the REST API configuration.
1044+ // @Tags General
1045+ // @Description Set the REST API configuration.
1046+ // @Accept json
1047+ // @Produce json
1048+ // @Success 201 {string} string "OK"
1049+ // @Failure 400 {object} Error
1050+ // @Param data body Configuration true "Configuration"
1051+ // @Router /v1/configuration [post]
1052+ func (a * Api ) SetConfiguration (c * gin.Context ) {
1053+ var req Configuration
1054+ err := c .BindJSON (& req )
1055+ if err != nil {
1056+ c .JSON (400 , Error {Msg : "Couldn't process request - invalid request" })
1057+ log .Error (err .Error ())
1058+ return
1059+ }
1060+
1061+ if req .Logging .Level != "" {
1062+ if req .Logging .Level == "debug" {
1063+ log .SetLevel (log .DebugLevel )
1064+ } else if req .Logging .Level == "info" {
1065+ log .SetLevel (log .InfoLevel )
1066+ } else if req .Logging .Level == "warn" {
1067+ log .SetLevel (log .WarnLevel )
1068+ } else {
1069+ c .JSON (400 , Error {Msg : "Couldn't set log level - invalid log level" })
1070+ return
1071+ }
1072+ }
1073+ c .Status (http .StatusNoContent )
1074+ }
1075+
1076+ // @Summary List the REST API configuration.
1077+ // @Tags General
1078+ // @Description List the REST API configuration.
1079+ // @Accept json
1080+ // @Produce json
1081+ // @Success 200 {object} Configuration
1082+ // @Failure 400 {object} Error
1083+ // @Router /v1/configuration [get]
1084+ func (a * Api ) GetConfiguration (c * gin.Context ) {
1085+ logLevel := ""
1086+ if log .GetLevel () == log .DebugLevel {
1087+ logLevel = "debug"
1088+ } else if log .GetLevel () == log .InfoLevel {
1089+ logLevel = "info"
1090+ } else if log .GetLevel () == log .WarnLevel {
1091+ logLevel = "warn"
1092+ }
1093+
1094+ configuration := Configuration {Logging : LoggingConfiguration {Level : logLevel }}
1095+ c .JSON (200 , configuration )
1096+ }
0 commit comments