From 6b75ab8aeb99d77e303a0203db90f993176c5658 Mon Sep 17 00:00:00 2001 From: KUMAKAIHA Date: Sat, 25 May 2024 21:22:41 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=AF=B9Docker=E4=B8=8B=E7=9A=84=E9=83=A8?= =?UTF-8?q?=E7=BD=B2=E6=B7=BB=E5=8A=A0=E6=9C=89=E6=95=88=E7=9A=84TZ?= =?UTF-8?q?=E8=AE=BE=E5=AE=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .DS_Store | Bin 0 -> 6148 bytes Dockerfile | 4 ++++ results/telemetry_db.php | 21 +++++++++++++++++---- 3 files changed, 21 insertions(+), 4 deletions(-) create mode 100644 .DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..cfa157febe8465d91faec9c31498a18437ab9bcd GIT binary patch literal 6148 zcmeHK!Ab)$5S_Hub}2#yg&qT53)WT-#miFb54fTSmD+U|ySQ#jcWV!&uxI@tzr^ox zCP~Fo1rH)pW?<$elbM8hS&|I^i0&jf0H^^#1(mSip!q^*oODGB)+8vCqsCTYZ>@V5_{~`*f{o2lnO0q$egkzl$1tEr9Uq(rwrd>5jf>h^v zX25YOPQO;4&DuwuhHSSw^M;&tTFr($?6l@{r?R`Ze|*+|h#wR6Z0HsEC2HBSxPTXI z{Gie&Z=A#`xyR_mOp6&9nE_^i8CVwv?DFAd>&b62uH0dDp$~cc*S=bkf(5s_g z>TnRQLAJ~QGqB7+(R6Ec|DS&U{$Ebw9y7oUtQ7;I)bn~>EXm%jE5*@WD^YJzNhmHi m_>qDQeHCLYUBz`&E$EljKy)qU2GN7UKLVNtHq5}EGVl)ER#UP7 literal 0 HcmV?d00001 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..2b66c25cd 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,19 @@ 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(); + } } catch (Exception $e) { if($returnExceptionOnError){ return $e; From ebaba3ed06de8cb29f683ab795f8b500f8a5c6f4 Mon Sep 17 00:00:00 2001 From: KUMAKAIHA Date: Sat, 25 May 2024 22:42:53 +0800 Subject: [PATCH 2/2] fix TZ code bug --- results/telemetry_db.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/results/telemetry_db.php b/results/telemetry_db.php index 2b66c25cd..76ec6a115 100755 --- a/results/telemetry_db.php +++ b/results/telemetry_db.php @@ -198,14 +198,13 @@ function insertSpeedtestUser($ip, $ispinfo, $extra, $ua, $lang, $dl, $ul, $ping, $stmt = $pdo->prepare( 'INSERT INTO speedtest_users - (ip, ispinfo, extra, ua, lang, dl, ul, ping, jitter, log, timestamp) - VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)' // Added the timestamp field here + (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, $formattedTimestamp // Added $formattedTimestamp in the execute parameters ]); - $id = $pdo->lastInsertId(); - } + $id = $pdo->lastInsertId(); } catch (Exception $e) { if($returnExceptionOnError){ return $e;