-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsbbslist.js
2700 lines (2575 loc) · 77.4 KB
/
sbbslist.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
// $Id: sbbslist.js,v 1.66 2020/04/19 19:57:15 rswindell Exp $
// Synchronet BBS List
// This one script replaces (or *will* replace) the functionality of:
// sbl[.exe] - External online program (door)
// smb2sbl[.exe] - Imports BBS entries from Synchronet Message Base (e.g. from SYNCDATA echo)
// sbl2smb[.exe] - Exports BBS entries to Synchronet Message Base (e.g. to SYNCDATA echo)
// sbbslist[.exe] - Exports BBS entries to HTML and various plain-text formats (e.g. sbbs.lst, sbbsimsg.lst, syncterm.lst)
// TODO: Daily maintenance, warning local creators and purging old unverified entries
var REVISION = "$Revision: 1.66 $".split(' ')[1];
var version_notice = "Synchronet BBS List v4(" + REVISION + ")";
load("sbbsdefs.js");
load("sockdefs.js");
load("portdefs.js");
load("hexdump_lib.js");
var sbl_dir = "../xtrn/sbl/";
var list_format = 0;
var export_freq = 7; // minimum days between exports
var color_cfg = {
header: BLACK | BG_LIGHTGRAY,
selection: BG_BLUE,
column: [ WHITE ],
sorted: BG_RED,
};
var cmd_prompt_fmt = "\1n\1c\xfe \1h%s \1n\1c\xfe ";
if(js.global.console==undefined || !console.term_supports(USER_ANSI))
cmd_prompt_fmt = "%s: ";
var debug = false;
var options=load({}, "modopts.js", "sbbslist");
if(!options)
options = {};
if(!options.sub)
options.sub = load({}, "syncdata.js").find();
if(!options.max_inactivity)
options.max_inactivity = 180; // Days
if(options && options.format > 0)
list_format = options.format;
if(options && options.export_freq > 0)
export_freq = options.export_freq;
var lib = load({}, "sbbslist_lib.js");
var capture = load({}, "termcapture_lib.js");
capture.timeout=15;
capture.poll_timeout=10;
if(js.global.bbs && bbs.mods.avatar_lib)
avatar_lib = bbs.mods.avatar_lib;
else
avatar_lib = load({}, 'avatar_lib.js');
function objcopy(obj)
{
return JSON.parse(JSON.stringify(obj));
}
// This date format is required for backwards compatibility with SMB2SBL
function date_to_str(date)
{
return format("%02u/%02u/%02u", date.getUTCMonth()+1, date.getUTCDate(), date.getUTCFullYear()%100);
}
function date_from_str(str)
{
var a = str.split("/");
var month = parseInt(a[0], 10);
var day = parseInt(a[1], 10);
var year = parseInt(a[2], 10);
year += 1900;
if(year < 1970)
year += 100;
return new Date(year, month - 1, day);
}
function export_entry(bbs, msgbase)
{
var i;
var hdr = { to:'SBL', from:bbs.entry.created.by, subject:bbs.name };
var body = ""; // This section for SMB2SBL compatibility
body += "Name: " + bbs.name + "\r\n";
if(bbs.first_online)
body += "Birth: " + date_to_str(new Date(bbs.first_online)) + "\r\n";
if(bbs.software)
body += "Software: " + bbs.software + "\r\n";
for(i in bbs.sysop) {
body += "Sysop: " + bbs.sysop[i].name + "\r\n";
if(i==0 && bbs.sysop[i].email)
body += "e-mail: " + bbs.sysop[i].email + "\r\n";
}
if(bbs.web_site)
body += "Web-site: " + bbs.web_site + "\r\n";
if(bbs.location)
body += "Location: " + bbs.location + "\r\n";
for(i in bbs.service) {
switch(bbs.service[i].protocol.toLowerCase()) {
case 'modem':
body += "Number: " + bbs.service[i].address + "\r\n";
body += "MinRate: " + bbs.service[i].min_rate + "\r\n";
body += "MaxRate: " + bbs.service[i].max_rate + "\r\n";
if(bbs.service[i].description)
body += "Modem: " + bbs.service[i].description + "\r\n";
break;
case 'telnet':
body += "Telnet: " + bbs.service[i].address + "\r\n";
if(bbs.service[i].port
&& bbs.service[i].port != standard_service_port["telnet"])
body += "Port: " + bbs.service[i].port + "\r\n";
break;
}
}
for(i in bbs.network) {
if(i >= sbl_defs.MAX_NETS)
break;
body += "Network: " + bbs.network[i].name + "\r\n";
body += "Address: " + bbs.network[i].address + "\r\n";
}
for(i in bbs.terminal.types)
body += "Terminal: " + bbs.terminal.types[i] + "\r\n";
if(bbs.terminal.nodes)
body += "Nodes: " + bbs.terminal.nodes + "\r\n";
if(bbs.total.storage)
body += "Megs: " + bbs.total.storage / (1024*1024) + "\r\n";
if(bbs.total.msgs)
body += "Msgs: " + bbs.total.msgs + "\r\n";
if(bbs.total.files)
body += "Files: " + bbs.total.files + "\r\n";
if(bbs.total.users)
body += "Users: " + bbs.total.users + "\r\n";
if(bbs.total.subs)
body += "Subs: " + bbs.total.subs + "\r\n";
if(bbs.total.dirs)
body += "Dirs: " + bbs.total.dirs + "\r\n";
if(bbs.total.doors)
body += "Xtrns: " + bbs.total.doors + "\r\n";
for(i in bbs.description)
body += "Desc: " + bbs.description[i] + "\r\n";
delete bbs.entry;
body += "\r\njson-begin\r\n";
body += lfexpand(JSON.stringify(bbs, null, 1)) + "\r\n";
body += "json-end\r\n";
body += "--- " + js.exec_file + " " + REVISION + "\r\n";
// print(body);
return msgbase.save_msg(hdr, body);
}
function export_to_msgbase(list, msgbase, limit, all)
{
var i;
var count=0;
var errors=0;
for(i in list) {
if(js.terminated)
break;
if(all != true) {
if(list[i].imported)
continue;
var last_export = 0;
if(list[i].entry.exported)
last_export = new Date(list[i].entry.exported.on).valueOf();
var created = 0;
if(list[i].entry.created)
created = new Date(list[i].entry.created.on).valueOf();
var updated = 0;
if(list[i].entry.updated)
updated = new Date(list[i].entry.updated.on).valueOf();
var verified = 0;
if(list[i].entry.verified)
verified = new Date(list[i].entry.verified.on).valueOf();
if(created <= last_export
&& updated <= last_export
&& verified <= last_export)
continue;
if((new Date().valueOf() - last_export) < export_freq * (24*60*60*1000))
continue;
}
if(!export_entry(objcopy(list[i]), msgbase)) {
alert("MsgBase error: " + msgbase.last_error);
errors++;
}
else {
if(!list[i].entry.exported)
list[i].entry.exported = { on: null, by: null, to: null, count: 1 };
else
list[i].entry.exported.count++;
list[i].entry.exported.on = new Date().toISOString();
list[i].entry.exported.by = js.exec_file + " " + REVISION;
list[i].entry.exported.to = file_getname(msgbase.file);
count++;
}
if(limit && count >= limit)
break;
}
print("Exported " + count + " entries (" + errors + " errors)");
if(count)
lib.write_list(list);
}
function delete_in_msgbase(msgbase, bbs)
{
var i;
var hdr = { to:'SBL-Remove', from:bbs.entry.created.by, subject:bbs.name };
var body = "Name: " + bbs.name + "\r\n";
return msgbase.save_msg(hdr, body);
}
function import_entry(name, text)
{
var i;
var json_begin;
var json_end;
var bbs = lib.new_system(name, /* nodes: */0);
text=text.split("\r\n");
for(i=0; i<text.length; i++) {
if(text[i]=="---" || text[i].substring(0,4)=="--- ")
break;
}
text.length=i;
for(i=0; i<text.length; i++) {
if(text[i].toLowerCase()=="json-begin")
json_begin=i+1;
else if(text[i].toLowerCase()=="json-end")
json_end=i;
}
if(json_begin && json_end > json_begin) {
text=text.splice(json_begin, json_end-json_begin);
try {
if((bbs = JSON.parse(text.join(' '))) != undefined)
return bbs;
} catch(e) {
alert("Error " + e + " parsing JSON");
}
return bbs;
}
/* Parse the old SBL2SMB syntax: */
var sysop=0;
var network=0;
var terminal=0;
var desc=0;
var number=0;
for(i in text) {
//print(text[i]);
var line = truncsp(text[i]);
if(!line.length)
continue;
var match=line.match(/\s*([A-Z\-]+)\:\s*(.*)/i);
if(!match || match.length < 3) {
print("No match: " + line);
continue;
}
if(debug) print(match[1] + " = " + match[2]);
switch(match[1].toLowerCase()) {
case 'birth':
if(match[2] && match[2].length)
bbs.first_online = date_from_str(match[2]);
break;
case 'software':
bbs.software = match[2];
break;
case 'sysop':
if(bbs.sysop.length)
sysop++;
bbs.sysop[sysop] = { name: match[2] };
break;
case 'e-mail':
if(bbs.sysop.length)
bbs.sysop[0].email = match[2];
break;
case 'web-site':
bbs.web_site = match[2];
break;
case 'number':
if(bbs.service.length)
number++;
bbs.service[number] = {address: match[2], protocol: 'modem'};
break;
case 'telnet': /* SBL2SMB never actually generated this line though SMB2SBL supported it */
if(bbs.service.length)
number++;
bbs.service[number] = {address: match[2], protocol: 'telnet', port: standard_service_port["telnet"]};
break;
case 'minrate':
var minrate = parseInt(match[2], 10);
if(minrate == 0xffff) {
bbs.service[number].protocol = 'telnet';
var uri=bbs.service[number].address.match(/^(\S+)\:\/\/(\S+)/);
if(uri) {
bbs.service[number].protocol = uri[1];
bbs.service[number].address = uri[2];
}
bbs.service[number].port = standard_service_port[bbs.service[number].protocol.toLowerCase()];
} else
bbs.service[number].minrate = minrate;
break;
case 'maxrate':
if(bbs.service[number].protocol != 'modem')
bbs.service[number].port = parseInt(match[2], 10);
else
bbs.service[number].maxrate = parseInt(match[2], 10);
break;
case 'location':
bbs.location = match[2];
break;
case 'port': /* SBL2SMB never actually generated this line though SMB2SBL supported it */
bbs.service[number].port = parseInt(match[2], 10);
break;
case 'network':
if(bbs.network.length)
network++;
bbs.network[network] = {name: match[2]};
break;
case 'address':
bbs.network[network].address = match[2];
break;
case 'terminal':
if(bbs.terminal.types.length)
terminal++;
bbs.terminal.types[terminal] = match[2];
break;
case 'desc':
if(bbs.description.length)
desc++;
bbs.description[desc] = match[2];
break;
case 'megs':
bbs.total.storage = parseInt(match[2], 10)*1024*1024;
break;
case 'msgs':
case 'files':
case 'users':
case 'subs':
case 'dirs':
bbs.total[match[1].toLowerCase()] = parseInt(match[2], 10);
break;
case 'xtrns':
bbs.total.doors = parseInt(match[2], 10);
break;
case 'nodes':
bbs.terminal.nodes = parseInt(match[2], 10);
break;
}
}
if(debug) print(JSON.stringify(bbs, null, 1));
return bbs;
}
function import_from_msgbase(list, msgbase, import_ptr, limit, all)
{
var i=0;
var count=0;
var highest;
var sbl_crc=crc16_calc("sbl");
var sbl_remove_crc=crc16_calc("sbl-remove");
var ini = new File(msgbase.file + ".ini");
if(import_ptr == undefined) {
if(ini.open("r")) {
import_ptr=ini.iniGetValue("sbbslist","import_ptr", 0);
ini.close();
} else if(debug)
print("Error " + ini.error + " opening " + ini.name);
if(import_ptr==undefined) {
var f = new File(file_getcase(msgbase.file + ".sbl"));
if(f.open("rb")) {
import_ptr = f.readBin(4);
f.close();
}
}
}
highest=import_ptr;
var total_msgs = msgbase.total_msgs;
log(LOG_DEBUG, "import_ptr = " + import_ptr + ", last_msg = " + msgbase.last_msg + ", total_msgs = " + total_msgs);
if(msgbase.last_msg >= import_ptr)
i = total_msgs - (msgbase.last_msg - import_ptr);
for(; i<total_msgs; i++) {
if(js.terminated)
break;
if(debug)
print(i);
var idx = msgbase.get_msg_index(/* by_offset: */true, i);
if(!idx) {
// print("Error " + msgbase.error + " reading index of msg offset " + i);
continue;
}
if(idx.number <= import_ptr)
continue;
if(idx.number > highest)
highest = idx.number;
if(idx.to != sbl_crc && idx.to != sbl_remove_crc)
continue;
var hdr = msgbase.get_msg_header(/* by_offset: */true, i);
if(!hdr.to)
continue;
var sbl_remove = hdr.to.toLowerCase() == "sbl-remove";
if(hdr.to.toLowerCase() != "sbl" && !sbl_remove)
continue;
var l;
var msg_from = hdr.from;
if(all != true && !hdr.from_net_type) // Skip locally posted messages
continue;
if(hdr.from_net_addr && hdr.from_net_addr.length)
msg_from += "@" + hdr.from_net_addr;
var bbs_name = truncsp(hdr.subject);
printf("Msg #%u from %s: ", i+1, msg_from);
// print("Searching " + list.length + " entries for BBS: " + bbs_name);
for(l=0; l<list.length; l++) {
//print("Comparing " + list[l].name);
if(list[l].name.toLowerCase() == bbs_name.toLowerCase())
break;
}
// print("l = " + l);
if(l==undefined)
l=0;
var entry = {}; // We preserve this object (and the BBS name) in the system's entry
if(list.length && list[l]) {
if(!list[l].entry)
continue;
if(!list[l].imported && hdr.from_net_type) {
print(msg_from + " attempted to update/over-write local entry: " + bbs_name);
continue;
}
entry = list[l].entry;
if(entry.created.by.toLowerCase() != hdr.from.toLowerCase()
|| (entry.created.at && entry.created.at != hdr.from_net_addr)) {
print(msg_from + " did not create entry: "
+ bbs_name + " (" + entry.created.by + "@" + entry.created.at + " did)");
continue;
}
print((sbl_remove ? "Removing" : "Updating")
+ " existing entry: " + bbs_name + " (by " + entry.created.by + ")");
if(sbl_remove) {
if(!lib.remove(entry))
alert("Failed to remove: " + bbs_name);
continue;
}
} else {
if(sbl_remove)
continue;
print(msg_from + " creating new entry: " + bbs_name);
entry = { created: { on:new Date().toISOString(), by:hdr.from, at:hdr.from_net_addr } };
}
var body = msgbase.get_msg_body(/* by_offset: */true, i
,/* strip Ctrl-A */true, /* rfc822-encoded: */false, /* include tails: */false);
var bbs = import_entry(bbs_name, body);
if(bbs.name != bbs_name) {
alert("Message body contained different BBS name (" + bbs.name + ") than subject: " + bbs_name);
continue;
}
if(hdr.from_net_type)
bbs.imported = true;
bbs.entry = entry;
bbs.entry.updated= { on: new Date().toISOString(), by:hdr.from, at:hdr.from_net_addr };
if(!lib.check_entry(bbs))
continue;
list[l] = bbs;
// if(!list[l].birth)
// list[l].birth=list[l].entry.created.on;
count++;
if(limit && count >= limit)
break;
}
if(ini.open(file_exists(ini.name) ? 'r+':'w+')) {
ini.iniSetValue("sbbslist","import_ptr",highest);
ini.close();
} else
print("Error opening/creating " + ini.name);
print("Imported " + count + " messages");
if(count)
return lib.write_list(list);
}
// From sbldefs.h (Do not change, for backwards compatibility):
const sbl_defs = {
MAX_SYSOPS: 5,
MAX_NUMBERS: 20,
MAX_NETS: 10,
MAX_TERMS: 5,
DESC_LINES: 5,
DESC_LINE_LEN: 50,
};
// Reads a single BBS entry from SBL v3.x "sbl.dab" file
function read_dab_entry(f)
{
// These sbl.dab magic numbers come from sbldefs.h (now deprecated)
var i;
var total;
var obj = { name: '', entry:{}, sysop:[], service:[], terminal:{}, network:[], description:[], total:{} };
obj.name = truncsp(f.read(26));
if(f.eof)
return null;
obj.entry.created = { on:null, by:truncsp(f.read(26)) };
obj.software = truncsp(f.read(16));
total = f.readBin(1);
for(i=0;i<sbl_defs.MAX_SYSOPS;i++)
obj.sysop[i] = { name: truncsp(f.read(26)) };
obj.sysop.length = total;
total_numbers = f.readBin(1);
total = f.readBin(1);
for(i=0;i<sbl_defs.MAX_NETS;i++) {
obj.network[i] = {};
obj.network[i].name = truncsp(f.read(16));
}
for(i=0;i<sbl_defs.MAX_NETS;i++)
obj.network[i].address = truncsp(f.read(26));
obj.network.length = total;
total = f.readBin(1);
obj.terminal.types = [];
for(i=0;i<sbl_defs.MAX_TERMS;i++)
obj.terminal.types[i] = truncsp(f.read(16));
obj.terminal.types.length = total;
for(i=0;i<sbl_defs.DESC_LINES;i++)
obj.description.push(truncsp(f.read(51)));
for(i=0;i<sbl_defs.DESC_LINES;i++)
if(obj.description[i].length == 0)
break;
obj.description.length=i; // terminate description at first blank line
obj.terminal.nodes = f.readBin(2);
obj.total.users = f.readBin(2);
obj.total.subs = f.readBin(2);
obj.total.dirs = f.readBin(2);
obj.total.doors = f.readBin(2);
obj.entry.created.on = new Date(f.readBin(4)*1000).toISOString();
var updated = f.readBin(4);
if(updated)
obj.entry.updated = { on: new Date(updated*1000).toISOString() };
var first_online = f.readBin(4);
if(first_online)
obj.first_online = new Date(first_online*1000).toISOString();
obj.total.storage = f.readBin(4)*1024*1024;
obj.total.msgs = f.readBin(4);
obj.total.files = f.readBin(4);
obj.imported = Boolean(f.readBin(4));
for(i=0;i<sbl_defs.MAX_NUMBERS;i++) {
var service = { address: truncsp(f.read(13)), description: truncsp(f.read(16)), protocol: 'modem' };
var location = truncsp(f.read(31));
var min_rate = f.readBin(2)
var port = f.readBin(2);
if(min_rate==0xffff) {
service.address = service.address + service.description;
service.description = undefined;
service.protocol = 'telnet';
var uri=service.address.match(/^(\S+)\:\/\/(\S+)/);
if(uri) {
service.protocol = uri[1].toLowerCase();
service.address = uri[2];
}
service.port = port;
} else {
// Only the first 12 chars of the modem "address" (number) are valid
//service.address = service.address.substr(0, 12);
service.min_rate = min_rate;
service.max_rate = port;
}
if(obj.service.indexOf(service) < 0)
obj.service.push(service);
if(obj.location==undefined || obj.location.length==0)
obj.location=location;
}
obj.service.length = total_numbers;
var updated_by = truncsp(f.read(26));
if(obj.entry.updated)
obj.entry.updated.by = updated_by;
var verified_date = f.readBin(4);
var verified_by = f.read(26);
if(verified_date)
obj.entry.verified = { on: new Date(verified_date*1000).toISOString(), by: truncsp(verified_by), count: 1 };
obj.web_site = truncsp(f.read(61));
var sysop_email = truncsp(f.read(61));
if(obj.sysop.length)
obj.sysop[0].email = sysop_email;
f.readBin(4); // 'exported' not used, always zero
obj.entry.autoverify = { successes: f.readBin(4), attempts: f.readBin(4) };
f.read(310); // unused padding
return obj;
}
// Upgrades from SBL v3.x (native/binary-data) to v4.x (JavaScript/JSON-data)
function upgrade_list(sbl_dab)
{
var dab = new File(sbl_dab);
print("Upgrading from: " + sbl_dab);
if(!dab.open("rb", /* shareable: */true)) {
alert("Error " + dab.error + " opening " + dab.name);
return [];
}
var list=[];
while(!dab.eof) {
if(js.terminated)
break;
var bbs = read_dab_entry(dab);
if(bbs==null || !bbs.name.length || bbs.name.charAt(0) == 0)
continue;
// print(bbs.name);
list.push(bbs);
}
dab.close();
lib.write_list(list);
return list;
}
function capture_preview(bbs, addr)
{
for(var i in bbs.service) {
if(js.terminated)
break;
var service = bbs.service[i];
var protocol = service.protocol.toLowerCase();
if(protocol != "telnet" && protocol != "rlogin")
continue;
capture.protocol = protocol;
if(addr)
capture.address = addr;
else
capture.address = service.address;
capture.port = service.port;
var result = capture.capture();
if(result == false)
return capture.error;
bbs.preview = lib.encode_preview(result.preview);
return true;
}
return false;
}
function verify_terminal_service(service)
{
print("Verifying terminal service: " + service.protocol + " at " + service.address + ":" + service.port);
capture.protocol = service.protocol.toLowerCase();
capture.address = service.address;
capture.port = service.port;
return capture.capture();
}
// Perform a limited TCP port scan to test for common "other services" on standard ports
// Results are used for instant message list and other stuff
// Terminal services (e.g. telnet, rlogin, ssh) are purposely excluded
function verify_services(address, timeout)
{
var i;
var tcp_services=[
"ftp",
"msp",
"nntp",
"smtp",
// "submission",
"pop3",
"imap",
"irc",
];
var udp_services=[
"systat",
];
var verified={ tcp: [], udp: []};
var udp_socket = new Socket(SOCK_DGRAM);
for(i in udp_services) {
var service = udp_services[i];
printf("Verifying %-10s UDP connection at %s\r\n", service, address);
if(!udp_socket.sendto("\r\n", address, standard_service_port[service]))
log(LOG_NOTICE,format("FAILED Send to %s UDP service at %s", service, address));
}
for(i in tcp_services) {
if(js.terminated)
break;
var service = tcp_services[i]
printf("Verifying %-10s TCP connection at %s ", service, address);
var socket = new Socket();
if(socket.connect(address, standard_service_port[service], timeout)) {
print("Succeeded");
verified.tcp.push(service);
socket.close();
} else
print("Failed");
}
print("Waiting for UDP replies");
while(verified.udp.length < udp_services.length && udp_socket.poll(3)) {
if(js.terminated)
break;
var msg=udp_socket.recvfrom(32*1024);
if(msg==null)
log(LOG_NOTICE, "FAILED (UDP recv)");
else {
log(LOG_DEBUG, format("UDP message (%u bytes) from %s port %u", msg.data.length, msg.ip_address, msg.port));
if(msg.ip_address != address)
continue;
for(i in udp_services) {
var service = udp_services[i];
if(standard_service_port[service] == msg.port) {
print("Valid UDP reply for service: " + service);
verified.udp.push(service);
}
}
}
}
print(format("Successfully verified %u TCP services and %u UDP services", verified.tcp.length, verified.udp.length));
return verified;
}
function verify_bbs(bbs)
{
var i;
var error="N/A";
if(!bbs.entry.autoverify)
bbs.entry.autoverify = {attempts:0, successes:0, last_failure: {result:'none'}};
bbs.entry.autoverify.success=false;
for(i in bbs.service) {
if(js.terminated)
break;
var protocol = bbs.service[i].protocol.toLowerCase();
if(protocol != "telnet" && protocol != "rlogin")
continue;
bbs.entry.autoverify.attempts++;
var result = verify_terminal_service(bbs.service[i]);
var failure = {
on: new Date(),
result: capture.error,
service: bbs.service[i],
ip_address: result.ip_address,
};
if(result == false) {
print(capture.error);
bbs.entry.autoverify.last_failure = failure;
} else {
print(result.stopcause);
if(result.hello.length && result.hello[0].indexOf("Synchronet BBS") == 0) {
bbs.entry.autoverify.success=true;
bbs.entry.autoverify.successes++;
bbs.entry.autoverify.last_success = {
on: new Date(),
result: result.hello[0],
stopcause: result.stopcause,
service: bbs.service[i],
ip_address: result.ip_address,
other_services: verify_services(result.ip_address, 5)
};
lib.verify_system(bbs, js.exec_file + " " + REVISION);
bbs.preview = lib.encode_preview(result.preview);
return true;
}
log(LOG_DEBUG,"Non-Synchronet identification: " + result.hello[0]);
failure.result = "non-Synchronet";
bbs.entry.autoverify.last_failure = failure;
}
}
return false;
}
function verify_list(list)
{
var i;
js.auto_terminate=false;
for(i in list) {
var bbs=list[i];
printf("Verifying BBS %u of %u: %s\n", Number(i)+1, list.length, bbs.name);
if(verify_bbs(bbs))
print("Success: " + bbs.entry.autoverify.last_success.result);
else if(bbs.entry.autoverify.last_failure)
print("Failure: " + bbs.entry.autoverify.last_failure.result);
lib.replace(bbs);
if(js.terminated)
break;
}
}
function console_color(arg, selected)
{
if(selected)
arg |= BG_BLUE;
if(js.global.console != undefined)
console.attributes = arg;
}
function console_beep()
{
if(js.global.console != undefined && options.beep !== false)
console.beep();
}
/* Supported list formats (the property values for 2nd & 3rd columns) */
const list_formats = [
[ "sysops", "location" ],
[ "phone_number", "service_address" ],
[ "since", "software", "web_site" ],
[ "description" ],
[ "networks"],
[ "nodes", "users", "subs", "dirs", "doors", "msgs", "files", "storage"],
[ "protocols"],
[ "created_by", "created_on" ],
[ "updated_by", "updated_on" ],
[ "verified_by", "verified_on" ],
];
function list_bbs_entry(bbs, selected, sort, is_first_on_page)
{
var sysop="";
var color = color_cfg.column[0];
if(sort=="name")
color |= color_cfg.sorted;
console_color(color, selected);
printf("%-*s%c", lib.max_len.name, bbs.name, selected ? '<' : ' ');
color = LIGHTMAGENTA;
if(!js.global.console || console.screen_columns >= 80) {
for(var i in list_formats[list_format]) {
var fmt = "%-*.*s";
var len = Math.max(list_formats[list_format][i].length, lib.max_len[list_formats[list_format][i]]);
if(i > 0)
len++;
if(js.global.console)
len = Math.min(len, console.screen_columns - console.current_column -1);
if(color > WHITE)
color = DARKGRAY;
if(color_cfg.column[i+1] != undefined)
color = color_cfg.column[i+1];
if(list_formats[list_format][i] == sort)
color |= color_cfg.sorted;
console_color(color++, selected);
if(i > 0 && i == list_formats[list_format].length-1)
fmt = "%*.*s";
if (selected && console.term_supports(USER_PETSCII) && !is_first_on_page)
--len;
printf(fmt, len, len, lib.property_value(bbs, list_formats[list_format][i]));
}
}
/* Ensure the rest of the line has the correct color */
if (typeof(console) == "object")
{
console_color(color, selected);
console.cleartoeol();
}
}
function right_justify(text)
{
console.print(format("%*s", console.screen_columns - console.current_column - 1, text));
}
function help()
{
console.clear();
console.printfile(system.text_dir + "sbbslist.hlp");
console.pause();
console.clear();
}
function test_port(port)
{
sock = new Socket();
success = sock.connect(system.host_name,port);
sock.close();
return(success);
}
function this_bbs()
{
var bbs = lib.new_system(system.name, system.nodes, lib.system_stats());
bbs.sysop.push({ name: system.operator, email: system.operator.replace(' ', '.') +'@'+ system.inet_addr });
bbs.software = "Synchronet";
bbs.location = system.location;
bbs.web_site = system.inet_addr;
bbs.terminal.types.push("TTY", "ANSI");
if(msg_area.grp["DOVE-Net"])
bbs.network.push({ name: "DOVE-Net", address: system.qwk_id});
if(msg_area.grp["FidoNet"] || msg_area.grp["Fidonet"])
bbs.network.push({ name: "FidoNet", address: system.fido_addr_list[0] });
print("Testing common BBS service ports (this may take a minute)");
var ports = [];
for(var i in lib.common_bbs_services) {
var prot = lib.common_bbs_services[i];
if(prot == "modem") // No method to test
continue;
if(ports.indexOf(standard_service_port[prot]) >= 0) // Already tested this port
continue;
printf("\b\b\b%s ...", prot);
ports.push(standard_service_port[prot]);
if(test_port(standard_service_port[prot]))
bbs.service.push({ protocol: prot, address: system.inet_addr, port: standard_service_port[prot] });
}
print();
if(!bbs.service.length)
bbs.service.push({ protocol: 'telnet', address: system.inet_addr, port: standard_service_port['telnet'] });
return bbs;
}
function getstr(prmpt, maxlen, mode)
{
if(!js.global.console)
return prompt(prmpt);
printf("\1n\1y\1h%s\1w: ", prmpt);
return console.getstr(maxlen, mode !==undefined ? (mode|K_TRIM) : (K_LINE|K_TRIM));
}
function get_description()
{
var description = [];
while(description.length < sbl_defs.DESC_LINES
&& (str=getstr("Description [line " + (description.length + 1) + " of " + sbl_defs.DESC_LINES + "]"
, sbl_defs.DESC_LINE_LEN, description.length < sbl_defs.DESC_LINES -1 ? K_WRAP : 0))) {
description.push(str);
}
return description;
}
// Return true if there's a message for the user to read
function add_entry(list)
{
console.clear();
if(options.add_ars && !user.compare_ars(options.add_ars)) {
console_beep();
alert("Sorry, you cannot do that");
return true;
}
console.attributes = WHITE;
print("Adding a BBS to the BBS List");
console.attributes = CYAN;
print("~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
console.attributes = LIGHTCYAN;
print("Required fields:");
console.attributes = CYAN;
print("\t- BBS Name");
print("\t- Terminal Server Host Name");
print("\t- Description");
var bbs_name = getstr("BBS Name", lib.max_len.name);
if(!bbs_name)
return false;
if(lib.system_exists(list, bbs_name)) {
alert("System '" + bbs_name + "' already exists");
return true;
}
var bbs = lib.new_system(bbs_name, /* nodes: */1);
bbs.sysop.push({ name: user.alias, email: user.email });
bbs.location = user.location;
bbs.software = getstr("BBS Software", lib.max_len.software);
bbs.web_site = getstr("Web-Site (address/URL)", lib.max_len.web_site);
bbs.terminal.types.push("TTY", "ANSI");
// Automatically test ports here?
var host_name = getstr("Terminal Server Host Name or IP Address", lib.max_len.service_address);
if(typeof host_name !== 'string' || host_name.length < 3) {
alert("You must provide a valid terminal server address");
return true;
}
bbs.service.push({ protocol: 'telnet', address: host_name, port: standard_service_port['telnet'] });
bbs.description = get_description();
if(!bbs.description.length) {
alert("You need to provide a description");
return true;
}
bbs.first_online = new Date().toISOString();
if(!edit(bbs)) {
alert("Edit aborted");
return true;
}
lib.add_system(list, bbs, user.alias);
lib.append(bbs);
print("System added successfully");
return true;
}
function list_page_of_bbs_entries(list, top, pagesize, current_idx, sort)
{
var num_entries_written = 0;
for(var i = top; i-top < pagesize; ++i)
{
console.line_counter = 0;
if (list[i])
{