/
cp_security.cgi
executable file
·1603 lines (1460 loc) · 58.5 KB
/
cp_security.cgi
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
#!/bin/tclsh
source once.tcl
sourceOnce common.tcl
sourceOnce session.tcl
sourceOnce file_io.tcl
sourceOnce backup.tcl
load tclrpc.so
load tclrega.so
set PFMD_URL "bin://127.0.0.1:2002"
set portnumber 2001
catch { source "/etc/eq3services.ports.tcl" }
if { [info exists EQ3_SERVICE_RFD_PORT] } {
set portnumber $EQ3_SERVICE_RFD_PORT
}
set RFD_URL "bin://127.0.0.1:$portnumber"
proc array_getValue { pArray name } {
upvar $pArray arr
set value {}
catch { set value $arr($name) }
return $value
}
proc get_current_key_index {} {
set KEY_FILE "/etc/config/keys"
set CURRENT_INDEX "Current user key"
set PREVIOUS_INDEX "Previous user key"
# Schl�ssel-Index ermitteln
set fd [open "|crypttool -g" r]
set content [read $fd]
close $fd
array set keys {}
foreach line [split $content "\n"] {
if { [regexp {([^=]*)=(.*)} $line dummy key value] } then {
set key [string trim $key]
set value [string trim $value]
set keys($key) $value
}
}
set currentIndex 0
if { [info exists keys($CURRENT_INDEX)] } then {
set currentIndex $keys($CURRENT_INDEX)
}
return $currentIndex
}
proc set_key { key } {
global RFD_URL
xmlrpc $RFD_URL changeKey $key
# set always new key with crypttool
set index [get_current_key_index]
incr index 1
set fd [open "|crypttool -S -k $key -i $index" r]
close $fd
}
proc getSGTIN_CCU {} {
set fp [open "/var/hmip_board_sgtin" r]
set file_data [read $fp]
close $fp
set sgtinCCU [lindex [split $file_data "\n"] 0]
return $sgtinCCU
}
proc getSGTIN_Backup {migrationMode} {
switch $migrationMode {
"CCU2_CCU2" {set path_crRFD "/tmp/backup/usr/local/etc/config/crRFD/data"}
"CCU2_CCU3" {set path_crRFD "/tmp/backup/usr/local/etc/config/crRFD/data"}
"CCU3_CCU3" {set path_crRFD "/usr/local/eQ-3-Backup/restore/etc/config/crRFD/data"}
}
cd $path_crRFD
set sgtinBackup [lindex [split [glob *.apkx] "."] 0]
return "$sgtinBackup"
}
proc getBackupErrorMessage {errorCode migration_mode} {
set errorCode [expr $errorCode * 1]
# ERROR CODES:
# 9 = Check the script /bin/checkUsrBackup.sh - the java call is wrong
# 10 = OK
# 11 = Backup fehlerhaft / unvollst�ndig (z.B. *.apkx Datei fehlt)
# 12 = Internet fehlt / KeyServer Timeout
# 13 = KeyServer NAK (eine oder beide sind nicht im KeyServer)
# 14 = Fehler bei Ger�tepersistenz (einlesen fehlgeschlagen oder Versionen / Typen nicht kompatibel)
# 15 = Migration Fehlgeschlagen (nicht f�r die Backup Validierungs Main)
# 16 = Adapter (Coprozessor) nicht verf�gbar (basierend auf den Konfigurationen aus dem Backup + Default aus /etc)
# 17 = Adapter konnte nicht initialisiert werden (besch�digte Application / Fehlerr�ckmeldungen)
# 18 = Adapter Version nicht unterst�tzt
# 99 = Unknown error
if {$errorCode == 13} {
# TODO This is currently deactivated because we cannot determine for sure if a SGTIN belongs to a CCU or to a DRAP (see TWIST-1928)
# set sgtinCCU [getSGTIN_CCU]
# set sgtinBackup [getSGTIN_Backup $migration_mode]
}
set code(9) "<br/><b>\$\{backupWrongJavaCall\}</b>"
set code(10) "<br/><b>\$\{backupOK\}</b>"
set code(11) "<br/><b>\$\{backupBackupImperfectMissingFile\}</b>"
set code(12) "<br/><b>\$\{backupNoInternet_KeyserverTimeout\}</b>"
# TODO Activate the next line and delete the line after that when we can extract the SGTIN (see TWIST-1928)
# set code(13) "<br/><b>\$\{backupKeyServer_NAK\}</b><br/><br/>SGTIN CCU: $sgtinCCU<br/>SGTIN Backup: $sgtinBackup<br/> "
set code(13) "<br/><b>\$\{backupKeyServer_NAK\}</b>"
set code(14) "<br/><b>\$\{backupErrorDevicePersistence_TypesNotCompatibel\}</b>"
set code(15) "<br/><b>\$\{backupMigrationFailed\}</b>"
set code(16) "<br/><b>\$\{backupCoProcessor_not_availabel\}</b>"
set code(17) "<br/><b>\$\{backupCoProcessor_NotInitialized\}</b>"
set code(18) "<br/><b>\$\{backupCoProcessor_VersionNotSupported\}</b>"
set code(99) "<br/><b>\$\{backupUnknownError\}</b>"
return $code($errorCode)
}
proc readBackupStatus {} {
set fp [open "/tmp/backupStatus.log" r]
set data [read $fp]
close $fp
return $data
}
proc checkUserBackupValidility {migrationMode} {
switch $migrationMode {
"CCU2_CCU2" {set pathBackup "/tmp/backup/usr/local/"}
"CCU2_CCU3" {set pathBackup "/tmp/backup/usr/local/"}
"CCU3_CCU3" {set pathBackup "/usr/local/eQ-3-Backup/restore/"}
}
catch {exec killall java}
set tmp [catch {exec checkUsrBackup.sh $pathBackup}]
return [readBackupStatus]
}
proc action_change_key {} {
global env RFD_URL
http_head
import key1
import key2
if { "$key1" != "$key2" } {
#put_message "\${dialogSettingsSecurityMessageErrorSecKeyTitle}" "Die beiden eingegebenen Schlüssel stimmen nicht überein." {\${dialogBack} "showSecurityCP();"}
put_message "\${dialogSettingsSecurityMessageErrorSecKeyTitle}" "\${dialogSettingsSecurityMessageErrorSecKeyContentKeysNotIdentical}" {\${dialogBack} "showSecurityCP();"}
return
}
if { [string length "$key1"] < 5 } {
#put_message "Sicherheitsschlüssel setzen - Fehler" "Der eingegebene Schlüssel ist zu kurz. Geben Sie einen Schlüssel ein, der mindestens 5 Zeichen lang ist." {"Zurück" "showSecurityCP();"}
put_message "\${dialogSettingsSecurityMessageErrorSecKeyTitle}" \${dialogSettingsSecurityMessageErrorSecKeyContentKeyShort} {\${dialogBack} "showSecurityCP();"}
return
}
if { 0 == [regexp {^[0-9a-zA-Z_]+$} $key1 dummy] } {
#put_message "Sicherheitsschlüssel setzen - Fehler" "Der eingegebene Schlüssel darf keine Sonderzeichen enthalten. Erlaubt sind lediglich die Buchstaben A bis Z, die Ziffern 0 bis 9 sowie der Unterstrich." {"Zurück" "showSecurityCP();"}
put_message "\${dialogSettingsSecurityMessageErrorSecKeyTitle}" \${dialogSettingsSecurityMessageErrorSecKeyContentIllegalChar} {\${dialogBack} "showSecurityCP();"}
return
}
# check the entered key against our current system key
if { ![catch {exec crypttool -v -t 3 -k "$key1"}]} {
# "Der eingegebene Schl�ssel entspricht dem aktuellen Schl�ssel der Zentrale. "
# "Der Schl�ssel wird nicht ge�ndert."
put_message "\${dialogSettingsSecurityMessageHintSecKeyTitle}" \${dialogSettingsSecurityMessageErrorSecKeyContentKeysIsIdentical} {\${dialogBack} "showSecurityCP();"}
return
}
if { [catch {set_key $key1}] } {
# "Der Schl�ssel konnte nicht gesetzt werden. Das liegt vermutlich daran, da� "
# "der aktuelle Schl�;ssel noch nicht an alle Komponenten �bertragen wurde. "
# "Hinweise darauf finden Sie in den Servicemeldungen."
put_message "\${dialogSettingsSecurityMessageErrorSecKeyTitle}" \${dialogSettingsSecurityMessageErrorSecKeyContentKeyNotAllDevices} {\${dialogBack} "showSecurityCP();"}
return
}
put_message "\${dialogSettingsSecurityMessageOKSecKeyTitle}" \${dialogSettingsSecurityMessageErrorSecKeyContentSetKeySucceed} {\${dialogBack} "showSecurityCP();"}
}
proc action_factory_reset_check {} {
global env
http_head
division {class="popupTitle"} {
puts "\${dialogSettingsSecurityMessagePerformSystemResetTitle}"
}
division {class="CLASS20800"} {
table {class="popupTable"} {border="1"} {
table_row {
table_data {
table {class="CLASS20810"} {width="100%"} {
set system_has_user_key [catch {exec crypttool -v -t 0}]
if { $system_has_user_key } {
table_row {
table_data {colspan="3"} {align="left"} {
puts "\${dialogSetSecKeyRebootHead}"
}
}
table_row {
td {width="20"} {}
table_data {align="left"} {
puts "\${dialogSetSecKeyRebootLbl}"
}
table_data {align="right"} {
cgi_text key= {size="16"} {id="text_key"} {type="password"}
}
}
} else {
table_row {
table_data {colspan="3"} {
puts "\${dialogSettingsSecurityMessagePerformSystemResetContent}"
cgi_put "<input type=hidden name=\"key\" value=dummy id=\"text_key\"/>"
}
}
}
table_row {
table_data {align="right"} {class="CLASS20812"} {colspan="3"} {
division {class="popupControls CLASS20811"} {
division {class="CLASS20813"} {onClick="OnNextStep()"} {
puts "\${dialogSettingsSecurityMessagePerformBtnSystemReset}"
}
}
}
}
}
}
}
}
}
division {class="popupControls"} {
table {
table_row {
table_data {class="CLASS20803"} {
division {class="CLASS20804"} {onClick="showSecurityCP();"} {
puts "\${btnCancel}"
}
}
}
}
}
puts ""
cgi_javascript {
puts "var url = \"$env(SCRIPT_NAME)?sid=\" + SessionId;"
puts {
OnNextStep = function() {
dlgPopup.hide();
dlgPopup.setWidth(400);
dlgPopup.LoadFromFile(url, "action=factory_reset_go&key="+document.getElementById("text_key").value);
}
}
puts "translatePage('#messagebox');"
}
}
proc action_factory_reset_go {} {
global env
http_head
set system_has_user_key [catch {exec crypttool -v -t 0}]
if { $system_has_user_key } {
import key
# check the entered key against our current system key
if { [catch {exec crypttool -v -t 3 -k "$key"}]} {
put_message "\${dialogSetSecKeyRebootFalseTitle}" {
${dialogSetSecKeyRebootFalseContent}
} {"\${dialogBack}" "showSecurityCP();"}
return
}
}
catch {
exec run-parts -a stop /etc/config/rc.d
}
if { [catch {
exec crypttool -r
# exec umount /usr/local
# exec /usr/sbin/ubidetach -p /dev/mtd6
# exec /usr/sbin/ubiformat /dev/mtd6 -y
# exec /usr/sbin/ubiattach -p /dev/mtd6
# exec /usr/sbin/ubimkvol /dev/ubi1 -N user -m
# exec mount /usr/local
if {[getProduct] < 3 } {
# CCU2
exec touch /var/doFactoryReset
} else {
exec touch /usr/local/.doFactoryReset
}
exec kill -SIGQUIT 1
}]} {
# TWIST-22
set comment {
division {class="popupTitle"} {
puts "Systemreset: Fehler"
}
division {class="CLASS20800"} {
table {class="popupTable CLASS20801"} {border="1"} {
table_row {class="CLASS20802"} {
table_data {
puts {
Das System konnte nicht auf Werkseinstellungen zurückgesetzt werden. Die Zentrale wird jetzt neu gestartet.
Versuchen Sie es danach bitte erneut.<br>
Falls diese Meldung danach wieder erscheint, deinstallieren Sie bitte jegliche Zusatzsoftware, starten die Zentrale neu und versuchen es nocheinmal.
}
}
}
}
}
}
}
put_message "\${dialogPerformRebootTitle}" {
${dialogPerformRebootContent}
} {"\${btnNewLogin}" "window.location.href='/';"}
# Nicht mehr n�tig, siehe TWIST-22
set comment {
else {
division {class="popupTitle"} {
puts "Systemreset: Neustart des Systems"
}
division {class="CLASS20800"} {
table {class="popupTable CLASS20801"} {border="1"} {
table_row {class="CLASS20802"} {
table_data {
puts {
Das System wurde auf Werkseinstellungen zurückgesetzt. Die Zentrale wird jetzt neu gestartet.
Bitte melden Sie sich nach dem Starten der Zentrale neu an.
}
}
}
}
}
}
division {class="popupControls"} {
table {
table_row {
table_data {class="CLASS20803" align="center"} {
division {class="CLASS20804"} {onClick="window.location.href='/';"} {
puts "Neu anmelden"
}
}
}
}
}
}
puts ""
cgi_javascript {
puts "var url = \"$env(SCRIPT_NAME)?sid=\" + SessionId;"
puts {
var pb = "action=reboot";
var opts = {
postBody: pb,
sendXML: false
};
new Ajax.Request(url, opts);
}
}
}
proc action_backup_restore_check {} {
global env
cd /tmp/
http_head
set i 0
if { [catch {
exec tar xf new_config.tar
file delete -force /tmp/new_config.tar
set config_version [read_version "firmware_version"]
set ccu1_backup false
if { [version_compare $config_version 2.0.0] < 0 } {
set ccu1_backup true
}
set system_has_user_key [catch {exec crypttool -v -t 0}]
set stored_signature [exec cat signature]
set calculated_signature [exec crypttool -s -t 0 <usr_local.tar.gz]
if { "false" == $ccu1_backup } {
set config_has_user_key [expr {"$stored_signature" != "$calculated_signature"} ]
} else { #CCU1 used an other default key. So we can�t check with crypttool.
set config_has_user_key [exec cat key_index]
}
} errorMessage] } {
# "Die ausgew�hlte Datei enth�lt kein HomeMatic Systembackup. "
# "Bitte w�hlen Sie eine g�ltige Backup-Datei aus."
put_message "\${dialogSettingsSecurityMessageSysBackupInvalidFileTitle}" \${dialogSettingsSecurityMessageSysBackupInvalidFileContent} {\${dialogBack} "showSecurityCP();"}
return
}
if { [version_compare $config_version 2.0.0] < 0 } {
division {id="ccu1Backup" class="j_translate"} {
put_message "\${dialogVersionControlTitle}" "\${dialogVersionControlContent}" {"\${dialogBack}" "PopupClose();"} {"\${btnOk}" "jQuery('#ccu1Backup').hide(); jQuery('#performUpdateTitle, #performUpdateContent, #performUpdateFooter').show()"}
cgi_javascript {
puts "translatePage('#ccu1Backup');"
}
}
} else {
cgi_javascript {
puts "jQuery('#performUpdateTitle, #performUpdateContent, #performUpdateFooter').show()"
}
}
division {id="performUpdateTitle" style="display:none" class="popupTitle"} {
puts "\${dialogSettingsSecurityMessageSysBackupPerformTitle}"
}
division {id="performUpdateContent" style="display:none" class="CLASS20800"} {
table {class="popupTable"} {border="1"} {
table_row {
table_data {
table {class="CLASS20810"} {width="100%"} {
if { $system_has_user_key || $config_has_user_key } {
table_row {
table_data {colspan="3"} {
puts {
${dialogSetSecKeyLoadBackupHead}
}
number_list {
li {
${dialogSetSecKeyLoadBackuplblA}
}
li {
${dialogSetSecKeyLoadBackuplblB}
}
}
}
}
table_row {
td {width="20"} {}
table_data {align="left"} {
puts "\${dialogSetSecKeyLoadBackupLblC}"
}
table_data {align="right"} {
cgi_text key= {size="16"} {id="text_key"} {type="password"}
}
}
} else {
table_row {
table_data {colspan="3"} {
#puts "Bitte bestätigen Sie hier, um das Systembackup einzuspielen."
puts "\${dialogSettingsSecurityMessageSysBackupPerformContent}"
cgi_put "<input type=hidden name=\"key\" value=dummy id=\"text_key\"/>"
}
}
}
table_row {
table_data {align="right"} {class="CLASS20812"} {colspan="3"} {
division {class="popupControls CLASS20811"} {
division {class="CLASS20813"} {onClick="OnNextStep()"} {
puts "\${dialogSettingsSecurityMessageSysBackupBtnPerformRestore}"
}
}
}
}
table_row {
table_data {class="CLASS20814"} {colspan="3"} {
# Unterbrechen Sie während des Einspielens nicht die Stromversorgung der Zentrale. Dies kann zu Datenverlust
# führen.
puts "\${dialogSettingsSecurityMessageSysBackupPerformWarning}"
}
}
}
}
}
}
}
division {id="performUpdateFooter" style="display:none" class="popupControls"} {
table {
table_row {
table_data {class="CLASS20803"} {
division {class="CLASS20804"} {onClick="PopupClose();"} {
puts "\${btnCancel}"
}
}
}
}
cgi_javascript {
puts "translatePage('#messagebox');"
}
}
puts ""
cgi_javascript {
puts "var url = \"$env(SCRIPT_NAME)?sid=\" + SessionId;"
puts {
OnNextStep = function() {
InterfaceMonitor.stop();
MessageBox.show('${transferUserBackupTitle}','${transferUserBackupContent}'+' <br/><br/><img id="msgBoxBarGraph" src="/ise/img/anim_bargraph.gif"><br/>','','320','60','msgBckID', 'msgBoxBarGraph');
dlgPopup.hide();
dlgPopup.setWidth(400);
dlgPopup.LoadFromFile(url, "action=backup_restore_go&key="+document.getElementById("text_key").value);
}
}
}
}
proc action_backup_restore_go {} {
global env
cd /tmp/
http_head
set system_version [read_version "/boot/VERSION"]
set config_version [read_version "firmware_version"]
set ccu1_backup false
if { [version_compare $config_version 2.0.0] < 0 } {
set ccu1_backup true
set comment {
put_message "Backup: Versionskontrolle" {
ACHTUNG! ES WIRD JETZT VERSUCHT EIN BACKUP VON EINER CCU1 EINZUSPIELEN. HIER MUSS EVTL. NOCH EIN ABBRUCH-BUTTON IMPLEMENTIERT WERDEN.
} {"OK" }
}
}
set system_has_user_key [catch {exec crypttool -v -t 0}]
set stored_signature [exec cat signature]
if { "false" == $ccu1_backup } {
set config_has_user_key [expr {"$stored_signature" != "[exec crypttool -s -t 0 <usr_local.tar.gz]"} ]
} else { #CCU1 used an other default key. So we can�t check with crypttool.
set config_has_user_key [exec cat key_index]
}
catch { import key }
if { $system_has_user_key } {
# check the entered key against our current system key
if { [catch {exec crypttool -v -t 3 -k "$key"}]} {
#Der eingegebene System-Sicherheitsschlüssel entspricht nicht dem aktuellen System-Sicherheitsschlüssel der Zentrale.
cgi_javascript {puts "MessageBox.close();"}
put_message "\${dialogSettingsSecurityMessageSysBackupSecurityErrorTitle}" "\${dialogSettingsSecurityMessageSysBackupSecurityError1Content}"
return
}
}
if { $config_has_user_key } {
if { "$stored_signature" != "[exec crypttool -t 3 -k "$key" -s <usr_local.tar.gz]" } {
# Der eingegebene System-Sicherheitsschlüssel entspricht nicht dem zur Backup-Datei gehörenden System-Sicherheitsschlüssel.
cgi_javascript {puts "MessageBox.close();"}
put_message "\${dialogSettingsSecurityMessageSysBackupSecurityErrorTitle}" "\${dialogSettingsSecurityMessageSysBackupSecurityError2Content}"
return
}
}
if { [version_compare $config_version $system_version] > 0 } {
# set msg "Das Einspielen des Backups ist nicht möglich. Das vorliegende Backup basiert auf der Zentralen-Firmware $config_version.<br>\n"
# append msg "Diese Firmware ist aktueller, als die derzeit auf der Zentrale installierte Version ($system_version).<br>\n"
# append msg "Führen Sie zunächst ein Update der Zentralen-Firmware durch und starten Sie dann das Einspielen des Systembackups erneut."
cgi_javascript {puts "MessageBox.close();"}
put_message "\${dialogSettingsSecurityMessageSysBackupFWUpdateNecessaryTitle}" "\${dialogSettingsSecurityMessageSysBackupFWUpdateNecessaryContentA} $config_version \${dialogSettingsSecurityMessageSysBackupFWUpdateNecessaryContentB} ($system_version) \${dialogSettingsSecurityMessageSysBackupFWUpdateNecessaryContentC}"
return
}
#get key index
set stored_index [exec cat key_index]
if { !$system_has_user_key && $config_has_user_key } {
exec crypttool -S -i $stored_index -k "$key"
}
cd /
catch {
exec killall hss_led
exec killall java
exec run-parts -a stop /etc/config/rc.d
exec killall crond
}
after 5000
# backup for version >= 2/3
if { "false" == $ccu1_backup } {
set migration_mode "invalid"
if { [version_compare $config_version 3.0.0] < 0 } {
# CCU2 Backup
if { [version_compare $system_version 3.0.0] < 0 } {
# CCU2 ==> CCU2
set migration_mode "CCU2_CCU2"
} else {
# CCU2 ==> CCU3
set migration_mode "CCU2_CCU3"
}
} else {
# CCU3 Backup
set migration_mode "CCU3_CCU3"
}
if { "CCU2_CCU2" == $migration_mode } {
# CCU2 ==> CCU2
set backuperror false
set source_version [read_version "/tmp/firmware_version"]
set source_version [split $source_version .]
set source_major [lindex $source_version 0]
set source_minor [lindex $source_version 1]
set source_patch [lindex $source_version 2]
if { (($source_major == 2) && ($source_minor > 17)) || (($source_major == 2) && ($source_minor == 17) && ($source_patch >= 14))} {
# extract backup to /tmp to enable checkUsrBackup.sh to validate backup
file delete -force /tmp/backup
file mkdir /tmp/backup
cd /tmp/backup
if { [catch {exec tar xzf /tmp/usr_local.tar.gz} errorMessage] } {
cgi_javascript {puts "MessageBox.close();"}
put_message "\${dialogSettingsSecurityMessageSysBackupErrorTitle}" "\${dialogSettingsSecurityMessageSysBackupErrorContent} $errorMessage"
file delete -force /tmp/firmware_version /tmp/signature /tmp/usr_local.tar.gz /tmp/backup
return
#set backuperror true
} else {
set backuperror false
# Check if a backup with HmIP support can be used without problems
set checkBackupState [checkUserBackupValidility $migration_mode]
if {$checkBackupState != 10} {
# It's not possible to use the backup
set backuperror true
# Start /etc/init.d/S62HMServer start
cgi_javascript {puts "MessageBox.close();"}
put_message "\${dialogSettingsSecurityMessageSysBackupErrorTitle}" "\${dialogSettingsSecurityMessageSysBackupErrorContent} [getBackupErrorMessage $checkBackupState $migration_mode]"
file delete -force /tmp/firmware_version /tmp/signature /tmp/usr_local.tar.gz /tmp/backup
cgi_javascript {puts "homematic('User.restartHmIPServer');"}
return
}
}
}
if { "false" == $backuperror } {
#if { [version_compare $system_version 3.0.0] < 0 } {
# Erase user file system
exec umount /usr/local
exec /usr/sbin/ubidetach -p /dev/mtd6
exec /usr/sbin/ubiformat /dev/mtd6 -y
exec /usr/sbin/ubiattach -p /dev/mtd6
exec /usr/sbin/ubimkvol /dev/ubi1 -N user -m
exec mount /usr/local
#}
#Apply backup
cd /
if { [catch {exec tar xzf /tmp/usr_local.tar.gz} errorMessage] } {
# set msg "Beim Einspielen des Systembackups ist ein Fehler aufgetreten. Bitte versuchen Sie es erneut. "
# append msg "Falls dieser Fehler wiederholt Auftritt, wenden Sie sich bitte mit der folgenden Fehlermeldung an den Kundenservice:\n<br>"
# append msg $errorMessage
cgi_javascript {puts "MessageBox.close();"}
put_message "\${dialogSettingsSecurityMessageSysBackupErrorTitle}" "\${dialogSettingsSecurityMessageSysBackupErrorContent} $errorMessage"
file delete -force /tmp/firmware_version /tmp/signature /tmp/usr_local.tar.gz /tmp/backup
return
} else {
set backuperror false
}
}
} elseif { "CCU3_CCU3" == $migration_mode } {
# CCU3 ==> CCU3
file delete -force /usr/local/eQ-3-Backup/restore
file mkdir /usr/local/eQ-3-Backup/restore
cd /usr/local/eQ-3-Backup/restore
if { [catch {exec tar xzf /tmp/usr_local.tar.gz --strip 2} errorMessage] } {
# show message "Beim Einspielen des Systembackups ist ein Fehler aufgetreten. Bitte versuchen Sie es erneut. "
cgi_javascript {puts "MessageBox.close();"}
put_message "\${dialogSettingsSecurityMessageSysBackupErrorTitle}" "\${dialogSettingsSecurityMessageSysBackupErrorContent} $errorMessage"
set backuperror true
} else {
set backuperror false
}
} elseif { "CCU2_CCU3" == $migration_mode } {
# CCU2 ==> CCU3
# be sure /tmp/backup is empty
file delete -force /tmp/backup
# be sure restore directory is empty
file delete -force /usr/local/eQ-3-Backup/restore
file mkdir /tmp/backup
cd /tmp/backup
if { [catch {exec tar xzf /tmp/usr_local.tar.gz} errorMessage] } {
cgi_javascript {puts "MessageBox.close();"}
put_message "\${dialogSettingsSecurityMessageSysBackupErrorTitle}" "\${dialogSettingsSecurityMessageSysBackupErrorContent} $errorMessage"
set backuperror true
} else {
# only do this when the compatibility check says ok:
#copy old files
file mkdir /usr/local/eQ-3-Backup/restore/etc/config
if { [file exists /tmp/backup/usr/local/etc/config] } {
cd /tmp/backup/usr/local/etc/config
}
if { [file exists InterfacesList.xml] } { file copy InterfacesList.xml /usr/local/eQ-3-Backup/restore/etc/config/InterfacesList.xml }
if { [file exists hs485d] } { file copy hs485d /usr/local/eQ-3-Backup/restore/etc/config/hs485d }
if { [file exists hs485d.conf] } { file copy hs485d.conf /usr/local/eQ-3-Backup/restore/etc/config/hs485d.conf }
if { [file exists hs485types] } { file copy hs485types /usr/local/eQ-3-Backup/restore/etc/config/hs485types }
if { [file exists rfd] } { file copy rfd /usr/local/eQ-3-Backup/restore/etc/config/rfd }
if { [file exists rfd.conf] } { file copy rfd.conf /usr/local/eQ-3-Backup/restore/etc/config/rfd.conf }
if { [file exists crRFD] } { file copy crRFD /usr/local/eQ-3-Backup/restore/etc/config/crRFD }
if { [file exists userprofiles] } { file copy userprofiles /usr/local/eQ-3-Backup/restore/etc/config/userprofiles }
if { [file exists measurement] } { file copy measurement /usr/local/eQ-3-Backup/restore/etc/config/measurement }
if { [file exists eshlight] } { file copy eshlight /usr/local/eQ-3-Backup/restore/etc/config/eshlight }
if { [file exists firmware] } { file copy firmware /usr/local/eQ-3-Backup/restore/etc/config/firmware }
if { [file exists homematic.regadom] } { file copy homematic.regadom /usr/local/eQ-3-Backup/restore/etc/config/homematic.regadom }
if { [file exists homematic.regadom.bak] } { file copy homematic.regadom.bak /usr/local/eQ-3-Backup/restore/etc/config/homematic.regadom.bak }
if { [file exists ids] } { file copy ids /usr/local/eQ-3-Backup/restore/etc/config/ids }
if { [file exists ntpclient] } { file copy ntpclient /usr/local/eQ-3-Backup/restore/etc/config/ntpclient }
if { [file exists rega.conf] } { file copy rega.conf /usr/local/eQ-3-Backup/restore/etc/config/rega.conf }
if { [file exists syslog] } { file copy syslog /usr/local/eQ-3-Backup/restore/etc/config/syslog }
if { [file exists groups.gson] } { file copy groups.gson /usr/local/eQ-3-Backup/restore/etc/config/groups.gson }
if { [file exists energyPrice] } { file copy energyPrice /usr/local/eQ-3-Backup/restore/etc/config/energyPrice }
if { [file exists hmip_address.conf] } { file copy hmip_address.conf /usr/local/eQ-3-Backup/restore/etc/config/hmip_address.conf }
if { [file exists crypttool.cfg] } { file copy crypttool.cfg /usr/local/eQ-3-Backup/restore/etc/config/crypttool.cfg }
if { [file exists keys] } { file copy keys /usr/local/eQ-3-Backup/restore/etc/config/keys }
if { [file exists tweaks] } { file copy tweaks /usr/local/eQ-3-Backup/restore/etc/config/tweaks }
if { [file exists time.conf] } { file copy time.conf /usr/local/eQ-3-Backup/restore/etc/config/time.conf }
#patch changed port settings for interfaces processes (rfd/hs485d/...)
catch { exec /bin/migrateSecuritySettings.sh /usr/local/eQ-3-Backup/restore/etc/config}
set backuperror false
cd /
}
}
} else { # backup for version < 2
#delete existing files
file delete -force /tmp/backup
file delete -force /etc/config/hs485d /etc/config/hs485types /etc/config/rfd /etc/config/userprofiles
file delete -force /etc/config/homematic.regadom /etc/config/homematic.regadom.bak
file delete -force /etc/config/ids /etc/config/ntpclient /etc/config/rega.conf /etc/config/syslog
file delete -force /etc/config/tweaks /etc/config/TZ /etc/config/server.pem /etc/config/keys
file delete -force /etc/config/time.conf
file mkdir /tmp/backup
cd /tmp/backup
if { [catch {exec tar xzf /tmp/usr_local.tar.gz} errorMessage] } {
put_message "\${dialogSettingsSecurityMessageSysBackupErrorTitle}" "\${dialogSettingsSecurityMessageSysBackupErrorContent} $errorMessage"
set backuperror true
} else {
#copy old files
if { [file exists /tmp/backup/usr/local/etc/config] } {
cd /tmp/backup/usr/local/etc/config
}
if { [file exists hs485d] } { file copy hs485d /etc/config/hs485d }
if { [file exists hs485types] } { file copy hs485types /etc/config/hs485types }
if { [file exists rfd] } { file copy rfd /etc/config/rfd }
if { [file exists userprofiles] } { file copy userprofiles /etc/config/userprofiles }
if { [file exists homematic.regadom] } { file copy homematic.regadom /etc/config/homematic.regadom }
if { [file exists homematic.regadom.bak] } { file copy homematic.regadom.bak /etc/config/homematic.regadom.bak }
if { [file exists ids] } { file copy ids /etc/config/ids }
if { [file exists ntpclient] } { file copy ntpclient /etc/config/ntpclient }
if { [file exists rega.conf] } { file copy rega.conf /etc/config/rega.conf }
if { [file exists syslog] } { file copy syslog /etc/config/syslog }
if { [file exists tweaks] } { file copy tweaks /etc/config/tweaks }
if { [file exists TZ] } { file copy TZ /etc/config/TZ }
if { [file exists server.pem] } { file copy server.pem /etc/config/server.pem }
if { [file exists time.conf] } { file copy time.conf /etc/config/time.conf }
if { [file exists keys] } then {
file copy keys /etc/config/keys
} else {
if { $config_has_user_key } then {
set fd [open "/etc/config/crypttool.cfg" r]
set content [read $fd]
close $fd
array set keys {}
foreach line [split $content "\n"] {
if { [regexp {([0-9]+) (.*)} $line dummy key value] } then {
set key [string trim $key]
set value [string trim $value]
set keys($key) $value
}
}
if { [info exists keys($stored_index)] } then {
set keyvalue $keys($stored_index)
set fd -1
catch {set fd [open "/etc/config/keys" w]}
if { $fd > 0 } {
puts $fd "Current Index = $stored_index"
puts $fd "Key 0 ="
puts $fd "Key $stored_index = $keyvalue"
puts $fd "Last Index = 0"
close $fd
}
}
}
}
catch {exec eq3configcmd rfd-interface-copy rfd.conf /etc/config/rfd.conf}
set backuperror false
}
cd /
}
set source_version [read_version "/tmp/firmware_version"]
set source_version [split $source_version .]
set source_major [lindex $source_version 0]
set source_minor [lindex $source_version 1]
set source_patch [lindex $source_version 2]
# Check if a backup with HmIP support can be used without problems - A CCU with a version < 2.17.14 had no HmIP support. Therefore we don't check such backups
# (For CCU2_CCU2 this check has been executed above)
if { "CCU2_CCU2" != $migration_mode } {
if {($source_major >= 3) || (($source_major == 2) && ($source_minor > 17)) || (($source_major == 2) && ($source_minor == 17) && ($source_patch >= 14))} {
set checkBackupState [checkUserBackupValidility $migration_mode]
if {$checkBackupState != 10} {
# It's not possible to use the backup
set backuperror true
# Start /etc/init.d/S62HMServer start
cgi_javascript {puts "homematic('User.restartHmIPServer');"}
put_message "\${dialogSettingsSecurityMessageSysBackupErrorTitle}" "\${dialogSettingsSecurityMessageSysBackupErrorContent} [getBackupErrorMessage $checkBackupState $migration_mode]"
}
}
}
cgi_javascript {puts "MessageBox.close();"}
if { "false" == $backuperror } {
exec mount -o remount,ro /usr/local
exec mount -o remount,rw /usr/local
division {class="popupTitle"} {
puts "\${dialogSettingsSecurityMessageSysBackupRestartSystemTitle}"
}
division {class="CLASS20800"} {
table {class="popupTable CLASS20801"} {border="1"} {
table_row {class="CLASS20802"} {
table_data {
puts "\${dialogSettingsSecurityMessageSysBackupRestartSystemContent}"
}
}
}
}
division {class="popupControls"} {
table {
table_row {
table_data {class="CLASS20803"} {
division {class="CLASS20804"} {onClick="window.location.href='/';"} {
puts "\${dialogSettingsSecurityMessageSysBackupBtnRestartSystem}"
}
}
}
}
}
cgi_javascript {
puts "var url = \"$env(SCRIPT_NAME)?sid=\" + SessionId;"
puts {
var pb = "action=reboot";
var opts = {
postBody: pb,
sendXML: false
};
new Ajax.Request(url, opts);
}
}
}
cgi_javascript {
puts "translatePage('#messagebox');"
}
file delete -force /tmp/new_config.tar /tmp/firmware_version /tmp/signature /tmp/usr_local.tar.gz /tmp/backup
}
proc put_message {title msg args} {
division {class="popupTitle"} {
puts $title
}
division {class="CLASS20800"} {
table {class="popupTable CLASS20801"} {border="1"} {
table_row {class="CLASS20802"} {
table_data {
puts $msg
}
}
}
}
division {class="popupControls"} {
table {
table_row {
if { [llength $args] < 1 } { set args {{\${dialogBack} "PopupClose();"}}}
foreach b $args {
table_data {class="CLASS20803"} {
division {class="CLASS20804"} "onClick=\"[lindex $b 1]\"" {
puts [lindex $b 0]
}
}
}
}
}
}
cgi_javascript {
puts "translatePage('#messagebox');"
}
}
proc action_set_session_timeout {} {
set REGA_CONF_FILE "/etc/config/rega.conf"
http_head
if { [catch {
import timeout
if { $timeout != [expr int($timeout)] || 180 > $timeout || 600 < $timeout } then { error "invalid timeout" }
set rega_conf "# rega.conf\n"
append rega_conf "# This file is generated by cp_security.cgi\n"
append rega_conf "SessionTimeout=$timeout\n"
saveToFile $REGA_CONF_FILE rega_conf
# Die neue Zeit bis zum Ablauf der Sitzung wurde erfolgreich übernommen.
# Die Änderung wird mit dem nächsten Start der HomeMatic Zentrale wirksam.
put_message "\${dialogSettingsSecurityMessageSessionTimeOutSaveTitle}" {
<p>
${dialogSettingsSecurityMessageSessionTimeOutSaveContent}
</p>
}
}]} then {
# Fehler: Session Timeout übernehmen
# Bitte wählen Sie eine Zeit zwischen 180 und 600 Sekunden.
put_message "\${dialogSettingsSecurityMessageSessionTimeOutErrorTitle}" "\${dialogSettingsSecurityMessageSessionTimeOutErrorContent}"
}
}
proc action_put_page {} {
global env sid
cgi_debug -on
http_head
division {class="popupTitle j_translate"} {
puts "\${dialogSettingsSecurityTitle}"
}
division {class="CLASS20815"} {
table {class="popupTable j_translate"} {border="1"} {
table_row {class="CLASS20806"} {
table_data {class="CLASS20807"} {
puts "\${dialogSettingsSecurityTDKey}"
}
table_data {class="CLASS20808"} {
table {class="CLASS20810"} {
table_row {
table_data {colspan="3"} {style="text-align:left"} {
puts "\${dialogSettingsSecurityLblEnterSecKey}"
}
}
table_row {
td {width="20"} {}
table_data {align="left"} {
puts "\${dialogSettingsSecurityLblSecKey}"
}
table_data {align="right"} {
cgi_text key1= {size="16"} {id="text_key1"} {type="password"}
}
}
table_row {
td {width="20"} {}
table_data {align="left"} {
puts "\${dialogSettingsSecurityLblSecKeyRepeat}"
}
table_data {align="right"} {
cgi_text key2= {size="16"} {id="text_key2"} {type="password"}
}
}
table_row {
table_data {align="right"} {class="CLASS20812"} {colspan="3"} {
division {class="popupControls CLASS20811"} {
division {class="CLASS20813"} {onClick="OnChangeKey()"} {
puts "\${dialogSettingsSecurityBtnSaveKey}"
}
}
}
}
}
}
table_data {align="left"} {class="CLASS20816"} {
puts "\${dialogSettingsSecurityHintSecKey1}"
number_list {
li {
${dialogSettingsSecurityHintSecKey2}
}
li {
${dialogSettingsSecurityHintSecKey3}
}
li {
${dialogSettingsSecurityHintSecKey4}
}
}
}
}
table_row {class="CLASS20806"} {
table_data {class="CLASS20807"} {
puts "\${dialogSettingsSecurityTDBackup}"
}
table_data {class="CLASS20808"} {