BOINC /
boinc
| 1 | <?php |
||||
| 2 | // This file is part of BOINC. |
||||
| 3 | // http://boinc.berkeley.edu |
||||
| 4 | // Copyright (C) 2008 University of California |
||||
| 5 | // |
||||
| 6 | // BOINC is free software; you can redistribute it and/or modify it |
||||
| 7 | // under the terms of the GNU Lesser General Public License |
||||
| 8 | // as published by the Free Software Foundation, |
||||
| 9 | // either version 3 of the License, or (at your option) any later version. |
||||
| 10 | // |
||||
| 11 | // BOINC is distributed in the hope that it will be useful, |
||||
| 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
| 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
||||
| 14 | // See the GNU Lesser General Public License for more details. |
||||
| 15 | // |
||||
| 16 | // You should have received a copy of the GNU Lesser General Public License |
||||
| 17 | // along with BOINC. If not, see <http://www.gnu.org/licenses/>. |
||||
| 18 | |||||
| 19 | // Manage user settings |
||||
| 20 | // |
||||
| 21 | // Displays user settings, allows one to control special user status |
||||
| 22 | // and forum suspension (banishment). Put this in html/ops, |
||||
| 23 | // (or could be used by moderators for bans < 24 hrs). |
||||
| 24 | |||||
| 25 | |||||
| 26 | // TODO: use DB abstraction layer |
||||
|
0 ignored issues
–
show
Coding Style
Best Practice
introduced
by
Loading history...
|
|||||
| 27 | |||||
| 28 | require_once("../inc/util.inc"); |
||||
| 29 | require_once("../inc/user.inc"); |
||||
| 30 | require_once("../inc/team.inc"); |
||||
| 31 | require_once("../inc/forum.inc"); |
||||
| 32 | require_once("../inc/util_ops.inc"); |
||||
| 33 | require_once("../inc/profile.inc"); |
||||
| 34 | require_once("../project/project.inc"); |
||||
| 35 | |||||
| 36 | error_reporting(E_ALL); |
||||
| 37 | ini_set('display_errors', true); |
||||
|
0 ignored issues
–
show
true of type true is incompatible with the type string expected by parameter $value of ini_set().
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 38 | ini_set('display_startup_errors', true); |
||||
| 39 | |||||
| 40 | // Delete a user if they have no credit, results, or posts |
||||
| 41 | // |
||||
| 42 | function possibly_delete_user($user){ |
||||
| 43 | if ($user->total_credit > 0.0){ |
||||
| 44 | admin_error_page("Cannot delete user: User has credit."); |
||||
| 45 | } |
||||
| 46 | |||||
| 47 | // Don't delete user if they have any outstanding Results |
||||
| 48 | // |
||||
| 49 | if (BoincResult::count("userid=$user->id")) { |
||||
| 50 | admin_error_page("Cannot delete user: User has count results in the database."); |
||||
| 51 | } |
||||
| 52 | |||||
| 53 | // Don't delete user if they have posted to the forums |
||||
| 54 | // |
||||
| 55 | if (BoincPost::count("user=$user->id")) { |
||||
| 56 | admin_error_page("Cannot delete user: User has forum posts."); |
||||
| 57 | } |
||||
| 58 | |||||
| 59 | if ($user->teamid){ |
||||
| 60 | user_quit_team($user); |
||||
| 61 | } |
||||
| 62 | delete_user($user); |
||||
| 63 | } |
||||
| 64 | |||||
| 65 | // Process special user settings |
||||
| 66 | // |
||||
| 67 | function handle_special_user($user) { |
||||
| 68 | global $special_user_bitfield; |
||||
| 69 | $Nbf = sizeof($special_user_bitfield); |
||||
| 70 | $bits=""; |
||||
| 71 | for ($i=0; $i<$Nbf; $i++) { |
||||
| 72 | $key = "special_user_$i"; |
||||
| 73 | if (array_key_exists($key, $_POST) && $_POST[$key]) { |
||||
| 74 | $bits .= "1"; |
||||
| 75 | } else { |
||||
| 76 | $bits .= "0"; |
||||
| 77 | } |
||||
| 78 | } |
||||
| 79 | $q = "UPDATE forum_preferences SET special_user=\"$bits\" WHERE userid=$user->id"; |
||||
| 80 | _mysql_query($q); |
||||
| 81 | } |
||||
| 82 | |||||
| 83 | |||||
| 84 | // Process a suspension: |
||||
| 85 | // |
||||
| 86 | function handle_suspend($user) { |
||||
| 87 | global $g_logged_in_user; |
||||
| 88 | $dt = post_int('suspend_for', true); |
||||
| 89 | |||||
| 90 | $reason = $_POST['suspend_reason']; |
||||
| 91 | if ($dt > 0 && empty($reason)) { |
||||
| 92 | admin_error_page("You must supply a reason for a suspension. |
||||
| 93 | <p><a href=manage_user.php?userid=$user->id>Try again</a>" |
||||
| 94 | ); |
||||
| 95 | } else { |
||||
| 96 | if (is_numeric($dt)) { |
||||
| 97 | $t = $dt>0 ? time()+$dt : 0; |
||||
| 98 | $q = "UPDATE forum_preferences SET banished_until=$t WHERE userid=$user->id"; |
||||
| 99 | _mysql_query($q); |
||||
| 100 | |||||
| 101 | // put a timestamp in wiki to trigger re-validation of credentials |
||||
| 102 | |||||
| 103 | if (function_exists('touch_wiki_user')){ |
||||
| 104 | touch_wiki_user($user); |
||||
| 105 | } |
||||
| 106 | |||||
| 107 | // Send suspension e-mail to user and administrators |
||||
| 108 | |||||
| 109 | if ($dt>0) { |
||||
| 110 | $subject = PROJECT." posting privileges suspended for ". $user->name; |
||||
| 111 | $body = " |
||||
| 112 | Forum posting privileges for the " .PROJECT. " user \"".$user->name."\" |
||||
| 113 | have been suspended for " .time_diff($dt). " by ".$g_logged_in_user->name.". |
||||
| 114 | The reason given was: |
||||
| 115 | |||||
| 116 | $reason |
||||
| 117 | |||||
| 118 | The suspension will end at " .time_str($t)."\n"; |
||||
| 119 | } else { |
||||
| 120 | $subject = PROJECT." user ". $user->name. " unsuspended"; |
||||
| 121 | $body = " |
||||
| 122 | Forum posting privileges for the " .PROJECT. " user \"".$user->name."\" |
||||
| 123 | have been restored by ".$g_logged_in_user->name."\n"; |
||||
| 124 | if ($reason) { |
||||
| 125 | $body.="The reason given was:\n\n $reason\n"; |
||||
| 126 | } |
||||
| 127 | } |
||||
| 128 | |||||
| 129 | send_email($user, $subject, $body); |
||||
| 130 | |||||
| 131 | $emails = explode(",", POST_REPORT_EMAILS); |
||||
| 132 | foreach ($emails as $email) { |
||||
| 133 | $admin->email_addr = $email; |
||||
|
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||||
| 134 | send_email($admin, $subject, $body); |
||||
| 135 | } |
||||
| 136 | } |
||||
| 137 | } |
||||
| 138 | } |
||||
| 139 | |||||
| 140 | function show_manage_user_form($user) { |
||||
| 141 | global $special_user_bitfield; |
||||
| 142 | $Nbf = sizeof($special_user_bitfield); |
||||
| 143 | |||||
| 144 | admin_page_head("Management $user->name"); |
||||
| 145 | |||||
| 146 | if (!defined("POST_REPORT_EMAILS")) { |
||||
| 147 | echo "<p><font color='RED'> |
||||
| 148 | There is no administrative email address defined for reporting problems |
||||
| 149 | or abuse in the forums. Please define POST_REPORT_EMAILS in project.inc |
||||
| 150 | </font></p>\n"; |
||||
| 151 | } |
||||
| 152 | |||||
| 153 | echo "<form name='manage_user' action=manage_user.php method='POST'> |
||||
| 154 | <input type='hidden' name='userid' value='". $user->id."'> |
||||
| 155 | "; |
||||
| 156 | |||||
| 157 | start_table(); |
||||
| 158 | |||||
|
0 ignored issues
–
show
|
|||||
| 159 | |||||
| 160 | row1("<b>User: </b> $user->name <div align='right'> |
||||
| 161 | <input class=\"btn btn-danger\" name=\"delete_user\" type=\"submit\" value=\"Delete user\"> |
||||
| 162 | </div>" |
||||
| 163 | ); |
||||
| 164 | |||||
| 165 | show_user_summary_public($user); |
||||
| 166 | show_profile_link_ops($user); |
||||
| 167 | row2("Email:", "$user->email_addr"); |
||||
| 168 | project_user_summary($user); |
||||
| 169 | end_table(); |
||||
| 170 | project_user_page_private($user); |
||||
| 171 | |||||
| 172 | echo "</form>\n"; |
||||
| 173 | |||||
|
0 ignored issues
–
show
|
|||||
| 174 | |||||
| 175 | // Special User status: |
||||
| 176 | |||||
| 177 | echo "\n\n<P> |
||||
| 178 | <table width='100%'><tr> |
||||
| 179 | <td width='50%' valign='TOP'> \n"; |
||||
| 180 | |||||
| 181 | echo "<form name='special_user' action=manage_user.php method=\"POST\"> |
||||
| 182 | <input type='hidden' name='userid' value='".$user->id."'> |
||||
| 183 | "; |
||||
| 184 | |||||
| 185 | start_table(); |
||||
| 186 | row1("Special User Status"); |
||||
| 187 | |||||
| 188 | echo "<tr>\n"; |
||||
| 189 | for ($i=0; $i<$Nbf; $i++) { |
||||
| 190 | $bit = substr($user->prefs->special_user, $i, 1); |
||||
| 191 | echo "<tr><td><input type='checkbox'' name='special_user_".$i."' value='1'"; |
||||
| 192 | if ($bit == 1) { |
||||
| 193 | echo " checked='checked'"; |
||||
| 194 | } |
||||
| 195 | echo ">". $special_user_bitfield[$i] ."</td></tr>\n"; |
||||
| 196 | } |
||||
| 197 | echo "</tr>"; |
||||
| 198 | |||||
| 199 | echo "</tr><td colspan=$Nbf align='RIGHT'> |
||||
| 200 | <input name='special_user' type='SUBMIT' value='Update'> |
||||
| 201 | </td></tr> |
||||
| 202 | "; |
||||
| 203 | end_table(); |
||||
| 204 | echo "</form>\n"; |
||||
| 205 | |||||
| 206 | echo "\n\n</td><td valign='TOP'>\n\n"; |
||||
| 207 | |||||
|
0 ignored issues
–
show
|
|||||
| 208 | |||||
| 209 | // Suspended posting privileges |
||||
| 210 | |||||
| 211 | echo "<form name='banishment' action=manage_user.php method=\"POST\"> |
||||
| 212 | <input type='hidden' name='userid' value='".$user->id."'> |
||||
| 213 | "; |
||||
| 214 | start_table(); |
||||
| 215 | row1("Suspension"); |
||||
| 216 | |||||
| 217 | if ($user->prefs->banished_until) { |
||||
| 218 | $dt = $user->prefs->banished_until - time(); |
||||
| 219 | if ($dt > 0) { |
||||
| 220 | $x = " Suspended until " . time_str($user->prefs->banished_until) |
||||
| 221 | ."<br/> (Expires in " . time_diff($dt) .")" ; |
||||
|
0 ignored issues
–
show
|
|||||
| 222 | } else { |
||||
| 223 | $x = " last suspended " . time_str($user->prefs->banished_until); |
||||
| 224 | } |
||||
| 225 | row1($x); |
||||
| 226 | } else { |
||||
| 227 | $dt = 0; |
||||
| 228 | } |
||||
| 229 | |||||
| 230 | echo "<tr><td> |
||||
| 231 | Suspend user for: |
||||
| 232 | <blockquote> |
||||
| 233 | <input type='radio' name='suspend_for' value='3600'> 1 hour <br/> |
||||
| 234 | <input type='radio' name='suspend_for' value='7200'> 2 hours <br/> |
||||
| 235 | <input type='radio' name='suspend_for' value='18000'> 6 hours <br/> |
||||
| 236 | <input type='radio' name='suspend_for' value='36000'> 12 hours <br/> |
||||
| 237 | <input type='radio' name='suspend_for' value='86400'> 24 hours <br/> |
||||
| 238 | "; |
||||
| 239 | echo " |
||||
| 240 | <input type='radio' name='suspend_for' value='172800'> 48 hours <br/> |
||||
| 241 | <input type='radio' name='suspend_for' value='",86400*7,"'> 1 week <br/> |
||||
| 242 | <input type='radio' name='suspend_for' value='",86400*14,"'> 2 weeks <br/> |
||||
| 243 | "; |
||||
| 244 | |||||
| 245 | if ($dt>0) { |
||||
| 246 | echo " |
||||
| 247 | <input type='radio' name='suspend_for' value='-1'> <b>unsuspend</b> <br/>"; |
||||
| 248 | } |
||||
| 249 | echo " |
||||
| 250 | </blockquote> |
||||
| 251 | |||||
| 252 | "; |
||||
| 253 | |||||
| 254 | echo "<P>Reason (required):\n"; |
||||
| 255 | echo "<textarea name='suspend_reason' cols='40' rows='4'></textarea>"; |
||||
| 256 | echo "<br><font size='-2' >The reason will be sent to both the user |
||||
| 257 | and to the project administrators.</font>\n"; |
||||
| 258 | |||||
|
0 ignored issues
–
show
|
|||||
| 259 | |||||
| 260 | echo "<p align='RIGHT'><input name='suspend_submit' type='SUBMIT' value='Update'></P>\n"; |
||||
| 261 | echo " </td></tr>\n"; |
||||
| 262 | |||||
| 263 | end_table(); |
||||
| 264 | echo "</form>\n"; |
||||
| 265 | |||||
| 266 | echo "</td></tr> </table>\n"; |
||||
| 267 | |||||
| 268 | admin_page_tail(); |
||||
| 269 | } |
||||
| 270 | |||||
| 271 | get_logged_in_user(); |
||||
| 272 | db_init(); |
||||
| 273 | |||||
| 274 | $q = null; |
||||
| 275 | |||||
| 276 | $id = get_int("userid", true); |
||||
| 277 | if (!$id) { |
||||
| 278 | $id = post_int("userid", true); |
||||
| 279 | } |
||||
| 280 | if (!$id) admin_error_page("No ID given"); |
||||
| 281 | $user = BoincUser::lookup_id($id); |
||||
| 282 | if (!$user) admin_error_page("No such user: $id"); |
||||
| 283 | |||||
| 284 | BoincForumPrefs::lookup($user); |
||||
| 285 | |||||
| 286 | if (isset($_POST['delete_user'])) { |
||||
| 287 | possibly_delete_user($user); |
||||
| 288 | admin_page_head("User deleted"); |
||||
| 289 | echo " |
||||
| 290 | User $user->name ($user->id) deleted. |
||||
| 291 | <p> |
||||
| 292 | <a href= |
||||
| 293 | "; |
||||
| 294 | admin_page_tail(); |
||||
| 295 | exit; |
||||
| 296 | } |
||||
| 297 | |||||
| 298 | if (isset($_POST['special_user'])) { |
||||
| 299 | handle_special_user($user); |
||||
| 300 | Header("Location: manage_user.php?userid=$user->id"); |
||||
|
0 ignored issues
–
show
|
|||||
| 301 | } |
||||
| 302 | if (isset($_POST['suspend_submit'])) { |
||||
| 303 | handle_suspend($user); |
||||
| 304 | Header("Location: manage_user.php?userid=$user->id"); |
||||
|
0 ignored issues
–
show
|
|||||
| 305 | } |
||||
| 306 | |||||
| 307 | show_manage_user_form($user); |
||||
| 308 | |||||
| 309 | ?> |
||||
| 310 |