Skip to content

Commit

Permalink
GH-230 Move proxy handling to an util
Browse files Browse the repository at this point in the history
  • Loading branch information
mdziekon committed Jul 2, 2022
1 parent 3049170 commit 0e97daf
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 29 deletions.
1 change: 1 addition & 0 deletions modules/overview/_includes.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
$includePath = $_EnginePath . 'modules/overview/';

include($includePath . './screens/FirstLogin/FirstLogin.screen.php');
include($includePath . './screens/FirstLogin/utils/effects/handleProxyDetection.effect.php');

});

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

namespace UniEngine\Engine\Modules\Overview\Screens\FirstLogin\Utils\Effects;

use UniEngine\Engine\Includes\Helpers\Users;

/**
* @param array $params
* @param arrayRef $params['user']
* @param number $params['currentTimestamp']
*/
function handleProxyDetection($props) {
global $_EnginePath, $_Included_AlertSystemUtilities;

$user = &$props['user'];
$currentTimestamp = $props['currentTimestamp'];

$usersIP = Users\Session\getCurrentIP();
$IPHash = md5($usersIP);
$Query_CheckProxy = "SELECT `ID`, `isProxy` FROM {{table}} WHERE `ValueHash` = '{$IPHash}' LIMIT 1;";
$Result_CheckProxy = doquery($Query_CheckProxy, 'used_ip_and_ua', true);
if($Result_CheckProxy['ID'] > 0 AND $Result_CheckProxy['isProxy'] == 1)
{
if(!isset($_Included_AlertSystemUtilities))
{
include($_EnginePath.'includes/functions/AlertSystemUtilities.php');
$_Included_AlertSystemUtilities = true;
}
$FiltersData = array();
$FiltersData['place'] = 4;
$FiltersData['alertsender'] = 5;
$FiltersData['users'] = array($user['id']);
$FiltersData['ips'] = array($Result_CheckProxy['ID']);

$FilterResult = AlertUtils_CheckFilters($FiltersData, array('DontLoad' => true, 'DontLoad_OnlyIfCacheEmpty' => true));
if($FilterResult['SendAlert'])
{
$_Alert['Data']['IPID'] = $Result_CheckProxy['ID'];
if($usersIP == $user['ip_at_reg'])
{
$_Alert['Data']['RegIP'] = true;
}

Alerts_Add(5, $currentTimestamp, 1, 3, 8, $user['id'], $_Alert['Data']);
}
}
}

?>
5 changes: 5 additions & 0 deletions modules/overview/screens/FirstLogin/utils/effects/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

header("Location: ../index.php");

?>
5 changes: 5 additions & 0 deletions modules/overview/screens/FirstLogin/utils/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

header("Location: ../index.php");

?>
35 changes: 6 additions & 29 deletions overview.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@
include_once($_EnginePath . 'modules/session/_includes.php');
include_once($_EnginePath . 'modules/flights/_includes.php');
include_once($_EnginePath . 'modules/flightControl/_includes.php');
include_once($_EnginePath . 'modules/overview/_includes.php');

use UniEngine\Engine\Includes\Helpers\Users;
use UniEngine\Engine\Includes\Helpers\World\Elements;
use UniEngine\Engine\Modules\Session;
use UniEngine\Engine\Modules\Flights;
use UniEngine\Engine\Modules\FlightControl;
use UniEngine\Engine\Modules\Overview;

loggedCheck();

Expand Down Expand Up @@ -159,35 +161,10 @@
}

// Check, if this IP is Proxy
$usersIP = Users\Session\getCurrentIP();
$IPHash = md5($usersIP);
$Query_CheckProxy = "SELECT `ID`, `isProxy` FROM {{table}} WHERE `ValueHash` = '{$IPHash}' LIMIT 1;";
$Result_CheckProxy = doquery($Query_CheckProxy, 'used_ip_and_ua', true);
if($Result_CheckProxy['ID'] > 0 AND $Result_CheckProxy['isProxy'] == 1)
{
if(!isset($_Included_AlertSystemUtilities))
{
include($_EnginePath.'includes/functions/AlertSystemUtilities.php');
$_Included_AlertSystemUtilities = true;
}
$FiltersData = array();
$FiltersData['place'] = 4;
$FiltersData['alertsender'] = 5;
$FiltersData['users'] = array($_User['id']);
$FiltersData['ips'] = array($Result_CheckProxy['ID']);

$FilterResult = AlertUtils_CheckFilters($FiltersData, array('DontLoad' => true, 'DontLoad_OnlyIfCacheEmpty' => true));
if($FilterResult['SendAlert'])
{
$_Alert['Data']['IPID'] = $Result_CheckProxy['ID'];
if($usersIP == $_User['ip_at_reg'])
{
$_Alert['Data']['RegIP'] = true;
}

Alerts_Add(5, $Now, 1, 3, 8, $_User['id'], $_Alert['Data']);
}
}
Overview\Screens\FirstLogin\Utils\Effects\handleProxyDetection([
'user' => &$_User,
'currentTimestamp' => $Now,
]);

// Give Free ProAccount for 7 days
//doquery("INSERT INTO {{table}} VALUES (NULL, {$_User['id']}, UNIX_TIMESTAMP(), 0, 0, 11, 0);", 'premium_free');
Expand Down

0 comments on commit 0e97daf

Please sign in to comment.