Verzeichnisstruktur phpBB-3.0.0


Veröffentlicht
12.12.2007

So funktioniert es


Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück

Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

(Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

add_permissions.php

Zuletzt modifiziert: 09.10.2024, 12:50 - Dateigröße: 11.33 KiB


001  <?php
002  // -------------------------------------------------------------
003  //
004  // $Id$
005  //
006  // FILENAME  : add_permissions.php
007  // STARTED   : Sat Nov 06, 2004
008  // COPYRIGHT : � 2004 phpBB Group
009  // WWW       : http://www.phpbb.com/
010  // LICENCE   : GPL vs2.0 [ see /docs/COPYING ] 
011  // 
012  // -------------------------------------------------------------
013   
014  //
015  // Security message:
016  //
017  // This script is potentially dangerous.
018  // Remove or comment the next line (die(".... ) to enable this script.
019  // Do NOT FORGET to either remove this script or disable it after you have used it.
020  //
021  die("Please read the first lines of this script for instructions on how to enable it");
022   
023   
024  // This script adds missing permissions
025  $db = $dbhost = $dbuser = $dbpasswd = $dbport = $dbname = '';
026   
027  define('IN_PHPBB', 1);
028  define('ANONYMOUS', 1);
029  $phpEx = substr(strrchr(__FILE__, '.'), 1);
030  $phpbb_root_path='./../';
031  include($phpbb_root_path . 'config.'.$phpEx);
032  require($phpbb_root_path . 'includes/acm/acm_' . $acm_type . '.'.$phpEx);
033  require($phpbb_root_path . 'includes/db/' . $dbms . '.'.$phpEx);
034  include($phpbb_root_path . 'includes/functions.'.$phpEx);
035   
036  define('ACL_NEVER', 0);
037  define('ACL_YES', 1);
038  define('ACL_NO', -1);
039   
040  define('ACL_GROUPS_TABLE', $table_prefix.'acl_groups');
041  define('ACL_OPTIONS_TABLE', $table_prefix.'acl_options');
042  define('ACL_USERS_TABLE', $table_prefix.'acl_users');
043  define('GROUPS_TABLE', $table_prefix.'groups');
044  define('USERS_TABLE', $table_prefix.'users');
045   
046  $cache        = new acm();
047  $db            = new sql_db();
048   
049  // Connect to DB
050  $db->sql_connect($dbhost, $dbuser, $dbpasswd, $dbname, $dbport, false);
051   
052  // auth => is_local, is_global
053  $f_permissions = array(
054      'f_'        => array(1, 0),
055      'f_list'    => array(1, 0),
056      'f_read'    => array(1, 0),
057      'f_post'    => array(1, 0),
058      'f_reply'    => array(1, 0),
059      'f_edit'    => array(1, 0),
060      'f_user_lock'    => array(1, 0),
061      'f_delete'    => array(1, 0),
062      'f_bump'    => array(1, 0),
063      'f_poll'    => array(1, 0),
064      'f_vote'    => array(1, 0),
065      'f_votechg'    => array(1, 0),
066      'f_announce'=> array(1, 0),
067      'f_sticky'    => array(1, 0),
068      'f_attach'    => array(1, 0),
069      'f_download'=> array(1, 0),
070      'f_icons'    => array(1, 0),
071      'f_bbcode'    => array(1, 0),
072      'f_smilies'    => array(1, 0),
073      'f_img'        => array(1, 0),
074      'f_flash'    => array(1, 0),
075      'f_sigs'    => array(1, 0),
076      'f_search'    => array(1, 0),
077      'f_email'    => array(1, 0),
078      'f_print'    => array(1, 0),
079      'f_ignoreflood'    => array(1, 0),
080      'f_postcount'    => array(1, 0),
081      'f_noapprove'=> array(1, 0),
082      'f_report'    => array(1, 0),
083      'f_subscribe'    => array(1, 0),
084  );
085   
086  $m_permissions = array(
087      'm_'        => array(1, 1),
088      'm_edit'    => array(1, 1),
089      'm_delete'    => array(1, 1),
090      'm_move'    => array(1, 1),
091      'm_lock'    => array(1, 1),
092      'm_split'    => array(1, 1),
093      'm_merge'    => array(1, 1),
094      'm_approve'    => array(1, 1),
095      'm_unrate'    => array(1, 1),
096      'm_auth'    => array(1, 1),
097      'm_ip'        => array(1, 1),
098      'm_info'    => array(1, 1),
099  );
100   
101  $a_permissions = array(
102      'a_'        => array(0, 1),
103      'a_server'    => array(0, 1),
104      'a_board'    => array(0, 1),
105      'a_clearlogs'    => array(0, 1),
106      'a_words'    => array(0, 1),
107      'a_icons'    => array(0, 1),
108      'a_bbcode'    => array(0, 1),
109      'a_attach'    => array(0, 1),
110      'a_email'    => array(0, 1),
111      'a_styles'    => array(0, 1),
112      'a_user'    => array(0, 1),
113      'a_useradd'    => array(0, 1),
114      'a_userdel'    => array(0, 1),
115      'a_ranks'    => array(0, 1),
116      'a_ban'        => array(0, 1),
117      'a_names'    => array(0, 1),
118      'a_group'    => array(0, 1),
119      'a_groupadd'=> array(0, 1),
120      'a_groupdel'=> array(0, 1),
121      'a_forum'    => array(0, 1),
122      'a_forumadd'=> array(0, 1),
123      'a_forumdel'=> array(0, 1),
124      'a_prune'    => array(0, 1),
125      'a_auth'    => array(0, 1),
126      'a_authmods'=> array(0, 1),
127      'a_authadmins'    => array(0, 1),
128      'a_authusers'    => array(0, 1),
129      'a_authgroups'    => array(0, 1),
130      'a_authdeps'=> array(0, 1),
131      'a_backup'    => array(0, 1),
132      'a_restore'    => array(0, 1),
133      'a_search'    => array(0, 1),
134      'a_events'    => array(0, 1),
135      'a_cron'    => array(0, 1),
136  );
137   
138  $u_permissions = array(
139      'u_'            => array(0, 1),
140      'u_sendemail'    => array(0, 1),
141      'u_readpm'        => array(0, 1),
142      'u_sendpm'        => array(0, 1),
143      'u_sendim'        => array(0, 1),
144      'u_hideonline'    => array(0, 1),
145      'u_viewonline'    => array(0, 1),
146      'u_viewprofile'    => array(0, 1),
147      'u_chgavatar'    => array(0, 1),
148      'u_chggrp'        => array(0, 1),
149      'u_chgemail'    => array(0, 1),
150      'u_chgname'        => array(0, 1),
151      'u_chgpasswd'    => array(0, 1),
152      'u_chgcensors'    => array(0, 1),
153      'u_search'        => array(0, 1),
154      'u_savedrafts'    => array(0, 1),
155      'u_download'    => array(0, 1),
156      'u_attach'        => array(0, 1),
157      'u_sig'            => array(0, 1),
158      'u_pm_attach'    => array(0, 1),
159      'u_pm_bbcode'    => array(0, 1),
160      'u_pm_smilies'    => array(0, 1),
161      'u_pm_download'    => array(0, 1),
162      'u_pm_edit'        => array(0, 1),
163      'u_pm_printpm'    => array(0, 1),
164      'u_pm_emailpm'    => array(0, 1),
165      'u_pm_forward'    => array(0, 1),
166      'u_pm_delete'    => array(0, 1),
167      'u_pm_img'        => array(0, 1),
168      'u_pm_flash'    => array(0, 1),
169  );
170   
171  echo "<p><b>Determining existing permissions</b></p>\n";
172   
173  $sql = 'SELECT auth_option_id, auth_option FROM ' . ACL_OPTIONS_TABLE;
174  $result = $db->sql_query($sql);
175   
176  $remove_auth_options = array();
177  while ($row = $db->sql_fetchrow($result))
178  {
179      if (!in_array($row['auth_option'], array_keys(${substr($row['auth_option'], 0, 2) . 'permissions'})))
180      {
181          $remove_auth_options[$row['auth_option']] = $row['auth_option_id'];
182      }
183      unset(${substr($row['auth_option'], 0, 2) . 'permissions'}[$row['auth_option']]);
184  }
185  $db->sql_freeresult($result);
186   
187  if (sizeof($remove_auth_options))
188  {
189      $db->sql_query('DELETE FROM ' . ACL_USERS_TABLE . ' WHERE auth_option_id IN (' . implode(', ', $remove_auth_options) . ')');
190      $db->sql_query('DELETE FROM ' . ACL_GROUPS_TABLE . ' WHERE auth_option_id IN (' . implode(', ', $remove_auth_options) . ')');
191      $db->sql_query('DELETE FROM ' . ACL_OPTIONS_TABLE . ' WHERE auth_option_id IN (' . implode(', ', $remove_auth_options) . ')');
192   
193      echo '<p><b>Removed the following auth options... [<i>' . implode(', ', array_keys($remove_auth_options)) . "</i>]</b></p>\n\n";
194  }
195   
196  $prefixes = array('f_', 'a_', 'm_', 'u_');
197   
198  foreach ($prefixes as $prefix)
199  {
200      $var = $prefix . 'permissions';
201      if (sizeof($$var))
202      {
203          foreach ($$var as $auth_option => $l_ary)
204          {
205              $sql_ary = array(
206                  'auth_option'    => $auth_option,
207                  'is_local'        => $l_ary[0],
208                  'is_global'        => $l_ary[1]
209              );
210   
211              $db->sql_query('INSERT INTO ' . ACL_OPTIONS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary));
212          
213              echo "<p><b>Adding $auth_option...</b></p>\n";
214   
215              mass_auth('group', 0, 'guests', $auth_option, ACL_NEVER);
216              mass_auth('group', 0, 'inactive', $auth_option, ACL_NEVER);
217              mass_auth('group', 0, 'inactive_coppa', $auth_option, ACL_NEVER);
218              mass_auth('group', 0, 'registered_coppa', $auth_option, ACL_NEVER);
219              mass_auth('group', 0, 'registered', $auth_option, (($prefix != 'm_' && $prefix != 'a_') ? ACL_YES : ACL_NEVER));
220              mass_auth('group', 0, 'global_moderators', $auth_option, (($prefix != 'a_') ? ACL_YES : ACL_NEVER));
221              mass_auth('group', 0, 'administrators', $auth_option, ACL_YES);
222              mass_auth('group', 0, 'bots', $auth_option, (($prefix != 'm_' && $prefix != 'a_') ? ACL_YES : ACL_NEVER));
223          }
224      }
225  }
226   
227  $sql = 'UPDATE ' . USERS_TABLE . " SET user_permissions = ''";
228  $db->sql_query($sql);
229   
230  $cache->destroy('_acl_options');
231   
232  echo "<p><b>Done</b></p>\n";
233   
234  /*
235      $ug_type = user|group
236      $forum_id = forum ids (array|int|0) -> 0 == all forums
237      $ug_id = [int] user_id|group_id : [string] usergroup name
238      $acl_list = [string] acl entry : [array] acl entries
239      $setting = ACL_YES|ACL_NEVER|ACL_NO
240  */
241  function mass_auth($ug_type, $forum_id, $ug_id, $acl_list, $setting)
242  {
243      global $db;
244      static $acl_option_ids, $group_ids;
245   
246      if ($ug_type == 'group' && is_string($ug_id))
247      {
248          if (!isset($group_ids[$ug_id]))
249          {
250              $sql = 'SELECT group_id FROM ' . GROUPS_TABLE . 
251                  WHERE group_name = '" . strtoupper($ug_id) . "'";
252              $result = $db->sql_query_limit($sql, 1);
253              $id = (int) $db->sql_fetchfield('group_id', 0, $result);
254              $db->sql_freeresult($result);
255   
256              if (!$id)
257              {
258                  return;
259              }
260   
261              $group_ids[$ug_id] = $id;
262          }
263   
264          $ug_id = (int) $group_ids[$ug_id];
265      }
266   
267      // Build correct parameters
268      $auth = array();
269   
270      if (!is_array($acl_list))
271      {
272          $auth = array($acl_list => $setting);
273      }
274      else
275      {
276          foreach ($acl_list as $auth_option)
277          {
278              $auth[$auth_option] = $setting;
279          }
280      }
281      unset($acl_list);
282   
283      if (!is_array($forum_id))
284      {
285          $forum_id = array($forum_id);
286      }
287   
288      // Set any flags as required
289      foreach ($auth as $auth_option => $acl_setting)
290      {
291          $flag = substr($auth_option, 0, strpos($auth_option, '_') + 1);
292          if (empty($auth[$flag]))
293          {
294              $auth[$flag] = $acl_setting;
295          }
296      }
297   
298      if (!is_array($acl_option_ids) || empty($acl_option_ids))
299      {
300          $sql = 'SELECT auth_option_id, auth_option
301              FROM ' . ACL_OPTIONS_TABLE;
302          $result = $db->sql_query($sql);
303   
304          while ($row = $db->sql_fetchrow($result))
305          {
306              $acl_option_ids[$row['auth_option']] = $row['auth_option_id'];
307          }
308          $db->sql_freeresult($result);
309      }
310   
311      $sql_forum = 'AND a.forum_id IN (' . implode(', ', array_map('intval', $forum_id)) . ')';
312   
313      $sql = ($ug_type == 'user') ? 'SELECT o.auth_option_id, o.auth_option, a.forum_id, a.auth_setting FROM ' . ACL_USERS_TABLE . ' a, ' . ACL_OPTIONS_TABLE . " o WHERE a.auth_option_id = o.auth_option_id $sql_forum AND a.user_id = $ug_id" : 'SELECT o.auth_option_id, o.auth_option, a.forum_id, a.auth_setting FROM ' . ACL_GROUPS_TABLE . ' a, ' . ACL_OPTIONS_TABLE . " o WHERE a.auth_option_id = o.auth_option_id $sql_forum AND a.group_id = $ug_id";
314      $result = $db->sql_query($sql);
315   
316      $cur_auth = array();
317      while ($row = $db->sql_fetchrow($result))
318      {
319          $cur_auth[$row['forum_id']][$row['auth_option_id']] = $row['auth_setting'];
320      }
321      $db->sql_freeresult($result);
322   
323      $table = ($ug_type == 'user') ? ACL_USERS_TABLE : ACL_GROUPS_TABLE;
324      $id_field  = $ug_type . '_id';
325   
326      $sql_ary = array();
327      foreach ($forum_id as $forum)
328      {
329          foreach ($auth as $auth_option => $setting)
330          {
331              $auth_option_id = $acl_option_ids[$auth_option];
332   
333              if (!$auth_option_id)
334              {
335                  continue;
336              }
337   
338              switch ($setting)
339              {
340                  case ACL_NO:
341                      if (isset($cur_auth[$forum][$auth_option_id]))
342                      {
343                          $sql_ary['delete'][] = "DELETE FROM $table 
344                              WHERE forum_id = $forum
345                                  AND auth_option_id = $auth_option_id
346                                  AND $id_field = $ug_id";
347                      }
348                      break;
349   
350                  default:
351                      if (!isset($cur_auth[$forum][$auth_option_id]))
352                      {
353                          $sql_ary['insert'][] = "$ug_id$forum$auth_option_id$setting";
354                      }
355                      else if ($cur_auth[$forum][$auth_option_id] != $setting)
356                      {
357                          $sql_ary['update'][] = "UPDATE " . $table . " 
358                              SET auth_setting = $setting 
359                              WHERE $id_field = $ug_id 
360                                  AND forum_id = $forum 
361                                  AND auth_option_id = $auth_option_id";
362                      }
363              }
364          }
365      }
366      unset($cur_auth);
367   
368      $sql = '';
369      foreach ($sql_ary as $sql_type => $sql_subary)
370      {
371          switch ($sql_type)
372          {
373              case 'insert':
374                  switch ($db->sql_layer)
375                  {
376                      case 'mysql':
377                      case 'mysql4':
378                          $sql = 'VALUES ' . implode(', ', preg_replace('#^(.*?)$#', '(\1)', $sql_subary));
379                          break;
380   
381                      case 'mssql':
382                      case 'sqlite':
383                          $sql = implode(' UNION ALL ', preg_replace('#^(.*?)$#', 'SELECT \1', $sql_subary));
384                          break;
385   
386                      default:
387                          foreach ($sql_subary as $sql)
388                          {
389                              $sql = "INSERT INTO $table ($id_field, forum_id, auth_option_id, auth_setting) VALUES ($sql)";
390                              $result = $db->sql_query($sql);
391                              $sql = '';
392                          }
393                  }
394   
395                  if ($sql != '')
396                  {
397                      $sql = "INSERT INTO $table ($id_field, forum_id, auth_option_id, auth_setting) $sql";
398                      $result = $db->sql_query($sql);
399                  }
400                  break;
401   
402              case 'update':
403              case 'delete':
404                  foreach ($sql_subary as $sql)
405                  {
406                      $result = $db->sql_query($sql);
407                      $sql = '';
408                  }
409                  break;
410          }
411          unset($sql_ary[$sql_type]);
412      }
413      unset($sql_ary);
414   
415  }
416   
417  ?>