Integração Pangolin Proxy

This commit is contained in:
2025-12-06 21:11:34 -03:00
parent dc7c446254
commit 5291d8ccae
2008 changed files with 1062 additions and 477 deletions

View File

@@ -34,8 +34,21 @@
<?php foreach ($servers as $server): ?>
<?php
$lastSeen = !empty($server['last_seen']) ? strtotime($server['last_seen']) : 0;
$isOnline = $lastSeen && (time() - $lastSeen < 300); // 5 minutes
// Servidor só está online se está ATIVO e foi visto nos últimos 5 minutos
$isOnline = $server['status'] === 'active' && $lastSeen && (time() - $lastSeen < 300);
$lastSeenText = $lastSeen ? date('d/m/Y H:i', $lastSeen) : 'Nunca';
// Define a cor do badge do agente
if ($server['status'] !== 'active') {
$agentClass = 'bg-gray-100 text-gray-600';
$agentText = 'Inativo';
} elseif ($isOnline) {
$agentClass = 'bg-green-100 text-green-800';
$agentText = 'Online';
} else {
$agentClass = 'bg-red-100 text-red-800';
$agentText = 'Offline';
}
?>
<tr class="hover:bg-gray-50 transition-colors">
<td class="px-6 py-4 text-sm font-medium text-gray-900"><?= htmlspecialchars($server['name']) ?>
@@ -64,8 +77,8 @@
</td>
<td class="px-6 py-4 text-sm">
<span title="Visto por último: <?= $lastSeenText ?>"
class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full <?= $isOnline ? 'bg-green-100 text-green-800' : 'bg-red-100 text-red-800' ?>">
<?= $isOnline ? 'Online' : 'Offline' ?>
class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full <?= $agentClass ?>">
<?= $agentText ?>
</span>
</td>
<td class="px-6 py-4 text-sm font-medium">

View File

@@ -7,6 +7,11 @@
class="whitespace-nowrap py-4 px-1 border-b-2 font-medium text-sm transition-colors">
Interações
</button>
<button @click="activeTab = 'pangolin'"
:class="activeTab === 'pangolin' ? 'border-primary-500 text-primary-600' : 'border-transparent text-gray-500 hover:text-gray-700 hover:border-gray-300'"
class="whitespace-nowrap py-4 px-1 border-b-2 font-medium text-sm transition-colors">
Pangolin Proxy
</button>
</nav>
</div>
@@ -84,16 +89,93 @@
</div>
</div>
<!-- Pangolin Tab -->
<div x-show="activeTab === 'pangolin'" x-transition:enter="transition ease-out duration-200"
x-transition:enter-start="opacity-0 translate-y-2" x-transition:enter-end="opacity-100 translate-y-0"
style="display: none;">
<div class="max-w-2xl mx-auto bg-white rounded-xl shadow-sm border border-gray-100 p-6">
<h3 class="text-lg font-semibold text-gray-800 mb-6">Pangolin Proxy</h3>
<p class="text-sm text-gray-500 mb-6">Configure a integração com o Pangolin para gerenciar permissões de
acesso baseadas no ASN.</p>
<form action="/admin/settings/update" method="POST">
<div class="space-y-4">
<!-- Enable -->
<div class="flex items-center">
<input type="hidden" name="pangolin_enabled" value="0">
<input type="checkbox" name="pangolin_enabled" id="pangolin_enabled" value="1"
<?= ($settings['pangolin_enabled'] ?? '0') === '1' ? 'checked' : '' ?>
class="h-4 w-4 text-primary-600 focus:ring-primary-500 border-gray-300 rounded">
<label for="pangolin_enabled" class="ml-2 block text-sm text-gray-900">
Ativar Integração
</label>
</div>
<!-- API URL -->
<div>
<label for="pangolin_url" class="block text-sm font-medium text-gray-700 mb-1">URL da
API</label>
<input type="text" name="pangolin_url" id="pangolin_url"
value="<?= htmlspecialchars($settings['pangolin_url'] ?? '') ?>"
class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-primary-500 focus:border-transparent"
placeholder="https://api.pangolin.net/v1">
</div>
<!-- API Token -->
<div>
<label for="pangolin_token" class="block text-sm font-medium text-gray-700 mb-1">API
Token</label>
<input type="password" name="pangolin_token" id="pangolin_token"
value="<?= htmlspecialchars($settings['pangolin_token'] ?? '') ?>"
class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-primary-500 focus:border-transparent"
placeholder="Seu token de acesso">
</div>
<!-- Org ID -->
<div>
<label for="pangolin_org_id" class="block text-sm font-medium text-gray-700 mb-1">Organization ID</label>
<input type="text" name="pangolin_org_id" id="pangolin_org_id"
value="<?= htmlspecialchars($settings['pangolin_org_id'] ?? '') ?>"
class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-primary-500 focus:border-transparent"
placeholder="ipv0">
<p class="mt-1 text-sm text-gray-500">O identificador da organização (ex: na URL /ipv0/settings/... seria "ipv0").</p>
</div>
<!-- Resource Name -->
<div>
<label for="pangolin_resource_name" class="block text-sm font-medium text-gray-700 mb-1">Resource Name (Slug)</label>
<input type="text" name="pangolin_resource_name" id="pangolin_resource_name"
value="<?= htmlspecialchars($settings['pangolin_resource_name'] ?? '') ?>"
class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-primary-500 focus:border-transparent"
placeholder="cooperative-plains-pocket-gopher">
<p class="mt-1 text-sm text-gray-500">O nome do resource na URL (slug). Ex: na URL /resources/cooperative-plains-pocket-gopher/... seria "cooperative-plains-pocket-gopher".</p>
</div>
</div>
<div class="mt-6 flex justify-end space-x-3">
<button type="submit"
class="px-4 py-2 bg-primary-600 text-white rounded-lg hover:bg-primary-700 transition-colors">
Salvar Configurações
</button>
</div>
</form>
</div>
</div>
</div>
<script>
document.addEventListener('alpine:init', () => {
Alpine.data('settings', () => ({
activeTab: 'interactions',
activeTab: '<?= isset($_GET['tab']) ? $_GET['tab'] : 'interactions' ?>',
testing: false,
testIntegration() {
this.testing = true;
// Save settings first via AJAX if needed, but for now we assume saved settings

View File

@@ -23,8 +23,21 @@
<?php foreach ($servers as $server): ?>
<?php
$lastSeen = !empty($server['last_seen']) ? strtotime($server['last_seen']) : 0;
$isOnline = $lastSeen && (time() - $lastSeen < 300); // 5 minutes
// Servidor só está online se está ATIVO e foi visto nos últimos 5 minutos
$isOnline = $server['status'] === 'active' && $lastSeen && (time() - $lastSeen < 300);
$lastSeenText = $lastSeen ? date('d/m/Y H:i', $lastSeen) : 'Nunca';
// Define a cor do badge do agente
if ($server['status'] !== 'active') {
$agentClass = 'bg-gray-100 text-gray-600';
$agentText = 'Inativo';
} elseif ($isOnline) {
$agentClass = 'bg-green-100 text-green-800';
$agentText = 'Online';
} else {
$agentClass = 'bg-red-100 text-red-800';
$agentText = 'Offline';
}
?>
<tr class="hover:bg-gray-50 transition-colors">
<td class="px-6 py-4 text-sm font-medium text-gray-900"><?= htmlspecialchars($server['name']) ?>
@@ -52,8 +65,8 @@
</td>
<td class="px-6 py-4 text-sm">
<span title="Visto por último: <?= $lastSeenText ?>"
class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full <?= $isOnline ? 'bg-green-100 text-green-800' : 'bg-red-100 text-red-800' ?>">
<?= $isOnline ? 'Online' : 'Offline' ?>
class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full <?= $agentClass ?>">
<?= $agentText ?>
</span>
</td>
</tr>