Bezpiecze?stwo - dodatki pomagaj?ce adminowi

Miejsce na wszelkie dyskusje odnośnie problemów technicznych i ewentualnych pytań z rozbudowaniem systemu w plikach i skryptach Opencart, a które nie dotyczą instalacji.

Bezpieczeństwo - dodatki pomagające adminowi

Postprzez konik » 3 lut 2014, o 18:30

Witam po raz kolejny.
OpenCart się u mnie przyjął na tyle że zaczynam go rozumieć i używać.

Chciałbym jednak dowiedzieć się o narzędzia które znam np z Joomli.

Mówię tu o Akeeba Backup, Admin Tools czy RSFirewall!
Czy istnieją jakieś odpowiedniki? W Joomla się to nieźle sprawdza i pomaga adminowi. Wiem że sporo rzeczy można zrobić od strony serwera, natomiast mnie interesuje coś co można zainstalować i funkcjonalnością będzie przypominać komponenty wymienione powyżej.

Nie muszą być rozwiązania darmowe.

Z góry dzięki za podpowiedź i dyskusję w temacie.
konik
 
Posty: 3
Dołączył(a): 18 lis 2013, o 22:25

Re: Bezpieczeństwo - dodatki pomagające adminowi

Postprzez staniapl » 4 lut 2014, o 00:13

Avatar użytkownika
staniapl
 
Posty: 631
Dołączył(a): 13 lut 2012, o 19:47
Lokalizacja: Zambr?w, Nowe Piekuty

Re: Bezpieczeństwo - dodatki pomagające adminowi

Postprzez konik » 11 lut 2014, o 16:24

Ale chciałbym wiedzieć i znać próby logowania się na admina. W przypadku kilku prób odcinał by na jakiś czas możliwość logowania się.

To co podałeś nie daje takiej możliwości. Takie standardowe zabezpieczenia dla większości sklepów i CMS-ów

Czy naprawdę nie ma nic bardziej zaawansowanego?
konik
 
Posty: 3
Dołączył(a): 18 lis 2013, o 22:25

Re: Bezpieczeństwo - dodatki pomagające adminowi

Postprzez adikon.oc » 12 lut 2014, o 09:14

blokowanie admina przy trzeciej nieudanej próbie logowania na 15 min
wkleiłem tutaj cały plik ale możesz sobie go porównać ze swoim i tylko przekopiować to co zostało dodane
plik admin/controller/common/login.php
Kod: Zaznacz cały
<?php 
class ControllerCommonLogin extends Controller {
   private $error = array();
            
   public function index() {
       $this->language->load('common/login');

      $this->document->setTitle($this->language->get('heading_title'));

      if ($this->user->isLogged() && isset($this->request->get['token']) && ($this->request->get['token'] == $this->session->data['token'])) {
         $this->redirect($this->url->link('common/home', 'token=' . $this->session->data['token'], 'SSL'));
      }

      if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
         $this->session->data['token'] = md5(mt_rand());
         
         $this->clearLoginAttempts(getIp());

         if (isset($this->request->post['redirect'])) {
            $this->redirect($this->request->post['redirect'] . '&token=' . $this->session->data['token']);
         } else {
            $this->redirect($this->url->link('common/home', 'token=' . $this->session->data['token'], 'SSL'));
         }
      }
      
       $this->data['heading_title'] = $this->language->get('heading_title');
      
      $this->data['text_login'] = $this->language->get('text_login');
      $this->data['text_forgotten'] = $this->language->get('text_forgotten');
      
      $this->data['entry_username'] = $this->language->get('entry_username');
       $this->data['entry_password'] = $this->language->get('entry_password');

       $this->data['button_login'] = $this->language->get('button_login');
      
      if ((isset($this->session->data['token']) && !isset($this->request->get['token'])) || ((isset($this->request->get['token']) && (isset($this->session->data['token']) && ($this->request->get['token'] != $this->session->data['token']))))) {
         $this->error['warning'] = $this->language->get('error_token');
      }
      
      if (isset($this->error['warning'])) {
         $this->data['error_warning'] = $this->error['warning'];
      } else {
         $this->data['error_warning'] = '';
      }
      
      if (isset($this->error['attempts'])) {
         $this->data['error_attempts'] = $this->error['attempts'];
      } else {
         $this->data['error_attempts'] = '';
      }

      if (isset($this->session->data['success'])) {
          $this->data['success'] = $this->session->data['success'];
   
         unset($this->session->data['success']);
      } else {
         $this->data['success'] = '';
      }
            
       $this->data['action'] = $this->url->link('common/login', '', 'SSL');

      if (isset($this->request->post['username'])) {
         $this->data['username'] = $this->request->post['username'];
      } else {
         $this->data['username'] = '';
      }
      
      if (isset($this->request->post['password'])) {
         $this->data['password'] = $this->request->post['password'];
      } else {
         $this->data['password'] = '';
      }

      if (isset($this->request->get['route'])) {
         $route = $this->request->get['route'];
         
         unset($this->request->get['route']);
         
         if (isset($this->request->get['token'])) {
            unset($this->request->get['token']);
         }
         
         $url = '';
                  
         if ($this->request->get) {
            $url .= http_build_query($this->request->get);
         }
         
         $this->data['redirect'] = $this->url->link($route, $url, 'SSL');
      } else {
         $this->data['redirect'] = '';   
      }
      
      if ($this->config->get('config_password')) {
         $this->data['forgotten'] = $this->url->link('common/forgotten', '', 'SSL');
      } else {
         $this->data['forgotten'] = '';
      }
      
      $this->template = 'common/login.tpl';
      $this->children = array(
         'common/header',
         'common/footer'
      );
            
      $this->response->setOutput($this->render());
     }
      
   protected function validate() {
      $ip = getIp();
      $result = $this->confirmIPAddress($ip);

      if ($result == 1) {
         $this->error['attempts'] = $this->language->get('error_login_attempts');
      } else {
         if (isset($this->request->post['username']) && isset($this->request->post['password']) && !$this->user->login($this->request->post['username'], $this->request->post['password'])) {
            $this->error['warning'] = $this->language->get('error_login');

            $this->addLoginAttempt($ip);
         }
      }
      
      if (!$this->error) {
         return true;
      } else {
         return false;
      }
   }

   private function confirmIPAddress($value) {
      $query = $this->db->query("SELECT attempts, (CASE when last_login is not NULL and DATE_ADD(last_login, INTERVAL 15 MINUTE) > NOW() then 1 else 0 end) as denied FROM " . DB_PREFIX . "login_attempts WHERE ip = '" . $this->db->escape($value) . "'");

      $data = $query->row;

      if (!$data) {
         return 0;
      }

      if ($data["attempts"] >= 3) {
         if ($data["denied"] == 1) {
            return 1;
         } else {
            $this->clearLoginAttempts($value);

            return 0;
         }
      }

      return 0; 
   }

   function addLoginAttempt($value) {
      $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "login_attempts WHERE ip = '" . $this->db->escape($value) . "'");

      $data = $query->row;

      if ($data) {
         $attempts = $data["attempts"] + 1;

         if ($attempts == 3) {
            $this->db->query("UPDATE " . DB_PREFIX . "login_attempts SET attempts = " . $attempts . ", last_login = NOW() WHERE ip = '" . $this->db->escape($value) . "'");
         } else {
            $this->db->query("UPDATE " . DB_PREFIX . "login_attempts SET attempts = " . $attempts . " WHERE ip = '" . $this->db->escape($value) . "'");
         }
      } else {
         $this->db->query("INSERT INTO " . DB_PREFIX . "login_attempts (attempts, ip, last_login) values (1, '" . $this->db->escape($value) . "', NOW())");
      }
    }

   function clearLoginAttempts($value) {
      $this->db->query("UPDATE " . DB_PREFIX . "login_attempts SET attempts = 0 WHERE ip = '" . $this->db->escape($value) . "'");
   }
}

function getIp() {
   $ip = '';

   if (isset($_SERVER)) {
      if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
      elseif (isset($_SERVER['HTTP_CLIENT_IP']))   $ip = $_SERVER['HTTP_CLIENT_IP'];
      else                                         $ip = $_SERVER['REMOTE_ADDR'];
   } else {
      if (getenv('HTTP_X_FORWARDED_FOR')) $ip = getenv('HTTP_X_FORWARDED_FOR');
      elseif (getenv('HTTP_CLIENT_IP'))   $ip = getenv('HTTP_CLIENT_IP');
      else                                $ip = getenv('REMOTE_ADDR');
   }

   return $ip;
}
?>


tabela do mysql, wystarczy wrzucić przez phpmyadmin, pamiętaj o prefixie do tabel jeżeli go używasz
Kod: Zaznacz cały
CREATE TABLE IF NOT EXISTS `login_attempts` (
  `ip` varchar(20) COLLATE utf8_bin NOT NULL,
  `attempts` int(11) NOT NULL,
  `last_login` datetime NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
adikon.oc
 
Posty: 603
Dołączył(a): 28 gru 2010, o 22:56


Powrót do Pomoc techniczna przy Opencart

Kto przegląda forum

Użytkownicy przeglądający ten dział: Brak zidentyfikowanych użytkowników i 3 gości

cron