1 # ===================================================================== 2 # listUsers.awk: RPC I/O function for rpclib/listUsers. 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,outfile,i,\ 26 url,a,fmt,tmp) { 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 # optional search keyword, with any special chars turned 42 # into the "." wildcard. 43 if ((value=_request("2",1)) != _NULL) { 44 gsub(/[^a-zA-Z0-9]/,".",value) 45 _rcset("cgi.grep.user",value) 46 } 47 48 # The following test is necessary since the address could, 49 # at least in theory, have been set to any string by the 50 # remote user, due to how it is handled to cope with stunnel(8) 51 # and the lack of transproxy support in kernel 2.4.x. 52 53 if (_isipaddr(ENVIRON["REMOTE_ADDR"]) == _TRUE) 54 value = ENVIRON["REMOTE_ADDR"] 55 else value = "0.0.0.0" 56 57 _rcset("REMOTE_ADDR",value) 58 } 59 60 else { # response. 61 62 outfile = _rcget("tpl.include.tw.page") 63 if (outfile !~ /^\/\.*[a-zA-Z0-9]/) 64 return(_sys("csaExit.fault 0041 outfile")) 65 66 # Set user list format string. 67 68 fmt = readfmt("tw-list-users") 69 gsub(/%/,"%%",fmt) # turn plain '%' into '%%'. 70 gsub(/\\/,"\\\\&",fmt) # turn '\' into '\\'. 71 gsub(/[\n\r]+/,"",fmt) # just in case. 72 73 # the user format string is currently not customizable. 74 for (i=1; i<=6; i++) { 75 if (!sub(//,"%s",fmt)) fmt = fmt "" 76 } 77 78 # encode any extra markers. 79 gsub(//,"\\<tw:s/\\>",fmt) 80 81 fmt = fmt "\n" 82 83 url = ENVIRON["CSA_RPC_URI"] "/" \ 84 ENVIRON["CSA_LANG"] "/" _rcget("cgi.group") "/tw-user/" 85 86 #url = ENVIRON["CSA_CGI_STEM"] ENVIRON["CSA_REQUEST_URI"] "/" 87 #gsub(/.UNKNOWN/,_NULL,url) # can be /UNKNOWN?UNKNOWN 88 gsub(/ /,"%20",url) # just in case. 89 90 # Make sure output file is cleared, in case we are re-using 91 # an old temporary file and we have nothing to print to it. 92 _creat(outfile,_O_TRUNC) 93 94 # read input table. 95 # k_user, u_name, u_sname, u_email, u_gui 96 97 i=1 98 while (split(_TBLS[1,i++],a,"\t")) { 99 100 if (a[4] == _NULL) 101 tmp = "(" _nlsmap(_NULL,"deleted","listUsers") ")" 102 else if (a[5] ~ /^-/) 103 tmp = "(" _nlsmap(_NULL,"suspended","listUsers") ")" 104 else tmp = _NULL 105 106 printf(fmt,_xmlencode(url a[1]),_xmlencode(a[1]),\ 107 _xmlencode(a[2]),_xmlencode(a[3]),\ 108 _xmlencode(a[4]),_xmlencode(tmp)) > outfile 109 110 # Provide also a machine-readable format. 111 _wsresponse(1,i-1,url a[1]) 112 _wsresponse(2,i-1,a[2]) 113 _wsresponse(3,i-1,a[3]) 114 _wsresponse(4,i-1,a[4]) 115 _wsresponse(5,i-1,tmp) 116 } 117 118 close(outfile) 119 120 # generic template conditionals. 121 122 ifsections() 123 } 124 } 125 126 # EOF