Compare commits
No commits in common. "ai-dev" and "master" have entirely different histories.
@ -1,81 +0,0 @@
|
||||
body {
|
||||
margin: 0;
|
||||
overflow: hidden;
|
||||
background-color: #000;
|
||||
}
|
||||
canvas {
|
||||
display: block;
|
||||
}
|
||||
#stats-container {
|
||||
position: absolute;
|
||||
top: 20px;
|
||||
left: 20px;
|
||||
color: #000;
|
||||
background-color: rgba(255, 255, 255, 0.9);
|
||||
padding: 10px;
|
||||
border-radius: 5px;
|
||||
font-family: sans-serif;
|
||||
width: 250px;
|
||||
}
|
||||
|
||||
#stats-buttons {
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
#stats-buttons button {
|
||||
background-color: #333;
|
||||
color: white;
|
||||
border: 1px solid #555;
|
||||
padding: 5px 10px;
|
||||
cursor: pointer;
|
||||
border-radius: 3px;
|
||||
margin-right: 5px;
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
|
||||
#stats-buttons button:hover {
|
||||
background-color: #555;
|
||||
}
|
||||
|
||||
#stats-buttons button.active {
|
||||
background-color: #007bff;
|
||||
border-color: #007bff;
|
||||
}
|
||||
|
||||
#controls-container {
|
||||
position: absolute;
|
||||
bottom: 20px;
|
||||
left: 50%;
|
||||
transform: translateX(-50%);
|
||||
background-color: rgba(0, 0, 0, 0.5);
|
||||
padding: 10px;
|
||||
border-radius: 5px;
|
||||
z-index: 10;
|
||||
}
|
||||
|
||||
#controls-container button {
|
||||
background-color: #333;
|
||||
color: white;
|
||||
border: 1px solid #555;
|
||||
padding: 10px 20px;
|
||||
cursor: pointer;
|
||||
border-radius: 3px;
|
||||
}
|
||||
|
||||
#controls-container button:hover {
|
||||
background-color: #555;
|
||||
}
|
||||
|
||||
#time-container {
|
||||
position: absolute;
|
||||
top: 20px;
|
||||
left: 50%;
|
||||
transform: translateX(-50%);
|
||||
color: white;
|
||||
background-color: rgba(0, 0, 0, 0.5);
|
||||
padding: 10px 20px;
|
||||
border-radius: 5px;
|
||||
font-family: monospace;
|
||||
font-size: 1.2em;
|
||||
z-index: 10;
|
||||
}
|
||||
@ -1,391 +0,0 @@
|
||||
import * as THREE from 'three';
|
||||
import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
|
||||
|
||||
// Scene
|
||||
const scene = new THREE.Scene();
|
||||
|
||||
// Camera
|
||||
const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
|
||||
camera.position.set(0, 25, 45);
|
||||
camera.lookAt(scene.position);
|
||||
|
||||
// Renderer
|
||||
const renderer = new THREE.WebGLRenderer();
|
||||
renderer.setSize(window.innerWidth, window.innerHeight);
|
||||
document.body.appendChild(renderer.domElement);
|
||||
|
||||
// Controls
|
||||
const controls = new OrbitControls(camera, renderer.domElement);
|
||||
controls.enableDamping = true; // an animation loop is required when either damping or auto-rotation are enabled
|
||||
controls.dampingFactor = 0.05;
|
||||
controls.screenSpacePanning = false;
|
||||
controls.minDistance = 10;
|
||||
controls.maxDistance = 500;
|
||||
|
||||
// Lighting
|
||||
const pointLight = new THREE.PointLight(0xffffff, 5, 3000); // Increased intensity and distance
|
||||
scene.add(pointLight);
|
||||
const ambientLight = new THREE.AmbientLight(0xffffff, 0.6); // Increased ambient light
|
||||
scene.add(ambientLight);
|
||||
|
||||
|
||||
// Texture Loader
|
||||
const textureLoader = new THREE.TextureLoader();
|
||||
|
||||
// Stars
|
||||
const starVertices = [];
|
||||
for (let i = 0; i < 10000; i++) {
|
||||
const x = (Math.random() - 0.5) * 2000;
|
||||
const y = (Math.random() - 0.5) * 2000;
|
||||
const z = (Math.random() - 0.5) * 2000;
|
||||
starVertices.push(x, y, z);
|
||||
}
|
||||
|
||||
const starGeometry = new THREE.BufferGeometry();
|
||||
starGeometry.setAttribute('position', new THREE.Float32BufferAttribute(starVertices, 3));
|
||||
|
||||
const starMaterial = new THREE.PointsMaterial({
|
||||
color: 0xffffff,
|
||||
size: 0.7
|
||||
});
|
||||
|
||||
const stars = new THREE.Points(starGeometry, starMaterial);
|
||||
scene.add(stars);
|
||||
|
||||
// --- Sun ---
|
||||
const sunTexture = textureLoader.load('assets/textures/sun.jpg');
|
||||
const sunMaterial = new THREE.MeshBasicMaterial({ map: sunTexture });
|
||||
const sun = new THREE.Mesh(new THREE.SphereGeometry(7, 32, 32), sunMaterial);
|
||||
scene.add(sun);
|
||||
|
||||
// --- Planets & Orbits ---
|
||||
const segments = 128;
|
||||
const orbitMaterial = new THREE.LineBasicMaterial({ color: 0xffffff, opacity: 0.5, transparent: true });
|
||||
|
||||
function createPlanet(radius, textureFile, distance, orbitalPeriodDays) {
|
||||
const texture = textureLoader.load(`assets/textures/${textureFile}?v=${Date.now()}`);
|
||||
const geometry = new THREE.SphereGeometry(radius, 32, 32);
|
||||
const material = new THREE.MeshBasicMaterial({ map: texture }); // Reverted
|
||||
const planet = new THREE.Mesh(geometry, material);
|
||||
|
||||
const pivot = new THREE.Object3D();
|
||||
sun.add(pivot);
|
||||
pivot.add(planet);
|
||||
planet.position.x = distance;
|
||||
|
||||
// Trail setup
|
||||
const trailPoints = [];
|
||||
const trailGeometry = new THREE.BufferGeometry();
|
||||
const trailMaterial = new THREE.LineBasicMaterial({ color: 0xffffff, opacity: 0.5, transparent: true });
|
||||
const trail = new THREE.Line(trailGeometry, trailMaterial);
|
||||
scene.add(trail);
|
||||
|
||||
return { planet, pivot, orbitalPeriodDays, trail, trailPoints };
|
||||
}
|
||||
|
||||
const mercuryData = createPlanet(0.4, 'mercury.jpg', 7, 88);
|
||||
const venusData = createPlanet(0.9, 'venus.jpg', 11, 225);
|
||||
const earthData = createPlanet(1, 'earth.jpg', 15, 365);
|
||||
const marsData = createPlanet(0.7, 'mars.jpg', 20, 687);
|
||||
const jupiterData = createPlanet(3, 'jupiter.jpg', 30, 4333);
|
||||
const saturnData = createPlanet(2.5, 'saturn.jpg', 40, 10759);
|
||||
const uranusData = createPlanet(2, 'uranus.jpg', 50, 30687);
|
||||
const neptuneData = createPlanet(1.9, 'neptune.jpg', 60, 60190);
|
||||
|
||||
// --- Saturn's Rings ---
|
||||
const ringGeometry = new THREE.RingGeometry(3.5, 5, 64);
|
||||
const ringMaterial = new THREE.MeshBasicMaterial({
|
||||
color: 0xffffff,
|
||||
side: THREE.DoubleSide,
|
||||
transparent: true,
|
||||
opacity: 0.6
|
||||
});
|
||||
const ring = new THREE.Mesh(ringGeometry, ringMaterial);
|
||||
ring.rotation.x = -Math.PI / 2.5; // Tilt the rings
|
||||
saturnData.planet.add(ring);
|
||||
|
||||
// --- Moon ---
|
||||
const moonGeometry = new THREE.SphereGeometry(0.25, 32, 32);
|
||||
const moonMaterial = new THREE.MeshBasicMaterial({ color: 0x888888 });
|
||||
const moon = new THREE.Mesh(moonGeometry, moonMaterial);
|
||||
|
||||
const moonPivot = new THREE.Object3D();
|
||||
earthData.planet.add(moonPivot);
|
||||
moonPivot.add(moon);
|
||||
moon.position.x = 2;
|
||||
|
||||
// --- Asteroid Belt ---
|
||||
const asteroidCount = 1500;
|
||||
const asteroidGeometry = new THREE.SphereGeometry(0.05, 8, 8); // A small sphere for asteroids
|
||||
const asteroidMaterial = new THREE.MeshStandardMaterial({ color: 0x999999, roughness: 0.9 });
|
||||
const asteroidMesh = new THREE.InstancedMesh(asteroidGeometry, asteroidMaterial, asteroidCount);
|
||||
|
||||
const beltMinRadius = 23;
|
||||
const beltMaxRadius = 28;
|
||||
const beltHeight = 1.5; // Vertical thickness
|
||||
|
||||
const dummy = new THREE.Object3D();
|
||||
const asteroidData = [];
|
||||
|
||||
for (let i = 0; i < asteroidCount; i++) {
|
||||
const radius = Math.random() * (beltMaxRadius - beltMinRadius) + beltMinRadius;
|
||||
const angle = Math.random() * Math.PI * 2;
|
||||
const y = (Math.random() - 0.5) * beltHeight;
|
||||
const orbitSpeed = (Math.random() * 0.002 + 0.0005); // Slower than Mars, faster than Jupiter
|
||||
const rotationSpeed = Math.random() * 0.05;
|
||||
|
||||
asteroidData.push({ radius, angle, y, orbitSpeed, rotationSpeed });
|
||||
|
||||
dummy.position.set(
|
||||
Math.cos(angle) * radius,
|
||||
y,
|
||||
Math.sin(angle) * radius
|
||||
);
|
||||
dummy.updateMatrix();
|
||||
asteroidMesh.setMatrixAt(i, dummy.matrix);
|
||||
}
|
||||
|
||||
scene.add(asteroidMesh);
|
||||
|
||||
|
||||
const planets = [mercuryData, venusData, earthData, marsData, jupiterData, saturnData, uranusData, neptuneData];
|
||||
|
||||
// Planet Data
|
||||
const planetData = {
|
||||
[earthData.planet.uuid]: {
|
||||
name: 'Earth',
|
||||
mass: '5.97 × 10^24 kg',
|
||||
radius: '6,371 km',
|
||||
orbital_speed: '29.78 km/s',
|
||||
},
|
||||
[mercuryData.planet.uuid]: {
|
||||
name: 'Mercury',
|
||||
mass: '3.285 × 10^23 kg',
|
||||
radius: '2,439.7 km',
|
||||
orbital_speed: '47.36 km/s',
|
||||
},
|
||||
[venusData.planet.uuid]: {
|
||||
name: 'Venus',
|
||||
mass: '4.867 × 10^24 kg',
|
||||
radius: '6,051.8 km',
|
||||
orbital_speed: '35.02 km/s',
|
||||
},
|
||||
[marsData.planet.uuid]: {
|
||||
name: 'Mars',
|
||||
mass: '6.39 × 10^23 kg',
|
||||
radius: '3,389.5 km',
|
||||
orbital_speed: '24.07 km/s',
|
||||
},
|
||||
[jupiterData.planet.uuid]: {
|
||||
name: 'Jupiter',
|
||||
mass: '1.898 × 10^27 kg',
|
||||
radius: '69,911 km',
|
||||
orbital_speed: '13.07 km/s',
|
||||
},
|
||||
[saturnData.planet.uuid]: {
|
||||
name: 'Saturn',
|
||||
mass: '5.683 × 10^26 kg',
|
||||
radius: '58,232 km',
|
||||
orbital_speed: '9.69 km/s',
|
||||
},
|
||||
[uranusData.planet.uuid]: {
|
||||
name: 'Uranus',
|
||||
mass: '8.681 × 10^25 kg',
|
||||
radius: '25,362 km',
|
||||
orbital_speed: '6.81 km/s',
|
||||
},
|
||||
[neptuneData.planet.uuid]: {
|
||||
name: 'Neptune',
|
||||
mass: '1.024 × 10^26 kg',
|
||||
radius: '24,622 km',
|
||||
orbital_speed: '5.43 km/s',
|
||||
}
|
||||
};
|
||||
|
||||
// --- Selection Outline ---
|
||||
let outlineMesh;
|
||||
const outlineMaterial = new THREE.MeshBasicMaterial({ color: 0xffff00, side: THREE.BackSide });
|
||||
const outlineScale = 1.15;
|
||||
|
||||
function setOutline(object) {
|
||||
if (outlineMesh && outlineMesh.parent) {
|
||||
outlineMesh.parent.remove(outlineMesh);
|
||||
}
|
||||
|
||||
outlineMesh = new THREE.Mesh(object.geometry, outlineMaterial);
|
||||
outlineMesh.scale.set(outlineScale, outlineScale, outlineScale);
|
||||
object.add(outlineMesh);
|
||||
}
|
||||
|
||||
|
||||
// Stats Panel
|
||||
const statsInfo = document.getElementById('stats-info');
|
||||
const statsButtons = document.getElementById('stats-buttons');
|
||||
|
||||
function updateStats(planetUUID) {
|
||||
const data = planetData[planetUUID];
|
||||
if (data) {
|
||||
statsInfo.innerHTML = `
|
||||
<h3>${data.name}</h3>
|
||||
<p>Mass: ${data.mass}</p>
|
||||
<p>Radius: ${data.radius}</p>
|
||||
<p>Orbital Speed: ${data.orbital_speed}</p>
|
||||
`;
|
||||
}
|
||||
}
|
||||
|
||||
statsButtons.addEventListener('click', (event) => {
|
||||
if (event.target.tagName === 'BUTTON') {
|
||||
const planetName = event.target.dataset.planet;
|
||||
let planetObject, planetUUID;
|
||||
|
||||
statsButtons.querySelectorAll('button').forEach(btn => btn.classList.remove('active'));
|
||||
event.target.classList.add('active');
|
||||
|
||||
if (planetName === 'earth') {
|
||||
planetObject = earthData.planet;
|
||||
planetUUID = earthData.planet.uuid;
|
||||
} else if (planetName === 'mercury') {
|
||||
planetObject = mercuryData.planet;
|
||||
planetUUID = mercuryData.planet.uuid;
|
||||
} else if (planetName === 'venus') {
|
||||
planetObject = venusData.planet;
|
||||
planetUUID = venusData.planet.uuid;
|
||||
} else if (planetName === 'mars') {
|
||||
planetObject = marsData.planet;
|
||||
planetUUID = marsData.planet.uuid;
|
||||
} else if (planetName === 'jupiter') {
|
||||
planetObject = jupiterData.planet;
|
||||
planetUUID = jupiterData.planet.uuid;
|
||||
} else if (planetName === 'saturn') {
|
||||
planetObject = saturnData.planet;
|
||||
planetUUID = saturnData.planet.uuid;
|
||||
} else if (planetName === 'uranus') {
|
||||
planetObject = uranusData.planet;
|
||||
planetUUID = uranusData.planet.uuid;
|
||||
} else if (planetName === 'neptune') {
|
||||
planetObject = neptuneData.planet;
|
||||
planetUUID = neptuneData.planet.uuid;
|
||||
}
|
||||
|
||||
if (planetUUID) {
|
||||
updateStats(planetUUID);
|
||||
if (planetObject) {
|
||||
setOutline(planetObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Display Earth's stats by default and set button to active
|
||||
updateStats(earthData.planet.uuid);
|
||||
statsButtons.querySelector('button[data-planet="earth"]').classList.add('active');
|
||||
setOutline(earthData.planet); // Initial outline for Earth
|
||||
|
||||
|
||||
// --- Controls Logic ---
|
||||
let isPaused = false;
|
||||
const pauseButton = document.getElementById('pause-button');
|
||||
const speedToggleButton = document.getElementById('speed-toggle-button');
|
||||
|
||||
pauseButton.addEventListener('click', () => {
|
||||
isPaused = !isPaused;
|
||||
pauseButton.textContent = isPaused ? 'Play' : 'Pause';
|
||||
});
|
||||
|
||||
const speeds = [1, 100, 500, 1000, 10000];
|
||||
let currentSpeedIndex = 0;
|
||||
let timeScale = speeds[currentSpeedIndex]; // Start with 1x speed
|
||||
|
||||
speedToggleButton.addEventListener('click', () => {
|
||||
currentSpeedIndex = (currentSpeedIndex + 1) % speeds.length;
|
||||
timeScale = speeds[currentSpeedIndex];
|
||||
speedToggleButton.textContent = 'Speed: ' + timeScale + 'x';
|
||||
});
|
||||
|
||||
|
||||
// --- Time & Simulation ---
|
||||
const clock = new THREE.Clock();
|
||||
const timeContainer = document.getElementById('time-container');
|
||||
let simulationTime = new Date();
|
||||
const TIME_SPEED_FACTOR = 60; // 1 real second = 1 simulation minute at 1x
|
||||
const MS_IN_A_DAY = 24 * 60 * 60 * 1000;
|
||||
const MOON_ORBIT_DAYS = 27.3;
|
||||
|
||||
|
||||
function updateTimeDisplay() {
|
||||
const hours = String(simulationTime.getHours()).padStart(2, '0');
|
||||
const minutes = String(simulationTime.getMinutes()).padStart(2, '0');
|
||||
const seconds = String(simulationTime.getSeconds()).padStart(2, '0');
|
||||
const day = String(simulationTime.getDate()).padStart(2, '0');
|
||||
const month = String(simulationTime.getMonth() + 1).padStart(2, '0'); // Month is 0-indexed
|
||||
const year = simulationTime.getFullYear();
|
||||
timeContainer.textContent = `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
|
||||
}
|
||||
|
||||
// Animation loop
|
||||
function animate() {
|
||||
requestAnimationFrame(animate);
|
||||
|
||||
// Get time delta for frame-rate independent animation
|
||||
let delta = clock.getDelta();
|
||||
// Clamp the delta to a maximum value to prevent large jumps, e.g., on the first frame or after tab refocus.
|
||||
delta = Math.min(delta, 0.1);
|
||||
|
||||
// Update controls
|
||||
controls.update();
|
||||
|
||||
if (!isPaused) {
|
||||
// Advance simulation time using milliseconds for precision
|
||||
const incrementMs = delta * 1000 * timeScale * TIME_SPEED_FACTOR;
|
||||
simulationTime.setTime(simulationTime.getTime() + incrementMs);
|
||||
|
||||
// Sun's self-rotation (can be slower and independent of timeScale)
|
||||
sun.rotation.y += 0.005 * delta;
|
||||
|
||||
const maxTrailPoints = 200;
|
||||
const worldPosition = new THREE.Vector3();
|
||||
|
||||
planets.forEach(p => {
|
||||
const orbitalPeriodMs = p.orbitalPeriodDays * MS_IN_A_DAY;
|
||||
const angleIncrement = (incrementMs / orbitalPeriodMs) * (2 * Math.PI);
|
||||
p.pivot.rotation.y += angleIncrement;
|
||||
|
||||
// Planet's self-rotation (can also be constant)
|
||||
p.planet.rotation.y += 0.05 * delta;
|
||||
|
||||
// Update trail
|
||||
p.planet.getWorldPosition(worldPosition);
|
||||
p.trailPoints.push(worldPosition.clone());
|
||||
|
||||
if (p.trailPoints.length > maxTrailPoints) {
|
||||
p.trailPoints.shift();
|
||||
}
|
||||
|
||||
p.trail.geometry.setFromPoints(p.trailPoints);
|
||||
});
|
||||
|
||||
// Moon's orbit (also scaled by timeScale)
|
||||
const moonOrbitalPeriodMs = MOON_ORBIT_DAYS * MS_IN_A_DAY;
|
||||
const moonAngleIncrement = (incrementMs / moonOrbitalPeriodMs) * (2 * Math.PI);
|
||||
moonPivot.rotation.y += moonAngleIncrement;
|
||||
}
|
||||
|
||||
// Update time display every frame
|
||||
updateTimeDisplay();
|
||||
|
||||
renderer.render(scene, camera);
|
||||
}
|
||||
|
||||
|
||||
animate();
|
||||
|
||||
// Handle window resize
|
||||
window.addEventListener('resize', () => {
|
||||
camera.aspect = window.innerWidth / window.innerHeight;
|
||||
camera.updateProjectionMatrix();
|
||||
renderer.setSize(window.innerWidth, window.innerHeight);
|
||||
});
|
||||
|
||||
// Initial call to set time
|
||||
updateTimeDisplay();
|
||||
|
Before Width: | Height: | Size: 452 KiB |
|
Before Width: | Height: | Size: 487 KiB |
|
Before Width: | Height: | Size: 733 KiB |
|
Before Width: | Height: | Size: 852 KiB |
|
Before Width: | Height: | Size: 236 KiB |
|
Before Width: | Height: | Size: 195 KiB |
|
Before Width: | Height: | Size: 803 KiB |
|
Before Width: | Height: | Size: 76 KiB |
|
Before Width: | Height: | Size: 864 KiB |
17
db/config.php
Normal file
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
// Generated by setup_mariadb_project.sh — edit as needed.
|
||||
define('DB_HOST', '127.0.0.1');
|
||||
define('DB_NAME', 'app_30855');
|
||||
define('DB_USER', 'app_30855');
|
||||
define('DB_PASS', 'eee81949-37de-47f9-a26f-14ebc8402f7f');
|
||||
|
||||
function db() {
|
||||
static $pdo;
|
||||
if (!$pdo) {
|
||||
$pdo = new PDO('mysql:host='.DB_HOST.';dbname='.DB_NAME.';charset=utf8mb4', DB_USER, DB_PASS, [
|
||||
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
|
||||
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
|
||||
]);
|
||||
}
|
||||
return $pdo;
|
||||
}
|
||||
155
index.php
@ -1,38 +1,131 @@
|
||||
<!DOCTYPE html>
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
@ini_set('display_errors', '1');
|
||||
@error_reporting(E_ALL);
|
||||
@date_default_timezone_set('UTC');
|
||||
|
||||
$phpVersion = PHP_VERSION;
|
||||
$now = date('Y-m-d H:i:s');
|
||||
?>
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>3D Solar System</title>
|
||||
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<title>New Style</title>
|
||||
<link rel="preconnect" href="https://fonts.googleapis.com">
|
||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
||||
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;700&display=swap" rel="stylesheet">
|
||||
<style>
|
||||
:root {
|
||||
--bg-color-start: #6a11cb;
|
||||
--bg-color-end: #2575fc;
|
||||
--text-color: #ffffff;
|
||||
--card-bg-color: rgba(255, 255, 255, 0.01);
|
||||
--card-border-color: rgba(255, 255, 255, 0.1);
|
||||
}
|
||||
body {
|
||||
margin: 0;
|
||||
font-family: 'Inter', sans-serif;
|
||||
background: linear-gradient(45deg, var(--bg-color-start), var(--bg-color-end));
|
||||
color: var(--text-color);
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
min-height: 100vh;
|
||||
text-align: center;
|
||||
overflow: hidden;
|
||||
position: relative;
|
||||
}
|
||||
body::before {
|
||||
content: '';
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100" viewBox="0 0 100 100"><path d="M-10 10L110 10M10 -10L10 110" stroke-width="1" stroke="rgba(255,255,255,0.05)"/></svg>');
|
||||
animation: bg-pan 20s linear infinite;
|
||||
z-index: -1;
|
||||
}
|
||||
@keyframes bg-pan {
|
||||
0% { background-position: 0% 0%; }
|
||||
100% { background-position: 100% 100%; }
|
||||
}
|
||||
main {
|
||||
padding: 2rem;
|
||||
}
|
||||
.card {
|
||||
background: var(--card-bg-color);
|
||||
border: 1px solid var(--card-border-color);
|
||||
border-radius: 16px;
|
||||
padding: 2rem;
|
||||
backdrop-filter: blur(20px);
|
||||
-webkit-backdrop-filter: blur(20px);
|
||||
box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
.loader {
|
||||
margin: 1.25rem auto 1.25rem;
|
||||
width: 48px;
|
||||
height: 48px;
|
||||
border: 3px solid rgba(255, 255, 255, 0.25);
|
||||
border-top-color: #fff;
|
||||
border-radius: 50%;
|
||||
animation: spin 1s linear infinite;
|
||||
}
|
||||
@keyframes spin {
|
||||
from { transform: rotate(0deg); }
|
||||
to { transform: rotate(360deg); }
|
||||
}
|
||||
.hint {
|
||||
opacity: 0.9;
|
||||
}
|
||||
.sr-only {
|
||||
position: absolute;
|
||||
width: 1px; height: 1px;
|
||||
padding: 0; margin: -1px;
|
||||
overflow: hidden;
|
||||
clip: rect(0, 0, 0, 0);
|
||||
white-space: nowrap; border: 0;
|
||||
}
|
||||
h1 {
|
||||
font-size: 3rem;
|
||||
font-weight: 700;
|
||||
margin: 0 0 1rem;
|
||||
letter-spacing: -1px;
|
||||
}
|
||||
p {
|
||||
margin: 0.5rem 0;
|
||||
font-size: 1.1rem;
|
||||
}
|
||||
code {
|
||||
background: rgba(0,0,0,0.2);
|
||||
padding: 2px 6px;
|
||||
border-radius: 4px;
|
||||
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
|
||||
}
|
||||
footer {
|
||||
position: absolute;
|
||||
bottom: 1rem;
|
||||
font-size: 0.8rem;
|
||||
opacity: 0.7;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div id="time-container"></div>
|
||||
<div id="stats-container">
|
||||
<div id="stats-buttons">
|
||||
<button data-planet="mercury">Mercury</button>
|
||||
<button data-planet="venus">Venus</button>
|
||||
<button data-planet="earth">Earth</button>
|
||||
<button data-planet="mars">Mars</button>
|
||||
<button data-planet="jupiter">Jupiter</button>
|
||||
<button data-planet="saturn">Saturn</button>
|
||||
<button data-planet="uranus">Uranus</button>
|
||||
<button data-planet="neptune">Neptune</button>
|
||||
</div>
|
||||
<div id="stats-info"></div>
|
||||
<main>
|
||||
<div class="card">
|
||||
<h1>Analyzing your requirements and generating your website…</h1>
|
||||
<div class="loader" role="status" aria-live="polite" aria-label="Applying initial changes">
|
||||
<span class="sr-only">Loading…</span>
|
||||
</div>
|
||||
<p class="hint">Flatlogic AI is collecting your requirements and applying the first changes.</p>
|
||||
<p class="hint">This page will update automatically as the plan is implemented.</p>
|
||||
<p>Runtime: PHP <code><?= htmlspecialchars($phpVersion) ?></code> — UTC <code><?= htmlspecialchars($now) ?></code></p>
|
||||
</div>
|
||||
<div id="controls-container">
|
||||
<button id="pause-button">Pause</button>
|
||||
<button id="speed-toggle-button">Speed: 1x</button>
|
||||
</div>
|
||||
<script type="importmap">
|
||||
{
|
||||
"imports": {
|
||||
"three": "https://unpkg.com/three@0.164.1/build/three.module.js",
|
||||
"three/addons/": "https://unpkg.com/three@0.164.1/examples/jsm/"
|
||||
}
|
||||
}
|
||||
</script>
|
||||
<script type="module" src="assets/js/main.js?v=<?php echo time(); ?>"></script>
|
||||
</main>
|
||||
<footer>
|
||||
Page updated: <?= htmlspecialchars($now) ?> (UTC)
|
||||
</footer>
|
||||
</body>
|
||||
</html>
|
||||
235
mail/MailService.php
Normal file
@ -0,0 +1,235 @@
|
||||
<?php
|
||||
// Minimal mail service for the workspace app (VM).
|
||||
// Usage:
|
||||
// require_once __DIR__ . '/MailService.php';
|
||||
// // Generic:
|
||||
// MailService::sendMail($to, $subject, $htmlBody, $textBody = null, $opts = []);
|
||||
// // Contact form helper:
|
||||
// MailService::sendContactMessage($name, $email, $message, $to = null, $subject = 'New contact form');
|
||||
|
||||
class MailService
|
||||
{
|
||||
// Universal mail sender (no attachments by design)
|
||||
public static function sendMail($to, string $subject, string $htmlBody, ?string $textBody = null, array $opts = [])
|
||||
{
|
||||
$cfg = self::loadConfig();
|
||||
|
||||
$autoload = __DIR__ . '/../vendor/autoload.php';
|
||||
if (file_exists($autoload)) {
|
||||
require_once $autoload;
|
||||
}
|
||||
if (!class_exists('PHPMailer\\PHPMailer\\PHPMailer')) {
|
||||
@require_once 'libphp-phpmailer/autoload.php';
|
||||
if (!class_exists('PHPMailer\\PHPMailer\\PHPMailer')) {
|
||||
@require_once 'libphp-phpmailer/src/Exception.php';
|
||||
@require_once 'libphp-phpmailer/src/SMTP.php';
|
||||
@require_once 'libphp-phpmailer/src/PHPMailer.php';
|
||||
}
|
||||
if (!class_exists('PHPMailer\\PHPMailer\\PHPMailer')) {
|
||||
@require_once 'PHPMailer/src/Exception.php';
|
||||
@require_once 'PHPMailer/src/SMTP.php';
|
||||
@require_once 'PHPMailer/src/PHPMailer.php';
|
||||
}
|
||||
if (!class_exists('PHPMailer\\PHPMailer\\PHPMailer')) {
|
||||
@require_once 'PHPMailer/Exception.php';
|
||||
@require_once 'PHPMailer/SMTP.php';
|
||||
@require_once 'PHPMailer/PHPMailer.php';
|
||||
}
|
||||
}
|
||||
|
||||
if (!class_exists('PHPMailer\\PHPMailer\\PHPMailer')) {
|
||||
return [ 'success' => false, 'error' => 'PHPMailer not available' ];
|
||||
}
|
||||
|
||||
$mail = new PHPMailer\PHPMailer\PHPMailer(true);
|
||||
try {
|
||||
$mail->isSMTP();
|
||||
$mail->Host = $cfg['smtp_host'] ?? '';
|
||||
$mail->Port = (int)($cfg['smtp_port'] ?? 587);
|
||||
$secure = $cfg['smtp_secure'] ?? 'tls';
|
||||
if ($secure === 'ssl') $mail->SMTPSecure = PHPMailer\PHPMailer\PHPMailer::ENCRYPTION_SMTPS;
|
||||
elseif ($secure === 'tls') $mail->SMTPSecure = PHPMailer\PHPMailer\PHPMailer::ENCRYPTION_STARTTLS;
|
||||
else $mail->SMTPSecure = false;
|
||||
$mail->SMTPAuth = true;
|
||||
$mail->Username = $cfg['smtp_user'] ?? '';
|
||||
$mail->Password = $cfg['smtp_pass'] ?? '';
|
||||
|
||||
$fromEmail = $opts['from_email'] ?? ($cfg['from_email'] ?? 'no-reply@localhost');
|
||||
$fromName = $opts['from_name'] ?? ($cfg['from_name'] ?? 'App');
|
||||
$mail->setFrom($fromEmail, $fromName);
|
||||
if (!empty($opts['reply_to']) && filter_var($opts['reply_to'], FILTER_VALIDATE_EMAIL)) {
|
||||
$mail->addReplyTo($opts['reply_to']);
|
||||
} elseif (!empty($cfg['reply_to'])) {
|
||||
$mail->addReplyTo($cfg['reply_to']);
|
||||
}
|
||||
|
||||
// Recipients
|
||||
$toList = [];
|
||||
if ($to) {
|
||||
if (is_string($to)) $toList = array_map('trim', explode(',', $to));
|
||||
elseif (is_array($to)) $toList = $to;
|
||||
} elseif (!empty(getenv('MAIL_TO'))) {
|
||||
$toList = array_map('trim', explode(',', getenv('MAIL_TO')));
|
||||
}
|
||||
$added = 0;
|
||||
foreach ($toList as $addr) {
|
||||
if (filter_var($addr, FILTER_VALIDATE_EMAIL)) { $mail->addAddress($addr); $added++; }
|
||||
}
|
||||
if ($added === 0) {
|
||||
return [ 'success' => false, 'error' => 'No recipients defined (set MAIL_TO or pass $to)' ];
|
||||
}
|
||||
|
||||
foreach ((array)($opts['cc'] ?? []) as $cc) { if (filter_var($cc, FILTER_VALIDATE_EMAIL)) $mail->addCC($cc); }
|
||||
foreach ((array)($opts['bcc'] ?? []) as $bcc){ if (filter_var($bcc, FILTER_VALIDATE_EMAIL)) $mail->addBCC($bcc); }
|
||||
|
||||
// Optional DKIM
|
||||
if (!empty($cfg['dkim_domain']) && !empty($cfg['dkim_selector']) && !empty($cfg['dkim_private_key_path'])) {
|
||||
$mail->DKIM_domain = $cfg['dkim_domain'];
|
||||
$mail->DKIM_selector = $cfg['dkim_selector'];
|
||||
$mail->DKIM_private = $cfg['dkim_private_key_path'];
|
||||
}
|
||||
|
||||
$mail->isHTML(true);
|
||||
$mail->Subject = $subject;
|
||||
$mail->Body = $htmlBody;
|
||||
$mail->AltBody = $textBody ?? strip_tags($htmlBody);
|
||||
$ok = $mail->send();
|
||||
return [ 'success' => $ok ];
|
||||
} catch (\Throwable $e) {
|
||||
return [ 'success' => false, 'error' => 'PHPMailer error: ' . $e->getMessage() ];
|
||||
}
|
||||
}
|
||||
private static function loadConfig(): array
|
||||
{
|
||||
$configPath = __DIR__ . '/config.php';
|
||||
if (!file_exists($configPath)) {
|
||||
throw new \RuntimeException('Mail config not found. Copy mail/config.sample.php to mail/config.php and fill in credentials.');
|
||||
}
|
||||
$cfg = require $configPath;
|
||||
if (!is_array($cfg)) {
|
||||
throw new \RuntimeException('Invalid mail config format: expected array');
|
||||
}
|
||||
return $cfg;
|
||||
}
|
||||
|
||||
// Send a contact message
|
||||
// $to can be: a single email string, a comma-separated list, an array of emails, or null (fallback to MAIL_TO/MAIL_FROM)
|
||||
public static function sendContactMessage(string $name, string $email, string $message, $to = null, string $subject = 'New contact form')
|
||||
{
|
||||
$cfg = self::loadConfig();
|
||||
|
||||
// Try Composer autoload if available (for PHPMailer)
|
||||
$autoload = __DIR__ . '/../vendor/autoload.php';
|
||||
if (file_exists($autoload)) {
|
||||
require_once $autoload;
|
||||
}
|
||||
// Fallback to system-wide PHPMailer (installed via apt: libphp-phpmailer)
|
||||
if (!class_exists('PHPMailer\\PHPMailer\\PHPMailer')) {
|
||||
// Debian/Ubuntu package layout (libphp-phpmailer)
|
||||
@require_once 'libphp-phpmailer/autoload.php';
|
||||
if (!class_exists('PHPMailer\\PHPMailer\\PHPMailer')) {
|
||||
@require_once 'libphp-phpmailer/src/Exception.php';
|
||||
@require_once 'libphp-phpmailer/src/SMTP.php';
|
||||
@require_once 'libphp-phpmailer/src/PHPMailer.php';
|
||||
}
|
||||
// Alternative layout (older PHPMailer package names)
|
||||
if (!class_exists('PHPMailer\\PHPMailer\\PHPMailer')) {
|
||||
@require_once 'PHPMailer/src/Exception.php';
|
||||
@require_once 'PHPMailer/src/SMTP.php';
|
||||
@require_once 'PHPMailer/src/PHPMailer.php';
|
||||
}
|
||||
if (!class_exists('PHPMailer\\PHPMailer\\PHPMailer')) {
|
||||
@require_once 'PHPMailer/Exception.php';
|
||||
@require_once 'PHPMailer/SMTP.php';
|
||||
@require_once 'PHPMailer/PHPMailer.php';
|
||||
}
|
||||
}
|
||||
|
||||
$transport = $cfg['transport'] ?? 'smtp';
|
||||
if ($transport === 'smtp' && class_exists('PHPMailer\\PHPMailer\\PHPMailer')) {
|
||||
return self::sendViaPHPMailer($cfg, $name, $email, $message, $to, $subject);
|
||||
}
|
||||
|
||||
// Fallback: attempt native mail() — works only if MTA is configured on the VM
|
||||
return self::sendViaNativeMail($cfg, $name, $email, $message, $to, $subject);
|
||||
}
|
||||
|
||||
private static function sendViaPHPMailer(array $cfg, string $name, string $email, string $body, $to, string $subject)
|
||||
{
|
||||
$mail = new PHPMailer\PHPMailer\PHPMailer(true);
|
||||
try {
|
||||
$mail->isSMTP();
|
||||
$mail->Host = $cfg['smtp_host'] ?? '';
|
||||
$mail->Port = (int)($cfg['smtp_port'] ?? 587);
|
||||
$secure = $cfg['smtp_secure'] ?? 'tls';
|
||||
if ($secure === 'ssl') $mail->SMTPSecure = PHPMailer\PHPMailer\PHPMailer::ENCRYPTION_SMTPS;
|
||||
elseif ($secure === 'tls') $mail->SMTPSecure = PHPMailer\PHPMailer\PHPMailer::ENCRYPTION_STARTTLS;
|
||||
else $mail->SMTPSecure = false;
|
||||
$mail->SMTPAuth = true;
|
||||
$mail->Username = $cfg['smtp_user'] ?? '';
|
||||
$mail->Password = $cfg['smtp_pass'] ?? '';
|
||||
|
||||
$fromEmail = $cfg['from_email'] ?? 'no-reply@localhost';
|
||||
$fromName = $cfg['from_name'] ?? 'App';
|
||||
$mail->setFrom($fromEmail, $fromName);
|
||||
|
||||
// Use Reply-To for the user's email to avoid spoofing From
|
||||
if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
||||
$mail->addReplyTo($email, $name ?: $email);
|
||||
}
|
||||
if (!empty($cfg['reply_to'])) {
|
||||
$mail->addReplyTo($cfg['reply_to']);
|
||||
}
|
||||
|
||||
// Destination: prefer dynamic recipients ($to), fallback to MAIL_TO; no silent FROM fallback
|
||||
$toList = [];
|
||||
if ($to) {
|
||||
if (is_string($to)) {
|
||||
// allow comma-separated list
|
||||
$toList = array_map('trim', explode(',', $to));
|
||||
} elseif (is_array($to)) {
|
||||
$toList = $to;
|
||||
}
|
||||
} elseif (!empty(getenv('MAIL_TO'))) {
|
||||
$toList = array_map('trim', explode(',', getenv('MAIL_TO')));
|
||||
}
|
||||
$added = 0;
|
||||
foreach ($toList as $addr) {
|
||||
if (filter_var($addr, FILTER_VALIDATE_EMAIL)) {
|
||||
$mail->addAddress($addr);
|
||||
$added++;
|
||||
}
|
||||
}
|
||||
if ($added === 0) {
|
||||
return [ 'success' => false, 'error' => 'No recipients defined (set MAIL_TO or pass $to)' ];
|
||||
}
|
||||
|
||||
// DKIM (optional)
|
||||
if (!empty($cfg['dkim_domain']) && !empty($cfg['dkim_selector']) && !empty($cfg['dkim_private_key_path'])) {
|
||||
$mail->DKIM_domain = $cfg['dkim_domain'];
|
||||
$mail->DKIM_selector = $cfg['dkim_selector'];
|
||||
$mail->DKIM_private = $cfg['dkim_private_key_path'];
|
||||
}
|
||||
|
||||
$mail->isHTML(true);
|
||||
$mail->Subject = $subject;
|
||||
$safeName = htmlspecialchars($name, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
|
||||
$safeEmail = htmlspecialchars($email, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
|
||||
$safeBody = nl2br(htmlspecialchars($body, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'));
|
||||
$mail->Body = "<p><strong>Name:</strong> {$safeName}</p><p><strong>Email:</strong> {$safeEmail}</p><hr>{$safeBody}";
|
||||
$mail->AltBody = "Name: {$name}\nEmail: {$email}\n\n{$body}";
|
||||
|
||||
$ok = $mail->send();
|
||||
return [ 'success' => $ok ];
|
||||
} catch (\Throwable $e) {
|
||||
return [ 'success' => false, 'error' => 'PHPMailer error: ' . $e->getMessage() ];
|
||||
}
|
||||
}
|
||||
|
||||
private static function sendViaNativeMail(array $cfg, string $name, string $email, string $body, $to, string $subject)
|
||||
{
|
||||
$opts = ['reply_to' => $email];
|
||||
$html = nl2br(htmlspecialchars($body, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'));
|
||||
return self::sendMail($to, $subject, $html, $body, $opts);
|
||||
}
|
||||
}
|
||||
76
mail/config.php
Normal file
@ -0,0 +1,76 @@
|
||||
<?php
|
||||
// Mail configuration sourced from environment variables.
|
||||
// No secrets are stored here; the file just maps env -> config array for MailService.
|
||||
|
||||
function env_val(string $key, $default = null) {
|
||||
$v = getenv($key);
|
||||
return ($v === false || $v === null || $v === '') ? $default : $v;
|
||||
}
|
||||
|
||||
// Fallback: if critical vars are missing from process env, try to parse executor/.env
|
||||
// This helps in web/Apache contexts where .env is not exported.
|
||||
// Supports simple KEY=VALUE lines; ignores quotes and comments.
|
||||
function load_dotenv_if_needed(array $keys): void {
|
||||
$missing = array_filter($keys, fn($k) => getenv($k) === false || getenv($k) === '');
|
||||
if (empty($missing)) return;
|
||||
static $loaded = false;
|
||||
if ($loaded) return;
|
||||
$envPath = realpath(__DIR__ . '/../../.env'); // executor/.env
|
||||
if ($envPath && is_readable($envPath)) {
|
||||
$lines = @file($envPath, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES) ?: [];
|
||||
foreach ($lines as $line) {
|
||||
if ($line[0] === '#' || trim($line) === '') continue;
|
||||
if (!str_contains($line, '=')) continue;
|
||||
[$k, $v] = array_map('trim', explode('=', $line, 2));
|
||||
// Strip potential surrounding quotes
|
||||
$v = trim($v, "\"' ");
|
||||
// Do not override existing env
|
||||
if ($k !== '' && (getenv($k) === false || getenv($k) === '')) {
|
||||
putenv("{$k}={$v}");
|
||||
}
|
||||
}
|
||||
$loaded = true;
|
||||
}
|
||||
}
|
||||
|
||||
load_dotenv_if_needed([
|
||||
'MAIL_TRANSPORT','SMTP_HOST','SMTP_PORT','SMTP_SECURE','SMTP_USER','SMTP_PASS',
|
||||
'MAIL_FROM','MAIL_FROM_NAME','MAIL_REPLY_TO','MAIL_TO',
|
||||
'DKIM_DOMAIN','DKIM_SELECTOR','DKIM_PRIVATE_KEY_PATH'
|
||||
]);
|
||||
|
||||
$transport = env_val('MAIL_TRANSPORT', 'smtp');
|
||||
$smtp_host = env_val('SMTP_HOST');
|
||||
$smtp_port = (int) env_val('SMTP_PORT', 587);
|
||||
$smtp_secure = env_val('SMTP_SECURE', 'tls'); // tls | ssl | null
|
||||
$smtp_user = env_val('SMTP_USER');
|
||||
$smtp_pass = env_val('SMTP_PASS');
|
||||
|
||||
$from_email = env_val('MAIL_FROM', 'no-reply@localhost');
|
||||
$from_name = env_val('MAIL_FROM_NAME', 'App');
|
||||
$reply_to = env_val('MAIL_REPLY_TO');
|
||||
|
||||
$dkim_domain = env_val('DKIM_DOMAIN');
|
||||
$dkim_selector = env_val('DKIM_SELECTOR');
|
||||
$dkim_private_key_path = env_val('DKIM_PRIVATE_KEY_PATH');
|
||||
|
||||
return [
|
||||
'transport' => $transport,
|
||||
|
||||
// SMTP
|
||||
'smtp_host' => $smtp_host,
|
||||
'smtp_port' => $smtp_port,
|
||||
'smtp_secure' => $smtp_secure,
|
||||
'smtp_user' => $smtp_user,
|
||||
'smtp_pass' => $smtp_pass,
|
||||
|
||||
// From / Reply-To
|
||||
'from_email' => $from_email,
|
||||
'from_name' => $from_name,
|
||||
'reply_to' => $reply_to,
|
||||
|
||||
// DKIM (optional)
|
||||
'dkim_domain' => $dkim_domain,
|
||||
'dkim_selector' => $dkim_selector,
|
||||
'dkim_private_key_path' => $dkim_private_key_path,
|
||||
];
|
||||