From f5c3e029b5626db75f40168f3e4e95b1d7b0ca86 Mon Sep 17 00:00:00 2001 From: Martin Ambrus Date: Sat, 28 Oct 2017 18:59:16 +0200 Subject: [PATCH] feat: access log config setting and a real get-post-cookie logger This is a very naive and primitive logger of user requests to the game. To be used on systems where access to webserver's log data is not available (especially if the webserver doesn't store POST data as well). --- .htaccess | 5 ++ a2b.php | 3 + a2b2.php | 3 + activate.php | 4 ++ ajax.php | 23 +++++++ allianz.php | 4 ++ anleitung.php | 3 + anmelden.php | 4 ++ banned.php | 5 +- berichte.php | 4 ++ build.php | 4 ++ celebration.php | 4 ++ create_account.php | 2 + crop_finder.php | 3 + dorf1.php | 4 ++ dorf2.php | 4 ++ dorf3.php | 4 ++ impressum.php | 3 + index.php | 9 ++- install/data/constant_format.tpl | 4 ++ karte.php | 4 ++ karte2.php | 6 +- login.php | 5 +- logout.php | 4 ++ massmessage.php | 6 +- nachrichten.php | 6 +- packages.php | 4 ++ password.php | 3 + plus.php | 4 ++ plus1.php | 4 ++ rules.php | 4 ++ spieler.php | 4 ++ spielregeln.php | 3 + src/Database/IDbConnection.php | 2 +- src/Utils/AccessLogger.php | 112 +++++++++++++++++++++++++++++++ src/Utils/Math.php | 2 +- statistiken.php | 4 ++ support.php | 6 +- sysmsg.php | 4 ++ tutorial.php | 3 + var/log/access.log | 0 version.php | 4 ++ warsim.php | 4 ++ winner.php | 4 ++ 44 files changed, 291 insertions(+), 10 deletions(-) create mode 100644 src/Utils/AccessLogger.php create mode 100644 var/log/access.log diff --git a/.htaccess b/.htaccess index 69a1060b..558b1059 100644 --- a/.htaccess +++ b/.htaccess @@ -8,6 +8,11 @@ Deny from all + + Order Allow,Deny + Deny from all + + Order Allow,Deny Deny from all diff --git a/a2b.php b/a2b.php index 62e5b0cc..8bcec895 100644 --- a/a2b.php +++ b/a2b.php @@ -9,7 +9,10 @@ ## ## ################################################################################# +use App\Utils\AccessLogger; + include("GameEngine/Village.php"); +AccessLogger::logRequest(); $start = $generator->pageLoadTimeStart(); if(isset($_GET['newdid'])) { diff --git a/a2b2.php b/a2b2.php index af0001ec..caa19e09 100644 --- a/a2b2.php +++ b/a2b2.php @@ -10,8 +10,11 @@ ## ## ################################################################################# +use App\Utils\AccessLogger; include("GameEngine/Village.php"); +AccessLogger::logRequest(); + $amount = $_SESSION['amount']; $start = $generator->pageLoadTimeStart(); if(isset($_GET['newdid'])) { diff --git a/activate.php b/activate.php index ffcea1a9..171bcb98 100644 --- a/activate.php +++ b/activate.php @@ -10,7 +10,11 @@ ## ## ################################################################################# +use App\Utils\AccessLogger; + include('GameEngine/Account.php'); +AccessLogger::logRequest(); + ?> diff --git a/ajax.php b/ajax.php index e6a38155..d337d54e 100644 --- a/ajax.php +++ b/ajax.php @@ -9,6 +9,29 @@ ## ## ################################################################################# +// even with autoloader created, we can't use it here yet, as it's not been created +// ... so, let's see where it is and include it +$autoloader_found = false; +// go max 5 levels up - we don't have folders that go deeper than that +for ($i = 0; $i < 5; $i++) { + $autoprefix = str_repeat('../', $i); + if (file_exists($autoprefix.'autoloader.php')) { + $autoloader_found = true; + include_once $autoprefix.'autoloader.php'; + break; + } +} + +if (!$autoloader_found) { + die('Could not find autoloading class.'); +} + +// we need config to determine whether to log access or not +include_once($autoprefix.'GameEngine/config.php'); + +use App\Utils\AccessLogger; +AccessLogger::logRequest(); + switch($_GET['f']) { case 'k7': header('Content-Type: application/json'); diff --git a/allianz.php b/allianz.php index 3aa6dcb6..6ff74035 100644 --- a/allianz.php +++ b/allianz.php @@ -1,8 +1,12 @@ pageLoadTimeStart(); $alliance->procAlliance($_GET); if(isset($_GET['newdid'])) { diff --git a/anleitung.php b/anleitung.php index 3fe2ff13..813de02d 100644 --- a/anleitung.php +++ b/anleitung.php @@ -9,9 +9,12 @@ ## ## ################################################################################# +use App\Utils\AccessLogger; + include("GameEngine/config.php"); include("GameEngine/Database.php"); include("GameEngine/Lang/".LANG.".php"); +AccessLogger::logRequest(); ?> diff --git a/anmelden.php b/anmelden.php index 61408c99..a4257ebc 100644 --- a/anmelden.php +++ b/anmelden.php @@ -10,12 +10,16 @@ ## ## ################################################################################# +use App\Utils\AccessLogger; + if(!file_exists('var/installed') && @opendir('install')) { header("Location: install/"); exit; } include('GameEngine/Account.php'); +AccessLogger::logRequest(); + $invited=(isset($_GET['uid'])) ? filter_var($_GET['uid'], FILTER_SANITIZE_NUMBER_INT):$form->getError('invt'); ?> diff --git a/banned.php b/banned.php index 17eb3f83..b16af3ba 100644 --- a/banned.php +++ b/banned.php @@ -9,9 +9,12 @@ ## ## ################################################################################# +use App\Utils\AccessLogger; + include("GameEngine/Village.php"); -$start = $generator->pageLoadTimeStart(); +AccessLogger::logRequest(); +$start = $generator->pageLoadTimeStart(); if($session->access == BANNED){ ?> diff --git a/berichte.php b/berichte.php index 669d6993..d96ecc8a 100644 --- a/berichte.php +++ b/berichte.php @@ -10,7 +10,11 @@ ## ## ################################################################################# +use App\Utils\AccessLogger; + include("GameEngine/Village.php"); +AccessLogger::logRequest(); + $start = $generator->pageLoadTimeStart(); $message->noticeType($_GET); $message->procNotice($_POST); diff --git a/build.php b/build.php index 855c6dd2..c1b35be2 100644 --- a/build.php +++ b/build.php @@ -10,9 +10,13 @@ ## ## ################################################################################# +use App\Utils\AccessLogger; + ob_start(); include_once("GameEngine/Village.php"); include_once("GameEngine/Units.php"); +AccessLogger::logRequest(); + if(isset($_GET['newdid'])) { $_SESSION['wid'] = $_GET['newdid']; header("Location: ".$_SERVER['PHP_SELF'].(isset($_GET['id'])?'?id='.$_GET['id']:(isset($_GET['gid'])?'?gid='.$_GET['gid']:''))); diff --git a/celebration.php b/celebration.php index 036a8ef2..5fbc6843 100644 --- a/celebration.php +++ b/celebration.php @@ -8,7 +8,11 @@ ## Copyright: TravianX (c) 2010-2011. All rights reserved. ## ## ## ################################################################################# +use App\Utils\AccessLogger; + include("GameEngine/Village.php"); +AccessLogger::logRequest(); + if(isset($_GET['newdid'])){ $_SESSION['wid'] = $_GET['newdid']; header("Location: ".$_SERVER['PHP_SELF']); diff --git a/create_account.php b/create_account.php index ef60d080..e1f04472 100644 --- a/create_account.php +++ b/create_account.php @@ -19,6 +19,7 @@ use App\Entity\User; +use App\Utils\AccessLogger; global $autoprefix; @@ -34,6 +35,7 @@ include_once ($autoprefix."GameEngine/Session.php"); include_once ($autoprefix."GameEngine/config.php"); +AccessLogger::logRequest(); /** diff --git a/crop_finder.php b/crop_finder.php index 8374086d..9852e54c 100644 --- a/crop_finder.php +++ b/crop_finder.php @@ -8,7 +8,10 @@ | Copyright: TravianX Project All rights reserved | \*-------------------------------------------------------*/ + use App\Utils\AccessLogger; + include ("GameEngine/Village.php"); + AccessLogger::logRequest(); if($session->goldclub == 0) { header("Location: plus.php?id=3"); diff --git a/dorf1.php b/dorf1.php index 06ca73f1..2bc5bbcf 100644 --- a/dorf1.php +++ b/dorf1.php @@ -9,7 +9,11 @@ ## Copyright: TravianX (c) 2010-2011. All rights reserved. ## ## ## ################################################################################# +use App\Utils\AccessLogger; + include("GameEngine/Village.php"); +AccessLogger::logRequest(); + $start = $generator->pageLoadTimeStart(); if(isset($_GET['ok'])){ $database->updateUserField($session->uid,'ok','0','1'); $_SESSION['ok'] = '0'; diff --git a/dorf2.php b/dorf2.php index 4c52c77f..4e1d3425 100644 --- a/dorf2.php +++ b/dorf2.php @@ -9,7 +9,11 @@ ## Copyright: TravianX (c) 2010-2011. All rights reserved. ## ## ## ################################################################################# +use App\Utils\AccessLogger; + include("GameEngine/Village.php"); +AccessLogger::logRequest(); + $start = $generator->pageLoadTimeStart(); if(isset($_GET['newdid'])) { $_SESSION['wid'] = $_GET['newdid']; diff --git a/dorf3.php b/dorf3.php index 65b9f00a..c37f105b 100644 --- a/dorf3.php +++ b/dorf3.php @@ -11,7 +11,11 @@ ################################################################################# +use App\Utils\AccessLogger; + include("GameEngine/Village.php"); +AccessLogger::logRequest(); + $start = $generator->pageLoadTimeStart(); if(isset($_GET['newdid'])) { $_SESSION['wid'] = $_GET['newdid']; diff --git a/impressum.php b/impressum.php index ddd47fbc..6eda0704 100644 --- a/impressum.php +++ b/impressum.php @@ -14,9 +14,12 @@ ## ## ################################################################################# +use App\Utils\AccessLogger; + include("GameEngine/config.php"); include("GameEngine/Database.php"); include("GameEngine/Lang/".LANG.".php"); +AccessLogger::logRequest(); ?> diff --git a/index.php b/index.php index 5787cc41..bd5c8b99 100644 --- a/index.php +++ b/index.php @@ -1,4 +1,6 @@ diff --git a/install/data/constant_format.tpl b/install/data/constant_format.tpl index 026d87ce..693fe078 100644 --- a/install/data/constant_format.tpl +++ b/install/data/constant_format.tpl @@ -305,6 +305,10 @@ define("MULTIHUNTER",8); define("ADMIN",9); define("COOKIE_EXPIRE", 60*60*24*7); define("COOKIE_PATH", "/"); +define("LOG_PAGE_ACCESS", false); +define("PAGE_ACCESS_LOG_DATE", true); +define("PAGE_ACCESS_LOG_IP", true); +define("PAGE_ACCESS_LOG_FILENAME", 'access.log'); // filename ONLY, no path! //////////////////////////////////////////// diff --git a/karte.php b/karte.php index fc68fb4a..8c732225 100644 --- a/karte.php +++ b/karte.php @@ -10,8 +10,12 @@ ## ## ################################################################################# +use App\Utils\AccessLogger; + if(isset($_GET['z']) && !is_numeric($_GET['z'])) die('Hacking Attempt'); include("GameEngine/Village.php"); +AccessLogger::logRequest(); + $start = $generator->pageLoadTimeStart(); if(isset($_GET['newdid'])) { $_SESSION['wid'] = $_GET['newdid']; diff --git a/karte2.php b/karte2.php index ba18f111..f94e7478 100644 --- a/karte2.php +++ b/karte2.php @@ -8,8 +8,12 @@ ## Copyright: TravianX (c) 2010-2011. All rights reserved. ## ## ## ################################################################################# +use App\Utils\AccessLogger; + include("GameEngine/Village.php"); - $building->procBuild($_GET); +AccessLogger::logRequest(); + +$building->procBuild($_GET); if($session->plus){ ?> diff --git a/login.php b/login.php index 133ec212..f8cd8311 100644 --- a/login.php +++ b/login.php @@ -10,13 +10,16 @@ ## ## ################################################################################# +use App\Utils\AccessLogger; + if(!file_exists('var/installed') && @opendir('install')) { header("Location: install/"); exit; } -error_reporting(E_ALL); include("GameEngine/Account.php"); +AccessLogger::logRequest(); + if(isset($_GET['del_cookie'])) { setcookie("COOKUSR","",time()-3600*24,"/"); header("Location: login.php"); diff --git a/logout.php b/logout.php index 8608e7db..3e8dab5b 100644 --- a/logout.php +++ b/logout.php @@ -11,7 +11,11 @@ ################################################################################# +use App\Utils\AccessLogger; + include("GameEngine/Account.php"); +AccessLogger::logRequest(); + $start = $generator->pageLoadTimeStart(); ?> diff --git a/massmessage.php b/massmessage.php index cd98930d..beb65e5e 100644 --- a/massmessage.php +++ b/massmessage.php @@ -10,7 +10,11 @@ ## ## ################################################################################# +use App\Utils\AccessLogger; + include_once("GameEngine/Account.php"); +AccessLogger::logRequest(); + $max_per_pass = 1000; if (mysqli_num_rows(mysqli_query($GLOBALS['link'],"SELECT id FROM ".TB_PREFIX."users WHERE access = 9 AND id = ".(int) $session->uid)) != '1') die("Hacking attemp!"); @@ -189,7 +193,7 @@ function toggleDisplay(e){ -