yellow/system/plugins/update.php

599 lines
22 KiB
PHP
Raw Normal View History

2016-06-27 13:28:10 +00:00
<?php
2017-01-03 13:11:44 +00:00
// Copyright (c) 2013-2017 Datenstrom, http://datenstrom.se
2016-06-27 13:28:10 +00:00
// This file may be used and distributed under the terms of the public license.
// Update plugin
class YellowUpdate
{
2017-02-02 08:54:57 +00:00
const VERSION = "0.6.12";
2016-06-27 13:28:10 +00:00
var $yellow; //access to API
// Handle initialisation
function onLoad($yellow)
{
$this->yellow = $yellow;
$this->yellow->config->setDefault("updatePluginsUrl", "https://github.com/datenstrom/yellow-plugins");
$this->yellow->config->setDefault("updateThemesUrl", "https://github.com/datenstrom/yellow-themes");
2016-07-10 18:44:02 +00:00
$this->yellow->config->setDefault("updateInformationFile", "update.ini");
2017-02-02 08:54:57 +00:00
$this->yellow->config->setDefault("updateVersionFile", "version.ini");
2017-01-03 13:11:44 +00:00
$this->yellow->config->setDefault("updateNotification", "none");
}
// Handle update
function onUpdate($name)
{
if(empty($name)) $this->processUpdateNotification();
2016-06-27 13:28:10 +00:00
}
// Handle request
function onRequest($serverScheme, $serverName, $base, $location, $fileName)
{
$statusCode = 0;
2017-01-03 13:11:44 +00:00
if($this->isInstallationMode())
2016-06-27 13:28:10 +00:00
{
2017-01-03 13:11:44 +00:00
$statusCode = $this->processRequestInstallationMode($serverScheme, $serverName, $base, $location, $fileName);
2016-06-27 13:28:10 +00:00
} else {
2017-01-03 13:11:44 +00:00
$statusCode = $this->processRequestInstallationPending($serverScheme, $serverName, $base, $location, $fileName);
2016-06-27 13:28:10 +00:00
}
return $statusCode;
}
// Handle command
function onCommand($args)
{
list($command) = $args;
switch($command)
{
2017-01-03 13:11:44 +00:00
case "clean": $statusCode = $this->cleanCommand($args); break;
2016-06-27 13:28:10 +00:00
case "update": $statusCode = $this->updateCommand($args); break;
2017-01-03 13:11:44 +00:00
default: $statusCode = $this->processCommandInstallationPending($args); break;
2016-06-27 13:28:10 +00:00
}
return $statusCode;
}
// Handle command help
function onCommandHelp()
{
return "update [FEATURE]";
}
2017-01-03 13:11:44 +00:00
// Clean downloads
function cleanCommand($args)
{
$statusCode = 0;
list($command, $path) = $args;
if($path=="all")
{
$path = $this->yellow->config->get("pluginDir");
$regex = "/^.*\\".$this->yellow->config->get("downloadExtension")."$/";
foreach($this->yellow->toolbox->getDirectoryEntries($path, $regex, false, false) as $entry)
{
if(!$this->yellow->toolbox->deleteFile($entry)) $statusCode = 500;
}
if($statusCode==500) echo "ERROR cleaning downloads: Can't delete files in directory '$path'!\n";
}
return $statusCode;
}
2016-08-18 19:57:07 +00:00
// Update website
2016-06-27 13:28:10 +00:00
function updateCommand($args)
{
2017-01-03 13:11:44 +00:00
list($command, $feature, $option) = $args;
list($statusCode, $data) = $this->getSoftwareUpdates($feature);
2016-07-19 16:28:52 +00:00
if(!empty($data))
2016-06-27 13:28:10 +00:00
{
2016-07-19 16:28:52 +00:00
foreach($data as $key=>$value)
2016-06-27 13:28:10 +00:00
{
2016-07-20 09:44:17 +00:00
list($version) = explode(',', $value);
2016-07-19 16:28:52 +00:00
echo "$key $version\n";
2016-06-27 13:28:10 +00:00
}
2017-01-03 13:11:44 +00:00
if($statusCode==200) $statusCode = $this->downloadSoftware($data);
if($statusCode==200) $statusCode = $this->updateSoftware($option);
2016-07-19 22:12:05 +00:00
if($statusCode!=200) echo "ERROR updating files: ".$this->yellow->page->get("pageError")."\n";
2016-08-18 19:57:07 +00:00
echo "Yellow $command: Website ".($statusCode!=200 ? "not " : "")."updated\n";
2016-06-27 13:28:10 +00:00
} else {
2016-07-19 22:12:05 +00:00
if($statusCode!=200) echo "ERROR updating files: ".$this->yellow->page->get("pageError")."\n";
2016-06-27 13:28:10 +00:00
echo "Yellow $command: No updates available\n";
2016-07-10 18:44:02 +00:00
}
return $statusCode;
}
2016-07-15 16:35:11 +00:00
2017-01-03 13:11:44 +00:00
// Download software
function downloadSoftware($data)
2016-07-19 16:28:52 +00:00
{
$statusCode = 0;
$path = $this->yellow->config->get("pluginDir");
2016-07-29 22:41:19 +00:00
$fileExtension = $this->yellow->config->get("downloadExtension");
2016-07-19 16:28:52 +00:00
foreach($data as $key=>$value)
{
$fileName = strtoloweru("$path$key.zip");
list($version, $url) = explode(',', $value);
list($statusCode, $fileData) = $this->getSoftwareFile($url);
2016-07-29 22:41:19 +00:00
if(empty($fileData) || !$this->yellow->toolbox->createFile($fileName.$fileExtension, $fileData))
2016-07-19 16:28:52 +00:00
{
$statusCode = 500;
2016-08-19 11:16:37 +00:00
$this->yellow->page->error($statusCode, "Can't write file '$fileName'!");
2016-07-19 16:28:52 +00:00
break;
}
}
2016-07-19 22:12:05 +00:00
if($statusCode==200)
2016-07-19 16:28:52 +00:00
{
foreach($data as $key=>$value)
{
$fileName = strtoloweru("$path$key.zip");
2016-07-29 22:41:19 +00:00
if(!$this->yellow->toolbox->renameFile($fileName.$fileExtension, $fileName))
2016-07-19 16:28:52 +00:00
{
$statusCode = 500;
2016-08-19 11:16:37 +00:00
$this->yellow->page->error($statusCode, "Can't write file '$fileName'!");
2016-07-19 16:28:52 +00:00
}
}
}
return $statusCode;
}
2016-07-10 18:44:02 +00:00
2017-01-03 13:11:44 +00:00
// Update software
function updateSoftware($option = "")
2016-07-10 18:44:02 +00:00
{
$statusCode = 0;
2017-01-03 13:11:44 +00:00
$path = $this->yellow->config->get("pluginDir");
foreach($this->yellow->toolbox->getDirectoryEntries($path, "/^.*\.zip$/", true, false) as $entry)
2016-07-10 18:44:02 +00:00
{
2017-01-03 13:11:44 +00:00
$statusCode = max($statusCode, $this->updateSoftwareArchive($entry, $option));
2016-07-10 18:44:02 +00:00
}
2017-01-03 13:11:44 +00:00
$path = $this->yellow->config->get("themeDir");
foreach($this->yellow->toolbox->getDirectoryEntries($path, "/^.*\.zip$/", true, false) as $entry)
2016-07-10 18:44:02 +00:00
{
2017-01-03 13:11:44 +00:00
$statusCode = max($statusCode, $this->updateSoftwareArchive($entry, $option));
2016-07-10 18:44:02 +00:00
}
return $statusCode;
}
2017-01-03 13:11:44 +00:00
2016-07-10 18:44:02 +00:00
// Update software from archive
2017-01-03 13:11:44 +00:00
function updateSoftwareArchive($path, $option = "")
2016-07-10 18:44:02 +00:00
{
$statusCode = 0;
$zip = new ZipArchive();
2016-07-19 22:12:05 +00:00
if($zip->open($path)===true)
2016-07-10 18:44:02 +00:00
{
2017-01-03 13:11:44 +00:00
if(defined("DEBUG") && DEBUG>=2) echo "YellowUpdate::updateSoftwareArchive file:$path<br/>\n";
if(strtoloweru($option)=="force") $force = true;
if(preg_match("#^(.*\/).*?$#", $zip->getNameIndex(0), $matches)) $pathBase = $matches[1];
$fileData = $zip->getFromName($pathBase.$this->yellow->config->get("updateInformationFile"));
foreach($this->yellow->toolbox->getTextLines($fileData) as $line)
2016-07-10 18:44:02 +00:00
{
2017-01-03 13:11:44 +00:00
preg_match("/^\s*(.*?)\s*:\s*(.*?)\s*$/", $line, $matches);
if(!empty($matches[1]) && !empty($matches[2]))
2016-07-10 18:44:02 +00:00
{
2017-02-02 08:54:57 +00:00
list($dummy, $entry) = explode('/', $matches[1], 2);
list($fileName, $flags) = explode(',', $matches[2], 2);
if($dummy[0]!='Y') $fileName = $matches[1]; //TODO: remove later, converts old file format
if(is_file($fileName)) { $lastPublished = filemtime($fileName); break; }
2016-07-10 18:44:02 +00:00
}
}
foreach($this->yellow->toolbox->getTextLines($fileData) as $line)
{
preg_match("/^\s*(.*?)\s*:\s*(.*?)\s*$/", $line, $matches);
if(lcfirst($matches[1])=="plugin" || lcfirst($matches[1])=="theme") $software = $matches[2];
2017-01-03 13:11:44 +00:00
if(lcfirst($matches[1])=="published") $modified = strtotime($matches[2]);
2017-02-02 08:54:57 +00:00
if(!empty($matches[1]) && !empty($matches[2]) && strposu($matches[1], '/'))
2016-07-10 18:44:02 +00:00
{
2017-02-02 08:54:57 +00:00
list($dummy, $entry) = explode('/', $matches[1], 2);
list($fileName, $flags) = explode(',', $matches[2], 2);
if($dummy[0]!='Y') //TODO: remove later, converts old file format
{
list($entry, $flags) = explode(',', $matches[2], 2);
$fileName = $matches[1];
}
2017-01-03 13:11:44 +00:00
$fileData = $zip->getFromName($pathBase.$entry);
$lastModified = $this->yellow->toolbox->getFileModified($fileName);
$statusCode = $this->updateSoftwareFile($fileName, $fileData, $modified, $lastModified, $lastPublished, $flags, $force, $software);
2016-07-19 22:12:05 +00:00
if($statusCode!=200) break;
2016-07-10 18:44:02 +00:00
}
}
$zip->close();
2017-02-02 08:54:57 +00:00
if($statusCode==200) $statusCode = $this->updateStartupNotification($software);
2016-07-10 18:44:02 +00:00
}
2017-01-03 13:11:44 +00:00
if(!$this->yellow->toolbox->deleteFile($path))
{
$statusCode = 500;
$this->yellow->page->error($statusCode, "Can't delete file '$path'!");
}
2016-07-10 18:44:02 +00:00
return $statusCode;
}
// Update software file
2017-01-03 13:11:44 +00:00
function updateSoftwareFile($fileName, $fileData, $modified, $lastModified, $lastPublished, $flags, $force, $software)
2016-07-10 18:44:02 +00:00
{
$statusCode = 200;
$fileName = $this->yellow->toolbox->normaliseTokens($fileName);
2017-02-02 08:54:57 +00:00
if($this->yellow->lookup->isValidFile($fileName) && !empty($software))
2016-07-10 18:44:02 +00:00
{
$create = $update = $delete = false;
2016-07-19 16:28:52 +00:00
if(preg_match("/create/i", $flags) && !is_file($fileName) && !empty($fileData)) $create = true;
if(preg_match("/update/i", $flags) && is_file($fileName) && !empty($fileData)) $update = true;
2016-07-15 16:35:11 +00:00
if(preg_match("/delete/i", $flags) && is_file($fileName)) $delete = true;
2017-01-03 13:11:44 +00:00
if(preg_match("/careful/i", $flags) && is_file($fileName) && $lastModified!=$lastPublished && !$force) $update = false;
if(preg_match("/optional/i", $flags) && $this->isSoftwareExisting($software)) $create = $update = $delete = false;
2016-07-15 16:35:11 +00:00
if($create)
2016-07-10 18:44:02 +00:00
{
2016-07-19 16:28:52 +00:00
if(!$this->yellow->toolbox->createFile($fileName, $fileData, true) ||
2016-07-10 18:44:02 +00:00
!$this->yellow->toolbox->modifyFile($fileName, $modified))
{
$statusCode = 500;
2016-08-19 11:16:37 +00:00
$this->yellow->page->error($statusCode, "Can't write file '$fileName'!");
2016-07-10 18:44:02 +00:00
}
}
2016-07-15 16:35:11 +00:00
if($update)
2016-07-10 18:44:02 +00:00
{
if(!$this->yellow->toolbox->deleteFile($fileName, $this->yellow->config->get("trashDir")) ||
2016-07-19 16:28:52 +00:00
!$this->yellow->toolbox->createFile($fileName, $fileData) ||
2016-07-10 18:44:02 +00:00
!$this->yellow->toolbox->modifyFile($fileName, $modified))
{
$statusCode = 500;
$this->yellow->page->error($statusCode, "Can't update file '$fileName'!");
}
}
2016-07-15 16:35:11 +00:00
if($delete)
2016-07-10 18:44:02 +00:00
{
if(!$this->yellow->toolbox->deleteFile($fileName, $this->yellow->config->get("trashDir")))
{
$statusCode = 500;
$this->yellow->page->error($statusCode, "Can't delete file '$fileName'!");
}
}
2017-01-03 13:11:44 +00:00
if(defined("DEBUG") && DEBUG>=2)
{
$debug = "action:".($create ? "create" : "").($update ? "update" : "").($delete ? "delete" : "");
if(!$create && !$update && !$delete) $debug = "action:none";
echo "YellowUpdate::updateSoftwareFile file:$fileName $debug<br/>\n";
}
2016-06-27 13:28:10 +00:00
}
return $statusCode;
}
2017-02-02 08:54:57 +00:00
// Update startup notification
function updateStartupNotification($software)
{
$statusCode = 200;
$updateNotification = $this->yellow->config->get("updateNotification");
if($updateNotification=="none") $updateNotification = "";
if(!empty($updateNotification)) $updateNotification .= ",";
$updateNotification .= $software;
$fileNameConfig = $this->yellow->config->get("configDir").$this->yellow->config->get("configFile");
if(!$this->yellow->config->update($fileNameConfig, array("updateNotification" => $updateNotification)))
{
$statusCode = 500;
$this->yellow->page->error(500, "Can't write file '$fileNameConfig'!");
}
return $statusCode;
}
2017-01-03 13:11:44 +00:00
// Update software features
function updateSoftwareFeatures($feature)
2016-07-29 22:41:19 +00:00
{
2017-01-03 13:11:44 +00:00
$statusCode = 200;
2016-07-29 22:41:19 +00:00
$path = $this->yellow->config->get("pluginDir");
2017-01-03 13:11:44 +00:00
$regex = "/^.*\\".$this->yellow->config->get("installationExtension")."$/";
2016-07-29 22:41:19 +00:00
foreach($this->yellow->toolbox->getDirectoryEntries($path, $regex, true, false) as $entry)
{
2016-08-07 10:51:23 +00:00
if(stristr(basename($entry), $feature))
2016-07-29 22:41:19 +00:00
{
2017-01-03 13:11:44 +00:00
$statusCode = max($statusCode, $this->updateSoftwareArchive($entry));
2016-07-30 00:58:14 +00:00
}
}
2017-01-03 13:11:44 +00:00
if($statusCode==200)
2016-07-30 00:58:14 +00:00
{
foreach($this->yellow->toolbox->getDirectoryEntries($path, $regex, true, false) as $entry)
{
$this->yellow->toolbox->deleteFile($entry);
2016-07-29 22:41:19 +00:00
}
}
2017-01-03 13:11:44 +00:00
return $statusCode;
}
// Process update notification for recently installed software
function processUpdateNotification()
{
if($this->yellow->config->get("updateNotification")!="none")
{
$tokens = explode(',', $this->yellow->config->get("updateNotification"));
foreach($this->yellow->plugins->plugins as $key=>$value)
{
if(in_array($value["plugin"], $tokens) && method_exists($value["obj"], "onUpdate")) $value["obj"]->onUpdate($key);
}
$fileNameConfig = $this->yellow->config->get("configDir").$this->yellow->config->get("configFile");
$this->yellow->config->update($fileNameConfig, array("updateNotification" => "none"));
}
}
// Process command to install pending software
function processCommandInstallationPending($args)
{
$statusCode = 0;
if($this->isSoftwarePending())
{
$statusCode = $this->updateSoftware();
if($statusCode!=0)
{
if($statusCode!=200) echo "ERROR updating files: ".$this->yellow->page->get("pageError")."\n";
echo "Yellow has ".($statusCode!=200 ? "not " : "")."been updated: Please run command again\n";
}
}
return $statusCode;
2016-07-29 22:41:19 +00:00
}
2016-08-18 19:57:07 +00:00
// Process request to install pending software
2017-01-03 13:11:44 +00:00
function processRequestInstallationPending($serverScheme, $serverName, $base, $location, $fileName)
2016-06-27 13:28:10 +00:00
{
2016-07-10 18:44:02 +00:00
$statusCode = 0;
2017-01-03 13:11:44 +00:00
if($this->yellow->lookup->isContentFile($fileName) && $this->isSoftwarePending())
2016-07-10 18:44:02 +00:00
{
2017-01-03 13:11:44 +00:00
$statusCode = $this->updateSoftware();
2016-07-19 22:12:05 +00:00
if($statusCode==200)
2016-07-10 18:44:02 +00:00
{
$statusCode = 303;
$location = $this->yellow->lookup->normaliseUrl($serverScheme, $serverName, $base, $location);
$this->yellow->sendStatus($statusCode, $location);
}
}
return $statusCode;
2016-06-27 13:28:10 +00:00
}
// Process request to install website
2017-01-03 13:11:44 +00:00
function processRequestInstallationMode($serverScheme, $serverName, $base, $location, $fileName)
2016-06-27 13:28:10 +00:00
{
$statusCode = 0;
2017-01-03 13:11:44 +00:00
if($this->yellow->lookup->isContentFile($fileName) && $this->isInstallationMode())
2016-06-27 13:28:10 +00:00
{
$this->yellow->pages->pages["root/"] = array();
$this->yellow->page = new YellowPage($this->yellow);
$this->yellow->page->setRequestInformation($serverScheme, $serverName, $base, $location, $fileName);
2017-01-03 13:11:44 +00:00
$this->yellow->page->parseData($this->getRawDataInstallation(), false, 404);
2016-06-27 13:28:10 +00:00
$this->yellow->page->parserSafeMode = false;
$this->yellow->page->parseContent();
$name = trim(preg_replace("/[^\pL\d\-\. ]/u", "-", $_REQUEST["name"]));
$email = trim($_REQUEST["email"]);
$password = trim($_REQUEST["password"]);
$language = trim($_REQUEST["language"]);
2016-07-29 22:41:19 +00:00
$feature = trim($_REQUEST["feature"]);
2016-06-27 13:28:10 +00:00
$status = trim($_REQUEST["status"]);
2016-07-19 22:12:05 +00:00
if($status=="install")
2016-06-27 13:28:10 +00:00
{
$status = "ok";
$fileNameHome = $this->yellow->lookup->findFileFromLocation("/");
$fileData = strreplaceu("\r\n", "\n", $this->yellow->toolbox->readFile($fileNameHome));
if($fileData==$this->getRawDataHome("en") && $language!="en")
{
$status = $this->yellow->toolbox->createFile($fileNameHome, $this->getRawDataHome($language)) ? "ok" : "error";
2016-07-19 22:12:05 +00:00
if($status=="error") $this->yellow->page->error(500, "Can't write file '$fileNameHome'!");
2016-06-27 13:28:10 +00:00
}
}
2016-07-19 22:12:05 +00:00
if($status=="ok")
2016-06-27 13:28:10 +00:00
{
if(!empty($email) && !empty($password) && $this->yellow->plugins->isExisting("webinterface"))
{
$fileNameUser = $this->yellow->config->get("configDir").$this->yellow->config->get("webinterfaceUserFile");
$status = $this->yellow->plugins->get("webinterface")->users->update($fileNameUser, $email, $password, $name, $language) ? "ok" : "error";
2016-07-19 22:12:05 +00:00
if($status=="error") $this->yellow->page->error(500, "Can't write file '$fileNameUser'!");
2016-06-27 13:28:10 +00:00
}
}
2016-07-19 22:12:05 +00:00
if($status=="ok")
2016-07-29 22:41:19 +00:00
{
if(!empty($feature))
{
2017-01-03 13:11:44 +00:00
$status = $this->updateSoftwareFeatures($feature)==200 ? "ok" : "error";
2016-07-29 22:41:19 +00:00
if($status=="error") $this->yellow->page->error(500, "Can't install feature '$feature'!");
}
}
if($status=="ok")
2016-06-27 13:28:10 +00:00
{
2016-07-19 22:12:05 +00:00
if($this->yellow->config->get("sitename")=="Yellow") $_REQUEST["sitename"] = $name;
2016-06-27 13:28:10 +00:00
$fileNameConfig = $this->yellow->config->get("configDir").$this->yellow->config->get("configFile");
$status = $this->yellow->config->update($fileNameConfig, $this->getConfigData()) ? "done" : "error";
2016-07-19 22:12:05 +00:00
if($status=="error") $this->yellow->page->error(500, "Can't write file '$fileNameConfig'!");
2016-06-27 13:28:10 +00:00
}
2016-07-19 22:12:05 +00:00
if($status=="done")
2016-06-27 13:28:10 +00:00
{
$statusCode = 303;
$location = $this->yellow->lookup->normaliseUrl($serverScheme, $serverName, $base, $location);
$this->yellow->sendStatus($statusCode, $location);
} else {
$statusCode = $this->yellow->sendPage();
}
}
return $statusCode;
}
// Return raw data for installation page
2017-01-03 13:11:44 +00:00
function getRawDataInstallation()
2016-06-27 13:28:10 +00:00
{
2017-01-03 13:11:44 +00:00
$language = $this->yellow->toolbox->detectBrowserLanguage($this->yellow->text->getLanguages(), $this->yellow->config->get("language"));
2016-08-13 15:48:18 +00:00
$fileName = strreplaceu("(.*)", "installation", $this->yellow->config->get("configDir").$this->yellow->config->get("webinterfaceNewFile"));
2016-06-27 13:28:10 +00:00
$rawData = $this->yellow->toolbox->readFile($fileName);
if(empty($rawData))
{
$this->yellow->text->setLanguage($language);
$rawData = "---\nTitle:".$this->yellow->text->get("webinterfaceInstallationTitle")."\nLanguage:$language\nNavigation:navigation\n---\n";
2016-06-27 21:26:26 +00:00
$rawData .= "<form class=\"installation-form\" action=\"".$this->yellow->page->getLocation(true)."\" method=\"post\">\n";
2016-06-27 13:28:10 +00:00
$rawData .= "<p><label for=\"name\">".$this->yellow->text->get("webinterfaceSignupName")."</label><br /><input class=\"form-control\" type=\"text\" maxlength=\"64\" name=\"name\" id=\"name\" value=\"\"></p>\n";
$rawData .= "<p><label for=\"email\">".$this->yellow->text->get("webinterfaceSignupEmail")."</label><br /><input class=\"form-control\" type=\"text\" maxlength=\"64\" name=\"email\" id=\"email\" value=\"\"></p>\n";
$rawData .= "<p><label for=\"password\">".$this->yellow->text->get("webinterfaceSignupPassword")."</label><br /><input class=\"form-control\" type=\"password\" maxlength=\"64\" name=\"password\" id=\"password\" value=\"\"></p>\n";
2016-07-19 22:12:05 +00:00
if(count($this->yellow->text->getLanguages())>1)
2016-06-27 13:28:10 +00:00
{
$rawData .= "<p>";
foreach($this->yellow->text->getLanguages() as $language)
{
$checked = $language==$this->yellow->text->language ? " checked=\"checked\"" : "";
$rawData .= "<label for=\"$language\"><input type=\"radio\" name=\"language\" id=\"$language\" value=\"$language\"$checked> ".$this->yellow->text->getTextHtml("languageDescription", $language)."</label><br />";
}
$rawData .= "</p>\n";
}
2017-01-03 13:11:44 +00:00
if(count($this->getSoftwareFeatures())>1)
2016-07-29 22:41:19 +00:00
{
$rawData .= "<p>".$this->yellow->text->get("webinterfaceInstallationFeature")."<p>";
2017-01-03 13:11:44 +00:00
foreach($this->getSoftwareFeatures() as $feature)
2016-07-29 22:41:19 +00:00
{
$checked = $feature=="website" ? " checked=\"checked\"" : "";
$rawData .= "<label for=\"$feature\"><input type=\"radio\" name=\"feature\" id=\"$feature\" value=\"$feature\"$checked> ".ucfirst($feature)."</label><br />";
}
$rawData .= "</p>\n";
}
2016-06-27 13:28:10 +00:00
$rawData .= "<input class=\"btn\" type=\"submit\" value=\"".$this->yellow->text->get("webinterfaceOkButton")."\" />\n";
$rawData .= "<input type=\"hidden\" name=\"status\" value=\"install\" />\n";
$rawData .= "</form>\n";
}
return $rawData;
}
// Return raw data for home page
function getRawDataHome($language)
{
$rawData = "---\nTitle: Home\n---\n".strreplaceu("\\n", "\n", $this->yellow->text->getText("webinterfaceInstallationHomePage", $language));
return $rawData;
}
2017-01-03 13:11:44 +00:00
// Return configuration data
2016-06-27 13:28:10 +00:00
function getConfigData()
{
$data = array();
foreach($_REQUEST as $key=>$value)
{
if(!$this->yellow->config->isExisting($key)) continue;
$data[$key] = trim($value);
}
$data["# serverScheme"] = $this->yellow->toolbox->getServerScheme();
$data["# serverName"] = $this->yellow->toolbox->getServerName();
$data["# serverBase"] = $this->yellow->toolbox->getServerBase();
$data["# serverTime"] = $this->yellow->toolbox->getServerTime();
$data["installationMode"] = "0";
return $data;
}
2016-07-19 16:28:52 +00:00
2017-01-03 13:11:44 +00:00
// Return software features
function getSoftwareFeatures()
2016-07-29 22:41:19 +00:00
{
$data = array("website");
$path = $this->yellow->config->get("pluginDir");
2017-01-03 13:11:44 +00:00
$regex = "/^.*\\".$this->yellow->config->get("installationExtension")."$/";
2016-07-29 22:41:19 +00:00
foreach($this->yellow->toolbox->getDirectoryEntries($path, $regex, true, false, false) as $entry)
{
2016-07-30 00:58:14 +00:00
if(preg_match("/^(.*?)-(.*?)\./", $entry, $matches))
2016-07-29 22:41:19 +00:00
{
2016-07-30 00:58:14 +00:00
array_push($data, $matches[2]);
2016-07-29 22:41:19 +00:00
}
}
return $data;
}
2017-01-03 13:11:44 +00:00
// Return software updates
function getSoftwareUpdates($feature)
2016-07-19 16:28:52 +00:00
{
$data = array();
list($statusCode, $dataCurrent) = $this->getSoftwareVersion();
list($statusCode, $dataLatest) = $this->getSoftwareVersion(true, true);
foreach($dataCurrent as $key=>$value)
{
2016-07-20 09:44:17 +00:00
list($version) = explode(',', $dataLatest[$key]);
2016-07-19 16:28:52 +00:00
if(empty($feature))
{
2016-07-19 22:12:05 +00:00
if(strnatcasecmp($dataCurrent[$key], $version)<0) $data[$key] = $dataLatest[$key];
2016-07-19 16:28:52 +00:00
} else {
2016-08-07 10:51:23 +00:00
if(stristr($key, $feature) && $version) $data[$key] = $dataLatest[$key];
2016-07-19 16:28:52 +00:00
}
}
return array($statusCode, $data);
}
2016-06-27 13:28:10 +00:00
// Return software version
2016-07-19 16:28:52 +00:00
function getSoftwareVersion($latest = false, $rawFormat = false)
2016-06-27 13:28:10 +00:00
{
$data = array();
if($latest)
{
2016-07-19 16:28:52 +00:00
$urlPlugins = $this->yellow->config->get("updatePluginsUrl")."/raw/master/".$this->yellow->config->get("updateVersionFile");
$urlThemes = $this->yellow->config->get("updateThemesUrl")."/raw/master/".$this->yellow->config->get("updateVersionFile");
2017-02-02 08:54:57 +00:00
list($statusCodePlugins, $fileDataPlugins) = $this->getSoftwareFile($urlPlugins);
list($statusCodeThemes, $fileDataThemes) = $this->getSoftwareFile($urlThemes);
2016-06-27 13:28:10 +00:00
$statusCode = max($statusCodePlugins, $statusCodeThemes);
2016-07-19 22:12:05 +00:00
if($statusCode==200)
2016-07-19 16:28:52 +00:00
{
foreach($this->yellow->toolbox->getTextLines($fileDataPlugins."\n".$fileDataThemes) as $line)
{
preg_match("/^\s*(.*?)\s*:\s*(.*?)\s*$/", $line, $matches);
if(!empty($matches[1]) && !empty($matches[2]))
{
2016-07-20 09:44:17 +00:00
list($version) = explode(',', $matches[2]);
2016-07-19 16:28:52 +00:00
$data[$matches[1]] = $rawFormat ? $matches[2] : $version;
}
}
}
2016-06-27 13:28:10 +00:00
} else {
$statusCode = 200;
2017-01-03 13:11:44 +00:00
$data = array_merge($this->yellow->plugins->getData(), $this->yellow->themes->getData());
2016-06-27 13:28:10 +00:00
}
return array($statusCode, $data);
}
2016-07-19 16:28:52 +00:00
// Return software file
function getSoftwareFile($url)
2016-06-27 13:28:10 +00:00
{
2016-07-19 16:28:52 +00:00
$fileData = "";
2016-06-27 13:28:10 +00:00
if(extension_loaded("curl"))
{
2016-07-19 16:28:52 +00:00
$urlRequest = $url;
if(preg_match("#^https://github.com/(.+)/raw/(.+)$#", $url, $matches))
{
$urlRequest = "https://raw.githubusercontent.com/".$matches[1]."/".$matches[2];
}
2016-06-27 13:28:10 +00:00
$curlHandle = curl_init();
2016-07-19 16:28:52 +00:00
curl_setopt($curlHandle, CURLOPT_URL, $urlRequest);
2016-07-19 22:12:05 +00:00
curl_setopt($curlHandle, CURLOPT_USERAGENT, "Mozilla/5.0 (compatible; YellowCore/".YellowCore::VERSION).")";
2016-06-27 13:28:10 +00:00
curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curlHandle, CURLOPT_CONNECTTIMEOUT, 30);
$rawData = curl_exec($curlHandle);
$statusCode = curl_getinfo($curlHandle, CURLINFO_HTTP_CODE);
curl_close($curlHandle);
2016-07-19 22:12:05 +00:00
if($statusCode==200)
2016-06-27 13:28:10 +00:00
{
2016-07-19 16:28:52 +00:00
$fileData = $rawData;
2016-07-19 22:12:05 +00:00
} else if($statusCode==0) {
2017-01-03 13:11:44 +00:00
$statusCode = 500;
$this->yellow->page->error($statusCode, "Can't connect to server!");
2016-07-19 16:28:52 +00:00
} else {
2017-01-03 13:11:44 +00:00
$statusCode = 500;
2016-07-19 16:28:52 +00:00
$this->yellow->page->error($statusCode, "Can't download file '$url'!");
2016-06-27 13:28:10 +00:00
}
2017-02-02 08:54:57 +00:00
if(defined("DEBUG") && DEBUG>=2) echo "YellowUpdate::getSoftwareFile status:$statusCode url:$url<br/>\n";
2016-06-27 13:28:10 +00:00
} else {
$statusCode = 500;
2016-07-19 16:28:52 +00:00
$this->yellow->page->error($statusCode, "Plugin 'update' requires cURL library!");
2016-06-27 13:28:10 +00:00
}
2016-07-19 16:28:52 +00:00
return array($statusCode, $fileData);
2016-06-27 13:28:10 +00:00
}
2017-02-02 08:54:57 +00:00
// Check if software pending
2016-08-22 09:54:13 +00:00
function isSoftwarePending()
{
$path = $this->yellow->config->get("pluginDir");
$foundPlugins = count($this->yellow->toolbox->getDirectoryEntries($path, "/^.*\.zip$/", true, false))>0;
$path = $this->yellow->config->get("themeDir");
$foundThemes = count($this->yellow->toolbox->getDirectoryEntries($path, "/^.*\.zip$/", true, false))>0;
return $foundPlugins || $foundThemes;
}
2017-01-03 13:11:44 +00:00
// Check if software exists
function isSoftwareExisting($software)
2016-06-27 13:28:10 +00:00
{
2017-01-03 13:11:44 +00:00
$data = array_merge($this->yellow->plugins->getData(), $this->yellow->themes->getData());
return !is_null($data[$software]);
2016-07-10 18:44:02 +00:00
}
2017-01-03 13:11:44 +00:00
// Check if installation mode
function isInstallationMode()
2016-07-10 18:44:02 +00:00
{
2017-01-03 13:11:44 +00:00
return $this->yellow->config->get("installationMode") && PHP_SAPI!="cli";
2016-06-27 13:28:10 +00:00
}
}
2016-07-19 22:12:05 +00:00
$yellow->plugins->register("update", "YellowUpdate", YellowUpdate::VERSION, 1);
2016-06-27 13:28:10 +00:00
?>