forked from talkkonnect/talkkonnect
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhttpapi.go
265 lines (255 loc) · 7.82 KB
/
httpapi.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
/*
* talkkonnect headless mumble client/gateway with lcd screen and channel control
* Copyright (C) 2018-2019, Suvir Kumar <[email protected]>
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* talkkonnect is the based on talkiepi and barnard by Daniel Chote and Tim Cooper
*
* The Initial Developer of the Original Code is
* Suvir Kumar <[email protected]>
* Portions created by the Initial Developer are Copyright (C) Suvir Kumar. All Rights Reserved.
*
* Contributor(s):
*
* Suvir Kumar <[email protected]>
*
* My Blog is at www.talkkonnect.com
* The source code is hosted at github.com/talkkonnect
*
*
*/
package talkkonnect
import (
"fmt"
"log"
"net/http"
"strconv"
"strings"
)
func (b *Talkkonnect) httpAPI(w http.ResponseWriter, r *http.Request) {
Commands, ok := r.URL.Query()["command"]
if !ok || len(Commands) < 1 {
log.Println("error: URL Param 'command' is missing example http api commands should be of the format http://a.b.c.d/?command=starttransmitting")
fmt.Fprintf(w, "error: API should be of the format http://a.b.c.d:"+APIListenPort+"/?command=StartTransmitting or of the format http://a.b.c.d:"+APIListenPort+"?command=setvoicetarget&id=0\n")
return
}
var Command string
var ID int
var err error
for key, values := range r.URL.Query() {
if strings.ToLower(key) == "command" {
Command = values[0]
}
if strings.ToLower(key) == "id" {
ID, err = strconv.Atoi(values[0])
if err != nil {
log.Println("error: Target ID is not Number")
fmt.Fprintf(w, "API VoiceTarget ID is not Number\n")
return
}
}
}
log.Println("debug: http command " + string(Command))
log.Println("debug: http parameters ", ID)
b.BackLightTimer()
switch string(strings.ToLower(Command)) {
case "displaymenu":
if APIDisplayMenu {
b.cmdDisplayMenu()
fmt.Fprintf(w, "API Display Menu Request Processed Successfully\n")
} else {
fmt.Fprintf(w, "API Display Menu Request Denied\n")
}
case "channelup":
if APIChannelUp {
b.cmdChannelUp()
fmt.Fprintf(w, "API Channel Up Request Processed Successfully\n")
} else {
fmt.Fprintf(w, "API Channel Up Request Denied\n")
}
case "channeldown":
if APIChannelDown {
b.cmdChannelDown()
fmt.Fprintf(w, "API Channel Down Request Processed Successfully\n")
} else {
fmt.Fprintf(w, "API Channel Down Request Denied\n")
}
case "mute-toggle":
if APIMute {
b.cmdMuteUnmute("toggle")
fmt.Fprintf(w, "API Mute/UnMute Speaker Request Processed Successfully\n")
} else {
fmt.Fprintf(w, "API Mute/Unmute Speaker Request Denied\n")
}
case "mute":
if APIMute {
b.cmdMuteUnmute("mute")
fmt.Fprintf(w, "API Mute/UnMute Speaker Request Processed Successfully\n")
} else {
fmt.Fprintf(w, "API Mute/Unmute Speaker Request Denied\n")
}
case "unmute":
if APIMute {
b.cmdMuteUnmute("unmute")
fmt.Fprintf(w, "API Mute/UnMute Speaker Request Processed Successfully\n")
} else {
fmt.Fprintf(w, "API Mute/Unmute Speaker Request Denied\n")
}
case "currentvolume":
if APICurrentVolumeLevel {
b.cmdCurrentVolume()
fmt.Fprintf(w, "API Current Volume Level Request Processed Successfully\n")
} else {
fmt.Fprintf(w, "API Current Volume Level Request Denied\n")
}
case "volumeup":
if APIDigitalVolumeUp {
b.cmdVolumeUp()
fmt.Fprintf(w, "API Digital Volume Up Request Processed Successfully\n")
} else {
fmt.Fprintf(w, "API Digital Volume Up Request Denied\n")
}
case "volumedown":
if APIDigitalVolumeDown {
b.cmdVolumeDown()
fmt.Fprintf(w, "API Digital Volume Down Request Processed Successfully\n")
} else {
fmt.Fprintf(w, "API Digital Volume Down Request Denied\n")
}
case "listchannels":
if APIListServerChannels {
b.cmdListServerChannels()
fmt.Fprintf(w, "API List Server Channels Request Processed Successfully\n")
} else {
fmt.Fprintf(w, "API List Server Channels Request Denied\n")
}
case "starttransmitting":
if APIStartTransmitting {
b.cmdStartTransmitting()
fmt.Fprintf(w, "API Start Transmitting Request Processed Successfully\n")
} else {
fmt.Fprintf(w, "API Start Transmitting Request Denied\n")
}
case "stoptransmitting":
if APIStopTransmitting {
b.cmdStopTransmitting()
fmt.Fprintf(w, "API Stop Transmitting Request Processed Successfully\n")
} else {
fmt.Fprintf(w, "API Stop Transmitting Request Denied\n")
}
case "listonlineusers":
if APIListOnlineUsers {
b.cmdListOnlineUsers()
fmt.Fprintf(w, "API List Online Users Request Processed Successfully\n")
} else {
fmt.Fprintf(w, "API List Online Users Request Denied\n")
}
case "stream-toggle":
if APIPlayStream {
b.cmdPlayback()
fmt.Fprintf(w, "API Play/Stop Stream Request Processed Successfully\n")
} else {
fmt.Fprintf(w, "API Play/Stop Stream Request Denied\n")
}
case "gpsposition":
if APIRequestGpsPosition {
b.cmdGPSPosition()
fmt.Fprintf(w, "API Request GPS Position Processed Successfully\n")
} else {
fmt.Fprintf(w, "API Request GPS Position Denied\n")
}
case "sendemail":
if APIEmailEnabled {
b.cmdSendEmail()
fmt.Fprintf(w, "API Send Email Processed Successfully\n")
} else {
fmt.Fprintf(w, "API Send Email Config Denied\n")
}
case "connpreviousserver":
if APINextServer {
b.cmdConnPreviousServer()
fmt.Fprintf(w, "API Previous Server Processed Successfully\n")
} else {
fmt.Fprintf(w, "API Previous Server Denied\n")
}
case "connnextserver":
if APINextServer {
b.cmdConnNextServer()
fmt.Fprintf(w, "API Next Server Processed Successfully\n")
} else {
fmt.Fprintf(w, "API Next Server Denied\n")
}
case "clearscreen":
if APIClearScreen {
b.cmdClearScreen()
fmt.Fprintf(w, "API Clear Screen Processed Successfully\n")
} else {
fmt.Fprintf(w, "API Clear Screen Denied\n")
}
case "pingservers":
if APIEmailEnabled {
b.cmdPingServers()
fmt.Fprintf(w, "API Ping Servers Processed Successfully\n")
} else {
fmt.Fprintf(w, "API Ping Servers Denied\n")
}
case "panicsimulation":
if APIPanicSimulation {
b.cmdPanicSimulation()
fmt.Fprintf(w, "API Request Panic Simulation Processed Successfully\n")
} else {
fmt.Fprintf(w, "API Request Panic Simulation Denied\n")
}
case "repeattxloop":
if APIRepeatTxLoopTest {
b.cmdRepeatTxLoop()
fmt.Fprintf(w, "API Request Repeat Tx Loop Test Processed Successfully\n")
} else {
fmt.Fprintf(w, "API Request Repeat Tx Loop Test Denied\n")
}
case "scanchannels":
if APIScanChannels {
b.cmdScanChannels()
fmt.Fprintf(w, "API Request Scan Processed Successfully\n")
} else {
fmt.Fprintf(w, "API Request Scan Denied\n")
}
case "thanks":
if true {
b.cmdThanks()
fmt.Fprintf(w, "API Request Show Acknowledgements Processed Successfully\n")
} else {
fmt.Fprintf(w, "API Request Show Acknowledgements Denied\n")
}
case "showuptime":
if APIDisplayVersion {
b.cmdShowUptime()
fmt.Fprintf(w, "API Request Current Version Successfully\n")
} else {
fmt.Fprintf(w, "API Request Current Version Denied\n")
}
case "dumpxmlconfig":
if APIPrintXmlConfig {
b.cmdDumpXMLConfig()
fmt.Fprintf(w, "API Print XML Config Processed Successfully\n")
} else {
fmt.Fprintf(w, "API Print XML Congfig Denied\n")
}
case "playrepeatertone":
b.cmdPlayRepeaterTone()
fmt.Fprintf(w, "API Play Repeater Tone Processed Successfully\n")
case "setvoicetarget":
fmt.Fprintf(w, "API Set Voice Target to ID %v Processed Successfully\n", ID)
b.cmdSendVoiceTargets(uint32(ID))
default:
fmt.Fprintf(w, "API Command Not Defined\n")
}
}