]> git.immae.eu Git - github/shaarli/Shaarli.git/commitdiff
Merge pull request #1273 from ArthurHoaro/feature/ban-manager
authorArthurHoaro <arthur@hoa.ro>
Sat, 25 May 2019 14:13:56 +0000 (16:13 +0200)
committerGitHub <noreply@github.com>
Sat, 25 May 2019 14:13:56 +0000 (16:13 +0200)
Rewrite IP ban management

1  2 
doc/md/Server-configuration.md
index.php

index 4753df1d5fa817cb02a714423b962b5cce531703,0930a4896c04c383500c0e854eabc6c939af0be8..88eed8e6eb566074498b4fef418c306bd030e3c2
@@@ -17,7 -17,7 +17,7 @@@ Version | Status | Shaarli compatibilit
  :---:|:---:|:---:
  7.2 | Supported | Yes
  7.1 | Supported | Yes
 -7.0 | Supported | Yes
 +7.0 | EOL: 2018-12-03 | Yes (up to Shaarli 0.10.x)
  5.6 | EOL: 2018-12-31 | Yes (up to Shaarli 0.10.x)
  5.5 | EOL: 2016-07-10 | Yes
  5.4 | EOL: 2015-09-14 | Yes (up to Shaarli 0.8.x)
@@@ -404,6 -404,8 +404,8 @@@ If Shaarli is served behind a proxy (i.
  - `X-Forwarded-Host`
  - `X-Forwarded-For`
  
+ In you [Shaarli configuration](Shaarli-configuration) `data/config.json.php`, add the public IP of your proxy under `security.trusted_proxies`.
  See also [proxy-related](https://github.com/shaarli/Shaarli/issues?utf8=%E2%9C%93&q=label%3Aproxy+) issues.
  
  ## Robots and crawlers
diff --combined index.php
index 68e0364cbdba182af47337f52d4767e9f7e982a2,a27681dc20f43c86e72f935d96fbd06ef1efb5ad..ff42114c3bb9ef3b365d99ce6a83635f592b558c
+++ b/index.php
@@@ -125,7 -125,7 +125,7 @@@ if (isset($_COOKIE['shaarli']) && !Sess
  
  $conf = new ConfigManager();
  $sessionManager = new SessionManager($_SESSION, $conf);
- $loginManager = new LoginManager($GLOBALS, $conf, $sessionManager);
+ $loginManager = new LoginManager($conf, $sessionManager);
  $loginManager->generateStaySignedInToken($_SERVER['REMOTE_ADDR']);
  $clientIpId = client_ip_id($_SERVER);
  
@@@ -312,7 -312,9 +312,7 @@@ function showDailyRSS($conf, $loginMana
      $LINKSDB = new LinkDB(
          $conf->get('resource.datastore'),
          $loginManager->isLoggedIn(),
 -        $conf->get('privacy.hide_public_links'),
 -        $conf->get('redirector.url'),
 -        $conf->get('redirector.encode_url')
 +        $conf->get('privacy.hide_public_links')
      );
  
      /* Some Shaarlies may have very few links, so we need to look
  
          // We pre-format some fields for proper output.
          foreach ($links as &$link) {
 -            $link['formatedDescription'] = format_description(
 -                $link['description'],
 -                $conf->get('redirector.url'),
 -                $conf->get('redirector.encode_url')
 -            );
 +            $link['formatedDescription'] = format_description($link['description']);
              $link['timestamp'] = $link['created']->getTimestamp();
 -            if (startsWith($link['url'], '?')) {
 +            if (is_note($link['url'])) {
                  $link['url'] = index_url($_SERVER) . $link['url'];  // make permalink URL absolute
              }
          }
@@@ -427,7 -433,11 +427,7 @@@ function showDaily($pageBuilder, $LINKS
          $taglist = explode(' ', $link['tags']);
          uasort($taglist, 'strcasecmp');
          $linksToDisplay[$key]['taglist']=$taglist;
 -        $linksToDisplay[$key]['formatedDescription'] = format_description(
 -            $link['description'],
 -            $conf->get('redirector.url'),
 -            $conf->get('redirector.encode_url')
 -        );
 +        $linksToDisplay[$key]['formatedDescription'] = format_description($link['description']);
          $linksToDisplay[$key]['timestamp'] =  $link['created']->getTimestamp();
      }
  
@@@ -1064,6 -1074,7 +1064,6 @@@ function renderPage($conf, $pluginManag
              $PAGE->assign('api_enabled', $conf->get('api.enabled', true));
              $PAGE->assign('api_secret', $conf->get('api.secret'));
              $PAGE->assign('languages', Languages::getAvailableLanguages());
 -            $PAGE->assign('language', $conf->get('translation.language'));
              $PAGE->assign('gd_enabled', extension_loaded('gd'));
              $PAGE->assign('thumbnails_mode', $conf->get('thumbnails.mode', Thumbnailer::MODE_NONE));
              $PAGE->assign('pagetitle', t('Configure') .' - '. $conf->get('general.title', 'Shaarli'));
              $link['title'] = $link['url'];
          }
  
 -        if ($conf->get('thumbnails.mode', Thumbnailer::MODE_NONE) !== Thumbnailer::MODE_NONE) {
 +        if ($conf->get('thumbnails.mode', Thumbnailer::MODE_NONE) !== Thumbnailer::MODE_NONE
 +            && ! is_note($link['url'])
 +        ) {
              $thumbnailer = new Thumbnailer($conf);
              $link['thumbnail'] = $thumbnailer->get($url);
          }
  
 +        $link['sticky'] = isset($link['sticky']) ? $link['sticky'] : false;
 +
          $pluginManager->executeHooks('save_link', $link);
  
          $LINKSDB[$id] = $link;
          exit;
      }
  
 +    // -------- User clicked either "Set public" or "Set private" bulk operation
 +    if ($targetPage == Router::$PAGE_CHANGE_VISIBILITY) {
 +        if (! $sessionManager->checkToken($_GET['token'])) {
 +            die(t('Wrong token.'));
 +        }
 +
 +        $ids = trim($_GET['ids']);
 +        if (strpos($ids, ' ') !== false) {
 +            // multiple, space-separated ids provided
 +            $ids = array_values(array_filter(preg_split('/\s+/', escape($ids))));
 +        } else {
 +            // only a single id provided
 +            $ids = [$ids];
 +        }
 +
 +        // assert at least one id is given
 +        if (!count($ids)) {
 +            die('no id provided');
 +        }
 +        // assert that the visibility is valid
 +        if (!isset($_GET['newVisibility']) || !in_array($_GET['newVisibility'], ['public', 'private'])) {
 +            die('invalid visibility');
 +        } else {
 +            $private = $_GET['newVisibility'] === 'private';
 +        }
 +        foreach ($ids as $id) {
 +            $id = (int) escape($id);
 +            $link = $LINKSDB[$id];
 +            $link['private'] = $private;
 +            $pluginManager->executeHooks('save_link', $link);
 +            $LINKSDB[$id] = $link;
 +        }
 +        $LINKSDB->save($conf->get('resource.page_cache')); // save to disk
 +
 +        $location = '?';
 +        if (isset($_SERVER['HTTP_REFERER'])) {
 +            $location = generateLocation(
 +                $_SERVER['HTTP_REFERER'],
 +                $_SERVER['HTTP_HOST']
 +            );
 +        }
 +        header('Location: ' . $location); // After deleting the link, redirect to appropriate location
 +        exit;
 +    }
 +
      // -------- User clicked the "EDIT" button on a link: Display link edit form.
      if (isset($_GET['edit_link'])) {
          $id = (int) escape($_GET['edit_link']);
          $ids = [];
          foreach ($LINKSDB as $link) {
              // A note or not HTTP(S)
 -            if ($link['url'][0] === '?' || ! startsWith(strtolower($link['url']), 'http')) {
 +            if (is_note($link['url']) || ! startsWith(strtolower($link['url']), 'http')) {
                  continue;
              }
              $ids[] = $link['id'];
@@@ -1700,7 -1662,11 +1700,7 @@@ function buildLinkList($PAGE, $LINKSDB
      $linkDisp = array();
      while ($i<$end && $i<count($keys)) {
          $link = $linksToDisplay[$keys[$i]];
 -        $link['description'] = format_description(
 -            $link['description'],
 -            $conf->get('redirector.url'),
 -            $conf->get('redirector.encode_url')
 -        );
 +        $link['description'] = format_description($link['description']);
          $classLi =  ($i % 2) != 0 ? '' : 'publicLinkHightLight';
          $link['class'] = $link['private'] == 0 ? $classLi : 'private';
          $link['timestamp'] = $link['created']->getTimestamp();
          'search_term' => $searchterm,
          'search_tags' => $searchtags,
          'visibility' => ! empty($_SESSION['visibility']) ? $_SESSION['visibility'] : '',
 -        'redirector' => $conf->get('redirector.url'),  // Optional redirector URL.
          'links' => $linkDisp,
      );
  
@@@ -1910,7 -1877,9 +1910,7 @@@ try 
  $linkDb = new LinkDB(
      $conf->get('resource.datastore'),
      $loginManager->isLoggedIn(),
 -    $conf->get('privacy.hide_public_links'),
 -    $conf->get('redirector.url'),
 -    $conf->get('redirector.encode_url')
 +    $conf->get('privacy.hide_public_links')
  );
  
  $container = new \Slim\Container();
@@@ -1933,7 -1902,7 +1933,7 @@@ $app->group('/api/v1', function () 
      $this->put('/tags/{tagName:[\w]+}', '\Shaarli\Api\Controllers\Tags:putTag')->setName('putTag');
      $this->delete('/tags/{tagName:[\w]+}', '\Shaarli\Api\Controllers\Tags:deleteTag')->setName('deleteTag');
  
 -    $this->get('/history', '\Shaarli\Api\Controllers\History:getHistory')->setName('getHistory');
 +    $this->get('/history', '\Shaarli\Api\Controllers\HistoryController:getHistory')->setName('getHistory');
  })->add('\Shaarli\Api\ApiMiddleware');
  
  $response = $app->run(true);