1 # ===================================================================== 2 # cmtBan: allow a moderator to ban/unban a specified TW comment. 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.page = () 28 cgi.page.literal = () 29 cgi.cmt.id = () 30 cgi.what = ban 31 cgi.paging = 0 # default is no paging. 32 33 # ===================================================================== 34 # Main program 35 # ===================================================================== 36 37 # Load call arguments. 38 csaGetArgs DELETE 39 40 #~ $REMOTE_ADDR 192.168.1.2 && csaExit.env 41 42 . $CSA_ROOT/lib/group-stuff.rc 43 44 # Only *authenticated* *global* editors may ban other people's comments. 45 # This must be checked *before* a user is granted group-level editor 46 # privileges! 47 48 csaTrue $CSA_AUTH_OK || csaExit.needauth 49 50 # Policy checks should always come after the inclusion of group 51 # (and possibly also page) meta-data. 52 53 ~ ,$TNS_AUTH_GRP, *,editor,* || csaExit.needauth 54 55 . $CSA_ROOT/lib/group-editor.rc 56 57 . $CSA_ROOT/lib/page-stuff.rc 58 59 . $CSA_ROOT/lib/tpl-stuff.rc 60 61 # For comments to be enabled it is required that the relevant table 62 # already exists. I need to print an explanatory message, as the comment 63 # link may be present also on pages that do not actually take comments, 64 # or comments may have been disabled while the user was about to post a 65 # message, so she needs to be informed about that. To disable comments 66 # for a page that has already got comments, one possibility is to 67 # manually make the comment file hidden. I prefer not perform automated 68 # table creation here, not even if comments are enabled by default on 69 # all pages for this group. If comments are enabled by default, then 70 # it will suffice that a user calls either cmtList or cmtView prior to 71 # calling this program (a common situation) for the comment table to pop 72 # into existence. 73 74 csaIsFullPath --exists --quiet $tw_pstem+cmt || csaExit.fault 1013 75 76 #~ $REMOTE_ADDR 192.168.1.2 && csaExit.env 77 78 # Check misc. required args. 79 ~ $'cgi.cmt.id' () && csaExit.fault 0066 # should not occur 80 81 tpl.var.tw.cmt.parent.id = $'cgi.cmt.id' 82 83 # Policy checks should always come after the inclusion of group 84 # (and possibly also page) meta-data. Note that in case we default 85 # all users to the editor group, as it is the case with a publicly 86 # writable wiki (see the relevant group+cf file), we allow comment 87 # banning only to authenticated editors, otherwise every user could 88 # ban/restore other people's comments. Note that group-level editors 89 # are also allowed here. 90 91 if (!csaTrue $CSA_AUTH_OK || !~ ,$TNS_AUTH_GRP, *,editor,*) { 92 CSA_EXIT_SCRIPT = ($CSA_EXIT_SCRIPT back) 93 csaExit.needauth 94 } 95 96 #~ $REMOTE_ADDR 192.168.1.2 && csaExit.env 97 98 # Set Principal Lock Semaphore(s) (PLS). Unfortunately the lock needs 99 # to be set on the 'recent-comment' table, which is common to all 100 # pages within a group; this may become a bottleneck in case of heavily 101 # commented groups. 102 103 csaLock $tw_gstem/recent-comment+dat || csaExit.fault 104 105 # Create target table if it does not yet exist. 106 if (!csaIsFullPath --exists --quiet $tw_gstem/recent-comment+dat) { 107 maketable --input \ 108 $CSA_ROOT/lib/recent-comment.xrf > $tw_gstem/recent-comment+dat || 109 csaExit.fault 0003 maketable 110 } 111 112 # Test whether the comment table vanished in the meantime, possibly for 113 # having been made hidden to disable comments for this page. 114 115 csaIsFullPath --exists --quiet $tw_pstem+cmt || { 116 CSA_EXIT_SCRIPT = ($CSA_EXIT_SCRIPT back) 117 csaExit.fault 1013 118 } 119 120 csaOpen --fast --relaxed $tw_pstem+cmt || csaExit.fault 121 cmt_tmp = $CSA_RESULT 122 123 if (~ $'cgi.what' ban) { 124 tns1 = $CSA_AUTH_USER:$CSA_TIME_ISO 125 } else tns1 = $nil 126 127 awktable -H -i $tw_pstem+cmt '-vcmt_='$'cgi.cmt.id' '-vban_='$tns1 -- '{ 128 if ($k_cmt == cmt_) $c_banned = ban_ 129 print 130 }' > $cmt_tmp || csaExit.fault 0003 awktable 131 132 #csaMkTemp debug; viewtable < $cmt_tmp > $debug; csaExit.pcdata $debug 133 134 # Update the recent-comment table and the associated static view. 135 csaOpen --fast $tw_gstem/recent-comment+dat || csaExit.fault 136 tmp_rcmt = $CSA_RESULT 137 138 if (~ $'cgi.what' ban) { 139 awktable -H -i $tw_gstem/recent-comment+dat \ 140 '-vcmt_='$'cgi.cmt.id' -- '$k_rcmt != cmt_' | 141 sorttable -r rc_ctime | head -n $TNS_RECENT_COMMENTS_NUM > $tmp_rcmt 142 } else { 143 awktable -i $tw_pstem+cmt '-vpage_='$'tbl_page.p_name' -- 'BEGIN{ 144 print "\001k_rcmt\t\001rc_page\t\001rc_ctime" \ 145 "\t\001rc_subject\t\001rc_excerpt\t\001k_node" 146 } 147 { print $k_cmt,page_,$c_ctime,$c_subject,$c_excerpt,$k_node }' | 148 sorttable -r rc_ctime | head -n $TNS_RECENT_COMMENTS_NUM > $tmp_rcmt 149 } 150 151 csaStatus || csaExit.fault 0003 awktable/sorttable/head 152 153 #csaMkTemp debug; viewtable < $tmp_rcmt > $debug; csaExit.pcdata $debug 154 155 csaOpen --fast --relaxed $tw_gstem/recent-comments+xml || csaExit.fault 156 tmp1 = $CSA_RESULT 157 csaAwkCmd groupRecentComments.awk 158 getcolumn --input $tmp_rcmt k_rcmt rc_^(page subject) | $CSA_RESULT > $tmp1 159 csaStatus || csaExit.fault 0003 getcolumn/AWK 160 161 # Take the client back to the updated list of page comments. 162 csaExit.ok --confirmed \ 163 $CSA_RPC_URI/$CSA_LANG/$'tbl_group.g_uri'/$'tbl_page.p_uri'/comment'?4='$'cgi.paging' 164 165 # End of program.