major refactoring of almost all files
This commit is contained in:
@@ -1,91 +1,90 @@
|
||||
<?php
|
||||
namespace Froxlor\Config;
|
||||
|
||||
/**
|
||||
* This file is part of the Froxlor project.
|
||||
* Copyright (c) 2010 the Froxlor Team (see authors).
|
||||
*
|
||||
* For the full copyright and license information, please view the COPYING
|
||||
* file that was distributed with this source code. You can also view the
|
||||
* COPYING file online at http://files.froxlor.org/misc/COPYING.txt
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* @copyright (c) the authors
|
||||
* @author Florian Aders <eleras@froxlor.org>
|
||||
* @author Froxlor team <team@froxlor.org> (2010-)
|
||||
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
|
||||
* @package Classes
|
||||
*
|
||||
* @since 0.9.34
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, you can also view it online at
|
||||
* https://files.froxlor.org/misc/COPYING.txt
|
||||
*
|
||||
* @copyright the authors
|
||||
* @author Froxlor team <team@froxlor.org>
|
||||
* @license https://files.froxlor.org/misc/COPYING.txt GPLv2
|
||||
*/
|
||||
|
||||
namespace Froxlor\Config;
|
||||
|
||||
use Exception;
|
||||
use Froxlor\Froxlor;
|
||||
use Froxlor\Settings;
|
||||
use SimpleXMLElement;
|
||||
|
||||
/**
|
||||
* Class ConfigDaemon
|
||||
*
|
||||
* Parses a distributions XML - file and gives access to the configuration
|
||||
* Not to be used directly
|
||||
*
|
||||
* @copyright (c) the authors
|
||||
* @author Florian Aders <eleras@froxlor.org>
|
||||
* @author Froxlor team <team@froxlor.org> (2010-)
|
||||
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
|
||||
* @package Classes
|
||||
*/
|
||||
class ConfigDaemon
|
||||
{
|
||||
|
||||
/**
|
||||
* Holding the commands for this daemon
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $orders = array();
|
||||
|
||||
/**
|
||||
* Store the parsed SimpleXMLElement for usage
|
||||
*
|
||||
* @var \SimpleXMLElement
|
||||
*/
|
||||
private $fullxml;
|
||||
|
||||
/**
|
||||
* Memorize if we already parsed the XML
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
private $isparsed = false;
|
||||
|
||||
/**
|
||||
* Sub - area of the full - XML only holding the daemon - data we are interested in
|
||||
*
|
||||
* @var \SimpleXMLElement
|
||||
*/
|
||||
private $daemon;
|
||||
|
||||
/**
|
||||
* xpath leading to this daemon in the full XML
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $xpath;
|
||||
|
||||
/**
|
||||
* cache of sql-data if used
|
||||
*/
|
||||
private $sqldata_cache = null;
|
||||
|
||||
/**
|
||||
* Human - readable title of this service
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $title;
|
||||
|
||||
/**
|
||||
* Whether this is the default daemon of the service-category
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
public $default;
|
||||
/**
|
||||
* Holding the commands for this daemon
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $orders = [];
|
||||
/**
|
||||
* Store the parsed SimpleXMLElement for usage
|
||||
*
|
||||
* @var SimpleXMLElement
|
||||
*/
|
||||
private $fullxml;
|
||||
/**
|
||||
* Memorize if we already parsed the XML
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
private $isparsed = false;
|
||||
/**
|
||||
* Sub - area of the full - XML only holding the daemon - data we are interested in
|
||||
*
|
||||
* @var SimpleXMLElement
|
||||
*/
|
||||
private $daemon;
|
||||
/**
|
||||
* xpath leading to this daemon in the full XML
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $xpath;
|
||||
/**
|
||||
* cache of sql-data if used
|
||||
*/
|
||||
private $sqldata_cache = null;
|
||||
|
||||
public function __construct($xml, $xpath)
|
||||
{
|
||||
@@ -94,13 +93,76 @@ class ConfigDaemon
|
||||
$this->daemon = $this->fullxml->xpath($this->xpath);
|
||||
$attributes = $this->daemon[0]->attributes();
|
||||
if ($attributes['title'] != '') {
|
||||
$this->title = $this->parseContent((string) $attributes['title']);
|
||||
$this->title = $this->parseContent((string)$attributes['title']);
|
||||
}
|
||||
if (isset($attributes['default'])) {
|
||||
$this->default = ($attributes['default'] == true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace placeholders with content
|
||||
*
|
||||
* @param string $content
|
||||
* @return string $content w/o placeholder
|
||||
*/
|
||||
private function parseContent($content)
|
||||
{
|
||||
$content = preg_replace_callback('/\{\{(.*)\}\}/Ui', function ($matches) {
|
||||
$match = null;
|
||||
if (preg_match('/^settings\.(.*)$/', $matches[1], $match)) {
|
||||
return Settings::Get($match[1]);
|
||||
} elseif (preg_match('/^lng\.(.*)(?:\.(.*)(?:\.(.*)))$/U', $matches[1], $match)) {
|
||||
global $lng;
|
||||
if (isset($match[1]) && $match[1] != '' && isset($match[2]) && $match[2] != '' && isset($match[3]) && $match[3] != '') {
|
||||
return $lng[$match[1]][$match[2]][$match[3]];
|
||||
} elseif (isset($match[1]) && $match[1] != '' && isset($match[2]) && $match[2] != '') {
|
||||
return $lng[$match[1]][$match[2]];
|
||||
} elseif (isset($match[1]) && $match[1] != '') {
|
||||
return $lng[$match[1]];
|
||||
}
|
||||
return '';
|
||||
} elseif (preg_match('/^const\.(.*)$/', $matches[1], $match)) {
|
||||
return $this->returnDynamic($match[1]);
|
||||
} elseif (preg_match('/^sql\.(.*)$/', $matches[1], $match)) {
|
||||
if (is_null($this->sqldata_cache)) {
|
||||
// read in sql-data (if exists)
|
||||
if (file_exists(Froxlor::getInstallDir() . "/lib/userdata.inc.php")) {
|
||||
require Froxlor::getInstallDir() . "/lib/userdata.inc.php";
|
||||
unset($sql_root);
|
||||
$this->sqldata_cache = $sql;
|
||||
}
|
||||
}
|
||||
return isset($this->sqldata_cache[$match[1]]) ? $this->sqldata_cache[$match[1]] : '';
|
||||
}
|
||||
}, $content);
|
||||
return $content;
|
||||
}
|
||||
|
||||
private function returnDynamic($key = null)
|
||||
{
|
||||
$dynamics = [
|
||||
'install_dir' => Froxlor::getInstallDir()
|
||||
];
|
||||
return $dynamics[$key] ?? '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get config for this daemon
|
||||
*
|
||||
* The returned array will be an array of array, each sub-array looking like this:
|
||||
* array('type' => 'install|file|command', 'content' => '<TEXT>')
|
||||
* If the type is "file", an additional "name" - element will be added to the array
|
||||
* To configure a daemon, the steps in the array must be followed in order
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getConfig()
|
||||
{
|
||||
$this->parse();
|
||||
return $this->orders;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the XML and populate $this->orders
|
||||
*
|
||||
@@ -113,10 +175,10 @@ class ConfigDaemon
|
||||
return true;
|
||||
}
|
||||
|
||||
$preparsed = array();
|
||||
$preparsed = [];
|
||||
// First: let's push everything into an array and expand all includes
|
||||
foreach ($this->daemon[0]->children() as $order) {
|
||||
switch ((string) $order->getName()) {
|
||||
switch ((string)$order->getName()) {
|
||||
case "install":
|
||||
case "file":
|
||||
case "command":
|
||||
@@ -125,10 +187,10 @@ class ConfigDaemon
|
||||
break;
|
||||
case "include":
|
||||
// Includes, get the part we want via xpath
|
||||
$includes = $this->fullxml->xpath((string) $order);
|
||||
$includes = $this->fullxml->xpath((string)$order);
|
||||
foreach ($includes[0] as $include) {
|
||||
// The "include" is also a child, so just skip it, would make a mess later
|
||||
if ((string) $include->getName() == 'include') {
|
||||
if ((string)$include->getName() == 'include') {
|
||||
continue;
|
||||
}
|
||||
$preparsed[] = $include;
|
||||
@@ -141,7 +203,7 @@ class ConfigDaemon
|
||||
// Hold the results
|
||||
$visibility = 1;
|
||||
foreach ($order->children() as $child) {
|
||||
switch ((string) $child->getName()) {
|
||||
switch ((string)$child->getName()) {
|
||||
case "visibility":
|
||||
$visibility += $this->checkVisibility($child);
|
||||
break;
|
||||
@@ -154,10 +216,10 @@ class ConfigDaemon
|
||||
break;
|
||||
case "include":
|
||||
// Includes, get the part we want via xpath
|
||||
$includes = $this->fullxml->xpath((string) $child);
|
||||
$includes = $this->fullxml->xpath((string)$child);
|
||||
foreach ($includes[0] as $include) {
|
||||
// The "include" is also a child, so just skip it, would make a mess later
|
||||
if ((string) $include->getName() == 'include') {
|
||||
if ((string)$include->getName() == 'include') {
|
||||
continue;
|
||||
}
|
||||
$preparsed[] = $include;
|
||||
@@ -189,37 +251,108 @@ class ConfigDaemon
|
||||
}
|
||||
|
||||
/**
|
||||
* Get config for this daemon
|
||||
* Check if visibility should be changed
|
||||
*
|
||||
* The returned array will be an array of array, each sub-array looking like this:
|
||||
* array('type' => 'install|file|command', 'content' => '<TEXT>')
|
||||
* If the type is "file", an additional "name" - element will be added to the array
|
||||
* To configure a daemon, the steps in the array must be followed in order
|
||||
*
|
||||
* @return array
|
||||
* @param SimpleXMLElement $order
|
||||
* @return int 0|-1
|
||||
*/
|
||||
public function getConfig()
|
||||
private function checkVisibility($order)
|
||||
{
|
||||
$this->parse();
|
||||
return $this->orders;
|
||||
$attributes = [];
|
||||
foreach ($order->attributes() as $key => $value) {
|
||||
$attributes[(string)$key] = $this->parseContent(trim((string)$value));
|
||||
}
|
||||
|
||||
$order = $this->parseContent(trim((string)$order));
|
||||
if (!array_key_exists('mode', $attributes)) {
|
||||
throw new Exception('"<visibility>' . $order . '</visibility>" is missing mode');
|
||||
}
|
||||
|
||||
$return = 0;
|
||||
switch ($attributes['mode']) {
|
||||
case "isfile":
|
||||
if (!is_file($order)) {
|
||||
$return = -1;
|
||||
}
|
||||
break;
|
||||
case "notisfile":
|
||||
if (is_file($order)) {
|
||||
$return = -1;
|
||||
}
|
||||
break;
|
||||
case "isdir":
|
||||
if (!is_dir($order)) {
|
||||
$return = -1;
|
||||
}
|
||||
break;
|
||||
case "notisdir":
|
||||
if (is_dir($order)) {
|
||||
$return = -1;
|
||||
}
|
||||
break;
|
||||
case "false":
|
||||
if ($order == true) {
|
||||
$return = -1;
|
||||
}
|
||||
break;
|
||||
case "true":
|
||||
if ($order == false) {
|
||||
$return = -1;
|
||||
}
|
||||
break;
|
||||
case "notempty":
|
||||
if ($order == "") {
|
||||
$return = -1;
|
||||
}
|
||||
break;
|
||||
case "userexists":
|
||||
if (posix_getpwuid($order) === false) {
|
||||
$return = -1;
|
||||
}
|
||||
break;
|
||||
case "groupexists":
|
||||
if (posix_getgrgid($order) === false) {
|
||||
$return = -1;
|
||||
}
|
||||
break;
|
||||
case "usernotexists":
|
||||
if (is_array(posix_getpwuid($order))) {
|
||||
$return = -1;
|
||||
}
|
||||
break;
|
||||
case "groupnotexists":
|
||||
if (is_array(posix_getgrgid($order))) {
|
||||
$return = -1;
|
||||
}
|
||||
break;
|
||||
case "usernamenotexists":
|
||||
if (is_array(posix_getpwnam($order))) {
|
||||
$return = -1;
|
||||
}
|
||||
break;
|
||||
case "equals":
|
||||
$return = (isset($attributes['value']) && $attributes['value'] == $order ? 0 : -1);
|
||||
break;
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a single order and return it in a format for easier usage
|
||||
*
|
||||
* @param
|
||||
* SimpleXMLElement object holding a single order from the distribution - XML
|
||||
* SimpleXMLElement object holding a single order from the distribution - XML
|
||||
* @return array|string
|
||||
*/
|
||||
private function parseOrder($order)
|
||||
{
|
||||
$attributes = array();
|
||||
$attributes = [];
|
||||
foreach ($order->attributes() as $key => $value) {
|
||||
$attributes[(string) $key] = (string) $value;
|
||||
$attributes[(string)$key] = (string)$value;
|
||||
}
|
||||
|
||||
$parsedorder = '';
|
||||
switch ((string) $order->getName()) {
|
||||
switch ((string)$order->getName()) {
|
||||
case "file":
|
||||
$parsedorder = $this->parseFile($order, $attributes);
|
||||
break;
|
||||
@@ -230,99 +363,17 @@ class ConfigDaemon
|
||||
$parsedorder = $this->parseInstall($order, $attributes);
|
||||
break;
|
||||
default:
|
||||
throw new \Exception('Invalid order: ' . (string) $order->getName());
|
||||
throw new Exception('Invalid order: ' . (string)$order->getName());
|
||||
}
|
||||
|
||||
return $parsedorder;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a install - order and return it in a format for easier usage
|
||||
*
|
||||
* @param
|
||||
* SimpleXMLElement object holding a single install from the distribution - XML
|
||||
* @return array|string
|
||||
*/
|
||||
private function parseInstall($order, $attributes)
|
||||
{
|
||||
// No sub - elements, so the content can be returned directly
|
||||
if ($order->count() == 0) {
|
||||
return array(
|
||||
'type' => 'install',
|
||||
'content' => $this->parseContent(trim((string) $order))
|
||||
);
|
||||
}
|
||||
|
||||
// Hold the results
|
||||
$visibility = 1;
|
||||
$content = '';
|
||||
foreach ($order->children() as $child) {
|
||||
switch ((string) $child->getName()) {
|
||||
case "visibility":
|
||||
$visibility += $this->checkVisibility($child);
|
||||
break;
|
||||
case "content":
|
||||
$content = trim((string) $child);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ($visibility > 0) {
|
||||
return array(
|
||||
'type' => 'install',
|
||||
'content' => $this->parseContent($content)
|
||||
);
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a command - order and return it in a format for easier usage
|
||||
*
|
||||
* @param
|
||||
* SimpleXMLElement object holding a single command from the distribution - XML
|
||||
* @return array|string
|
||||
*/
|
||||
private function parseCommand($order, $attributes)
|
||||
{
|
||||
// No sub - elements, so the content can be returned directly
|
||||
if ($order->count() == 0) {
|
||||
return array(
|
||||
'type' => 'command',
|
||||
'content' => $this->parseContent(trim((string) $order))
|
||||
);
|
||||
}
|
||||
|
||||
// Hold the results
|
||||
$visibility = 1;
|
||||
$content = '';
|
||||
foreach ($order->children() as $child) {
|
||||
switch ((string) $child->getName()) {
|
||||
case "visibility":
|
||||
$visibility += $this->checkVisibility($child);
|
||||
break;
|
||||
case "content":
|
||||
$content = trim((string) $child);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ($visibility > 0) {
|
||||
return array(
|
||||
'type' => 'command',
|
||||
'content' => $this->parseContent($content)
|
||||
);
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a file - order and return it in a format for easier usage
|
||||
*
|
||||
* @param
|
||||
* SimpleXMLElement object holding a single file from the distribution - XML
|
||||
* SimpleXMLElement object holding a single file from the distribution - XML
|
||||
* @return array|string
|
||||
*/
|
||||
private function parseFile($order, $attributes)
|
||||
@@ -330,22 +381,22 @@ class ConfigDaemon
|
||||
$visibility = 1;
|
||||
// No sub - elements, so the content can be returned directly
|
||||
if ($order->count() == 0) {
|
||||
$content = (string) $order;
|
||||
$content = (string)$order;
|
||||
} else {
|
||||
// Hold the results
|
||||
foreach ($order->children() as $child) {
|
||||
switch ((string) $child->getName()) {
|
||||
switch ((string)$child->getName()) {
|
||||
case "visibility":
|
||||
$visibility += $this->checkVisibility($child);
|
||||
break;
|
||||
case "content":
|
||||
$content = (string) $child;
|
||||
$content = (string)$child;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$return = array();
|
||||
$return = [];
|
||||
// Check if the original file should be backupped
|
||||
// @TODO: Maybe have a backup - location somewhere central?
|
||||
// @TODO: Use IO - class
|
||||
@@ -355,54 +406,54 @@ class ConfigDaemon
|
||||
} else {
|
||||
$cmd = 'mv';
|
||||
}
|
||||
$return[] = array(
|
||||
$return[] = [
|
||||
'type' => 'command',
|
||||
'content' => $cmd . ' "' . $this->parseContent($attributes['name']) . '" "' . $this->parseContent($attributes['name']) . '.frx.bak"',
|
||||
'execute' => "pre"
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
// Now the content of the file can be written
|
||||
if (isset($attributes['mode'])) {
|
||||
$return[] = array(
|
||||
$return[] = [
|
||||
'type' => 'file',
|
||||
'content' => $this->parseContent($content),
|
||||
'name' => $this->parseContent($attributes['name']),
|
||||
'mode' => $this->parseContent($attributes['mode'])
|
||||
);
|
||||
];
|
||||
} else {
|
||||
$return[] = array(
|
||||
$return[] = [
|
||||
'type' => 'file',
|
||||
'content' => $this->parseContent($content),
|
||||
'name' => $this->parseContent($attributes['name'])
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
// Let's check if the mode of the file should be changed
|
||||
if (array_key_exists('chmod', $attributes)) {
|
||||
$return[] = array(
|
||||
$return[] = [
|
||||
'type' => 'command',
|
||||
'content' => 'chmod ' . $attributes['chmod'] . ' "' . $this->parseContent($attributes['name']) . '"',
|
||||
'execute' => "post"
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
// Let's check if the owner of the file should be changed
|
||||
if (array_key_exists('chown', $attributes)) {
|
||||
$return[] = array(
|
||||
$return[] = [
|
||||
'type' => 'command',
|
||||
'content' => 'chown ' . $attributes['chown'] . ' "' . $this->parseContent($attributes['name']) . '"',
|
||||
'execute' => "post"
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
// If we have more than 1 element, we want to group this stuff for easier processing later
|
||||
if (count($return) > 1) {
|
||||
$return = array(
|
||||
$return = [
|
||||
'type' => 'file',
|
||||
'subcommands' => $return,
|
||||
'name' => $this->parseContent($attributes['name'])
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
if ($visibility > 0) {
|
||||
@@ -413,148 +464,84 @@ class ConfigDaemon
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace placeholders with content
|
||||
* Parse a command - order and return it in a format for easier usage
|
||||
*
|
||||
* @param string $content
|
||||
* @return string $content w/o placeholder
|
||||
* @param
|
||||
* SimpleXMLElement object holding a single command from the distribution - XML
|
||||
* @return array|string
|
||||
*/
|
||||
private function parseContent($content)
|
||||
private function parseCommand($order, $attributes)
|
||||
{
|
||||
$content = preg_replace_callback('/\{\{(.*)\}\}/Ui', function ($matches) {
|
||||
$match = null;
|
||||
if (preg_match('/^settings\.(.*)$/', $matches[1], $match)) {
|
||||
return \Froxlor\Settings::Get($match[1]);
|
||||
} elseif (preg_match('/^lng\.(.*)(?:\.(.*)(?:\.(.*)))$/U', $matches[1], $match)) {
|
||||
global $lng;
|
||||
if (isset($match[1]) && $match[1] != '' && isset($match[2]) && $match[2] != '' && isset($match[3]) && $match[3] != '') {
|
||||
return $lng[$match[1]][$match[2]][$match[3]];
|
||||
} elseif (isset($match[1]) && $match[1] != '' && isset($match[2]) && $match[2] != '') {
|
||||
return $lng[$match[1]][$match[2]];
|
||||
} elseif (isset($match[1]) && $match[1] != '') {
|
||||
return $lng[$match[1]];
|
||||
}
|
||||
return '';
|
||||
} elseif (preg_match('/^const\.(.*)$/', $matches[1], $match)) {
|
||||
return $this->returnDynamic($match[1]);
|
||||
} elseif (preg_match('/^sql\.(.*)$/', $matches[1], $match)) {
|
||||
if (is_null($this->sqldata_cache)) {
|
||||
// read in sql-data (if exists)
|
||||
if (file_exists(\Froxlor\Froxlor::getInstallDir() . "/lib/userdata.inc.php")) {
|
||||
require \Froxlor\Froxlor::getInstallDir() . "/lib/userdata.inc.php";
|
||||
unset($sql_root);
|
||||
$this->sqldata_cache = $sql;
|
||||
}
|
||||
}
|
||||
return isset($this->sqldata_cache[$match[1]]) ? $this->sqldata_cache[$match[1]] : '';
|
||||
}
|
||||
}, $content);
|
||||
return $content;
|
||||
}
|
||||
// No sub - elements, so the content can be returned directly
|
||||
if ($order->count() == 0) {
|
||||
return [
|
||||
'type' => 'command',
|
||||
'content' => $this->parseContent(trim((string)$order))
|
||||
];
|
||||
}
|
||||
|
||||
private function returnDynamic($key = null)
|
||||
{
|
||||
$dynamics = [
|
||||
'install_dir' => \Froxlor\Froxlor::getInstallDir()
|
||||
];
|
||||
return $dynamics[$key] ?? '';
|
||||
// Hold the results
|
||||
$visibility = 1;
|
||||
$content = '';
|
||||
foreach ($order->children() as $child) {
|
||||
switch ((string)$child->getName()) {
|
||||
case "visibility":
|
||||
$visibility += $this->checkVisibility($child);
|
||||
break;
|
||||
case "content":
|
||||
$content = trim((string)$child);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ($visibility > 0) {
|
||||
return [
|
||||
'type' => 'command',
|
||||
'content' => $this->parseContent($content)
|
||||
];
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if visibility should be changed
|
||||
* Parse a install - order and return it in a format for easier usage
|
||||
*
|
||||
* @param \SimpleXMLElement $order
|
||||
* @return int 0|-1
|
||||
* @param
|
||||
* SimpleXMLElement object holding a single install from the distribution - XML
|
||||
* @return array|string
|
||||
*/
|
||||
private function checkVisibility($order)
|
||||
private function parseInstall($order, $attributes)
|
||||
{
|
||||
$attributes = array();
|
||||
foreach ($order->attributes() as $key => $value) {
|
||||
$attributes[(string) $key] = $this->parseContent(trim((string) $value));
|
||||
// No sub - elements, so the content can be returned directly
|
||||
if ($order->count() == 0) {
|
||||
return [
|
||||
'type' => 'install',
|
||||
'content' => $this->parseContent(trim((string)$order))
|
||||
];
|
||||
}
|
||||
|
||||
$order = $this->parseContent(trim((string) $order));
|
||||
if (! array_key_exists('mode', $attributes)) {
|
||||
throw new \Exception('"<visibility>' . $order . '</visibility>" is missing mode');
|
||||
// Hold the results
|
||||
$visibility = 1;
|
||||
$content = '';
|
||||
foreach ($order->children() as $child) {
|
||||
switch ((string)$child->getName()) {
|
||||
case "visibility":
|
||||
$visibility += $this->checkVisibility($child);
|
||||
break;
|
||||
case "content":
|
||||
$content = trim((string)$child);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$return = 0;
|
||||
switch ($attributes['mode']) {
|
||||
case "isfile":
|
||||
if (! is_file($order)) {
|
||||
$return = - 1;
|
||||
}
|
||||
;
|
||||
break;
|
||||
case "notisfile":
|
||||
if (is_file($order)) {
|
||||
$return = - 1;
|
||||
}
|
||||
;
|
||||
break;
|
||||
case "isdir":
|
||||
if (! is_dir($order)) {
|
||||
$return = - 1;
|
||||
}
|
||||
;
|
||||
break;
|
||||
case "notisdir":
|
||||
if (is_dir($order)) {
|
||||
$return = - 1;
|
||||
}
|
||||
;
|
||||
break;
|
||||
case "false":
|
||||
if ($order == true) {
|
||||
$return = - 1;
|
||||
}
|
||||
;
|
||||
break;
|
||||
case "true":
|
||||
if ($order == false) {
|
||||
$return = - 1;
|
||||
}
|
||||
;
|
||||
break;
|
||||
case "notempty":
|
||||
if ($order == "") {
|
||||
$return = - 1;
|
||||
}
|
||||
;
|
||||
break;
|
||||
case "userexists":
|
||||
if (posix_getpwuid($order) === false) {
|
||||
$return = - 1;
|
||||
}
|
||||
;
|
||||
break;
|
||||
case "groupexists":
|
||||
if (posix_getgrgid($order) === false) {
|
||||
$return = - 1;
|
||||
}
|
||||
;
|
||||
break;
|
||||
case "usernotexists":
|
||||
if (is_array(posix_getpwuid($order))) {
|
||||
$return = - 1;
|
||||
}
|
||||
;
|
||||
break;
|
||||
case "groupnotexists":
|
||||
if (is_array(posix_getgrgid($order))) {
|
||||
$return = - 1;
|
||||
}
|
||||
;
|
||||
break;
|
||||
case "usernamenotexists":
|
||||
if (is_array(posix_getpwnam($order))) {
|
||||
$return = - 1;
|
||||
}
|
||||
;
|
||||
break;
|
||||
case "equals":
|
||||
$return = (isset($attributes['value']) && $attributes['value'] == $order ? 0 : - 1);
|
||||
break;
|
||||
if ($visibility > 0) {
|
||||
return [
|
||||
'type' => 'install',
|
||||
'content' => $this->parseContent($content)
|
||||
];
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,28 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace Froxlor\Config;
|
||||
|
||||
use Froxlor\Froxlor;
|
||||
use Froxlor\Settings;
|
||||
use Froxlor\PhpHelper;
|
||||
use Froxlor\FileDir;
|
||||
use Froxlor\Database\Database;
|
||||
use Froxlor\UI\Panel\UI;
|
||||
|
||||
/**
|
||||
* This file is part of the Froxlor project.
|
||||
* Copyright (c) 2010 the Froxlor Team (see authors).
|
||||
*
|
||||
* For the full copyright and license information, please view the COPYING
|
||||
* file that was distributed with this source code. You can also view the
|
||||
* COPYING file online at http://files.froxlor.org/misc/COPYING.txt
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* @copyright (c) the authors
|
||||
* @author Froxlor team <team@froxlor.org> (2010-)
|
||||
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
|
||||
* @package Config
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, you can also view it online at
|
||||
* https://files.froxlor.org/misc/COPYING.txt
|
||||
*
|
||||
* @copyright the authors
|
||||
* @author Froxlor team <team@froxlor.org>
|
||||
* @license https://files.froxlor.org/misc/COPYING.txt GPLv2
|
||||
*/
|
||||
|
||||
namespace Froxlor\Config;
|
||||
|
||||
use Froxlor\Database\Database;
|
||||
use Froxlor\FileDir;
|
||||
use Froxlor\Froxlor;
|
||||
use Froxlor\PhpHelper;
|
||||
use Froxlor\Settings;
|
||||
use Froxlor\UI\Panel\UI;
|
||||
|
||||
class ConfigDisplay
|
||||
{
|
||||
/**
|
||||
@@ -74,9 +83,9 @@ class ConfigDisplay
|
||||
// ignore invalid responses
|
||||
if (!is_array($nameserver_ips)) {
|
||||
// act like \Froxlor\PhpHelper::gethostbynamel6() and return unmodified hostname on error
|
||||
$nameserver_ips = array(
|
||||
$nameserver_ips = [
|
||||
$nameserver
|
||||
);
|
||||
];
|
||||
} else {
|
||||
$known_ns_ips = array_merge($known_ns_ips, $nameserver_ips);
|
||||
}
|
||||
@@ -103,7 +112,7 @@ class ConfigDisplay
|
||||
Database::needSqlData(true);
|
||||
$sql = Database::getSqlData();
|
||||
|
||||
self::$replace_arr = array(
|
||||
self::$replace_arr = [
|
||||
'<SQL_UNPRIVILEGED_USER>' => $sql['user'],
|
||||
'<SQL_UNPRIVILEGED_PASSWORD>' => 'FROXLOR_MYSQL_PASSWORD',
|
||||
'<SQL_DB>' => $sql['db'],
|
||||
@@ -124,7 +133,7 @@ class ConfigDisplay
|
||||
'<CUSTOMER_LOGS>' => FileDir::makeCorrectDir(Settings::Get('system.logfiles_directory')),
|
||||
'<FPM_IPCDIR>' => FileDir::makeCorrectDir(Settings::Get('phpfpm.fastcgi_ipcdir')),
|
||||
'<WEBSERVER_GROUP>' => Settings::Get('system.httpgroup')
|
||||
);
|
||||
];
|
||||
|
||||
$commands_pre = "";
|
||||
$commands_file = "";
|
||||
@@ -139,7 +148,10 @@ class ConfigDisplay
|
||||
if ($lasttype != '' && $lasttype != $_action['type']) {
|
||||
$commands = trim($commands);
|
||||
$numbrows = count(explode("\n", $commands));
|
||||
$configpage .= UI::twig()->render(self::$theme . '/settings/conf/command.html.twig', ['commands' => $commands, 'numbrows' => $numbrows]);
|
||||
$configpage .= UI::twig()->render(self::$theme . '/settings/conf/command.html.twig', [
|
||||
'commands' => $commands,
|
||||
'numbrows' => $numbrows
|
||||
]);
|
||||
$lasttype = '';
|
||||
$commands = '';
|
||||
}
|
||||
@@ -170,12 +182,18 @@ class ConfigDisplay
|
||||
$commands = trim($commands_pre);
|
||||
if ($commands != "") {
|
||||
$numbrows = count(explode("\n", $commands));
|
||||
$commands_pre = UI::twig()->render(self::$theme . '/settings/conf/command.html.twig', ['commands' => $commands, 'numbrows' => $numbrows]);
|
||||
$commands_pre = UI::twig()->render(self::$theme . '/settings/conf/command.html.twig', [
|
||||
'commands' => $commands,
|
||||
'numbrows' => $numbrows
|
||||
]);
|
||||
}
|
||||
$commands = trim($commands_post);
|
||||
if ($commands != "") {
|
||||
$numbrows = count(explode("\n", $commands));
|
||||
$commands_post = UI::twig()->render(self::$theme . '/settings/conf/command.html.twig', ['commands' => $commands, 'numbrows' => $numbrows]);
|
||||
$commands_post = UI::twig()->render(self::$theme . '/settings/conf/command.html.twig', [
|
||||
'commands' => $commands,
|
||||
'numbrows' => $numbrows
|
||||
]);
|
||||
}
|
||||
$configpage .= UI::twig()->render(self::$theme . '/settings/conf/fileblock.html.twig', [
|
||||
'realname' => $realname,
|
||||
@@ -192,7 +210,10 @@ class ConfigDisplay
|
||||
$commands = trim($commands);
|
||||
if ($commands != '') {
|
||||
$numbrows = count(explode("\n", $commands));
|
||||
$configpage .= UI::twig()->render(self::$theme . '/settings/conf/command.html.twig', ['commands' => $commands, 'numbrows' => $numbrows]);
|
||||
$configpage .= UI::twig()->render(self::$theme . '/settings/conf/command.html.twig', [
|
||||
'commands' => $commands,
|
||||
'numbrows' => $numbrows
|
||||
]);
|
||||
}
|
||||
return $configpage;
|
||||
}
|
||||
|
||||
@@ -1,59 +1,89 @@
|
||||
<?php
|
||||
|
||||
namespace Froxlor\Config;
|
||||
|
||||
/**
|
||||
* This file is part of the Froxlor project.
|
||||
* Copyright (c) 2010 the Froxlor Team (see authors).
|
||||
*
|
||||
* For the full copyright and license information, please view the COPYING
|
||||
* file that was distributed with this source code. You can also view the
|
||||
* COPYING file online at http://files.froxlor.org/misc/COPYING.txt
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* @copyright (c) the authors
|
||||
* @author Florian Aders <eleras@froxlor.org>
|
||||
* @author Froxlor team <team@froxlor.org> (2010-)
|
||||
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
|
||||
* @package Classes
|
||||
*
|
||||
* @since 0.9.34
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, you can also view it online at
|
||||
* https://files.froxlor.org/misc/COPYING.txt
|
||||
*
|
||||
* @copyright the authors
|
||||
* @author Froxlor team <team@froxlor.org>
|
||||
* @license https://files.froxlor.org/misc/COPYING.txt GPLv2
|
||||
*/
|
||||
|
||||
namespace Froxlor\Config;
|
||||
|
||||
use Exception;
|
||||
use SimpleXMLElement;
|
||||
|
||||
/**
|
||||
* Class ConfigParser
|
||||
*
|
||||
* Parses a distributions XML - file and gives access to the configuration
|
||||
*
|
||||
* @copyright (c) the authors
|
||||
* @author Florian Aders <eleras@froxlor.org>
|
||||
* @author Froxlor team <team@froxlor.org> (2010-)
|
||||
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
|
||||
* @package Classes
|
||||
*/
|
||||
class ConfigParser
|
||||
{
|
||||
|
||||
/**
|
||||
* Name of the distribution this configuration is for
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $distributionName = '';
|
||||
/**
|
||||
* Codename of the distribution this configuration is for
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $distributionCodename = '';
|
||||
/**
|
||||
* Version of the distribution this configuration is for
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $distributionVersion = '';
|
||||
/**
|
||||
* Recommended editor
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $distributionEditor = '/bin/nano';
|
||||
/**
|
||||
* Show if this configuration is deprecated
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $deprecated = false;
|
||||
/**
|
||||
* Holding the available services in the XML
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $services = array();
|
||||
|
||||
private $services = [];
|
||||
/**
|
||||
* Holding the available defaults in the XML
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $defaults = array();
|
||||
|
||||
private $defaults = [];
|
||||
/**
|
||||
* Store the parsed SimpleXMLElement for usage
|
||||
*
|
||||
* @var \SimpleXMLElement
|
||||
* @var SimpleXMLElement
|
||||
*/
|
||||
private $xml;
|
||||
|
||||
/**
|
||||
* Memorize if we already parsed the XML
|
||||
*
|
||||
@@ -61,54 +91,19 @@ class ConfigParser
|
||||
*/
|
||||
private $isparsed = false;
|
||||
|
||||
/**
|
||||
* Name of the distribution this configuration is for
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $distributionName = '';
|
||||
|
||||
/**
|
||||
* Codename of the distribution this configuration is for
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $distributionCodename = '';
|
||||
|
||||
/**
|
||||
* Version of the distribution this configuration is for
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $distributionVersion = '';
|
||||
|
||||
/**
|
||||
* Recommended editor
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $distributionEditor = '/bin/nano';
|
||||
|
||||
/**
|
||||
* Show if this configuration is deprecated
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $deprecated = false;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* Initialize the XML - ConfigParser
|
||||
*
|
||||
* @param string $filename
|
||||
* filename of the froxlor - configurationfile
|
||||
* filename of the froxlor - configurationfile
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($filename)
|
||||
{
|
||||
if (!is_readable($filename)) {
|
||||
throw new \Exception('File not readable');
|
||||
throw new Exception('File not readable');
|
||||
}
|
||||
|
||||
$this->xml = simplexml_load_file($filename);
|
||||
@@ -117,7 +112,7 @@ class ConfigParser
|
||||
foreach (libxml_get_errors() as $error) {
|
||||
$error .= "\t" . $error->message;
|
||||
}
|
||||
throw new \Exception($error);
|
||||
throw new Exception($error);
|
||||
}
|
||||
|
||||
// Let's see if we can find a <distribution> block in the XML
|
||||
@@ -125,31 +120,47 @@ class ConfigParser
|
||||
|
||||
// No distribution found - can't use this file
|
||||
if (!is_array($distribution)) {
|
||||
throw new \Exception('Invalid XML, no distribution found');
|
||||
throw new Exception('Invalid XML, no distribution found');
|
||||
}
|
||||
|
||||
// Search for attributes we understand
|
||||
foreach ($distribution[0]->attributes() as $key => $value) {
|
||||
switch ((string) $key) {
|
||||
switch ((string)$key) {
|
||||
case "name":
|
||||
$this->distributionName = (string) $value;
|
||||
$this->distributionName = (string)$value;
|
||||
break;
|
||||
case "version":
|
||||
$this->distributionVersion = (string) $value;
|
||||
$this->distributionVersion = (string)$value;
|
||||
break;
|
||||
case "codename":
|
||||
$this->distributionCodename = (string) $value;
|
||||
$this->distributionCodename = (string)$value;
|
||||
break;
|
||||
case "defaulteditor":
|
||||
$this->distributionEditor = (string) $value;
|
||||
$this->distributionEditor = (string)$value;
|
||||
break;
|
||||
case "deprecated":
|
||||
(string) $value == 'true' ? $this->deprecated = true : $this->deprecated = false;
|
||||
(string)$value == 'true' ? $this->deprecated = true : $this->deprecated = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all services defined by the XML
|
||||
*
|
||||
* The array will hold ConfigService - Objects for further handling
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getServices()
|
||||
{
|
||||
// Let's parse this shit(!)
|
||||
$this->parseServices();
|
||||
|
||||
// Return our carefully searched for services
|
||||
return $this->services;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the XML and populate $this->services
|
||||
*
|
||||
@@ -172,7 +183,7 @@ class ConfigParser
|
||||
// Search the attributes for "type"
|
||||
foreach ($service->attributes() as $key => $value) {
|
||||
if ($key == 'type') {
|
||||
$this->services[(string) $value] = new ConfigService($this->xml, '//services/service[@type="' . (string) $value . '"]');
|
||||
$this->services[(string)$value] = new ConfigService($this->xml, '//services/service[@type="' . (string)$value . '"]');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -182,6 +193,22 @@ class ConfigParser
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all defaults defined by the XML
|
||||
*
|
||||
* The array will hold ConfigDefaults - Objects for further handling
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getDefaults()
|
||||
{
|
||||
// Let's parse this shit(!)
|
||||
$this->parseDefaults();
|
||||
|
||||
// Return our carefully searched for defaults
|
||||
return $this->defaults;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the XML and populate $this->services
|
||||
*
|
||||
@@ -205,38 +232,6 @@ class ConfigParser
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all services defined by the XML
|
||||
*
|
||||
* The array will hold ConfigService - Objects for further handling
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getServices()
|
||||
{
|
||||
// Let's parse this shit(!)
|
||||
$this->parseServices();
|
||||
|
||||
// Return our carefully searched for services
|
||||
return $this->services;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all defaults defined by the XML
|
||||
*
|
||||
* The array will hold ConfigDefaults - Objects for further handling
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getDefaults()
|
||||
{
|
||||
// Let's parse this shit(!)
|
||||
$this->parseDefaults();
|
||||
|
||||
// Return our carefully searched for defaults
|
||||
return $this->defaults;
|
||||
}
|
||||
|
||||
/**
|
||||
* return complete distribution string "Name [codename] [ (version)] [deprecated]
|
||||
*
|
||||
|
||||
@@ -1,72 +1,73 @@
|
||||
<?php
|
||||
namespace Froxlor\Config;
|
||||
|
||||
/**
|
||||
* This file is part of the Froxlor project.
|
||||
* Copyright (c) 2010 the Froxlor Team (see authors).
|
||||
*
|
||||
* For the full copyright and license information, please view the COPYING
|
||||
* file that was distributed with this source code. You can also view the
|
||||
* COPYING file online at http://files.froxlor.org/misc/COPYING.txt
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* @copyright (c) the authors
|
||||
* @author Florian Aders <eleras@froxlor.org>
|
||||
* @author Froxlor team <team@froxlor.org> (2010-)
|
||||
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
|
||||
* @package Classes
|
||||
*
|
||||
* @since 0.9.34
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, you can also view it online at
|
||||
* https://files.froxlor.org/misc/COPYING.txt
|
||||
*
|
||||
* @copyright the authors
|
||||
* @author Froxlor team <team@froxlor.org>
|
||||
* @license https://files.froxlor.org/misc/COPYING.txt GPLv2
|
||||
*/
|
||||
|
||||
namespace Froxlor\Config;
|
||||
|
||||
use Exception;
|
||||
use Froxlor\Settings;
|
||||
use SimpleXMLElement;
|
||||
|
||||
/**
|
||||
* Class ConfigService
|
||||
*
|
||||
* Parses a distributions XML - file and gives access to the services within
|
||||
* Not to be used directly
|
||||
*
|
||||
* @copyright (c) the authors
|
||||
* @author Florian Aders <eleras@froxlor.org>
|
||||
* @author Froxlor team <team@froxlor.org> (2010-)
|
||||
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
|
||||
* @package Classes
|
||||
*/
|
||||
class ConfigService
|
||||
{
|
||||
|
||||
/**
|
||||
* Holding the available daemons in this service
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $daemons = array();
|
||||
|
||||
/**
|
||||
* Store the parsed SimpleXMLElement for usage
|
||||
*
|
||||
* @var \SimpleXMLElement
|
||||
*/
|
||||
private $fullxml;
|
||||
|
||||
/**
|
||||
* Memorize if we already parsed the XML
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
private $isparsed = false;
|
||||
|
||||
/**
|
||||
* xpath leading to this service in the full XML
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $xpath;
|
||||
|
||||
/**
|
||||
* Human - readable title of this service
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $title;
|
||||
/**
|
||||
* Holding the available daemons in this service
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $daemons = [];
|
||||
/**
|
||||
* Store the parsed SimpleXMLElement for usage
|
||||
*
|
||||
* @var SimpleXMLElement
|
||||
*/
|
||||
private $fullxml;
|
||||
/**
|
||||
* Memorize if we already parsed the XML
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
private $isparsed = false;
|
||||
/**
|
||||
* xpath leading to this service in the full XML
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $xpath;
|
||||
|
||||
public function __construct($xml, $xpath)
|
||||
{
|
||||
@@ -75,10 +76,43 @@ class ConfigService
|
||||
$service = $this->fullxml->xpath($this->xpath);
|
||||
$attributes = $service[0]->attributes();
|
||||
if ($attributes['title'] != '') {
|
||||
$this->title = $this->parseContent((string) $attributes['title']);
|
||||
$this->title = $this->parseContent((string)$attributes['title']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace placeholders with content
|
||||
*
|
||||
* @param string $content
|
||||
* @return string $content w/o placeholder
|
||||
*/
|
||||
private function parseContent($content)
|
||||
{
|
||||
$content = preg_replace_callback('/\{\{(.*)\}\}/Ui', function ($matches) {
|
||||
$match = null;
|
||||
if (preg_match('/^settings\.(.*)$/', $matches[1], $match)) {
|
||||
return Settings::Get($match[1]);
|
||||
} elseif (preg_match('/^lng\.(.*)(?:\.(.*)(?:\.(.*)))$/U', $matches[1], $match)) {
|
||||
global $lng;
|
||||
if (isset($match[1]) && $match[1] != '' && isset($match[2]) && $match[2] != '' && isset($match[3]) && $match[3] != '') {
|
||||
return $lng[$match[1]][$match[2]][$match[3]];
|
||||
} elseif (isset($match[1]) && $match[1] != '' && isset($match[2]) && $match[2] != '') {
|
||||
return $lng[$match[1]][$match[2]];
|
||||
} elseif (isset($match[1]) && $match[1] != '') {
|
||||
return $lng[$match[1]];
|
||||
}
|
||||
return '';
|
||||
}
|
||||
}, $content);
|
||||
return $content;
|
||||
}
|
||||
|
||||
public function getDaemons()
|
||||
{
|
||||
$this->parse();
|
||||
return $this->daemons;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the XML and populate $this->daemons
|
||||
*
|
||||
@@ -101,10 +135,10 @@ class ConfigService
|
||||
$versiontag = '';
|
||||
foreach ($daemon->attributes() as $key => $value) {
|
||||
if ($key == 'name' && $name == '') {
|
||||
$name = (string) $value;
|
||||
$name = (string)$value;
|
||||
$nametag = "[@name='" . $value . "']";
|
||||
} elseif ($key == 'name' && $name != '') {
|
||||
$name = (string) $value . '_' . $name;
|
||||
$name = (string)$value . '_' . $name;
|
||||
$nametag = "[@name='" . $value . "']";
|
||||
} elseif ($key == 'version' && $name == '') {
|
||||
$name = str_replace('.', '', $value);
|
||||
@@ -115,7 +149,7 @@ class ConfigService
|
||||
}
|
||||
}
|
||||
if ($name == '') {
|
||||
throw new \Exception('No name attribute for daemon');
|
||||
throw new Exception('No name attribute for daemon');
|
||||
}
|
||||
$this->daemons[$name] = new ConfigDaemon($this->fullxml, $this->xpath . "/daemon" . $nametag . $versiontag);
|
||||
}
|
||||
@@ -124,37 +158,4 @@ class ConfigService
|
||||
$this->isparsed = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace placeholders with content
|
||||
*
|
||||
* @param string $content
|
||||
* @return string $content w/o placeholder
|
||||
*/
|
||||
private function parseContent($content)
|
||||
{
|
||||
$content = preg_replace_callback('/\{\{(.*)\}\}/Ui', function ($matches) {
|
||||
$match = null;
|
||||
if (preg_match('/^settings\.(.*)$/', $matches[1], $match)) {
|
||||
return \Froxlor\Settings::Get($match[1]);
|
||||
} elseif (preg_match('/^lng\.(.*)(?:\.(.*)(?:\.(.*)))$/U', $matches[1], $match)) {
|
||||
global $lng;
|
||||
if (isset($match[1]) && $match[1] != '' && isset($match[2]) && $match[2] != '' && isset($match[3]) && $match[3] != '') {
|
||||
return $lng[$match[1]][$match[2]][$match[3]];
|
||||
} elseif (isset($match[1]) && $match[1] != '' && isset($match[2]) && $match[2] != '') {
|
||||
return $lng[$match[1]][$match[2]];
|
||||
} elseif (isset($match[1]) && $match[1] != '') {
|
||||
return $lng[$match[1]];
|
||||
}
|
||||
return '';
|
||||
}
|
||||
}, $content);
|
||||
return $content;
|
||||
}
|
||||
|
||||
public function getDaemons()
|
||||
{
|
||||
$this->parse();
|
||||
return $this->daemons;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user