diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 000000000..cfa157feb Binary files /dev/null and b/.DS_Store differ diff --git a/Dockerfile b/Dockerfile index a626296bb..6bdd89878 100755 --- a/Dockerfile +++ b/Dockerfile @@ -12,6 +12,10 @@ RUN apt-get update && apt-get install -y \ && docker-php-ext-install -j$(nproc) gd pdo pdo_mysql pdo_pgsql pgsql \ && 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 46b8bf7fd..76ec6a115 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 */ @@ -184,15 +193,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;