Verzeichnisstruktur phpBB-3.1.0


Veröffentlicht
27.10.2014

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

acp_bots.php

Zuletzt modifiziert: 09.10.2024, 12:52 - Dateigröße: 12.17 KiB


 001  <?php
 002  /**
 003  *
 004  * This file is part of the phpBB Forum Software package.
 005  *
 006  * @copyright (c) phpBB Limited <https://www.phpbb.com>
 007  * @license GNU General Public License, version 2 (GPL-2.0)
 008  *
 009  * For full copyright and license information, please see
 010  * the docs/CREDITS.txt file.
 011  *
 012  */
 013   
 014  /**
 015  * @ignore
 016  */
 017  if (!defined('IN_PHPBB'))
 018  {
 019      exit;
 020  }
 021   
 022  class acp_bots
 023  {
 024      var $u_action;
 025   
 026      function main($id, $mode)
 027      {
 028          global $config, $db, $user, $auth, $template, $cache, $request;
 029          global $phpbb_root_path, $phpbb_admin_path, $phpEx, $table_prefix;
 030   
 031          $action = request_var('action', '');
 032          $submit = (isset($_POST['submit'])) ? true : false;
 033          $mark    = request_var('mark', array(0));
 034          $bot_id    = request_var('id', 0);
 035   
 036          if (isset($_POST['add']))
 037          {
 038              $action = 'add';
 039          }
 040   
 041          $error = array();
 042   
 043          $user->add_lang('acp/bots');
 044          $this->tpl_name = 'acp_bots';
 045          $this->page_title = 'ACP_BOTS';
 046          $form_key = 'acp_bots';
 047          add_form_key($form_key);
 048   
 049          if ($submit && !check_form_key($form_key))
 050          {
 051              $error[] = $user->lang['FORM_INVALID'];
 052          }
 053   
 054          // User wants to do something, how inconsiderate of them!
 055          switch ($action)
 056          {
 057              case 'activate':
 058                  if ($bot_id || sizeof($mark))
 059                  {
 060                      $sql_id = ($bot_id) ? " = $bot_id" : ' IN (' . implode(', ', $mark) . ')';
 061   
 062                      $sql = 'UPDATE ' . BOTS_TABLE . "
 063                          SET bot_active = 1
 064                          WHERE bot_id $sql_id";
 065                      $db->sql_query($sql);
 066                  }
 067   
 068                  $cache->destroy('_bots');
 069              break;
 070   
 071              case 'deactivate':
 072                  if ($bot_id || sizeof($mark))
 073                  {
 074                      $sql_id = ($bot_id) ? " = $bot_id" : ' IN (' . implode(', ', $mark) . ')';
 075   
 076                      $sql = 'UPDATE ' . BOTS_TABLE . "
 077                          SET bot_active = 0
 078                          WHERE bot_id $sql_id";
 079                      $db->sql_query($sql);
 080                  }
 081   
 082                  $cache->destroy('_bots');
 083              break;
 084   
 085              case 'delete':
 086                  if ($bot_id || sizeof($mark))
 087                  {
 088                      if (confirm_box(true))
 089                      {
 090                          // We need to delete the relevant user, usergroup and bot entries ...
 091                          $sql_id = ($bot_id) ? " = $bot_id" : ' IN (' . implode(', ', $mark) . ')';
 092   
 093                          $sql = 'SELECT bot_name, user_id
 094                              FROM ' . BOTS_TABLE . "
 095                              WHERE bot_id $sql_id";
 096                          $result = $db->sql_query($sql);
 097   
 098                          $user_id_ary = $bot_name_ary = array();
 099                          while ($row = $db->sql_fetchrow($result))
 100                          {
 101                              $user_id_ary[] = (int) $row['user_id'];
 102                              $bot_name_ary[] = $row['bot_name'];
 103                          }
 104                          $db->sql_freeresult($result);
 105   
 106                          $db->sql_transaction('begin');
 107   
 108                          $sql = 'DELETE FROM ' . BOTS_TABLE . "
 109                              WHERE bot_id $sql_id";
 110                          $db->sql_query($sql);
 111   
 112                          if (sizeof($user_id_ary))
 113                          {
 114                              $_tables = array(USERS_TABLE, USER_GROUP_TABLE);
 115                              foreach ($_tables as $table)
 116                              {
 117                                  $sql = "DELETE FROM $table
 118                                      WHERE " . $db->sql_in_set('user_id', $user_id_ary);
 119                                  $db->sql_query($sql);
 120                              }
 121                          }
 122   
 123                          $db->sql_transaction('commit');
 124   
 125                          $cache->destroy('_bots');
 126   
 127                          add_log('admin', 'LOG_BOT_DELETE', implode(', ', $bot_name_ary));
 128                          trigger_error($user->lang['BOT_DELETED'] . adm_back_link($this->u_action));
 129                      }
 130                      else
 131                      {
 132                          confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array(
 133                              'mark'        => $mark,
 134                              'id'        => $bot_id,
 135                              'mode'        => $mode,
 136                              'action'    => $action))
 137                          );
 138                      }
 139                  }
 140              break;
 141   
 142              case 'edit':
 143              case 'add':
 144                  include_once($phpbb_root_path . 'includes/functions_user.' . $phpEx);
 145   
 146                  $bot_row = array(
 147                      'bot_name'        => utf8_normalize_nfc(request_var('bot_name', '', true)),
 148                      'bot_agent'        => request_var('bot_agent', ''),
 149                      'bot_ip'        => request_var('bot_ip', ''),
 150                      'bot_active'    => request_var('bot_active', true),
 151                      'bot_lang'        => request_var('bot_lang', $config['default_lang']),
 152                      'bot_style'        => request_var('bot_style' , $config['default_style']),
 153                  );
 154   
 155                  if ($submit)
 156                  {
 157                      if (!$bot_row['bot_agent'] && !$bot_row['bot_ip'])
 158                      {
 159                          $error[] = $user->lang['ERR_BOT_NO_MATCHES'];
 160                      }
 161   
 162                      if ($bot_row['bot_ip'] && !preg_match('#^[\d\.,:]+$#', $bot_row['bot_ip']))
 163                      {
 164                          if (!$ip_list = gethostbynamel($bot_row['bot_ip']))
 165                          {
 166                              $error[] = $user->lang['ERR_BOT_NO_IP'];
 167                          }
 168                          else
 169                          {
 170                              $bot_row['bot_ip'] = implode(',', $ip_list);
 171                          }
 172                      }
 173                      $bot_row['bot_ip'] = str_replace(' ', '', $bot_row['bot_ip']);
 174   
 175                      // Make sure the admin is not adding a bot with an user agent similar to his one
 176                      if ($bot_row['bot_agent'] && substr($user->data['session_browser'], 0, 149) === substr($bot_row['bot_agent'], 0, 149))
 177                      {
 178                          $error[] = $user->lang['ERR_BOT_AGENT_MATCHES_UA'];
 179                      }
 180   
 181                      $bot_name = false;
 182                      if ($bot_id)
 183                      {
 184                          $sql = 'SELECT u.username_clean
 185                              FROM ' . BOTS_TABLE . ' b, ' . USERS_TABLE . " u
 186                              WHERE b.bot_id = $bot_id
 187                                  AND u.user_id = b.user_id";
 188                          $result = $db->sql_query($sql);
 189                          $row = $db->sql_fetchrow($result);
 190                          $db->sql_freeresult($result);
 191   
 192                          if (!$bot_row)
 193                          {
 194                              $error[] = $user->lang['NO_BOT'];
 195                          }
 196                          else
 197                          {
 198                              $bot_name = $row['username_clean'];
 199                          }
 200                      }
 201                      if (!$this->validate_botname($bot_row['bot_name'], $bot_name))
 202                      {
 203                          $error[] = $user->lang['BOT_NAME_TAKEN'];
 204                      }
 205   
 206                      if (!sizeof($error))
 207                      {
 208                          // New bot? Create a new user and group entry
 209                          if ($action == 'add')
 210                          {
 211                              $sql = 'SELECT group_id, group_colour
 212                                  FROM ' . GROUPS_TABLE . "
 213                                  WHERE group_name = 'BOTS'
 214                                      AND group_type = " . GROUP_SPECIAL;
 215                              $result = $db->sql_query($sql);
 216                              $group_row = $db->sql_fetchrow($result);
 217                              $db->sql_freeresult($result);
 218   
 219                              if (!$group_row)
 220                              {
 221                                  trigger_error($user->lang['NO_BOT_GROUP'] . adm_back_link($this->u_action . "&amp;id=$bot_id&amp;action=$action"), E_USER_WARNING);
 222                              }
 223   
 224                              $user_id = user_add(array(
 225                                  'user_type'                => (int) USER_IGNORE,
 226                                  'group_id'                => (int) $group_row['group_id'],
 227                                  'username'                => (string) $bot_row['bot_name'],
 228                                  'user_regdate'            => time(),
 229                                  'user_password'            => '',
 230                                  'user_colour'            => (string) $group_row['group_colour'],
 231                                  'user_email'            => '',
 232                                  'user_lang'                => (string) $bot_row['bot_lang'],
 233                                  'user_style'            => (int) $bot_row['bot_style'],
 234                                  'user_allow_massemail'    => 0,
 235                              ));
 236   
 237                              $sql = 'INSERT INTO ' . BOTS_TABLE . ' ' . $db->sql_build_array('INSERT', array(
 238                                  'user_id'        => (int) $user_id,
 239                                  'bot_name'        => (string) $bot_row['bot_name'],
 240                                  'bot_active'    => (int) $bot_row['bot_active'],
 241                                  'bot_agent'        => (string) $bot_row['bot_agent'],
 242                                  'bot_ip'        => (string) $bot_row['bot_ip'])
 243                              );
 244                              $db->sql_query($sql);
 245   
 246                              $log = 'ADDED';
 247                          }
 248                          else if ($bot_id)
 249                          {
 250                              $sql = 'SELECT user_id, bot_name
 251                                  FROM ' . BOTS_TABLE . "
 252                                  WHERE bot_id = $bot_id";
 253                              $result = $db->sql_query($sql);
 254                              $row = $db->sql_fetchrow($result);
 255                              $db->sql_freeresult($result);
 256   
 257                              if (!$row)
 258                              {
 259                                  trigger_error($user->lang['NO_BOT'] . adm_back_link($this->u_action . "&amp;id=$bot_id&amp;action=$action"), E_USER_WARNING);
 260                              }
 261   
 262                              $sql_ary = array(
 263                                  'user_style'    => (int) $bot_row['bot_style'],
 264                                  'user_lang'        => (string) $bot_row['bot_lang'],
 265                              );
 266   
 267                              if ($bot_row['bot_name'] !== $row['bot_name'])
 268                              {
 269                                  $sql_ary['username'] = (string) $bot_row['bot_name'];
 270                                  $sql_ary['username_clean'] = (string) utf8_clean_string($bot_row['bot_name']);
 271                              }
 272   
 273                              $sql = 'UPDATE ' . USERS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . " WHERE user_id = {$row['user_id']}";
 274                              $db->sql_query($sql);
 275   
 276                              $sql = 'UPDATE ' . BOTS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', array(
 277                                  'bot_name'        => (string) $bot_row['bot_name'],
 278                                  'bot_active'    => (int) $bot_row['bot_active'],
 279                                  'bot_agent'        => (string) $bot_row['bot_agent'],
 280                                  'bot_ip'        => (string) $bot_row['bot_ip'])
 281                              ) . " WHERE bot_id = $bot_id";
 282                              $db->sql_query($sql);
 283   
 284                              // Updated username?
 285                              if ($bot_row['bot_name'] !== $row['bot_name'])
 286                              {
 287                                  user_update_name($row['bot_name'], $bot_row['bot_name']);
 288                              }
 289   
 290                              $log = 'UPDATED';
 291                          }
 292   
 293                          $cache->destroy('_bots');
 294   
 295                          add_log('admin', 'LOG_BOT_' . $log, $bot_row['bot_name']);
 296                          trigger_error($user->lang['BOT_' . $log] . adm_back_link($this->u_action));
 297   
 298                      }
 299                  }
 300                  else if ($bot_id)
 301                  {
 302                      $sql = 'SELECT b.*, u.user_lang, u.user_style
 303                          FROM ' . BOTS_TABLE . ' b, ' . USERS_TABLE . " u
 304                          WHERE b.bot_id = $bot_id
 305                              AND u.user_id = b.user_id";
 306                      $result = $db->sql_query($sql);
 307                      $bot_row = $db->sql_fetchrow($result);
 308                      $db->sql_freeresult($result);
 309   
 310                      if (!$bot_row)
 311                      {
 312                          trigger_error($user->lang['NO_BOT'] . adm_back_link($this->u_action . "&amp;id=$bot_id&amp;action=$action"), E_USER_WARNING);
 313                      }
 314   
 315                      $bot_row['bot_lang'] = $bot_row['user_lang'];
 316                      $bot_row['bot_style'] = $bot_row['user_style'];
 317                      unset($bot_row['user_lang'], $bot_row['user_style']);
 318                  }
 319   
 320                  $s_active_options = '';
 321                  $_options = array('0' => 'NO', '1' => 'YES');
 322                  foreach ($_options as $value => $lang)
 323                  {
 324                      $selected = ($bot_row['bot_active'] == $value) ? ' selected="selected"' : '';
 325                      $s_active_options .= '<option value="' . $value . '"' . $selected . '>' . $user->lang[$lang] . '</option>';
 326                  }
 327   
 328                  $style_select = style_select($bot_row['bot_style'], true);
 329                  $lang_select = language_select($bot_row['bot_lang']);
 330   
 331                  $l_title = ($action == 'edit') ? 'EDIT' : 'ADD';
 332   
 333                  $template->assign_vars(array(
 334                      'L_TITLE'        => $user->lang['BOT_' . $l_title],
 335                      'U_ACTION'        => $this->u_action . "&amp;id=$bot_id&amp;action=$action",
 336                      'U_BACK'        => $this->u_action,
 337                      'ERROR_MSG'        => (sizeof($error)) ? implode('<br />', $error) : '',
 338   
 339                      'BOT_NAME'        => $bot_row['bot_name'],
 340                      'BOT_IP'        => $bot_row['bot_ip'],
 341                      'BOT_AGENT'        => $bot_row['bot_agent'],
 342   
 343                      'S_EDIT_BOT'        => true,
 344                      'S_ACTIVE_OPTIONS'    => $s_active_options,
 345                      'S_STYLE_OPTIONS'    => $style_select,
 346                      'S_LANG_OPTIONS'    => $lang_select,
 347                      'S_ERROR'            => (sizeof($error)) ? true : false,
 348                      )
 349                  );
 350   
 351                  return;
 352   
 353              break;
 354          }
 355   
 356          if ($request->is_ajax() && ($action == 'activate' || $action == 'deactivate'))
 357          {
 358              $json_response = new \phpbb\json_response;
 359              $json_response->send(array(
 360                  'text'    => $user->lang['BOT_' . (($action == 'activate') ? 'DE' : '') . 'ACTIVATE'],
 361              ));
 362          }
 363   
 364          $s_options = '';
 365          $_options = array('activate' => 'BOT_ACTIVATE', 'deactivate' => 'BOT_DEACTIVATE', 'delete' => 'DELETE');
 366          foreach ($_options as $value => $lang)
 367          {
 368              $s_options .= '<option value="' . $value . '">' . $user->lang[$lang] . '</option>';
 369          }
 370   
 371          $template->assign_vars(array(
 372              'U_ACTION'        => $this->u_action,
 373              'S_BOT_OPTIONS'    => $s_options)
 374          );
 375   
 376          $sql = 'SELECT b.bot_id, b.bot_name, b.bot_active, u.user_lastvisit
 377              FROM ' . BOTS_TABLE . ' b, ' . USERS_TABLE . ' u
 378              WHERE u.user_id = b.user_id
 379              ORDER BY u.user_lastvisit DESC, b.bot_name ASC';
 380          $result = $db->sql_query($sql);
 381   
 382          while ($row = $db->sql_fetchrow($result))
 383          {
 384              $active_lang = (!$row['bot_active']) ? 'BOT_ACTIVATE' : 'BOT_DEACTIVATE';
 385              $active_value = (!$row['bot_active']) ? 'activate' : 'deactivate';
 386   
 387              $template->assign_block_vars('bots', array(
 388                  'BOT_NAME'        => $row['bot_name'],
 389                  'BOT_ID'        => $row['bot_id'],
 390                  'LAST_VISIT'    => ($row['user_lastvisit']) ? $user->format_date($row['user_lastvisit']) : $user->lang['BOT_NEVER'],
 391   
 392                  'U_ACTIVATE_DEACTIVATE'    => $this->u_action . "&amp;id={$row['bot_id']}&amp;action=$active_value",
 393                  'L_ACTIVATE_DEACTIVATE'    => $user->lang[$active_lang],
 394                  'U_EDIT'                => $this->u_action . "&amp;id={$row['bot_id']}&amp;action=edit",
 395                  'U_DELETE'                => $this->u_action . "&amp;id={$row['bot_id']}&amp;action=delete")
 396              );
 397          }
 398          $db->sql_freeresult($result);
 399      }
 400   
 401      /**
 402      * Validate bot name against username table
 403      */
 404      function validate_botname($newname, $oldname = false)
 405      {
 406          global $db;
 407   
 408          if ($oldname && utf8_clean_string($newname) === $oldname)
 409          {
 410              return true;
 411          }
 412   
 413          // Admins might want to use names otherwise forbidden, thus we only check for duplicates.
 414          $sql = 'SELECT username
 415              FROM ' . USERS_TABLE . "
 416              WHERE username_clean = '" . $db->sql_escape(utf8_clean_string($newname)) . "'";
 417          $result = $db->sql_query($sql);
 418          $row = $db->sql_fetchrow($result);
 419          $db->sql_freeresult($result);
 420   
 421          return ($row) ? false : true;
 422      }
 423  }
 424