Attak from the Web - need help with hook order

Open to all! Ask other shopowners for help.
Post Reply
loop
Contributor
Posts: 253
Joined: Thu Mar 25, 2021 12:26 pm
Phoenix Version:
Has thanked: 7 times
Been thanked: 3 times

Attak from the Web - need help with hook order

Post by loop »

Hi All
i have since a couple of days alot request from strange (abusive) ip's

i have made a hook in the shop/system/_block_ip_range.php

and the idea is to block ip's on the "startApplication" so it should block BEFORE everything else will happen but i see there is alot of executed before my hook is firing. Can somebody tell me how i can make the hook that it fires +- at the beginning (but that i can make a DB Query to check ip)

that's my hook

Code: Select all

class hook_shop_system__block_ip_range {

  public function listen_startApplication() {
    //Block ip Ranges
    if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
        $ip = $_SERVER['HTTP_CLIENT_IP'];
    } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
        $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
    } else {
        $ip = $_SERVER['REMOTE_ADDR'];
    }  

    if(!empty($ip)){
      $block_ip_query_range = tep_db_query("SELECT ip_start FROM `ip_range_block` WHERE INET_ATON('".$ip."') between ip_start and ip_end limit 1");
      if (mysqli_num_rows($block_ip_query_range) > 0) {
            $block_ip_range = tep_db_fetch_array($block_ip_query_range);
            if(!empty($block_ip_range['ip_start'])){
                //Whitelist exkluden von Block
                $whitelist_ip_query_range = tep_db_query("SELECT ip_start FROM `ip_range_whitelist` WHERE INET_ATON('".$ip."') between  ip_start and ip_end limit 1");
                if (mysqli_num_rows($whitelist_ip_query_range) > 0) {
                //Blocken
                }else{
                    header('HTTP/1.0 403 Forbidden');
                    echo "Ihre IP (".$ip.") wurden aufgrund Ihrer Zugriffe gesperrt";
                    exit();
                }
            }
      }else{
        tep_db_query("INSERT INTO ip_log (ip_address, views, time) VALUES (INET_ATON('" . $ip . "'), views + 1, ".time().") ON DUPLICATE KEY UPDATE views = views + 1");
      }
    }
  }
  
}
to name a example, the ACTION = Wishlist_add from the request: /index.php?products_id=449109&action=wishlist_add is executed before my hook to block it

UPDATE: i renamed it to hook_shop_system__001_block_ip_range and it seems that it solves the problem, is that correct like this, or other name recomandations?


Join The Code Co-op to get access to your library in the Code Co-op Forum
ecartz
Core Team
Posts: 3084
Joined: Tue Nov 05, 2019 6:02 pm
Phoenix Version:
Has thanked: 4 times
Been thanked: 208 times

Re: Attak from the Web - need help with hook order

Post by ecartz »

loop wrote: Fri Mar 03, 2023 12:56 pm renamed it to hook_shop_system__001_block_ip_range and it seems that it solves the problem, is that correct like this
That's fine. It probably would have been enough to do hook_shop_system__00_block_ip_range

The database gets instantiated before any hooks run, since hooks can be stored in the database. The configure.php file is loaded before the database, since it stores the DB configuration. And the autoloader is loaded before the database as well, as it's what loads the database classes.


Join The Code Co-op to get access to your library in the Code Co-op Forum
Post Reply