Subir archivos a "/"

This commit is contained in:
darnix 2025-11-24 21:51:07 +00:00
parent 5f1f504a13
commit 8a88153cf5

145
php.sh Normal file
View File

@ -0,0 +1,145 @@
#!/usr/bin/env bash
set -euo pipefail
# Comprobar que se ejecuta como root
if [ "$(id -u)" -ne 0 ]; then
echo "Ejecuta este script como root (sudo)."
exit 1
fi
# Variables
WWW_DIR="/var/www/html/CheckPHP"
PHP_FILE="$WWW_DIR/CheckKey.php"
DATABASE="$WWW_DIR/database.txt"
MESSAGE="$WWW_DIR/message.txt"
USED_LOGS="$WWW_DIR/used_logs.txt"
echo "==> Actualizando paquetes e instalando apache2, php y libapache2-mod-php..."
apt-get update
apt-get install -y apache2 php libapache2-mod-php
echo "==> Creando carpeta $WWW_DIR y archivos necesarios..."
mkdir -p "$WWW_DIR"
touch "$DATABASE" "$MESSAGE" "$USED_LOGS"
echo "==> Escribiendo el archivo PHP (no se modifica el código que proporcionaste)..."
cat > "$PHP_FILE" <<'PHP'
<?php
// ==========================================
// CONFIGURACIÓN
// ==========================================
$bot_token = "6267632209:AAHWAEr9B7Bi73MSbHDCafq9u34uhZ3A0VI"; // <--- ¡PON TU TOKEN AQUÍ!
$key_recibida = trim($_REQUEST['clave']);
$database = "database.txt";
$history_log = "used_logs.txt";
$message_file = "message.txt"; // <--- El archivo donde guardaremos el nombre
// Validaciones básicas
if (!file_exists($database) || empty($key_recibida)) {
die("clave_invalida");
}
// Leer base de datos
$lineas = file($database, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
$status = "clave_invalida";
$nuevas_lineas = array();
$ip_cliente = $_SERVER['REMOTE_ADDR'];
$fecha_hora = date("Y-m-d H:i:s");
// Función para enviar mensaje a Telegram
function enviar_notificacion($token, $chat_id, $key, $ip, $nombre) {
if (empty($chat_id) || empty($token)) return;
$mensaje = "🔔 <b>NOTIFICACIÓN DE USO</b> 🔔\n\n";
$mensaje .= "✅ <b>Tu Key ha sido activada.</b>\n";
$mensaje .= "👤 <b>Nombre:</b> $nombre\n";
$mensaje .= "🔑 <b>Key:</b> <code>$key</code>\n";
$mensaje .= "🌐 <b>IP Cliente:</b> <code>$ip</code>\n";
$mensaje .= "📅 <b>Fecha:</b> " . date("Y-m-d H:i:s");
$url = "https://api.telegram.org/bot$token/sendMessage";
$data = [
'chat_id' => $chat_id,
'text' => $mensaje,
'parse_mode' => 'HTML'
];
$options = [
'http' => [
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
'method' => 'POST',
'content' => http_build_query($data),
],
];
$context = stream_context_create($options);
file_get_contents($url, false, $context);
}
foreach ($lineas as $linea) {
// Formato: KEY | NOMBRE_TELEGRAM | FECHA | ID_TELEGRAM
$datos = explode('|', trim($linea));
if (count($datos) < 3) continue;
$key_db = $datos[0];
$usuario_db = $datos[1]; // Aquí viene el Nombre de Telegram
$fecha_exp = $datos[2];
$telegram_id = isset($datos[3]) ? $datos[3] : "";
if ($key_db == $key_recibida) {
$fecha_actual = date("Y-m-d");
if ($fecha_actual <= $fecha_exp) {
$status = "clave_valida";
// 1. Guardar Log de historial
$registro = "$fecha_hora | IP: $ip_cliente | Nombre: $usuario_db | Key: $key_db\n";
file_put_contents($history_log, $registro, FILE_APPEND);
// 2. GUARDAR EL NOMBRE EN message.txt
// Esto sobrescribe el archivo con el nombre del usuario actual
file_put_contents($message_file, $usuario_db);
// 3. Enviar notificación a Telegram
if (!empty($telegram_id)) {
enviar_notificacion($bot_token, $telegram_id, $key_db, $ip_cliente, $usuario_db);
}
// La línea NO se añade a $nuevas_lineas, por lo tanto se borra de la DB
} else {
$status = "clave_expirada";
}
} else {
$nuevas_lineas[] = $linea;
}
}
// Reescribir archivo (borrando la usada)
if ($status == "clave_valida") {
$contenido_final = implode("\n", $nuevas_lineas);
if (!empty($contenido_final)) {
$contenido_final .= "\n";
}
file_put_contents($database, $contenido_final);
}
echo $status;
?>
PHP
echo "==> Aplicando permisos y cambiando propietario..."
chmod -R 777 "$WWW_DIR"
chown -R www-data:www-data "$WWW_DIR"
echo "==> Reiniciando Apache..."
if command -v systemctl >/dev/null 2>&1; then
systemctl restart apache2
else
service apache2 restart
fi
echo "==> Instalación completada."
echo "Archivos creados en: $WWW_DIR"
echo "Asegúrate de que tu token y datos en CheckKey.php son correctos."