1 # ===================================================================== 2 # pingbackServer.awk: RPC I/O function for rpclib/pingbackServer. 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,a,i,j,re) { 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 47 value = unixify(value,1) 48 _rcset("cgi.page",value) 49 } 50 51 # Target URL, i.e. the local URL being pinged. 52 _rcset("cgi.grep.pattern",tbpattern(_request("2_1",1))) 53 54 # Compute the local URL initial part which may be needed by 55 # the underlying rc(1) script to load a local page. 56 57 tmp = ENVIRON["CSA_RPC_URI"] 58 sub(/:\/\/.*/,"",tmp) 59 tmp = tmp "://" ENVIRON["CSA_FQDN"] 60 if (ENVIRON["SERVER_PORT"] != "80") 61 tmp = tmp ":" ENVIRON["SERVER_PORT"] 62 63 _rcset("cgi.localurl.stub",tmp) 64 65 # Actual trackback data. 66 67 # mandatory originating URL. 68 if ((value=_request("1_1",1)) != _NULL && \ 69 value ~ /^https?:\/\/.+/ && length(value) < 256 && \ 70 value !~ /[ \t\r\n<>]/) { 71 72 re = _escreg(ENVIRON["CSA_RPC_URI"]) 73 sub(/http:/,"https?:",re) 74 75 # Make the leading "http://host" part optional in 76 # local URL pattern. 77 78 sub(/^/,"^(",re) 79 sub(/[^\/:]\//,"&\001",re) 80 sub(/\/\001/,")?/",re) 81 82 tmp = ENVIRON["CSA_RPC_URI"] 83 sub(/[^\/:]\//,"\001",tmp) 84 sub(/.*\001/,"/",tmp) 85 86 _rcset("cgi.pb.url.stem",tmp) 87 _rcset("cgi.pb.url",value) 88 89 # Now compute hash value of pinging URL 90 if (value ~ /^\/./) value = tmp value 91 if (value ~ /%/) value = _uridecode(value) 92 value = tolower(value) 93 gsub(/[^-_:a-z0-9]/,_NULL,value) 94 _rcset("cgi.pb.hash",value) 95 } 96 else _rcset("cgi.pb.url","-") # invalid source URL. 97 98 # The following test is necessary since the address could, 99 # at least in theory, have been set to any string by the 100 # remote user, due to how it is handled to cope with stunnel(8) 101 # and the lack of transproxy support in kernel 2.4.x. 102 103 if (_isipaddr(ENVIRON["REMOTE_ADDR"]) == _TRUE) 104 value = ENVIRON["REMOTE_ADDR"] 105 else value = "0.0.0.0" 106 107 _rcset("REMOTE_ADDR",value) 108 } 109 } 110 111 # EOF