| | @@ -77,50 +77,312 @@ |
| 77 | 77 | ** Show a list of users. Clicking on any user jumps to the edit |
| 78 | 78 | ** screen for that user. |
| 79 | 79 | */ |
| 80 | 80 | void setup_ulist(void){ |
| 81 | 81 | Stmt s; |
| 82 | + |
| 83 | + style_footer(); |
| 82 | 84 | login_check_credentials(); |
| 83 | | - if( !g.okSetup ){ |
| 85 | + if( !g.okWrite || g.isAnon ){ |
| 84 | 86 | login_needed(); |
| 87 | + return; |
| 85 | 88 | } |
| 86 | 89 | |
| 90 | + style_submenu_element("Add", "Add User", "setup_uedit"); |
| 87 | 91 | style_header(); |
| 88 | | - |
| 89 | | - @ <table border="0" cellpadding="0" cellspacing="0"> |
| 90 | | - db_prepare(&s, "SELECT uid, login, cap FROM repuser ORDER BY login"); |
| 92 | + @ <h2>List Of Users</h2> |
| 93 | + @ <table cellspacing=0 cellpadding=0 border=0> |
| 94 | + @ <tr> |
| 95 | + @ <th align="right"><nobr>User ID</nobr></th> |
| 96 | + @ <th> Capabilities </th> |
| 97 | + @ <th><nobr>Contact Info</nobr></th> |
| 98 | + @ </tr> |
| 99 | + db_prepare(&s, "SELECT uid, login, cap, info FROM user ORDER BY login"); |
| 91 | 100 | while( db_step(&s)==SQLITE_ROW ){ |
| 92 | | - @ <tr><td><a href="%s(g.zBaseURL)/setup_uedit?uid=%d(db_column_int(&s,0))"> |
| 93 | | - @ %h(db_column_text(&s,1))</a></td><td width="10"></td> |
| 94 | | - @ <td>%h(db_column_text(&s,2))</td></tr> |
| 101 | + @ <tr> |
| 102 | + @ <td align="right"> |
| 103 | + if( g.okAdmin ){ |
| 104 | + @ <a href="setup_uedit?id=%d(db_column_int(&s,0))"> |
| 105 | + } |
| 106 | + @ <nobr>%h(db_column_text(&s,1))</nobr> |
| 107 | + if( g.okAdmin ){ |
| 108 | + @ </a> |
| 109 | + } |
| 110 | + @ </td> |
| 111 | + @ <td align="center">%s(db_column_text(&s,2))</td> |
| 112 | + @ <td align="center">%s(db_column_text(&s,3))</td> |
| 113 | + @ </tr> |
| 95 | 114 | } |
| 96 | | - db_finalize(&s); |
| 115 | + @ </table> |
| 116 | + @ <p><hr> |
| 117 | + @ <b>Notes:</b> |
| 118 | + @ <ol> |
| 119 | + @ <li><p>The permission flags are as follows:</p> |
| 120 | + @ <table> |
| 121 | + @ <tr><td>a</td><td width="10"></td> |
| 122 | + @ <td>Admin: Create or delete users and ticket report formats</td></tr> |
| 123 | + @ <tr><td>d</td><td></td> |
| 124 | + @ <td>Delete: Erase anonymous wiki, tickets, and attachments</td></tr> |
| 125 | + @ <tr><td>i</td><td></td> |
| 126 | + @ <td>Check-in: Add new code to the repository</td></tr> |
| 127 | + @ <tr><td>j</td><td></td><td>Read-Wiki: View wiki pages</td></tr> |
| 128 | + @ <tr><td>k</td><td></td><td>Wiki: Create or modify wiki pages</td></tr> |
| 129 | + @ <tr><td>n</td><td></td><td>New: Create new tickets</td></tr> |
| 130 | + @ <tr><td>o</td><td></td> |
| 131 | + @ <td>Check-out: Read code out of the repository</td></tr> |
| 132 | + @ <tr><td>p</td><td></td><td>Password: Change password</td></tr> |
| 133 | + @ <tr><td>q</td><td></td><td>Query: Create or edit report formats</td></tr> |
| 134 | + @ <tr><td>r</td><td></td><td>Read: View tickets and change histories</td></tr> |
| 135 | + @ <tr><td>s</td><td></td><td>Setup: Change CVSTrac options</td></tr> |
| 136 | + @ <tr><td>w</td><td></td><td>Write: Edit tickets</td></tr> |
| 97 | 137 | @ </table> |
| 98 | | - |
| 138 | + @ </p></li> |
| 139 | + @ |
| 140 | + @ <li><p> |
| 141 | + @ If a user named "<b>anonymous</b>" exists, then anyone can access |
| 142 | + @ the server without having to log in. The permissions on the |
| 143 | + @ anonymous user determine the access rights for anyone who is not |
| 144 | + @ logged in. |
| 145 | + @ </p></li> |
| 146 | + @ |
| 147 | + @ </ol> |
| 99 | 148 | style_footer(); |
| 100 | 149 | } |
| 101 | 150 | |
| 102 | 151 | /* |
| 103 | | -** WEBPAGE: setup_uedit |
| 104 | | -** |
| 105 | | -** Edit the user with REPUSER.UID equal to the "u" query parameter. |
| 152 | +** WEBPAGE: /setup_uedit |
| 106 | 153 | */ |
| 107 | | -void setup_uedit(void){ |
| 154 | +void user_edit(void){ |
| 155 | + const char *zId, *zLogin, *zInfo, *zCap; |
| 156 | + char *oaa, *oas, *oar, *oaw, *oan, *oai, *oaj, *oao, *oap ; |
| 157 | + char *oak, *oad, *oaq; |
| 158 | + int doWrite; |
| 108 | 159 | int uid; |
| 160 | + int higherUser = 0; /* True if user being edited is SETUP and the */ |
| 161 | + /* user doing the editing is ADMIN. Disallow editing */ |
| 109 | 162 | |
| 163 | + /* Must have ADMIN privleges to access this page |
| 164 | + */ |
| 110 | 165 | login_check_credentials(); |
| 111 | | - if( !g.okSetup ){ |
| 112 | | - login_needed(); |
| 166 | + if( !g.okAdmin ){ login_needed(); return; } |
| 167 | + |
| 168 | + /* Check to see if an ADMIN user is trying to edit a SETUP account. |
| 169 | + ** Don't allow that. |
| 170 | + */ |
| 171 | + zId = PD("id", "0"); |
| 172 | + uid = atoi(zId); |
| 173 | + if( zId && !g.okSetup && uid>0 ){ |
| 174 | + char *zOldCaps; |
| 175 | + zOldCaps = db_text(0, "SELECT caps FROM user WHERE uid=%d",uid); |
| 176 | + higherUser = zOldCaps && strchr(zOldCaps,'s'); |
| 177 | + } |
| 178 | + |
| 179 | + if( P("can") ){ |
| 180 | + cgi_redirect("setup_ulist"); |
| 181 | + return; |
| 113 | 182 | } |
| 114 | | - uid = atoi(PD("u","0")); |
| 115 | | - if( uid<=0 ){ |
| 183 | + |
| 184 | + /* If we have all the necessary information, write the new or |
| 185 | + ** modified user record. After writing the user record, redirect |
| 186 | + ** to the page that displays a list of users. |
| 187 | + */ |
| 188 | + doWrite = cgi_all("login","info","pw") && !higherUser; |
| 189 | + if( doWrite ){ |
| 190 | + const char *zPw; |
| 191 | + const char *zLogin; |
| 192 | + char zCap[20]; |
| 193 | + int i = 0; |
| 194 | + int aa = P("aa")!=0; |
| 195 | + int ad = P("ad")!=0; |
| 196 | + int ai = P("ai")!=0; |
| 197 | + int aj = P("aj")!=0; |
| 198 | + int ak = P("ak")!=0; |
| 199 | + int an = P("an")!=0; |
| 200 | + int ao = P("ao")!=0; |
| 201 | + int ap = P("ap")!=0; |
| 202 | + int aq = P("aq")!=0; |
| 203 | + int ar = P("ar")!=0; |
| 204 | + int as = g.okSetup && P("as")!=0; |
| 205 | + int aw = P("aw")!=0; |
| 206 | + if( as ) aa = 1; |
| 207 | + if( aa ) ai = aw = ap = 1; |
| 208 | + if( aw ) an = ar = 1; |
| 209 | + if( ai ) ao = 1; |
| 210 | + if( ak ) aj = 1; |
| 211 | + if( aa ){ zCap[i++] = 'a'; } |
| 212 | + if( ad ){ zCap[i++] = 'd'; } |
| 213 | + if( ai ){ zCap[i++] = 'i'; } |
| 214 | + if( aj ){ zCap[i++] = 'j'; } |
| 215 | + if( ak ){ zCap[i++] = 'k'; } |
| 216 | + if( an ){ zCap[i++] = 'n'; } |
| 217 | + if( ao ){ zCap[i++] = 'o'; } |
| 218 | + if( ap ){ zCap[i++] = 'p'; } |
| 219 | + if( aq ){ zCap[i++] = 'q'; } |
| 220 | + if( ar ){ zCap[i++] = 'r'; } |
| 221 | + if( as ){ zCap[i++] = 's'; } |
| 222 | + if( aw ){ zCap[i++] = 'w'; } |
| 223 | + |
| 224 | + zCap[i] = 0; |
| 225 | + zPw = P("pw"); |
| 226 | + if( zPw==0 || zPw[0]==0 ){ |
| 227 | + zPw = db_text(0, "SELECT pw FROM user WHERE uid=%d", uid); |
| 228 | + } |
| 229 | + zLogin = P("login"); |
| 230 | + if( uid>0 && |
| 231 | + db_exists("SELECT 1 FROM user WHERE login=%Q AND uid!=%d", zLogin, uid) |
| 232 | + ){ |
| 233 | + style_header(); |
| 234 | + @ <font color="red">Login "%h(zLogin)" is already used by a different |
| 235 | + @ user.</font> |
| 236 | + @ |
| 237 | + @ <p><a href="setup_uedit?id=%d(uid))>[Bummer]</a></p> |
| 238 | + style_footer(); |
| 239 | + return; |
| 240 | + } |
| 241 | + db_multi_exec( |
| 242 | + "REPLACE INTO user(uid,login,info,pw,cap) " |
| 243 | + "VALUES(nullif(%d,0),%Q,%Q,%Q,'%s')", |
| 244 | + uid, P("login"), P("info"), zPw, zCap |
| 245 | + ); |
| 116 | 246 | cgi_redirect("setup_ulist"); |
| 117 | | - assert(0); |
| 247 | + return; |
| 248 | + } |
| 249 | + |
| 250 | + /* Load the existing information about the user, if any |
| 251 | + */ |
| 252 | + zLogin = ""; |
| 253 | + zInfo = ""; |
| 254 | + zCap = ""; |
| 255 | + oaa = oad = oai = oaj = oak = oan = oao = oap = oaq = oar = oas = oaw = ""; |
| 256 | + if( uid ){ |
| 257 | + zLogin = db_text("", "SELECT login FROM user WHERE uid=%d", uid); |
| 258 | + zInfo = db_text("", "SELECT info FROM user WHERE uid=%d", uid); |
| 259 | + zCap = db_text("", "SELECT cap FROM user WHERE uid=%d", uid); |
| 260 | + if( strchr(zCap, 'a') ) oaa = " checked"; |
| 261 | + if( strchr(zCap, 'd') ) oad = " checked"; |
| 262 | + if( strchr(zCap, 'i') ) oai = " checked"; |
| 263 | + if( strchr(zCap, 'j') ) oaj = " checked"; |
| 264 | + if( strchr(zCap, 'k') ) oak = " checked"; |
| 265 | + if( strchr(zCap, 'n') ) oan = " checked"; |
| 266 | + if( strchr(zCap, 'o') ) oao = " checked"; |
| 267 | + if( strchr(zCap, 'p') ) oap = " checked"; |
| 268 | + if( strchr(zCap, 'q') ) oaq = " checked"; |
| 269 | + if( strchr(zCap, 'r') ) oar = " checked"; |
| 270 | + if( strchr(zCap, 's') ) oas = " checked"; |
| 271 | + if( strchr(zCap, 'w') ) oaw = " checked"; |
| 118 | 272 | } |
| 273 | + |
| 274 | + /* Begin generating the page |
| 275 | + */ |
| 276 | + style_submenu_element("Cancel", "Cancel", "setup_ulist"); |
| 119 | 277 | style_header(); |
| 120 | | - style_footer(); |
| 278 | + if( uid ){ |
| 279 | + @ <h2>Edit User %h(zLogin)</h2> |
| 280 | + }else{ |
| 281 | + @ <h2>Add A New User</h2> |
| 282 | + } |
| 283 | + @ <table align="left" hspace="20" vspace="10"><tr><td> |
| 284 | + @ <form action="%s(g.zPath)" method="POST"> |
| 285 | + @ <table> |
| 286 | + @ <tr> |
| 287 | + @ <td align="right"><nobr>User ID:</nobr></td> |
| 288 | + if( uid ){ |
| 289 | + @ <td>%d(uid) <input type="hidden" name="id" value="%d(uid)"></td> |
| 290 | + }else{ |
| 291 | + @ <td>(new user)<input type="hidden" name="id" value=0></td> |
| 292 | + } |
| 293 | + @ </tr> |
| 294 | + @ <tr> |
| 295 | + @ <td align="right"><nobr>Login:</nobr></td> |
| 296 | + @ <td><input type="text" name="login" value="%h(zLogin)"></td> |
| 297 | + @ </tr> |
| 298 | + @ <tr> |
| 299 | + @ <td align="right"><nobr>Contact Info:</nobr></td> |
| 300 | + @ <td><input type="text" name="info" size=40 value="%h(zInfo)"></td> |
| 301 | + @ </tr> |
| 302 | + @ <tr> |
| 303 | + @ <td align="right" valign="top">Capabilities:</td> |
| 304 | + @ <td> |
| 305 | + @ <input type="checkbox" name="aa"%s(oaa)>Admin</input><br> |
| 306 | + @ <input type="checkbox" name="ad"%s(oad)>Delete</input><br> |
| 307 | + @ <input type="checkbox" name="ai"%s(oai)>Check-In</input><br> |
| 308 | + @ <input type="checkbox" name="aj"%s(oaj)>Read Wiki</input><br> |
| 309 | + @ <input type="checkbox" name="ak"%s(oak)>Write Wiki</input><br> |
| 310 | + @ <input type="checkbox" name="an"%s(oan)>New Tkt</input><br> |
| 311 | + @ <input type="checkbox" name="ao"%s(oao)>Check-Out</input><br> |
| 312 | + @ <input type="checkbox" name="ap"%s(oap)>Password</input><br> |
| 313 | + @ <input type="checkbox" name="aq"%s(oaq)>Query</input><br> |
| 314 | + @ <input type="checkbox" name="ar"%s(oar)>Read</input><br> |
| 315 | + if( g.okSetup ){ |
| 316 | + @ <input type="checkbox" name="as"%s(oas)>Setup</input><br> |
| 317 | + } |
| 318 | + @ <input type="checkbox" name="aw"%s(oaw)>Write</input> |
| 319 | + @ </td> |
| 320 | + @ </tr> |
| 321 | + @ <tr> |
| 322 | + @ <td align="right">Password:</td> |
| 323 | + @ <td><input type="password" name="pw" value=""></td> |
| 324 | + @ </tr> |
| 325 | + if( !higherUser ){ |
| 326 | + @ <tr> |
| 327 | + @ <td> </td> |
| 328 | + @ <td><input type="submit" name="submit" value="Apply Changes"> |
| 329 | + @ </tr> |
| 330 | + } |
| 331 | + @ </table></td></tr></table> |
| 332 | + @ <p><b>Notes:</b></p> |
| 333 | + @ <ol> |
| 334 | + if( higherUser ){ |
| 335 | + @ <li><p> |
| 336 | + @ User %h(zId) has Setup privileges and you only have Admin privileges |
| 337 | + @ so you are not permitted to make changes to %h(zId). |
| 338 | + @ </p></li> |
| 339 | + @ |
| 340 | + } |
| 341 | + @ <li><p> |
| 342 | + @ The <b>Read</b> and <b>Write</b> privileges give the user the ability |
| 343 | + @ to read and write tickets. The <b>New Tkt</b> capability means that |
| 344 | + @ the user is able to create new tickets. |
| 345 | + @ </p></li> |
| 346 | + @ |
| 347 | + @ <li><p> |
| 348 | + @ The <b>Delete</b> privilege give the user the ability to erase |
| 349 | + @ wiki, tickets, and atttachments that have been added by anonymous |
| 350 | + @ users. This capability is intended for deletion of spam. |
| 351 | + @ </p></li> |
| 352 | + @ |
| 353 | + @ <li><p> |
| 354 | + @ The <b>Query</b> privilege allows the user to create or edit |
| 355 | + @ report formats by specifying appropriate SQL. Users can run |
| 356 | + @ existing reports without the Query privilege. |
| 357 | + @ </p></li> |
| 358 | + @ |
| 359 | + @ <li><p> |
| 360 | + @ An <b>Admin</b> user can add other users, create new ticket report |
| 361 | + @ formats, and change system defaults. But only the <b>Setup</b> user |
| 362 | + @ is able to change the repository to |
| 363 | + @ which this program is linked. |
| 364 | + @ </p></li> |
| 365 | + @ |
| 366 | + if( zId==0 || strcmp(zId,"anonymous")==0 ){ |
| 367 | + @ <li><p> |
| 368 | + @ No login is required for user "<b>anonymous</b>". The capabilities |
| 369 | + @ of this user are available to anyone without supplying a username or |
| 370 | + @ password. To disable anonymous access, make sure there is no user |
| 371 | + @ with an ID of <b>anonymous</b>. |
| 372 | + @ </p></li> |
| 373 | + @ |
| 374 | + @ <li><p> |
| 375 | + @ The password for the "<b>anonymous</b>" user is used for anonymous |
| 376 | + @ access. The recommended value for the anonymous password |
| 377 | + @ is "anonymous". |
| 378 | + @ </p></li> |
| 379 | + } |
| 380 | + @ </form> |
| 381 | + style_footer(); |
| 121 | 382 | } |
| 383 | + |
| 122 | 384 | |
| 123 | 385 | /* |
| 124 | 386 | ** Generate a checkbox for an attribute. |
| 125 | 387 | */ |
| 126 | 388 | static void onoff_attribute( |
| 127 | 389 | |