2013-04-14 22:41:04 +00:00
|
|
|
<?php
|
2016-02-20 17:34:06 +00:00
|
|
|
// Copyright (c) 2013-2016 Datenstrom, http://datenstrom.se
|
2013-04-14 22:41:04 +00:00
|
|
|
// This file may be used and distributed under the terms of the public license.
|
|
|
|
|
2015-10-06 12:19:11 +00:00
|
|
|
// Web interface plugin
|
2013-12-01 11:59:07 +00:00
|
|
|
class YellowWebinterface
|
2013-04-14 22:41:04 +00:00
|
|
|
{
|
2016-06-02 15:31:42 +00:00
|
|
|
const Version = "0.6.8";
|
2013-07-11 20:33:28 +00:00
|
|
|
var $yellow; //access to API
|
2014-05-15 11:53:54 +00:00
|
|
|
var $active; //web interface is active? (boolean)
|
2016-05-15 16:35:10 +00:00
|
|
|
var $userEmail; //web interface user
|
|
|
|
var $userLanguage; //web interface user language
|
2016-04-12 13:58:56 +00:00
|
|
|
var $userRestrictions; //web interface user can change page? (boolean)
|
2016-05-15 16:35:10 +00:00
|
|
|
var $action; //web interface action
|
|
|
|
var $status; //web interface status
|
2016-06-02 15:31:42 +00:00
|
|
|
var $installation; //web interface installation
|
2014-11-13 13:49:21 +00:00
|
|
|
var $users; //web interface users
|
|
|
|
var $merge; //web interface merge
|
2014-07-25 10:46:58 +00:00
|
|
|
var $rawDataSource; //raw data of page for comparison
|
|
|
|
var $rawDataEdit; //raw data of page for editing
|
2013-04-14 22:41:04 +00:00
|
|
|
|
2015-04-29 07:26:48 +00:00
|
|
|
// Handle initialisation
|
2013-12-01 11:59:07 +00:00
|
|
|
function onLoad($yellow)
|
2013-04-14 22:41:04 +00:00
|
|
|
{
|
|
|
|
$this->yellow = $yellow;
|
2016-06-02 15:31:42 +00:00
|
|
|
$this->installation = new YellowInstallation($yellow);
|
2015-10-06 12:19:11 +00:00
|
|
|
$this->users = new YellowUsers($yellow);
|
|
|
|
$this->merge = new YellowMerge($yellow);
|
2015-12-13 09:02:43 +00:00
|
|
|
$this->yellow->config->setDefault("webinterfaceServerScheme", $this->yellow->config->get("serverScheme"));
|
2014-05-15 11:53:54 +00:00
|
|
|
$this->yellow->config->setDefault("webinterfaceServerName", $this->yellow->config->get("serverName"));
|
2016-02-20 17:34:06 +00:00
|
|
|
$this->yellow->config->setDefault("webinterfaceLocation", "/edit/");
|
2016-04-12 13:58:56 +00:00
|
|
|
$this->yellow->config->setDefault("webinterfaceUserPasswordMinLength", "4");
|
2014-06-13 22:14:09 +00:00
|
|
|
$this->yellow->config->setDefault("webinterfaceUserHashAlgorithm", "bcrypt");
|
|
|
|
$this->yellow->config->setDefault("webinterfaceUserHashCost", "10");
|
2016-04-12 13:58:56 +00:00
|
|
|
$this->yellow->config->setDefault("webinterfaceUserStatus", "active");
|
2015-09-06 15:59:14 +00:00
|
|
|
$this->yellow->config->setDefault("webinterfaceUserHome", "/");
|
2014-06-13 22:14:09 +00:00
|
|
|
$this->yellow->config->setDefault("webinterfaceUserFile", "user.ini");
|
2015-04-29 07:26:48 +00:00
|
|
|
$this->yellow->config->setDefault("webinterfaceNewFile", "page-new-(.*).txt");
|
|
|
|
$this->yellow->config->setDefault("webinterfaceMetaFilePrefix", "published");
|
2013-04-14 22:41:04 +00:00
|
|
|
$this->users->load($this->yellow->config->get("configDir").$this->yellow->config->get("webinterfaceUserFile"));
|
|
|
|
}
|
|
|
|
|
2014-05-29 21:33:01 +00:00
|
|
|
// Handle request
|
2014-05-15 11:53:54 +00:00
|
|
|
function onRequest($serverScheme, $serverName, $base, $location, $fileName)
|
2013-04-14 22:41:04 +00:00
|
|
|
{
|
|
|
|
$statusCode = 0;
|
2016-06-02 15:31:42 +00:00
|
|
|
if($this->yellow->config->get("installationMode"))
|
2013-04-14 22:41:04 +00:00
|
|
|
{
|
2016-06-02 15:31:42 +00:00
|
|
|
$statusCode = $this->installation->processRequest($serverScheme, $serverName, $base, $location, $fileName);
|
|
|
|
} else if($this->checkRequest($location)) {
|
2014-07-25 10:46:58 +00:00
|
|
|
$statusCode = $this->processRequest($serverScheme, $serverName, $base, $location, $fileName);
|
2013-04-14 22:41:04 +00:00
|
|
|
}
|
|
|
|
return $statusCode;
|
|
|
|
}
|
|
|
|
|
2014-01-27 11:30:39 +00:00
|
|
|
// Handle page meta data parsing
|
2015-04-29 07:26:48 +00:00
|
|
|
function onParseMeta($page)
|
2014-01-27 11:30:39 +00:00
|
|
|
{
|
2016-04-12 13:58:56 +00:00
|
|
|
if($this->isActive() && $page==$this->yellow->page)
|
2014-01-27 11:30:39 +00:00
|
|
|
{
|
2016-04-12 13:58:56 +00:00
|
|
|
if($this->isUser())
|
2014-01-27 11:30:39 +00:00
|
|
|
{
|
2014-07-25 10:46:58 +00:00
|
|
|
if(empty($this->rawDataSource)) $this->rawDataSource = $page->rawData;
|
|
|
|
if(empty($this->rawDataEdit)) $this->rawDataEdit = $page->rawData;
|
2016-05-15 16:35:10 +00:00
|
|
|
if($page->statusCode == 424) $this->rawDataEdit = $this->getRawDataNew($page->location);
|
2014-01-27 11:30:39 +00:00
|
|
|
}
|
2016-05-15 16:35:10 +00:00
|
|
|
if(empty($this->userLanguage)) $this->userLanguage = $page->get("language");
|
|
|
|
if(empty($this->action)) $this->action = $this->isUser() ? "none" : "login";
|
|
|
|
if(empty($this->status)) $this->status = "none";
|
|
|
|
if($this->status == "error") $this->action = "error";
|
2014-01-27 11:30:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-26 08:27:28 +00:00
|
|
|
// Handle page content parsing of custom block
|
2015-06-10 15:13:17 +00:00
|
|
|
function onParseContentBlock($page, $name, $text, $shortcut)
|
2015-05-26 08:27:28 +00:00
|
|
|
{
|
|
|
|
$output = NULL;
|
2015-06-10 15:13:17 +00:00
|
|
|
if($name=="edit" && $shortcut)
|
2015-05-26 08:27:28 +00:00
|
|
|
{
|
|
|
|
$editText = "$name $text";
|
|
|
|
if(substru($text, 0, 2)=="- ") $editText = trim(substru($text, 2));
|
|
|
|
$output = "<a href=\"".$page->get("pageEdit")."\">".htmlspecialchars($editText)."</a>";
|
|
|
|
}
|
|
|
|
return $output;
|
|
|
|
}
|
|
|
|
|
2015-04-29 07:26:48 +00:00
|
|
|
// Handle page extra HTML data
|
2015-05-04 11:11:33 +00:00
|
|
|
function onExtra($name)
|
2013-04-14 22:41:04 +00:00
|
|
|
{
|
2015-05-21 13:19:56 +00:00
|
|
|
$output = NULL;
|
2015-05-04 11:11:33 +00:00
|
|
|
if($this->isActive() && $name=="header")
|
2013-04-14 22:41:04 +00:00
|
|
|
{
|
2016-04-12 13:58:56 +00:00
|
|
|
$location = $this->yellow->config->get("serverBase").$this->yellow->config->get("pluginLocation")."webinterface";
|
|
|
|
$output = "<link rel=\"stylesheet\" type=\"text/css\" media=\"all\" href=\"".htmlspecialchars($location).".css\" />\n";
|
|
|
|
$output .= "<script type=\"text/javascript\" src=\"".htmlspecialchars($location).".js\"></script>\n";
|
|
|
|
$output .= "<script type=\"text/javascript\">\n";
|
|
|
|
$output .= "// <![CDATA[\n";
|
|
|
|
$output .= "yellow.page = ".json_encode($this->getPageData()).";\n";
|
|
|
|
$output .= "yellow.config = ".json_encode($this->getConfigData()).";\n";
|
|
|
|
$output .= "yellow.text = ".json_encode($this->getTextData()).";\n";
|
|
|
|
$output .= "// ]]>\n";
|
|
|
|
$output .= "</script>\n";
|
2013-04-14 22:41:04 +00:00
|
|
|
}
|
2015-04-29 07:26:48 +00:00
|
|
|
return $output;
|
2013-12-21 13:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Handle command
|
|
|
|
function onCommand($args)
|
|
|
|
{
|
|
|
|
list($name, $command) = $args;
|
|
|
|
switch($command)
|
|
|
|
{
|
2016-06-02 15:31:42 +00:00
|
|
|
case "clean": $statusCode = $this->cleanCommand($args); break;
|
2013-12-21 13:10:15 +00:00
|
|
|
case "user": $statusCode = $this->userCommand($args); break;
|
|
|
|
default: $statusCode = 0;
|
|
|
|
}
|
|
|
|
return $statusCode;
|
|
|
|
}
|
|
|
|
|
2015-04-29 07:26:48 +00:00
|
|
|
// Handle command help
|
|
|
|
function onCommandHelp()
|
|
|
|
{
|
2015-10-06 12:19:11 +00:00
|
|
|
return "user [EMAIL PASSWORD NAME LANGUAGE STATUS HOME]\n";
|
2015-04-29 07:26:48 +00:00
|
|
|
}
|
2016-06-02 15:31:42 +00:00
|
|
|
|
|
|
|
// Clean user accounts
|
|
|
|
function cleanCommand($args)
|
|
|
|
{
|
|
|
|
$fileNameUser = $this->yellow->config->get("configDir").$this->yellow->config->get("webinterfaceUserFile");
|
|
|
|
$statusCode = $this->users->clean($fileNameUser) ? 200 : 500;
|
|
|
|
if($statusCode == 500) echo "ERROR cleaning configuration: Can't write file '$fileNameUser'!\n";
|
|
|
|
return status;
|
|
|
|
}
|
2015-04-29 07:26:48 +00:00
|
|
|
|
2015-08-09 20:17:17 +00:00
|
|
|
// Update user account
|
2013-12-21 13:10:15 +00:00
|
|
|
function userCommand($args)
|
|
|
|
{
|
|
|
|
$statusCode = 0;
|
2015-10-06 12:19:11 +00:00
|
|
|
list($dummy, $command, $email, $password, $name, $language, $status, $home) = $args;
|
|
|
|
if(!empty($email) && !empty($password))
|
|
|
|
{
|
2016-04-12 13:58:56 +00:00
|
|
|
$userExisting = $this->users->isExisting($email);
|
|
|
|
$status = $this->getUserAccount($email, $password, $command);
|
|
|
|
switch($status)
|
2014-05-04 12:57:52 +00:00
|
|
|
{
|
2016-04-12 13:58:56 +00:00
|
|
|
case "invalid": echo "ERROR updating configuration: Please enter a valid email!\n"; break;
|
|
|
|
case "weak": echo "ERROR updating configuration: Please enter a different password!\n"; break;
|
2014-05-04 12:57:52 +00:00
|
|
|
}
|
2016-04-12 13:58:56 +00:00
|
|
|
if($status == "ok")
|
|
|
|
{
|
|
|
|
$fileNameUser = $this->yellow->config->get("configDir").$this->yellow->config->get("webinterfaceUserFile");
|
|
|
|
$status = $this->users->update($fileNameUser, $email, $password, $name, $language, $status, $home) ? "ok" : "error";
|
|
|
|
if($status == "error") echo "ERROR updating configuration: Can't write file '$fileNameUser'!\n";
|
|
|
|
}
|
|
|
|
if($status == "ok")
|
|
|
|
{
|
|
|
|
$algorithm = $this->yellow->config->get("webinterfaceUserHashAlgorithm");
|
|
|
|
$status = substru($this->users->getHash($email), 0, 5)!="error-hash" ? "ok" : "error";
|
|
|
|
if($status == "error") echo "ERROR updating configuration: Hash algorithm '$algorithm' not supported!\n";
|
|
|
|
}
|
|
|
|
$statusCode = $status=="ok" ? 200 : 500;
|
2015-10-06 12:19:11 +00:00
|
|
|
echo "Yellow $command: User account ".($statusCode!=200 ? "not " : "");
|
2016-04-12 13:58:56 +00:00
|
|
|
echo ($userExisting ? "updated" : "created")."\n";
|
2013-12-21 13:10:15 +00:00
|
|
|
} else {
|
2015-10-06 12:19:11 +00:00
|
|
|
$statusCode = 200;
|
|
|
|
foreach($this->getUserData() as $line) echo "$line\n";
|
|
|
|
if(!$this->users->getNumber()) echo "Yellow $command: No user accounts\n";
|
2013-12-21 13:10:15 +00:00
|
|
|
}
|
|
|
|
return $statusCode;
|
|
|
|
}
|
|
|
|
|
2014-07-25 10:46:58 +00:00
|
|
|
// Process request
|
|
|
|
function processRequest($serverScheme, $serverName, $base, $location, $fileName)
|
|
|
|
{
|
|
|
|
$statusCode = 0;
|
2016-06-02 15:31:42 +00:00
|
|
|
list($serverScheme, $serverName, $base, $location, $fileName) = $this->updateRequestInformation();
|
|
|
|
if($this->checkUser($location, $fileName))
|
2014-07-25 10:46:58 +00:00
|
|
|
{
|
2016-04-12 13:58:56 +00:00
|
|
|
switch($_REQUEST["action"])
|
|
|
|
{
|
|
|
|
case "": $statusCode = $this->processRequestShow($serverScheme, $serverName, $base, $location, $fileName); break;
|
|
|
|
case "login": $statusCode = $this->processRequestLogin($serverScheme, $serverName, $base, $location, $fileName); break;
|
|
|
|
case "logout": $statusCode = $this->processRequestLogout($serverScheme, $serverName, $base, $location, $fileName); break;
|
|
|
|
case "signup": $statusCode = $this->processRequestSignup($serverScheme, $serverName, $base, $location, $fileName); break;
|
|
|
|
case "confirm": $statusCode = $this->processRequestConfirm($serverScheme, $serverName, $base, $location, $fileName); break;
|
|
|
|
case "approve": $statusCode = $this->processRequestApprove($serverScheme, $serverName, $base, $location, $fileName); break;
|
|
|
|
case "recover": $statusCode = $this->processRequestRecover($serverScheme, $serverName, $base, $location, $fileName); break;
|
2016-05-15 16:35:10 +00:00
|
|
|
case "settings": $statusCode = $this->processRequestSettings($serverScheme, $serverName, $base, $location, $fileName); break;
|
2016-04-12 13:58:56 +00:00
|
|
|
case "create": $statusCode = $this->processRequestCreate($serverScheme, $serverName, $base, $location, $fileName); break;
|
|
|
|
case "edit": $statusCode = $this->processRequestEdit($serverScheme, $serverName, $base, $location, $fileName); break;
|
|
|
|
case "delete": $statusCode = $this->processRequestDelete($serverScheme, $serverName, $base, $location, $fileName); break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
switch($_REQUEST["action"])
|
2014-07-25 10:46:58 +00:00
|
|
|
{
|
2016-04-12 13:58:56 +00:00
|
|
|
case "signup": $statusCode = $this->processRequestSignup($serverScheme, $serverName, $base, $location, $fileName); break;
|
|
|
|
case "confirm": $statusCode = $this->processRequestConfirm($serverScheme, $serverName, $base, $location, $fileName); break;
|
|
|
|
case "approve": $statusCode = $this->processRequestApprove($serverScheme, $serverName, $base, $location, $fileName); break;
|
|
|
|
case "recover": $statusCode = $this->processRequestRecover($serverScheme, $serverName, $base, $location, $fileName); break;
|
2014-07-25 10:46:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if($statusCode == 0)
|
|
|
|
{
|
2015-01-19 19:05:51 +00:00
|
|
|
$statusCode = $this->yellow->processRequest($serverScheme, $serverName, $base, $location, $fileName, false);
|
2016-05-15 16:35:10 +00:00
|
|
|
$fileNameConfig = $this->yellow->config->get("configDir").$this->yellow->config->get("configFile");
|
|
|
|
if($this->action == "off") $this->yellow->page->error(500, "Please configure webmaster email in file '$fileNameConfig'!");
|
|
|
|
if($this->action == "fail") $this->yellow->page->error(500, "Login failed, [please log in](javascript:yellow.action('login');)!");
|
2014-07-25 10:46:58 +00:00
|
|
|
}
|
|
|
|
return $statusCode;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Process request to show page
|
|
|
|
function processRequestShow($serverScheme, $serverName, $base, $location, $fileName)
|
|
|
|
{
|
|
|
|
$statusCode = 0;
|
|
|
|
if(is_readable($fileName))
|
|
|
|
{
|
2015-01-19 19:05:51 +00:00
|
|
|
$statusCode = $this->yellow->processRequest($serverScheme, $serverName, $base, $location, $fileName, false);
|
2014-07-25 10:46:58 +00:00
|
|
|
} else {
|
2015-04-29 07:26:48 +00:00
|
|
|
if($this->yellow->isRequestContentDirectory($location))
|
2014-07-25 10:46:58 +00:00
|
|
|
{
|
|
|
|
$statusCode = 301;
|
2016-05-15 16:35:10 +00:00
|
|
|
$location = $this->yellow->lookup->isFileLocation($location) ? "$location/" : "/".$this->yellow->getRequestLanguage(true)."/";
|
2015-04-29 07:26:48 +00:00
|
|
|
$location = $this->yellow->lookup->normaliseUrl($serverScheme, $serverName, $base, $location);
|
|
|
|
$this->yellow->sendStatus($statusCode, $location);
|
2014-07-25 10:46:58 +00:00
|
|
|
} else {
|
2016-04-12 13:58:56 +00:00
|
|
|
$statusCode = $this->userRestrictions ? 404 : 424;
|
2015-01-19 19:05:51 +00:00
|
|
|
$this->yellow->processRequest($serverScheme, $serverName, $base, $location, $fileName, false);
|
|
|
|
$this->yellow->page->error($statusCode);
|
2014-07-25 10:46:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return $statusCode;
|
|
|
|
}
|
|
|
|
|
2016-04-12 13:58:56 +00:00
|
|
|
// Process request for user login
|
|
|
|
function processRequestLogin($serverScheme, $serverName, $base, $location, $fileName)
|
|
|
|
{
|
|
|
|
$statusCode = 0;
|
2016-05-15 16:35:10 +00:00
|
|
|
$home = $this->users->getHome($this->userEmail);
|
2016-04-12 13:58:56 +00:00
|
|
|
if(substru($location, 0, strlenu($home)) == $home)
|
|
|
|
{
|
|
|
|
$statusCode = 303;
|
|
|
|
$location = $this->yellow->lookup->normaliseUrl($serverScheme, $serverName, $base, $location);
|
|
|
|
$this->yellow->sendStatus($statusCode, $location);
|
|
|
|
} else {
|
|
|
|
$statusCode = 302;
|
|
|
|
$location = $this->yellow->lookup->normaliseUrl($serverScheme, $serverName, $base, $home);
|
|
|
|
$this->yellow->sendStatus($statusCode, $location);
|
|
|
|
}
|
|
|
|
return $statusCode;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Process request for user logout
|
|
|
|
function processRequestLogout($serverScheme, $serverName, $base, $location, $fileName)
|
|
|
|
{
|
|
|
|
$statusCode = 302;
|
2016-05-15 16:35:10 +00:00
|
|
|
$this->userEmail = "";
|
2016-04-12 13:58:56 +00:00
|
|
|
$this->users->destroyCookie("login");
|
|
|
|
$location = $this->yellow->lookup->normaliseUrl(
|
|
|
|
$this->yellow->config->get("serverScheme"),
|
|
|
|
$this->yellow->config->get("serverName"),
|
|
|
|
$this->yellow->config->get("serverBase"), $location);
|
|
|
|
$this->yellow->sendStatus($statusCode, $location);
|
|
|
|
return $statusCode;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Process request for user signup
|
|
|
|
function processRequestSignup($serverScheme, $serverName, $base, $location, $fileName)
|
|
|
|
{
|
2016-05-15 16:35:10 +00:00
|
|
|
$this->action = "signup";
|
|
|
|
$this->status = "ok";
|
2016-04-12 13:58:56 +00:00
|
|
|
$name = trim(preg_replace("/[^\pL\d\-\. ]/u", "-", $_REQUEST["name"]));
|
|
|
|
$email = trim($_REQUEST["email"]);
|
|
|
|
$password = trim($_REQUEST["password"]);
|
2016-05-15 16:35:10 +00:00
|
|
|
if(empty($name) || empty($email) || empty($password)) $this->status = "incomplete";
|
|
|
|
if($this->status == "ok") $this->status = $this->getUserAccount($email, $password, $this->action);
|
|
|
|
if($this->status == "ok" && !$this->users->isWebmaster()) $this->status = "next";
|
|
|
|
if($this->status == "ok" && $this->users->isExisting($email)) $this->status = "next";
|
|
|
|
if($this->status == "ok")
|
2016-04-12 13:58:56 +00:00
|
|
|
{
|
|
|
|
$fileNameUser = $this->yellow->config->get("configDir").$this->yellow->config->get("webinterfaceUserFile");
|
2016-05-15 16:35:10 +00:00
|
|
|
$this->status = $this->users->update($fileNameUser, $email, $password, $name, "", "unconfirmed") ? "ok" : "error";
|
|
|
|
if($this->status == "error") $this->yellow->page->error(500, "Can't write file '$fileNameUser'!");
|
2016-04-12 13:58:56 +00:00
|
|
|
}
|
2016-05-15 16:35:10 +00:00
|
|
|
if($this->status == "ok")
|
2016-04-12 13:58:56 +00:00
|
|
|
{
|
2016-05-15 16:35:10 +00:00
|
|
|
$this->status = $this->sendMail($serverScheme, $serverName, $base, $email, "confirm") ? "next" : "error";
|
|
|
|
if($this->status == "error") $this->yellow->page->error(500, "Can't send email on this server!");
|
2016-04-12 13:58:56 +00:00
|
|
|
}
|
|
|
|
$statusCode = $this->yellow->processRequest($serverScheme, $serverName, $base, $location, $fileName, false);
|
|
|
|
return $statusCode;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Process request to confirm user signup
|
|
|
|
function processRequestConfirm($serverScheme, $serverName, $base, $location, $fileName)
|
|
|
|
{
|
2016-05-15 16:35:10 +00:00
|
|
|
$this->action = "confirm";
|
|
|
|
$this->status = "ok";
|
2016-04-12 13:58:56 +00:00
|
|
|
$email = $_REQUEST["email"];
|
2016-05-15 16:35:10 +00:00
|
|
|
$this->status = $this->getUserRequest($email, $_REQUEST["action"], $_REQUEST["expire"], $_REQUEST["id"]);
|
|
|
|
if($this->status == "ok")
|
2016-04-12 13:58:56 +00:00
|
|
|
{
|
|
|
|
$fileNameUser = $this->yellow->config->get("configDir").$this->yellow->config->get("webinterfaceUserFile");
|
2016-05-15 16:35:10 +00:00
|
|
|
$this->status = $this->users->update($fileNameUser, $email, "", "", "", "unapproved") ? "ok" : "error";
|
|
|
|
if($this->status == "error") $this->yellow->page->error(500, "Can't write file '$fileNameUser'!");
|
2016-04-12 13:58:56 +00:00
|
|
|
}
|
2016-05-15 16:35:10 +00:00
|
|
|
if($this->status == "ok")
|
2016-04-12 13:58:56 +00:00
|
|
|
{
|
2016-05-15 16:35:10 +00:00
|
|
|
$this->status = $this->sendMail($serverScheme, $serverName, $base, $email, "approve") ? "done" : "error";
|
|
|
|
if($this->status == "error") $this->yellow->page->error(500, "Can't send email on this server!");
|
2016-04-12 13:58:56 +00:00
|
|
|
}
|
|
|
|
$statusCode = $this->yellow->processRequest($serverScheme, $serverName, $base, $location, $fileName, false);
|
|
|
|
return $statusCode;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Process request to approve user signup
|
|
|
|
function processRequestApprove($serverScheme, $serverName, $base, $location, $fileName)
|
|
|
|
{
|
2016-05-15 16:35:10 +00:00
|
|
|
$this->action = "approve";
|
|
|
|
$this->status = "ok";
|
2016-04-12 13:58:56 +00:00
|
|
|
$email = $_REQUEST["email"];
|
2016-05-15 16:35:10 +00:00
|
|
|
$this->status = $this->getUserRequest($email, $_REQUEST["action"], $_REQUEST["expire"], $_REQUEST["id"]);
|
|
|
|
if($this->status == "ok")
|
2016-04-12 13:58:56 +00:00
|
|
|
{
|
|
|
|
$fileNameUser = $this->yellow->config->get("configDir").$this->yellow->config->get("webinterfaceUserFile");
|
2016-05-15 16:35:10 +00:00
|
|
|
$this->status = $this->users->update($fileNameUser, $email, "", "", "", "active") ? "ok" : "error";
|
|
|
|
if($this->status == "error") $this->yellow->page->error(500, "Can't write file '$fileNameUser'!");
|
2016-04-12 13:58:56 +00:00
|
|
|
}
|
2016-05-15 16:35:10 +00:00
|
|
|
if($this->status == "ok")
|
2016-04-12 13:58:56 +00:00
|
|
|
{
|
2016-05-15 16:35:10 +00:00
|
|
|
$this->status = $this->sendMail($serverScheme, $serverName, $base, $email, "welcome") ? "done" : "error";
|
|
|
|
if($this->status == "error") $this->yellow->page->error(500, "Can't send email on this server!");
|
2016-04-12 13:58:56 +00:00
|
|
|
}
|
|
|
|
$statusCode = $this->yellow->processRequest($serverScheme, $serverName, $base, $location, $fileName, false);
|
|
|
|
return $statusCode;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Process request to recover password
|
|
|
|
function processRequestRecover($serverScheme, $serverName, $base, $location, $fileName)
|
|
|
|
{
|
2016-05-15 16:35:10 +00:00
|
|
|
$this->action = "recover";
|
|
|
|
$this->status = "ok";
|
2016-04-12 13:58:56 +00:00
|
|
|
$email = trim($_REQUEST["email"]);
|
|
|
|
$password = trim($_REQUEST["password"]);
|
|
|
|
if(empty($_REQUEST["id"]))
|
|
|
|
{
|
2016-05-15 16:35:10 +00:00
|
|
|
if(!filter_var($email, FILTER_VALIDATE_EMAIL)) $this->status = "invalid";
|
|
|
|
if($this->status == "ok" && !$this->users->isWebmaster()) $this->status = "next";
|
|
|
|
if($this->status == "ok" && !$this->users->isExisting($email)) $this->status = "next";
|
|
|
|
if($this->status == "ok")
|
2016-04-12 13:58:56 +00:00
|
|
|
{
|
2016-05-15 16:35:10 +00:00
|
|
|
$this->status = $this->sendMail($serverScheme, $serverName, $base, $email, "recover") ? "next" : "error";
|
|
|
|
if($this->status == "error") $this->yellow->page->error(500, "Can't send email on this server!");
|
2016-04-12 13:58:56 +00:00
|
|
|
}
|
|
|
|
} else {
|
2016-05-15 16:35:10 +00:00
|
|
|
$this->status = $this->getUserRequest($email, $_REQUEST["action"], $_REQUEST["expire"], $_REQUEST["id"]);
|
|
|
|
if($this->status == "ok")
|
2016-04-12 13:58:56 +00:00
|
|
|
{
|
2016-05-15 16:35:10 +00:00
|
|
|
if(empty($password)) $this->status = "password";
|
|
|
|
if($this->status == "ok") $this->status = $this->getUserAccount($email, $password, $this->action);
|
|
|
|
if($this->status == "ok")
|
2016-04-12 13:58:56 +00:00
|
|
|
{
|
|
|
|
$fileNameUser = $this->yellow->config->get("configDir").$this->yellow->config->get("webinterfaceUserFile");
|
2016-05-15 16:35:10 +00:00
|
|
|
$this->status = $this->users->update($fileNameUser, $email, $password) ? "ok" : "error";
|
|
|
|
if($this->status == "error") $this->yellow->page->error(500, "Can't write file '$fileNameUser'!");
|
2016-04-12 13:58:56 +00:00
|
|
|
}
|
2016-05-15 16:35:10 +00:00
|
|
|
if($this->status == "ok")
|
2016-04-12 13:58:56 +00:00
|
|
|
{
|
2016-05-15 16:35:10 +00:00
|
|
|
$this->userEmail = "";
|
|
|
|
$this->users->destroyCookie("login");
|
|
|
|
$this->status = $this->sendMail($serverScheme, $serverName, $base, $email, "information") ? "done" : "error";
|
|
|
|
if($this->status == "error") $this->yellow->page->error(500, "Can't send email on this server!");
|
2016-04-12 13:58:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$statusCode = $this->yellow->processRequest($serverScheme, $serverName, $base, $location, $fileName, false);
|
|
|
|
return $statusCode;
|
|
|
|
}
|
2016-05-15 16:35:10 +00:00
|
|
|
|
|
|
|
// Process request to change settings
|
|
|
|
function processRequestSettings($serverScheme, $serverName, $base, $location, $fileName)
|
|
|
|
{
|
2016-06-02 15:31:42 +00:00
|
|
|
$this->action = "settings";
|
|
|
|
$this->status = $this->getUserAccount($this->userEmail, "", $this->action);
|
|
|
|
if($this->status == "ok")
|
2016-05-15 16:35:10 +00:00
|
|
|
{
|
|
|
|
$name = trim(preg_replace("/[^\pL\d\-\. ]/u", "-", $_REQUEST["name"]));
|
|
|
|
$language = trim($_REQUEST["language"]);
|
|
|
|
$fileNameUser = $this->yellow->config->get("configDir").$this->yellow->config->get("webinterfaceUserFile");
|
2016-06-02 15:31:42 +00:00
|
|
|
$this->status = $this->users->update($fileNameUser, $this->userEmail, "", $name, $language) ? "done" : "error";
|
|
|
|
if($this->status == "error") $this->yellow->page->error(500, "Can't write file '$fileNameUser'!");
|
|
|
|
}
|
|
|
|
if($this->status == "done")
|
|
|
|
{
|
|
|
|
$statusCode = 303;
|
|
|
|
$location = $this->yellow->lookup->normaliseUrl($serverScheme, $serverName, $base, $location);
|
|
|
|
$this->yellow->sendStatus($statusCode, $location);
|
|
|
|
} else {
|
|
|
|
$statusCode = $this->yellow->processRequest($serverScheme, $serverName, $base, $location, $fileName, false);
|
2016-05-15 16:35:10 +00:00
|
|
|
}
|
|
|
|
return $statusCode;
|
|
|
|
}
|
2016-04-12 13:58:56 +00:00
|
|
|
|
2014-07-25 10:46:58 +00:00
|
|
|
// Process request to create page
|
|
|
|
function processRequestCreate($serverScheme, $serverName, $base, $location, $fileName)
|
|
|
|
{
|
|
|
|
$statusCode = 0;
|
2016-04-12 13:58:56 +00:00
|
|
|
if(!$this->userRestrictions && !empty($_POST["rawdataedit"]))
|
2014-07-25 10:46:58 +00:00
|
|
|
{
|
2014-12-21 23:53:51 +00:00
|
|
|
$this->rawDataSource = $this->rawDataEdit = rawurldecode($_POST["rawdatasource"]);
|
2016-04-12 13:58:56 +00:00
|
|
|
$rawData = $this->normaliseText(rawurldecode($_POST["rawdataedit"]));
|
|
|
|
$page = $this->getPageNew($serverScheme, $serverName, $base, $location, $fileName, $rawData);
|
2014-08-13 14:36:13 +00:00
|
|
|
if(!$page->isError())
|
2014-07-25 10:46:58 +00:00
|
|
|
{
|
2014-08-13 14:36:13 +00:00
|
|
|
if($this->yellow->toolbox->createFile($page->fileName, $page->rawData))
|
|
|
|
{
|
|
|
|
$statusCode = 303;
|
2015-04-29 07:26:48 +00:00
|
|
|
$location = $this->yellow->lookup->normaliseUrl($serverScheme, $serverName, $base, $page->location);
|
|
|
|
$this->yellow->sendStatus($statusCode, $location);
|
2014-08-13 14:36:13 +00:00
|
|
|
} else {
|
|
|
|
$statusCode = 500;
|
2015-01-19 19:05:51 +00:00
|
|
|
$this->yellow->processRequest($serverScheme, $serverName, $base, $location, $fileName, false);
|
2014-08-13 14:36:13 +00:00
|
|
|
$this->yellow->page->error($statusCode, "Can't write file '$page->fileName'!");
|
|
|
|
}
|
2014-07-25 10:46:58 +00:00
|
|
|
} else {
|
|
|
|
$statusCode = 500;
|
2016-04-12 13:58:56 +00:00
|
|
|
$this->yellow->processRequest($serverScheme, $serverName, $base, $location, $fileName, false);
|
2014-08-13 14:36:13 +00:00
|
|
|
$this->yellow->page->error($statusCode, $page->get("pageError"));
|
2014-07-25 10:46:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return $statusCode;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Process request to edit page
|
|
|
|
function processRequestEdit($serverScheme, $serverName, $base, $location, $fileName)
|
|
|
|
{
|
|
|
|
$statusCode = 0;
|
2016-04-12 13:58:56 +00:00
|
|
|
if(!$this->userRestrictions && !empty($_POST["rawdataedit"]))
|
2014-07-25 10:46:58 +00:00
|
|
|
{
|
2014-12-21 23:53:51 +00:00
|
|
|
$this->rawDataSource = rawurldecode($_POST["rawdatasource"]);
|
2016-04-12 13:58:56 +00:00
|
|
|
$this->rawDataEdit = $this->normaliseText(rawurldecode($_POST["rawdataedit"]));
|
2014-11-13 13:49:21 +00:00
|
|
|
$page = $this->getPageUpdate($serverScheme, $serverName, $base, $location, $fileName,
|
2016-02-20 17:34:06 +00:00
|
|
|
$this->rawDataSource, $this->rawDataEdit, $this->yellow->toolbox->readFile($fileName));
|
2014-08-13 14:36:13 +00:00
|
|
|
if(!$page->isError())
|
2014-07-25 10:46:58 +00:00
|
|
|
{
|
2014-08-13 14:36:13 +00:00
|
|
|
if($this->yellow->toolbox->renameFile($fileName, $page->fileName) &&
|
|
|
|
$this->yellow->toolbox->createFile($page->fileName, $page->rawData))
|
2014-07-25 10:46:58 +00:00
|
|
|
{
|
|
|
|
$statusCode = 303;
|
2015-04-29 07:26:48 +00:00
|
|
|
$location = $this->yellow->lookup->normaliseUrl($serverScheme, $serverName, $base, $page->location);
|
|
|
|
$this->yellow->sendStatus($statusCode, $location);
|
2014-07-25 10:46:58 +00:00
|
|
|
} else {
|
|
|
|
$statusCode = 500;
|
2015-01-19 19:05:51 +00:00
|
|
|
$this->yellow->processRequest($serverScheme, $serverName, $base, $location, $fileName, false);
|
2014-08-13 14:36:13 +00:00
|
|
|
$this->yellow->page->error($statusCode, "Can't write file '$page->fileName'!");
|
2014-07-25 10:46:58 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$statusCode = 500;
|
2015-01-19 19:05:51 +00:00
|
|
|
$this->yellow->processRequest($serverScheme, $serverName, $base, $location, $fileName, false);
|
2014-08-13 14:36:13 +00:00
|
|
|
$this->yellow->page->error($statusCode, $page->get("pageError"));
|
2014-07-25 10:46:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return $statusCode;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Process request to delete page
|
|
|
|
function processRequestDelete($serverScheme, $serverName, $base, $location, $fileName)
|
2013-04-14 22:41:04 +00:00
|
|
|
{
|
|
|
|
$statusCode = 0;
|
2016-04-12 13:58:56 +00:00
|
|
|
if(!$this->userRestrictions)
|
2013-04-14 22:41:04 +00:00
|
|
|
{
|
2014-12-21 23:53:51 +00:00
|
|
|
$this->rawDataSource = $this->rawDataEdit = rawurldecode($_POST["rawdatasource"]);
|
2014-07-25 10:46:58 +00:00
|
|
|
if(!is_file($fileName) || $this->yellow->toolbox->deleteFile($fileName))
|
|
|
|
{
|
|
|
|
$statusCode = 303;
|
2015-04-29 07:26:48 +00:00
|
|
|
$location = $this->yellow->lookup->normaliseUrl($serverScheme, $serverName, $base, $location);
|
|
|
|
$this->yellow->sendStatus($statusCode, $location);
|
2014-07-25 10:46:58 +00:00
|
|
|
} else {
|
|
|
|
$statusCode = 500;
|
2015-01-19 19:05:51 +00:00
|
|
|
$this->yellow->processRequest($serverScheme, $serverName, $base, $location, $fileName, false);
|
2014-07-25 10:46:58 +00:00
|
|
|
$this->yellow->page->error($statusCode, "Can't delete file '$fileName'!");
|
|
|
|
}
|
2013-04-14 22:41:04 +00:00
|
|
|
}
|
|
|
|
return $statusCode;
|
|
|
|
}
|
2014-07-25 10:46:58 +00:00
|
|
|
|
2016-04-12 13:58:56 +00:00
|
|
|
// Send mail to web interface user
|
|
|
|
function sendMail($serverScheme, $serverName, $base, $email, $action)
|
2014-07-25 10:46:58 +00:00
|
|
|
{
|
2016-05-15 16:35:10 +00:00
|
|
|
if($action=="welcome" || $action=="information")
|
2016-04-12 13:58:56 +00:00
|
|
|
{
|
|
|
|
$url = "$serverScheme://$serverName$base/";
|
|
|
|
} else {
|
2016-05-15 16:35:10 +00:00
|
|
|
$expire = time()+60*60*24;
|
|
|
|
$id = $this->users->createUserRequestId($email, $action, $expire);
|
|
|
|
$url = "$serverScheme://$serverName$base"."/action:$action/email:$email/expire:$expire/id:$id/";
|
2016-04-12 13:58:56 +00:00
|
|
|
}
|
|
|
|
if($action == "approve")
|
|
|
|
{
|
|
|
|
$account = $email;
|
|
|
|
$name = $this->yellow->config->get("author");
|
|
|
|
$email = $this->yellow->config->get("email");
|
|
|
|
} else {
|
|
|
|
$account = $email;
|
|
|
|
$name = $this->users->getName($email);
|
|
|
|
}
|
|
|
|
$language = $this->users->getLanguage($email);
|
|
|
|
if(!$this->yellow->text->isLanguage($language)) $language = $this->yellow->config->get("language");
|
|
|
|
$sitename = $this->yellow->config->get("sitename");
|
|
|
|
$prefix = "webinterface".ucfirst($action);
|
|
|
|
$message = $this->yellow->text->getText("{$prefix}Message", $language);
|
|
|
|
$message = preg_replace("/@useraccount/i", $account, $message);
|
|
|
|
$message = preg_replace("/@usershort/i", strtok($name, " "), $message);
|
|
|
|
$message = preg_replace("/@username/i", $name, $message);
|
|
|
|
$message = preg_replace("/@userlanguage/i", $language, $message);
|
|
|
|
$mailTo = mb_encode_mimeheader("$name <$email>");
|
|
|
|
$mailSubject = mb_encode_mimeheader($this->yellow->text->getText("{$prefix}Subject", $language));
|
|
|
|
$mailHeaders = mb_encode_mimeheader("From: $sitename <noreply>")."\r\n";
|
|
|
|
$mailHeaders .= mb_encode_mimeheader("X-Request-Url: $serverScheme://$serverName$base")."\r\n";
|
|
|
|
$mailHeaders .= mb_encode_mimeheader("X-Remote-Addr: $_SERVER[REMOTE_ADDR]")."\r\n";
|
|
|
|
$mailHeaders .= "Mime-Version: 1.0\r\n";
|
|
|
|
$mailHeaders .= "Content-Type: text/plain; charset=utf-8\r\n";
|
|
|
|
$mailMessage = "$message\r\n\r\n$url\r\n-- \r\n$sitename";
|
|
|
|
return mail($mailTo, $mailSubject, $mailMessage, $mailHeaders);
|
2014-07-25 10:46:58 +00:00
|
|
|
}
|
|
|
|
|
2014-05-15 11:53:54 +00:00
|
|
|
// Check web interface request
|
2016-06-02 15:31:42 +00:00
|
|
|
function checkRequest($location)
|
2013-04-14 22:41:04 +00:00
|
|
|
{
|
2016-05-15 16:35:10 +00:00
|
|
|
if($this->yellow->toolbox->getServerScheme()==$this->yellow->config->get("webinterfaceServerScheme") &&
|
|
|
|
$this->yellow->toolbox->getServerName()==$this->yellow->config->get("webinterfaceServerName"))
|
|
|
|
{
|
|
|
|
$locationLength = strlenu($this->yellow->config->get("webinterfaceLocation"));
|
|
|
|
$this->active = substru($location, 0, $locationLength) == $this->yellow->config->get("webinterfaceLocation");
|
|
|
|
}
|
2016-06-02 15:31:42 +00:00
|
|
|
return $this->isActive();
|
2013-04-14 22:41:04 +00:00
|
|
|
}
|
|
|
|
|
2014-04-07 15:14:31 +00:00
|
|
|
// Check web interface user
|
2014-07-25 10:46:58 +00:00
|
|
|
function checkUser($location, $fileName)
|
2013-04-14 22:41:04 +00:00
|
|
|
{
|
|
|
|
if($_POST["action"] == "login")
|
|
|
|
{
|
2013-12-05 22:30:45 +00:00
|
|
|
$email = $_POST["email"];
|
2013-04-14 22:41:04 +00:00
|
|
|
$password = $_POST["password"];
|
|
|
|
if($this->users->checkUser($email, $password))
|
|
|
|
{
|
|
|
|
$this->users->createCookie("login", $email);
|
2016-05-15 16:35:10 +00:00
|
|
|
$this->userEmail = $email;
|
|
|
|
$this->userLanguage = $this->getUserLanguage($email);
|
2016-04-12 13:58:56 +00:00
|
|
|
$this->userRestrictions = $this->getUserRestrictions($email, $location, $fileName);
|
2013-04-14 22:41:04 +00:00
|
|
|
} else {
|
2016-05-15 16:35:10 +00:00
|
|
|
$this->action = "fail";
|
2013-04-14 22:41:04 +00:00
|
|
|
}
|
|
|
|
} else if(isset($_COOKIE["login"])) {
|
2016-04-12 13:58:56 +00:00
|
|
|
list($email, $session) = explode(',', $_COOKIE["login"], 2);
|
2014-05-04 12:57:52 +00:00
|
|
|
if($this->users->checkCookie($email, $session))
|
2013-04-14 22:41:04 +00:00
|
|
|
{
|
2016-05-15 16:35:10 +00:00
|
|
|
$this->userEmail = $email;
|
|
|
|
$this->userLanguage = $this->getUserLanguage($email);
|
2016-04-12 13:58:56 +00:00
|
|
|
$this->userRestrictions = $this->getUserRestrictions($email, $location, $fileName);
|
2013-04-14 22:41:04 +00:00
|
|
|
} else {
|
2016-05-15 16:35:10 +00:00
|
|
|
$this->action = "fail";
|
2013-04-14 22:41:04 +00:00
|
|
|
}
|
|
|
|
}
|
2016-05-15 16:35:10 +00:00
|
|
|
if(!$this->users->getNumber() && !$this->users->isWebmaster()) $this->action = "off";
|
2013-04-14 22:41:04 +00:00
|
|
|
return $this->isUser();
|
|
|
|
}
|
2016-05-15 16:35:10 +00:00
|
|
|
|
|
|
|
// Return user language
|
|
|
|
function getUserLanguage($email)
|
|
|
|
{
|
|
|
|
$language = $this->users->getLanguage($email);
|
|
|
|
if(!$this->yellow->text->isLanguage($language)) $language = $this->yellow->config->get("language");
|
|
|
|
return $language;
|
|
|
|
}
|
2014-04-07 15:14:31 +00:00
|
|
|
|
2016-04-12 13:58:56 +00:00
|
|
|
// Return user account request
|
|
|
|
function getUserRequest($email, $action, $expire, $id)
|
2013-04-14 22:41:04 +00:00
|
|
|
{
|
2016-05-15 16:35:10 +00:00
|
|
|
$status = $this->users->checkUserRequest($email, $action, $expire, $id) ? "ok" : "done";
|
|
|
|
if($status=="done" && $expire<=time()) $status = "expire";
|
|
|
|
return $status;
|
2016-04-12 13:58:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Return user account changes
|
|
|
|
function getUserAccount($email, $password, $action)
|
|
|
|
{
|
2016-05-15 16:35:10 +00:00
|
|
|
$status = NULL;
|
2014-04-07 15:14:31 +00:00
|
|
|
foreach($this->yellow->plugins->plugins as $key=>$value)
|
|
|
|
{
|
2016-04-12 13:58:56 +00:00
|
|
|
if(method_exists($value["obj"], "onUserAccount"))
|
2014-04-07 15:14:31 +00:00
|
|
|
{
|
2016-05-15 16:35:10 +00:00
|
|
|
$status = $value["obj"]->onUserAccount($email, $password, $action, $status, $this->users);
|
|
|
|
if(!is_null($status)) break;
|
2014-04-07 15:14:31 +00:00
|
|
|
}
|
|
|
|
}
|
2016-05-15 16:35:10 +00:00
|
|
|
if(is_null($status))
|
2015-09-06 15:59:14 +00:00
|
|
|
{
|
2016-05-15 16:35:10 +00:00
|
|
|
$status = "ok";
|
|
|
|
if(!empty($password) && strlenu($password)<$this->yellow->config->get("webinterfaceUserPasswordMinLength")) $status = "weak";
|
|
|
|
if(!empty($email) && !filter_var($email, FILTER_VALIDATE_EMAIL)) $status = "invalid";
|
2015-09-06 15:59:14 +00:00
|
|
|
}
|
2016-05-15 16:35:10 +00:00
|
|
|
return $status;
|
2013-04-14 22:41:04 +00:00
|
|
|
}
|
|
|
|
|
2016-04-12 13:58:56 +00:00
|
|
|
// Return user restrictions to change page
|
|
|
|
function getUserRestrictions($email, $location, $fileName)
|
2015-08-09 20:17:17 +00:00
|
|
|
{
|
2016-04-12 13:58:56 +00:00
|
|
|
$userRestrictions = NULL;
|
|
|
|
foreach($this->yellow->plugins->plugins as $key=>$value)
|
2015-10-06 12:19:11 +00:00
|
|
|
{
|
2016-04-12 13:58:56 +00:00
|
|
|
if(method_exists($value["obj"], "onUserRestrictions"))
|
|
|
|
{
|
|
|
|
$userRestrictions = $value["obj"]->onUserRestrictions($email, $location, $fileName, $this->users);
|
|
|
|
if(!is_null($userRestrictions)) break;
|
|
|
|
}
|
2015-10-06 12:19:11 +00:00
|
|
|
}
|
2016-04-12 13:58:56 +00:00
|
|
|
if(is_null($userRestrictions))
|
|
|
|
{
|
|
|
|
$userRestrictions = !is_dir(dirname($fileName)) || strlenu(basename($fileName))>128;
|
2016-05-15 16:35:10 +00:00
|
|
|
$userRestrictions |= substru($location, 0, strlenu($this->users->getHome($email))) != $this->users->getHome($email);
|
2016-04-12 13:58:56 +00:00
|
|
|
}
|
|
|
|
return $userRestrictions;
|
2015-08-09 20:17:17 +00:00
|
|
|
}
|
|
|
|
|
2014-07-25 10:46:58 +00:00
|
|
|
// Update request information
|
|
|
|
function updateRequestInformation()
|
2013-04-14 22:41:04 +00:00
|
|
|
{
|
2016-04-12 13:58:56 +00:00
|
|
|
if($this->isActive())
|
|
|
|
{
|
|
|
|
$serverScheme = $this->yellow->config->get("webinterfaceServerScheme");
|
|
|
|
$serverName = $this->yellow->config->get("webinterfaceServerName");
|
|
|
|
$base = rtrim($this->yellow->config->get("serverBase").$this->yellow->config->get("webinterfaceLocation"), '/');
|
|
|
|
$this->yellow->page->base = $base;
|
|
|
|
}
|
2014-05-15 11:53:54 +00:00
|
|
|
return $this->yellow->getRequestInformation($serverScheme, $serverName, $base);
|
2013-04-14 22:41:04 +00:00
|
|
|
}
|
|
|
|
|
2014-07-25 10:46:58 +00:00
|
|
|
// Update page data with title
|
|
|
|
function updateDataTitle($rawData, $title)
|
|
|
|
{
|
2014-11-13 13:49:21 +00:00
|
|
|
foreach($this->yellow->toolbox->getTextLines($rawData) as $line)
|
2014-07-25 10:46:58 +00:00
|
|
|
{
|
|
|
|
if(preg_match("/^(\s*Title\s*:\s*)(.*?)(\s*)$/i", $line, $matches)) $line = $matches[1].$title.$matches[3];
|
|
|
|
$rawDataNew .= $line;
|
|
|
|
}
|
|
|
|
return $rawDataNew;
|
|
|
|
}
|
|
|
|
|
2015-05-24 15:31:17 +00:00
|
|
|
// Return page data title
|
|
|
|
function getDataTitle($rawData)
|
|
|
|
{
|
|
|
|
$title = $this->yellow->page->get("title");
|
|
|
|
if(preg_match("/^(\xEF\xBB\xBF)?\-\-\-[\r\n]+(.+?)[\r\n]+\-\-\-[\r\n]+/s", $rawData))
|
|
|
|
{
|
|
|
|
foreach($this->yellow->toolbox->getTextLines($rawData) as $line)
|
|
|
|
{
|
|
|
|
if(preg_match("/^(\s*Title\s*:\s*)(.*?)(\s*)$/i", $line, $matches)) { $title = $matches[2]; break; }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $title;
|
|
|
|
}
|
|
|
|
|
2014-07-25 10:46:58 +00:00
|
|
|
// Return new page
|
|
|
|
function getPageNew($serverScheme, $serverName, $base, $location, $fileName, $rawData)
|
|
|
|
{
|
2015-01-19 19:05:51 +00:00
|
|
|
$page = new YellowPage($this->yellow);
|
|
|
|
$page->setRequestInformation($serverScheme, $serverName, $base, $location, $fileName);
|
2015-04-29 07:26:48 +00:00
|
|
|
$page->parseData($rawData, false, 0);
|
2015-10-21 12:28:56 +00:00
|
|
|
if($this->yellow->lookup->isFileLocation($location) || is_file($fileName))
|
2014-07-25 10:46:58 +00:00
|
|
|
{
|
2015-10-21 12:28:56 +00:00
|
|
|
$page->fileName = $this->yellow->lookup->findFileFromTitle(
|
|
|
|
$page->get($this->yellow->config->get("webinterfaceMetaFilePrefix")), $page->get("title"), $fileName,
|
|
|
|
$this->yellow->config->get("contentDefaultFile"), $this->yellow->config->get("contentExtension"));
|
|
|
|
$page->location = $this->yellow->lookup->findLocationFromFile($page->fileName);
|
|
|
|
if($this->yellow->pages->find($page->location))
|
2014-07-25 10:46:58 +00:00
|
|
|
{
|
2015-10-21 12:28:56 +00:00
|
|
|
preg_match("/^(.*?)(\d*)$/", $page->get("title"), $matches);
|
|
|
|
$titleText = $matches[1];
|
|
|
|
$titleNumber = $matches[2];
|
|
|
|
if(strempty($titleNumber)) { $titleNumber = 2; $titleText = $titleText.' '; }
|
|
|
|
for(; $titleNumber<=999; ++$titleNumber)
|
|
|
|
{
|
|
|
|
$page->rawData = $this->updateDataTitle($rawData, $titleText.$titleNumber);
|
|
|
|
$page->fileName = $this->yellow->lookup->findFileFromTitle(
|
|
|
|
$page->get($this->yellow->config->get("webinterfaceMetaFilePrefix")), $titleText.$titleNumber, $fileName,
|
|
|
|
$this->yellow->config->get("contentDefaultFile"), $this->yellow->config->get("contentExtension"));
|
|
|
|
$page->location = $this->yellow->lookup->findLocationFromFile($page->fileName);
|
|
|
|
if(!$this->yellow->pages->find($page->location)) { $ok = true; break; }
|
|
|
|
}
|
|
|
|
if(!$ok) $page->error(500, "Page '".$page->get("title")."' can not be created!");
|
2014-07-25 10:46:58 +00:00
|
|
|
}
|
2014-08-13 14:36:13 +00:00
|
|
|
}
|
2016-05-15 16:35:10 +00:00
|
|
|
if($this->getUserRestrictions($this->userEmail, $page->location, $page->fileName))
|
2016-04-12 13:58:56 +00:00
|
|
|
{
|
|
|
|
$page->error(500, "Page '".$page->get("title")."' is not allowed!");
|
|
|
|
}
|
2014-08-13 14:36:13 +00:00
|
|
|
return $page;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return modified page
|
2014-11-13 13:49:21 +00:00
|
|
|
function getPageUpdate($serverScheme, $serverName, $base, $location, $fileName, $rawDataSource, $rawDataEdit, $rawDataFile)
|
2014-08-13 14:36:13 +00:00
|
|
|
{
|
2015-01-19 19:05:51 +00:00
|
|
|
$page = new YellowPage($this->yellow);
|
|
|
|
$page->setRequestInformation($serverScheme, $serverName, $base, $location, $fileName);
|
2015-04-29 07:26:48 +00:00
|
|
|
$page->parseData($this->merge->merge($rawDataSource, $rawDataEdit, $rawDataFile), false, 0);
|
2014-08-13 14:36:13 +00:00
|
|
|
if(empty($page->rawData)) $page->error(500, "Page has been modified by someone else!");
|
2015-04-29 07:26:48 +00:00
|
|
|
if($this->yellow->lookup->isFileLocation($location) && !$page->isError())
|
2014-08-13 14:36:13 +00:00
|
|
|
{
|
2015-01-19 19:05:51 +00:00
|
|
|
$pageSource = new YellowPage($this->yellow);
|
|
|
|
$pageSource->setRequestInformation($serverScheme, $serverName, $base, $location, $fileName);
|
2015-04-29 07:26:48 +00:00
|
|
|
$pageSource->parseData($rawDataSource, false, 0);
|
|
|
|
$prefix = $this->yellow->config->get("webinterfaceMetaFilePrefix");
|
2014-08-13 14:36:13 +00:00
|
|
|
if($pageSource->get($prefix)!=$page->get($prefix) || $pageSource->get("title")!=$page->get("title"))
|
2014-07-25 10:46:58 +00:00
|
|
|
{
|
2015-04-29 07:26:48 +00:00
|
|
|
$page->fileName = $this->yellow->lookup->findFileFromTitle(
|
2014-08-13 14:36:13 +00:00
|
|
|
$page->get($prefix), $page->get("title"), $fileName,
|
2014-07-25 10:46:58 +00:00
|
|
|
$this->yellow->config->get("contentDefaultFile"), $this->yellow->config->get("contentExtension"));
|
2015-04-29 07:26:48 +00:00
|
|
|
$page->location = $this->yellow->lookup->findLocationFromFile($page->fileName);
|
2015-10-21 12:28:56 +00:00
|
|
|
if($pageSource->location != $page->location)
|
2014-08-13 14:36:13 +00:00
|
|
|
{
|
2015-10-21 12:28:56 +00:00
|
|
|
if(!$this->yellow->lookup->isFileLocation($page->location))
|
|
|
|
{
|
|
|
|
$page->error(500, "Page '".$page->get("title")."' is not allowed!");
|
|
|
|
} else if($this->yellow->pages->find($page->location)) {
|
|
|
|
$page->error(500, "Page '".$page->get("title")."' already exists!");
|
|
|
|
}
|
2014-08-13 14:36:13 +00:00
|
|
|
}
|
2014-07-25 10:46:58 +00:00
|
|
|
}
|
|
|
|
}
|
2016-05-15 16:35:10 +00:00
|
|
|
if($this->getUserRestrictions($this->userEmail, $page->location, $page->fileName))
|
2016-04-12 13:58:56 +00:00
|
|
|
{
|
|
|
|
$page->error(500, "Page '".$page->get("title")."' is not allowed!");
|
|
|
|
}
|
2014-07-25 10:46:58 +00:00
|
|
|
return $page;
|
|
|
|
}
|
|
|
|
|
2016-02-20 17:34:06 +00:00
|
|
|
// Return raw data for new page
|
2016-05-15 16:35:10 +00:00
|
|
|
function getRawDataNew($location = "")
|
2014-05-31 21:48:59 +00:00
|
|
|
{
|
2015-04-29 07:26:48 +00:00
|
|
|
$fileName = $this->yellow->lookup->findFileFromLocation($this->yellow->page->location);
|
|
|
|
$fileName = $this->yellow->lookup->findFileNew($fileName,
|
2015-04-30 19:32:58 +00:00
|
|
|
$this->yellow->config->get("webinterfaceNewFile"), $this->yellow->config->get("configDir"),
|
|
|
|
$this->yellow->config->get("template"));
|
2016-06-02 15:31:42 +00:00
|
|
|
$rawData = $this->yellow->toolbox->readFile($fileName);
|
|
|
|
$rawData = preg_replace("/@datetime/i", date("Y-m-d H:i:s"), $rawData);
|
|
|
|
$rawData = preg_replace("/@date/i", date("Y-m-d"), $rawData);
|
|
|
|
$rawData = preg_replace("/@usershort/i", strtok($this->users->getName($this->userEmail), " "), $rawData);
|
|
|
|
$rawData = preg_replace("/@username/i", $this->users->getName($this->userEmail), $rawData);
|
|
|
|
$rawData = preg_replace("/@userlanguage/i", $this->users->getLanguage($this->userEmail), $rawData);
|
2016-05-15 16:35:10 +00:00
|
|
|
if(!empty($location))
|
|
|
|
{
|
|
|
|
$title = $this->yellow->toolbox->createTextTitle($location);
|
2016-06-02 15:31:42 +00:00
|
|
|
$rawData = $this->updateDataTitle($rawData, $title);
|
2016-05-15 16:35:10 +00:00
|
|
|
}
|
2016-06-02 15:31:42 +00:00
|
|
|
return $rawData;
|
2014-05-31 21:48:59 +00:00
|
|
|
}
|
|
|
|
|
2016-04-12 13:58:56 +00:00
|
|
|
// Return page data including login information
|
2016-02-20 17:34:06 +00:00
|
|
|
function getPageData()
|
|
|
|
{
|
|
|
|
$data = array();
|
|
|
|
if($this->isUser())
|
|
|
|
{
|
|
|
|
$data["title"] = $this->getDataTitle($this->rawDataEdit);
|
|
|
|
$data["rawDataSource"] = $this->rawDataSource;
|
|
|
|
$data["rawDataEdit"] = $this->rawDataEdit;
|
|
|
|
$data["rawDataNew"] = $this->getRawDataNew();
|
|
|
|
$data["pageFile"] = $this->yellow->page->get("pageFile");
|
|
|
|
$data["parserSafeMode"] = $this->yellow->page->parserSafeMode;
|
|
|
|
}
|
2016-05-15 16:35:10 +00:00
|
|
|
if($this->action != "none") $data = array_merge($data, $this->getRequestData());
|
|
|
|
$data["action"] = $this->action;
|
|
|
|
$data["status"] = $this->status;
|
|
|
|
$data["statusCode"] = $this->yellow->page->statusCode;
|
2016-02-20 17:34:06 +00:00
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return configuration data including user information
|
|
|
|
function getConfigData()
|
2013-04-14 22:41:04 +00:00
|
|
|
{
|
2014-08-19 21:44:22 +00:00
|
|
|
$data = $this->yellow->config->getData("", "Location");
|
|
|
|
if($this->isUser())
|
|
|
|
{
|
2016-05-15 16:35:10 +00:00
|
|
|
$data["userEmail"] = $this->userEmail;
|
|
|
|
$data["userName"] = $this->users->getName($this->userEmail);
|
|
|
|
$data["userLanguage"] = $this->users->getLanguage($this->userEmail);
|
|
|
|
$data["userStatus"] = $this->users->getStatus($this->userEmail);
|
|
|
|
$data["userHome"] = $this->users->getHome($this->userEmail);
|
|
|
|
$data["userRestrictions"] = $this->userRestrictions;
|
2014-08-19 21:44:22 +00:00
|
|
|
$data["serverScheme"] = $this->yellow->config->get("serverScheme");
|
|
|
|
$data["serverName"] = $this->yellow->config->get("serverName");
|
|
|
|
$data["serverBase"] = $this->yellow->config->get("serverBase");
|
2016-02-20 17:34:06 +00:00
|
|
|
$data["serverTime"] = $this->yellow->config->get("serverTime");
|
2016-05-15 16:35:10 +00:00
|
|
|
$data["serverLanguages"] = array();
|
|
|
|
foreach($this->yellow->text->getLanguages() as $language)
|
|
|
|
{
|
|
|
|
$data["serverLanguages"][$language] = $this->yellow->text->getTextHtml("languageDescription", $language);
|
|
|
|
}
|
2016-06-02 15:31:42 +00:00
|
|
|
$data["serverVersion"] = "Yellow ".YellowCore::Version;
|
2014-08-19 21:44:22 +00:00
|
|
|
} else {
|
2014-10-19 19:22:47 +00:00
|
|
|
$data["loginEmail"] = $this->yellow->config->get("loginEmail");
|
|
|
|
$data["loginPassword"] = $this->yellow->config->get("loginPassword");
|
2016-05-15 16:35:10 +00:00
|
|
|
$data["loginButtons"] = intval($this->users->isWebmaster());
|
2016-04-12 13:58:56 +00:00
|
|
|
}
|
2016-05-15 16:35:10 +00:00
|
|
|
if(defined("DEBUG") && DEBUG>=1) $data["debug"] = DEBUG;
|
2016-04-12 13:58:56 +00:00
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return request strings
|
|
|
|
function getRequestData()
|
|
|
|
{
|
|
|
|
$data = array();
|
|
|
|
foreach($_REQUEST as $key=>$value)
|
|
|
|
{
|
2016-05-15 16:35:10 +00:00
|
|
|
if($key=="login" || $key=="password") continue;
|
2016-04-12 13:58:56 +00:00
|
|
|
$data["request".ucfirst($key)] = trim($value);
|
2014-08-19 21:44:22 +00:00
|
|
|
}
|
|
|
|
return $data;
|
2013-04-14 22:41:04 +00:00
|
|
|
}
|
2014-05-15 11:53:54 +00:00
|
|
|
|
2016-04-12 13:58:56 +00:00
|
|
|
// Return user data
|
|
|
|
function getUserData()
|
|
|
|
{
|
|
|
|
$data = array();
|
|
|
|
foreach($this->users->users as $key=>$value)
|
|
|
|
{
|
|
|
|
$data[$key] = "$value[email] - $value[name] $value[language] $value[status] $value[home]";
|
|
|
|
}
|
|
|
|
usort($data, strnatcasecmp);
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
2016-02-20 17:34:06 +00:00
|
|
|
// Return text strings
|
|
|
|
function getTextData()
|
|
|
|
{
|
2016-05-15 16:35:10 +00:00
|
|
|
$textLanguage = array_merge($this->yellow->text->getData("language", $this->userLanguage));
|
|
|
|
$textWebinterface = array_merge($this->yellow->text->getData("webinterface", $this->userLanguage));
|
|
|
|
$textYellow = array_merge($this->yellow->text->getData("yellow", $this->userLanguage));
|
2016-02-20 17:34:06 +00:00
|
|
|
return array_merge($textLanguage, $textWebinterface, $textYellow);
|
|
|
|
}
|
|
|
|
|
2016-04-12 13:58:56 +00:00
|
|
|
// Normlise text with special characters
|
|
|
|
function normaliseText($text)
|
|
|
|
{
|
|
|
|
if($this->yellow->plugins->isExisting("emojiawesome"))
|
|
|
|
{
|
|
|
|
$text = $this->yellow->plugins->get("emojiawesome")->normaliseText($text, true, false);
|
|
|
|
}
|
|
|
|
return $text;
|
|
|
|
}
|
|
|
|
|
2016-05-15 16:35:10 +00:00
|
|
|
// Check if user is logged in
|
|
|
|
function isUser()
|
2016-04-12 13:58:56 +00:00
|
|
|
{
|
2016-05-15 16:35:10 +00:00
|
|
|
return !empty($this->userEmail);
|
2016-04-12 13:58:56 +00:00
|
|
|
}
|
2014-05-15 11:53:54 +00:00
|
|
|
|
2016-05-15 16:35:10 +00:00
|
|
|
// Check if web interface request
|
|
|
|
function isActive()
|
2014-05-15 11:53:54 +00:00
|
|
|
{
|
2016-05-15 16:35:10 +00:00
|
|
|
return $this->active;
|
2014-05-15 11:53:54 +00:00
|
|
|
}
|
2013-04-14 22:41:04 +00:00
|
|
|
}
|
2016-06-02 15:31:42 +00:00
|
|
|
|
|
|
|
// Yellow installation
|
|
|
|
class YellowInstallation
|
|
|
|
{
|
|
|
|
var $yellow; //access to API
|
|
|
|
|
|
|
|
function __construct($yellow)
|
|
|
|
{
|
|
|
|
$this->yellow = $yellow;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Process request to install
|
|
|
|
function processRequest($serverScheme, $serverName, $base, $location, $fileName)
|
|
|
|
{
|
|
|
|
$statusCode = 0;
|
|
|
|
if(!$this->yellow->isStaticFile($location, $fileName, false))
|
|
|
|
{
|
|
|
|
$fileName = $this->yellow->config->get("configDir")."page-installation.txt";
|
|
|
|
$this->yellow->pages->pages["root/"] = array();
|
|
|
|
$this->yellow->page = new YellowPage($this->yellow);
|
|
|
|
$this->yellow->page->setRequestInformation($serverScheme, $serverName, $base, $location, $fileName);
|
|
|
|
$this->yellow->page->parseData($this->getRawDataWelcome($fileName, $this->yellow->getRequestLanguage()), false, 404);
|
|
|
|
$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"]);
|
|
|
|
$status = trim($_REQUEST["status"]);
|
|
|
|
if($status == "install")
|
|
|
|
{
|
|
|
|
$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";
|
|
|
|
if($status == "error") $this->yellow->page->error(500, "Can't write file '$fileNameHome'!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if($status == "ok")
|
|
|
|
{
|
|
|
|
if(!empty($email) && !empty($password))
|
|
|
|
{
|
|
|
|
$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";
|
|
|
|
if($status == "error") $this->yellow->page->error(500, "Can't write file '$fileNameUser'!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if($status == "ok")
|
|
|
|
{
|
|
|
|
if($this->yellow->config->get("sitename") == "Yellow") $_REQUEST["sitename"] = $name;
|
|
|
|
$fileNameConfig = $this->yellow->config->get("configDir").$this->yellow->config->get("configFile");
|
|
|
|
$status = $this->yellow->config->update($fileNameConfig, $this->getConfigData()) ? "done" : "error";
|
|
|
|
if($status == "error") $this->yellow->page->error(500, "Can't write file '$fileNameConfig'!");
|
|
|
|
}
|
|
|
|
if($status == "done")
|
|
|
|
{
|
|
|
|
$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 welcome page
|
|
|
|
function getRawDataWelcome($fileName, $language)
|
|
|
|
{
|
|
|
|
$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";
|
|
|
|
$rawData .= "<form class=\"installation-form\" action=\"".$this->yellow->page->getLocation()."\" method=\"post\">\n";
|
|
|
|
$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";
|
|
|
|
if(count($this->yellow->text->getLanguages()) > 1)
|
|
|
|
{
|
|
|
|
$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";
|
|
|
|
}
|
|
|
|
$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;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return configuration data
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2013-04-14 22:41:04 +00:00
|
|
|
|
2015-10-06 12:19:11 +00:00
|
|
|
// Yellow users
|
|
|
|
class YellowUsers
|
2013-04-14 22:41:04 +00:00
|
|
|
{
|
2013-12-21 13:10:15 +00:00
|
|
|
var $yellow; //access to API
|
2013-04-14 22:41:04 +00:00
|
|
|
var $users; //registered users
|
|
|
|
|
2013-12-21 13:10:15 +00:00
|
|
|
function __construct($yellow)
|
2013-04-14 22:41:04 +00:00
|
|
|
{
|
2013-12-21 13:10:15 +00:00
|
|
|
$this->yellow = $yellow;
|
2013-04-14 22:41:04 +00:00
|
|
|
$this->users = array();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Load users from file
|
2016-02-20 17:34:06 +00:00
|
|
|
function load($fileName)
|
2013-04-14 22:41:04 +00:00
|
|
|
{
|
2016-02-20 17:34:06 +00:00
|
|
|
if(defined("DEBUG") && DEBUG>=2) echo "YellowUsers::load file:$fileName<br/>\n";
|
|
|
|
$fileData = $this->yellow->toolbox->readFile($fileName);
|
|
|
|
foreach($this->yellow->toolbox->getTextLines($fileData) as $line)
|
2013-04-14 22:41:04 +00:00
|
|
|
{
|
2016-02-20 17:34:06 +00:00
|
|
|
if(preg_match("/^\#/", $line)) continue;
|
2016-05-15 16:35:10 +00:00
|
|
|
preg_match("/^\s*(.*?)\s*:\s*(.*?),\s*(.*?),\s*(.*?),\s*(.*?),\s*(.*?)\s*$/", $line, $matches);
|
2016-02-20 17:34:06 +00:00
|
|
|
if(!empty($matches[1]) && !empty($matches[2]) && !empty($matches[3]) && !empty($matches[4]) &&
|
|
|
|
!empty($matches[5]) && !empty($matches[6]))
|
2013-04-14 22:41:04 +00:00
|
|
|
{
|
2016-02-20 17:34:06 +00:00
|
|
|
$this->set($matches[1], $matches[2], $matches[3], $matches[4], $matches[5], $matches[6]);
|
|
|
|
if(defined("DEBUG") && DEBUG>=3) echo "YellowUsers::load email:$matches[1]<br/>\n";
|
2013-04-14 22:41:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-12-21 13:10:15 +00:00
|
|
|
|
2016-06-02 15:31:42 +00:00
|
|
|
// Clean users in file
|
|
|
|
function clean($fileName)
|
|
|
|
{
|
|
|
|
$fileData = $this->yellow->toolbox->readFile($fileName);
|
|
|
|
foreach($this->yellow->toolbox->getTextLines($fileData) as $line)
|
|
|
|
{
|
|
|
|
preg_match("/^\s*(.*?)\s*:\s*(.*?),\s*(.*?),\s*(.*?),\s*(.*?),\s*(.*?)\s*$/", $line, $matches);
|
|
|
|
if(empty($matches[5]) || $matches[5]=="active" || $matches[5]=="inactive")
|
|
|
|
{
|
|
|
|
$fileDataNew .= $line;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $this->yellow->toolbox->createFile($fileName, $fileDataNew);
|
|
|
|
}
|
|
|
|
|
2016-04-12 13:58:56 +00:00
|
|
|
// Update users in file
|
|
|
|
function update($fileName, $email, $password = "", $name = "", $language = "", $status = "", $home = "")
|
|
|
|
{
|
|
|
|
if(!empty($password))
|
|
|
|
{
|
|
|
|
$algorithm = $this->yellow->config->get("webinterfaceUserHashAlgorithm");
|
|
|
|
$cost = $this->yellow->config->get("webinterfaceUserHashCost");
|
|
|
|
$hash = $this->yellow->toolbox->createHash($password, $algorithm, $cost);
|
|
|
|
if(empty($hash)) $hash = "error-hash-algorithm-$algorithm";
|
|
|
|
}
|
|
|
|
if($this->isExisting($email))
|
|
|
|
{
|
|
|
|
$email = strreplaceu(',', '-', $email);
|
|
|
|
$hash = strreplaceu(',', '-', empty($hash) ? $this->users[$email]["hash"] : $hash);
|
|
|
|
$name = strreplaceu(',', '-', empty($name) ? $this->users[$email]["name"] : $name);
|
|
|
|
$language = strreplaceu(',', '-', empty($language) ? $this->users[$email]["language"] : $language);
|
|
|
|
$status = strreplaceu(',', '-', empty($status) ? $this->users[$email]["status"] : $status);
|
|
|
|
$home = strreplaceu(',', '-', empty($home) ? $this->users[$email]["home"] : $home);
|
|
|
|
} else {
|
|
|
|
$email = strreplaceu(',', '-', empty($email) ? "none" : $email);
|
|
|
|
$hash = strreplaceu(',', '-', empty($hash) ? "none" : $hash);
|
|
|
|
$name = strreplaceu(',', '-', empty($name) ? $this->yellow->config->get("sitename") : $name);
|
|
|
|
$language = strreplaceu(',', '-', empty($language) ? $this->yellow->config->get("language") : $language);
|
|
|
|
$status = strreplaceu(',', '-', empty($status) ? $this->yellow->config->get("webinterfaceUserStatus") : $status);
|
|
|
|
$home = strreplaceu(',', '-', empty($home) ? $this->yellow->config->get("webinterfaceUserHome") : $home);
|
|
|
|
}
|
|
|
|
$this->set($email, $hash, $name, $language, $status, $home);
|
|
|
|
$fileData = $this->yellow->toolbox->readFile($fileName);
|
|
|
|
foreach($this->yellow->toolbox->getTextLines($fileData) as $line)
|
|
|
|
{
|
2016-05-15 16:35:10 +00:00
|
|
|
preg_match("/^\s*(.*?)\s*:\s*(.*?),\s*(.*?),\s*(.*?),\s*(.*?),\s*(.*?)\s*$/", $line, $matches);
|
2016-04-12 13:58:56 +00:00
|
|
|
if(!empty($matches[1]) && $matches[1]==$email)
|
|
|
|
{
|
|
|
|
$fileDataNew .= "$email: $hash,$name,$language,$status,$home\n";
|
|
|
|
$found = true;
|
|
|
|
} else {
|
|
|
|
$fileDataNew .= $line;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(!$found) $fileDataNew .= "$email: $hash,$name,$language,$status,$home\n";
|
|
|
|
return $this->yellow->toolbox->createFile($fileName, $fileDataNew);
|
|
|
|
}
|
|
|
|
|
2014-04-07 15:14:31 +00:00
|
|
|
// Set user data
|
2015-10-06 12:19:11 +00:00
|
|
|
function set($email, $hash, $name, $language, $status, $home)
|
2014-04-07 15:14:31 +00:00
|
|
|
{
|
|
|
|
$this->users[$email] = array();
|
|
|
|
$this->users[$email]["email"] = $email;
|
2014-05-04 12:57:52 +00:00
|
|
|
$this->users[$email]["hash"] = $hash;
|
2014-04-07 15:14:31 +00:00
|
|
|
$this->users[$email]["name"] = $name;
|
|
|
|
$this->users[$email]["language"] = $language;
|
2015-10-06 12:19:11 +00:00
|
|
|
$this->users[$email]["status"] = $status;
|
2014-04-07 15:14:31 +00:00
|
|
|
$this->users[$email]["home"] = $home;
|
|
|
|
}
|
|
|
|
|
2013-04-14 22:41:04 +00:00
|
|
|
// Check user login
|
|
|
|
function checkUser($email, $password)
|
|
|
|
{
|
2014-05-04 12:57:52 +00:00
|
|
|
$algorithm = $this->yellow->config->get("webinterfaceUserHashAlgorithm");
|
2015-10-06 12:19:11 +00:00
|
|
|
return $this->isExisting($email) && $this->users[$email]["status"]=="active" &&
|
|
|
|
$this->yellow->toolbox->verifyHash($password, $algorithm, $this->users[$email]["hash"]);
|
2013-04-14 22:41:04 +00:00
|
|
|
}
|
|
|
|
|
2016-04-12 13:58:56 +00:00
|
|
|
// Check user login from browser cookie
|
|
|
|
function checkCookie($email, $session)
|
|
|
|
{
|
|
|
|
return $this->isExisting($email) && $this->users[$email]["status"]=="active" &&
|
|
|
|
$this->yellow->toolbox->verifyHash($this->users[$email]["hash"], "sha256", $session);
|
|
|
|
}
|
|
|
|
|
2013-04-14 22:41:04 +00:00
|
|
|
// Create browser cookie
|
|
|
|
function createCookie($cookieName, $email)
|
|
|
|
{
|
|
|
|
if($this->isExisting($email))
|
|
|
|
{
|
2015-07-06 19:31:51 +00:00
|
|
|
$serverScheme = $this->yellow->config->get("webinterfaceServerScheme");
|
2014-05-04 12:57:52 +00:00
|
|
|
$location = $this->yellow->config->get("serverBase").$this->yellow->config->get("webinterfaceLocation");
|
|
|
|
$session = $this->yellow->toolbox->createHash($this->users[$email]["hash"], "sha256");
|
|
|
|
if(empty($session)) $session = "error-hash-algorithm-sha256";
|
2016-03-13 14:29:32 +00:00
|
|
|
setcookie($cookieName, "$email,$session", time()+60*60*24*365, $location, "", $serverScheme=="https");
|
2013-04-14 22:41:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Destroy browser cookie
|
|
|
|
function destroyCookie($cookieName)
|
|
|
|
{
|
2015-07-06 19:31:51 +00:00
|
|
|
$serverScheme = $this->yellow->config->get("webinterfaceServerScheme");
|
2014-05-04 12:57:52 +00:00
|
|
|
$location = $this->yellow->config->get("serverBase").$this->yellow->config->get("webinterfaceLocation");
|
2016-02-16 22:10:16 +00:00
|
|
|
setcookie($cookieName, "", time()-3600, $location, "", $serverScheme=="https");
|
2013-04-14 22:41:04 +00:00
|
|
|
}
|
|
|
|
|
2016-04-12 13:58:56 +00:00
|
|
|
// Check user request
|
2016-05-15 16:35:10 +00:00
|
|
|
function checkUserRequest($email, $action, $expire, $id)
|
2013-04-14 22:41:04 +00:00
|
|
|
{
|
2016-04-12 13:58:56 +00:00
|
|
|
switch($action)
|
|
|
|
{
|
2016-05-15 16:35:10 +00:00
|
|
|
case "confirm": $status = "unconfirmed"; break;
|
|
|
|
case "approve": $status = "unapproved"; break;
|
|
|
|
default: $status = "active"; break;
|
2016-04-12 13:58:56 +00:00
|
|
|
}
|
|
|
|
return $this->isExisting($email) && $this->users[$email]["status"]==$status && $expire>time() &&
|
|
|
|
$this->yellow->toolbox->verifyHash($this->users[$email]["hash"].$action.$expire, "sha256", $id);
|
2013-04-14 22:41:04 +00:00
|
|
|
}
|
|
|
|
|
2016-04-12 13:58:56 +00:00
|
|
|
// Create user request ID
|
2016-05-15 16:35:10 +00:00
|
|
|
function createUserRequestId($email, $action, $expire)
|
2013-04-14 22:41:04 +00:00
|
|
|
{
|
2016-04-12 13:58:56 +00:00
|
|
|
return $this->yellow->toolbox->createHash($this->users[$email]["hash"].$action.$expire, "sha256");
|
2013-04-14 22:41:04 +00:00
|
|
|
}
|
|
|
|
|
2016-04-12 13:58:56 +00:00
|
|
|
// Return user hash
|
|
|
|
function getHash($email = "")
|
|
|
|
{
|
|
|
|
return $this->isExisting($email) ? $this->users[$email]["hash"] : "";
|
|
|
|
}
|
|
|
|
|
2013-04-14 22:41:04 +00:00
|
|
|
// Return user name
|
2014-04-07 15:14:31 +00:00
|
|
|
function getName($email = "")
|
2013-04-14 22:41:04 +00:00
|
|
|
{
|
|
|
|
return $this->isExisting($email) ? $this->users[$email]["name"] : "";
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return user language
|
2014-04-07 15:14:31 +00:00
|
|
|
function getLanguage($email = "")
|
2013-04-14 22:41:04 +00:00
|
|
|
{
|
|
|
|
return $this->isExisting($email) ? $this->users[$email]["language"] : "";
|
|
|
|
}
|
2015-10-06 12:19:11 +00:00
|
|
|
|
|
|
|
// Return user status
|
|
|
|
function getStatus($email = "")
|
|
|
|
{
|
|
|
|
return $this->isExisting($email) ? $this->users[$email]["status"] : "";
|
|
|
|
}
|
|
|
|
|
2014-04-07 15:14:31 +00:00
|
|
|
// Return user home
|
|
|
|
function getHome($email = "")
|
|
|
|
{
|
|
|
|
return $this->isExisting($email) ? $this->users[$email]["home"] : "";
|
|
|
|
}
|
2013-04-14 22:41:04 +00:00
|
|
|
|
2015-05-05 16:11:43 +00:00
|
|
|
// Return number of users
|
|
|
|
function getNumber()
|
|
|
|
{
|
|
|
|
return count($this->users);
|
|
|
|
}
|
2016-05-15 16:35:10 +00:00
|
|
|
|
|
|
|
// Check if web master exists
|
|
|
|
function isWebmaster()
|
|
|
|
{
|
|
|
|
return strposu($this->yellow->config->get("email"), '@') !== false;
|
|
|
|
}
|
2015-05-05 16:11:43 +00:00
|
|
|
|
2013-04-14 22:41:04 +00:00
|
|
|
// Check if user exists
|
|
|
|
function isExisting($email)
|
|
|
|
{
|
|
|
|
return !is_null($this->users[$email]);
|
|
|
|
}
|
|
|
|
}
|
2014-11-13 13:49:21 +00:00
|
|
|
|
2015-10-06 12:19:11 +00:00
|
|
|
// Yellow merge
|
|
|
|
class YellowMerge
|
2014-11-13 13:49:21 +00:00
|
|
|
{
|
|
|
|
var $yellow; //access to API
|
|
|
|
const Add = '+'; //merge types
|
|
|
|
const Modify = '*';
|
|
|
|
const Remove = '-';
|
|
|
|
const Same = ' ';
|
|
|
|
|
|
|
|
function __construct($yellow)
|
|
|
|
{
|
|
|
|
$this->yellow = $yellow;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Merge text, NULL if not possible
|
|
|
|
function merge($textSource, $textMine, $textYours, $showDiff = false)
|
|
|
|
{
|
|
|
|
if($textMine != $textYours)
|
|
|
|
{
|
|
|
|
$diffMine = $this->buildDiff($textSource, $textMine);
|
|
|
|
$diffYours = $this->buildDiff($textSource, $textYours);
|
|
|
|
$diff = $this->mergeDiff($diffMine, $diffYours);
|
|
|
|
$output = $this->getOutput($diff, $showDiff);
|
|
|
|
} else {
|
|
|
|
$output = $textMine;
|
|
|
|
}
|
|
|
|
return $output;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Build differences to common source
|
|
|
|
function buildDiff($textSource, $textOther)
|
|
|
|
{
|
|
|
|
$diff = array();
|
|
|
|
$lastRemove = -1;
|
|
|
|
$textStart = 0;
|
|
|
|
$textSource = $this->yellow->toolbox->getTextLines($textSource);
|
|
|
|
$textOther = $this->yellow->toolbox->getTextLines($textOther);
|
|
|
|
$sourceEnd = $sourceSize = count($textSource);
|
|
|
|
$otherEnd = $otherSize = count($textOther);
|
|
|
|
while($textStart<$sourceEnd && $textStart<$otherEnd && $textSource[$textStart]==$textOther[$textStart]) ++$textStart;
|
|
|
|
while($textStart<$sourceEnd && $textStart<$otherEnd && $textSource[$sourceEnd-1]==$textOther[$otherEnd-1])
|
|
|
|
{
|
|
|
|
--$sourceEnd; --$otherEnd;
|
|
|
|
}
|
2015-10-06 12:19:11 +00:00
|
|
|
for($pos=0; $pos<$textStart; ++$pos) array_push($diff, array(YellowMerge::Same, $textSource[$pos], false));
|
2014-11-13 13:49:21 +00:00
|
|
|
$lcs = $this->buildDiffLCS($textSource, $textOther, $textStart, $sourceEnd-$textStart, $otherEnd-$textStart);
|
|
|
|
for($x=0,$y=0,$xEnd=$otherEnd-$textStart,$yEnd=$sourceEnd-$textStart; $x<$xEnd || $y<$yEnd;)
|
|
|
|
{
|
|
|
|
$max = $lcs[$y][$x];
|
|
|
|
if($y<$yEnd && $lcs[$y+1][$x]==$max)
|
|
|
|
{
|
2015-10-06 12:19:11 +00:00
|
|
|
array_push($diff, array(YellowMerge::Remove, $textSource[$textStart+$y], false));
|
2014-11-13 13:49:21 +00:00
|
|
|
if($lastRemove == -1) $lastRemove = count($diff)-1;
|
|
|
|
++$y;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if($x<$xEnd && $lcs[$y][$x+1]==$max)
|
|
|
|
{
|
2015-10-06 12:19:11 +00:00
|
|
|
if($lastRemove==-1 || $diff[$lastRemove][0]!=YellowMerge::Remove)
|
2014-11-13 13:49:21 +00:00
|
|
|
{
|
2015-10-06 12:19:11 +00:00
|
|
|
array_push($diff, array(YellowMerge::Add, $textOther[$textStart+$x], false));
|
2014-11-13 13:49:21 +00:00
|
|
|
$lastRemove = -1;
|
|
|
|
} else {
|
2015-10-06 12:19:11 +00:00
|
|
|
$diff[$lastRemove] = array(YellowMerge::Modify, $textOther[$textStart+$x], false);
|
2014-11-13 13:49:21 +00:00
|
|
|
++$lastRemove; if(count($diff)==$lastRemove) $lastRemove = -1;
|
|
|
|
}
|
|
|
|
++$x;
|
|
|
|
continue;
|
|
|
|
}
|
2015-10-06 12:19:11 +00:00
|
|
|
array_push($diff, array(YellowMerge::Same, $textSource[$textStart+$y], false));
|
2014-11-13 13:49:21 +00:00
|
|
|
$lastRemove = -1;
|
|
|
|
++$x;
|
|
|
|
++$y;
|
|
|
|
}
|
2015-10-06 12:19:11 +00:00
|
|
|
for($pos=$sourceEnd;$pos<$sourceSize; ++$pos) array_push($diff, array(YellowMerge::Same, $textSource[$pos], false));
|
2014-11-13 13:49:21 +00:00
|
|
|
return $diff;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Build longest common subsequence
|
|
|
|
function buildDiffLCS($textSource, $textOther, $textStart, $yEnd, $xEnd)
|
|
|
|
{
|
|
|
|
$lcs = array_fill(0, $yEnd+1, array_fill(0, $xEnd+1, 0));
|
|
|
|
for($y=$yEnd-1; $y>=0; --$y)
|
|
|
|
{
|
|
|
|
for($x=$xEnd-1; $x>=0; --$x)
|
|
|
|
{
|
|
|
|
if($textSource[$textStart+$y] == $textOther[$textStart+$x])
|
|
|
|
{
|
|
|
|
$lcs[$y][$x] = $lcs[$y+1][$x+1]+1;
|
|
|
|
} else {
|
|
|
|
$lcs[$y][$x] = max($lcs[$y][$x+1], $lcs[$y+1][$x]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $lcs;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Merge differences
|
|
|
|
function mergeDiff($diffMine, $diffYours)
|
|
|
|
{
|
|
|
|
$diff = array();
|
|
|
|
$posMine = $posYours = 0;
|
|
|
|
while($posMine<count($diffMine) && $posYours<count($diffYours))
|
|
|
|
{
|
|
|
|
$typeMine = $diffMine[$posMine][0];
|
|
|
|
$typeYours = $diffYours[$posYours][0];
|
2015-10-06 12:19:11 +00:00
|
|
|
if($typeMine==YellowMerge::Same)
|
2014-11-13 13:49:21 +00:00
|
|
|
{
|
|
|
|
array_push($diff, $diffYours[$posYours]);
|
2015-10-06 12:19:11 +00:00
|
|
|
} else if($typeYours==YellowMerge::Same) {
|
2014-11-13 13:49:21 +00:00
|
|
|
array_push($diff, $diffMine[$posMine]);
|
2015-10-06 12:19:11 +00:00
|
|
|
} else if($typeMine==YellowMerge::Add && $typeYours==YellowMerge::Add) {
|
2014-11-13 13:49:21 +00:00
|
|
|
$this->mergeConflict($diff, $diffMine[$posMine], $diffYours[$posYours], false);
|
2015-10-06 12:19:11 +00:00
|
|
|
} else if($typeMine==YellowMerge::Modify && $typeYours==YellowMerge::Modify) {
|
2014-11-13 13:49:21 +00:00
|
|
|
$this->mergeConflict($diff, $diffMine[$posMine], $diffYours[$posYours], false);
|
2015-10-06 12:19:11 +00:00
|
|
|
} else if($typeMine==YellowMerge::Remove && $typeYours==YellowMerge::Remove) {
|
2014-11-13 13:49:21 +00:00
|
|
|
array_push($diff, $diffMine[$posMine]);
|
2015-10-06 12:19:11 +00:00
|
|
|
} else if($typeMine==YellowMerge::Add) {
|
2014-11-13 13:49:21 +00:00
|
|
|
array_push($diff, $diffMine[$posMine]);
|
2015-10-06 12:19:11 +00:00
|
|
|
} else if($typeYours==YellowMerge::Add) {
|
2014-11-13 13:49:21 +00:00
|
|
|
array_push($diff, $diffYours[$posYours]);
|
|
|
|
} else {
|
|
|
|
$this->mergeConflict($diff, $diffMine[$posMine], $diffYours[$posYours], true);
|
|
|
|
}
|
2015-10-06 12:19:11 +00:00
|
|
|
if(defined("DEBUG") && DEBUG>=2) echo "YellowMerge::mergeDiff $typeMine $typeYours pos:$posMine\t$posYours<br/>\n";
|
|
|
|
if($typeMine==YellowMerge::Add || $typeYours==YellowMerge::Add)
|
2014-11-13 13:49:21 +00:00
|
|
|
{
|
2015-10-06 12:19:11 +00:00
|
|
|
if($typeMine==YellowMerge::Add) ++$posMine;
|
|
|
|
if($typeYours==YellowMerge::Add) ++$posYours;
|
2014-11-13 13:49:21 +00:00
|
|
|
} else {
|
|
|
|
++$posMine;
|
|
|
|
++$posYours;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for(;$posMine<count($diffMine); ++$posMine)
|
|
|
|
{
|
|
|
|
array_push($diff, $diffMine[$posMine]);
|
|
|
|
$typeMine = $diffMine[$posMine][0]; $typeYours = ' ';
|
2015-10-06 12:19:11 +00:00
|
|
|
if(defined("DEBUG") && DEBUG>=2) echo "YellowMerge::mergeDiff $typeMine $typeYours pos:$posMine\t$posYours<br/>\n";
|
2014-11-13 13:49:21 +00:00
|
|
|
}
|
|
|
|
for(;$posYours<count($diffYours); ++$posYours)
|
|
|
|
{
|
|
|
|
array_push($diff, $diffYours[$posYours]);
|
|
|
|
$typeYours = $diffYours[$posYours][0]; $typeMine = ' ';
|
2015-10-06 12:19:11 +00:00
|
|
|
if(defined("DEBUG") && DEBUG>=2) echo "YellowMerge::mergeDiff $typeMine $typeYours pos:$posMine\t$posYours<br/>\n";
|
2014-11-13 13:49:21 +00:00
|
|
|
}
|
|
|
|
return $diff;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Merge potential conflict
|
|
|
|
function mergeConflict(&$diff, $diffMine, $diffYours, $conflict)
|
|
|
|
{
|
|
|
|
if(!$conflict && $diffMine[1]==$diffYours[1])
|
|
|
|
{
|
|
|
|
array_push($diff, $diffMine);
|
|
|
|
} else {
|
|
|
|
array_push($diff, array($diffMine[0], $diffMine[1], true));
|
|
|
|
array_push($diff, array($diffYours[0], $diffYours[1], true));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return merged text, NULL if not possible
|
|
|
|
function getOutput($diff, $showDiff = false)
|
|
|
|
{
|
|
|
|
$output = "";
|
|
|
|
if(!$showDiff)
|
|
|
|
{
|
|
|
|
for($i=0; $i<count($diff); ++$i)
|
|
|
|
{
|
2015-10-06 12:19:11 +00:00
|
|
|
if($diff[$i][0] != YellowMerge::Remove) $output .= $diff[$i][1];
|
2014-11-13 13:49:21 +00:00
|
|
|
$conflict |= $diff[$i][2];
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for($i=0; $i<count($diff); ++$i)
|
|
|
|
{
|
|
|
|
$output .= $diff[$i][2] ? "! " : $diff[$i][0].' ';
|
|
|
|
$output .= $diff[$i][1];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return !$conflict ? $output : NULL;
|
|
|
|
}
|
|
|
|
}
|
2013-04-14 22:41:04 +00:00
|
|
|
|
2014-07-10 08:42:32 +00:00
|
|
|
$yellow->plugins->register("webinterface", "YellowWebinterface", YellowWebinterface::Version);
|
2013-04-14 22:41:04 +00:00
|
|
|
?>
|