Compare commits
6
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3701072bb3 | ||
|
|
8d92d08a56 | ||
|
|
12dfdd5fed | ||
|
|
a9ecad4ee1 | ||
|
|
0bbf053703 | ||
|
|
b1c9ffa461 |
@@ -74,7 +74,12 @@ function createMissingSchemaTablesAndFields() {
|
||||
$mysqlTableName = $TABLE_PREFIX . $tableName;
|
||||
if (!in_array($mysqlTableName, $mysqlTables)) {
|
||||
notice("Creating MySQL table for schema table: $tableName<br/>\n");
|
||||
$result = mysql_query("CREATE TABLE `".mysql_real_escape_string($mysqlTableName)."` (num int(10) unsigned NOT NULL auto_increment, PRIMARY KEY (num)) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4;");
|
||||
// InnoDB (antes MyISAM): las tablas nuevas nacen con recuperacion
|
||||
// ante caida y bloqueo por fila. No cambia que INSERT se aceptan:
|
||||
// el CMS conecta en modo estricto (mysqlStrictMode / TRADITIONAL
|
||||
// en Db.php) y en un INSERT de una fila eso rechaza lo mismo con
|
||||
// MyISAM que con InnoDB. Ver docs/motor-innodb.md del repo Forge.
|
||||
$result = mysql_query("CREATE TABLE `".mysql_real_escape_string($mysqlTableName)."` (num int(10) unsigned NOT NULL auto_increment, PRIMARY KEY (num)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;");
|
||||
if (!$result) { alert("Error creating MySQL table: $mysqlTableName<br/>\MySQL error was: ". htmlspecialchars(mysql_error()) . "\n"); }
|
||||
}
|
||||
|
||||
|
||||
@@ -324,17 +324,24 @@ function _removeFile() {
|
||||
}
|
||||
|
||||
function _deleteAll($str) {
|
||||
if (!file_exists($str)) return false;
|
||||
if (is_file($str)) {
|
||||
if (!file_exists($str) && !is_link($str)) return false;
|
||||
// Un symlink se quita, NUNCA se sigue: borrar su contenido seria borrar algo
|
||||
// que vive fuera de la carpeta que se pidio borrar.
|
||||
if (is_link($str) || is_file($str)) {
|
||||
return unlink($str);
|
||||
}
|
||||
elseif (is_dir($str)) {
|
||||
//Get a list of the files in this directory.
|
||||
$scan = glob(rtrim($str,'/').'/*');
|
||||
//Loop through the list of files.
|
||||
foreach($scan as $index=>$path) {
|
||||
//Call our recursive function.
|
||||
_deleteAll($path);
|
||||
// `scandir` y no `glob`: glob NO devuelve los ficheros ocultos, asi que
|
||||
// un `.htaccess` sobrevivia al borrado, la carpeta no quedaba vacia y el
|
||||
// rmdir de abajo fallaba en silencio. Con eso, desinstalar en produccion
|
||||
// un plugin con .htaccess —5 de 14 en una web real— borraba su codigo,
|
||||
// devolvia "no se ha podido desinstalar" y dejaba la operacion a medias:
|
||||
// sin ficheros, pero con la carpeta y con el alta en el central.
|
||||
$entradas = @scandir($str);
|
||||
if ($entradas === false) return false;
|
||||
foreach ($entradas as $nombre) {
|
||||
if ($nombre === '.' || $nombre === '..') continue;
|
||||
_deleteAll(rtrim($str, '/') . '/' . $nombre);
|
||||
}
|
||||
//Remove the directory itself.
|
||||
return @rmdir($str);
|
||||
@@ -392,13 +399,45 @@ function _renameFile() {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Segunda via de autenticacion del ciclo de vida, para las copias LOCALES de
|
||||
* Forge (standalone o de test). El WS central solo conoce webs de produccion:
|
||||
* el token de una web sin dominio real nunca le valida, asi que los ganchos
|
||||
* (install/uninstall/enable/disable) quedaban inservibles ahi con un
|
||||
* "Token no valido" que no tenia nada que ver con el token.
|
||||
*
|
||||
* No es un bypass: se compara el par token+tokenHash recibido con el que la
|
||||
* propia web guarda en su .acai, que es exactamente el que Forge envia. Sin
|
||||
* .acai (produccion), con mode=production, o sin coincidencia exacta, no
|
||||
* autoriza nada.
|
||||
*/
|
||||
function _lifecycleTokenLocalValido($datosAuth) {
|
||||
$acaiPath = __DIR__ . "/../../../.acai";
|
||||
if (!is_file($acaiPath)) {
|
||||
return false;
|
||||
}
|
||||
$acai = @json_decode(@file_get_contents($acaiPath), true);
|
||||
if (!is_array($acai) || @$acai["mode"] === "production") {
|
||||
return false;
|
||||
}
|
||||
$token = (string) @$datosAuth["token"];
|
||||
$hash = (string) @$datosAuth["tokenHash"];
|
||||
$tokenLocal = (string) @$acai["token"];
|
||||
$hashLocal = (string) @$acai["tokenHash"];
|
||||
if ($token === "" || $hash === "" || $tokenLocal === "" || $hashLocal === "") {
|
||||
return false;
|
||||
}
|
||||
return hash_equals($tokenLocal, $token) && hash_equals($hashLocal, $hash);
|
||||
}
|
||||
|
||||
function _pluginLifecycle() {
|
||||
// Fase 0 (2026-09-12): ejecuta los ganchos de ciclo de vida de un plugin
|
||||
// (install/uninstall/enable/disable/status) DENTRO de la web. Unico punto
|
||||
// de entrada para Forge y para el CMS legacy. Misma autenticacion que coreUpdate.
|
||||
$datosAuth = json_decode(file_get_contents('php://input'), true);
|
||||
CocoWS::setToken(@$datosAuth["token"]);
|
||||
if (!CocoWS::validateUploadToken(@$datosAuth["tokenHash"])) {
|
||||
if (!CocoWS::validateUploadToken(@$datosAuth["tokenHash"])
|
||||
&& !_lifecycleTokenLocalValido($datosAuth)) {
|
||||
die(json_encode(['error' => ['message' => 'Token no válido', 'code' => 403]]));
|
||||
}
|
||||
// Solo body JSON (como _saveFile): el token no debe viajar en la query string.
|
||||
|
||||
@@ -16,7 +16,10 @@ function getSchemaPlugins($force = false){
|
||||
}
|
||||
|
||||
$customSchemaFile = $fullPath."/custom-schema.ini.php";
|
||||
if (file_exists($customSchemaFile)){
|
||||
// Sin schema.ini.php no hay plugin: un custom-schema huerfano (p.ej. tras
|
||||
// un descarte del sync, que no mueve los custom-schema) se ignora en vez
|
||||
// de avisar en cada peticion.
|
||||
if (isset($schemaPlugins[$dirname]) && file_exists($customSchemaFile)){
|
||||
$customSchema = loadINI($customSchemaFile);
|
||||
$exclude = array("version", "name", "description");
|
||||
foreach ($exclude as $e):
|
||||
@@ -207,7 +210,7 @@ function addTablePlugin($path,$file) {
|
||||
$result = mysql_query("CREATE TABLE `".mysql_real_escape_string($tableNameWithPrefix)."` (
|
||||
num int(10) unsigned NOT NULL auto_increment,
|
||||
PRIMARY KEY (num)
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8;");
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;");
|
||||
if (!$result) {
|
||||
print "Error creating MySQL table.\n\nMySQL error was: ". htmlspecialchars(mysql_error()) . "\n";
|
||||
exit;
|
||||
|
||||
Reference in New Issue
Block a user