-
Notifications
You must be signed in to change notification settings - Fork 5
/
rfcmarkup.sh
executable file
·1359 lines (1198 loc) · 59.7 KB
/
rfcmarkup.sh
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
#!/usr/bin/env python
# -*- python -*-
#
# Add HTML markup and links to internet-drafts and RFCs
#
# -----------------------------------------------------------------
#
# Copyright 2002 Henrik Levkowetz
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# -----------------------------------------------------------------
#
# The current version of GPL is at http://www.gnu.org/licenses/gpl.txt
#
# -----------------------------------------------------------------
#
# The purpose of this program is to fetch a text document
# indicated by a URL, and add markup so that any references to
# interet-drafts or RFCs are changed into hyperlinks, for easier
# browsing.
#
# It is called as:
#
# .../cgi-bin/markup.cgi?url=http://www.ietf.org/internet-drafts/draft-something-or-other-00.txt
#
#
import cgi, os, sys, urllib, re, string, cgitb
"""
TODO:
* Handle IEN-nnnn references
* Refactor into
get_args()
markup_top()
markup_body()
markup_refs()
which in turn use
fix_urls()
fix_rfcs()
fix_drafts()
fix_refref()
fix_refdef()
...
"""
version = "1.96"
cgitb.enable()
args = {}
args["bisdraft"] = ""
args["dcmeta"] = ""
args["dcmetaprofile"] = ""
args["diffmenu"] = ""
args["doccolor"] = ""
args["docinfo"] = True
args["draft"] = ""
args["errata"] = ""
args["favicon"] = ""
args["iprmenu"] = ""
args["erratamenu"] = ""
args["nitsmenu"] = ""
args["obsolete"] = ""
args["overflow"] = ""
args["padding"] = ""
args["plaintext"] = ""
args["script"] = "rfcmarkup"
args["status"] = ""
args["title"] = "rfcmarkup.cgi"
args["tracker"] = ""
args["updated"] = ""
args["version"] = version
args["wgmenu"] = ""
args["emailmenu"] = ""
args["doc"] = ""
args["extrastyle"] = ""
args["htmllink"] = ""
args["style"] = """
<style type="text/css">
body {
margin: 0px 8px;
font-size: 1em;
}
h1, h2, h3, h4, h5, h6, .h1, .h2, .h3, .h4, .h5, .h6 {
font-weight: bold;
line-height: 0pt;
display: inline;
white-space: pre;
font-family: monospace;
font-size: 1em;
font-weight: bold;
}
pre {
font-size: 1em;
margin-top: 0px;
margin-bottom: 0px;
}
.pre {
white-space: pre;
font-family: monospace;
}
.header{
font-weight: bold;
}
.newpage {
page-break-before: always;
}
.invisible {
text-decoration: none;
color: white;
}
@media print {
body {
font-size: 10.5pt;
}
h1, h2, h3, h4, h5, h6 {
font-size: 10.5pt;
}
a:link, a:visited {
color: inherit;
text-decoration: none;
}
.noprint {
display: none;
}
}
@media screen {
.grey, .grey a:link, .grey a:visited {
color: #777;
}
.docinfo {
background-color: #EEE;
}
.top {
border-top: 7px solid #EEE;
}
.bgwhite { background-color: white; }
.bgred { background-color: #F44; }
.bggrey { background-color: #666; }
.bgbrown { background-color: #840; }
.bgorange { background-color: #FA0; }
.bgyellow { background-color: #EE0; }
.bgmagenta{ background-color: #F4F; }
.bgblue { background-color: #66F; }
.bgcyan { background-color: #4DD; }
.bggreen { background-color: #4F4; }
.legend { font-size: 90%; }
.cplate { font-size: 70%; border: solid grey 1px; }
}
</style>
<!--[if IE]>
<style>
body {
font-size: 13px;
margin: 10px 10px;
}
</style>
<![endif]-->
"""
status2style = {
"BEST CURRENT PRACTICE": "bgmagenta",
"DRAFT STANDARD": "bgcyan",
"EXPERIMENTAL": "bgyellow",
"HISTORIC": "bggrey",
"INFORMATIONAL": "bgorange",
"PROPOSED STANDARD": "bgblue",
"STANDARD": "bggreen",
}
usagetext = """
NAME
%(script)s - add HTML markup and links to internet-drafts and RFCs
SYNOPSIS
http://example.com/cgi-bin/%(script)s?url=http://example.org/document.txt
DESCRIPTION
This program is a cgi-bin script which adds html link markup on the
fly to IETF text-format documents - i.e. RFCs, drafts and other text
documents which contain references to RFCs and drafts.
The script is written in Python, so the http server on which you run
it must have Python installed. You can download Python
from http://www.python.org. The script has been verified to work with
Python 2.2 and later.
It may be called by either http POST or GET, and the relevant field
names which may be provided are as follows:
OPTIONS
rfc=number
Specify the number of an RFC to fetch and mark up.
draft=draft-name
Specify the name of an internet-draft to fetch and mark up
doc=rfcnum-or-draftname
%(script)s will guess which document is wanted based on the
name or number given
url=some-general-url
Specify an url to fetch and mark up. If the URL does not have a
scheme identifier, or if it has file: as its scheme identifier,
this opens a local file; otherwise it opens a socket to a
server somewhere on the network.
Either rfc, draft, doc or url must be provided.
Example:
http://www.levkowetz.com/ietf/%(script)s?rfc=3344
will return RFC 3344 with added link markup.
repository=repository-path
Specify a nonstandard repository to fetch documents from. By
default, RFCs or drafts are read from the repository at
http://www.ietf.org/. repository-path may be an url or a path
local to the server on which the script is running. The last
alternative is useful when running the script under a http server on
a local machine, when you also have an RFC and draft repository
on the same machine. This option assumes that there is one rfc/
directory and one internet-drafts/ directory under the given
repository path, whether it is an url or a local path.
Example:
http://localhost/cgi-bin/%(script)s?rfc=3344&repository=/usr/local/share/ietf
will fetch RFCs from /usr/local/share/ietf/rfc/ on the server on
which the script is running.
COPYRIGHT
Copyright 2002 Henrik Levkowetz
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should be able to retrieve a copy of the GNU General Public
License from http://www.gnu.org/licenses/gpl.txt; if not, write
to the Free Software Foundation, Inc., 59 Temple Place, Suite
330, Boston, MA 02111-1307 USA
MAINTAINER
%(script)s is maintained by Henrik Levkowetz, <[email protected]>.
The latest version of this script can be retrieved from
http://tools.ietf.org/tools/rfcmarkup.
""" % args
def prelude(static=False):
if int(args.get("header", "1")):
if os.environ.get("GATEWAY_INTERFACE","") and not static:
print "Content-type: text/html; charset=utf-8\nCache-Control: max-age=86400\n"
sys.stdout.write( """<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head %(dcmetaprofile)s>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="robots" content="%(robots)s" />
<meta name="creator" content="%(script)s version %(version)s" />
%(dcmeta)s
<link rel="icon" href="%(favicon)s" type="image/png" />
<link rel="shortcut icon" href="%(favicon)s" type="image/png" />
<title>%(title)s</title>
%(extrastyle)s
%(style)s
<script type="text/javascript"><!--
function addHeaderTags() {
var spans = document.getElementsByTagName("span");
for (var i=0; i < spans.length; i++) {
var elem = spans[i];
if (elem) {
var level = elem.getAttribute("class");
if (level == "h1" || level == "h2" || level == "h3" || level == "h4" || level == "h5" || level == "h6") {
elem.innerHTML = "<"+level+">"+elem.innerHTML+"</"+level+">";
}
}
}
}
var legend_html = "Colour legend:<br /> \
<table> \
<tr><td>Unknown:</td> <td><span class='cplate bgwhite'> </span></td></tr> \
<tr><td>Draft:</td> <td><span class='cplate bgred'> </span></td></tr> \
<tr><td>Informational:</td> <td><span class='cplate bgorange'> </span></td></tr> \
<tr><td>Experimental:</td> <td><span class='cplate bgyellow'> </span></td></tr> \
<tr><td>Best Common Practice:</td><td><span class='cplate bgmagenta'> </span></td></tr> \
<tr><td>Proposed Standard:</td><td><span class='cplate bgblue'> </span></td></tr> \
<tr><td>Draft Standard:</td> <td><span class='cplate bgcyan'> </span></td></tr> \
<tr><td>Standard:</td> <td><span class='cplate bggreen'> </span></td></tr> \
<tr><td>Historic:</td> <td><span class='cplate bggrey'> </span></td></tr> \
<tr><td>Obsolete:</td> <td><span class='cplate bgbrown'> </span></td></tr> \
</table>";
function showElem(id) {
var elem = document.getElementById(id);
elem.innerHTML = eval(id+"_html");
elem.style.visibility='visible';
}
function hideElem(id) {
var elem = document.getElementById(id);
elem.style.visibility='hidden';
elem.innerHTML = "";
}
// -->
</script>
</head>
<body onload="addHeaderTags()">
<div style="height: 13px;">
<div onmouseover="this.style.cursor='pointer';"
onclick="showElem('legend');"
onmouseout="hideElem('legend')"
style="height: 6px; position: absolute;"
class="pre noprint docinfo %(doccolor)s"
title="Click for colour legend." > </div>
<div id="legend"
class="docinfo noprint pre legend"
style="position:absolute; top: 4px; left: 4ex; visibility:hidden; background-color: white; padding: 4px 9px 5px 7px; border: solid #345 1px; "
onmouseover="showElem('legend');"
onmouseout="hideElem('legend');">
</div>
</div>
""" % args)
else:
print """<html><body>
<!-- %(script)s version %(version)s -->
%(style)s
<pre>""" % args
topmenu = """<span class="pre noprint docinfo top">[<a href="../html/" title="Document search and retrieval page">Docs</a>] [<a href="%(plaintext)s" title="Plaintext version of this document">txt</a>|<a href="/pdf/%(doc)s" title="PDF version of this document">pdf</a>%(htmllink)s]%(draft)s%(tracker)s%(wgmenu)s%(emailmenu)s%(diffmenu)s%(nitsmenu)s%(iprmenu)s%(erratamenu)s%(padding)s</span><br />"""
#wgmenu = """ [<a href="../wg/%(wg)s" title="The working group handling this
#document">WG</a>] [<a href="../wg/%(wg)s/%(base)s" title="The WG docment page for this document">Doc Info</a>]"""
wgmenu = """ [<a href="../wg/%(wg)s" title="The working group handling this document">WG</a>]"""
emailmenu = """ [<a href="mailto:%(base)[email protected]?subject=%(base)s%%20" title="Send email to the document authors">Email</a>]"""
diffmenu = """ [<a href="/rfcdiff?difftype=--hwdiff&url2=%(doc)s" title="Inline diff (wdiff)">Diff1</a>] [<a href="/rfcdiff?url2=%(doc)s" title="Side-by-side diff">Diff2</a>]"""
nitsmenu = """ [<a href="/idnits?url=http://tools.ietf.org/id/%(doc)s" title="Run an idnits check of this document">Nits</a>]"""
draftiprmenu = """ [<a href="https://datatracker.ietf.org/ipr/search/?option=document_search&document_search=%(base)s" title="IPR disclosures related to this document">IPR</a>]"""
rfciprmenu = """ [<a href="https://datatracker.ietf.org/ipr/search/?option=rfc_search&rfc_search=%(rfc)s" title="IPR disclosures related to this document">IPR</a>]"""
htmllink = """|<a href="/id/%(draftname)s.html" title="HTML version of this document, from XML2RFC">html</a>"""
docinfo = """
<span class="pre noprint docinfo"> </span><br />
<span class="pre noprint docinfo">%(obsolete)-51s%(status)21s</span><br />
<span class="pre noprint docinfo">%(updated)-60s%(errata)12s</span><br />
<pre>
"""
nomenu = """<pre>
"""
statuslen = len("BEST CURRENT PRACTICE") # 21
erratalen = len("Errata Exist") # 12
def postlude():
if int(args.get("blurb", "1")):
print """</pre><br />
<span class="noprint"><small><small>Html markup produced by rfcmarkup %(version)s, available from
<a href="http://tools.ietf.org/tools/rfcmarkup/">http://tools.ietf.org/tools/rfcmarkup/</a>
</small></small></span>
</body></html>""" % args
else:
print "</pre></body></html>"
def version():
prelude()
print "%(script)s version %(version)s" % args
postlude()
def usage():
print usagetext
def markup():
global args
# sys.stderr = sys.stdout
extra = ""
bcp = None
std = None
rfc = None
wgname = None
draftname = None
charter = None
info = {}
attribs = {}
fields = cgi.FieldStorage()
for key in fields.keys():
attribs[key] = fields[key].value
script = os.environ.get("SCRIPT_NAME", sys.argv[0])
if fields.has_key("info"):
info = fields["info"].value
if (info=="usage"):
usage()
if (info=="version"):
version()
return
if fields.has_key("--info"):
info = fields["--info"].value
if (info=="usage"):
print usagetext
if (info=="version"):
print "%(script)s version %(version)s" % args
return
if fields.has_key("repository"):
rfcs = fields["repository"].value + "/rfc"
ids = fields["repository"].value + "/internet-drafts"
extra = extra + "repository=%s&" % fields["repository"].value
else:
if os.path.exists("/home/ietf/rfc"):
rfcs = "file:///home/ietf/rfc"
else:
rfcs = "http://tools.ietf.org/rfc"
if os.path.exists("/home/ietf/id"):
ids = "file:///home/ietf/id"
else:
ids = "http://tools.ietf.org/id"
if fields.has_key("rfc-repository"):
rfcs = fields["rfc-repository"].value
extra = extra + "rfc-repository=%s&" % fields["rfc-repository"].value
if fields.has_key("id-repository"):
ids = fields["id-repository"].value
extra = extra + "id-repository=%s&" % fields["id-repository"].value
if fields.has_key("header"):
args["header"] = fields["header"].value
if fields.has_key("blurb"):
args["blurb"] = fields["blurb"].value
if fields.has_key("style"):
args["style"] = fields["style"].value
if fields.has_key("docinfo"):
args["docinfo"] = eval(fields["docinfo"].value)
if fields.has_key("robots"):
args["robots"] = fields["robots"].value
else:
args["robots"] = "index,nofollow"
if fields.has_key("staticpath"):
optstatic = fields["staticpath"].value == "true"
args["robots"] = "index,follow"
else:
optstatic = False
if fields.has_key("topmenu"):
optmenu = fields["topmenu"].value == "true"
#extra = extra + "topmenu=%s&" % fields["topmenu"].value
else:
optmenu = False
if fields.has_key("lineoffset"):
optlineoffs = int(fields["lineoffset"].value)
#extra = extra + "topmenu=%s&" % fields["topmenu"].value
else:
optlineoffs = 0
# Handle document information.
if fields.has_key("draft"):
url = "%s/%s" % (ids, fields["draft"].value)
args["title"] = fields["draft"].value[6:].split(".")[0]
# if not url[-4:] == ".txt":
# url = url + ".txt"
elif fields.has_key("rfc"):
rfc = fields["rfc"].value
url = "%s/rfc%s.txt" % (rfcs, rfc)
args["title"] = "rfc "+fields["rfc"].value
args["doc"] = "rfc"+rfc
elif fields.has_key("bcp"):
bcp = fields["bcp"].value
url = "%s/bcp/bcp%s.txt" % (rfcs, bcp)
args["title"] = "bcp "+fields["bcp"].value
args["doc"] = "bcp"+bcp
elif fields.has_key("fyi"):
fyi = fields["fyi"].value
url = "%s/fyi/fyi%s.txt" % (rfcs, fyi)
args["title"] = "fyi "+fields["fyi"].value
args["doc"] = "fyi"+fyi
elif fields.has_key("std"):
std = fields["std"].value
url = "%s/std/std%s.txt" % (rfcs, std)
args["title"] = "std "+fields["std"].value
args["doc"] = "std"+std
elif fields.has_key("url"):
url = fields["url"].value
if not re.match("^(http|https|ftp|file)", url):
url = "http://%s%s/%s" %( os.environ.get("SERVER_NAME", "ietf.levkowetz.com"), os.path.dirname(script), url)
args["title"] = os.path.basename(fields["url"].value)
elif fields.has_key("doc") or os.environ.get("PATH_INFO", "/") != "/":
if fields.has_key("doc"):
doc = fields["doc"].value
else:
doc = os.environ.get("PATH_INFO", "/")[1:]
# Remove extension
if doc.rfind(".") > 0:
doc = doc[:doc.rfind(".")]
if re.match("^[0-9]+$", doc):
rfc = doc
url = "file:///home/ietf/rfc/rfc%s.txt" % doc
title = "RFC " + rfc
args["doc"] = "rfc"+rfc
elif re.match("rfc[0-9]+$", doc):
rfc = doc[3:]
url = "%s/%s.txt" % (rfcs, doc)
title = "RFC " + rfc
args["doc"] = "rfc"+rfc
elif re.match("^bcp[0-9]+$", doc):
url = "%s/bcp/%s.txt" % (rfcs, doc)
title = "BCP " + doc[3:]
args["doc"] = "bcp"+doc[3:]
elif re.match("^fyi[0-9]+$", doc):
url = "%s/fyi/%s.txt" % (rfcs, doc)
title = "FYI " + doc[3:]
args["doc"] = "fyi"+doc[3:]
elif re.match("^std[0-9]+$", doc):
url = "%s/std/%s.txt" % (rfcs, doc)
title = "STD " + doc[3:]
args["doc"] = "std"+doc[3:]
elif re.match("^ion-.+$", doc):
url = "file:///home/ietf/ion/approved/%s.txt" % doc
title = "ION: " + doc
args["doc"] = doc
elif re.match("^charter-.+$", doc):
url = "file:///www/tools.ietf.org/charter/%s.txt" % doc
title = doc.split(".")[0]
args["doc"] = doc
charter = doc
elif re.match("draft-[0-9a-z.*-]+$", doc):
if not re.match(".*\..+", doc):
doc = doc + ".txt"
url = "http://tools.ietf.org/id/%s" % doc
title = doc.split(".")[0]
draftparts = re.match("draft-([0-9a-z]+)-(krb-wg|[0-9a-z]+)-([0-9a-z.*-]+)$", doc)
if draftparts and draftparts.group(1) == "ietf":
wgname = draftparts.group(2)
args["wg"] = wgname
args["base"] = os.path.splitext(doc)[0][:-3]
draftname = doc
args["doc"] = doc
else:
url = "your document ('%s')." % doc
title = ""
args["title"] = title
elif script == "rfcmarkup":
usage()
#print "<pre>"
#print fields
#print os.environ
#print "</pre>"
return
else:
prelude()
print """</pre>
<p>
<big><b>Add HTML markup to a document:</b></big>
</p>
<p>
Please provide a document number, draft name or URL:
</p>
<p>
<form action="%s">
<table>
<tr><td>RFC (number only): </td><td><input type="text" name="rfc" /></td></tr>
<tr><td>Draft: (name starting with <tt>draft-</tt>): </td><td><input type="text" name="draft" /></td></tr>
<tr><td>URL (any text document available through http or ftp): </td><td><input type="text" name="url" /></td></tr>
<tr><td> </td><td><input type="Submit" value="Submit"/></td></tr>
</table>
</form>
</p>
</body>
</html>
""" % script
return
if fields.has_key("title"):
args["title"] = fields["title"].value
if fields.has_key("extrastyle"):
args["extrastyle"] = "<style>"+fields["extrastyle"].value+"</style>"
tags = []
if fields.has_key("comments"):
if type(fields["comments"]) is type([]):
for item in fields["comments"]: tags.append(item.value)
else:
tags.append(fields["comments"].value)
colors = []
if fields.has_key("color"):
if type(fields["color"]) is type([]):
for item in fields["color"]: colors.append(item.value)
else:
colors.append(untaint(fields["color"].value))
else:
colors = ["#F00", "#0A0", "#00C", "#880", "#088", "#808", ]
if url.startswith("file:///home/ietf/"):
start = len("file:///home/ietf/") -1
args["plaintext"] = url[start:]
else:
args["plaintext"] = url
# Get the raw text of the source page
try:
f = urllib.urlopen(url)
data = f.read()
f.close()
except:
prelude();
print "<h3> Sorry, couldn't find %s</h3>" % os.path.basename(url)
sys.exit(0)
def filetext(path):
if os.path.isfile(path):
file = open(path)
text = file.read()
file.close()
return text.strip()
else:
return ""
def listdir(path, pattern):
dirlist = os.listdir(path)
files = [ x for x in dirlist if re.match(pattern, x) ]
files.sort()
return files
def stateinfo(fullname):
name = fullname
if name.endswith(".txt"):
name = name[:-4]
if re.search("-[0-9][0-9]$", name):
name = name[:-3]
info = filetext("/www/tools.ietf.org/draft/%s/now" % (name))
attribs = {}
if info:
first, rest = info.split(None, 1)
if first.startswith("19") or first.startswith("20"):
attribs["timestamp"] = first
first, rest = rest.split(None, 1)
if first.startswith("draft-"):
attribs["document"] = first
attriblist = re.findall("([A-Za-z]+='[^']+')", info)
for attrib in attriblist:
try:
attr, value = attrib.split("=")
value = value[1:-1]
if ";" in value:
value = value.rsplit(";", 1)[0]
value = eval("'"+value+"'")
attribs[attr] = value
except:
pass
else:
try:
import idauthors
if not fullname.endswith(".txt"):
fullname = fullname + ".txt"
attribs = idauthors.getmeta(fullname) or {}
except Exception:
pass
return attribs
def setdcmeta(attribs, args):
metatext = '<link rel="schema.DC" href="http://purl.org/dc/elements/1.1/" />\n'
metaval = {}
metatags = [
("doctitle", "DC.Title"),
("docauthors", "DC.Creator"),
("docsubmitted", "DC.Date.Issued"),
("docpublished", "DC.Date.Issued"), # overrides submission date
("docabstract", "DC.Description.Abstract"),
("document", "DC.Identifier"),
("docrfcnum", "DC.Identifier"), # overides draft id
("docreplaces", "DC.Relation.Replaces"),
("docobsoletes", "DC.Relation.Replaces"), # overrides draft replacement
]
listtags = ["DC.Creator", "DC.Relation.Replaces", ]
for key, tag in metatags:
if key in attribs:
if key == "document":
val = "urn:ietf:id:%s" % attribs[key][6:]
elif key == "docrfcnum":
val = "urn:ietf:rfc:%s" % attribs[key]
else:
val = attribs[key] or ""
metaval[tag] = cgi.escape(val)
for tag, val in metaval.items():
val = val.replace(r"\\n", " ")
if tag in listtags and "," in val:
items = val.split(",")
if tag == "DC.Creator":
for i in range(len(items)):
item = items[i]
parts = item.split()
if parts:
if "@" in parts[-1]:
parts = parts[:-1]
items[i] = " ".join(parts)
items = list(set(items))
for item in items:
parts = item.split()
if parts:
# emit with family name first, then comma and given name or initials
metatext += '<meta name="%s" content="%s, %s" />\n' % (tag, parts[-1], " ".join(parts[:-1]))
else:
for item in items:
metatext += '<meta name="%s" content="%s" />\n' % (tag, item.strip())
else:
metatext += '<meta name="%s" content="%s" />\n' % (tag, val)
args["dcmeta"] = metatext
args["dcmetaprofile"] = 'profile="http://dublincore.org/documents/2008/08/04/dc-html/"'
return args
# Helper function to generate left-side metainformation (list of RFCs)
def leftmeta(docname, tag, prefix, rightlen):
line = ""
info = filetext("/home/ietf/rfc/meta/%s.%s" % (docname, tag))
if info:
line = prefix
leftlen = len(prefix)
rfclen = len(" 0000,")
count = 0
maxcount = (72 - leftlen - max(rightlen,erratalen,statuslen))/rfclen
for rfc in info.split():
rfcnum = rfc[3:]
if count:
line = line + ","
if (count % maxcount) == 0:
line = line + " "*(72-leftlen-rfclen*maxcount) + "\n" + " "*leftlen
count += 1
if optstatic:
line = line + """ <a href=\"./rfc%s\">%s</a>""" % (rfcnum, rfcnum)
else:
line = line + """ <a href=\"%s/%s\">%s</a>""" % (script, rfcnum, rfcnum)
line = line + " "*(72-leftlen-rightlen-((count-1)%maxcount+1)*rfclen+1) # +1 for the missing comma after the last rfcnum
return line, info
def chartermeta(charter, prefix, rightlen, attribs):
name = re.sub("-[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9](\.txt)?$", "", charter)
line = ""
files = listdir("/www/tools.ietf.org/charter/", name+"-[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]\.txt$")
versions = [ file[-14:-4] for file in files ]
if versions:
line = line + prefix
leftlen = len(prefix)
verlen = len(" 2000-01-01")
count = 0
nextdoclen = 0
maxcount = (72 - leftlen - rightlen)/verlen
for ver in versions:
if count:
#line = line + ","
if (count % maxcount) == 0:
line = line + " "*(72-leftlen-verlen*maxcount) + "\n" + " "*leftlen
count += 1
if optstatic:
line = line + """ <a href=\"./%s-%s\">%s</a>""" % (name, ver, ver)
else:
line = line + """ <a href=\"%s/%s-%s\">%s</a>""" % (script, name, ver, ver)
line = line + " "*(50-leftlen-rightlen-nextdoclen-(count%maxcount)*verlen+1) # +1 for the missing comma after the last rfcnum
return line
def draftmeta(draftname, prefix, rightlen, attribs):
name = draftname[:-3]
rev = draftname[-2:]
line = ""
rfc = filetext("/home/ietf/rfc/meta/%s.rfcnum" % (name,))
versions = filetext("/www/tools.ietf.org/draft/%s/versions" % (name,))
if versions:
if not rev in versions:
versions += " " + rev
attribs["docversions"] = ", ".join(versions.split())
line = line + prefix
leftlen = len(prefix)
verlen = len(" 00")
count = 0
nextdoclen = 0
maxcount = (47 - leftlen - rightlen)/verlen
prev = None
if "docreplaces" in attribs:
prev = attribs["docreplaces"]
pname = prev
else:
match = re.match(".*-((rfc)?[0-9][0-9][0-9]+)bis(-.*|$)", name)
if match:
prev = match.group(1)
pname = prev
if pname.startswith("rfc"):
pname = pname[3:]
pname = "RFC " + pname
if prev:
if optstatic:
line = line + """ (<a href="./%s" title="Precursor">%s</a>)""" % (prev, pname)
else:
line = line + """ (<a href="%s/%s" title="Precursor">%s</a>)""" % (script, prev, pname)
prevlen = len(" (%s)" % pname)
count = (prevlen + verlen-1) // verlen
line = line + " " * (count*verlen - prevlen)
if count >= maxcount:
line = line + " "*(72-leftlen-verlen*count) + "\n" + " "*leftlen
count = 0
for ver in versions.split():
if count:
#line = line + ","
if (count % maxcount) == 0:
line = line + " "*(72-leftlen-verlen*maxcount) + "\n" + " "*leftlen
count += 1
if optstatic:
line = line + """ <a href=\"./%s-%s\">%s</a>""" % (name, ver, ver)
else:
line = line + """ <a href=\"%s/%s-%s\">%s</a>""" % (script, name, ver, ver)
if rfc:
rfcnum = rfc[3:]
if int(rfcnum) > 0:
if (count % maxcount) == 0:
line = line + " "*(72-leftlen-verlen*maxcount) + "\n" + " "*leftlen
nextdoclen = len(" RFC 0000")
if optstatic:
line = line + """ <a href=\"./rfc%s\">RFC %4s</a>""" % (rfcnum, rfcnum)
else:
line = line + """ <a href=\"%s/%s\">RFC %4s</a>""" % (script, rfcnum, rfcnum)
elif "docreplacement" in attribs:
replacement = attribs["docreplacement"]
if replacement and replacement != "0":
if (count % maxcount) == 0:
line = line + " "*(72-leftlen-verlen*maxcount) + "\n" + " "*leftlen
nextdoclen = len(replacement)+1
if optstatic:
line = line + """ <a href=\"./%s\" title="%s replaces this draft">%s</a>""" % (replacement, replacement, replacement)
else:
line = line + """ <a href=\"%s/%s\" title="%s replaces this draft">%s</a>""" % (script, replacement, replacement, replacement)
line = line + " "*(50-leftlen-rightlen-nextdoclen-(count%maxcount)*verlen+1) # +1 for the missing comma after the last rfcnum
return line
if draftname:
attribs.update(stateinfo(draftname))
args["favicon"] = "/images/id.png"
draftname = draftname.split(".")[0]
args["obsolete"] = draftmeta(draftname, "Versions:", 0, attribs)
args["doccolor"] = "bgred"
args["tracker"] = " [<a href='https://datatracker.ietf.org/doc/%s' title='IESG Datatracker information for this document'>Tracker</a>]" % (draftname[:-3])
elif charter and optmenu:
args["obsolete"] = chartermeta(charter, "Versions:", 0, attribs)
elif rfc:
attribs.update(stateinfo("rfc%s" % (rfc)))
args["favicon"] = "/images/rfc.png"
if filetext("/home/ietf/rfc/meta/rfc%s.errata" % rfc):
# Errata URL changes around 18 Oct 2007
# args["errata"] = """<a href="http://www.rfc-editor.org/cgi-bin/errataSearch.pl?rfc=%s">Errata</a>""" % rfc
args["errata"] = "<span style='color: #C00;'>Errata Exist</span>"
args["erratamenu"] = """ [<a href="http://www.rfc-editor.org/errata_search.php?rfc=%s">Errata</a>]""" % rfc
args["status"] = filetext("/home/ietf/rfc/meta/rfc%s.status" % rfc)
args["obsolete"], info = leftmeta("rfc%s"%rfc, "obsolete", "Obsoleted by:", statuslen)
args["updated"], info = leftmeta("rfc%s"%rfc, "updated", "Updated by:", erratalen)
if args["obsolete"]:
args["doccolor"] = "bgbrown"
else:
if args["status"] in status2style:
args["doccolor"] = status2style[args["status"]]
else:
args["doccolor"] = "bgwhite"
# If there is no obsolete field, use that for Updated
# Assumption: the obsoleted by list never has more than 6 rfcs,
# but the updated by list may have more.
if len(args["updated"]) and not len(args["obsolete"]):
leftlen = len("Updated by:")
rightlen = statuslen
rfclen = len(" 0000,")
maxcount = (72 - leftlen - max(rightlen,erratalen,statuslen))/rfclen
count = min(maxcount, len(info.split()))
updated = args["updated"].split("\n", 1)
args["obsolete"] = updated[0]
if updated[1:]:
args["updated"] = updated[1]
else:
args["updated"] = ""
# Add padding to make the line 72 spaces wide when rendered
if len(info.split()) > maxcount:
args["obsolete"] = args["obsolete"].strip() + " " * (72-leftlen-rightlen-count*rfclen)
else:
args["obsolete"] = args["obsolete"].strip() + " " * (72-leftlen-rightlen-count*rfclen+1) # +1 for the missing comma after the last rfcnum
draft = filetext("/home/ietf/rfc/meta/rfc%s.draft" % rfc)
if draft:
short = draft
draftmaxlen = 29
if "errata" in args:
draftmaxlen -= len(" [Errata]")
if len(draft) > draftmaxlen:
short = draft[:draftmaxlen-3] + "..."
if optstatic:
args["draft"] = (""" [<a href="%s" title="%s">%s</a>]""") % (draft, draft, short)
else:
args["draft"] = (""" [<a href="%s?%sdoc=%s" title="%s">%s</a>]""") % (script, optmenu and "topmenu=true&" or "",draft, draft, short)
elif bcp:
args["doccolor"] = "bgmagenta"
elif std:
args["doccolor"] = "bggreen"
args = setdcmeta(attribs, args)
if f.info().gettype() == "text/html":
print "Location: %s\n" % url
# print f.info()
# print data
return
# ------------------------------------------------------------------------
# Start of markup handling
# Convert \r which is not followed or preceded by a \n to \n
# (in case this is a mac document)
data = re.sub("([^\n])\r([^\n])", "\g<1>\n\g<2>", data)
# Strip \r (in case this is a ms format document):
data = string.replace(data,"\r","")
# -------------
# Normalization
# Remove whitespace at the end of lines
data = re.sub("[\t ]+\n", "\n", data)
data = data.expandtabs()
# Remove extra blank lines at the start of the document
data = re.sub("^\n*", "", data, 1)
# Fix up page breaks:
# \f should aways be preceeded and followed by \n
data = re.sub("([^\n])\f", "\g<1>\n\f", data)
data = re.sub("\f([^\n])", "\f\n\g<1>", data)
# [Page nn] should be followed by \n\f\n
data = re.sub("(?i)(\[Page [0-9ivxlc]+\])[\n\f\t ]*(\n *[^\n\f\t ])", "\g<1>\n\f\g<2>", data)
# Normalize indentation
linestarts = re.findall("(?m)^([ ]*)\S", data);
prefixlen = 72
for start in linestarts:
if len(start) < prefixlen:
prefixlen = len(start)