1 # =====================================================================
2 # sourceList.awk: RPC I/O function for rpclib/sourceList.
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 AFFERO General Public License as published
8 # by Affero, Inc.; version 1 dated March, 2002.
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 # AFFERO General Public License for more details.
14 #
15 # You should be able to access an on-line copy of the AFFERO General
16 # Public License through the same Web server that runs this program.
17 # If not, you can request a copy of the license by writing to Affero,
18 # Inc., 510 Third Street - Suite 225, San Francisco, CA 94107, USA.
19 #
20 # =====================================================================
21
22 # =====================================================================
23 # void _userproc(int mode)
24 # =====================================================================
25
26 function _userproc(mode, value,outfile,i,j,url,a,fmt) {
27
28 if (mode == _O_REQUEST) { # request.
29
30 # target group
31 value = _request("1",1)
32
33 # group must not be null and it may not contain the
34 # unescaped ``.'' character.
35
36 if (value != _NULL && value !~ /\./) {
37 _rcset("cgi.group",unixify(value))
38 _rcset("cgi.group.literal",value)
39 }
40
41 # The following test is necessary since the address could,
42 # at least in theory, have been set to any string by the
43 # remote user, due to how it is handled to cope with stunnel(8)
44 # and the lack of transproxy support in kernel 2.4.x.
45
46 if (_isipaddr(ENVIRON["REMOTE_ADDR"]) == _TRUE)
47 value = ENVIRON["REMOTE_ADDR"]
48 else value = "0.0.0.0"
49
50 _rcset("REMOTE_ADDR",value)
51 }
52
53 else { # response
54
55 outfile = _rcget("tpl.include.tw.page")
56 if (outfile !~ /^\/\.*[a-zA-Z0-9]/)
57 return(_sys("csaExit.fault 0041 outfile"))
58
59 # Set output format string.
60
61 fmt = readfmt("tw-system-sourcelist")
62 gsub(/%/,"%%",fmt) # turn plain '%' into '%%'.
63 gsub(/\\/,"\\\\&",fmt) # turn '\' into '\\'.
64 gsub(/[\n\r]+/,"",fmt) # just in case.
65
66 # this format string is currently not customizable.
67 if (!sub(//,"%s",fmt)) fmt = fmt ""
68 if (!sub(//,"%s",fmt)) fmt = fmt ""
69
70 # encode any extra markers.
71 gsub(//,"\\<tw:s/\\>",fmt)
72
73 fmt = fmt "\n"
74
75 url = ENVIRON["CSA_RPC_URI"] "/" \
76 ENVIRON["CSA_LANG"] "/" \
77 _rcget("tbl_group.g_uri") "/13/"
78
79 # read input table.
80
81 i=j=1
82 while (split(_TBLS[1,i++],a,"\t")) {
83
84 # k_source, src_num
85
86 printf(fmt,_xmlencode(url a[2]),_xmlencode(a[1])) > outfile
87
88 # Provide also a machine-readable format.
89 _wsresponse(1,j++,url a[2])
90 }
91
92 close(outfile)
93
94 # Set fixed page title for the specified view.
95 _response("tpl.var.html.title",\
96 _nlsmap(_NULL,"tw-group-sourcelist"))
97
98 # generic template conditionals.
99
100 ifsections()
101 }
102 }
103
104 # EOF