diff --git a/vbcms-admin/updater.php b/vbcms-admin/updater.php index 9c2597fc1c27c5e421be66d7cd5791bf2d931923..44aead9af1d1bb5c5aa3783e89b44e0f0b0b3907 100644 --- a/vbcms-admin/updater.php +++ b/vbcms-admin/updater.php @@ -111,29 +111,39 @@ if (!$hasNewUpdate) { } ?> }); - async function updateVBcms(){ - <?php - $updateKey = getRandomString(5); - $query=$bdd->query("SELECT * FROM `vbcms-settings` WHERE name = 'updateKey'")->fetch(PDO::FETCH_ASSOC); - if(empty($query)){ - $query=$bdd->prepare("INSERT INTO `vbcms-settings` (`name`, `value`) VALUES ('updateKey', ?)"); - $query->execute([$updateKey]); + function isJson(str) { + try { + JSON.parse(str); + } catch (e) { + return false; + } + return true; + } + async function updateVBcms(){ + <?php + $updateKey = getRandomString(5); + $query=$bdd->query("SELECT * FROM `vbcms-settings` WHERE name = 'updateKey'")->fetch(PDO::FETCH_ASSOC); + if(empty($query)){ + $query=$bdd->prepare("INSERT INTO `vbcms-settings` (`name`, `value`) VALUES ('updateKey', ?)"); + $query->execute([$updateKey]); + }else{ + $query=$bdd->prepare("UPDATE `vbcms-settings` SET `value` = ? WHERE `name` = 'updateKey'"); + $query->execute([$updateKey]); + } + + ?> + $.get("<?=VBcmsGetSetting("websiteUrl")?>backTasks?updateVBcms=<?=$updateKey?>", function(data) { + if (data=="") { + SnackBar({ + message: "backTasks ne retourne rien: "+data, + status: "danger", + timeout: false + }); }else{ - $query=$bdd->prepare("UPDATE `vbcms-settings` SET `value` = ? WHERE `name` = 'updateKey'"); - $query->execute([$updateKey]); - } - - ?> - $.get("<?=VBcmsGetSetting("websiteUrl")?>backTasks?updateVBcms=<?=$updateKey?>", function(data) { - if (data=="") { - SnackBar({ - message: "backTasks ne retourne rien: "+data, - status: "danger", - timeout: false - }); - }else{ - console.log(data); - details = JSON.parse(data); + console.log("<?=VBcmsGetSetting("websiteUrl")?>backTasks?updateVBcms=<?=$updateKey?> : "+data); + + if(isJson(data)){ + details = JSON.parse(data); if (details.success == true) { window.location.replace(details.link); } else { @@ -157,9 +167,17 @@ if (!$hasNewUpdate) { }); } } - } - }); - } + }else{ + SnackBar({ + message: "Erreur, backTasks ne retourne pas du JSON. Check la console.", + status: "danger", + timeout: false + }); + } + + } + }); + } </script> </body> </html> \ No newline at end of file diff --git a/vbcms-core/clientBackTasks.php b/vbcms-core/clientBackTasks.php index 238d8b50d867d6457d2a7e0074e103fa312809ad..f6c356c8247ab2eeec40e6c5d8719adc2308d627 100644 --- a/vbcms-core/clientBackTasks.php +++ b/vbcms-core/clientBackTasks.php @@ -7,7 +7,10 @@ if (isset($_GET["updateVBcms"])&&!empty($_GET["updateVBcms"])) { $updateFilename = $GLOBALS['vbcmsRootPath']."/vbcms-content/updates/".basename($newUpdateInfos['zip']); if (!file_exists($GLOBALS['vbcmsRootPath']."/vbcms-content/updates")) mkdir($GLOBALS['vbcmsRootPath']."/vbcms-content/updates", 0755); //echo $updateInfosData["downloadLink"]."?serverId=".VBcmsGetSetting("serverId")."&key=".$key; - file_put_contents($updateFilename, file_get_contents($newUpdateInfos["zip"])); + $options = array('http' => array('user_agent' => 'VBcms Updater')); + $context = stream_context_create($options); + + file_put_contents($updateFilename, file_get_contents($newUpdateInfos["zip"], true, $context)); if (file_exists($updateFilename)) { $zip = new ZipArchive; if ($zip->open($updateFilename) === TRUE) {