haproxy map

This commit is contained in:
Mateusz Gruszczyński
2026-02-23 13:10:16 +01:00
parent d82926a4d1
commit bf02af0192
7 changed files with 348 additions and 142 deletions

View File

@@ -352,120 +352,231 @@ const pollProgress = setInterval(async () => {
</div>
</div>
<!-- Endpoint 6: Generate Raw CIDR -->
<div class="card mb-3">
<div class="card-header api-header-post" onclick="toggleEndpoint('endpoint6')">
<div class="d-flex justify-content-between align-items-center">
<div>
<span class="badge bg-success me-2">POST</span>
<code class="api-path">/api/generate/raw</code>
<span class="ms-3 text-muted">Generate raw CIDR blocklist</span>
</div>
<i class="fas fa-chevron-down"></i>
</div>
</div>
<div class="card-body collapse" id="endpoint6">
<h6 class="fw-bold">Description</h6>
<p>Generates a raw CIDR blocklist without application-specific configuration. Perfect for iptables, fail2ban, or custom implementations.</p>
<h6 class="fw-bold mt-3">Request Body</h6>
<pre><code>{
<!-- Endpoint 6: Generate Raw CIDR -->
<div class="card mb-3">
<div class="card-header api-header-post" onclick="toggleEndpoint('endpoint6')">
<div class="d-flex justify-content-between align-items-center">
<div>
<span class="badge bg-success me-2">POST</span>
<code class="api-path">/api/generate/raw</code>
<span class="ms-3 text-muted">Generate raw blocklist (TXT/CSV/JSON/JS)</span>
</div>
<i class="fas fa-chevron-down"></i>
</div>
</div>
<div class="card-body collapse" id="endpoint6">
<h6 class="fw-bold">Description</h6>
<p>
Generates a raw blocklist without application-specific configuration.
Use this endpoint for programmatic integrations when you need structured output (JSON) or a JS-wrapped JSON payload.
</p>
<h6 class="fw-bold mt-3">Request Body</h6>
<pre><code>{
"countries": [<span class="text-warning">"CN"</span>, <span class="text-warning">"RU"</span>],
"app_variant": <span class="text-warning">"txt"</span>,
"app_type": <span class="text-warning">"raw-json"</span>,
"aggregate": <span class="text-success">true</span>,
"use_cache": <span class="text-success">true</span>
"use_cache": <span class="text-success">true</span>,
"as_js": <span class="text-success">false</span>,
"js_var": <span class="text-warning">"geoipBlocklist"</span>
}</code></pre>
<h6 class="fw-bold mt-3">Parameters</h6>
<table class="table table-sm">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Required</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>countries</code></td>
<td>array</td>
<td><span class="badge bg-danger">required</span></td>
<td>List of ISO 3166-1 alpha-2 country codes</td>
</tr>
<tr>
<td><code>app_variant</code></td>
<td>string</td>
<td><span class="badge bg-secondary">optional</span></td>
<td>Output format: <code>txt</code> (default) or <code>csv</code></td>
</tr>
<tr>
<td><code>aggregate</code></td>
<td>boolean</td>
<td><span class="badge bg-secondary">optional</span></td>
<td>Aggregate IP networks (default: true)</td>
</tr>
<tr>
<td><code>use_cache</code></td>
<td>boolean</td>
<td><span class="badge bg-secondary">optional</span></td>
<td>Use Redis cache if available (default: true)</td>
</tr>
</tbody>
</table>
<h6 class="fw-bold mt-3">Response</h6>
<p>Returns plain text file with CIDR blocks (one per line) or CSV with CIDR and country columns.</p>
<h6 class="fw-bold mt-3">Response Headers</h6>
<table class="table table-sm">
<thead>
<tr>
<th>Header</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>X-From-Cache</code></td>
<td><code>true</code> or <code>false</code> - indicates if served from Redis</td>
</tr>
<tr>
<td><code>X-Cache-Type</code></td>
<td><code>redis</code> or <code>sqlite</code> - data source type</td>
</tr>
<tr>
<td><code>X-Generated-At</code></td>
<td>Timestamp when config was generated</td>
</tr>
</tbody>
</table>
<h6 class="fw-bold mt-3">cURL Examples</h6>
<p class="mb-2"><strong>With cache (faster):</strong></p>
<pre><code>curl -X POST <span id="curlUrl2"></span>/api/generate/raw \
<h6 class="fw-bold mt-3">Parameters</h6>
<table class="table table-sm">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Required</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>countries</code></td>
<td>array</td>
<td><span class="badge bg-danger">required</span></td>
<td>List of ISO 3166-1 alpha-2 country codes</td>
</tr>
<tr>
<td><code>app_type</code></td>
<td>string</td>
<td><span class="badge bg-secondary">optional</span></td>
<td>
Output format selector. Examples:
<code>raw-json</code> (JSON), <code>raw-json</code> + <code>as_js=true</code> (JS wrapper).
</td>
</tr>
<tr>
<td><code>aggregate</code></td>
<td>boolean</td>
<td><span class="badge bg-secondary">optional</span></td>
<td>Aggregate IP networks (default: true)</td>
</tr>
<tr>
<td><code>use_cache</code></td>
<td>boolean</td>
<td><span class="badge bg-secondary">optional</span></td>
<td>Use Redis cache if available (default: true)</td>
</tr>
<tr>
<td>
Only for <code>raw-json</code>.
When <code>true</code>, wraps JSON into JavaScript and returns <code>application/javascript</code> as:
<code>const &lt;js_var&gt; = {...};</code>
</td>
</tr>
<tr>
<td><code>js_var</code></td>
<td>string</td>
<td><span class="badge bg-secondary">optional</span></td>
<td>
Variable name used by <code>as_js</code> wrapper (default: <code>geoipBlocklist</code>).
</td>
</tr>
</tbody>
</table>
<h6 class="fw-bold mt-3">Responses</h6>
<table class="table table-sm">
<thead>
<tr>
<th>Mode</th>
<th>Content-Type</th>
<th>Body</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>raw-cidr_txt</code></td>
<td><code>text/plain</code></td>
<td>One CIDR per line</td>
</tr>
<tr>
<td><code>raw-cidr_csv</code></td>
<td><code>text/csv</code></td>
<td>CSV export</td>
</tr>
<tr>
<td><code>raw-cidr_json</code></td>
<td><code>application/json</code></td>
<td>JSON object with <code>countries</code>, <code>networks</code>, <code>count</code>, <code>aggregated</code></td>
</tr>
<tr>
<td><code>raw-cidr_json</code> + <code>as_js=true</code></td>
<td><code>application/javascript</code></td>
<td><code>const &lt;js_var&gt; = {...};</code></td>
</tr>
</tbody>
</table>
<h6 class="fw-bold mt-3">Responses</h6>
<table class="table table-sm">
<thead>
<tr>
<th>Mode</th>
<th>Content-Type</th>
<th>Body</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>raw-cidr_txt</code></td>
<td><code>text/plain</code></td>
<td>One CIDR per line</td>
</tr>
<tr>
<td><code>raw-cidr_csv</code></td>
<td><code>text/csv</code></td>
<td>CSV export</td>
</tr>
<tr>
<td><code>raw-json</code></td>
<td><code>application/json</code></td>
<td>JSON object with <code>generated_at</code>, <code>countries</code>, <code>networks</code>, <code>total_networks</code></td>
</tr>
<tr>
<td><code>raw-json</code> + <code>as_js=true</code></td>
<td><code>application/javascript</code></td>
<td><code>const &lt;js_var&gt; = {...};</code></td>
</tr>
</tbody>
</table>
<h6 class="fw-bold mt-3">Response Headers</h6>
<table class="table table-sm">
<thead>
<tr>
<th>Header</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>X-From-Cache</code></td>
<td><code>true</code> or <code>false</code> - indicates if served from Redis</td>
</tr>
<tr>
<td><code>X-Cache-Type</code></td>
<td><code>redis-full</code> or computed cache type (e.g. <code>hybrid</code>)</td>
</tr>
<tr>
<td><code>X-Generated-At</code></td>
<td>Timestamp when config was generated</td>
</tr>
</tbody>
</table>
<h6 class="fw-bold mt-3">cURL Examples</h6>
<p class="mb-2"><strong>TXT (default):</strong></p>
<pre><code>curl -X POST <span id="curlUrl2"></span>/api/generate/raw \
-H "Content-Type: application/json" \
-d '{
"countries": ["CN", "RU"],
"app_variant": "txt",
"app_type": "raw-cidr_txt",
"aggregate": true,
"use_cache": true
}' \
-o blocklist.txt</code></pre>
<p class="mb-2 mt-3"><strong>Force fresh data (slower but guaranteed up-to-date):</strong></p>
<pre><code>curl -X POST <span id="curlUrl2b"></span>/api/generate/raw \
<p class="mb-2 mt-3"><strong>CSV:</strong></p>
<pre><code>curl -X POST <span id="curlUrl2csv"></span>/api/generate/raw \
-H "Content-Type: application/json" \
-d '{
"countries": ["CN", "RU"],
"app_variant": "txt",
"app_type": "raw-cidr_csv",
"aggregate": true,
"use_cache": false
"use_cache": true
}' \
-o blocklist_fresh.txt</code></pre>
</div>
</div>
-o blocklist.csv</code></pre>
<p class="mb-2 mt-3"><strong>JSON:</strong></p>
<pre><code>curl -X POST <span id="curlUrl2b"></span>/api/generate/raw \
-H "Content-Type: application/json" \
-d '{
"countries": ["CN", "RU"],
"app_type": "raw-json",
"aggregate": true,
"use_cache": true
}' \
-o blocklist.json</code></pre>
<p class="mb-2 mt-3"><strong>JS-wrapped JSON:</strong></p>
<pre><code>curl -X POST <span id="curlUrl2c"></span>/api/generate/raw \
-H "Content-Type: application/json" \
-d '{
"countries": ["CN", "RU"],
"app_type": "raw-json",
"aggregate": true,
"use_cache": true,
"as_js": true,
"js_var": "geoipBlocklist"
}' \
-o blocklist.js</code></pre>
</div>
</div>
<!-- Endpoint 7: Generate Configuration -->
@@ -541,7 +652,7 @@ const pollProgress = setInterval(async () => {
<ul>
<li><strong>nginx:</strong> <code>geo</code>, <code>map</code>, <code>deny</code></li>
<li><strong>apache:</strong> <code>22</code> (Apache 2.2), <code>24</code> (Apache 2.4)</li>
<li><strong>haproxy:</strong> <code>acl</code>, <code>lua</code></li>
<li><strong>haproxy:</strong> <code>acl</code>, <code>lua</code>, <code>map</code></li>
</ul>
<h6 class="fw-bold mt-3">Response</h6>