1 # ===================================================================== 2 # showStatic.awk: RPC I/O function for rpclib/showStatic. 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,a) { 26 27 if (mode == _O_REQUEST) { # request. 28 29 # target group 30 value = _request("1",1) 31 32 # group must not be null and it may not contain the 33 # unescaped ``.'' character. 34 35 if (value != _NULL && value !~ /\./) { 36 _rcset("cgi.group",unixify(value)) 37 _rcset("cgi.group.literal",value) 38 } 39 40 # special page name corresponding to the desired view. 41 value = _request("2",1) 42 43 # special page names must begin with 'tw-'. 44 45 if (value ~ /^tw-[a-z][-a-z0-9]+-recent-(pages|headlines)$/) { 46 # extract subcat from cgi.tw.page if cgi.subcat is empty (this 47 # is necessary to have the "Print" action do the right thing). 48 sub(/^tw-/,"",value) 49 if (sub(/-recent-pages$/,"",value)) 50 _rcset("cgi.tw.page","tw-recent-pages") 51 else if (sub(/-recent-headlines$/,"",value)) 52 _rcset("cgi.tw.page","tw-recent-headlines") 53 _rcset("cgi.subcat",value) 54 } 55 else if (value ~ /^tw-unwatch(-request)?$/) { 56 sub(/-request$/,_NULL,value) # backward-compatibility 57 _rcset("cgi.tw.page",value "-request") 58 if ((value=_strip(_request("5",1))) > 99) 59 _rcset("cgi.watch.node",value) 60 } 61 else if (value ~ /^tw-/) 62 _rcset("cgi.tw.page",unixify(value,1)) 63 64 # Output visual appearance. 65 if ((value=_request("3",1)) ~ /^(screen|print)$/) 66 _rcset("cgi.style",value) 67 68 # optional target page within group (required by some views). 69 value = _request("4",1) 70 71 # page name must be at least 2-character long. 72 if (length(value) > 1) { 73 _rcset("cgi.page.literal",value) 74 _rcset("cgi.page.uri",_uriencode(value)) 75 value = unixify(value,1) 76 _rcset("cgi.page",value) 77 78 # Extract page meta-category if available. This will override 79 # any subcat extracted from cgi.tw.page (see above). 80 if ((value=getcat(value)) != _NULL) _rcset("cgi.subcat",value) 81 } 82 83 # Optional OpenID registration data. 84 _rcset("cgi.sreg.email",\ 85 substr(_strip(_request("sreg_email",1),_O_CRUSH),1,256)) 86 87 # Try and turn full-name into "Last, First" format by applying some 88 # (questionable) heuristics. This is far from being bullet-proof 89 # (think of "Mr. Joseph Robert Smarr, Esq.") but, after all, the 90 # resulting stuff will end up in the registration form, where the 91 # user will be able to fix it to her likings. 92 93 value = substr(_strip(_request("sreg_fullname",1),_O_CRUSH),1,64) 94 95 if (value != _NULL) { 96 97 # I have verified that both myOpenID and Google return 98 # the fullname in the form "Last, First" (if available). 99 100 # Swap input if it contains no commas, assuming 101 # it is in the most usual form of "First Last". 102 103 if (value !~ /[^,]+,[^,]+/) { 104 sub(/ /,",",value) 105 if (split(value,a,",") > 1) 106 value = _strip(a[2],_O_MIDDLE) ", " _strip(a[1],_O_MIDDLE) 107 } 108 else { 109 if (split(value,a,",") > 1) 110 value = _strip(a[1],_O_MIDDLE) ", " _strip(a[2],_O_MIDDLE) 111 } 112 113 _rcset("cgi.sreg.fullname",value) 114 } 115 116 if (_isdate((value=substr(_strip(_request("sreg_dob",1),\ 117 _O_CRUSH),1,10)),_O_SHORT) == _TRUE) 118 _rcset("cgi.sreg.dob",_localdate(value)) 119 120 _rcset("cgi.sreg.gender",\ 121 substr(_strip(_request("sreg_gender",1),_O_CRUSH),1,1)) 122 _rcset("cgi.sreg.postcode",\ 123 substr(_strip(_request("sreg_postcode",1),_O_CRUSH),1,32)) 124 _rcset("cgi.sreg.language",\ 125 substr(_strip(_request("sreg_language",1),_O_CRUSH),1,5)) 126 _rcset("cgi.sreg.timezone",\ 127 substr(_strip(_request("sreg_timezone",1),_O_CRUSH),1,32)) 128 _rcset("cgi.sreg.nickname",\ 129 substr(_strip(_request("sreg_nickname",1),_O_CRUSH),1,32)) 130 131 _rcset("cgi.reg.openid",\ 132 substr(_strip(_request("openid",1),_O_CRUSH),1,512)) 133 134 # optional author name, if available, to be used in selected 135 # static views where auth:u_name and auth:u_sname may not 136 # be available. 137 138 if ((value=_request("twauthor",1)) != _NULL) { 139 gsub(/[\t\r\n<>]+/," ",value) 140 _rcset("cgi.author",substr(_strip(value,_O_MIDDLE),1,32)) 141 } 142 143 # The following test is necessary since the address could, 144 # at least in theory, have been set to any string by the 145 # remote user, due to how it is handled to cope with stunnel(8) 146 # and the lack of transproxy support in kernel 2.4.x. 147 148 if (_isipaddr(ENVIRON["REMOTE_ADDR"]) == _TRUE) 149 value = ENVIRON["REMOTE_ADDR"] 150 else value = "0.0.0.0" 151 152 _rcset("REMOTE_ADDR",value) 153 } 154 155 else { # response 156 157 # generic template conditionals. 158 159 ifsections() 160 161 # Set fixed page title for the specified view. 162 value = _rcget("cgi.tw.page",1) 163 _response("tpl.var.html.title",\ 164 _rcget("tbl_group.g_descr") ": " \ 165 _nlsmap(_NULL,value)) 166 167 # Remove surrounding commas from displayed value. 168 value = _rcget("tpl.var.tw.reg.auth",1) 169 sub(/^,+/,"",value); sub(/,+$/,"",value) 170 _response("tpl.var.tw.reg.auth",value) 171 } 172 } 173 174 # EOF