public function action() { $user = $this->hasAuthorative(); $xml = $this->getXML(); $xml = $this->makeMenu($xml); $confirmation = $this->_http->getParam("confirm", 'post'); $password = SLS_String::trimSlashesFromString($this->_http->getParam("password", 'post')); $login = SLS_String::trimSlashesFromString($this->_http->getParam("login", 'post')); $stepPassword = false; if ($confirmation == 'update') { $stepPassword = true; if (!empty($password) && !empty($login)) { $slsXml = $this->_generic->getCoreXML('sls'); $passXML = array_shift($slsXml->getTags("//sls_configs/auth/users/user[@login='******' and @level='0']/@pass")); if (!empty($passXML) && $passXML == sha1($password)) { $syncServer = array_shift($slsXml->getTags("slsnetwork")); $slsVersion = array_shift($slsXml->getTags("version")); $serversJSON = @file_get_contents($syncServer); if ($serversJSON !== false && !empty($serversJSON)) { $servers = json_decode($serversJSON); $updateServer = array_shift($servers->servers->update); if ($updateServer === false || empty($updateServer)) { $xml->addFullTag("error_server","Update server can't be found, please retry later"); } else { $serverContent = @file_get_contents($updateServer->url); $jsonContent = json_decode($serverContent); if ($jsonContent === false || empty($jsonContent)) { $xml->addFullTag("error_server","Update server not available, please retry later"); } else { $allSls = $jsonContent->releases; $currentSls = $slsVersion; // Foreach releases, check if we need to update it for($i=0 ; $i<$count=count($allSls) ; $i++) { $version = $allSls[$i]->version; // If it's we have to update to this version if ($version > $currentSls) { // If we can't download install files, abort update if (SLS_Remote::remoteFileExists($updateServer->domain.$allSls[$i]->archive) != 0 || SLS_Remote::remoteFileExists($updateServer->domain.$allSls[$i]->script) != 0) { $xml->addFullTag("error_server","Update process failed"); break; } // Else, it's cool, update this version else { // If 'Releases' directory doesn't exists, create it if (!is_dir($this->_generic->getPathConfig("coreTmpDownload")."Releases")) mkdir($this->_generic->getPathConfig("coreTmpDownload")."Releases"); // If 'Releases/[Release Version]' directory doesn't exists, create it if (!is_dir($this->_generic->getPathConfig("coreTmpDownload")."Releases/".$allSls[$i]->version)) mkdir($this->_generic->getPathConfig("coreTmpDownload")."Releases/".$allSls[$i]->version); // Archive & script names $archive = $this->_generic->getPathConfig("coreTmpDownload")."Releases/".$allSls[$i]->version."/archive.tar"; $script = $this->_generic->getPathConfig("coreTmpDownload")."Releases/".$allSls[$i]->version."/update.php"; // Copy archive & script $resultTar = @copy($updateServer->domain.$allSls[$i]->archive, $archive); $resultScript = @copy($updateServer->domain.$allSls[$i]->script, $script); // If a copy has failed if ($resultTar === false || $resultScript === false) { $xml->addFullTag("error_server","Update process failed"); break; } // Execute script eval(file_get_contents($script)); // Delete unstall files @unlink($this->_generic->getPathConfig("coreTmpDownload")."Releases/".$allSls[$i]->version."/archive.tar"); @unlink($this->_generic->getPathConfig("coreTmpDownload")."Releases/".$allSls[$i]->version."/update.php"); @rmdir($this->_generic->getPathConfig("coreTmpDownload")."Releases/".$allSls[$i]->version); } } } $this->_generic->goDirectTo("SLS_Bo","Updates"); } } } else { $xml->addFullTag("error_server","Synchronisation server not available, please retry later"); } } } } $xml->addFullTag('stepPassword', ($stepPassword) ? 'yes' : 'no', true); $this->saveXML($xml); }
public function action() { $user = $this->hasAuthorative(); $xml = $this->makeMenu($this->getXML()); $slsXml = $this->_generic->getCoreXML('sls'); $errors = array(); $syncServer = array_shift($slsXml->getTags("slsnetwork")); $action = $this->_http->getParam('Action'); $serverID = $this->_http->getParam("Server"); $pluginID = $this->_http->getParam("Plugin"); $this->registerLink("CREATE", "SLS_Bo", "CreatePlugin"); $controllers = $this->_generic->getTranslatedController('SLS_Bo', 'SearchPlugin'); $serversJSON = @file_get_contents($syncServer); if ($serversJSON === false ||empty($serversJSON)) $errors[] = "You are not connected to internet or synchronisation server is temporaly unavailable"; else { $servers = json_decode($serversJSON); $pluginsServers = $servers->servers->plugins; $plugins = array(); $xml->startTag("servers"); foreach ($pluginsServers as $pluginsServer) { $serverContent = @file_get_contents($pluginsServer->url); $xml->startTag("server", array("name"=>$pluginsServer->name,"id"=>$pluginsServer->id)); $xml->addFullTag("url", $pluginsServer->url, true, array("status"=>($serverContent === false || empty($serverContent)) ? "0" : "1")); if ($serverContent !== false && !empty($serverContent)) { $serverContent = json_decode($serverContent); $xml->startTag("plugins"); $plugs = $serverContent->plugins; foreach ($plugs as $plug) { // If we want to download this Plugin if ($action == "Download" && $pluginsServer->id == $serverID && $plug->id == $pluginID) { $way = $this->_http->getParam('Way'); $pluginXML = $this->_generic->getPluginXml("plugins"); if (count($pluginXML->getTags("//plugins/plugin[@id = '".$plug->id."']")) == 0 && count($pluginXML->getTags("//plugins/plugin[@code = '".$plug->code."' and @beta='1']")) == 0) { if (SLS_Remote::remoteFileExists($plug->file) != 0) $errors[] = $plug->name." is unavailable"; else { $filename = $this->_generic->getPathConfig("coreTmpDownload")."Plugins/".SLS_String::substrAfterLastDelimiter($plug->file, "/"); if (!is_dir($this->_generic->getPathConfig("coreTmpDownload")."Plugins")) mkdir($this->_generic->getPathConfig("coreTmpDownload")."Plugins"); $result = @copy($plug->file, $filename); if ($result === false) $errors[] = "The download of ".$plug->name." has failed"; else { $tar = new SLS_Tar(); if ($tar->openTAR($filename) === false) $errors[] = "Plugin archive is corrupted"; else { $hasConf = false; $isFile = true; $pathName = ""; foreach ($tar->directories as $directory) { if (SLS_String::startsWith($directory['name'], "Sources/")) { $dirName = SLS_String::substrAfterFirstDelimiter($directory['name'], "Sources/"); if (!empty($dirName)) { if (!is_dir($this->_generic->getPathConfig("plugins").$dirName)) mkdir($this->_generic->getPathConfig("plugins").$dirName); if (empty($pathName)) $pathName = (strpos($dirName, "/") !== false) ? SLS_String::substrBeforeLastDelimiter($dirName, "/") : $dirName; $isFile = false; } } } foreach ($tar->files as $file) { $copy = true; if (SLS_String::startsWith($file['name'], "Configs/") && SLS_String::endsWith($file['name'], ".xml")) { $hasConf = true; $copy = @file_put_contents($this->_generic->getPathConfig("configPlugins").$plug->id."_".$plug->code.".xml", $file['file']); } if (SLS_String::startsWith($file['name'], 'Sources/')) { if ($isFile === true && $pathName == "") $pathName = SLS_String::substrAfterFirstDelimiter($file['name'], "Sources/"); $realPathFile = $this->_generic->getPathConfig("plugins").SLS_String::substrAfterFirstDelimiter($file['name'], "Sources/"); $copy = @file_put_contents($realPathFile, $file['file']); } if ($copy === false) { $errors[] = "The copy of ".$file['name']." has failed"; } } if (empty($errors)) { $newPlugin = new SLS_XMLToolbox(false); $newPlugin->startTag("plugin", array("code"=>$plug->code,"id"=>$plug->id,"version"=>$plug->version,"compability"=>$plug->compability,"customizable"=>($hasConf) ? "1" : "0","file"=>($isFile)?"1":"0","path"=>$pathName)); $newPlugin->addFullTag("name", $plug->name, true); $newPlugin->addFullTag("description", $plug->desc, true); $newPlugin->addFullTag("author", $plug->author, true); $newPlugin->addFullTag("dependencies", "", false); $newPlugin->endTag("plugin"); $pluginXML->appendXMLNode("//plugins", $newPlugin->getXML('noHeader')); file_put_contents($this->_generic->getPathConfig("configPlugins")."plugins.xml", $pluginXML->getXML()); } if (is_file($filename)) unlink($filename); } } } } if ($way == "Maj") { $this->goDirectTo("SLS_Bo", "Plugins"); } }// /If we want to download this Plugin // We list all Plugins available on this server $exist = SLS_PluginsManager::isExists($plug->id); if ($exist) { $plugin = new SLS_PluginsManager($plug->id); } $xml->startTag("plugin", array("version"=>$plug->version,"code"=>$plug->code,"id"=>$plug->id,"compability"=>((float)$plug->compability<=(float)array_shift($slsXml->getTags("version"))) ? "1" : "0","has"=>($exist)?"1":"0")); $xml->addFullTag("name", $plug->name, true); $xml->addFullTag("doc", $pluginsServer->domain.$plug->doc, true); $xml->addFullTag("dl", $controllers['protocol']."://".$this->_generic->getSiteConfig("domainName")."/".$controllers['controller']."/".$controllers['scontroller']."/Action/Download/Server/".$pluginsServer->id."/Plugin/".$plug->id.".sls"); $xml->addFullTag("desc", $plug->desc, true); $xml->addFullTag("author", $plug->author, true); $xml->endTag("plugin"); } $xml->endTag("plugins"); } $xml->endTag("server"); } $xml->endTag("servers"); } if (!empty($errors)) { $xml->startTag("errors"); foreach ($errors as $error) $xml->addFullTag("error", $error, true); $xml->endTag("errors"); } $this->saveXML($xml); }