-
Notifications
You must be signed in to change notification settings - Fork 20
/
pages_admin.ml
3785 lines (3738 loc) · 124 KB
/
pages_admin.ml
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
(**************************************************************************)
(* BELENIOS *)
(* *)
(* Copyright © 2012-2023 Inria *)
(* *)
(* This program is free software: you can redistribute it and/or modify *)
(* it under the terms of the GNU Affero General Public License as *)
(* published by the Free Software Foundation, either version 3 of the *)
(* License, or (at your option) any later version, with the additional *)
(* exemption that compiling, linking, and/or using OpenSSL is allowed. *)
(* *)
(* This program 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 *)
(* Affero General Public License for more details. *)
(* *)
(* You should have received a copy of the GNU Affero General Public *)
(* License along with this program. If not, see *)
(* <http://www.gnu.org/licenses/>. *)
(**************************************************************************)
open Lwt
open Lwt.Syntax
open Belenios
open Belenios_api.Serializable_t
open Belenios_server_core
open Web_common
open Eliom_content.Html.F
open Eliom_content.Html.F.Form
module Make
(Web_state : Web_state_sig.S)
(Web_i18n : Web_i18n_sig.S)
(Web_services : Web_services_sig.S)
(Pages_common : Pages_common_sig.S)
(Mails_admin : Belenios_ui.Mails_admin_sig.S) =
struct
open Web_services
open Pages_common
let admin_background = " background: #FF9999;"
let get_preferred_gettext () = Web_i18n.get_preferred_gettext "admin"
let privacy_notice cont =
let* l = get_preferred_gettext () in
let open (val l) in
let title = s_ "Election server" ^ " — " ^ s_ "Terms of service" in
let content =
[
div
[
txt (s_ "To use this site, you must accept our ");
direct_a !Web_config.tos (s_ "terms of service");
txt ".";
];
post_form ~service:privacy_notice_accept
(fun ncont ->
[
div
[
input ~input_type:`Hidden ~name:ncont ~value:cont
(user string_of_privacy_cont);
input
~a:[ a_id "accept_tos" ]
~input_type:`Submit ~value:(s_ "Accept") string;
];
])
();
]
in
base ~title ~content ()
let checkpriv_link l uuid =
let open (val l : Belenios_ui.I18n.GETTEXT) in
let uri_base =
let service = Eliom_service.static_dir () in
Eliom_uri.make_string_uri ~absolute:true ~service
[ "static"; "checkpriv.html" ]
|> rewrite_prefix
in
let uri =
uri_base ^ "#" ^ Uuid.unwrap uuid |> Eliom_content.Xml.uri_of_string
in
Eliom_content.Html.F.Raw.a
~a:[ a_href uri ]
[ txt @@ s_ "Check private key ownership" ]
let login_box ?cont () =
let* l = get_preferred_gettext () in
let open (val l) in
let style = "float: right; text-align: right;" ^ admin_background in
let* user = Eliom_reference.get Web_state.site_user in
let auth_systems =
List.map (fun x -> x.auth_instance) !Web_config.site_auth_config
in
let cont = match cont with None -> ContSiteHome | Some x -> x in
let cont = default_admin cont in
let login service =
Eliom_service.preapply ~service:site_login (Some service, cont)
in
let logout () = Eliom_service.preapply ~service:logout cont in
let body =
match user with
| Some (_, account, _) ->
[
div
[
txt (s_ "Logged in as");
txt " ";
em [ a ~service:Web_services.account [ txt account.name ] () ];
txt ".";
];
div
[
a
~a:[ a_id "logout" ]
~service:(logout ())
[ txt (s_ "Log out") ]
();
txt ".";
];
]
| None ->
[
div [ txt (s_ "Not logged in.") ];
(let auth_systems =
List.map
(fun name ->
a
~a:[ a_id ("login_" ^ name) ]
~service:(login name)
[ txt name ]
())
auth_systems
|> List.join (txt ", ")
in
div ([ txt (s_ "Log in:"); txt " [" ] @ auth_systems @ [ txt "]" ]));
]
in
return (div ~a:[ a_style style ] body)
let admin_login get_handler =
let* l = get_preferred_gettext () in
let open (val l) in
let contact =
match !Web_config.contact_uri with
| None -> txt ""
| Some uri ->
div
[
txt (s_ "If you do not have any account, you may ");
direct_a ~target:"_blank" uri (s_ "contact us");
txt ".";
]
in
let* auth_div =
match !Web_config.site_auth_config with
| [] -> return @@ txt ""
| { auth_instance = service; _ } :: others ->
let* default = get_handler service in
let default =
match default with
| Web_auth_sig.Html x ->
div ~a:[ a_class [ "embedded-login-form" ] ] [ x ]
| Web_auth_sig.Redirection _ ->
div
[
txt (s_ "Log in with");
txt " ";
a ~service:site_login
[ txt service ]
(Some service, default_admin ContSiteAdmin);
txt ".";
]
in
let others =
List.map
(fun { auth_instance = service; _ } ->
div
[
txt (s_ "You can also log in with");
txt " ";
a ~service:site_login
[ txt service ]
(Some service, default_admin ContSiteAdmin);
txt ".";
])
others
in
return @@ div (default :: others)
in
let* body =
let default =
div
[ txt (s_ "To administer an election, you need to log in."); contact ]
in
read_snippet ~default ~lang !Web_config.admin_home
in
let content = [ body; auth_div ] in
let title = "Belenios" ^ " — " ^ s_ "Verifiable online voting platform" in
let* login_box = login_box ~cont:ContSiteAdmin () in
base ~title ~login_box ~content ()
let try_new_ui l uuid =
let@ () =
fun cont -> if !Web_config.restricted_mode then txt "" else cont ()
in
let open (val l : Belenios_ui.I18n.GETTEXT) in
div
@@
let str, xml =
let s_ = Belenios_ui.I18n.s_xml s_ in
s_
"<div><b>New:</b> try the <a>experimental interface</a> (more \
ergonomic)</div>"
in
match xml with
| Element ("div", [], xs) ->
List.map
(function
| Xml_light_types.PCData x -> txt x
| Element ("b", [], [ PCData x ]) ->
span ~a:[ a_class [ "markup-b" ] ] [ txt x ]
| Element ("a", [], [ PCData x ]) ->
Eliom_content.Html.F.Raw.a
~a:[ a_href (make_admin_new_uri uuid); a_id "experimental" ]
[ txt x ]
| _ -> txt str)
xs
| _ -> [ txt str ]
let admin ~elections =
let* l = get_preferred_gettext () in
let open (val l) in
let format_election { uuid; name; _ } =
let name = if name = "" then s_ "(no title)" else name in
li
[
a ~service:election_admin
~a:[ a_id ("election_admin_" ^ Uuid.unwrap uuid) ]
[ txt name ]
uuid;
]
in
let format_draft_election { uuid; name; _ } =
let name = if name = "" then s_ "(no title)" else name in
li
[
a ~service:election_draft
~a:[ a_id ("election_draft_" ^ Uuid.unwrap uuid) ]
[ txt name ]
uuid;
]
in
let title = s_ "Election server" ^ " — " ^ s_ "Administration" in
match elections with
| draft, elections, tallied, archived ->
let draft =
match draft with
| [] -> p [ txt (s_ "You own no such elections!") ]
| _ -> ul @@ List.map format_draft_election draft
in
let elections =
match elections with
| [] -> p [ txt (s_ "You own no such elections!") ]
| _ -> ul @@ List.map format_election elections
in
let tallied =
match tallied with
| [] -> p [ txt (s_ "You own no such elections!") ]
| _ -> ul @@ List.map format_election tallied
in
let archived =
match archived with
| [] -> p [ txt (s_ "You own no such elections!") ]
| _ -> ul @@ List.map format_election archived
in
let prepare_new_election =
if !Web_config.deny_newelection then
div [ txt (s_ "New elections are not allowed on this server.") ]
else
div
[
a
~a:[ a_id "prepare_new_election" ]
~service:election_draft_pre
[ txt (s_ "Prepare a new election") ]
();
]
in
let content =
[
div
[
prepare_new_election;
div [ br () ];
try_new_ui l None;
div [ br () ];
h2 [ txt (s_ "Elections being prepared") ];
draft;
div [ br () ];
h2 [ txt (s_ "Elections you can administer") ];
elections;
div [ br () ];
h2 [ txt (s_ "Tallied elections") ];
tallied;
div [ br () ];
h2 [ txt (s_ "Archived elections") ];
archived;
];
]
in
let* login_box = login_box () in
let* lang_box = lang_box ContSiteAdmin in
base ~lang_box ~title ~login_box ~content ()
let new_election_failure reason () =
let* l = get_preferred_gettext () in
let open (val l) in
let title = s_ "Create new election" in
let reason =
match reason with
| `Exists -> txt (s_ "An election with the same UUID already exists.")
| `Exception e -> txt @@ Printexc.to_string e
in
let content =
[ div [ p [ txt (s_ "The creation failed.") ]; p [ reason ] ] ]
in
let* login_box = login_box () in
base ~title ~login_box ~content ()
let election_draft_pre () =
let* l = get_preferred_gettext () in
let open (val l) in
let title = s_ "Prepare a new election" in
let form =
post_form ~service:election_draft_new
(fun (credmgmt, (auth, cas_server)) ->
let auth_systems =
!Web_config.exported_auth_config
|> List.mapi (fun i x ->
let checked = i = 0 in
match x with
| `BuiltinPassword ->
div
[
label
[
radio ~checked ~name:auth ~value:"password"
string;
txt " ";
txt
(s_
"sent in advance by e-mail (useful for \
multiple elections)");
];
]
| `BuiltinCAS ->
div
[
label
[
radio ~checked ~name:auth ~value:"cas" string;
txt " ";
txt
(s_
"CAS (external authentication server, \
offers better security guarantees when \
applicable)");
];
div
~a:[ a_style "margin-left: 5em;" ]
[
txt (s_ "Server address:");
txt " ";
input ~input_type:`Text ~name:cas_server string;
txt " ";
txt
(s_ "(for example: https://cas.inria.fr/cas)");
];
]
| `Export a ->
let legend =
match a.auth_system with
| "email" ->
[
txt
(s_
"sent by e-mail when voting (a short \
password, renewed for each vote)");
]
| _ ->
[
txt a.auth_instance;
txt " ";
txt (s_ "(imported from server)");
]
in
div
[
label
(radio ~checked ~name:auth
~value:("%" ^ a.auth_instance) string
:: txt " " :: legend);
])
in
let auto_credentials, checked =
if !Web_config.restricted_mode then (txt "", true)
else
( div
[
label
[
radio ~checked:true ~name:credmgmt ~value:"auto" string;
txt " ";
txt
(s_
"sent by our server (easier mode but offers less \
security)");
];
],
false )
in
[
div
[
txt
(s_
"For a better control of eligibility, voters will be \
authenticated by two factors: credentials and passwords");
txt " (";
direct_a Belenios_ui.Links.setup (s_ "more info");
txt ").";
];
ol
[
li
[
txt (s_ "Credentials:");
auto_credentials;
div
[
label
[
radio ~checked ~name:credmgmt ~value:"manual" string;
txt " ";
txt
(s_
"sent by a third party chosen by you (safe \
mode)");
];
];
];
li (txt (s_ "Passwords:") :: auth_systems);
];
div [ input ~input_type:`Submit ~value:(s_ "Proceed") string ];
])
()
in
let content = [ form ] in
let* login_box = login_box () in
base ~title ~login_box ~content ()
let preview_booth l uuid metadata =
let open (val l : Belenios_ui.I18n.GETTEXT) in
let hash =
Netencoding.Url.mk_url_encoded_parameters
[ ("uuid", Uuid.unwrap uuid); ("lang", lang); ("draft", "1") ]
in
match get_booth_index metadata.e_booth_version with
| Some i ->
let (Booth election_vote) = fst booths.(i) in
let service =
Eliom_uri.make_string_uri ~service:(election_vote ()) ~absolute:true
()
|> rewrite_prefix
in
span [ direct_a (service ^ "#" ^ hash) (s_ "Preview booth") ]
| None -> span [ txt @@ s_ "Unsupported booth version" ]
let election_draft uuid (Draft (_, se) as fse) () =
let* l = get_preferred_gettext () in
let open (val l) in
let title =
Printf.sprintf (f_ "Preparation of election %s") se.se_questions.t_name
in
let available_languages = List.map fst Belenios_ui.Languages.available in
let form_languages =
post_form ~service:election_draft_languages
(fun languages ->
[
div
[
txt (s_ "Languages:");
txt " ";
input ~name:languages ~input_type:`Text
~value:(string_of_languages se.se_metadata.e_languages)
string;
txt " (";
txt (s_ "Available languages:");
txt " ";
txt (string_of_languages (Some available_languages));
txt ")";
];
div
[
txt
(s_
"This is a space-separated list of languages that will be \
used in e-mails sent by the server.");
];
div [ input ~input_type:`Submit ~value:(s_ "Save changes") string ];
])
uuid
in
let div_languages = div [ h2 [ txt (s_ "Languages") ]; form_languages ] in
let form_description =
post_form ~service:election_draft_description
~a:[ a_id "name_and_description_form" ]
(fun (name, description) ->
[
div
[
txt (s_ "Name of the election:");
txt " ";
input ~name ~input_type:`Text ~value:se.se_questions.t_name
~a:[ a_placeholder (s_ "Name of the election") ]
string;
];
div
[
div [ txt (s_ "Description of the election:"); txt " " ];
div
[
textarea ~name:description
~a:
[
a_cols 80;
a_placeholder (s_ "Description of the election.");
]
~value:se.se_questions.t_description ();
];
];
div [ input ~input_type:`Submit ~value:(s_ "Save changes") string ];
])
uuid
in
let div_description =
div
[
h2 [ txt (s_ "Name and description of the election") ];
form_description;
]
in
let form_admin_name =
post_form ~service:election_draft_admin_name
~a:[ a_id "form_admin_name" ]
(fun name ->
[
div
[
txt (s_ "Public name of the administrator:");
txt " ";
(let value =
match se.se_administrator with Some x -> x | None -> ""
in
input ~name ~input_type:`Text ~value string);
];
div
[
txt
(s_ "This name will be published on the election result page.");
];
div [ input ~input_type:`Submit ~value:(s_ "Save changes") string ];
])
uuid
in
let div_admin_name =
div
[ h2 [ txt (s_ "Public name of the administrator") ]; form_admin_name ]
in
let form_contact =
post_form ~service:election_draft_contact
~a:[ a_id "form_contact" ]
(fun contact ->
[
div
[
txt (s_ "Contact:");
txt " ";
(let value =
match se.se_metadata.e_contact with
| Some x -> x
| None -> Defaults.contact
in
input ~name:contact ~input_type:`Text ~value
~a:[ a_placeholder (s_ "Name <user@example.org>") ]
string);
];
div
[
txt
(s_
"This contact will be added to e-mails sent to the voters.");
];
div [ input ~input_type:`Submit ~value:(s_ "Save changes") string ];
])
uuid
in
let div_contact = div [ h2 [ txt (s_ "Contact") ]; form_contact ] in
let auth =
match se.se_metadata.e_auth_config with
| Some [ { auth_system = "password"; _ } ] -> `Password
| Some [ { auth_system = "dummy"; _ } ] -> `Dummy
| Some
[ { auth_system = "cas"; auth_config = [ ("server", server) ]; _ } ]
->
`CAS server
| Some [ { auth_system = "import"; auth_instance = name; _ } ] ->
`Import name
| _ -> failwith "unknown authentication scheme in election_draft"
in
let div_auth =
div
[
h2 [ txt (s_ "Authentication") ];
(match auth with
| `Password ->
div
[
txt (s_ "Authentication scheme: password");
(if List.for_all (fun v -> v.sv_password <> None) se.se_voters
then div [ txt (s_ "All passwords have been sent!") ]
else
post_form ~service:election_draft_auth_genpwd
(fun () ->
[
input ~input_type:`Submit
~value:(s_ "Generate and mail missing passwords")
string;
])
uuid);
]
| `Dummy -> div [ txt (s_ "Authentication scheme: dummy") ]
| `CAS server ->
div
[
txt (s_ "Authentication scheme: CAS with server "); txt server;
]
| `Import name ->
div
[
txt
(Printf.sprintf
(f_ "Authentication scheme: %s (imported from server)")
name);
]);
]
in
let div_questions =
div
[
h2
[
a
~a:[ a_id "edit_questions" ]
~service:election_draft_questions
[ txt (s_ "Edit questions") ]
uuid;
];
preview_booth l uuid se.se_metadata;
]
in
let div_voters =
div
[
h2
[
a
~a:[ a_id "edit_voters" ]
~service:election_draft_voters
[ txt (s_ "Edit voters") ]
uuid;
];
div
[
txt @@ string_of_int @@ List.length se.se_voters;
txt (s_ " voter(s) registered");
];
]
in
let div_trustees =
div
[
h2 [ txt (s_ "Trustees") ];
div
[
txt
(s_
"By default, the election server manages the keys of the \
election (degraded privacy mode).");
txt " ";
txt
(s_
"For real elections, the key must be shared among \
independent trustees.");
txt " ";
txt (s_ "Click ");
a ~service:election_draft_trustees [ txt (s_ "here") ] uuid;
txt (s_ " to set up the election key.");
];
]
in
let cred_auth_is_server = se.se_metadata.e_cred_authority = Some "server" in
let div_credentials =
div
[
h2 [ txt (s_ "Credentials") ];
(match Web_persist.get_credentials_status uuid fse with
| `Done ->
let div_private_creds =
if cred_auth_is_server then
div
[
a ~service:election_draft_credentials_get
[ txt (s_ "Download private credentials") ]
uuid;
]
else txt ""
in
let div_edit_credential_authority_name =
if cred_auth_is_server then txt ""
else
div
[
a ~service:election_draft_credential_authority
[ txt (s_ "Edit credential authority name") ]
uuid;
]
in
div
[
div [ txt (s_ "Credentials have already been generated!") ];
div_edit_credential_authority_name;
div_private_creds;
]
| `None ->
div
[
txt (s_ "Warning: this will freeze the voter list!");
(if cred_auth_is_server then
post_form ~service:election_draft_credentials_server
(fun () ->
[
input ~input_type:`Submit
~value:(s_ "Generate on server") string;
])
uuid
else
div
[
a ~service:election_draft_credential_authority
[ txt (s_ "Credential management") ]
uuid;
]);
]
| `Pending n ->
div
[
txt (s_ "Credentials are being generated on the server.");
txt " ";
Printf.ksprintf txt (f_ "Number of credentials left: %d.") n;
]);
]
in
let link_confirm =
div
[
h2 [ txt (s_ "Validate creation") ];
a ~service:election_draft_confirm [ txt (s_ "Create election") ] uuid;
]
in
let form_destroy =
let t =
Option.value se.se_creation_date ~default:Defaults.creation_date
in
let t = Period.add t (Period.day Defaults.days_to_delete) in
post_form ~service:election_draft_destroy
(fun () ->
[
div
[
h2 [ txt (s_ "Destroy election") ];
div
[
txt
(s_
"Note: this election will be automatically destroyed \
after ");
txt (Datetime.format t);
txt ".";
];
input ~input_type:`Submit ~value:(s_ "Destroy election") string;
];
])
uuid
in
let content =
[
try_new_ui l (Some uuid);
hr ();
div_description;
hr ();
div_admin_name;
hr ();
div_languages;
hr ();
div_contact;
hr ();
div_questions;
hr ();
div_voters;
hr ();
div_credentials;
hr ();
div_auth;
hr ();
div_trustees;
hr ();
link_confirm;
hr ();
form_destroy;
]
in
let* login_box = login_box () in
base ~title ~login_box ~content ()
let election_draft_trustees ?token uuid (Draft (_, se)) () =
let* l = get_preferred_gettext () in
let open (val l) in
let title =
Printf.sprintf (f_ "Trustees for election %s") se.se_questions.t_name
in
let form_trustees_add =
post_form ~service:election_draft_trustee_add
(fun (n_id, n_comment) ->
[
txt (s_ "Trustee's e-mail address:");
txt " ";
input ~input_type:`Text ~name:n_id string;
txt ", ";
txt (s_ "public name:");
txt " ";
input ~input_type:`Text ~name:n_comment string;
input ~input_type:`Submit ~value:(s_ "Add") string;
])
uuid
in
let mk_form_trustee_del value =
post_form ~service:election_draft_trustee_del
(fun name ->
[
input ~input_type:`Hidden ~name ~value string;
input ~input_type:`Submit ~value:(s_ "Remove") string;
])
uuid
in
let langs = get_languages se.se_metadata.e_languages in
let* trustees =
match se.se_trustees with
| `Basic x when x.dbp_trustees <> [] ->
let ts = x.dbp_trustees in
let* ts =
Lwt_list.map_s
(fun t ->
let this_line =
match token with
| Some x when x = t.st_token -> true
| _ -> false
in
let uri =
compute_hash_link ~uuid ~token:t.st_token
~service:election_draft_trustee_static
in
let* mail_cell, link_cell =
if t.st_token <> "" then
if t.st_public_key = "" then
let* subject, body =
Mails_admin.mail_trustee_generation_basic langs uri
in
let mail_cell =
a_mailto ~dest:t.st_id ~subject ~body (s_ "E-mail")
in
let link_cell =
if this_line then
a ~service:election_draft_trustees
[ txt (s_ "Hide link") ]
uuid
else
Raw.a
~a:[ a_href (Xml.uri_of_string uri) ]
[ txt (s_ "Link") ]
in
return (mail_cell, link_cell)
else
let cell = txt (s_ "(done)") in
return (cell, cell)
else
let cell = txt (s_ "(server)") in
return (cell, cell)
in
let first_line =
tr
[
td [ txt t.st_id ];
td
[
(match t.st_name with
| None -> txt (s_ "(not available)")
| Some x -> txt x);
];
td [ mail_cell ];
td [ link_cell ];
td
[
txt
(if t.st_public_key = "" then s_ "No" else s_ "Yes");
];
td
[
(if t.st_id = "server" then
txt (s_ "(cannot be removed)")
else mk_form_trustee_del t.st_id);
];
]
in
let second_line =
if this_line then
[
tr
[
td
~a:[ a_colspan 6 ]
[
txt (s_ "The link that must be sent to trustee ");
txt t.st_id;
txt (s_ " is:");
br ();
txt uri;
];
];
]
else []
in
return (first_line :: second_line))
ts
in
return
@@ table
(tr
[
th [ txt (s_ "Trustee") ];
th [ txt (s_ "Public name") ];
th [ txt (s_ "E-mail") ];
th [ txt (s_ "Link") ];
th [ txt (s_ "Done?") ];
th [ txt (s_ "Remove") ];
]
:: List.flatten ts)
| _ -> return (txt "")
in
let import_link =
div
[
a ~service:Web_services.election_draft_import_trustees
[ txt (s_ "Import trustees from another election") ]
uuid;
]
in
let div_trustees =
match se.se_trustees with
| `Basic x ->
div
[
trustees;
(if x.dbp_trustees <> [] then
div
[
txt
(s_
"There is one link per trustee. Send each trustee \
the respective link.");
br ();
br ();
]
else txt "");
form_trustees_add;
]
| `Threshold _ -> txt ""
in