diff --git a/.gitignore b/.gitignore index b07ea8a47..21be3b1ad 100755 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ results/idObfuscation_salt.php backend/getIP_serverLocation.php db-dir/ .vscode/ +.DS_Store \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index e4ea1c8e7..cfd0a94f3 100755 --- a/Dockerfile +++ b/Dockerfile @@ -11,6 +11,10 @@ RUN rm -f /usr/src/php.tar.xz /usr/src/php.tar.xz.asc \ && apt autoremove -y \ && rm -rf /var/lib/apt/lists/* +# Set the timezone +ENV TZ=UTC +RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone + # Prepare files and folders RUN mkdir -p /speedtest/ diff --git a/results/telemetry_db.php b/results/telemetry_db.php index b5db86b5a..3f850e921 100755 --- a/results/telemetry_db.php +++ b/results/telemetry_db.php @@ -3,7 +3,16 @@ require_once 'idObfuscation.php'; define('TELEMETRY_SETTINGS_FILE', 'telemetry_settings.php'); - +$tz = getenv('TZ'); +//Set timezone to UTC if Environment variables are not set +if ($tz !== false) { + // If the TZ environment variable exists, set the default timezone for PHP to its value + date_default_timezone_set($tz); +} else { + // If the TZ environment variable does not exist, set a default timezone or handle the error + // Set it to the UTC timezone + date_default_timezone_set('UTC'); +} /** * @return PDO|false */ @@ -185,15 +194,18 @@ function insertSpeedtestUser($ip, $ispinfo, $extra, $ua, $lang, $dl, $ul, $ping, } try { + $currentTimestamp = new DateTime('now'); // This will automatically use the timezone configured in PHP + $formattedTimestamp = $currentTimestamp->format('Y-m-d H:i:s'); + $stmt = $pdo->prepare( 'INSERT INTO speedtest_users - (ip,ispinfo,extra,ua,lang,dl,ul,ping,jitter,log) - VALUES (?,?,?,?,?,?,?,?,?,?)' + (ip,ispinfo,extra,ua,lang,dl,ul,ping,jitter,log,timestamp) + VALUES (?,?,?,?,?,?,?,?,?,?,?)' // Added the timestamp field here ); $stmt->execute([ - $ip, $ispinfo, $extra, $ua, $lang, $dl, $ul, $ping, $jitter, $log + $ip, $ispinfo, $extra, $ua, $lang, $dl, $ul, $ping, $jitter, $log, $formattedTimestamp // Added $formattedTimestamp in the execute parameters ]); - $id = $pdo->lastInsertId(); + $id = $pdo->lastInsertId(); } catch (Exception $e) { if($returnExceptionOnError){ return $e;