Initial commit
commit
b1f4aa0051
|
@ -0,0 +1,2 @@
|
|||
vendor/
|
||||
config.yaml
|
|
@ -0,0 +1,13 @@
|
|||
{
|
||||
"name": "devbones/traefik-proxy",
|
||||
"type": "project",
|
||||
"license": "MIT",
|
||||
"authors": [
|
||||
{
|
||||
"name": "conky"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"symfony/yaml": "^6.1"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,175 @@
|
|||
{
|
||||
"_readme": [
|
||||
"This file locks the dependencies of your project to a known state",
|
||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "b86f98087a378b070b52e8464cfd3b19",
|
||||
"packages": [
|
||||
{
|
||||
"name": "symfony/polyfill-ctype",
|
||||
"version": "v1.26.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/symfony/polyfill-ctype.git",
|
||||
"reference": "6fd1b9a79f6e3cf65f9e679b23af304cd9e010d4"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/6fd1b9a79f6e3cf65f9e679b23af304cd9e010d4",
|
||||
"reference": "6fd1b9a79f6e3cf65f9e679b23af304cd9e010d4",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=7.1"
|
||||
},
|
||||
"provide": {
|
||||
"ext-ctype": "*"
|
||||
},
|
||||
"suggest": {
|
||||
"ext-ctype": "For best performance"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-main": "1.26-dev"
|
||||
},
|
||||
"thanks": {
|
||||
"name": "symfony/polyfill",
|
||||
"url": "https://github.com/symfony/polyfill"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"files": [
|
||||
"bootstrap.php"
|
||||
],
|
||||
"psr-4": {
|
||||
"Symfony\\Polyfill\\Ctype\\": ""
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Gert de Pagter",
|
||||
"email": "BackEndTea@gmail.com"
|
||||
},
|
||||
{
|
||||
"name": "Symfony Community",
|
||||
"homepage": "https://symfony.com/contributors"
|
||||
}
|
||||
],
|
||||
"description": "Symfony polyfill for ctype functions",
|
||||
"homepage": "https://symfony.com",
|
||||
"keywords": [
|
||||
"compatibility",
|
||||
"ctype",
|
||||
"polyfill",
|
||||
"portable"
|
||||
],
|
||||
"support": {
|
||||
"source": "https://github.com/symfony/polyfill-ctype/tree/v1.26.0"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
"url": "https://symfony.com/sponsor",
|
||||
"type": "custom"
|
||||
},
|
||||
{
|
||||
"url": "https://github.com/fabpot",
|
||||
"type": "github"
|
||||
},
|
||||
{
|
||||
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
|
||||
"type": "tidelift"
|
||||
}
|
||||
],
|
||||
"time": "2022-05-24T11:49:31+00:00"
|
||||
},
|
||||
{
|
||||
"name": "symfony/yaml",
|
||||
"version": "v6.1.6",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/symfony/yaml.git",
|
||||
"reference": "66c6b0cf52b00f74614a2cf7ae7db08ea1095931"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/symfony/yaml/zipball/66c6b0cf52b00f74614a2cf7ae7db08ea1095931",
|
||||
"reference": "66c6b0cf52b00f74614a2cf7ae7db08ea1095931",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=8.1",
|
||||
"symfony/polyfill-ctype": "^1.8"
|
||||
},
|
||||
"conflict": {
|
||||
"symfony/console": "<5.4"
|
||||
},
|
||||
"require-dev": {
|
||||
"symfony/console": "^5.4|^6.0"
|
||||
},
|
||||
"suggest": {
|
||||
"symfony/console": "For validating YAML files using the lint command"
|
||||
},
|
||||
"bin": [
|
||||
"Resources/bin/yaml-lint"
|
||||
],
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Symfony\\Component\\Yaml\\": ""
|
||||
},
|
||||
"exclude-from-classmap": [
|
||||
"/Tests/"
|
||||
]
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Fabien Potencier",
|
||||
"email": "fabien@symfony.com"
|
||||
},
|
||||
{
|
||||
"name": "Symfony Community",
|
||||
"homepage": "https://symfony.com/contributors"
|
||||
}
|
||||
],
|
||||
"description": "Loads and dumps YAML files",
|
||||
"homepage": "https://symfony.com",
|
||||
"support": {
|
||||
"source": "https://github.com/symfony/yaml/tree/v6.1.6"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
"url": "https://symfony.com/sponsor",
|
||||
"type": "custom"
|
||||
},
|
||||
{
|
||||
"url": "https://github.com/fabpot",
|
||||
"type": "github"
|
||||
},
|
||||
{
|
||||
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
|
||||
"type": "tidelift"
|
||||
}
|
||||
],
|
||||
"time": "2022-10-07T08:04:03+00:00"
|
||||
}
|
||||
],
|
||||
"packages-dev": [],
|
||||
"aliases": [],
|
||||
"minimum-stability": "stable",
|
||||
"stability-flags": [],
|
||||
"prefer-stable": false,
|
||||
"prefer-lowest": false,
|
||||
"platform": [],
|
||||
"platform-dev": [],
|
||||
"plugin-api-version": "2.3.0"
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
version: '3'
|
||||
|
||||
services:
|
||||
handler:
|
||||
image: thecodingmachine/php:8.1-v4-slim-apache
|
||||
restart: unless-stopped
|
||||
ports:
|
||||
- "8080:80"
|
||||
volumes:
|
||||
- "./:/var/www/html"
|
||||
- /var/run/docker.sock:/var/run/docker.sock
|
|
@ -0,0 +1,76 @@
|
|||
<?php
|
||||
|
||||
use Symfony\Component\Yaml\Yaml;
|
||||
|
||||
require './vendor/autoload.php';
|
||||
|
||||
$config = Yaml::parseFile('config.yaml');
|
||||
|
||||
$data = [
|
||||
'http' => [
|
||||
'routers' => [],
|
||||
'services' => [],
|
||||
],
|
||||
];
|
||||
foreach ($config['servers'] as $server_name => $server_ip) {
|
||||
$proxy_routers = @file_get_contents("http://{$server_ip}:8080/api/http/routers");
|
||||
if (empty($proxy_routers)) {
|
||||
continue;
|
||||
}
|
||||
$proxy_routers = json_decode($proxy_routers, TRUE);
|
||||
$server_key = 'proxy-'.$server_name;
|
||||
$data['http']['services'][$server_key] = [
|
||||
'loadBalancer' => [
|
||||
'servers' => [
|
||||
['url' => "http://{$server_ip}:80"],
|
||||
],
|
||||
'passHostHeader' => TRUE,
|
||||
],
|
||||
];
|
||||
foreach ($proxy_routers as $router) {
|
||||
if ($router['status'] !== 'enabled' || $router['provider'] !== 'docker') {
|
||||
continue;
|
||||
}
|
||||
preg_match_all("/Host\(\`(?'domain'[a-zA-Z\.\-]+)\`\)/m", $router['rule'], $rule_hosts);
|
||||
if (empty($rule_hosts['domain'])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$domains = [];
|
||||
foreach ($rule_hosts['domain'] as $domain) {
|
||||
$is_docker_name = !str_contains($domain, '.');
|
||||
if ($is_docker_name) {
|
||||
continue;
|
||||
}
|
||||
$domains[] = $domain;
|
||||
}
|
||||
if (empty($domains)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$main_router = [
|
||||
'entryPoints' => ['websecure'],
|
||||
'rule' => $router['rule'],
|
||||
'service' => $server_key,
|
||||
'tls' => [
|
||||
'certResolver' => 'defaultResolver',
|
||||
'domains' => [],
|
||||
],
|
||||
];
|
||||
|
||||
foreach ($domains as $domain) {
|
||||
$main_router['tls']['domains'][] = [
|
||||
'main' => $domain,
|
||||
'sans' => [],
|
||||
];
|
||||
}
|
||||
|
||||
$router_name = $server_key . '--' . $router['name'];
|
||||
$router_name = str_replace(['@'], '_', $router_name);
|
||||
$data['http']['routers'][$router_name] = $main_router;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
header('application/x-yaml');
|
||||
echo Yaml::dump($data, 4, 2, Yaml::DUMP_MULTI_LINE_LITERAL_BLOCK | Yaml::DUMP_OBJECT_AS_MAP);
|
Loading…
Reference in New Issue