forked from Motion-Project/motion
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webu_html.c
1265 lines (1079 loc) · 47.6 KB
/
webu_html.c
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
/*
* webu_html.c
*
* Create the html for the webcontrol page
*
* This software is distributed under the GNU Public License Version 2
* See also the file 'COPYING'.
*
* Functional naming scheme
* webu_html* - Functions that create the display webcontrol page.
* webu_html_main - Entry point from webu_ans_ctrl(in webu.c)
* webu_html_page - Create the web page
* webu_html_head - Header section of the page
* webu_html_style* - The style section of the web page
* webu_html_body - Calls all the functions to create the body
* webu_html_navbar* - The navbar section of the web page
* webu_html_config* - config parms of page
* webu_html_track* - Tracking functions
* webu_html_script* - The javascripts of the web page
*
* To debug, run code, open page, view source and make copy of html
* into a local file to revise changes then determine applicable section(s)
* in this code to modify to match modified version.
* Known HTML Issues:
* Single and double quotes are not consistently used.
* HTML ids do not follow any naming convention.
* After clicking restart, do something...Try to connect again?
*
* Additional functionality considerations:
* Notification to user of items that require restart when changed.
* Notification to user that item successfully implemented (config change/tracking)
* List motion parms somewhere so they can be found by xgettext
*
*/
#include "motion.h"
#include "webu.h"
#include "webu_html.h"
#include "translate.h"
/* struct to save information regarding the links to include in html page */
struct strminfo_ctx {
struct context **cntlst;
char lnk_ref[WEBUI_LEN_LNK];
char lnk_src[WEBUI_LEN_LNK];
char lnk_camid[WEBUI_LEN_LNK];
char proto[WEBUI_LEN_LNK];
int port;
int motion_images;
};
static void webu_html_style_navbar(struct webui_ctx *webui) {
/* Write out the style section of the web page */
char response[WEBUI_LEN_RESP];
snprintf(response, sizeof (response),"%s",
" .navbar {\n"
" overflow: hidden;\n"
" background-color: #333;\n"
" font-family: Arial;\n"
" }\n"
" .navbar a {\n"
" float: left;\n"
" font-size: 16px;\n"
" color: white;\n"
" text-align: center;\n"
" padding: 14px 16px;\n"
" text-decoration: none;\n"
" }\n"
" .navbar a:hover, {\n"
" background-color: darkgray;\n"
" }\n");
webu_write(webui, response);
}
static void webu_html_style_dropdown(struct webui_ctx *webui) {
/* Write out the style section of the web page */
char response[WEBUI_LEN_RESP];
snprintf(response, sizeof (response),"%s",
" .dropdown {\n"
" float: left;\n"
" overflow: hidden;\n"
" }\n"
" .dropdown .dropbtn {\n"
" font-size: 16px;\n"
" border: none;\n"
" outline: none;\n"
" color: white;\n"
" padding: 14px 16px;\n"
" background-color: inherit;\n"
" font-family: inherit;\n"
" margin: 0;\n"
" }\n"
" .dropdown-content {\n"
" display: none;\n"
" position: absolute;\n"
" background-color: #f9f9f9;\n"
" min-width: 160px;\n"
" box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);\n"
" z-index: 1;\n"
" }\n"
" .dropdown-content a {\n"
" float: none;\n"
" color: black;\n"
" padding: 12px 16px;\n"
" text-decoration: none;\n"
" display: block;\n"
" text-align: left;\n"
" }\n"
" .dropdown-content a:hover {\n"
" background-color: lightgray;\n"
" }\n"
" .dropdown:hover .dropbtn {\n"
" background-color: darkgray;\n"
" }\n"
" .border {\n"
" border-width: 2px;\n"
" border-color: white;\n"
" border-style: solid;\n"
" }\n");
webu_write(webui, response);
}
static void webu_html_style_input(struct webui_ctx *webui) {
/* Write out the style section of the web page */
char response[WEBUI_LEN_RESP];
snprintf(response, sizeof (response),"%s",
" input , select {\n"
" width: 25%;\n"
" padding: 5px;\n"
" margin: 0;\n"
" display: inline-block;\n"
" border: 1px solid #ccc;\n"
" border-radius: 4px;\n"
" box-sizing: border-box;\n"
" height: 50%;\n"
" font-size: 75%;\n"
" margin-bottom: 5px;\n"
" }\n"
" .frm-input{\n"
" text-align:center;\n"
" }\n");
webu_write(webui, response);
}
static void webu_html_style_base(struct webui_ctx *webui) {
/* Write out the style section of the web page */
char response[WEBUI_LEN_RESP];
snprintf(response, sizeof (response),"%s",
" * {margin: 0; padding: 0; }\n"
" body {\n"
" padding: 0;\n"
" margin: 0;\n"
" font-family: Arial, Helvetica, sans-serif;\n"
" font-size: 16px;\n"
" line-height: 1;\n"
" color: #606c71;\n"
" background-color: #159957;\n"
" background-image: linear-gradient(120deg, #155799, #159957);\n"
" margin-left:0.5% ;\n"
" margin-right:0.5% ;\n"
" width: device-width ;\n"
" }\n"
" img {\n"
" max-width: 100%;\n"
" max-height: 100%;\n"
" height: auto;\n"
" }\n"
" .page-header {\n"
" color: #fff;\n"
" text-align: center;\n"
" margin-top: 0rem;\n"
" margin-bottom: 0rem;\n"
" font-weight: normal;\n"
" }\n");
webu_write(webui, response);
snprintf(response, sizeof (response),"%s",
" .page-header h4 {\n"
" height: 2px;\n"
" padding: 0;\n"
" margin: 1rem 0;\n"
" border: 0;\n"
" }\n"
" .main-content {\n"
" background-color: #000000;\n"
" text-align: center;\n"
" margin-top: 0rem;\n"
" margin-bottom: 0rem;\n"
" font-weight: normal;\n"
" font-size: 0.90em;\n"
" }\n"
" .header-right{\n"
" float: right;\n"
" color: white;\n"
" }\n"
" .header-center {\n"
" text-align: center;\n"
" color: white;\n"
" margin-top: 10px;\n"
" margin-bottom: 10px;\n"
" }\n");
webu_write(webui, response);
}
static void webu_html_style(struct webui_ctx *webui) {
/* Write out the style section of the web page */
char response[WEBUI_LEN_RESP];
snprintf(response, sizeof (response),"%s", " <style>\n");
webu_write(webui, response);
webu_html_style_base(webui);
webu_html_style_navbar(webui);
webu_html_style_input(webui);
webu_html_style_dropdown(webui);
snprintf(response, sizeof (response),"%s", " </style>\n");
webu_write(webui, response);
}
static void webu_html_head(struct webui_ctx *webui) {
/* Write out the header section of the web page */
char response[WEBUI_LEN_RESP];
snprintf(response, sizeof (response),"%s","<head>\n"
" <meta charset=\"UTF-8\">\n"
" <title>Motion</title>\n"
" <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n");
webu_write(webui, response);
webu_html_style(webui);
snprintf(response, sizeof (response),"%s", "</head>\n");
webu_write(webui, response);
}
static void webu_html_navbar_camera(struct webui_ctx *webui) {
/*Write out the options included in the camera dropdown */
char response[WEBUI_LEN_RESP];
int indx;
if (webui->cam_threads == 1){
/* Only Motion.conf file */
if (webui->cntlst[0]->conf.camera_name == NULL){
snprintf(response, sizeof (response),
" <div class=\"dropdown\">\n"
" <button onclick='display_cameras()' id=\"cam_drop\" class=\"dropbtn\">%s</button>\n"
" <div id='cam_btn' class=\"dropdown-content\">\n"
" <a onclick=\"camera_click('cam_%05d');\">%s 1</a>\n"
,_("Cameras")
,webui->cntlst[0]->camera_id
,_("Camera"));
webu_write(webui, response);
} else {
snprintf(response, sizeof (response),
" <div class=\"dropdown\">\n"
" <button onclick='display_cameras()' id=\"cam_drop\" class=\"dropbtn\">%s</button>\n"
" <div id='cam_btn' class=\"dropdown-content\">\n"
" <a onclick=\"camera_click('cam_%05d');\">%s</a>\n"
,_("Cameras")
,webui->cntlst[0]->camera_id
,webui->cntlst[0]->conf.camera_name);
webu_write(webui, response);
}
} else if (webui->cam_threads > 1){
/* Motion.conf + separate camera.conf file */
snprintf(response, sizeof (response),
" <div class=\"dropdown\">\n"
" <button onclick='display_cameras()' id=\"cam_drop\" class=\"dropbtn\">%s</button>\n"
" <div id='cam_btn' class=\"dropdown-content\">\n"
" <a onclick=\"camera_click('cam_all00');\">%s</a>\n"
,_("Cameras")
,_("All"));
webu_write(webui, response);
for (indx=1;indx <= webui->cam_count;indx++){
if (webui->cntlst[indx]->conf.camera_name == NULL){
snprintf(response, sizeof (response),
" <a onclick=\"camera_click('cam_%05d');\">%s %d</a>\n"
,webui->cntlst[indx]->camera_id
, _("Camera"), webui->cntlst[indx]->camera_id);
} else {
snprintf(response, sizeof (response),
" <a onclick=\"camera_click('cam_%05d');\">%s</a>\n"
,webui->cntlst[indx]->camera_id
,webui->cntlst[indx]->conf.camera_name
);
}
webu_write(webui, response);
}
}
snprintf(response, sizeof (response),"%s",
" </div>\n"
" </div>\n");
webu_write(webui, response);
}
static void webu_html_navbar_action(struct webui_ctx *webui) {
/* Write out the options included in the actions dropdown*/
char response[WEBUI_LEN_RESP];
snprintf(response, sizeof (response),
" <div class=\"dropdown\">\n"
" <button onclick='display_actions()' id=\"act_drop\" class=\"dropbtn\">%s</button>\n"
" <div id='act_btn' class=\"dropdown-content\">\n"
" <a onclick=\"action_click('/action/eventstart');\">%s</a>\n"
" <a onclick=\"action_click('/action/eventend');\">%s</a>\n"
" <a onclick=\"action_click('/action/snapshot');\">%s</a>\n"
" <a onclick=\"action_click('config');\">%s</a>\n"
" <a onclick=\"action_click('/config/write');\">%s</a>\n"
" <a onclick=\"action_click('track');\">%s</a>\n"
" <a onclick=\"action_click('/detection/pause');\">%s</a>\n"
" <a onclick=\"action_click('/detection/start');\">%s</a>\n"
" <a onclick=\"action_click('/action/restart');\">%s</a>\n"
" </div>\n"
" </div>\n"
,_("Action")
,_("Start Event")
,_("End Event")
,_("Snapshot")
,_("Change Configuration")
,_("Write Configuration")
,_("Tracking")
,_("Pause")
,_("Start")
,_("Restart"));
webu_write(webui, response);
}
static void webu_html_navbar(struct webui_ctx *webui) {
/* Write the navbar section*/
char response[WEBUI_LEN_RESP];
snprintf(response, sizeof (response),"%s",
" <div class=\"navbar\">\n");
webu_write(webui, response);
webu_html_navbar_camera(webui);
webu_html_navbar_action(webui);
snprintf(response, sizeof (response),
" <a href=\"https://motion-project.github.io/motion_guide.html\" "
" target=\"_blank\">%s</a>\n"
" <p class=\"header-right\">Motion "VERSION"</p>\n"
" </div>\n"
,_("Help"));
webu_write(webui, response);
}
static void webu_html_config_notice(struct webui_ctx *webui) {
/* Print out the header description of which parameters are included based upon the
* webcontrol_parms that was specified
*/
char response[WEBUI_LEN_RESP];
if (webui->cntlst[0]->conf.webcontrol_parms == 0){
snprintf(response, sizeof (response),
" <h4 id='h4_parm' class='header-center'>webcontrol_parms = 0 (%s)</h4>\n"
,_("No Configuration Options"));
} else if (webui->cntlst[0]->conf.webcontrol_parms == 1){
snprintf(response, sizeof (response),
" <h4 id='h4_parm' class='header-center'>webcontrol_parms = 1 (%s)</h4>\n"
,_("Limited Configuration Options"));
} else if (webui->cntlst[0]->conf.webcontrol_parms == 2){
snprintf(response, sizeof (response),
" <h4 id='h4_parm' class='header-center'>webcontrol_parms = 2 (%s)</h4>\n"
,_("Advanced Configuration Options"));
} else{
snprintf(response, sizeof (response),
" <h4 id='h4_parm' class='header-center'>webcontrol_parms = 3 (%s)</h4>\n"
,_("Restricted Configuration Options"));
}
webu_write(webui, response);
}
static void webu_html_h3desc(struct webui_ctx *webui) {
/* Write out the status description for the camera */
char response[WEBUI_LEN_RESP];
if (webui->cam_threads == 1){
snprintf(response, sizeof (response),
" <div id=\"id_header\">\n"
" <h3 id='h3_cam' data-cam=\"cam_all00\" class='header-center'>%s (%s)</h3>\n"
" </div>\n"
,_("All Cameras")
,(!webui->cntlst[0]->running)? _("Not running") :
(webui->cntlst[0]->lost_connection)? _("Lost connection"):
(webui->cntlst[0]->pause)? _("Paused"):_("Active")
);
webu_write(webui,response);
} else {
snprintf(response, sizeof (response),
" <div id=\"id_header\">\n"
" <h3 id='h3_cam' data-cam=\"cam_all00\" class='header-center'>%s</h3>\n"
" </div>\n"
,_("All Cameras"));
webu_write(webui,response);
}
}
static void webu_html_config(struct webui_ctx *webui) {
/* Write out the options to put into the config dropdown
* We use html data attributes to store the values for the options
* We always set a cam_all00 attribute and if the value if different for
* any of our cameras, then we also add a cam_xxxxx which has the config
* value for camera xxxxx The javascript then decodes these to display
*/
char response[WEBUI_LEN_RESP];
int indx_parm, indx, diff_vals;
const char *val_main, *val_thread;
char *val_temp;
snprintf(response, sizeof (response),"%s",
" <div id='cfg_form' style=\"display:none\">\n");
webu_write(webui, response);
webu_html_config_notice(webui);
snprintf(response, sizeof (response),
" <form class=\"frm-input\">\n"
" <select id='cfg_parms' name='onames' "
" autocomplete='off' onchange='config_change();'>\n"
" <option value='default' data-cam_all00=\"\" >%s</option>\n"
,_("Select option"));
webu_write(webui, response);
/* The config_params[indx_parm].print reuses the buffer so create a
* temporary variable for storing our parameter from main to compare
* to the thread specific value
*/
val_temp=malloc(PATH_MAX);
indx_parm = 0;
while (config_params[indx_parm].param_name != NULL){
if ((config_params[indx_parm].webui_level > webui->cntlst[0]->conf.webcontrol_parms) ||
(config_params[indx_parm].webui_level == WEBUI_LEVEL_NEVER)){
indx_parm++;
continue;
}
val_main = config_params[indx_parm].print(webui->cntlst, NULL, indx_parm, 0);
snprintf(response, sizeof (response),
" <option value='%s' data-cam_all00=\""
, config_params[indx_parm].param_name);
webu_write(webui, response);
memset(val_temp,'\0',PATH_MAX);
if (val_main != NULL){
snprintf(response, sizeof (response),"%s", val_main);
webu_write(webui, response);
snprintf(val_temp, PATH_MAX,"%s", val_main);
}
/* Loop through all the treads and see if any have a different value from motion.conf */
if (webui->cam_threads > 1){
for (indx=1;indx <= webui->cam_count;indx++){
val_thread=config_params[indx_parm].print(webui->cntlst, NULL, indx_parm, indx);
diff_vals = FALSE;
if (((strlen(val_temp) == 0) && (val_thread == NULL)) ||
((strlen(val_temp) != 0) && (val_thread == NULL))) {
diff_vals = FALSE;
} else if (((strlen(val_temp) == 0) && (val_thread != NULL)) ) {
diff_vals = TRUE;
} else {
if (strcasecmp(val_temp, val_thread)) diff_vals = TRUE;
}
if (diff_vals){
snprintf(response, sizeof (response),"%s","\" \\ \n");
webu_write(webui, response);
snprintf(response, sizeof (response),
" data-cam_%05d=\""
,webui->cntlst[indx]->camera_id);
webu_write(webui, response);
if (val_thread != NULL){
snprintf(response, sizeof (response),"%s%s", response, val_thread);
webu_write(webui, response);
}
}
}
}
/* Terminate the open quote and option. For foreign language put hint in () */
if (!strcasecmp(webui->lang,"en") ||
!strcasecmp(config_params[indx_parm].param_name
,_(config_params[indx_parm].param_name))){
snprintf(response, sizeof (response),"\" >%s</option>\n",
config_params[indx_parm].param_name);
webu_write(webui, response);
} else {
snprintf(response, sizeof (response),"\" >%s (%s)</option>\n",
config_params[indx_parm].param_name
,_(config_params[indx_parm].param_name));
webu_write(webui, response);
}
indx_parm++;
}
free(val_temp);
snprintf(response, sizeof (response),
" </select>\n"
" <input type=\"text\" id=\"cfg_value\" >\n"
" <input type='button' id='cfg_button' value='%s' onclick='config_click()'>\n"
" </form>\n"
" </div>\n"
,_("Save"));
webu_write(webui, response);
}
static void webu_html_track(struct webui_ctx *webui) {
/* Write the section for handling the tracking function */
char response[WEBUI_LEN_RESP];
snprintf(response, sizeof (response),
" <div id='trk_form' style='display:none'>\n"
" <form class='frm-input'>\n"
" <select id='trk_option' name='trkopt' autocomplete='off' "
" style='width:20%%' onchange='track_change();'>\n"
" <option value='pan/tilt' data-trk='pan' >%s</option>\n"
" <option value='absolute' data-trk='abs' >%s</option>\n"
" <option value='center' data-trk='ctr' >%s</option>\n"
" </select>\n"
" <label id='trk_lblpan' style='color:white; display:inline' >%s</label>\n"
" <label id='trk_lblx' style='color:white; display:none' >X</label>\n"
" <input type='text' id='trk_panx' style='width:10%%' >\n"
" <label id='trk_lbltilt' style='color:white; display:inline' >%s</label>\n"
" <label id='trk_lbly' style='color:white; display:none' >Y</label>\n"
" <input type='text' id='trk_tilty' style='width:10%%' >\n"
" <input type='button' id='trk_button' value='%s' "
" style='width:10%%' onclick='track_click()'>\n"
" </form>\n"
" </div>\n"
,_("Pan/Tilt")
,_("Absolute Change")
,_("Center")
,_("Pan")
,_("Tilt")
,_("Save"));
webu_write(webui, response);
}
static void webu_html_strminfo(struct strminfo_ctx *strm_info, int indx) {
/* This determines all the items we need to know to specify links and
* stream sources for the page. The options are 0-3 as of this writing
* where 0 = full streams, 1 = substreams, 2 = static images and 3 is
* the legacy code for creating streams. So we need to assign not only
* what images are to be sent but also whether we have tls/ssl.
* There are WAY too many options for this.
*/
if (strm_info->cntlst[indx]->conf.stream_preview_method == 99){
snprintf(strm_info->proto,WEBUI_LEN_LNK,"%s","http");
snprintf(strm_info->lnk_ref,WEBUI_LEN_LNK,"%s","");
snprintf(strm_info->lnk_src,WEBUI_LEN_LNK,"%s","");
snprintf(strm_info->lnk_camid,WEBUI_LEN_LNK,"%s","");
strm_info->port = strm_info->cntlst[indx]->conf.stream_port;
} else {
/* If using the main port,we need to insert a thread number into url*/
if (strm_info->cntlst[0]->conf.stream_port != 0) {
snprintf(strm_info->lnk_camid,WEBUI_LEN_LNK,"/%d"
,strm_info->cntlst[indx]->camera_id);
strm_info->port = strm_info->cntlst[0]->conf.stream_port;
if (strm_info->cntlst[0]->conf.stream_tls) {
snprintf(strm_info->proto,WEBUI_LEN_LNK,"%s","https");
} else {
snprintf(strm_info->proto,WEBUI_LEN_LNK,"%s","http");
}
} else {
snprintf(strm_info->lnk_camid,WEBUI_LEN_LNK,"%s","");
strm_info->port = strm_info->cntlst[indx]->conf.stream_port;
if (strm_info->cntlst[indx]->conf.stream_tls) {
snprintf(strm_info->proto,WEBUI_LEN_LNK,"%s","https");
} else {
snprintf(strm_info->proto,WEBUI_LEN_LNK,"%s","http");
}
}
if (strm_info->motion_images){
snprintf(strm_info->lnk_ref,WEBUI_LEN_LNK,"%s","/motion");
snprintf(strm_info->lnk_src,WEBUI_LEN_LNK,"%s","/motion");
} else {
/* Assign what images and links we want */
if (strm_info->cntlst[indx]->conf.stream_preview_method == 1){
/* Substream for preview */
snprintf(strm_info->lnk_ref,WEBUI_LEN_LNK,"%s","/stream");
snprintf(strm_info->lnk_src,WEBUI_LEN_LNK,"%s","/substream");
} else if (strm_info->cntlst[indx]->conf.stream_preview_method == 2){
/* Static image for preview */
snprintf(strm_info->lnk_ref,WEBUI_LEN_LNK,"%s","/stream");
snprintf(strm_info->lnk_src,WEBUI_LEN_LNK,"%s","/current");
} else if (strm_info->cntlst[indx]->conf.stream_preview_method == 4){
/* Source image for preview */
snprintf(strm_info->lnk_ref,WEBUI_LEN_LNK,"%s","/source");
snprintf(strm_info->lnk_src,WEBUI_LEN_LNK,"%s","/source");
} else {
/* Full stream for preview (method 0 or 3)*/
snprintf(strm_info->lnk_ref,WEBUI_LEN_LNK,"%s","/stream");
snprintf(strm_info->lnk_src,WEBUI_LEN_LNK,"%s","/stream");
}
}
}
}
static void webu_html_preview(struct webui_ctx *webui) {
/* Write the initial version of the preview section. The javascript
* will change this section when user selects a different camera */
char response[WEBUI_LEN_RESP];
int indx, indx_st, preview_scale;
struct strminfo_ctx strm_info;
strm_info.cntlst = webui->cntlst;
snprintf(response, sizeof (response),"%s",
" <div id=\"liveview\">\n"
" <section class=\"main-content\">\n"
" <br>\n"
" <p id=\"id_preview\">\n");
webu_write(webui, response);
indx_st = 1;
if (webui->cam_threads == 1) indx_st = 0;
for (indx = indx_st; indx<webui->cam_threads; indx++){
if (webui->cntlst[indx]->conf.stream_preview_newline){
snprintf(response, sizeof (response),"%s"," <br>\n");
webu_write(webui, response);
}
if (webui->cntlst[indx]->conf.stream_preview_method == 3){
preview_scale = 45;
} else {
preview_scale = webui->cntlst[indx]->conf.stream_preview_scale;
}
strm_info.motion_images = FALSE;
webu_html_strminfo(&strm_info,indx);
snprintf(response, sizeof (response),
" <a href=%s://%s:%d%s%s> "
" <img src=%s://%s:%d%s%s border=0 width=%d%%></a>\n"
,strm_info.proto, webui->hostname, strm_info.port
,strm_info.lnk_camid, strm_info.lnk_ref
,strm_info.proto, webui->hostname, strm_info.port
,strm_info.lnk_camid, strm_info.lnk_src
,preview_scale);
webu_write(webui, response);
if (webui->cntlst[indx]->conf.stream_preview_method == 3){
strm_info.motion_images = TRUE;
webu_html_strminfo(&strm_info,indx);
snprintf(response, sizeof (response),
" <a href=%s://%s:%d%s%s> "
" <img src=%s://%s:%d%s%s class=border width=%d%%></a>\n"
,strm_info.proto, webui->hostname, strm_info.port
,strm_info.lnk_camid, strm_info.lnk_ref
,strm_info.proto, webui->hostname, strm_info.port
,strm_info.lnk_camid, strm_info.lnk_src
,preview_scale);
webu_write(webui, response);
}
}
snprintf(response, sizeof (response),"%s",
" </p>\n"
" <br>\n"
" </section>\n"
" </div>\n");
webu_write(webui, response);
}
static void webu_html_script_action(struct webui_ctx *webui) {
/* Write the javascript action_click() function.
* We do not have a good notification section on the page so the successful
* submission and response is currently a empty if block for the future
* enhancement to somehow notify the user everything worked */
char response[WEBUI_LEN_RESP];
snprintf(response, sizeof (response),"%s",
" function event_reloadpage() {\n"
" window.location.reload();\n"
" }\n\n"
);
webu_write(webui, response);
snprintf(response, sizeof (response),"%s",
" function action_click(actval) {\n"
" if (actval == \"config\"){\n"
" document.getElementById('trk_form').style.display=\"none\";\n"
" document.getElementById('cfg_form').style.display=\"inline\";\n"
" } else if (actval == \"track\"){\n"
" document.getElementById('cfg_form').style.display=\"none\";\n"
" document.getElementById('trk_form').style.display=\"inline\";\n"
" } else {\n"
" document.getElementById('cfg_form').style.display=\"none\";\n"
" document.getElementById('trk_form').style.display=\"none\";\n"
" var camstr = document.getElementById('h3_cam').getAttribute('data-cam');\n"
" var camnbr = camstr.substring(4,9);\n"
" var http = new XMLHttpRequest();\n"
" if ((actval == \"/detection/pause\") || (actval == \"/detection/start\")) {\n"
" http.addEventListener('load', event_reloadpage); \n"
" }\n"
);
webu_write(webui, response);
snprintf(response, sizeof (response),
" var url = \"%s://%s:%d/\"; \n"
,webui->hostproto, webui->hostname
,webui->cntlst[0]->conf.webcontrol_port);
webu_write(webui, response);
snprintf(response, sizeof (response),
" if (camnbr == \"all00\"){\n"
" url = url + \"%05d\";\n"
" } else {\n"
" url = url + camnbr;\n"
" }\n"
" url = url + actval;\n"
,webui->cntlst[0]->camera_id);
webu_write(webui, response);
snprintf(response, sizeof (response),"%s",
" http.open(\"GET\", url, true);\n"
" http.onreadystatechange = function() {\n"
" if(http.readyState == 4 && http.status == 200) {\n"
" }\n"
" }\n"
" http.send(null);\n"
" }\n"
" document.getElementById('act_btn').style.display=\"none\"; \n"
" document.getElementById('cfg_value').value = '';\n"
" document.getElementById('cfg_parms').value = 'default';\n"
" }\n\n");
webu_write(webui, response);
}
static void webu_html_script_camera_thread(struct webui_ctx *webui) {
/* Write the javascript thread IF conditions of camera_click() function */
char response[WEBUI_LEN_RESP];
int indx, indx_st, preview_scale;
struct strminfo_ctx strm_info;
indx_st = 1;
if (webui->cam_threads == 1) indx_st = 0;
strm_info.cntlst = webui->cntlst;
for (indx = indx_st; indx<webui->cam_threads; indx++){
snprintf(response, sizeof (response),
" if (camid == \"cam_%05d\"){\n"
,webui->cntlst[indx]->camera_id);
webu_write(webui, response);
if (webui->cntlst[indx]->conf.stream_preview_method == 3){
preview_scale = 45;
} else {
preview_scale = 95;
}
strm_info.motion_images = FALSE;
webu_html_strminfo(&strm_info, indx);
snprintf(response, sizeof (response),
" preview=\"<a href=%s://%s:%d%s%s> "
" <img src=%s://%s:%d%s%s/ border=0 width=%d%%></a>\" \n"
,strm_info.proto, webui->hostname, strm_info.port
,strm_info.lnk_camid, strm_info.lnk_ref
,strm_info.proto, webui->hostname,strm_info.port
,strm_info.lnk_camid, strm_info.lnk_src, preview_scale);
webu_write(webui, response);
if (webui->cntlst[indx]->conf.stream_preview_method == 3){
strm_info.motion_images = TRUE;
webu_html_strminfo(&strm_info, indx);
snprintf(response, sizeof (response),
" preview=preview + \"<a href=%s://%s:%d%s%s> "
" <img src=%s://%s:%d%s%s/ class=border width=%d%%></a>\" \n"
,strm_info.proto, webui->hostname, strm_info.port
,strm_info.lnk_camid, strm_info.lnk_ref
,strm_info.proto, webui->hostname,strm_info.port
,strm_info.lnk_camid, strm_info.lnk_src, preview_scale);
webu_write(webui, response);
}
if (webui->cntlst[indx]->conf.camera_name == NULL){
snprintf(response, sizeof (response),
" header=\"<h3 id='h3_cam' data-cam='\" + camid + \"' "
" class='header-center' >%s %d (%s)</h3>\"\n"
,_("Camera")
, webui->cntlst[indx]->camera_id
,(!webui->cntlst[indx]->running)? _("Not running") :
(webui->cntlst[indx]->lost_connection)? _("Lost connection"):
(webui->cntlst[indx]->pause)? _("Paused"):_("Active")
);
} else {
snprintf(response, sizeof (response),
" header=\"<h3 id='h3_cam' data-cam='\" + camid + \"' "
" class='header-center' >%s (%s)</h3>\"\n"
, webui->cntlst[indx]->conf.camera_name
,(!webui->cntlst[indx]->running)? _("Not running") :
(webui->cntlst[indx]->lost_connection)? _("Lost connection"):
(webui->cntlst[indx]->pause)? _("Paused"):_("Active")
);
}
webu_write(webui, response);
snprintf(response, sizeof (response),"%s"," }\n");
webu_write(webui, response);
}
return;
}
static void webu_html_script_camera_all(struct webui_ctx *webui) {
/* Write the javascript "All" IF condition of camera_click() function */
char response[WEBUI_LEN_RESP];
int indx, indx_st, preview_scale;
struct strminfo_ctx strm_info;
indx_st = 1;
if (webui->cam_threads == 1) indx_st = 0;
strm_info.cntlst = webui->cntlst;
snprintf(response, sizeof (response), " if (camid == \"cam_all00\"){\n");
webu_write(webui, response);
for (indx = indx_st; indx<webui->cam_threads; indx++){
if (indx == indx_st){
snprintf(response, sizeof (response),"%s"," preview = \"\";\n");
webu_write(webui, response);
}
if (webui->cntlst[indx]->conf.stream_preview_newline){
snprintf(response, sizeof (response),"%s"," preview = preview + \" <br>\";\n");
webu_write(webui, response);
}
if (webui->cntlst[indx]->conf.stream_preview_method == 3){
preview_scale = 45;
} else {
preview_scale = webui->cntlst[indx]->conf.stream_preview_scale;
}
strm_info.motion_images = FALSE;
webu_html_strminfo(&strm_info, indx);
snprintf(response, sizeof (response),
" preview = preview + \"<a href=%s://%s:%d%s%s> "
" <img src=%s://%s:%d%s%s border=0 width=%d%%></a>\"; \n"
,strm_info.proto, webui->hostname, strm_info.port
,strm_info.lnk_camid, strm_info.lnk_ref
,strm_info.proto, webui->hostname, strm_info.port
,strm_info.lnk_camid, strm_info.lnk_src
,preview_scale);
webu_write(webui, response);
if (webui->cntlst[indx]->conf.stream_preview_method == 3){
strm_info.motion_images = TRUE;
webu_html_strminfo(&strm_info, indx);
snprintf(response, sizeof (response),
" preview = preview + \"<a href=%s://%s:%d%s%s> "
" <img src=%s://%s:%d%s%s class=border width=%d%%></a>\"; \n"
,strm_info.proto, webui->hostname, strm_info.port
,strm_info.lnk_camid, strm_info.lnk_ref
,strm_info.proto, webui->hostname, strm_info.port
,strm_info.lnk_camid, strm_info.lnk_src
,preview_scale);
webu_write(webui, response);
}
}
snprintf(response, sizeof (response),
" header=\"<h3 id='h3_cam' data-cam='\" + camid + \"' "
" class='header-center' >%s</h3>\"\n"
" }\n"
,_("All Cameras"));
webu_write(webui, response);
return;
}
static void webu_html_script_camera(struct webui_ctx *webui) {
/* Write the javascript camera_click() function */
char response[WEBUI_LEN_RESP];
snprintf(response, sizeof (response),"%s",
" function camera_click(camid) {\n"
" var preview = \"\";\n"
" var header = \"\";\n");
webu_write(webui, response);
webu_html_script_camera_thread(webui);
webu_html_script_camera_all(webui);
snprintf(response, sizeof (response),"%s",
" document.getElementById(\"id_preview\").innerHTML = preview; \n"
" document.getElementById(\"id_header\").innerHTML = header; \n"
" document.getElementById('cfg_form').style.display=\"none\"; \n"
" document.getElementById('trk_form').style.display=\"none\"; \n"
" document.getElementById('cam_btn').style.display=\"none\"; \n"
" document.getElementById('cfg_value').value = '';\n"
" document.getElementById('cfg_parms').value = 'default';\n"
" }\n\n");
webu_write(webui, response);
}
static void webu_html_script_menucam(struct webui_ctx *webui) {
/* Write the javascript display_cameras() function */
char response[WEBUI_LEN_RESP];
snprintf(response, sizeof (response),"%s",
" function display_cameras() {\n"
" document.getElementById('act_btn').style.display = 'none';\n"
" if (document.getElementById('cam_btn').style.display == 'block'){\n"
" document.getElementById('cam_btn').style.display = 'none';\n"
" } else {\n"
" document.getElementById('cam_btn').style.display = 'block';\n"
" }\n"
" }\n\n");
webu_write(webui, response);
}
static void webu_html_script_menuact(struct webui_ctx *webui) {
/* Write the javascript display_actions() function */
char response[WEBUI_LEN_RESP];
snprintf(response, sizeof (response),"%s",
" function display_actions() {\n"
" document.getElementById('cam_btn').style.display = 'none';\n"
" if (document.getElementById('act_btn').style.display == 'block'){\n"
" document.getElementById('act_btn').style.display = 'none';\n"
" } else {\n"
" document.getElementById('act_btn').style.display = 'block';\n"
" }\n"
" }\n\n");
webu_write(webui, response);
}
static void webu_html_script_evtclk(struct webui_ctx *webui) {
/* Write the javascript 'click' EventListener */
char response[WEBUI_LEN_RESP];
snprintf(response, sizeof (response),"%s",
" document.addEventListener('click', function(event) {\n"
" const dropCam = document.getElementById('cam_drop');\n"
" const dropAct = document.getElementById('act_drop');\n"
" if (!dropCam.contains(event.target) && !dropAct.contains(event.target)) {\n"
" document.getElementById('cam_btn').style.display = 'none';\n"
" document.getElementById('act_btn').style.display = 'none';\n"
" }\n"
" });\n\n");
webu_write(webui, response);
}
static void webu_html_script_cfgclk(struct webui_ctx *webui) {
/* Write the javascript config_click function
* We do not have a good notification section on the page so the successful
* submission and response is currently a empty if block for the future
* enhancement to somehow notify the user everything worked */
char response[WEBUI_LEN_RESP];
snprintf(response, sizeof (response),"%s",
" function config_click() {\n"
" var camstr = document.getElementById('h3_cam').getAttribute('data-cam');\n"
" var camnbr = camstr.substring(4,9);\n"
" var opts = document.getElementById('cfg_parms');\n"
" var optsel = opts.options[opts.selectedIndex].value;\n"
" var baseval = document.getElementById('cfg_value').value;\n"
" var http = new XMLHttpRequest();\n");
webu_write(webui, response);
snprintf(response, sizeof (response),
" var url = \"%s://%s:%d/\"; \n"