-
Notifications
You must be signed in to change notification settings - Fork 5.9k
/
ApiController.groovy
executable file
·1878 lines (1616 loc) · 61 KB
/
ApiController.groovy
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
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* BigBlueButton open source conferencing system - http://www.bigbluebutton.org/
*
* Copyright (c) 2012 BigBlueButton Inc. and by respective authors (see below).
*
* This program is free software; you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free Software
* Foundation; either version 3.0 of the License, or (at your option) any later
* version.
*
* BigBlueButton is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along
* with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
*
*/
package org.bigbluebutton.web.controllers
import javax.servlet.ServletRequest;
import java.text.MessageFormat;
import java.text.SimpleDateFormat;
import java.util.Collections;
import org.apache.commons.codec.binary.Hex;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.lang.RandomStringUtils;
import org.apache.commons.lang.StringUtils;
import org.bigbluebutton.api.domain.Config;
import org.bigbluebutton.api.domain.Meeting;
import org.bigbluebutton.api.domain.UserSession;
import org.bigbluebutton.api.MeetingService;
import org.bigbluebutton.api.domain.Recording;
import org.bigbluebutton.api.Util;
import org.bigbluebutton.web.services.PresentationService
import org.bigbluebutton.web.services.turn.StunTurnService;
import org.bigbluebutton.web.services.turn.TurnEntry;
import org.bigbluebutton.presentation.PresentationUrlDownloadService;
import org.bigbluebutton.presentation.UploadedPresentation
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import org.bigbluebutton.api.ApiErrors;
import org.bigbluebutton.api.ClientConfigService;
import org.bigbluebutton.api.ParamsProcessorUtil;
import java.util.HashMap;
import java.util.Iterator;
import java.util.ArrayList;
import java.text.DateFormat;
import freemarker.template.Configuration;
import freemarker.cache.WebappTemplateLoader;
class ApiController {
private static final Integer SESSION_TIMEOUT = 14400 // 4 hours
private static final String CONTROLLER_NAME = 'ApiController'
private static final String RESP_CODE_SUCCESS = 'SUCCESS'
private static final String RESP_CODE_FAILED = 'FAILED'
private static final String ROLE_MODERATOR = "MODERATOR";
private static final String ROLE_ATTENDEE = "VIEWER";
private static final String SECURITY_SALT = '639259d4-9dd8-4b25-bf01-95f9567eaf4b'
private static final String API_VERSION = '0.81'
MeetingService meetingService;
PresentationService presentationService
ParamsProcessorUtil paramsProcessorUtil
ClientConfigService configService
PresentationUrlDownloadService presDownloadService
StunTurnService stunTurnService
/* general methods */
def index = {
log.debug CONTROLLER_NAME + "#index"
response.addHeader("Cache-Control", "no-cache")
withFormat {
xml {
render(contentType:"text/xml") {
response() {
returncode(RESP_CODE_SUCCESS)
version(paramsProcessorUtil.getApiVersion())
}
}
}
}
}
/***********************************
* CREATE (API)
***********************************/
def create = {
String API_CALL = 'create'
log.debug CONTROLLER_NAME + "#${API_CALL}"
log.debug params
// BEGIN - backward compatibility
if (StringUtils.isEmpty(params.checksum)) {
invalid("checksumError", "You did not pass the checksum security check")
return
}
if(!StringUtils.isEmpty(params.meetingID)) {
params.meetingID = StringUtils.strip(params.meetingID);
if (StringUtils.isEmpty(params.meetingID)) {
invalid("missingParamMeetingID", "You must specify a meeting ID for the meeting.");
return
}
} else {
invalid("missingParamMeetingID", "You must specify a meeting ID for the meeting.");
return
}
if (! paramsProcessorUtil.isChecksumSame(API_CALL, params.checksum, request.getQueryString())) {
invalid("checksumError", "You did not pass the checksum security check")
return
}
// END - backward compatibility
ApiErrors errors = new ApiErrors();
paramsProcessorUtil.processRequiredCreateParams(params, errors);
if (errors.hasErrors()) {
respondWithErrors(errors)
return
}
// Do we agree with the checksum? If not, complain.
if (! paramsProcessorUtil.isChecksumSame(API_CALL, params.checksum, request.getQueryString())) {
errors.checksumError()
respondWithErrors(errors)
return
}
// Translate the external meeting id into an internal meeting id.
String internalMeetingId = paramsProcessorUtil.convertToInternalMeetingId(params.meetingID);
Meeting existing = meetingService.getNotEndedMeetingWithId(internalMeetingId);
if (existing != null) {
log.debug "Existing conference found"
Map<String, Object> updateParams = paramsProcessorUtil.processUpdateCreateParams(params);
if (existing.getViewerPassword().equals(params.get("attendeePW")) && existing.getModeratorPassword().equals(params.get("moderatorPW"))) {
paramsProcessorUtil.updateMeeting(updateParams, existing);
// trying to create a conference a second time, return success, but give extra info
// Ignore pre-uploaded presentations. We only allow uploading of presentation once.
//uploadDocuments(existing);
respondWithConference(existing, "duplicateWarning", "This conference was already in existence and may currently be in progress.");
} else {
// BEGIN - backward compatibility
invalid("idNotUnique", "A meeting already exists with that meeting ID. Please use a different meeting ID.");
return;
// END - backward compatibility
// enforce meetingID unique-ness
errors.nonUniqueMeetingIdError()
respondWithErrors(errors)
}
return;
}
Meeting newMeeting = paramsProcessorUtil.processCreateParams(params);
if (! StringUtils.isEmpty(params.moderatorOnlyMessage)) {
newMeeting.setModeratorOnlyMessage(params.moderatorOnlyMessage);
}
meetingService.createMeeting(newMeeting);
// See if the request came with pre-uploading of presentation.
uploadDocuments(newMeeting);
respondWithConference(newMeeting, null, null)
}
/**********************************************
* JOIN API
*********************************************/
def join = {
String API_CALL = 'join'
log.debug CONTROLLER_NAME + "#${API_CALL}"
ApiErrors errors = new ApiErrors()
// BEGIN - backward compatibility
if (StringUtils.isEmpty(params.checksum)) {
invalid("checksumError", "You did not pass the checksum security check")
return
}
//checking for an empty username or for a username containing whitespaces only
if(!StringUtils.isEmpty(params.fullName)) {
params.fullName = StringUtils.strip(params.fullName);
if (StringUtils.isEmpty(params.fullName)) {
invalid("missingParamFullName", "You must specify a name for the attendee who will be joining the meeting.");
return
}
} else {
invalid("missingParamFullName", "You must specify a name for the attendee who will be joining the meeting.");
return
}
if(!StringUtils.isEmpty(params.meetingID)) {
params.meetingID = StringUtils.strip(params.meetingID);
if (StringUtils.isEmpty(params.meetingID)) {
invalid("missingParamMeetingID", "You must specify a meeting ID for the meeting.");
return
}
} else {
invalid("missingParamMeetingID", "You must specify a meeting ID for the meeting.");
return
}
if (StringUtils.isEmpty(params.password)) {
invalid("invalidPassword","You either did not supply a password or the password supplied is neither the attendee or moderator password for this conference.");
return
}
if (!paramsProcessorUtil.isChecksumSame(API_CALL, params.checksum, request.getQueryString())) {
invalid("checksumError", "You did not pass the checksum security check")
return
}
// END - backward compatibility
// Do we have a checksum? If none, complain.
if (StringUtils.isEmpty(params.checksum)) {
errors.missingParamError("checksum");
}
String guest;
if (!StringUtils.isEmpty(params.guest) && params.guest.equalsIgnoreCase("true"))
guest = "true";
else
guest = "false";
// Do we have a name for the user joining? If none, complain.
if(!StringUtils.isEmpty(params.fullName)) {
params.fullName = StringUtils.strip(params.fullName);
if (StringUtils.isEmpty(params.fullName)) {
errors.missingParamError("fullName");
}
} else {
errors.missingParamError("fullName");
}
String fullName = params.fullName
// Do we have a meeting id? If none, complain.
if(!StringUtils.isEmpty(params.meetingID)) {
params.meetingID = StringUtils.strip(params.meetingID);
if (StringUtils.isEmpty(params.meetingID)) {
errors.missingParamError("meetingID");
}
}
else {
errors.missingParamError("meetingID");
}
String externalMeetingId = params.meetingID
// Do we have a password? If not, complain.
String attPW = params.password
if (StringUtils.isEmpty(attPW)) {
errors.missingParamError("password");
}
if (errors.hasErrors()) {
respondWithErrors(errors)
return
}
// Do we agree on the checksum? If not, complain.
if (! paramsProcessorUtil.isChecksumSame(API_CALL, params.checksum, request.getQueryString())) {
errors.checksumError()
respondWithErrors(errors)
return
}
// Everything is good so far. Translate the external meeting id to an internal meeting id. If
// we can't find the meeting, complain.
String internalMeetingId = paramsProcessorUtil.convertToInternalMeetingId(externalMeetingId);
log.info("Retrieving meeting ${internalMeetingId}")
Meeting meeting = meetingService.getMeeting(internalMeetingId);
if (meeting == null) {
// BEGIN - backward compatibility
invalid("invalidMeetingIdentifier", "The meeting ID that you supplied did not match any existing meetings");
return;
// END - backward compatibility
errors.invalidMeetingIdError();
respondWithErrors(errors)
return;
}
// the createTime mismatch with meeting's createTime, complain
// In the future, the createTime param will be required
if (params.createTime != null) {
long createTime = 0;
try{
createTime=Long.parseLong(params.createTime);
} catch(Exception e){
log.warn("could not parse createTime param");
createTime = -1;
}
if(createTime != meeting.getCreateTime()) {
errors.mismatchCreateTimeParam();
respondWithErrors(errors);
return;
}
}
// Is this user joining a meeting that has been ended. If so, complain.
if (meeting.isForciblyEnded()) {
// BEGIN - backward compatibility
invalid("meetingForciblyEnded", "You can not re-join a meeting that has already been forcibly ended. However, once the meeting is removed from memory (according to the timeout configured on this server, you will be able to once again create a meeting with the same meeting ID");
return;
// END - backward compatibility
errors.meetingForciblyEndedError();
respondWithErrors(errors)
return;
}
// Now determine if this user is a moderator or a viewer.
String role = null;
if (meeting.getModeratorPassword().equals(attPW)) {
role = ROLE_MODERATOR;
} else if (meeting.getViewerPassword().equals(attPW)) {
role = ROLE_ATTENDEE;
}
if (role == null) {
// BEGIN - backward compatibility
invalid("invalidPassword","You either did not supply a password or the password supplied is neither the attendee or moderator password for this conference.");
return
// END - backward compatibility
errors.invalidPasswordError()
respondWithErrors(errors)
return;
}
String webVoice = StringUtils.isEmpty(params.webVoiceConf) ? meeting.getTelVoice() : params.webVoiceConf
boolean redirectImm = parseBoolean(params.redirectImmediately)
String internalUserID = RandomStringUtils.randomAlphanumeric(12).toLowerCase()
String authToken = RandomStringUtils.randomAlphanumeric(12).toLowerCase()
String externUserID = params.userID
if (StringUtils.isEmpty(externUserID)) {
externUserID = internalUserID
}
//Return a Map with the user custom data
Map<String,String> userCustomData = paramsProcessorUtil.getUserCustomData(params);
//Currently, it's associated with the externalUserID
if (userCustomData.size() > 0)
meetingService.addUserCustomData(meeting.getInternalId(), externUserID, userCustomData);
String configxml = null;
if (! StringUtils.isEmpty(params.configToken)) {
Config conf = meeting.getConfig(params.configToken);
if (conf == null) {
// Check if this config is one of our pre-built config
configxml = configService.getConfig(params.configToken)
if (configxml == null) {
// Default to the default config.
configxml = conf.config;
}
} else {
configxml = conf.config;
}
} else {
Config conf = meeting.getDefaultConfig();
if (conf == null) {
errors.noConfigFound();
respondWithErrors(errors);
} else {
configxml = conf.config;
}
}
if (StringUtils.isEmpty(configxml)) {
errors.noConfigFound();
respondWithErrors(errors);
}
UserSession us = new UserSession();
us.authToken = authToken;
us.internalUserId = internalUserID
us.conferencename = meeting.getName()
us.meetingID = meeting.getInternalId()
us.externMeetingID = meeting.getExternalId()
us.externUserID = externUserID
us.fullname = fullName
us.role = role
us.conference = meeting.getInternalId()
us.room = meeting.getInternalId()
us.voicebridge = meeting.getTelVoice()
us.webvoiceconf = meeting.getWebVoice()
us.mode = "LIVE"
us.record = meeting.isRecord()
us.welcome = meeting.getWelcomeMessage()
us.guest = guest
us.logoutUrl = meeting.getLogoutUrl();
us.configXML = configxml;
if (! StringUtils.isEmpty(params.defaultLayout)) {
us.defaultLayout = params.defaultLayout;
}
if (! StringUtils.isEmpty(params.avatarURL)) {
us.avatarURL = params.avatarURL;
} else {
us.avatarURL = meeting.defaultAvatarURL
}
// Store the following into a session so we can handle
// logout, restarts properly.
session['meeting-id'] = us.meetingID
session['user-token'] = us.meetingID + "-" + us.authToken;
session['logout-url'] = us.logoutUrl
meetingService.addUserSession(session['user-token'], us);
// Register user into the meeting.
meetingService.registerUser(us.meetingID, us.internalUserId, us.fullname, us.role, us.externUserID, us.authToken, us.guest)
log.info("Session user token for " + us.fullname + " [" + session['user-token'] + "]")
session.setMaxInactiveInterval(SESSION_TIMEOUT);
//check if exists the param redirect
boolean redirectClient = true;
String clientURL = paramsProcessorUtil.getDefaultClientUrl();
if(! StringUtils.isEmpty(params.redirect)) {
try{
redirectClient = Boolean.parseBoolean(params.redirect);
}catch(Exception e){
redirectClient = true;
}
}
if(!StringUtils.isEmpty(params.clientURL)){
clientURL = params.clientURL;
}
if (redirectClient){
println("Successfully joined. Redirecting to ${paramsProcessorUtil.getDefaultClientUrl()}");
println "ClientURL ${clientURL}"
log.info("Successfully joined. Redirecting to ${paramsProcessorUtil.getDefaultClientUrl()}");
redirect(url: clientURL);
}
else{
log.info("Successfully joined. Sending XML response.");
response.addHeader("Cache-Control", "no-cache")
withFormat {
xml {
render(contentType:"text/xml") {
response() {
returncode(RESP_CODE_SUCCESS)
messageKey("successfullyJoined")
message("You have joined successfully.")
meeting_id(us.meetingID)
user_id(us.internalUserId)
auth_token(us.authToken)
}
}
}
}
}
}
/*******************************************
* IS_MEETING_RUNNING API
*******************************************/
def isMeetingRunning = {
String API_CALL = 'isMeetingRunning'
log.debug CONTROLLER_NAME + "#${API_CALL}"
// BEGIN - backward compatibility
if (StringUtils.isEmpty(params.checksum)) {
invalid("checksumError", "You did not pass the checksum security check")
return
}
if(!StringUtils.isEmpty(params.meetingID)) {
params.meetingID = StringUtils.strip(params.meetingID);
if (StringUtils.isEmpty(params.meetingID)) {
invalid("missingParamMeetingID", "You must specify a meeting ID for the meeting.");
return
}
} else {
invalid("missingParamMeetingID", "You must specify a meeting ID for the meeting.");
return
}
if (! paramsProcessorUtil.isChecksumSame(API_CALL, params.checksum, request.getQueryString())) {
invalid("checksumError", "You did not pass the checksum security check")
return
}
// END - backward compatibility
ApiErrors errors = new ApiErrors()
// Do we have a checksum? If none, complain.
if (StringUtils.isEmpty(params.checksum)) {
errors.missingParamError("checksum");
}
// Do we have a meeting id? If none, complain.
if(!StringUtils.isEmpty(params.meetingID)) {
params.meetingID = StringUtils.strip(params.meetingID);
if (StringUtils.isEmpty(params.meetingID)) {
errors.missingParamError("meetingID");
}
} else {
errors.missingParamError("meetingID");
}
String externalMeetingId = params.meetingID
if (errors.hasErrors()) {
respondWithErrors(errors)
return
}
// Do we agree on the checksum? If not, complain.
if (! paramsProcessorUtil.isChecksumSame(API_CALL, params.checksum, request.getQueryString())) {
errors.checksumError()
respondWithErrors(errors)
return
}
// Everything is good so far. Translate the external meeting id to an internal meeting id. If
// we can't find the meeting, complain.
String internalMeetingId = paramsProcessorUtil.convertToInternalMeetingId(externalMeetingId);
log.info("Retrieving meeting ${internalMeetingId}")
Meeting meeting = meetingService.getMeeting(internalMeetingId);
boolean isRunning = meeting != null && meeting.isRunning();
response.addHeader("Cache-Control", "no-cache")
withFormat {
xml {
render(contentType:"text/xml") {
response() {
returncode(RESP_CODE_SUCCESS)
running(isRunning ? "true" : "false")
}
}
}
}
}
/************************************
* END API
************************************/
def end = {
String API_CALL = "end"
log.debug CONTROLLER_NAME + "#${API_CALL}"
// BEGIN - backward compatibility
if (StringUtils.isEmpty(params.checksum)) {
invalid("checksumError", "You did not pass the checksum security check")
return
}
if(!StringUtils.isEmpty(params.meetingID)) {
params.meetingID = StringUtils.strip(params.meetingID);
if (StringUtils.isEmpty(params.meetingID)) {
invalid("missingParamMeetingID", "You must specify a meeting ID for the meeting.");
return
}
} else {
invalid("missingParamMeetingID", "You must specify a meeting ID for the meeting.");
return
}
if (StringUtils.isEmpty(params.password)) {
invalid("invalidPassword","You must supply the moderator password for this call.");
return
}
if (! paramsProcessorUtil.isChecksumSame(API_CALL, params.checksum, request.getQueryString())) {
invalid("checksumError", "You did not pass the checksum security check")
return
}
// END - backward compatibility
ApiErrors errors = new ApiErrors()
// Do we have a checksum? If none, complain.
if (StringUtils.isEmpty(params.checksum)) {
errors.missingParamError("checksum");
}
// Do we have a meeting id? If none, complain.
if(!StringUtils.isEmpty(params.meetingID)) {
params.meetingID = StringUtils.strip(params.meetingID);
if (StringUtils.isEmpty(params.meetingID)) {
errors.missingParamError("meetingID");
}
} else {
errors.missingParamError("meetingID");
}
String externalMeetingId = params.meetingID
// Do we have a password? If not, complain.
String modPW = params.password
if (StringUtils.isEmpty(modPW)) {
errors.missingParamError("password");
}
if (errors.hasErrors()) {
respondWithErrors(errors)
return
}
// Do we agree on the checksum? If not, complain.
if (! paramsProcessorUtil.isChecksumSame(API_CALL, params.checksum, request.getQueryString())) {
errors.checksumError()
respondWithErrors(errors)
return
}
// Everything is good so far. Translate the external meeting id to an internal meeting id. If
// we can't find the meeting, complain.
String internalMeetingId = paramsProcessorUtil.convertToInternalMeetingId(externalMeetingId);
log.info("Retrieving meeting ${internalMeetingId}")
Meeting meeting = meetingService.getMeeting(internalMeetingId);
if (meeting == null) {
// BEGIN - backward compatibility
invalid("notFound", "We could not find a meeting with that meeting ID - perhaps the meeting is not yet running?");
return;
// END - backward compatibility
errors.invalidMeetingIdError();
respondWithErrors(errors)
return;
}
if (meeting.getModeratorPassword().equals(modPW) == false) {
// BEGIN - backward compatibility
invalid("invalidPassword","You must supply the moderator password for this call.");
return;
// END - backward compatibility
errors.invalidPasswordError();
respondWithErrors(errors)
return;
}
meetingService.endMeeting(meeting.getInternalId());
response.addHeader("Cache-Control", "no-cache")
withFormat {
xml {
render(contentType:"text/xml") {
response() {
returncode(RESP_CODE_SUCCESS)
messageKey("sentEndMeetingRequest")
message("A request to end the meeting was sent. Please wait a few seconds, and then use the getMeetingInfo or isMeetingRunning API calls to verify that it was ended.")
}
}
}
}
}
/*****************************************
* GETMEETINGINFO API
*****************************************/
def getMeetingInfo = {
String API_CALL = "getMeetingInfo"
log.debug CONTROLLER_NAME + "#${API_CALL}"
// BEGIN - backward compatibility
if (StringUtils.isEmpty(params.checksum)) {
invalid("checksumError", "You did not pass the checksum security check")
return
}
if(!StringUtils.isEmpty(params.meetingID)) {
params.meetingID = StringUtils.strip(params.meetingID);
if (StringUtils.isEmpty(params.meetingID)) {
invalid("missingParamMeetingID", "You must specify a meeting ID for the meeting.");
return
}
} else {
invalid("missingParamMeetingID", "You must specify a meeting ID for the meeting.");
return
}
if (! paramsProcessorUtil.isChecksumSame(API_CALL, params.checksum, request.getQueryString())) {
invalid("checksumError", "You did not pass the checksum security check")
return
}
// END - backward compatibility
ApiErrors errors = new ApiErrors()
// Do we have a checksum? If none, complain.
if (StringUtils.isEmpty(params.checksum)) {
errors.missingParamError("checksum");
}
// Do we have a meeting id? If none, complain.
if(!StringUtils.isEmpty(params.meetingID)) {
params.meetingID = StringUtils.strip(params.meetingID);
if (StringUtils.isEmpty(params.meetingID)) {
errors.missingParamError("meetingID");
}
} else {
errors.missingParamError("meetingID");
}
String externalMeetingId = params.meetingID
if (errors.hasErrors()) {
respondWithErrors(errors)
return
}
// Do we agree on the checksum? If not, complain.
if (! paramsProcessorUtil.isChecksumSame(API_CALL, params.checksum, request.getQueryString())) {
errors.checksumError()
respondWithErrors(errors)
return
}
// Everything is good so far. Translate the external meeting id to an internal meeting id. If
// we can't find the meeting, complain.
String internalMeetingId = paramsProcessorUtil.convertToInternalMeetingId(externalMeetingId);
log.info("Retrieving meeting ${internalMeetingId}")
Meeting meeting = meetingService.getMeeting(internalMeetingId);
if (meeting == null) {
// BEGIN - backward compatibility
invalid("notFound", "We could not find a meeting with that meeting ID");
return;
// END - backward compatibility
errors.invalidMeetingIdError();
respondWithErrors(errors)
return;
}
respondWithConferenceDetails(meeting, null, null, null);
}
/************************************
* GETMEETINGS API
************************************/
def getMeetingsHandler = {
String API_CALL = "getMeetings"
log.debug CONTROLLER_NAME + "#${API_CALL}"
println("##### GETMEETINGS API CALL ####")
// BEGIN - backward compatibility
if (StringUtils.isEmpty(params.checksum)) {
invalid("checksumError", "You did not pass the checksum security check")
return
}
if (! paramsProcessorUtil.isChecksumSame(API_CALL, params.checksum, request.getQueryString())) {
invalid("checksumError", "You did not pass the checksum security check")
return
}
// END - backward compatibility
ApiErrors errors = new ApiErrors()
// Do we have a checksum? If none, complain.
if (StringUtils.isEmpty(params.checksum)) {
errors.missingParamError("checksum");
}
if (errors.hasErrors()) {
respondWithErrors(errors)
return
}
// Do we agree on the checksum? If not, complain.
if (! paramsProcessorUtil.isChecksumSame(API_CALL, params.checksum, request.getQueryString())) {
errors.checksumError()
respondWithErrors(errors)
return
}
Collection<Meeting> mtgs = meetingService.getMeetings();
if (mtgs == null || mtgs.isEmpty()) {
response.addHeader("Cache-Control", "no-cache")
withFormat {
xml {
render(contentType:"text/xml") {
response() {
returncode(RESP_CODE_SUCCESS)
meetings()
messageKey("noMeetings")
message("no meetings were found on this server")
}
}
}
}
} else {
println("#### Has running meetings [" + mtgs.size() + "] #####")
response.addHeader("Cache-Control", "no-cache")
withFormat {
xml {
render(contentType:"text/xml") {
response() {
returncode(RESP_CODE_SUCCESS)
meetings {
for (m in mtgs) {
meeting {
meetingID(m.getExternalId())
meetingName(m.getName())
createTime(m.getCreateTime())
createDate(formatPrettyDate(m.getCreateTime()))
voiceBridge(m.getTelVoice())
dialNumber(m.getDialNumber())
attendeePW(m.getViewerPassword())
moderatorPW(m.getModeratorPassword())
hasBeenForciblyEnded(m.isForciblyEnded() ? "true" : "false")
running(m.isRunning() ? "true" : "false")
participantCount(m.getNumUsers())
listenerCount(m.getNumListenOnly())
voiceParticipantCount(m.getNumVoiceJoined())
videoCount(m.getNumVideos())
duration(m.duration)
hasUserJoined(m.hasUserJoined())
}
}
}
}
}
}
}
}
}
def getDefaultConfigXML = {
String API_CALL = "getDefaultConfigXML"
ApiErrors errors = new ApiErrors();
if (StringUtils.isEmpty(params.checksum)) {
invalid("checksumError", "You did not pass the checksum security check")
return
}
// Do we agree on the checksum? If not, complain.
if (! paramsProcessorUtil.isChecksumSame(API_CALL, params.checksum, request.getQueryString())) {
errors.checksumError()
respondWithErrors(errors)
return
}
String defConfigXML = paramsProcessorUtil.getDefaultConfigXML();
response.addHeader("Cache-Control", "no-cache")
render text: defConfigXML, contentType: 'text/xml'
}
private Map<String, String[]> getParameters(ServletRequest request) {
// Copy the parameters into our own Map as we can't pass the paramMap
// from the request as it's an unmodifiable map.
Map<String, String[]> reqParams = new HashMap<String, String[]>();
Map<String, String[]> unModReqParams = request.getParameterMap();
SortedSet<String> keys = new TreeSet<String>(unModReqParams.keySet());
for (String key: keys) {
reqParams.put(key, unModReqParams.get(key));
}
return reqParams;
}
/***********************************************
* POLL API
***********************************************/
def setPollXML = {
String API_CALL = "setPollXML"
log.debug CONTROLLER_NAME + "#${API_CALL}"
println CONTROLLER_NAME + "#${API_CALL}"
if (StringUtils.isEmpty(params.checksum)) {
invalid("checksumError", "You did not pass the checksum security check")
return
}
if (StringUtils.isEmpty(params.pollXML)) {
invalid("configXMLError", "You did not pass a poll XML")
return
}
if(!StringUtils.isEmpty(params.meetingID)) {
params.meetingID = StringUtils.strip(params.meetingID);
if (StringUtils.isEmpty(params.meetingID)) {
invalid("missingParamMeetingID", "You must specify a meeting ID for the meeting.");
return
}
} else {
invalid("missingParamMeetingID", "You must specify a meeting ID for the meeting.");
return
}
// Translate the external meeting id into an internal meeting id.
String internalMeetingId = paramsProcessorUtil.convertToInternalMeetingId(params.meetingID);
Meeting meeting = meetingService.getMeeting(internalMeetingId);
if (meeting == null) {
// BEGIN - backward compatibility
invalid("invalidMeetingIdentifier", "The meeting ID that you supplied did not match any existing meetings");
return;
// END - backward compatibility
errors.invalidMeetingIdError();
respondWithErrors(errors)
return;
}
Map<String, String[]> reqParams = getParameters(request)
String pollXML = params.pollXML
String decodedPollXML;
try {
decodedPollXML = URLDecoder.decode(pollXML, "UTF-8");
} catch (UnsupportedEncodingException e) {
log.error("Couldn't decode poll XML.");
invalid("pollXMLError", "Cannot decode poll XML")
return;
}
println "decodedPollXML [" + decodedPollXML + "]"
if (! paramsProcessorUtil.isPostChecksumSame(API_CALL, reqParams)) {
response.addHeader("Cache-Control", "no-cache")
withFormat {
xml {
render(contentType:"text/xml") {
response() {
returncode("FAILED")
messageKey("pollXMLChecksumError")
message("pollXMLChecksumError: request did not pass the checksum security check.")
}
}
}
}
} else {
println "**************** CHECKSUM PASSED **************************"
//println "[" + decodedPollXML + "]";
def pollxml = new XmlSlurper().parseText(decodedPollXML);
pollxml.children().each { poll ->
String title = poll.title.text();
String question = poll.question.text();
String questionType = poll.questionType.text();
ArrayList<String> answers = new ArrayList<String>();
poll.answers.children().each { answer ->
answers.add(answer.text());
}
//send poll to BigBlueButton Apps
meetingService.createdPolls(meeting.getInternalId(), title, question, questionType, answers);
}
response.addHeader("Cache-Control", "no-cache")
withFormat {
xml {
render(contentType:"text/xml") {
response() {
returncode("SUCCESS")
}
}
}
}
}
}
/***********************************************
* CONFIG API
***********************************************/
def setConfigXML = {
String API_CALL = "setConfigXML"
log.debug CONTROLLER_NAME + "#${API_CALL}"
if (StringUtils.isEmpty(params.checksum)) {
invalid("checksumError", "You did not pass the checksum security check")
return
}
if (StringUtils.isEmpty(params.configXML)) {
invalid("configXMLError", "You did not pass a config XML")