1 # ===================================================================== 2 # editGroup: W-TW page group configuration editor. 3 # 4 # Copyright (c) 2010,2011 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 MUST be set to a bogus value here, or the creation of a new 26 # group will fail with a checksum error due to how csa-tbl2rc behaves 27 # in the presence of an empty '--prefix' argument. 28 29 cgi.group = . 30 cgi.group.literal = () 31 32 tmp1 = /dev/null 33 tpl.var.checksum = () 34 35 # ===================================================================== 36 # Main program 37 # ===================================================================== 38 39 csaGetArgs GET 40 41 #~ $REMOTE_ADDR 192.168.1.2 && csaExit.env 42 43 # Assess whether we are being requested to edit an existing group or 44 # to create a new one. 45 46 # Refuse reserved names. 47 ~ $'cgi.group' tw-* && csaExit.fault 1000 48 49 # Set Principal Lock Semaphore(s) (PLS). 50 csaLock $CSA_ROOT/var/pages/$CSA_LANG/group+dat || csaExit.fault 51 52 # Create group table if it does not yet exist. 53 if (!csaIsFullPath --exists --quiet $CSA_ROOT/var/pages/$CSA_LANG/group+dat) { 54 maketable --input \ 55 $CSA_ROOT/lib/group.xrf > $CSA_ROOT/var/pages/$CSA_LANG/group+dat || 56 csaExit.fault 0003 maketable 57 } 58 59 # If this is a new group, then tmp1 is still undefined here. 60 csaMkTemp tmp1 61 62 # Fetch the requested group record, if available. 63 csa-tbl2rc --input $CSA_ROOT/var/pages/$CSA_LANG/group+dat \ 64 --key $'cgi.group' --prefix tbl_group. > $tmp1 || 65 csaExit.fault 0003 csa-tbl2rc 66 67 . $tmp1 68 69 csaSum --file $tmp1 70 tpl.var.checksum = $CSA_RESULT 71 72 if (!~ $'tbl_group.k_group' ()) { 73 74 # Existing group. 75 76 # Set group-related template vars. 77 tpl.var.tw.group = $'tbl_group.g_name' 78 tpl.var.tw.group.unx = $'tbl_group.k_group' 79 tpl.var.tw.group.descr = $'tbl_group.g_descr' 80 tpl.var.tw.group.editor = $'tbl_group.g_editor' 81 82 # Set default description if necessary. 83 ~ $'tpl.var.tw.group.descr' () && 84 tpl.var.tw.group.descr = $'tpl.var.tw.group' 85 86 . $CSA_ROOT/lib/group-stuff.rc 87 88 . $CSA_ROOT/lib/tpl-stuff.rc 89 90 } else { 91 92 # New group, so I cannot rely upon group-level custom templates 93 # and neiter I can call group-stuff.rc of course, so I need to 94 # hard-code part of the latter's logic here. 95 96 tw_dstem = $CSA_ROOT/lib/default 97 98 # Account for the fact that templates are created by the client. 99 CSA_TPL_SAFEPATH = ($CSA_INSTALL/lib $tw_dstem $TMPDIR $CSA_TPL_ROOT 100 $CSA_DOCROOT/$CSA_LANG/$TNS_ATTACH_PUBDIR) 101 102 CSA_EXIT_SCRIPT = $CSA_ROOT/lib/exit-stuff.rc 103 104 # Set group-related template vars. 105 tpl.var.tw.group = $'cgi.group.literal' 106 tpl.var.tw.group.unx = $'cgi.group.k_group' 107 tpl.var.tw.group.descr = $'tpl.var.tw.group' 108 } 109 110 # Authentication required to run this script. By doing the check here 111 # we will ensure that any error messages will be printed with the 112 # proper page templates. 113 114 csaTrue $CSA_AUTH_OK || csaExit.needauth 115 116 #~ $REMOTE_ADDR 192.168.1.2 && csaExit.env 117 118 if (!~ $'tbl_group.k_group' ()) { 119 120 # Existing group. 121 122 # Only those users who are either global editors or group-level editors 123 # for the target group are allowed to edit the latter. Note that for this 124 # to work at this stage it requires that 'lib/group-editor.rc' is *NOT* 125 # loaded by this script. 126 127 ~ ,$TNS_AUTH_GRP, *,editor,* || 128 ,$'tbl_group.g_editor', *,$CSA_AUTH_USER,* || csaExit.needauth 129 130 if (csaIsFullPath --exists --quiet $CSA_TPL_ROOT/tw-edit-group.txt) { 131 # custom group-editing template. 132 tpl.include.html.body = $CSA_TPL_ROOT/tw-edit-group.txt 133 } else { 134 # default group-editing template. 135 tpl.include.html.body = $tw_dstem/tw-edit-group.txt 136 } 137 138 } else { 139 140 # New group; I cannot rely on group-level templates here, so I pick the 141 # relevant default in the local language if available, otherwise I go 142 # for the global default. 143 144 if (csaIsFullPath --exists --quiet \ 145 $tw_dstem/i18n/$CSA_LANG/tw-create-group.txt) { 146 tpl.include.html.body = $tw_dstem/i18n/$CSA_LANG/tw-create-group.txt 147 } else tpl.include.html.body = $tw_dstem/tw-create-group.txt 148 149 if (csaIsFullPath --exists --quiet \ 150 $tw_dstem/i18n/$CSA_LANG/tw.$CSA_TPLEXT) { 151 tpl_file = (--file-root $tw_dstem/i18n/$CSA_LANG tw.$CSA_TPLEXT) 152 } else tpl_file = (--file-root $tw_dstem tw.$CSA_TPLEXT) 153 154 # Load local language-specific default group settings. 155 csaIsFullPath --exists --quiet \ 156 $CSA_ROOT/var/pages/$CSA_LANG/tw-default+cf && 157 . $CSA_ROOT/var/pages/$CSA_LANG/tw-default+cf 158 159 # Only global editors are allowed to create new groups, unless the 160 # TNS_ALLOW_WRITERS rc(1) list either contains/comprises the special 161 # keyword "ALL" or the requesting user. Again, for this to work at 162 # this stage it requires that 'lib/group-editor.rc' is *NOT* loaded 163 # by this script. 164 165 if (!~ ,$TNS_AUTH_GRP, *,editor,*) { 166 167 ~ $TNS_ALLOW_WRITERS ALL $CSA_AUTH_USER || csaExit.needauth 168 169 tpl.var.tw.group.editor = $CSA_AUTH_USER 170 } 171 } 172 173 tpl.if.tw.ispage = '(::DEL:)' 174 tpl.fi.tw.ispage = '(:DEL::)' 175 tpl.if.tw.isview = () 176 tpl.fi.tw.isview = () 177 178 csaExit.ok $tpl_file 179 180 # End of program.