-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathEnDeGUIx.js
1431 lines (1374 loc) · 54 KB
/
EnDeGUIx.js
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
/* ========================================================================= //
# vi: ts=4:
# vim: ts=4:
#?
#? NAME
#? EnDeGUIx.js
#?
#? SYNOPSIS
#? <SCRIPT language="JavaScript1.3" type="text/javascript" src="EnDeFile.js"></SCRIPT>
#? <SCRIPT language="JavaScript1.3" type="text/javascript" src="EnDeText.js"></SCRIPT>
#? <SCRIPT language="JavaScript1.5" type="text/javascript" src="EnDeGUI.js"></SCRIPT>
#? <SCRIPT language="JavaScript1.5" type="text/javascript" src="EnDeGUIx.js"></SCRIPT>
#?
#? DESCRIPTION
#? This file is part of EnDeGUI.js and needs to be included right after
#? EnDeGUI.js 'cause it is part of the EnDeGUI object defined there.
#?
#? This file contains all functions/methods used to read files for menus.
#? Such files can be simple (tab-seperated) text in JSON or XML format.
#? This file also contains all functions/methods to build HTML tags from
#? generated JSON definitions.
#?
#? Extends EnDeGUI class with following objects and functions:
#? .__files{} - hash for files and corresponding objects
#? .__filesSet - set specified values in .__files{}
#? .__filesDefault - set default values in .__files{}
#? .txt - object to read files and build JSON data
#? .txt.read - wrapper for EnDe.File.read(), uses EnDeGUI.usr
#? .txt.menu - build internal data structure for menus from EnDeGUI.txt.content
#? .txt.XMLmenu - convert XML structure to EnDeGUI's internal data structure
#? .Obj - object for building tags in DOM
#? .Obj.create - create a object from specified data
#? .Obj.menu - create (SELECT) menu with label
#? .Obj.addGrp - add SELECT menu or OPTGROUP
#? .Obj.hide - set object's display=none
#? .Obj.unhideall - set all hidden object's display=block
#? .Obj.redo - create button (menu item) with text and action
#?
#? Public input variables:
#? .trace - enable trace output
#? .error - 'exit' or 'continue' after errors
#? .warning - 'none' or 'alert' to show alert for warnings
#? .strip - true: remove comments (#) and empty lines
#? Public output variables:
#? .content - content read by EnDe.File.read()
#? null if failed, otherwise plain text or XML object
#? .errors - store parse errors here
#? .lines - array with line numbers
#?
#? Also adds some global functions for menus:
#? .makemenu - read data from file and create menu
#? .makelist - convert (payload) data from file to plain text
#? .initMenus - initialises all menus defined in files
#?
#? Builds/fills following variables
#? EnDeGUI.Obj.groups[]
#? EnDeGUI.Obj.menus[].use
#?
#? Required objects, variables from EnDeGUI (descriptions see EnDeGUI.js):
#? EnDeGUI.opts[]
#? EnDeGUI.useLabel
#? EnDeGUI.useANCHOR
#? EnDeGUI.dir
#? EnDeGUI.usr
#? EnDeGUI.nousr
#? EnDeGUI.grpID
#?
#? EXAMPLES
#? See EnDeMenu.txt
#?
#? SEE ALSO
#? EnDeMenu.txt
#? EnDeGUI.js
#?
# HACKER's INFO
#
# "internal data structure" for menus
# The internal data structure for all menus is a tab-seperated text where
# each line represents one entry in the menu. This is pretty close to the
# data to be found in the corresponding .txt files, i. e. EnDeMenu.txt.
# All data from external files will be converted to this structure. That
# is why we have special functions for XML and JSON data, i. e. XMLmenu()
# in EnDeGUI.txt.
# Finally this internal data structure is used to build objects in DOM.
#
# obj.selectedIndex:
# A onClick=
# For a detailled description see EnDeGUI.js.
#
# __dbx() vs. _dpr()
# Most objects herein use their own private function -named __dbx()- for
#? trace output. This allows to enable tracing for individual objects.
#?
#? VERSION
#? @(#) EnDeGUIx.js 3.9 18/08/05 12:36:19
#?
#? AUTHOR
#? 10-aug-10 Achim Hoffmann, mailto: EnDe (at) my (dash) stp (dot) net
#?
* ========================================================================= */
// ========================================================================= //
// private variables and functions //
// ========================================================================= //
var EnDeGUIx = new function() {
this.SID = '3.9';
}
EnDeGUI.__files = { // hash to hold data for menu from files
/* source file - file where menu is defined (will be read from)
* target - object where menu should be added
* funtion to be called - function to be called for each menu selection
* text for label - text for menu's label (if any)
* text for menu button - text for menu's title attribute
*/
/* -------------+--------------------+-------------------------------+--------------------------+-------------- */
/* source file : target function to be called text for label text for menu button
/* -------------+--------------------+-------------------------------+--------------------------+-------------- */
'EnDeUser.xml' : ['EnDeDOM.f.FF', 'EnDeGUI.dispatch(this,"FF")', ' User functions: ', 'User defined function call' ]
/* -------------+--------------------+-------------------------------+--------------------------+-------------- */
// above static entries are those for EnDe's menus itself
// more such lines added by this.menu() when reading .xml files
}; // .__files{}
EnDeGUI.__filesSet= function(src, target, func, label, txt) {
//#? add default entry to .__files{}
this.__files[src] = [ target, func, label, txt ];
}; // .__filesSet
EnDeGUI.__filesDefault= function(src) {
//#? add default entry to .__files{}
this.__files[src] = ['EnDeDOM.f.EN', 'EnDeGUI.dispatch(this,"EN")', ' (not configured)', 'user data from file: '+src];
}; // .__filesDefault
// ========================================================================= //
// object to read files and build menu (JSON) data //
// ========================================================================= //
EnDeGUI.txt = new function() {
//#? class for reading text files and converting to internal JSON data
this.ME = 'EnDeGUI.txt';
this.sid = function() { return(EnDeGUI.sid() + '.txt'); };
var __dbx = function(t,n) { if (EnDeGUI.txt.trace===true) { EnDeGUI.dpr(t, n); } };
this.trace = false;
this.warning= 'none'; // or alert to show an alert message for each error detected
this.error = 'exit'; // or continue after errors
this.lines = []; // store line numbers for errors (copies EnDe.File.lines[])
this.errors = ''; // store parse errors here
this.content= null; // store read content here
this.read = function(src) {
//#? wrapper for EnDe.File.read(): read file and store content in EnDeGUI.txt.content
/* if given src is a plain filename the filename is first checked for
* in EnDeGUI.usr directory, if that returns empty content (file not
* found) then the file itself (as specified in src) is read
*/
// ToDo: should return data instead of setting EnDeGUI.txt.content
/* read data and remove comment and empty lines */
if ((EnDeGUI.txt.trace===true) || (EnDe.File.trace===true)) {
_dpr(this.ME + '.read('+src+') {'); /* dummy } */
}
var bbb = false;
while(this.lines.pop()!=null) {}; // clear lines array
EnDe.File.reset();
if (EnDeGUI.nousr===false) {
if (src.match(/\//)===null) { // plain filename given
bbb = EnDe.File.read(EnDeGUI.usr + src);
}
}
if (bbb===false) { // nothing found; try what was given
bbb = EnDe.File.read(src);
}
if (bbb===false) { // last resort: default directory
/* EnDeGUI.dir may be empty, then above already should have matched */
bbb = EnDe.File.read(EnDeGUI.dir + src);
}
if ((EnDe.File.content===null) || (bbb===false)) {
if ((EnDeGUI.txt.trace===true) || (EnDe.File.trace===true)) {
for (bbb=0; bbb<EnDe.File.errors.length; bbb++) { _dpr(this.ME + '.read: ' + EnDe.File.errors[bbb]); }
}
_dpr('**ERROR: ' + src + ' **failed**');
if ((EnDeGUI.txt.trace===true) || (EnDe.File.trace===true)) {
/* dummy { */ _dpr(this.ME + '.read }');
}
//throw (EnDe.File.errors.join()); // we don't use exceptions
return;
}
this.content= EnDe.File.content;
// arrays need to be copied in JavaScript :-(
for (bbb=0; bbb<EnDe.File.lines.length; bbb++) { this.lines.push(EnDe.File.lines[bbb]); }
EnDe.File.reset();
if ((EnDeGUI.txt.trace===true) || (EnDe.File.trace===true)) {
/* dummy { */ _dpr(this.ME + '.read: ' + this.lines.length + ' lines }');
}
}; // .read
this.menu = function() {
//#? build data structure for menus from EnDeGUI.txt.content
/* data assumed to be TAB-seperated */
/* for a description of the syntax and keywords, see EnDeMenu.txt */
var bux = '';
var bbb = '';
var ccc = '';
var opt = '';
var brk = 0;
var i = 0;
var idx = 0;
var dat = '';
var obj = null;
var __obj= function(typ, key, lbl, txt) { // need a clousure here!
this.tag = '';
this.typ = typ; // menu or group
this.key = key; // index in menus[] or groups[]
this.label = lbl;
this.title = txt;
this.inside = '';
this.realCHR= false;
this.realUCS= false;
this.showHEX= false;
this.id = '';
this.clss = '';
this.style = '';
this.size = '';
this.disable= 0;
this.onClick= '';
this.onMover= '';
this.onMout = '';
this.items = [];
this.input = [];
this.use = [];
};
var genid = 0; // id of generated object (OPTION, A)
/* 0: use first column from item3, item4, hide3, file
* 1: increment genid and generate id
* n: ...
*/
var _gen= function(txt) {
if (genid===0) { return txt; }
genid++;
return (txt + genid.toString());
};
//dbx# __dbx('{#MENU: ' + EnDeGUI.txt.content + 'MENU#}');
var kkk = EnDeGUI.txt.content.split('\n');
while ((bbb = kkk.shift())!==undefined) { // store data in anonymous objects
idx++; if (idx==9999) break; // avoid loops
// next 2 just in case of missing before ...
if (bbb.match(/^\s*#/)!==null) { continue; } // skip comments
if (bbb.match(/^\s*$/)!==null) { continue; } // skip empty lines
if (bbb.match(/^options\t/)!==null) { // these are special ..
// for options lines tabs must not be squeezed
ccc = bbb.split(/\t/, 11);
if (ccc[10]===undefined) { EnDeGUI.alert('ERROR: misformated options line', '"' + bbb + '"'+ccc.length); }
// no ToDo: above check matches in IE8 'cause tabs are squeezed there
obj.items.push([ccc[0], _gen(ccc[1]), ccc[1], ccc[9], ccc[10]]);
EnDeGUI.opts[ccc[1]] = new Array();
for (i=2;i<9;i++) { // ToDo: ugly hack for option values
// anything we get is a string, check for some special keywords
switch (ccc[i]) {
case 'null': opt = null; break;
case 'true': opt = true; break;
case 'false': opt = false; break;
default: opt = ccc[i]; break;
}
EnDeGUI.opts[ccc[1]].push(opt);
}
continue;
}
if (dat!=='') {
// we're inside a <![CDATA 'til we find ]]> followed by a tab
if (bbb.match(/]]>\t/)!==null) {
dat += bbb.replace(/]]>.*/, '');
ccc = bbb.replace(/^.*?]]>\t/, '').split(/\t/);
obj.items.push(['item3', _gen(ccc[0]), '/* ' + ccc[1] + ' */\n' + dat.replace(/^\[/, ''), ccc[0], ccc[1]]);
// NOTE need to remove initial [ (see CDATA below)
//#dbx __dbx('## '+genid+':'+ccc[1]+'\n#'+ccc[0]);
dat = '';
} else {
dat += bbb;
}
continue;
}
bbb = bbb.replace(/\t{2,}/g, '\t'); // squeeze multiple TABs
ccc = bbb.split(/\t/);
switch (ccc[0]) { // handle all keywords (left most word in each line)
case 'options': /* ignored */ break; // see above
case '__DATA' : /* ignored */ break;
case '__END' : brk = 1; break;
case 'warn' : this.warning= ccc[1]; break; // no checks here, done when used
case 'error' : this.error = ccc[1]; break; // no checks here, done when used
case 'head' : /* ignored */ break;
case 'menu' :
//#dbx __dbx(' .txt.menu: '+bbb, '\n');
if (ccc[3]===undefined) { EnDeGUI.alert('ERROR: misformated menu line', '"' + bbb + '"'); }
if (obj!==null) {
EnDeGUI.Obj.addGrp(obj);
delete this.obj;
obj = null;
}
obj = new __obj(ccc[0], ccc[1], ccc[2], ccc[3]);
//#dbx EnDeGUI.dprint(' __obj: ', obj);
break;
case 'group' :
//#dbx __dbx('*** .txt.menu: group='+bbb, '\n');
if (ccc[3]===undefined) { EnDeGUI.alert('ERROR: misformated group line', '"' + bbb + '"'); }
if (obj!==null) {
EnDeGUI.Obj.addGrp(obj);
delete this.obj;
obj = null;
}
obj = new __obj(ccc[0], ccc[1], ccc[2], ccc[3]);
break;
case 'file' : // is a variant of item3
if (ccc[6]===undefined) { EnDeGUI.alert('ERROR: misformated file line', '"' + bbb + '"'); }
EnDeGUI.__filesSet(ccc[1], ccc[4], ccc[5], ccc[6], ccc[2]);
// no break;
case 'hide3' :
case 'item3' :
dat = '';
if (ccc[1].match(/<!.CDATA/)!==null) { //first column allows <![CDATA values
dat = ccc[1].replace(/<!.CDATA/, '');
// NOTE that we keep the initial [
} else {
if (ccc[3]===undefined) { EnDeGUI.alert('ERROR: misformated item3 line', '"' + bbb + '"'); }
if (obj.showHEX===true) {
if (obj.realUCS===true) {
ccc[3] = '0x' + ccc[1].replace(/ /g, '') + ': ' + ccc[3];
} else {
ccc[3] = '0x' + EnDe.i2h('hex0', ccc[1]) + ': ' + ccc[3];
}
}
obj.items.push([ccc[0], _gen(ccc[1]), ccc[1], ccc[2], ccc[3]]);
}
break;
case 'item4' : // is a variant of item3
if (ccc[4]===undefined) { EnDeGUI.alert('ERROR: misformated item4 line', '"' + bbb + '"'); }
obj.input.push([ccc[0], _gen(ccc[1]), ccc[1], ccc[2], ccc[3], ccc[4]]);
break;
case 'makeID' : genid = 1; break;
case 'key' : obj.key = ccc[1]; break; // overwrites setting from __obj() call in 'menu' above
case 'tag' :
case 'html' : obj.tag = ccc[1].toUpperCase(); break;
case 'realCHR': obj.realCHR = true; break;
case 'realUCS': obj.realUCS = true; break;
case 'showHEX': obj.showHEX = true; break;
case 'inside' :
case 'orientation':
case 'id' :
case 'name' :
case 'size' :
case 'style' : obj[ ccc[0] ] = ccc[1]; break;
case 'css' : obj.style = ccc[1]; break;
case 'class' : obj.clss = ccc[1]; break;
case 'onclick':
case 'onClick': obj.onClick = ccc[1]; break;
case 'disable': obj.disable = 1; break;
case 'onMouseover':obj.onMover= ccc[1]; break;
case 'onMouseout' :obj.onMout = ccc[1]; break;
case 'intern' : /* ignored for now */ break;
case 'use' : obj.use.push(ccc[1]); break; // add OPTGROUP to SELECT
default :
this.errors += EnDeGUI.txt.lines[idx] + ': unknown "' + ccc[0] + '"\t# ' + bbb + '\n';
if (this.warning!=='none') { // very lazy check
EnDeGUI.alert('ERROR: unknown', '"'+ccc[0]+'"');
}
if (this.error==='exit') { // very lazy check
brk = 1;
}
break;
} // ccc[0]
if (brk == 1) { break; }// exit while loop
} // while
EnDeGUI.Obj.addGrp(obj); // handle last processed object
delete this.obj;
if (this.errors != '') {
bbb = this.ME + '.menu: **ERRORs found in file:\n' + this.errors;
_dpr( bbb );
EnDeGUI.alert('ERROR '+this.ME+'.menu: errors found in file', this.errors);
this.errors = '';
}
// #dbx print groups# var t=''; for (var idx in EnDeGUI.Obj.groups) { t+=idx+'\n';} alert(t);
}; // .menu
this.XMLmenu = function(fil, src) {
//#? convert XML structure to EnDeGUI's internal tab-based tabular data
/* NOTE that all data will be copied here, but this avoids rewriting the
* functionalty of EnDeGUI.txt.menu() and EnDeGUI.Obj.create() here.
*/
/* **** general XML data looks like:
<xss><attack>
<name /><code /><label /><desc /><browser />
<target /><func /><prefix /><opts />
</attack></xss>
*/
/* **** Core-Rule-Set
* The core-rules*.xml generated by CoreRule2HTML.jar has its own tags
* which are not comparable to those used in other files.
* It also has scopes with missing data which needs to be completed.
* And finally it is not sorted, so that rules with the same <selector>
* value may appear anywhere in the file, not following each other.
* NOTE that this parser works for core-rule*.xml as all used keywords
* there are totally different to all others files processed here.
*
<core-rules>
<rule>
<operator /> // used for: code
<comment /> // used for: desc
<selector /> // used for: label
<action> <msg /><tag /></action> // ignored for now
</rule>
</core-rules>
*/
/* **** PHPIDS
* The default_filter.xml has its own tags which can simply be used.
*
<filters>
<filter>
<id>1</id> // used for: name
<rule /> // used for: code
<description /> // used for: desc
<tags> // used for: label (all <tag>s are concatenated)
<tag>xss</tag>
<tag>csrf</tag>
</tags>
<impact>4</impact> // ignored for now
</filter>
</filters>
*/
var bbb = fil.replace(/.*\/([^\/]*)$/,function(c,d){return(d)}); // index is filename, not a path
var tag = 'attack';
if (bbb==='default_filter.xml') { tag = 'filter'; }
var bux = src.getElementsByTagName(tag);
//#dbx __dbx(this.ME + '.XMLmenu: src=#{\n' + src + '#}');
if (bux.length===0) {
__dbx(this.ME + '.XMLmenu: no <' + tag + '> scopes found');
bux = src.getElementsByTagName('rule'); // core-rules.xml
if (bux.length===0) {
__dbx(this.ME + '.XMLmenu: no <rule> scopes found');
__dbx(this.ME + '.XMLmenu:{\n' + src + '\n}');
return '';
}
}
if (EnDeGUI.__files[bbb]===undefined) {// file not specified in EnDe.File.xml
// simply add it on the fly ..
EnDeGUI.__filesDefault(bbb);
EnDeGUI.__files[bbb][0] = $('EnDeDOM.GUI.obj').value;
EnDeGUI.__files[bbb][2] = 'User File ' + bbb + ': ';
//source file : target function to be called text label text button
}
var groups=[];
var c = 0, i = 0, n = 0;
var label = '-undef-';
var grp = EnDeGUI.grpID; // start numbering here
var txt = '';
var item = '';
var nam = '';
var cod = 'undef';
var des = '';
var msg = '';
var ctx = 'warn\tnone';
ctx += '\nmakeID\t' + 'auto'; // this must be before any item* line
for (c=0;c<bux.length;c++) { // walk XML tree
try {
if (bux[c].childNodes.length == 0) { continue; } // skip empty nodes
} catch(e){ __dbx(this.ME + '.XMLmenu: 0 bux['+c+'].childNodes.length failed: '+e); };
if (bux[c].nodeType != 1) { continue; } // skip empty or text nodes
nam = '';
cod = '';
des = '';
//#dbx if(you_want==huge_output) __dbx(':' + c + '=' + bux[c].nodeName);
for (n=0;n<bux[c].childNodes.length;n++) {
if (bux[c].childNodes[n].nodeType !==1) { continue; } // skip empty nodes
//#dbx if(you_want==huge_output) if(xxx===1) __dbx(' [' + n +']<' + bux[c].childNodes[n].nodeName + '>\t' + bux[c].childNodes[n].firstChild.nodeValue);
if (bux[c].childNodes[n].firstChild!==null) { // avoid error
txt = bux[c].childNodes[n].firstChild.nodeValue;
} else {
txt = '';
}
switch (bux[c].childNodes[n].nodeName) {
case 'id': // default_filter.xml
case 'name': nam = txt; break;
case 'description': // default_filter.xml
case 'desc': des = txt.replace(/\n/g, ' '); break;
case 'rule':
if (bbb!=='default_filter.xml') { /* skip */ break; }
// else rule is same as code in other files
case 'code': cod = txt;
if (cod.match(/[\n\t]/)!==null) {
cod = '<![CDATA[' + txt + ']]>';
}
break;
case 'label':
case 'selector': // core-rules*.xml
label= txt;
if (label.length > 58) { label = label.substr(0, 58) + '\u2026'; }
if (groups[label]===undefined) {
groups[label] = new Array();
}
break;
case 'impact': msg = txt; break // default_filter.xml
case 'comment': des = txt.replace(/\n/g, ' '); break; // core-rules*.xml
case 'operator': cod = txt; nam = txt;break; // core-rules*.xml
case 'actions': // core-rules*.xml
for (var a=0;a<bux[c].childNodes[n].childNodes.length;a++) {
switch (bux[c].childNodes[n].childNodes[a].nodeName) {
case 'msg' : msg = bux[c].childNodes[n].childNodes[a].firstChild.nodeValue; break;
//default: silently ignore for now
}
}
break;
case 'tags': // default_filter.xml
label = '';
for (var a=0;a<bux[c].childNodes[n].childNodes.length;a++) {
switch (bux[c].childNodes[n].childNodes[a].nodeName) {
case 'tag':
if (label!=='') { label += ','; }
label += bux[c].childNodes[n].childNodes[a].firstChild.nodeValue;
break;
}
}
break;
case 'target': item += '\ntarget\t' + txt; break;
case 'func': item += '\nfunc\t' + txt; break;
case 'prefix': item += '\nprefix\t' + txt; break;
case 'browser': /* NOT YET SUPPORTED */ break;
/* this is dangerous, so we don't allow eval for arbitrary data, see 'opts' instead
* case 'eval':
* try { eval(txt); }
* catch(e){ EnDeGUI.alert('this.menu: ['+c+'] eval('+txt+') failed', e); };
* break;
*/
default: /* silently ignored */
item += '\n#unknown\t' + bux[c].childNodes[n].nodeName; break;
break;
}
}
if ( des==='' ) { des = msg; } // try msg if comment was missing
if ((cod!=='') && (nam!=='')) { item += '\nitem3\t' + cod + '\t' + ((nam.length>58)?nam.substr(0, 58)+' \u2026':nam) + '\t' + des; }
if (groups[label]===undefined) {
// if there are no labeld groups
groups[label] = new Array();
}
groups[label].push(item);
item = '';
} // walk XML tree
delete bux; bux = null;
// generate groups
c = 0;
for (n in groups) { if (n!=='indexOf') { c++; } }
if (c>1) { // have groups
for (n in groups) {
if (n==='indexOf') { continue; }
if (n==='') { continue; }
ctx += '\ngroup\t' + 'group' + grp + '\t' + n + '\t' + n;
grp++;
for (i=0; i<groups[n].length; i++) {
ctx += '\n' + groups[n][i];
//ctx += '\n'+i;
}
}
}
// generate menu
ctx += '\n\nmenu\t' + bbb + '\t' + EnDeGUI.__files[bbb][2] + '\t' + EnDeGUI.__files[bbb][3];
ctx += '\ninside\t' + EnDeGUI.__files[bbb][0];
ctx += '\nid\t' + EnDeGUI.__files[bbb][0] + '.menu';
ctx += '\nonClick\t' + EnDeGUI.__files[bbb][1];
ctx += '\nhtml\t' + 'SELECT';
ctx += '\nsize\t' + '1';
if (c>1) { // have groups
grp = EnDeGUI.grpID;
for (n in groups) {
if (n==='indexOf') { continue; }
ctx += '\nuse\t' + 'group' + grp;
grp++;
}
EnDeGUI.grpID = grp;// ToDo: ugly side effect
} else { // no groups, plain menu
for (n in groups) { // may be one group, but we don't know the name
if (n==='indexOf') { continue; }
for (i=0; i<groups[n].length; i++) {
ctx += groups[n][i];
}
}
}
// finally
for (n in groups) {
if (n==='indexOf') { continue; }
while (groups[n].pop()) {}
delete groups[n];
}
//#dbx if(you_want==huge_output) __dbx('{#CTX:\n' + ctx + '\nCTX#}');
return ctx;
}; // XMLmenu
}; // .txt
// ========================================================================= //
// EnDeGUI object methods for building menus //
// ========================================================================= //
EnDeGUI.Obj = new function() {
//#? class for functions building menus in DOM
this.ME = 'EnDeGUI.txt';
this.sid = function() { return(EnDeGUI.sid() + '.Obj'); };
var __dbx = function(t,n) { if (EnDeGUI.Obj.trace===true) { EnDeGUI.dpr(t, n); } };
this.trace = false;
// ===================================================================== //
// public EnDeGUI.Obj variables //
// ===================================================================== //
this.menus = new Array(); // store (SELECT) menu objects
this.groups = new Array(); // store OPTGROUP menu objects
// ===================================================================== //
// (private) global EnDeGUI.Obj variables //
// ===================================================================== //
this.action = ''; // global variable for onClick or onChange attribute // ToDo: dirty hack
this.hidden = 0; // counter for dynamically generated tag id= attributes
this.menuCHR= false; // true: add real character to OPTION's label text
this.menuUCS= false; // true: add real Unicode character to OPTION's label text
this.menuHEX= false; // true: prefix description with hex value of character
/* menuCHR, menuUCS, menuHEX are necessary 'cause we need this information
* when processing the (array of) items of a group. The flag is stored
* in the same object as the items, but when processing items we don't
* have access to its parent object. Hence we need a more global flag.
* This is in particular important if the corresponding flags are set in
* the main menu (menu keyword) and not the used submenus (group keyword).
*/
// ===================================================================== //
// misc. methods //
// ===================================================================== //
// ===================================================================== //
// HTML tag creation functions //
// ===================================================================== //
this.unhideall = function() {
//#? toggle visibility of dynamically generated hidden objects (those named "hidden_NN")
/* see 'hide3', 'hide4' in EnDeMenu.txt also */
var bbb = null;
var ccc = null;
var i = 0;
for (i=0; i<= EnDeGUI.Obj.hidden; i++) {
bbb = 'hidden_' + i;
ccc = $(bbb);
// if condition used to trigger try{}, where catch ignores the error which is ok
try { if (ccc.style.display != '' ) { EnDeGUI.display(ccc); } } catch(e) {}
try { if (ccc.style.visibility) { EnDeGUI.visible(ccc); } } catch(e) {}
// ToDo: this.visible(ccc) not yet working with SELECT OPTGROUP
//this.visible(ccc);
}
bbb = null;
ccc = null;
return false;
}; // unhideall
this.hide = function(src, style) {
//#? sets object id to 'hidden_NN'; increments global EnDeGUI.Obj.hidden
EnDeGUI.Obj.hidden++;
src.setAttribute('id', 'hidden_'+EnDeGUI.Obj.hidden);
if ((style!=null) && (style!='')) {
src.setAttribute('style', style);
}
}; // .hide
this.redo = function(txt, act) {
//#? create button with text and action
var bux = document.createElement('A');
bux.setAttribute('onClick', act);
bux.setAttribute('class', 'button');
// ToDo: style in EnDe.css
bux.setAttribute('style', 'text-decoration:none;border:2px outset black;');
bux.value = 'repeat';
bux.innerHTML = txt;
bux.href = '#';
//alert('a: '+act);
return bux;
}; // .redo
this.create = function(pid, src, parenttyp, typ, hidden) {
//#? create objects and elements
/* pid: parent's id
* parenttyp: ANCHOR, BUTTON, SELECT (will be passed to sub-sequent calls)
* typ: menu, group, OPTGROUP, OPTION etc. (generates DOM object)
* hidden: true if created element should be display:none
* NOTE: label 'repeat' is handled special
*/
__dbx('EnDeGUI.Obj.create('+pid+', (src)'+parenttyp+', '+typ+', '+hidden+')');
var bux = null;
var bbb = null;
var ccc = null;
var obj = null;
var kkk = null;
// check for undefined or null object which may occour when reading .txt file failed
if (src===null) { bux = 'null'; }
if (src===undefined) { bux = 'undefined'; }
if (bux!==null) {
__dbx(' src=[' + bux + '] **failed**');
return null;
}
//#dbx var t=''; for (var xxx in src) { t+=xxx+':'+src[xxx]+'\n';} __dbx('.Obj.create: '+t);
/* WARNING: above debug produces huge output, may result in performance problems */
switch (typ) {
// menu types
case 'menu':
this.action = src.onClick;
if (src.tag.match(/SELECT/i)!==null) {
if (EnDeGUI.useANCHOR===true) { // overwrite menu file settings
bbb = 'ANCHOR'; // just a flag ..
src.tag = 'ANCHOR';
src.clss = 'select popup'; // ToDo: ugly hack, not yet perfect
}
}
// create container tag
bux = EnDeGUI.Obj.create(src.id, src, src.tag, src.tag, hidden);
//var t=''; for (var xxx in src){t+=xxx+':'+src[xxx]+'\n';} alert('.Obj.create: '+t); return;
// create sub menus
for (ccc in src.use) {
if (ccc==='indexOf') { continue; }
if (src.use[ccc].match(/function/) !==null) { continue; } // contribution to old Mozilla
if (EnDeGUI.Obj.groups[src.use[ccc]]===null) { // defensive programming
EnDeGUI.alert('ERROR: EnDeGUI.Obj.create', 'undefined use "'+src.use[ccc]+'"');
continue;
}
EnDeGUI.Obj.menuCHR = src.realCHR;
EnDeGUI.Obj.menuUCS = src.realUCS;
EnDeGUI.Obj.menuHEX = src.showHEX;
obj = EnDeGUI.Obj.create(src.id, EnDeGUI.Obj.groups[src.use[ccc]], src.tag, 'group', hidden);
bux.appendChild(obj);
delete this.obj;
} // use
// create items, if any
if (src.items.length>0) {
kkk = '';
switch (src.tag) {
// src.tag should always be capital letters, but we allow lazy developers ...
case 'select':
case 'SELECT': kkk = 'OPTION'; break;
case 'anchor':
case 'ANCHOR': kkk = 'A'; break;
// all following should never occure as they don't have items
case 'BUTTON':
case 'TABLE':
default:
EnDeGUI.alert( 'ERROR: EnDeGUI.Obj.create', 'object "'+src.typ+'" with items; ignored' );
break;
}
if (kkk!=='') {
for (ccc=0; ccc<src.items.length; ccc++) {
obj = EnDeGUI.Obj.create( pid, src.items[ccc], parenttyp, kkk, src.onClick );
bux.appendChild(obj);
delete this.obj;
}
}
kkk = null;
} // items
// create input fields, if any
if (src.input.length>0) { // very special for typ=TABLE
obj = document.createElement('INPUT');
obj.type = 'hidden';
obj.title = 'old: character to be replaced';
obj.value = '';
obj.id = 'EnDeDOM.MP.selected';
bux.appendChild(obj);
delete this.obj;
}
for (ccc in src.input) {
if (ccc==='indexOf') { continue; }
if (src.input[ccc] == null) { // defensive programming
EnDeGUI.alert('ERROR: EnDeGUI.Obj.create', 'undefined input "'+src.use[ccc]+'"');
continue;
}
obj = EnDeGUI.Obj.create(src.id, src.input[ccc], 'TABLE', 'group', hidden);
bux.appendChild(obj);
delete this.obj;
} // input
// ugly browser hacks, if needed
if (src.tag==='SELECT') { // onClick hack
bux.selectedIndex = -1;
}
if (bbb==='ANCHOR') { // flat menu hack
obj = document.createElement('SPAN');
obj.setAttribute('class', 'select popup'); // ToDo: ugly hack, not yet perfect
obj.className = 'select popup';
obj.appendChild(bux);
bux = obj;
}
// no return as we set other attributes also
break;
case 'group':
switch (parenttyp) {
case 'ANCHOR':
bux = document.createElement('LI');
bux.innerHTML = src.label;
bbb = document.createElement('UL');
if ((src.style!=null) && (src.style!='')) {
this.hide(bbb, src.style);
}
// ToDO: EnDeGUI.Obj.menuUCS = src.realUCS;
for (ccc in src.items) {
//src.items[ccc].onClick = src.onClick; // pass onClick attribute to .Obj.create()
if (ccc==='indexOf') { continue; }
obj = EnDeGUI.Obj.create(pid, src.items[ccc], parenttyp, 'A', src.onClick);
bbb.appendChild(obj);
delete this.obj;
}
// ToDO: EnDeGUI.Obj.menuUCS = false;
bux.appendChild(bbb);
delete this.bbb;
break;
case 'BUTTON':
bux = document.createElement('FIELDSET');
obj = document.createElement('LEGEND');
obj.innerHTML = src.title;
bux.appendChild(obj);
for (ccc in src.items) {
if (ccc==='indexOf') { continue; }
obj = EnDeGUI.Obj.create(pid, src.items[ccc], parenttyp, 'INPUT', hidden);
bux.appendChild(obj);
delete this.obj;
}
delete this.obj;
break;
case 'SELECT':
bux = EnDeGUI.Obj.create(pid, src, parenttyp, 'OPTGROUP', hidden);
// ToDo: EnDeGUI.Obj.menuUCS = src.realUCS;
for (ccc in src.items) {
if (ccc==='indexOf') { continue; }
obj = EnDeGUI.Obj.create(pid, src.items[ccc], parenttyp, 'OPTION', hidden);
// on*-events need to be set after object createion as src.items[] does not contain this information
if (src.onMover!=='') { obj.setAttribute('onMouseover', src.onMover); }
if (src.onMout !=='') { obj.setAttribute('onMouseout', src.onMout); }
bux.appendChild(obj);
delete this.obj;
}
// ToDo: EnDeGUI.Obj.menuUCS = false;
break;
case 'TABLE':
/* note that typ=TABLE is very special because:
* 1. it is not usable for generic tables because
* it is fixed with 4 colums per row
* 2. each column has its special width
* 3. special settings depending on name of field
* for example char1, char2, -99-, etc.)
* 4. uses fixed object IDs (EnDeDOM.MP.*)
*/
bux = document.createElement('DIV'); // a row
for (ccc=1; ccc<5; ccc++) { // the columns
obj = document.createElement('SPAN');
obj.setAttribute('class', 'd'+ccc);
//obj.setAttribute('style', 'float:left;width:3em');
bbb = document.createElement('INPUT');
switch (ccc) {
case 1:
bbb.type = 'checkbox';
bbb.title = 'check to use this replacement';
bbb.id = 'EnDeDOM.MP.use' + src[1];
if (src[1].match(/char/)===null) {
bbb.setAttribute('checked', 1);
}
break;
case 2:
delete this.bbb;
bbb = document.createElement('LABEL');
//obj.setAttribute('style', 'float:left;width:5em;text-align:right;');
bbb.innerHTML = src[1] + ' : ';
break;
case 3:
bbb.type = 'text';
bbb.title = 'character to be replaced';
bbb.value = src[2];
bbb.id = 'EnDeDOM.MP.old' + src[1];
if (src[1].match(/^char/)===null) {
bbb.setAttribute('disabled', 1);
}
bbb.setAttribute('onClick', 'EnDeGUI.MP.select(this.id);');
break;
case 4:
bbb.type = 'text';
bbb.title = 'new: replacement character';
bbb.value = src[3];
bbb.id = 'EnDeDOM.MP.new' + src[1];
obj.setAttribute('style', 'float:none;width:2em');
bbb.setAttribute('onClick', 'EnDeGUI.MP.select(this.id);');
break;
}
obj.appendChild(bbb);
bux.appendChild(obj);
delete this.obj;
delete this.bbb;
}
//bux.appendChild(document.createElement('BR'));
break;
}
delete this.obj;
delete this.bbb;
bbb = null;
return bux;
break;
// main object types
case 'SELECT':
bux = document.createElement('SELECT');
if (EnDeGUI.onClick===true) {
bux.setAttribute('onClick', src.onClick);
} else { // Konqueror
bux.setAttribute('onChange', src.onClick);
}
bux.selectedIndex = -1; // useless here in some browsers, unfortunatelly
break;
case 'ANCHOR': return document.createElement('UL'); break;
case 'BUTTON': return document.createElement('DIV'); break;
case 'TABLE': return document.createElement('DIV'); break;
// secondary object types
case 'OPTGROUP':
bux = document.createElement('OPTGROUP');
/*
if (hidden===true) {
this.hide(bux, src.style);
}
*/
//return bux;
break;
case 'INPUT':
bbb = this.action;
bbb = bbb.replace(/this.value/, "'" + src[2] + "'");
bux = document.createElement('SPAN');
obj = document.createElement('INPUT');
obj.type = 'button';
obj.id = pid + '.' + src[1];
obj.value = src[3];
obj.title = src[4];
obj.setAttribute('onClick', bbb);
obj.setAttribute('class', 'button');
bux.appendChild(obj);
delete this.obj;
bbb = null;
break;
case 'A':
bbb = this.action;
bbb = bbb.replace(/this.value/, "'" + src[2] + "'");
bux = document.createElement('LI');
obj = document.createElement('A');
obj.id = pid + '.' + src[1];
obj.innerHTML = EnDe.Text.Entity(src[3]);
obj.title = src[4];
if (EnDeGUI.a_Click===true) {
obj.setAttribute('onClick', bbb);
obj.href = '#';
} else {
obj.href = 'javascript:'+bbb;
}
if (src[0]!=null) { // contribution to old Mozilla 1.x
if (src[0].match(/^hidd?e/)!==null) { // matches hidden, hide3, hide4, ...
this.hide(obj, 'display:none');
}
}
bux.appendChild(obj);
delete this.obj;
bbb = null;
return bux;
break;
case 'OPTION':
// don't know why, but src comes as Object and not Array
bux = document.createElement('OPTION');
if (src[0]!=null) { // contribution to old Mozilla 1.x
if (src[0].match(/^hidd?e/)!==null) { // matches hidden, hide3, hide4, ...
this.hide(bux, 'display:none');
}
}
bux.id = pid + '.' + src[1];
bux.value = src[2];
bux.text = src[3];
bux.title = '';
if (EnDeGUI.Obj.menuUCS===true) { // Unicode/UTF-8 mismatch characters; i.e.: dead beef
for (bbb=src[3].length; bbb<3; bbb++) { bux.text += String.fromCharCode(160); } // beautify text
bux.text += ' : ' + String.fromCharCode(160);
kkk = src[2].split(/ /); // expect: dead beaf
for (bbb=0; bbb<kkk.length; bbb++) { bux.text += String.fromCharCode(parseInt(kkk[bbb], 16)); }
//dbx# __dbx('EnDeGUI.Obj.create: menuUCS['+src[2]+']: '+bux.text);
}
if (EnDeGUI.Obj.menuCHR===true) { // Unicode/ISO mismatch; i.e. 0722, 0727
bux.text = '';
for (bbb=src[3].length; bbb<3; bbb++) { bux.text += String.fromCharCode(160); } // beautify text
if (src[2].length<3) { bux.text += String.fromCharCode(160); } // one more beautify (dirty hack)
bux.text += src[3] + ' : ' + String.fromCharCode(160) + String.fromCharCode(src[2]);
//dbx# __dbx('EnDeGUI.Obj.create: menuCHR['+src[2]+']: '+bux.text);
}