1 # =====================================================================
2 # pageHistory.awk: RPC I/O function for rpclib/pageHistory.
3 #
4 # Copyright (c) 2007,2008,2009,2010 Carlo Strozzi
5 #
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; version 2 dated June, 1991.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 #
19 # =====================================================================
20
21 # =====================================================================
22 # void _userproc(int mode)
23 # =====================================================================
24
25 function _userproc(mode, value,infile,outfile,v1,l1,\
26 v2,l2,i,a,tmp,fmt,url,\
27 selected1,selected2) {
28
29 if (mode == _O_REQUEST) { # request.
30
31 # target group
32 value = _request("1",1)
33
34 # group must not be null and it may not contain the
35 # unescaped ``.'' character.
36
37 if (value != _NULL && value !~ /\./) {
38 _rcset("cgi.group",unixify(value))
39 _rcset("cgi.group.literal",value)
40 }
41
42 # target page within group.
43 value = _request("2",1)
44
45 # page name must be at least 2-character long.
46 if (length(value) > 1) {
47 _rcset("cgi.page.literal",value)
48 value = unixify(value,1)
49 _rcset("cgi.page",value)
50 }
51
52 # Set revisions to be compared, if any.
53 if ((value=_request("3",1)) ~ /^[0-9][0-9.]+$/)
54 _rcset("cgi.revisions",value)
55 if ((value=_request("4",1)) ~ /^[0-9][0-9.]+$/)
56 _rcset("cgi.revisions",value,_NULL,_O_APPEND)
57
58 # The following test is necessary since the address could,
59 # at least in theory, have been set to any string by the
60 # remote user, due to how it is handled to cope with stunnel(8)
61 # and the lack of transproxy support in kernel 2.4.x.
62
63 if (_isipaddr(ENVIRON["REMOTE_ADDR"]) == _TRUE)
64 value = ENVIRON["REMOTE_ADDR"]
65 else value = "0.0.0.0"
66
67 _rcset("REMOTE_ADDR",value)
68 }
69
70 else { # response.
71
72 infile = _rcget("TNS_RCS_OUT")
73 if (infile !~ /^\/\.*[a-zA-Z0-9]/)
74 return(_sys("csaExit.fault 0041 infile"))
75
76 outfile = _rcget("tpl.include.tw.page")
77 if (outfile !~ /^\/\.*[a-zA-Z0-9]/)
78 return(_sys("csaExit.fault 0041 outfile"))
79
80 # Set output format string.
81
82 fmt = readfmt("tw-page-history")
83 gsub(/%/,"%%",fmt) # turn plain '%' into '%%'.
84 gsub(/\\/,"\\\\&",fmt) # turn '\' into '\\'.
85 gsub(/[\n\r]+/,"",fmt) # just in case.
86
87 # this format string is currently not customizable.
88 for (i=1; i<=5; i++) {
89 if (!sub(//,"%s",fmt)) fmt = fmt ""
90 }
91
92 # encode any extra markers.
93 gsub(//, "\\<tw:s/\\>",fmt)
94
95 fmt = fmt "\n"
96
97 url = ENVIRON["CSA_RPC_URI"] "/" \
98 ENVIRON["CSA_LANG"] "/" \
99 _rcget("cgi.group") "/" _rcget("cgi.page") "/history/"
100
101 # Read and parse the output of rlog(1).
102
103 v1[1] = _NULL
104 l1[1] = _xmlencode(_nlsmap(_NULL,"current","pageHistory"))
105
106 v2[1] = _NULL
107 l2[1] = _xmlencode(_nlsmap(_NULL,"current","pageHistory"))
108
109 i=0
110 while (getline value < infile > 0) {
111 if (value ~ /^revision [0-9.]+/) {
112 sub(/^revision +/,_NULL,value)
113 sub(/[ \t].*/,_NULL,value)
114 tmp = value
115 i++
116 }
117 if (!i) continue
118 else if (sub(/^date: */,_NULL,value)) {
119 if (_bool(ENVIRON["CSA_AUTH_OK"]) != _TRUE ||\
120 "," ENVIRON["TNS_AUTH_GRP"] "," !~ /,editor,/) {
121
122 # hide author login to non authenticated editors.
123 sub(/;[^;]+; */,";;",value)
124 }
125 else sub(/; *author: */,";",value)
126 sub(/ *state:[^;]+; */,_NULL,value)
127 sub(/ *lines: */,_NULL,value)
128 tmp = tmp ";" value
129 }
130 else if (value ~ /^[0-9]/) { # either rev no. or IP
131 # hide author IP address to non authenticated editors.
132 if (_bool(ENVIRON["CSA_AUTH_OK"]) != _TRUE ||\
133 "," ENVIRON["TNS_AUTH_GRP"] "," !~ /,editor,/) tmp = tmp ";"
134 else tmp = tmp ";" value
135 }
136 if (value ~ /^[-=]/) {
137
138 split(tmp,a,";")
139
140 gsub(/\//,"-",a[3])
141 sub(/\+[0-9]+$/,_NULL,a[3]) # Remove TZ if any.
142
143 if (a[4] == _NULL) a[4] = "-"
144 if (a[6] == _NULL) a[6] = "-"
145
146 v1[0] = v2[0] = i+1
147 v1[i+1] = v2[i+1] = a[1]
148 l1[i+1] = l2[i+1] = a[3]
149
150 if (a[1] == _rcget("cgi.revisions",1)) {
151 selected1 = a[1]
152 #_response("tpl.var.tw.page.rev.date1",a[3])
153 }
154
155 if (a[1] == _rcget("cgi.revisions",2)) {
156 selected2 = a[1]
157 #_response("tpl.var.tw.page.rev.date2",a[3])
158 }
159
160 _response("tpl.var.tw.page.rev1",\
161 _formselect(v1,l1,"3",selected1))
162 _response("tpl.var.tw.page.rev2",
163 _formselect(v2,l2,"4",selected2))
164
165 printf(fmt,url _uriencode(a[3]),_xmlencode(a[3]),\
166 _xmlencode(a[4]),a[5],a[6]) > outfile
167
168 _wsresponse(1,i,url _uriencode(a[3]))
169 _wsresponse(2,i,a[4])
170 _wsresponse(3,i,a[5])
171 _wsresponse(4,i,a[6])
172 }
173 }
174
175 close(outfile)
176
177 # generic template conditionals.
178
179 ifsections()
180 }
181 }
182
183 # EOF