Ver Fonte

htaccess and DB updates

Benjamin Harris há 2 meses atrás
pai
commit
bed9c61196
4 ficheiros alterados com 71 adições e 49 exclusões
  1. 35 16
      .htaccess
  2. 7 7
      dashboard/inbox.php
  3. 3 0
      dashboard/pesticide.php
  4. 26 26
      layouts/header.php

+ 35 - 16
.htaccess

@@ -1,28 +1,47 @@
-Options -Indexes
-#DirectoryIndex index.php
+# ----------------------------------------------------------------------
+# | 8G Firewall for Security - Do not change this part @Update 03/2024
+# ----------------------------------------------------------------------
+
+# 8G FIREWALL v1.5 20250927
+# https://perishablepress.com/8g-firewall/
 
 
+# 8G:[CORE]
+ServerSignature Off
+Options -Indexes
 RewriteEngine On
 RewriteEngine On
 RewriteBase /
 RewriteBase /
 
 
+SetEnv TZ Australia/Hobart
+Options +SymLinksIfOwnerMatch
+
 # ── Allow .well-known for SSL/ACME challenges ──────────────────────────────
 # ── Allow .well-known for SSL/ACME challenges ──────────────────────────────
 RewriteRule ^\.well-known/ - [L]
 RewriteRule ^\.well-known/ - [L]
 
 
+<FilesMatch "(?i)\.(tpl|ini|log)$">
+	Require all denied
+</FilesMatch>
+
+# Allow Robots.txt to pass through
+RewriteRule ^robots.txt - [L]
+
+RewriteCond %{REQUEST_METHOD} !^POST$
+RewriteRule ^index\.php$ / [R=301,L]
+
+
+Header set X-Frame-Options "SAMEORIGIN"
+Header set X-Content-Type-Options "nosniff"
+Header set Referrer-Policy "no-referrer"
+Header set X-Robots-Tag "index, follow"
+
 # ── Block all other dotfiles ───────────────────────────────────────────────
 # ── Block all other dotfiles ───────────────────────────────────────────────
-RewriteRule (?:^|/)\. - [F,L]
+#RewriteRule (?:^|/)\. - [F,L]
 
 
 # ── www → non-www (301) ────────────────────────────────────────────────────
 # ── www → non-www (301) ────────────────────────────────────────────────────
-RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
-RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]
+#RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
+#RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]
 
 
-# ── Strip .php from the address bar (GET/HEAD only — POST submissions kept) ─
-# e.g. /login/login.php → /login/login
-RewriteCond %{REQUEST_METHOD} ^(GET|HEAD)$
-RewriteCond %{THE_REQUEST} \s/+(.*?)\.php[\s?]
-RewriteRule ^ /%2 [R=301,L,QSA]
-
-# ── Serve extensionless URLs by mapping to the matching .php file ──────────
-# e.g. /login/login → /login/login.php (internal, URL stays clean)
-RewriteCond %{REQUEST_FILENAME} !-d
+# ── Pass existing .php files directly (prevent vhost modX routing) ─────────
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-f
-RewriteCond %{REQUEST_FILENAME}\.php -f
-RewriteRule ^(.+?)/?$ $1.php [L]
+RewriteCond %{REQUEST_FILENAME} !-d
+RewriteCond %{REQUEST_URI} !.*\.(ico|gif|jpg|jpeg|png|js|css)
+RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]

+ 7 - 7
dashboard/inbox.php

@@ -32,10 +32,10 @@ $counts = [
     'deleted' => countRecords($pdo, 'soil_records',   $userId, 3),
     'deleted' => countRecords($pdo, 'soil_records',   $userId, 3),
 ];
 ];
 
 
-function fetchHistory(\PDO $pdo, string $table, int $userId): array {
+function fetchHistory(\PDO $pdo, string $table, int $userId, string $select = 'id, rand, lab_no, sample_id, site_id, crop_type, date_sampled'): array {
     $stmt = $pdo->prepare(
     $stmt = $pdo->prepare(
-        "SELECT id, rand, lab_no, sample_id, site_id, crop, date_sampled
-         FROM `$table`
+        "SELECT {$select}
+         FROM `{$table}`
          WHERE modx_user_id = ? AND status = 0
          WHERE modx_user_id = ? AND status = 0
          ORDER BY id DESC LIMIT 100"
          ORDER BY id DESC LIMIT 100"
     );
     );
@@ -45,8 +45,8 @@ function fetchHistory(\PDO $pdo, string $table, int $userId): array {
 
 
 $soilRows   = fetchHistory($pdo, 'soil_records',   $userId);
 $soilRows   = fetchHistory($pdo, 'soil_records',   $userId);
 $plantRows  = fetchHistory($pdo, 'plant_records',  $userId);
 $plantRows  = fetchHistory($pdo, 'plant_records',  $userId);
-$waterRows  = fetchHistory($pdo, 'water_records',  $userId);
-$animalRows = fetchHistory($pdo, 'animal_records', $userId);
+$waterRows  = fetchHistory($pdo, 'water_records',  $userId, 'id, rand, lab_no, sample_id, site_id, date_sampled');
+$animalRows = fetchHistory($pdo, 'animal_records', $userId, 'id, rand, lab_no, sample_id, NULL AS site_id, date_sampled');
 
 
 $h = fn($v) => htmlspecialchars((string) $v, ENT_QUOTES, 'UTF-8');
 $h = fn($v) => htmlspecialchars((string) $v, ENT_QUOTES, 'UTF-8');
 
 
@@ -146,7 +146,7 @@ include __DIR__ . '/../layouts/navbar.php';
                                         <td><?= $h($r['lab_no']) ?></td>
                                         <td><?= $h($r['lab_no']) ?></td>
                                         <td><?= $h($r['sample_id']) ?></td>
                                         <td><?= $h($r['sample_id']) ?></td>
                                         <td><?= $h($r['site_id']) ?></td>
                                         <td><?= $h($r['site_id']) ?></td>
-                                        <td><?= $h($r['crop']) ?></td>
+                                        <td><?= $h($r['crop_type']) ?></td>
                                         <td><?= $h($r['date_sampled']) ?></td>
                                         <td><?= $h($r['date_sampled']) ?></td>
                                         <td class="text-end">
                                         <td class="text-end">
                                             <a href="/dashboard/crop-analysis/soil-test-data/soil-analysis.php?rid=<?= (int)$r['id'] ?>&rand=<?= (float)$r['rand'] ?>"
                                             <a href="/dashboard/crop-analysis/soil-test-data/soil-analysis.php?rid=<?= (int)$r['id'] ?>&rand=<?= (float)$r['rand'] ?>"
@@ -176,7 +176,7 @@ include __DIR__ . '/../layouts/navbar.php';
                                         <td><?= $h($r['lab_no']) ?></td>
                                         <td><?= $h($r['lab_no']) ?></td>
                                         <td><?= $h($r['sample_id']) ?></td>
                                         <td><?= $h($r['sample_id']) ?></td>
                                         <td><?= $h($r['site_id']) ?></td>
                                         <td><?= $h($r['site_id']) ?></td>
-                                        <td><?= $h($r['crop']) ?></td>
+                                        <td><?= $h($r['crop_type']) ?></td>
                                         <td><?= $h($r['date_sampled']) ?></td>
                                         <td><?= $h($r['date_sampled']) ?></td>
                                         <td class="text-end">
                                         <td class="text-end">
                                             <a href="/dashboard/crop-analysis/plant-test-data/plant-analysis.php?rid=<?= (int)$r['id'] ?>&rand=<?= (float)$r['rand'] ?>"
                                             <a href="/dashboard/crop-analysis/plant-test-data/plant-analysis.php?rid=<?= (int)$r['id'] ?>&rand=<?= (float)$r['rand'] ?>"

+ 3 - 0
dashboard/pesticide.php

@@ -2,6 +2,9 @@
 <html lang="en">
 <html lang="en">
 
 
 <?php
 <?php
+error_reporting(E_ALL);
+ini_set('display_errors', 1);
+
 require_once __DIR__ . '/../config/database.php';
 require_once __DIR__ . '/../config/database.php';
 require_once __DIR__ . '/../lib/auth.php';
 require_once __DIR__ . '/../lib/auth.php';
 
 

+ 26 - 26
layouts/header.php

@@ -1,30 +1,30 @@
 <!doctype html>
 <!doctype html>
-<html lang="en">
-<head>
-    <meta charset="UTF-8">
-    <meta name="viewport" content="width=device-width, initial-scale=1.0">
-    <meta http-equiv="X-UA-Compatible" content="IE=edge">
-    <title><?= htmlspecialchars($pageTitle ?? 'Crop Management Platform', ENT_QUOTES, 'UTF-8') ?></title>
+    <html lang="en">
+    <head>
+        <meta charset="UTF-8">
+        <meta name="viewport" content="width=device-width, initial-scale=1.0">
+        <meta http-equiv="X-UA-Compatible" content="IE=edge">
+        <title><?= htmlspecialchars($pageTitle ?? 'Crop Management Platform', ENT_QUOTES, 'UTF-8') ?></title>
 
 
-    <meta name="description" content="Crop Management Platform - A comprehensive solution for monitoring and managing crop health, soil conditions, and weather patterns to optimize agricultural productivity.">
-    <meta name="keywords" content="Crop Management, Agriculture, Soil Analysis, Weather Monitoring, Crop Health, Farm Management, Agricultural Technology">
-    <meta name="author" content="Crop Management Platform Team">
-    
-    <link rel="icon" href="favicon.ico?v=2" type="image/x-icon">
+        <meta name="description" content="Crop Management Platform - A comprehensive solution for monitoring and managing crop health, soil conditions, and weather patterns to optimize agricultural productivity.">
+        <meta name="keywords" content="Crop Management, Agriculture, Soil Analysis, Weather Monitoring, Crop Health, Farm Management, Agricultural Technology">
+        <meta name="author" content="Crop Management Platform Team">
+        
+        <link rel="icon" href="./favicon.ico?v=2" type="image/x-icon">
 
 
-    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.0/dist/css/bootstrap.min.css" rel="stylesheet" crossorigin="anonymous">
-    <link href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/themes/smoothness/jquery-ui.css" rel="stylesheet" type="text/css" />
-    <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.9.0/css/all.css" integrity="sha256-PF6MatZtiJ8/c9O9HQ8uSUXr++R9KBYu4gbNG5511WE=" crossorigin="anonymous" rel="stylesheet" type="text/css"  />
-    <link type="text/css" href="/client-assets/weather-icons/css/weather-icons.min.css?version=1.16" rel="stylesheet" type="text/css" />
-    <link href="https://cdnjs.cloudflare.com/ajax/libs/magnific-popup.js/1.1.0/magnific-popup.css" rel="stylesheet" type="text/css" />
-    <link href="/client-assets/css/dashboard-2021.css" rel="stylesheet" type="text/css" />
-    <link href="/client-assets/home/css/graphing.css" rel="stylesheet" type="text/css" media="screen" />
-    <link href="/client-assets/home/css/alux.min.css" rel="stylesheet" type="text/css" media="screen" />
+        <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.0/dist/css/bootstrap.min.css" rel="stylesheet" crossorigin="anonymous">
+        <link href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/themes/smoothness/jquery-ui.css" rel="stylesheet" type="text/css" />
+        <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.9.0/css/all.css" integrity="sha256-PF6MatZtiJ8/c9O9HQ8uSUXr++R9KBYu4gbNG5511WE=" crossorigin="anonymous" rel="stylesheet" type="text/css"  />
+        <link type="text/css" href="/client-assets/weather-icons/css/weather-icons.min.css?version=1.16" rel="stylesheet" type="text/css" />
+        <link href="https://cdnjs.cloudflare.com/ajax/libs/magnific-popup.js/1.1.0/magnific-popup.css" rel="stylesheet" type="text/css" />
+        <link href="/client-assets/css/dashboard-2021.css" rel="stylesheet" type="text/css" />
+        <link href="/client-assets/home/css/graphing.css" rel="stylesheet" type="text/css" media="screen" />
+        <link href="/client-assets/home/css/alux.min.css" rel="stylesheet" type="text/css" media="screen" />
 
 
-    <script src="https://code.jquery.com/jquery-3.3.1.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script>
-    <script type="text/javascript" src="https://use.fontawesome.com/1e2844bb90.js"></script>
-    <script src="https://unpkg.com/gijgo@1.9.11/js/gijgo.min.js" type="text/javascript"></script>
-    <link href="https://unpkg.com/gijgo@1.9.11/css/gijgo.min.css" rel="stylesheet" type="text/css" />
-    <script src="/client-assets/js/skycons.js" type="text/javascript"></script>
-</head>
-<body class="sb-nav-fixed" id="page-top">
+        <script src="https://code.jquery.com/jquery-3.3.1.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script>
+        <script type="text/javascript" src="https://use.fontawesome.com/1e2844bb90.js"></script>
+        <script src="https://unpkg.com/gijgo@1.9.11/js/gijgo.min.js" type="text/javascript"></script>
+        <link href="https://unpkg.com/gijgo@1.9.11/css/gijgo.min.css" rel="stylesheet" type="text/css" />
+        <script src="/client-assets/js/skycons.js" type="text/javascript"></script>
+    </head>
+    <body class="sb-nav-fixed" id="page-top">