remove unused lib/version.inc.php file; added module-specific search to global-search; added new table for user-column-settings

Signed-off-by: Michael Kaufmann <d00p@froxlor.org>
This commit is contained in:
Michael Kaufmann
2022-04-03 18:42:49 +02:00
parent 07049909ef
commit 7779ec376a
11 changed files with 123 additions and 45 deletions

View File

@@ -25,7 +25,7 @@ use Froxlor\Http\HttpClient;
use Froxlor\UI\Panel\UI; use Froxlor\UI\Panel\UI;
// define update-uri // define update-uri
define('UPDATE_URI', "https://version.froxlor.org/Froxlor/api/" . $version); define('UPDATE_URI', "https://version.froxlor.org/Froxlor/api/" . \Froxlor\Froxlor::VERSION);
define('RELEASE_URI', "https://autoupdate.froxlor.org/froxlor-{version}.zip"); define('RELEASE_URI', "https://autoupdate.froxlor.org/froxlor-{version}.zip");
define('CHECKSUM_URI', "https://autoupdate.froxlor.org/froxlor-{version}.zip.sha256"); define('CHECKSUM_URI', "https://autoupdate.froxlor.org/froxlor-{version}.zip.sha256");
@@ -66,7 +66,7 @@ if ($page == 'overview') {
// add the branding so debian guys are not gettings confused // add the branding so debian guys are not gettings confused
// about their version-number // about their version-number
$version_label = $_version . $branding; $version_label = $_version . \Froxlor\Froxlor::BRANDING;
$version_link = $_link; $version_link = $_link;
$message_addinfo = $_message; $message_addinfo = $_message;
@@ -78,7 +78,7 @@ if ($page == 'overview') {
'page' => 'error', 'page' => 'error',
'errno' => 3 'errno' => 3
)); ));
} elseif (\Froxlor\Froxlor::versionCompare2($version, $_version) == -1) { } elseif (\Froxlor\Froxlor::versionCompare2(\Froxlor\Froxlor::VERSION, $_version) == -1) {
// there is a newer version - yay // there is a newer version - yay
$isnewerversion = 1; $isnewerversion = 1;
} else { } else {
@@ -89,7 +89,7 @@ if ($page == 'overview') {
// anzeige über version-status mit ggfls. formular // anzeige über version-status mit ggfls. formular
// zum update schritt #1 -> download // zum update schritt #1 -> download
if ($isnewerversion == 1) { if ($isnewerversion == 1) {
$text = 'There is a newer version available. Update to version <b>' . $_version . '</b> now?<br/>(Your current version is: ' . $version . ')'; $text = 'There is a newer version available. Update to version <b>' . $_version . '</b> now?<br/>(Your current version is: ' . \Froxlor\Froxlor::VERSION . ')';
$upd_formfield = [ $upd_formfield = [
'updates' => [ 'updates' => [

View File

@@ -273,7 +273,7 @@ if ($page == 'overview' && $userinfo['change_serversettings'] == '1') {
} catch (Exception $e) { } catch (Exception $e) {
\Froxlor\UI\Response::dynamic_error($e->getMessage()); \Froxlor\UI\Response::dynamic_error($e->getMessage());
} }
header('Content-disposition: attachment; filename=Froxlor_settings-' . $version . '-' . $dbversion . '_' . date('d.m.Y') . '.json'); header('Content-disposition: attachment; filename=Froxlor_settings-' . \Froxlor\Froxlor::VERSION . '-' . \Froxlor\Froxlor::DBVERSION . '_' . date('d.m.Y') . '.json');
header('Content-type: application/json'); header('Content-type: application/json');
echo $json_export; echo $json_export;
exit(); exit();

View File

@@ -80,11 +80,11 @@ if ($page == 'overview') {
if (empty($current_db_version)) { if (empty($current_db_version)) {
$current_db_version = "0"; $current_db_version = "0";
} }
$new_version = $version; $new_version = \Froxlor\Froxlor::VERSION;
$new_db_version = $dbversion; $new_db_version = \Froxlor\Froxlor::DBVERSION;
$ui_text = $lng['update']['update_information']['part_a']; $ui_text = $lng['update']['update_information']['part_a'];
if ($version != $current_version) { if (\Froxlor\Froxlor::VERSION != $current_version) {
$ui_text = str_replace('%curversion', $current_version, $ui_text); $ui_text = str_replace('%curversion', $current_version, $ui_text);
$ui_text = str_replace('%newversion', $new_version, $ui_text); $ui_text = str_replace('%newversion', $new_version, $ui_text);
} else { } else {

View File

@@ -54,8 +54,8 @@ if (!empty($errid)) {
$mail_body .= "Trace:\n" . trim($_error['trace']) . "\n\n"; $mail_body .= "Trace:\n" . trim($_error['trace']) . "\n\n";
$mail_body .= "-------------------------------------------------------------\n\n"; $mail_body .= "-------------------------------------------------------------\n\n";
$mail_body .= "User-Area: " . AREA . "\n"; $mail_body .= "User-Area: " . AREA . "\n";
$mail_body .= "Froxlor-version: " . $version . "\n"; $mail_body .= "Froxlor-version: " . \Froxlor\Froxlor::VERSION . "\n";
$mail_body .= "DB-version: " . $dbversion . "\n\n"; $mail_body .= "DB-version: " . \Froxlor\Froxlor::DBVERSION . "\n\n";
$mail_body .= "End of report"; $mail_body .= "End of report";
$mail_html = nl2br($mail_body); $mail_html = nl2br($mail_body);

View File

@@ -1053,3 +1053,13 @@ CREATE TABLE `api_keys` (
KEY customerid (customerid) KEY customerid (customerid)
) ENGINE=InnoDB CHARSET=utf8 COLLATE=utf8_general_ci; ) ENGINE=InnoDB CHARSET=utf8 COLLATE=utf8_general_ci;
DROP TABLE IF EXISTS `panel_usercolumns`;
CREATE TABLE `panel_usercolumns` (
`adminid` int(11) NOT NULL default '0',
`customerid` int(11) NOT NULL default '0',
`section` varchar(500) NOT NULL default '',
`columns` text NOT NULL,
UNIQUE KEY `user_section` (`adminid`, `customerid`, `section`),
KEY adminid (adminid),
KEY customerid (customerid)
) ENGINE=InnoDB CHARSET=utf8 COLLATE=utf8_general_ci;

View File

@@ -38,6 +38,21 @@ if (\Froxlor\Froxlor::isFroxlorVersion('0.10.99')) {
Settings::Set('panel.default_theme', 'Froxlor'); Settings::Set('panel.default_theme', 'Froxlor');
lastStepStatus(0); lastStepStatus(0);
showUpdateStep("Creating new tables");
Database::query("DROP TABLE IF EXISTS `panel_usercolumns`;");
$sql = "CREATE TABLE `panel_usercolumns` (
`adminid` int(11) NOT NULL default '0',
`customerid` int(11) NOT NULL default '0',
`section` varchar(500) NOT NULL default '',
`columns` text NOT NULL,
UNIQUE KEY `user_section` (`adminid`, `customerid`, `section`),
KEY adminid (adminid),
KEY customerid (customerid)
) ENGINE=InnoDB CHARSET=utf8 COLLATE=utf8_general_ci;";
Database::query($sql);
lastStepStatus(0);
showUpdateStep("Cleaning up old files"); showUpdateStep("Cleaning up old files");
$to_clean = array( $to_clean = array(
"templates/Sparkle", "templates/Sparkle",

View File

@@ -77,10 +77,17 @@ class GlobalSearch
$processed = []; $processed = [];
$stparts = explode(" ", $searchtext); $stparts = explode(" ", $searchtext);
$module = "";
foreach ($stparts as $searchtext) { foreach ($stparts as $searchtext) {
$searchtext = trim($searchtext); $searchtext = trim($searchtext);
if (preg_match('/^([a-z]+):$/', $searchtext, $matches)) {
$module = $matches[1];
continue;
}
// admin // admin
if (isset($userinfo['adminsession']) && $userinfo['adminsession'] == 1) { if (isset($userinfo['adminsession']) && $userinfo['adminsession'] == 1) {
@@ -262,6 +269,12 @@ class GlobalSearch
]; ];
} }
// module specific search
if (!empty($module)) {
$modSearch = $toSearch[$module] ?? [];
$toSearch = [$module => $modSearch];
}
foreach ($toSearch as $entity => $edata) { foreach ($toSearch as $entity => $edata) {
$collection = (new Collection($edata['class'], $userinfo)) $collection = (new Collection($edata['class'], $userinfo))

View File

@@ -2,8 +2,10 @@
namespace Froxlor\UI; namespace Froxlor\UI;
use Froxlor\Database\Database;
use Froxlor\UI\Panel\UI; use Froxlor\UI\Panel\UI;
use Exception; use InvalidArgumentException;
use Froxlor\CurrentUser;
/** /**
* This file is part of the Froxlor project. * This file is part of the Froxlor project.
@@ -38,7 +40,8 @@ class Listing
'empty_msg' => $tabellisting['empty_msg'] ?? null, 'empty_msg' => $tabellisting['empty_msg'] ?? null,
'total_entries' => ($collection->getPagination() instanceof Pagination) ? $collection->getPagination()->getEntries() : 0, 'total_entries' => ($collection->getPagination() instanceof Pagination) ? $collection->getPagination()->getEntries() : 0,
'is_search' => ($collection->getPagination() instanceof Pagination) ? $collection->getPagination()->isSearchResult() : false, 'is_search' => ($collection->getPagination() instanceof Pagination) ? $collection->getPagination()->isSearchResult() : false,
'self_overview' => $tabellisting['self_overview'] ?? [] 'self_overview' => $tabellisting['self_overview'] ?? [],
'available_columns' => self::getAvailableColumnsForListing($tabellisting)
]; ];
} }
@@ -110,7 +113,7 @@ class Listing
} elseif ($field) { } elseif ($field) {
$rows[$row]['td'][$col]['data'] = $data; $rows[$row]['td'][$col]['data'] = $data;
} else { } else {
throw new Exception('The visible column "' . $visible_column . '" has neither a "callback" nor a "field" set.'); throw new InvalidArgumentException('The visible column "' . $visible_column . '" has neither a "callback" nor a "field" set.');
} }
// Set class for table-row if defined // Set class for table-row if defined
@@ -173,12 +176,75 @@ class Listing
return $actions; return $actions;
} }
private static function getAvailableColumnsForListing(array $tabellisting): array
{
$result = [];
if (isset($tabellisting['columns'])) {
foreach ($tabellisting['columns'] as $column => $coldata) {
$result[$column] = $coldata['label'];
}
}
return $result;
}
/**
* store column listing selection of user to database
* the selection array should look like this:
* [
* 'section_name' => [
* 'column_name',
* 'column_name',
* 'column_name'
* ]
* ]
*
* @param array $tablelisting
*
* @return bool
*/
public static function storeColumnListingForUser(array $tabellisting): bool
{
$section = array_key_first($tabellisting);
if (empty($section) || !is_array($tabellisting[$section]) || empty($tabellisting[$section])) {
throw new InvalidArgumentException("Invalid selection array for " . __METHOD__);
}
$userid = 'customerid';
if (CurrentUser::isAdmin()) {
$userid = 'adminid';
}
// delete possible existing entry
$del_stmt = Database::prepare("
DELETE FROM `" . TABLE_PANEL_USERCOLUMNS . "` WHERE `" . $userid . "` = :uid AND `section` = :section
");
Database::pexecute($del_stmt, ['uid' => CurrentUser::getData($userid), 'section' => $section]);
// add new entry
$ins_stmt = Database::prepare("
INSERT INTO `" . TABLE_PANEL_USERCOLUMNS . "` SET
`" . $userid . "` = :uid,
`section` = :section,
`columns` = :cols
");
Database::pexecute($ins_stmt, [
'uid' => CurrentUser::getData($userid),
'section' => $section,
'cols' => json_encode($tabellisting[$section])
]);
return true;
}
public static function getVisibleColumnsForListing(string $listing, array $default_columns): array public static function getVisibleColumnsForListing(string $listing, array $default_columns): array
{ {
// Here would come the logic that pulls this from the DB ... $userid = 'customerid';
// alternatively, it takes the $default_columns if no entry is if (CurrentUser::isAdmin()) {
// defined in the DB $userid = 'adminid';
}
$sel_stmt = Database::prepare("
SELECT `columns` FROM `" . TABLE_PANEL_USERCOLUMNS . "` WHERE `" . $userid . "` = :uid AND `section` = :section
");
$columns_json = Database::pexecute_first($sel_stmt, ['uid' => CurrentUser::getData($userid), 'section' => $listing]);
if ($columns_json && isset($columns_json['columns'])) {
return json_decode($columns_json['columns'], true);
}
return $default_columns; return $default_columns;
} }

View File

@@ -30,7 +30,7 @@ return [
'self_overview' => ['section' => 'admins', 'page' => 'admins'], 'self_overview' => ['section' => 'admins', 'page' => 'admins'],
'columns' => [ 'columns' => [
'adminid' => [ 'adminid' => [
'label' => '#', 'label' => 'ID',
'field' => 'adminid', 'field' => 'adminid',
'sortable' => true, 'sortable' => true,
], ],

View File

@@ -50,5 +50,4 @@ const TABLE_DOMAIN_DNS = 'domain_dns_entries';
const TABLE_PANEL_FPMDAEMONS = 'panel_fpmdaemons'; const TABLE_PANEL_FPMDAEMONS = 'panel_fpmdaemons';
const TABLE_PANEL_PLANS = 'panel_plans'; const TABLE_PANEL_PLANS = 'panel_plans';
const TABLE_API_KEYS = 'api_keys'; const TABLE_API_KEYS = 'api_keys';
const TABLE_PANEL_USERCOLUMNS = 'panel_usercolumns';
require dirname(__FILE__) . '/version.inc.php';

View File

@@ -1,25 +0,0 @@
<?php
/**
* 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
*
* @copyright (c) the authors
* @author Froxlor team <team@froxlor.org> (2010-)
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
* @package System
*
*/
// Main version variable
$version = \Froxlor\Froxlor::VERSION;
// Database version (YYYYMMDDC where C is a daily counter)
$dbversion = \Froxlor\Froxlor::DBVERSION;
// Distribution branding-tag (used for Debian etc.)
$branding = \Froxlor\Froxlor::BRANDING;