1 # ===================================================================== 2 # watch.awk: RPC I/O function for rpclib/watch. 3 # 4 # Copyright (c) 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,i,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 # ID of the (single) object to be added to the watch-list. 41 # This must always be a node-ID, from which we get the actual 42 # item PK. 43 44 value = _strip(_request("2",1)) 45 46 if ((value /= 1) > 0) { 47 48 tmp = ENVIRON["CSA_ROOT"] "/var/nodes/" \ 49 substr(value,1,1) "/" substr(value,2,1) "/" \ 50 substr(value,3,1) "/" value 51 getline value < tmp; close(tmp) 52 53 if (split(value,a,/[\/ +]/) > 3 && a[4] ~ /^[1-9][0-9]+-/) { 54 _rcset("cgi.item.type","thread") 55 _rcset("cgi.item",a[4]) 56 } 57 else { 58 _rcset("cgi.item.type","page") 59 _rcset("cgi.item",a[3]) 60 } 61 62 # Page name is needed in any case. 63 _rcset("cgi.page",a[3]) 64 } 65 66 # The following test is necessary since the address could, 67 # at least in theory, have been set to any string by the 68 # remote user, due to how it is handled to cope with stunnel(8) 69 # and the lack of transproxy support in kernel 2.4.x. 70 71 if (_isipaddr(ENVIRON["REMOTE_ADDR"]) == _TRUE) 72 value = ENVIRON["REMOTE_ADDR"] 73 else value = "0.0.0.0" 74 75 _rcset("REMOTE_ADDR",value) 76 } 77 78 else { # response. 79 80 # generic template conditionals. 81 ifsections() 82 } 83 } 84 85 # EOF