- Removido README.md padrão do Laravel (backend) - Removidos scripts de deploy (não mais necessários) - Atualizado copilot-instructions.md para novo fluxo - Adicionada documentação de auditoria do servidor - Sincronizado código de produção com repositório Novo workflow: - Trabalhamos diretamente em /root/webmoney (symlink para /var/www/webmoney) - Mudanças PHP são instantâneas - Mudanças React requerem 'npm run build' - Commit após validação funcional
193 lines
5.6 KiB
PHP
Executable File
193 lines
5.6 KiB
PHP
Executable File
<?php
|
|
|
|
namespace App\Http\Controllers\Api;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\SiteSetting;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\File;
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
class SiteSettingsController extends Controller
|
|
{
|
|
/**
|
|
* Get all site settings
|
|
*/
|
|
public function index()
|
|
{
|
|
$settings = SiteSetting::all()->mapWithKeys(function ($setting) {
|
|
return [$setting->key => [
|
|
'value' => $setting->value['value'] ?? $setting->value,
|
|
'description' => $setting->description,
|
|
'updated_at' => $setting->updated_at,
|
|
]];
|
|
});
|
|
|
|
return response()->json([
|
|
'success' => true,
|
|
'settings' => $settings,
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Get a specific setting
|
|
*/
|
|
public function show(string $key)
|
|
{
|
|
$setting = SiteSetting::where('key', $key)->first();
|
|
|
|
if (!$setting) {
|
|
return response()->json([
|
|
'success' => false,
|
|
'message' => 'Configuración no encontrada',
|
|
], 404);
|
|
}
|
|
|
|
return response()->json([
|
|
'success' => true,
|
|
'key' => $setting->key,
|
|
'value' => $setting->value['value'] ?? $setting->value,
|
|
'description' => $setting->description,
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Update a setting
|
|
*/
|
|
public function update(Request $request, string $key)
|
|
{
|
|
$request->validate([
|
|
'value' => 'required',
|
|
'description' => 'nullable|string',
|
|
]);
|
|
|
|
$setting = SiteSetting::setValue(
|
|
$key,
|
|
$request->value,
|
|
$request->description
|
|
);
|
|
|
|
return response()->json([
|
|
'success' => true,
|
|
'message' => 'Configuración actualizada',
|
|
'setting' => [
|
|
'key' => $setting->key,
|
|
'value' => $setting->value['value'] ?? $setting->value,
|
|
'description' => $setting->description,
|
|
],
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Toggle cnxifly.com page mode
|
|
*/
|
|
public function toggleCnxiflyPage(Request $request)
|
|
{
|
|
$request->validate([
|
|
'mode' => 'required|in:live,maintenance,construction',
|
|
]);
|
|
|
|
$mode = $request->mode;
|
|
|
|
// Update database setting
|
|
SiteSetting::setValue('cnxifly_page_type', $mode, 'Tipo de página cnxifly.com');
|
|
SiteSetting::setValue('cnxifly_maintenance_mode', $mode !== 'live', 'Modo de mantenimiento');
|
|
|
|
// Get paths
|
|
$serverPath = '/var/www/cnxifly';
|
|
$localLandingPath = base_path('../landing');
|
|
|
|
// Log the action
|
|
Log::info("CnxiFly page mode changed to: {$mode}");
|
|
|
|
return response()->json([
|
|
'success' => true,
|
|
'message' => "Modo de página cambiado a: {$mode}",
|
|
'current_mode' => $mode,
|
|
'instructions' => $this->getInstructions($mode),
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Get cnxifly page status
|
|
*/
|
|
public function getCnxiflyStatus()
|
|
{
|
|
$mode = SiteSetting::getValue('cnxifly_page_type', 'live');
|
|
$maintenanceMode = SiteSetting::getValue('cnxifly_maintenance_mode', false);
|
|
|
|
return response()->json([
|
|
'success' => true,
|
|
'mode' => $mode,
|
|
'maintenance_mode' => $maintenanceMode,
|
|
'modes_available' => [
|
|
'live' => 'Página institucional completa',
|
|
'maintenance' => 'Página de mantenimiento',
|
|
'construction' => 'Página en construcción',
|
|
],
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Deploy cnxifly landing page to server
|
|
*/
|
|
public function deployCnxiflyPage(Request $request)
|
|
{
|
|
$request->validate([
|
|
'mode' => 'required|in:live,maintenance',
|
|
]);
|
|
|
|
$mode = $request->mode;
|
|
|
|
// Source files are in /var/www/cnxifly-pages/ on the server
|
|
$sourceDir = '/var/www/cnxifly-pages';
|
|
$targetDir = '/var/www/cnxifly';
|
|
$sourceFile = $mode === 'live' ? 'index.html' : 'maintenance.html';
|
|
$sourcePath = "{$sourceDir}/{$sourceFile}";
|
|
$targetPath = "{$targetDir}/index.html";
|
|
|
|
// Check if source file exists
|
|
if (!File::exists($sourcePath)) {
|
|
return response()->json([
|
|
'success' => false,
|
|
'message' => "Archivo de origen no encontrado: {$sourcePath}. Ejecute deploy-landing.sh primero.",
|
|
], 404);
|
|
}
|
|
|
|
// Copy the file
|
|
try {
|
|
File::copy($sourcePath, $targetPath);
|
|
} catch (\Exception $e) {
|
|
return response()->json([
|
|
'success' => false,
|
|
'message' => "Error al copiar archivo: " . $e->getMessage(),
|
|
], 500);
|
|
}
|
|
|
|
// Update setting
|
|
SiteSetting::setValue('cnxifly_page_type', $mode);
|
|
SiteSetting::setValue('cnxifly_maintenance_mode', $mode === 'maintenance');
|
|
|
|
return response()->json([
|
|
'success' => true,
|
|
'message' => "Página cnxifly.com actualizada a modo: {$mode}",
|
|
'current_mode' => $mode,
|
|
]);
|
|
}
|
|
|
|
private function getInstructions(string $mode): array
|
|
{
|
|
$sourceFile = match($mode) {
|
|
'live' => 'index.html',
|
|
'maintenance' => 'maintenance.html',
|
|
'construction' => 'maintenance.html',
|
|
};
|
|
|
|
return [
|
|
'description' => "Para aplicar el modo '{$mode}', copie el archivo {$sourceFile} al servidor",
|
|
'source_file' => $sourceFile,
|
|
'target_path' => '/var/www/cnxifly/index.html',
|
|
];
|
|
}
|
|
}
|