Changeset 31952 for extensions/AntiAspi


Ignore:
Timestamp:
Nov 27, 2018, 4:55:02 PM (6 years ago)
Author:
plg
Message:

cleaner configuration manager on install/update

Location:
extensions/AntiAspi
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • extensions/AntiAspi/admin.php

    r31372 r31952  
    7474        break;
    7575        case 'ipconfig':
     76        antiaspi_check_old_conf();
    7677  global $conf, $template;
    7778  $admin_base_url = ANTIASPI_ADMIN . '-ipconfig';
  • extensions/AntiAspi/initadmin.php

    r31362 r31952  
    1212}
    1313 
     14function antiaspi_check_old_conf()
     15{
     16  global $page;
     17
     18  $conf = array();
     19
     20  $local_conf_filpath = PHPWG_ROOT_PATH. 'local/config/config.inc.php';
     21  if (file_exists($local_conf_filpath))
     22  {
     23    @include($local_conf_filpath);
     24  }
     25
     26  if (isset($conf['antiaspi']))
     27  {
     28    $page['errors'][] = 'we have found some antiaspi settings in your local configuration, please remove it, no longer in use.';
     29  }
     30}
  • extensions/AntiAspi/maintain.class.php

    r31370 r31952  
    44class AntiAspi_maintain extends PluginMaintain
    55{
     6  private $default_conf = array(
     7    'diff' => '20 pages in 00:00:10',
     8    'same' => '15 pages in 00:00:30',
     9    'banned during' => '23:59:59',
     10    'only guest' => true,
     11    'only picture' => false,
     12    'allowed ip' => array('123.123.123.123','122.122.122.122'),
     13    );
     14
    615  function install($plugin_version, &$errors=array())
    716  {
    8     global $prefixeTable;
     17    global $prefixeTable, $conf;
     18
     19    // add config parameter
     20    if (empty($conf['antiaspi']))
     21    {
     22      conf_update_param('antiaspi', $this->default_conf, true);
     23    }
     24    else
     25    {
     26      $old_conf = safe_unserialize($conf['antiaspi']);
     27
     28      foreach (array_keys($this->default_conf) as $conf_key)
     29      {
     30        if (!isset($old_conf[$conf_key]))
     31        {
     32          $old_conf[$conf_key] = $this->default_conf[$conf_key];
     33        }
     34      }
     35
     36      conf_update_param('antiaspi', $old_conf, true);
     37    }
    938
    1039    // table antiaspi_ip_ban to store list of banned IP addresses
     
    4372  function update($old_version, $new_version, &$errors=array())
    4473  {
    45         global $conf; 
    46          
    47         if (!isset($conf['antiaspi']))
    48       {
    49                 $conf['antiaspi'] = array(
    50                   'diff' => '20 pages in 00:00:10' ,
    51                   'same' => '15 pages in 00:00:30' ,
    52                   'banned during' => '23:59:59' ,
    53                   'only guest' => true ,
    54                   'only picture' => false ,
    55                   'allowed ip' => array('123.123.123.123','122.122.122.122'),
    56                 );
    57                 conf_update_param('antiaspi', $conf['antiaspi']);
    58       } 
    59          
    6074    $this->install($new_version, $errors);
    6175  }
     
    6781    pwg_query('DROP TABLE '.$prefixeTable.'antiaspi_ip_ban;');
    6882    pwg_query('DROP TABLE '.$prefixeTable.'antiaspi_log;');
     83
     84    // delete configuration
     85    pwg_query('DELETE FROM `'. CONFIG_TABLE .'` WHERE param IN ("antiaspi");');
    6986  }
    7087}
Note: See TracChangeset for help on using the changeset viewer.