forked from multiOTP/multiotp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
multiotp.server.php
1758 lines (1622 loc) · 77.4 KB
/
multiotp.server.php
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
<?php
/**
* @file multiotp.server.php
* @brief web service for the multiOTP class.
*
* multiOTP web service - Strong two-factor authentication PHP class
* https://www.multiotp.net
*
* Visit http://forum.multiotp.net/ for additional support.
*
* Donation are always welcome! Please check https://www.multiotp.net
* and you will find the magic button ;-)
*
* The multiOTP web service is simply merged with the multiOTP PHP class
* in order to provide the server part of the client/server solution.
*
* This file can be used with any web server supporting PHP as
* script language, like the following web servers:
* - nginx is a light one under Linux
* (http://nginx.org/)
* - Mongoose is a light one under Windows
* (https://code.google.com/archive/p/mongoose/downloads)
* - The Apache HTTP server is a very well known web server running under Linux and Windows
* (http://httpd.apache.org/)
*
*
* PHP 5.4.0 or higher is supported.
*
* @author Andre Liechti, SysCo systemes de communication sa, <info@multiotp.net>
* @version 5.9.5.5
* @date 2023-01-19
* @since 2013-08-06
* @copyright (c) 2013-2023 SysCo systemes de communication sa
* @copyright GNU Lesser General Public License
*
*//*
*
* LICENCE
*
* Copyright (c) 2010-2023 SysCo systemes de communication sa
* SysCo (tm) is a trademark of SysCo systemes de communication sa
* (http://www.sysco.ch)
* All rights reserved.
*
* This file is part of the multiOTP PHP class
*
* multiOTP PHP class 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 of the License,
* or (at your option) any later version.
*
* multiOTP PHP class 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 MultiOTP PHP class.
* If not, see <http://www.gnu.org/licenses/>.
*
*
* Usage
*
* You will have to send an XML formatted content in the field named data
* in a POSTed form.
*
*
* Special issues
*
* If you need specific developments concerning strong authentication,
* do not hesitate to contact us per email at info@multiotp.net.
*
*
* Users feedbacks and comments
*
* 2017-02-09 Frank van der Aa, Vanboxtel BV (NL)
* Thanks for your debug about lockedlistarray[], the new
* GetDelayedUsersList() method and the delayed users display on the web GUI.
*
* 2013-07-25 Dominik Pretzsch from Last Squirrel IT
* After some discussions with Dominik, integration of the
* client/server support in the basic library
*
*
* Change Log
*
* 2022-05-08 5.8.8.5 SysCo/al Scratchlist can be generated from the Web GUI
* 2021-03-25 5.8.1.9 SysCo/al Cookie privacy (httponly and secure) are now handled in the application directly
* Weak SSL ciphers disabled
* 2021-02-12 5.8.1.0 SysCo/al Web GUI update
* 2019-01-24 5.4.1.5 SysCo/al If any, clean specific NTP DHCP option at every reboot
* 2019-01-07 5.4.1.1 SysCo/al Raspberry Pi 3B+ support
* 2018-08-21 5.3.0.0 SysCo/al without2FA algorithm added
* 2017-07-07 5.0.4.9 SysCo/al Code cleaning, possible web information added
* 2017-05-29 5.0.4.5 SysCo/al Restore configuration added
* Fixed configuration file directory under Windows
* The file can now be included from another one that have already an instance
* 2016-11-06 5.0.2.7 SysCo/al Better configuration file detection
* 2016-11-04 5.0.2.6 SysCo/al Backup configuration added
* 2016-10-16 5.0.2.5 SysCo/al New methods added for SOAP service
* 2016-04-18 5.0.0.0 SysCo/al ForceNoDisplayLog() method called to avoid log on display
* 2015-07-15 4.3.2.5 SysCo/al Admin password update has been fixed
* 2015-06-10 4.3.2.3 SysCo/al Enhancements for the Dev(Talks): demo
* 2015-06-09 4.3.2.2 SysCo/al More option available from the GUI, Dev Talks Edition
* 2014-12-09 4.3.1.0 SysCo/al Speed improvement (apc options have been tuned)
* 2014-11-04 4.3.0.0 SysCo/al Updated GUI
* 2014-04-13 4.2.4.2 SysCo/al Version synchronization
* 2014-03-30 4.2.4 SysCo/al Forum link added on the GUI, minor bug fixes
* 2014-03-01 4.2.2 SysCo/al More options available from the GUI
* 2014-01-20 4.1.1 SysCo/al Version synchronization
* 2013-12-23 4.1.0 SysCo/al Adding basic web functionalities
* 2013-08-30 4.0.7 SysCo/al Version synchronization
* 2013-08-25 4.0.6 SysCo/al Enhanced default page
* 2013-08-20 4.0.4 SysCo/al Initial release
*
*********************************************************************/
///////////////////////////////////////////////////////////////////////////
// For your convenience, the class file is directly integrated in this file
///////////////////////////////////////////////////////////////////////////
if (!class_exists('Multiotp')) {
require_once('multiotp.class.php');
}
$multiotp_etc_dir = '/etc/multiotp';
$config_folder = $multiotp_etc_dir.'/config';
if (false === mb_strpos(getcwd(), '/')) {
// if (!@file_exists($config_folder)) {
$multiotp_etc_dir = '';
$config_folder = '';
}
if (!isset($multiotp)) {
$multiotp = new Multiotp('DefaultCliEncryptionKey', false, '', $config_folder);
}
$multiotp->ForceNoDisplayLog(); // No log on display as we are running a web server
if ('' != $multiotp_etc_dir) {
$multiotp->SetLogFolder('/var/log/multiotp/');
$multiotp->SetConfigFolder($multiotp_etc_dir.'/config/');
$multiotp->SetDdnsFolder($multiotp_etc_dir.'/ddns/');
$multiotp->SetDevicesFolder($multiotp_etc_dir.'/devices/');
$multiotp->SetGroupsFolder($multiotp_etc_dir.'/groups/');
$multiotp->SetTokensFolder($multiotp_etc_dir.'/tokens/');
$multiotp->SetUsersFolder($multiotp_etc_dir.'/users/');
$multiotp->SetCacheFolder('/tmp/cache/');
$multiotp->SetLinuxFileMode('0666');
}
$multiotp->ReadConfigData();
$data = isset($_POST['data'])?$_POST['data']:'';
$method = mb_substr(isset($_GET['method'])?$_GET['method']:(isset($_POST['method'])?$_POST['method']:''),0,255);
$options = isset($_GET['options'])?$_GET['options']:(isset($_POST['options'])?$_POST['options']:'');
$postdata = file_get_contents("php://input");
if (FALSE !== mb_strpos($data,'<multiOTP')) {
$multiotp->XmlServer($data);
exit();
} elseif ((FALSE !== mb_strpos($postdata,'<SOAP-ENV')) || (isset($_GET['soap'])) || (isset($_GET['wsdl']))) {
/*******************
*******************
*** SOAP SERVER ***
*******************
******************/
// Instantiate the SOAP server
$soap_server = new soap_server();
$soap_service_name = "multiotp";
$soap_tns_namespace = 'https://www.multiotp.net/wsdl/multiotp/';
$soap_endpoint_url = false;
$soap_schema_target_namespace = 'https://www.multiotp.net/wsdl/multiotp/';
$soap_openotp_namespace = 'urn:openotp'; // urn:openotp
// Create the WSDL
$soap_server->configureWSDL($soap_service_name, $soap_tns_namespace, $soap_endpoint_url);
// Set the schema target namespace
// $soap_server->wsdl->schemaTargetNamespace = $soap_schema_target_namespace;
//Register openotpNormalLogin method
$soap_server->register(
'openotpNormalLogin', // method name
array('username' => 'xsd:string', // input parameters
'domain' => 'xsd:string',
'ldapPassword' => 'xsd:string',
'otpPassword' => 'xsd:string',
'client' => 'xsd:string',
'source' => 'xsd:string',
'settings' => 'xsd:string',
'options' => 'xsd:string'),
array('code' => 'xsd:integer', // return value(s)
'message' => 'xsd:string',
'session' => 'xsd:string',
'data' => 'xsd:string',
'timeout' => 'xsd:integer',
'otpChallenge' => 'xsd:string',
'u2fChallenge' => 'xsd:string'),
$soap_openotp_namespace, // namespace
false, // soapaction: (use default)
'rpc', // style: rpc or document
'encoded', // use: encoded or literal
'This method is used to send an authentication request.'); // description: documentation for the method
// Defined method
function openotpNormalLogin($username, $domain, $ldapPassword, $otpPassword, $client, $source, $settings, $options) {
global $multiotp;
return $multiotp->SoapOpenotpNormalLogin($username, $domain, $ldapPassword, $otpPassword, $client, $source, $settings, $options);
}
//Register openotpSimpleLogin method
$soap_server->register(
'openotpSimpleLogin',
array('username' => 'xsd:string',
'domain' => 'xsd:string',
'anyPassword' => 'xsd:string',
'client' => 'xsd:string',
'source' => 'xsd:string',
'settings' => 'xsd:string'),
array('code' => 'xsd:integer',
'message' => 'xsd:string',
'session' => 'xsd:string',
'data' => 'xsd:string',
'timeout' => 'xsd:integer'),
$soap_openotp_namespace,
false,
'rpc',
'encoded',
'This method is similar to openotpNormalLogin with only one generic password attribute.');
// Defined method
function openotpSimpleLogin($username, $domain, $anyPassword, $client, $source, $settings) {
global $multiotp;
return $multiotp->SoapOpenotpSimpleLogin($username, $domain, $anyPassword, $client, $source, $settings);
}
//Register openotpLogin method
$soap_server->register(
'openotpLogin',
array('username' => 'xsd:string', // input parameters
'domain' => 'xsd:string',
'ldapPassword' => 'xsd:string',
'otpPassword' => 'xsd:string',
'client' => 'xsd:string',
'source' => 'xsd:string',
'settings' => 'xsd:string',
'options' => 'xsd:string'),
array('code' => 'xsd:integer',
'message' => 'xsd:string',
'session' => 'xsd:string',
'data' => 'xsd:string',
'timeout' => 'xsd:integer'),
$soap_openotp_namespace,
false,
'rpc',
'encoded',
'This method is an alias of openotpNormalLogin. It ensures backward compatibility.');
// Defined method
function openotpLogin($username, $domain, $ldapPassword, $otpPassword, $client, $source, $settings, $options) {
global $multiotp;
return $multiotp->SoapOpenotpNormalLogin($username, $domain, $ldapPassword, $otpPassword, $client, $source, $settings, $options);
}
//Register openotpChallenge method
$soap_server->register(
'openotpChallenge',
array('username' => 'xsd:string',
'domain' => 'xsd:string',
'session' => 'xsd:string',
'otpPassword' => 'xsd:string',
'u2fResponse' => 'xsd:string'),
array('code' => 'xsd:integer',
'message' => 'xsd:string',
'data' => 'xsd:string'),
$soap_openotp_namespace,
false,
'rpc',
'encoded',
'This method is used when the openotpLogin returned a challenge (code 2). This is the second request to be sent containing the user one-time password.');
// Defined method
function openotpChallenge($username, $domain, $session, $otpPassword) {
global $multiotp;
return $multiotp->SoapOpenotpChallenge($username, $domain, $session, $otpPassword);
}
//Register openotpStatus method
$soap_server->register(
'openotpStatus',
array(),
array('status' => 'xsd:boolean',
'message' => 'xsd:string'),
$soap_openotp_namespace,
false,
'rpc',
'encoded',
'openotpStatus call');
// Defined method
function openotpStatus() {
global $multiotp;
return $multiotp->SoapOpenotpStatus();
}
$soap_server->service($postdata);
exit();
} else {
// Secure and httponly cookie parameters forced in the application
$params = session_get_cookie_params();
$cookie_secure = (!$multiotp->IsDebugOption()) && (!$multiotp->IsDeveloperMode());
$cookie_httponly = true;
session_set_cookie_params($params["lifetime"],
$params["path"], $params["domain"],
$cookie_secure, $cookie_httponly
);
session_start();
$multiotp->SetHashSalt('AjaxH@shS@lt'); // Shared secret
$hash_salt = $multiotp->GetHashSalt();
/****************************************
* WE REALLY DO NOT WANT TO BE CACHED !!!
****************************************/
header("Expires: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
$multiotp->SendWeeklyAnonymousStat();
if (isset($_FILES['upgrade_file']['tmp_name'])) {
if ((isset($_SESSION['logged']) && $_SESSION['logged'])) {
if (file_exists($_FILES['upgrade_file']['tmp_name']) && (UPLOAD_ERR_OK == $_FILES["upgrade_file"]["error"])) {
$upgrade_file = $multiotp->ConvertToWindowsPathIfNeeded(sys_get_temp_dir()."/".date("YmdHis")."-".md5($_FILES['upgrade_file']['tmp_name']).".cfg");
move_uploaded_file($_FILES['upgrade_file']['tmp_name'], $upgrade_file);
}
}
}
if (isset($_FILES['config_file']['tmp_name'])) {
if ((isset($_SESSION['logged']) && $_SESSION['logged'])) {
if (file_exists($_FILES['config_file']['tmp_name']) && (UPLOAD_ERR_OK == $_FILES["config_file"]["error"])) {
$config_file = $multiotp->GetConfigFolder().date("YmdHis")."-".md5($_FILES['config_file']['tmp_name']).".cfg";
if (move_uploaded_file($_FILES['config_file']['tmp_name'], $config_file)) {
if ($multiotp->RestoreConfiguration(array('backup_file' => $config_file, 'restore_key' => (isset($_POST['restore_config_password'])?nullable_trim($_POST['restore_config_password']):'')))) {
// Clean Devices
foreach (explode("\t", $multiotp->GetDevicesList()) as $one_device) {
if ('' != nullable_trim($one_device)) {
$multiotp->DeleteDevice($one_device);
}
}
$actual_folder = $multiotp->GetDevicesFolder();
$actual_filter = "*.db";
if (($actual_dir = opendir($actual_folder)) !== FALSE) {
while(($actual_file_name = readdir($actual_dir)) !== FALSE) {
if (fnmatch($actual_filter, $actual_file_name)) {
$actual_file = $actual_folder.$actual_file_name;
unlink($actual_file);
}
}
}
// Clean Groups
foreach (explode("\t", $multiotp->GetGroupsList()) as $one_group) {
if ('' != nullable_trim($one_group)) {
$multiotp->DeleteGroup($one_group);
}
}
$actual_folder = $multiotp->GetGroupsFolder();
$actual_filter = "*.db";
if (($actual_dir = opendir($actual_folder)) !== FALSE) {
while(($actual_file_name = readdir($actual_dir)) !== FALSE) {
if (fnmatch($actual_filter, $actual_file_name)) {
$actual_file = $actual_folder.$actual_file_name;
unlink($actual_file);
}
}
}
// Clean Tokens
foreach (explode("\t", $multiotp->GetTokensList()) as $one_token) {
if ('' != nullable_trim($one_token)) {
$multiotp->DeleteToken($one_token);
}
}
$actual_folder = $multiotp->GetTokensFolder();
$actual_filter = "*.db";
if (($actual_dir = opendir($actual_folder)) !== FALSE) {
while(($actual_file_name = readdir($actual_dir)) !== FALSE) {
if (fnmatch($actual_filter, $actual_file_name)) {
$actual_file = $actual_folder.$actual_file_name;
unlink($actual_file);
}
}
}
// Clean Users
$user_array = $multiotp->GetNextUserArray(TRUE);
while (FALSE !== $user_array) {
if (isset($user_array['user'])) {
$multiotp->DeleteUser($user_array['user']);
}
$user_array = $multiotp->GetNextUserArray();
}
$actual_folder = $multiotp->GetUsersFolder();
$actual_filter = "*.db";
if (($actual_dir = opendir($actual_folder)) !== FALSE) {
while(($actual_file_name = readdir($actual_dir)) !== FALSE) {
if (fnmatch($actual_filter, $actual_file_name)) {
$actual_file = $actual_folder.$actual_file_name;
unlink($actual_file);
}
}
}
$multiotp->RestoreConfiguration(array('backup_file' => $config_file, 'restore_key' => (isset($_POST['restore_config_password'])?nullable_trim($_POST['restore_config_password']):'')));
$_SESSION = array();
$_SESSION['logged'] = FALSE;
$ajax_result = "false";
// $multiotp->ReadConfigData();
header('Location: '.(isset($_SERVER['HTTPS']) ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]");
exit();
} // End of the restore is ok
} // if move_uploaded_file
if (file_exists($config_file)) {
unlink($config_file);
}
}
}
}
if (isset($_FILES['token_file']['tmp_name'])) {
if ((isset($_SESSION['logged']) && $_SESSION['logged'])) {
if (file_exists($_FILES['token_file']['tmp_name']) && (UPLOAD_ERR_OK == $_FILES["token_file"]["error"])) {
$multiotp->ImportTokensFile($_FILES['token_file']['tmp_name'], $_FILES['token_file']['name'], isset($_POST['token_password'])?nullable_trim($_POST['token_password']):'');
}
}
echo "DONE";
} elseif ('' == $method) {
/*********************
* Basic web server *
*********************/
$actual_date = date('Y-m-d H:i:s');
$class_name = $multiotp->GetClassName();
$class_version = $multiotp->GetVersion();
$class_date = $multiotp->GetDate();
$rpi_serial = $multiotp->GetRaspberryPiSerialNumber();
$rpi_info = (('' != $rpi_serial)?"<br />\n Raspberry Pi serial number: ".$rpi_serial."\n ":'');
$server_software = (isset($_SERVER['SERVER_SOFTWARE']) ? $_SERVER['SERVER_SOFTWARE'].', ' : '')."PHP/".phpversion();
$prefix_required0_checked = '';
$prefix_required1_checked = '';
if ($multiotp->IsDefaultRequestPrefixPin())
{
$prefix_required1_checked = ' checked="checked" ';
}
else
{
$prefix_required0_checked = ' checked="checked" ';
}
if ($multiotp->CheckAdminPassword("1234")) {
$default_user_info = "(default is admin)";
$default_password_info = "(default is 1234)";
} else {
$default_user_info = "";
$default_password_info = "";
}
$webpage = <<<EOWEBPAGE
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>
multiOTP web administration console
</title>
<style>
body {
font-family: Verdana, Helvetica, Arial;
color: black;
font-size: 10pt;
font-weight: normal;
text-decoration: none;
}
h2 {
font-size: 12pt;
font-weight: bold;
margin-top: 0em;
margin-bottom: 0em;
}
h3 {
font-size: 11pt;
font-weight: bold;
margin-top: 0.5em;
margin-bottom: 0.1em;
}
p {
margin-top: 0em;
margin-bottom: 0em;
}
th {
text-align: right;
}
.info {
font-style: italic;
font-weight: normal;
}
.section_title {
display: block;
font-weight: bold;
}
.section_title a {
color: black;
text-decoration: none;
}
/*************************/
/* Custom colors - BEGIN */
body {
background-color: black;
color: white;
font-family: Verdana, Helvetica, Arial;
font-size: 10pt;
font-weight: normal;
text-decoration: none;
}
.custom_logo_white {
color: white;
font-weight: bold;
font-size: 20px;
}
.custom_logo_red {
color: red;
font-weight: bold;
font-size: 20px;
}
a {
color: white;
font-weight: bold;
text-decoration: none;
}
a:hover {
color: red;
}
.section_title a {
color: white;
text-decoration: none;
}
.synced {
color: #80ff80;
}
.locked {
color: #ff4040;
}
.delayed {
color: #ff8000;
}
/* Custom colors - END */
/***********************/
</style>
<meta http-equiv="Content-type" content="text/html;charset=UTF-8" />
<script>
// Relative url page in order to execute the method remotely
var url_page = location.protocol + '//' + location.host + location.pathname;
// Shared secret
var hash_salt = '$hash_salt';
var selected_color = 'red';
var unselected_color = 'black';
var selected_background_color = '#e0e0e0';
var unselected_background_color = '';
var succeeded_color = '#80ff80';
var failed_color = 'red';
/*************************/
/* Custom colors - BEGIN */
var selected_color = 'red';
var unselected_color = 'white';
var selected_background_color = '#303030';
var unselected_background_color = '';
/* Custom colors - END */
/***********************/
function ChangeAdminPassword()
{
var newpassword = document.getElementById('newpassword').value;
var newpassword2 = document.getElementById('newpassword2').value;
document.getElementById('newpassword').value = '';
document.getElementById('newpassword2').value = '';
if ('' == newpassword)
{
alert('Password is empty!');
}
else if (newpassword != newpassword2)
{
alert('Passwords are not equal!');
}
else
{
var hash_password = md5(hash_salt+newpassword+hash_salt);
RemoteCall('SetAdminPasswordHash', hash_password);
Logout();
}
}
function Add()
{
var newuser = document.getElementById('newuser').value;
var newemail = document.getElementById('newemail').value;
var newsms = document.getElementById('newsms').value;
var prefix_required = (document.getElementById('prefix_required1').checked?'1':'0');
var algorithm = document.getElementById('algorithm').value;
var token_serial = document.getElementById('token_serial').value;
var pin = document.getElementById('pin').value;
if (IsLoggedIn())
{
RemoteCall('FastCreateUser', newuser+"\t"+newemail+"\t"+newsms+"\t"+prefix_required+"\t"+algorithm+"\t"+pin+"\t"+token_serial);
UpdatePage();
}
document.getElementById('newuser').value = '';
document.getElementById('newemail').value = '';
document.getElementById('newsms').value = '';
document.getElementById('newuser').focus();
}
function DeleteToken(one_token)
{
if ('' != one_token)
{
if (confirm('Are you sure you want to delete the token ' + one_token + '?'))
{
RemoteCall('DeleteToken', one_token);
UpdatePage();
}
}
}
function DeleteUser(one_user)
{
if ('' != one_user)
{
if (confirm('Are you sure you want to delete the user ' + one_user + '?'))
{
RemoteCall('DeleteUser', one_user);
UpdatePage();
}
}
}
function ResyncUserNow(resync_user, resync_otp1, resync_otp2)
{
var resynced = ('true' == eval(RemoteCall('ResyncUser', resync_user+"\t"+resync_otp1+"\t"+resync_otp2)));
if (resynced)
{
Toggle('resync', 'none');
document.getElementById('resync_user').value = '';
document.getElementById('resync_otp1').value = '';
document.getElementById('resync_otp2').value = '';
}
else
{
document.getElementById('resync_otp1').select();
document.getElementById('resync_otp1').focus();
}
}
function CheckUserNow(check_user_user, check_user_otp)
{
var result = eval(RemoteCall('CheckToken', check_user_user+"\t"+check_user_otp));
UpdatePage();
if ('true' == result)
{
document.getElementById('check_user_result').innerHTML = '<span style="color:'+succeeded_color+';">succeeded</span>';
document.getElementById('check_user_user').value = '';
document.getElementById('check_user_otp').value = '';
}
else
{
document.getElementById('check_user_result').innerHTML = '<span style="color:'+failed_color+';">failed ('+result+')</span>';
document.getElementById('check_user_user').select();
document.getElementById('check_user_user').focus();
document.getElementById('check_user_otp').value = '';
}
}
function BackupConfigNow(backup_config_password)
{
if (backup_config_password != '') {
var http_params = "method=BackupConfig"+"&options="+encodeURIComponent(backup_config_password);
var full_url = url_page +'?'+http_params;
window.open(full_url,'_blank');
document.getElementById('backup_config_password').value = '';
}
}
function IsLoggedIn()
{
var logged_in = ('true' == eval(RemoteCall('UserLoggedIn')));
return logged_in;
}
function Login()
{
var random_salt = eval(RemoteCall('GetRandomSalt'));
var user = document.getElementById('user').value;
var password = document.getElementById('password').value;
document.getElementById('password').value = '';
var hash_password = md5(random_salt+md5(hash_salt+password+hash_salt)+random_salt);
RemoteCall('Login', user+"\t"+hash_password);
if (UpdatePage())
{
Toggle('add_user', 'block');
document.getElementById('newuser').focus();
}
}
function Logout()
{
RemoteCall("Login", "");
Toggle('add_user', 'block');
UpdatePage();
}
function PrintQrCode(one_user)
{
if ('' != one_user)
{
var http_params = "method=PrintQrCode"+"&options="+encodeURIComponent(one_user);
var full_url = url_page +'?'+http_params;
window.open(full_url,'_blank');
}
}
function PrintScratchlist(one_user)
{
if ('' != one_user)
{
var http_params = "method=PrintScratchlist"+"&options="+encodeURIComponent(one_user);
var full_url = url_page +'?'+http_params;
window.open(full_url,'_blank');
}
}
function ResyncUser(one_user)
{
document.getElementById('resync_user').value = one_user;
Toggle('resync', 'block');
document.getElementById('resync_otp1').focus();
}
function RebootDevice()
{
var result = GetHttp('RebootDevice','');
}
function RemoteCall(my_method, my_options, my_id, async, form_method)
/******************************************************************************************
* RemoteCall is a sample function that make an (a)synchronous GET or POST request to launch
* a remote command and return the result as an HTML content in the defined id if defined.
*
* @param string my_method remote method to call
* @param string my_options options (separated by \t) for the called method
* @param string my_id id of the div/span to update asynchronously with the result
* @param boolean async define the asynchronous mode
* @param string form_method method used to send the request (GET or POST)
* @return none
******************************************************************************************/
{
my_method = typeof my_method !== 'undefined' ? my_method : '';
my_options = typeof my_options !== 'undefined' ? my_options : '';
my_id = typeof my_id !== 'undefined' ? my_id : '';
async = typeof async !== 'undefined' ? async : false;
form_method = typeof form_method !== 'undefined' ? form_method : 'GET';
async = false;
var result = '';
if ('POST' != form_method)
{
form_method = 'GET';
}
var xmlhttp;
if (window.XMLHttpRequest)
{ // code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{ // code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
if (true == async)
{
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
result = xmlhttp.responseText;
if ('' != my_id)
{
document.getElementById(my_id).innerHTML=eval(result);
}
}
}
}
var http_params = "method="+my_method+"&options="+encodeURIComponent(my_options);
var full_url = url_page;
var post_params = null;
if ('GET' == form_method)
{
full_url = url_page +'?'+http_params;
}
else
{
post_params = http_params;
}
xmlhttp.open(form_method,full_url,false);
if ('POST' == form_method)
{
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlhttp.setRequestHeader("Content-length", post_params.length);
xmlhttp.setRequestHeader("Connection", "close");
}
xmlhttp.send(post_params);
if (false == async)
{
if (xmlhttp.status === 200)
{
result = xmlhttp.responseText;
if ('' != my_id)
{
document.getElementById(my_id).innerHTML=eval(result);
}
}
return (result);
}
}
function Toggle(my_section, set_value)
{
var all_sections = ['add_user', 'change_password', 'import_tokens', 'resync', 'check_user', 'backup_config', 'restore_config', 'list_tokens'];
// Flush the check section
document.getElementById('check_user_user').value = '';
document.getElementById('check_user_otp').value = '';
document.getElementById('check_user_result').innerHTML = '';
set_value = typeof set_value !== 'undefined' ? set_value : '';
if ('all' == set_value)
{
all_sections.forEach(function(one_section)
{
document.getElementById(one_section+'_section').style.display = 'block';
document.getElementById(one_section+'_title').style.backgroundColor = selected_background_color;
document.getElementById(one_section+'_text').style.color=selected_color;
section_title = document.getElementById(one_section+'_toggle').innerHTML;
if ('[+]' == section_title)
{
document.getElementById(one_section+'_toggle').innerHTML = '[-]';
}
});
}
else if ((('none' == document.getElementById(my_section+'_section').style.display) || ('block' == set_value)) && ('none' != set_value))
{
all_sections.forEach(function(one_section)
{
if (one_section != my_section)
{
document.getElementById(one_section+'_section').style.display = 'none';
document.getElementById(one_section+'_title').style.backgroundColor = unselected_background_color;
document.getElementById(one_section+'_text').style.color=unselected_color;
section_title = document.getElementById(one_section+'_toggle').innerHTML;
if ('[-]' == section_title)
{
document.getElementById(one_section+'_toggle').innerHTML = '[+]';
}
}
});
document.getElementById(my_section+'_section').style.display = 'block';
document.getElementById(my_section+'_title').style.backgroundColor = selected_background_color;
document.getElementById(my_section+'_text').style.color=selected_color;
section_title = document.getElementById(my_section+'_toggle').innerHTML;
if ('[+]' == section_title)
{
document.getElementById(my_section+'_toggle').innerHTML = '[-]';
}
if ('add_user' == my_section)
{
document.getElementById('newuser').focus();
}
else if ('change_password' == my_section)
{
document.getElementById('newpassword').focus();
}
else if ('import_tokens' == my_section)
{
document.getElementById('token_file').value = '';
var ifrm = document.getElementById('hidden_frame');
ifrm = (ifrm.contentWindow) ? ifrm.contentWindow : (ifrm.contentDocument.document) ? ifrm.contentDocument.document : ifrm.contentDocument;
ifrm.document.open();
ifrm.document.write('Waiting...');
ifrm.document.close();
}
else if ('resync' == my_section) {
document.getElementById('resync_user').select();
document.getElementById('resync_user').focus();
document.getElementById('resync_otp1').value = '';
document.getElementById('resync_otp2').value = '';
}
else if ('check_user' == my_section)
{
document.getElementById('check_user_user').select();
document.getElementById('check_user_user').focus();
}
}
else
{
document.getElementById(my_section+'_section').style.display = 'none';
document.getElementById(my_section+'_title').style.backgroundColor = unselected_background_color;
document.getElementById(my_section+'_text').style.color=unselected_color;
section_title = document.getElementById(my_section+'_toggle').innerHTML;
if ('[-]' == section_title)
{
document.getElementById(my_section+'_toggle').innerHTML = '[+]';
}
}
}
function UnlockUser(one_user)
{
if ('' != one_user)
{
RemoteCall('UnlockUser', one_user);
UpdatePage();
}
}
function UpdatePage()
{
var logged_in = IsLoggedIn();
document.getElementById('logged').innerHTML = (logged_in?'User authenticated':'User NOT authenticated');
document.getElementById('logout_section').style.display=(logged_in?'block':'none');
document.getElementById('login_section').style.display=(logged_in?'none':'block');
document.getElementById('authenticated_section').style.display=(logged_in?'block':'none');
if (!logged_in)
{
document.getElementById('login_title').style.backgroundColor = selected_background_color;
document.getElementById('login_text').style.color=selected_color;
}
document.getElementById('token_type').style.display = 'table-row';
document.getElementById('pin').value = '';
UpdateTokensList();
UpdateUsersList();
return logged_in;
}
function UpdateTokensList()
{
// Tokens
var tokens_counter = 0;
var remotecall = eval(RemoteCall('GetTokensList'));
var tokenslist = typeof remotecall !== 'undefined' ? remotecall.trim() : '';
/*
var remotecall = eval(RemoteCall('GetLockedTokensList'));
var lockedlist = typeof remotecall !== 'undefined' ? remotecall.trim() : '';
*/
var lockedlist = '';