Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .vercelignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Exclude development and build tooling
.github/
.travis.yml
.codeclimate.yml
Dockerfile
README*.md
demo_data/

# Exclude test/dev files
*.test.php
*.spec.php
59 changes: 59 additions & 0 deletions api/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php
/**
* Vercel front controller — Ghana Council e.V.
*
* Single serverless function entry point (compatible with Vercel free plan).
* Routes every request to the correct Admidio PHP file, or falls back to
* the application root index.php.
*/

define('APP_ROOT', dirname(__DIR__));

// Public directories whose PHP files may be entered directly via URL
$publicDirs = [
'/modules/',
'/plugins/',
'/install/',
'/rss/',
];

$requestPath = parse_url($_SERVER['REQUEST_URI'] ?? '/', PHP_URL_PATH);
$requestPath = '/' . ltrim($requestPath, '/');

$targetFile = APP_ROOT . $requestPath;
$realRoot = realpath(APP_ROOT);
$realTarget = realpath($targetFile);

$isPhpFile = $realTarget && is_file($realTarget) && pathinfo($realTarget, PATHINFO_EXTENSION) === 'php';
$withinRoot = $realTarget && strncmp($realTarget, $realRoot, strlen($realRoot)) === 0;
$inPublicDir = false;

if ($isPhpFile && $withinRoot) {
$relative = substr($realTarget, strlen($realRoot));
// Allow root-level PHP files (e.g. /index.php, /sso.php) and public dirs
if (!str_contains(substr($relative, 1), '/')) {
$inPublicDir = true;
} else {
foreach ($publicDirs as $dir) {
if (str_starts_with($relative, $dir)) {
$inPublicDir = true;
break;
}
}
}
}

if ($isPhpFile && $withinRoot && $inPublicDir) {
$_SERVER['SCRIPT_FILENAME'] = $realTarget;
$_SERVER['PHP_SELF'] = $requestPath;
chdir(dirname($realTarget));
/** @noinspection PhpIncludeInspection */
require $realTarget;
} else {
// Default: application entry point
$entry = APP_ROOT . '/index.php';
$_SERVER['SCRIPT_FILENAME'] = $entry;
$_SERVER['PHP_SELF'] = '/index.php';
chdir(APP_ROOT);
require $entry;
}
27 changes: 27 additions & 0 deletions vercel.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"version": 2,
"buildCommand": "composer install --no-dev --optimize-autoloader && php vercel/build.php",
"functions": {
"api/index.php": {
"runtime": "vercel-php@0.7.2",
"maxDuration": 10
}
},
"routes": [
{
"src": "^/(.+\\.(css|js|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot|map|txt|xml|pdf|zip)$)",
"dest": "/$1"
},
{
"src": "/(.*)",
"dest": "/api/index.php"
}
],
"env": {
"DB_HOST": "db.ubjlwpytufhcrnrjbfme.supabase.co",
"DB_PORT": "5432",
"DB_NAME": "postgres",
"DB_USER": "postgres",
"DB_PASS": "REPLACE_WITH_SUPABASE_PASSWORD"
}
}
12 changes: 12 additions & 0 deletions vercel/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Supabase (PostgreSQL) credentials
# Get these from: Supabase Dashboard → Project Settings → Database

DB_HOST=db.xxxxxxxxxxxxxxxxxxxx.supabase.co
DB_PORT=5432
DB_NAME=postgres
DB_USER=postgres
DB_PASS=your-supabase-db-password

# Root URL and timezone are hard-coded in vercel/build.php:
# g_root_path = https://www.ghanacouncil-nrw.de
# gTimezone = Europe/Berlin
33 changes: 33 additions & 0 deletions vercel/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Vercel Deployment — Ghana Council e.V.

This folder contains all Vercel-specific configuration and build scripts
for deploying the GCM application to [www.ghanacouncil-nrw.de](https://www.ghanacouncil-nrw.de).

## Files

| File | Purpose |
|------|---------|
| `build.php` | Build-time script that generates `adm_my_files/config.php` from Vercel environment variables |

The root `vercel.json` controls deployment settings and references this folder.

## Required Vercel Environment Variables

Set these as **secrets** in your Vercel project dashboard (Settings → Environment Variables):

| Variable | Description |
|----------|-------------|
| `DB_HOST` | Database server hostname |
| `DB_PORT` | Database port (optional) |
| `DB_NAME` | Database name |
| `DB_USER` | Database username |
| `DB_PASS` | Database password |

## Deploy Steps

1. Connect the `sandydiv3r/gcm` GitHub repository to a new Vercel project.
2. Add the environment variables above.
3. Deploy — Vercel will run `composer install` and `vercel/build.php` automatically.

> The generated `adm_my_files/config.php` is not committed to git.
> It is produced fresh on every Vercel build from the secrets above.
56 changes: 56 additions & 0 deletions vercel/build.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php
/**
* Vercel build script for Ghana Council e.V.
*
* Reads database credentials from environment variables defined in vercel.json.
* For the demo deployment all values are pre-filled.
* For production, override them in Vercel → Project Settings → Environment Variables.
*/

$dbHost = getenv('DB_HOST') ?: '';
$dbPort = getenv('DB_PORT');
$dbName = getenv('DB_NAME') ?: 'gcm_demo';
$dbUser = getenv('DB_USER') ?: 'gcm_demo';
$dbPass = getenv('DB_PASS') ?: 'GcmDemo@2024';

$portValue = ($dbPort !== false && $dbPort !== '') ? (int)$dbPort : 'null';

$config = <<<PHP
<?php
/**
* Admidio Configuration — Ghana Council e.V. (Demo)
* Website: https://www.ghanacouncil-nrw.de
*
* Generated by Vercel build — do not edit manually.
*/

\$gDbType = 'pgsql';
\$g_tbl_praefix = 'adm';

\$g_adm_srv = '{$dbHost}';
\$g_adm_port = {$portValue};
\$g_adm_db = '{$dbName}';
\$g_adm_usr = '{$dbUser}';
\$g_adm_pw = '{$dbPass}';

\$g_root_path = 'https://www.ghanacouncil-nrw.de';
\$gTimezone = 'Europe/Berlin';
PHP;

$configDir = __DIR__ . '/../../adm_my_files';
$configPath = $configDir . '/config.php';

if (!is_dir($configDir)) {
mkdir($configDir, 0755, true);
}

if (file_put_contents($configPath, $config) === false) {
echo "ERROR: Could not write to {$configPath}\n";
exit(1);
}

echo "✓ Generated adm_my_files/config.php\n";
echo " Organisation : Ghana Council e.V.\n";
echo " Root path : https://www.ghanacouncil-nrw.de\n";
echo " DB host : {$dbHost}\n";
echo " DB name : {$dbName}\n";