Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
1bc3a3d
Add FTP deployment workflow
AlexCherrypi Jan 24, 2026
4536aed
Simplify FTP remote dir - user already in target folder
AlexCherrypi Jan 24, 2026
b7654e7
Trigger FTP deployment
AlexCherrypi Jan 24, 2026
7deee54
Fix: trigger on master branch instead of main
AlexCherrypi Jan 24, 2026
6ea88c1
Enable FTPS (TLS) for FTP connection
AlexCherrypi Jan 24, 2026
d655a90
Add .htaccess, index.php and update .gitignore
AlexCherrypi Jan 24, 2026
f81dcc2
Remove referer restriction for testing
AlexCherrypi Jan 24, 2026
8727d3f
Add debug script
AlexCherrypi Jan 24, 2026
12af43d
Add request parsing debug
AlexCherrypi Jan 24, 2026
8b8e7fd
Enable debug logging and error reporting
AlexCherrypi Jan 24, 2026
ab57afd
Fix curl error checking and double slash in cache path
AlexCherrypi Jan 24, 2026
54656d3
Clear server on deploy + scheduled cache cleanup every 5 days
AlexCherrypi Jan 24, 2026
5aefd3f
Clean server on every deploy
AlexCherrypi Jan 24, 2026
3688c23
Add referer restriction (block all invalid requests)
AlexCherrypi Jan 24, 2026
b871f86
Enable tile refresh after 5 days
AlexCherrypi Jan 24, 2026
08fb9cd
Add cache cleanup script for cron
AlexCherrypi Jan 24, 2026
469a246
Remove cleanup script - lives outside deploy dir
AlexCherrypi Jan 24, 2026
45ae9c3
Add generic cache cleanup script template
AlexCherrypi Jan 24, 2026
0c671ee
Make cache path a required argument
AlexCherrypi Jan 24, 2026
96b8fd6
Remove debug mode and debug.php
AlexCherrypi Jan 24, 2026
7b4da0c
Fix curl error handling and add cache cleanup script
AlexCherrypi Jan 24, 2026
75c2648
Forward Referer header to upstream tile servers
AlexCherrypi Apr 30, 2026
fb3bfa4
Merge branch 'master' into pr/bugfixes-and-improvements
AlexCherrypi May 2, 2026
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
34 changes: 34 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Deploy to FTP
concurrency:
group: ${{ github.workflow }}
cancel-in-progress: true
run-name: ${{ github.actor }} triggered deployment to FTP

on:
push:
branches:
- master

jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Upload to FTP
uses: SamKirkland/FTP-Deploy-Action@v4.3.5
with:
server: ${{ secrets.FTP_SERVER }}
username: ${{ secrets.FTP_USERNAME }}
password: ${{ secrets.FTP_PASSWORD }}
protocol: ftps
local-dir: ./
server-dir: ./
dangerous-clean-slate: true
exclude: |
**/.git*
**/.git*/**
**/example/**
**/README.md
**/LICENSE
**/composer.json
3 changes: 2 additions & 1 deletion public/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*
!.gitignore

!.htaccess
!index.php
13 changes: 13 additions & 0 deletions public/.htaccess
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
RewriteEngine on

# Block requests without valid referer (allow empty referer for direct API calls)
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^https?://(.*\.)?lammers-krueger\.de [NC]
RewriteCond %{HTTP_REFERER} !^https?://localhost [NC]
RewriteCond %{HTTP_REFERER} !^https?://127\.0\.0\.1 [NC]
RewriteRule .* - [F,L]

# Route all requests to index.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . /index.php [L]
17 changes: 17 additions & 0 deletions public/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

require_once(__DIR__ . '/../src/TileProxy.php');
require_once(__DIR__ . '/../src/MapStyle.php');

$style_osm = new \com\augmentedlogic\osmtileproxy\MapStyle("osm");
$style_osm->setMirrors(array("http://a.tile.openstreetmap.org", "http://b.tile.openstreetmap.org", "http://c.tile.openstreetmap.org"));

//$style_osm->setEffectModulate(100, 50, 100);
//$style_osm->setEffectSepia(90);
//$style_osm->setEffectNegate();

$tileproxy = new \com\augmentedlogic\osmtileproxy\TileProxy();
$tileproxy->addStyle($style_osm);
$tileproxy->setRefresh(5);
$tileproxy->setLogLevel(\com\augmentedlogic\osmtileproxy\TileProxy::LOGLEVEL_OFF);
$tileproxy->handle();
28 changes: 28 additions & 0 deletions scripts/cleanup-cache.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash
# OSM Tile Cache Cleanup Script
# Usage: ./cleanup-cache.sh [CACHE_DIR]
# Cron: 0 3 */5 * * /path/to/cleanup-cache.sh /path/to/cache

CACHE_DIR="${1:?Usage: $0 CACHE_DIR}"
MAX_AGE_DAYS=13
MAX_SIZE_BYTES=1073741824 # 1GB per style folder

# Delete files older than MAX_AGE_DAYS
find "$CACHE_DIR" -type f -mtime +$MAX_AGE_DAYS -delete

# Shrink folders over 1GB by deleting oldest files
for dir in "$CACHE_DIR"/*/; do
[ -d "$dir" ] || continue
while true; do
size=$(du -sb "$dir" 2>/dev/null | cut -f1)
[ -z "$size" ] && break
[ "$size" -le $MAX_SIZE_BYTES ] && break

oldest=$(find "$dir" -type f -printf '%T+ %p\n' 2>/dev/null | sort | head -1 | cut -d' ' -f2-)
[ -z "$oldest" ] && break
rm -f "$oldest"
done
done

# Remove empty directories
find "$CACHE_DIR" -type d -empty -delete
26 changes: 22 additions & 4 deletions src/TileProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,14 @@ class TileProxy

private $user_agent = "Mozilla/5.0 (X11; Linux i586; rv:31.0) Gecko/20100101 Firefox/74.0";

private $option_storage_dir = "../cache/";
private $option_log_dir = "../log/";
private $option_storage_dir = "../cache";
private $option_log_dir = "../log";
private $option_loglevel = 0;
private $option_ttl = 86400; // default browser expiry time
private $option_refresh = null; // refresh after n days, null = ignored

private $allow_referrer = null;
private $outgoing_referrer = null;
/**
* @var MapStyle[]
*/
Expand Down Expand Up @@ -91,6 +92,11 @@ public function setReferrer(?string $referrer = null): void
$this->allow_referrer = $referrer;
}

public function setOutgoingReferrer(?string $referrer = null): void
{
$this->outgoing_referrer = $referrer;
}

public function setLogLevel(int $loglevel): void
{
$this->option_loglevel = $loglevel;
Expand Down Expand Up @@ -140,14 +146,26 @@ private function fetchTile(MapStyle $current_style, string $filepath, string $ta
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_USERAGENT, $this->user_agent);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
$referer = !empty($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : $this->outgoing_referrer;
if (!empty($referer)) {
curl_setopt($ch, CURLOPT_REFERER, $referer);
}
curl_exec($ch);
$curlError = curl_errno($ch);
$curlErrorMsg = curl_error($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
fflush($fp);
fclose($fp);

// check if image downloaded successfully
if (curl_errno($ch) !== 0) {
throw new RuntimeException(curl_error($ch));
if ($curlError !== 0) {
throw new RuntimeException($curlErrorMsg);
} elseif ($httpCode !== 200) {
$content = @file_get_contents($save_to);
@unlink($save_to);
throw new RuntimeException("HTTP $httpCode: $content");
} elseif ($this->is_valid_image($save_to, $current_style)) {

if($current_style->getImageChecktype() !== MapStyle::IMAGE_FORMAT_PNG) {
Expand Down