1 # ===================================================================== 2 # cmtView.awk: RPC I/O function for rpclib/cmtView. 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,tmp) { 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 # target page within group. 41 value = _request("2",1) 42 43 # page name must be at least 2-character long. 44 if (length(value) > 1) { 45 gsub(/[ \t\n\r]/," ",value) # neutralize real junk. 46 _rcset("cgi.page.literal",value) 47 value = unixify(value,1) 48 _rcset("cgi.page",value) 49 } 50 51 # Mandatory parent post. 52 if ((value=_request("3",1)) ~ /^[1-9][-.a-zA-Z0-9]+$/) 53 _rcset("cgi.cmt.parent",value) 54 55 # Page visual appearance. 56 if ((value=_request("4",1)) ~ /^(screen|print)$/) 57 _rcset("cgi.style",value) 58 59 # optional author name. 60 if ((value=_request("twauthor",1)) != _NULL) { 61 sub(/[\t\r\n<>]+/," ",value) 62 _rcset("cgi.author",substr(_strip(value,_O_MIDDLE),1,32)) 63 } 64 65 # Paging block no. if any. 66 _rcset("cgi.paging",_request("5",1)/1) 67 68 # Generate the new comment key stem here. 69 value = ENVIRON["CSA_TIME_ISO"] 70 gsub(/[^0-9]/,"",value) 71 _rcset("cgi.cmt.new",value "-" ENVIRON["CSA_PID"]) 72 73 # The following test is necessary since the address could, 74 # at least in theory, have been set to any string by the 75 # remote user, due to how it is handled to cope with stunnel(8) 76 # and the lack of transproxy support in kernel 2.4.x. 77 78 if (_isipaddr(ENVIRON["REMOTE_ADDR"]) == _TRUE) 79 value = ENVIRON["REMOTE_ADDR"] 80 else value = "0.0.0.0" 81 82 _rcset("REMOTE_ADDR",value) 83 } 84 85 else { # response 86 87 _response("tpl.var.nls.1",\ 88 _nlsmap(_NULL,_rcget("tpl.var.nls.1",1),"cmtView")) 89 _response("tpl.var.tw.cmt.parent.date",\ 90 _localdate(_rcget("tpl.var.tw.cmt.parent.date",1))) 91 92 if (_rcget("tbl_pcmt.c_banned",1) != _NULL) { 93 tmp = ENVIRON["TNS_BANNED_SUBJECT"] 94 if (tmp == _NULL) tmp = _nlsmap(_NULL,"banned","cmtView") 95 # this is expected to be already XML-encoded, hence noenc. 96 _response("tpl.var.tw.cmt.parent.subject",tmp,0,0,_O_NOENC) 97 } 98 99 # Perform usual XML-encoding of subject. 100 else _response("tpl.var.tw.cmt.parent.subject",\ 101 _rcget("tpl.var.tw.cmt.parent.subject",1)) 102 103 # Default page title to page name and set page subcat name if any. 104 105 value = tmp = _rcget("tpl.var.tw.page",1) 106 107 if ((tmp=getcat(tmp)) != _NULL) { 108 _response("tpl.var.tw.page.subcat",tmp) 109 sub(/[^.]+\./,_NULL,value) 110 _html("show","tpl.if.tw.subcat","tpl.fi.tw.subcat") 111 } else _html("hide","tpl.if.tw.subcat","tpl.fi.tw.subcat") 112 113 # Make sure every page has a unique title, whatever it be. 114 value = value " (" _rcget("tbl_pcmt.k_node",1) ")" 115 _response("tpl.var.html.title",value) 116 117 value = _rcget("tbl_pcmt.c_auweb",1) 118 if (_isuri(value,1) == _TRUE) 119 _response("tpl.var.tw.cmt.parent.author",\ 120 extLink("" \ 121 _xmlencode(_rcget("tbl_pcmt.c_creau")) "")) 122 else _response("tpl.var.tw.cmt.parent.author",\ 123 _xmlencode(_rcget("tbl_pcmt.c_creau"))) 124 125 # generic template conditionals. 126 127 ifsections() 128 } 129 } 130 131 # EOF