1 # ===================================================================== 2 # groupFileList: list selected file types in a W-TW group. 3 # 4 # Copyright (c) 2007,2009 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 # Local variables and functions 23 # ===================================================================== 24 25 cgi.group = () 26 cgi.group.literal = () 27 cgi.grep.pattern = . # match all by default. 28 cgi.grep.literal = () 29 cgi.paging = 0 # default is no paging. 30 cgi.what = links 31 cgi.where = web # default location. 32 cgi.style = () 33 34 # ===================================================================== 35 # Main program 36 # ===================================================================== 37 38 # Load call arguments. 39 csaGetArgs GET 40 41 ~ $'cgi.paging' 0 && csaTrue $TNS_PAGER_DEFAULT && cgi.paging = 1 42 43 . $CSA_ROOT/lib/group-stuff.rc 44 45 . $CSA_ROOT/lib/group-editor.rc 46 47 # Set template vars to their final values. 48 tpl.var.tw.page = tw-group-filelist 49 tpl.var.tw.page.object = $'tpl.var.tw.page' 50 tpl.var.html.title = $'tpl.var.tw.group'/$'tpl.var.tw.page' 51 52 tpl.var.tw.arg2 = $'cgi.what' 53 54 switch ($'cgi.what') { 55 case links; tpl.var.tw.arg2.links = 'checked="checked"' 56 case images; tpl.var.tw.arg2.images = 'checked="checked"' 57 case media; tpl.var.tw.arg2.media = 'checked="checked"' 58 } 59 60 tpl.var.tw.arg3 = $'cgi.where' 61 62 switch ($'cgi.where') { 63 case web; tpl.var.tw.arg3.web = 'checked="checked"' 64 case wiki; tpl.var.tw.arg3.wiki = 'checked="checked"' 65 } 66 67 tpl.var.tw.arg5 = $'cgi.grep.literal' 68 69 tpl.var.tw.arg6 = $'cgi.style' 70 71 # Policy checks should always come after the inclusion of group meta-data. 72 73 ~ ,$TNS_AUTH_GRP, *,editor,* || csaExit.needauth 74 75 if (csaIsFullPath --exists --quiet $CSA_TPL_ROOT/tw-group-filelist.txt) { 76 # custom template. 77 tpl.include.html.body = $CSA_TPL_ROOT/tw-group-filelist.txt 78 } else { 79 # default template. 80 tpl.include.html.body = $tw_dstem/tw-group-filelist.txt 81 } 82 83 . $CSA_ROOT/lib/tpl-stuff.rc 84 85 csaMkTemp tpl.include.tw.page 86 87 # Make sure the file is created. 88 touch $'tpl.include.tw.page' || csaExit.fault 0009 $'tpl.include.tw.page' 89 90 # Wiki page names are prepended by '/', private attachments by ':', 91 # while public attachments and web objects by './' . 92 93 > $tmp1 # clear tmp file before re-using. 94 95 # Wiki page names are simplistically connsidered public links, even 96 # if some of them may actually have access restrictions. 97 98 if (~ $'cgi.what' links) { 99 getcolumn --no-header --input \ 100 $tw_gstem/page+dat p_uri | sed 's,^,/,' >> $tmp1 101 } 102 103 # private images (also PDF). 104 if (~ $'cgi.where' wiki && ~ $'cgi.what' links images) { 105 # Confine scope of directory change. It looks like rc(1) does not 106 # understand the "cd -" command. 107 @{ 108 csaSubshell 109 cd $tw_gstem || csaExit.fault 0033 $tw_gstem 110 find . -type f -and '(' -iname '*.png' -or -iname '*.jpg' \ 111 -or -iname '*.jpeg' -or -iname '*.gif' -or -iname '*.pdf' ')' \ 112 -and -size +0c -printf :%p\n >> $tmp1 113 } 114 } 115 116 # private media files. 117 if (!~ $'cgi.where' web && ~ $'cgi.what' links media) { 118 # confine scope of directory change. 119 @{ 120 csaSubshell 121 cd $tw_gstem || csaExit.fault 0033 $tw_gstem 122 find . -type f -and '(' -iname '*.mpg' -or -iname '*.swf' \ 123 -or -iname '*.avi' -or -iname '*.mp3' ')' \ 124 -and -size +0c -printf :%p\n >> $tmp1 125 } 126 } 127 128 # public images (also PDF). 129 if (!~ $'cgi.where' wiki && ~ $'cgi.what' links images) { 130 # confine scope of directory change. 131 @{ 132 csaSubshell 133 cd $CSA_DOCROOT/$CSA_LANG/$TNS_ATTACH_PUBDIR || 134 csaExit.fault 0033 $CSA_DOCROOT/$CSA_LANG 135 136 # This program is meant to list stuff that the group editor can 137 # create, delete and modify, not to list things that can only by 138 # handled with FTP and that can only be managed by the webmaster. 139 # This has also the beneficial effect of mitigating the excessive 140 # output problem explained further down. 141 # 142 # find $'cgi.group' -type f -and '(' -iname '*.png' \ 143 # -or -iname '*.jpg' -or -iname '*.jpeg' -or -iname '*.gif' \ 144 # -or -iname '*.pdf' ')' -and -size +0c >> $tmp1 145 146 find $'cgi.group' -type f -and '(' -iname '*.png' \ 147 -or -iname '*.jpg' -or -iname '*.jpeg' -or -iname '*.gif' \ 148 -or -iname '*.pdf' ')' -and -size +0c >> $tmp1 149 } 150 } 151 152 # public media files. 153 if (!~ $'cgi.where' wiki ~ $'cgi.what' links media) { 154 # confine scope of directory change. 155 @{ 156 csaSubshell 157 cd $CSA_DOCROOT/$CSA_LANG/$TNS_ATTACH_PUBDIR || 158 csaExit.fault 0033 $CSA_DOCROOT/$CSA_LANG 159 find $'cgi.group' -type f -and '(' -iname '*.mpg' \ 160 -or -iname '*.swf' -or -iname '*.avi' -or -iname '*.mpeg' \ 161 -or -iname '*.mp3' ')' -and -size +0c >> $tmp1 162 } 163 } 164 165 # Unfortunately the output may be so big that the AWK program called 166 # by csaExit.ok may take ages to process it, a time longer than the 30" 167 # default hard-coded into thttpd(8). When that time-limit expires the 168 # HTTP server kills the CGI process, with a blank page returned to the 169 # client, stale workfiles left in TMPDIR, etc. This seems to occur around 170 # approx. 1000 lines of output or more. To reproduce the problem at will, 171 # the output can be made artificially big by uncommenting the next two 172 # lines, possibly repeating the append multiple times. At the moment the 173 # problem has been bypassed by commenting-out the call to _mrwresponse() 174 # in lib/rpcio/groupFileList.awk, but I doubt this is the definitive 175 # solution, we'll see. Some tests using gawk(1) instead of mawk(1) did 176 # not improve the situation. I think the real solution is to always 177 # force paged output for sites with a lot of content. 178 # 179 #cp $'tpl.include.tw.page' /tmp/xxx 180 #cat /tmp/xxx >> $'tpl.include.tw.page' 181 182 # Let's have page names at the top. 183 if (~ $'cgi.grep.pattern' ()) { 184 sort -u -o $'tpl.include.tw.page' $tmp1 || csaExit.fault 0003 sort 185 } else { 186 grep -ie $'cgi.grep.pattern' $tmp1 | sort -u > $'tpl.include.tw.page' 187 188 # grep(1) may well return non-zero if $tmp1 is empty, so I cannot 189 # use 'csaStatus' here. 190 } 191 192 csaExit.ok --table $'tpl.include.tw.page' $tpl_file 193 194 # End of program.