Skip to content

Instantly share code, notes, and snippets.

@samuelloza
Created April 27, 2025 17:26
Show Gist options
  • Save samuelloza/24d703f44ab50f5a276de712dda1a46d to your computer and use it in GitHub Desktop.
Save samuelloza/24d703f44ab50f5a276de712dda1a46d to your computer and use it in GitHub Desktop.
Test
<?php
$user = $_POST['user'] ?? null;
$password = $_POST['password'] ?? null;
if (!$user || !$password) {
die('Faltan datos.');
}
$repoUrl = 'https://github.com/Olimpiada-Boliviana-De-Informatica/OFBI-2025-IWD.git';
$tempPath = '/tmp/ofbi-repo';
if (is_dir($tempPath)) {
exec("rm -rf " . escapeshellarg($tempPath));
}
exec("git clone $repoUrl $tempPath 2>&1", $cloneOutput, $cloneReturn);
if ($cloneReturn !== 0) {
echo "Error al clonar el repositorio:\n";
echo "<pre>" . implode("\n", $cloneOutput) . "</pre>";
exit;
}
$csvFile = $tempPath . '/users/users.csv';
if (!file_exists($csvFile)) {
die('No existe users.csv');
}
file_put_contents($csvFile, "$user,$password\n", FILE_APPEND);
chdir($tempPath);
exec('git config user.name "PHP Bot"');
exec('git config user.email "[email protected]"');
exec('git add users/users.csv');
exec('git commit -m "Agregar nuevo usuario automaticamente"');
exec('git push origin main 2>&1', $pushOutput, $pushReturn);
if ($pushReturn === 0) {
echo "Usuario agregado y cambios subidos.";
} else {
echo "Error al hacer push:\n";
echo "<pre>" . implode("\n", $pushOutput) . "</pre>";
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment