initial backup feature
Signed-off-by: Maurice Preuß (envoyr) <envoyr@froxlor.org>
This commit is contained in:
201
lib/Froxlor/Api/Commands/Backups.php
Normal file
201
lib/Froxlor/Api/Commands/Backups.php
Normal file
@@ -0,0 +1,201 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of the Froxlor project.
|
||||
* Copyright (c) 2010 the Froxlor Team (see authors).
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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\Api\Commands;
|
||||
|
||||
use Exception;
|
||||
use Froxlor\Api\ApiCommand;
|
||||
use Froxlor\Api\ResourceEntity;
|
||||
use Froxlor\Database\Database;
|
||||
use Froxlor\FroxlorLogger;
|
||||
use Froxlor\Idna\IdnaWrapper;
|
||||
use Froxlor\Settings;
|
||||
use Froxlor\System\Crypt;
|
||||
use Froxlor\UI\Response;
|
||||
use Froxlor\User;
|
||||
use Froxlor\Validate\Validate;
|
||||
use PDO;
|
||||
|
||||
/**
|
||||
* @since 2.1.0
|
||||
*/
|
||||
class Backups extends ApiCommand implements ResourceEntity
|
||||
{
|
||||
|
||||
/**
|
||||
* increase resource-usage
|
||||
*
|
||||
* @param int $adminid
|
||||
* @param string $resource
|
||||
* @param string $extra
|
||||
* optional, default empty
|
||||
* @param int $increase_by
|
||||
* optional, default 1
|
||||
*/
|
||||
public static function increaseUsage($adminid = 0, $resource = null, $extra = '', $increase_by = 1)
|
||||
{
|
||||
self::updateResourceUsage(TABLE_PANEL_BACKUPS, 'adminid', $adminid, '+', $resource, $extra, $increase_by);
|
||||
}
|
||||
|
||||
/**
|
||||
* decrease resource-usage
|
||||
*
|
||||
* @param int $adminid
|
||||
* @param string $resource
|
||||
* @param string $extra
|
||||
* optional, default empty
|
||||
* @param int $decrease_by
|
||||
* optional, default 1
|
||||
*/
|
||||
public static function decreaseUsage($adminid = 0, $resource = null, $extra = '', $decrease_by = 1)
|
||||
{
|
||||
self::updateResourceUsage(TABLE_PANEL_BACKUPS, 'adminid', $adminid, '-', $resource, $extra, $decrease_by);
|
||||
}
|
||||
|
||||
/**
|
||||
* lists all admin entries
|
||||
*
|
||||
* @param array $sql_search
|
||||
* optional array with index = fieldname, and value = array with 'op' => operator (one of <, > or =),
|
||||
* LIKE is used if left empty and 'value' => searchvalue
|
||||
* @param int $sql_limit
|
||||
* optional specify number of results to be returned
|
||||
* @param int $sql_offset
|
||||
* optional specify offset for resultset
|
||||
* @param array $sql_orderby
|
||||
* optional array with index = fieldname and value = ASC|DESC to order the resultset by one or more
|
||||
* fields
|
||||
*
|
||||
* @access admin
|
||||
* @return string json-encoded array count|list
|
||||
* @throws Exception
|
||||
*/
|
||||
public function listing()
|
||||
{
|
||||
if ($this->isAdmin() && $this->getUserDetail('change_serversettings') == 1) {
|
||||
$this->logger()->logAction(FroxlorLogger::ADM_ACTION, LOG_NOTICE, "[API] list backups");
|
||||
$query_fields = [];
|
||||
$result_stmt = Database::prepare("
|
||||
SELECT `b`.*, `a`.`loginname` as `adminname`
|
||||
FROM `" . TABLE_PANEL_BACKUPS . "` `b`
|
||||
LEFT JOIN `" . TABLE_PANEL_ADMINS . "` `a` USING(`adminid`)
|
||||
");
|
||||
Database::pexecute($result_stmt, $query_fields, true, true);
|
||||
$result = [];
|
||||
while ($row = $result_stmt->fetch(PDO::FETCH_ASSOC)) {
|
||||
$result[] = $row;
|
||||
}
|
||||
return $this->response([
|
||||
'count' => count($result),
|
||||
'list' => $result
|
||||
]);
|
||||
}
|
||||
throw new Exception("Not allowed to execute given command.", 403);
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the total number of backups for the given admin
|
||||
*
|
||||
* @access admin
|
||||
* @return string json-encoded response message
|
||||
* @throws Exception
|
||||
*/
|
||||
public function listingCount()
|
||||
{
|
||||
if ($this->isAdmin() && $this->getUserDetail('change_serversettings') == 1) {
|
||||
$result_stmt = Database::prepare("
|
||||
SELECT COUNT(*) as num_backups
|
||||
FROM `" . TABLE_PANEL_BACKUPS . "`
|
||||
");
|
||||
$result = Database::pexecute_first($result_stmt, null, true, true);
|
||||
if ($result) {
|
||||
return $this->response($result['num_backups']);
|
||||
}
|
||||
$this->response(0);
|
||||
}
|
||||
throw new Exception("Not allowed to execute given command.", 403);
|
||||
}
|
||||
|
||||
/**
|
||||
* create a new admin user
|
||||
*
|
||||
* @param string $name
|
||||
*
|
||||
* @access admin
|
||||
* @return string json-encoded array
|
||||
* @throws Exception
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
throw new Exception("Not allowed to execute given command.", 403);
|
||||
}
|
||||
|
||||
/**
|
||||
* return an admin entry by either id or loginname
|
||||
*
|
||||
* @param int $id
|
||||
* optional, the admin-id
|
||||
* @param string $loginname
|
||||
* optional, the loginname
|
||||
*
|
||||
* @access admin
|
||||
* @return string json-encoded array
|
||||
* @throws Exception
|
||||
*/
|
||||
public function get()
|
||||
{
|
||||
throw new Exception("Not allowed to execute given command.", 403);
|
||||
}
|
||||
|
||||
/**
|
||||
* update an admin user by given id or loginname
|
||||
*
|
||||
* @param int $id
|
||||
* required, the admin-id
|
||||
*
|
||||
* @access admin
|
||||
* @return string json-encoded array
|
||||
* @throws Exception
|
||||
*/
|
||||
public function update()
|
||||
{
|
||||
throw new Exception("Not allowed to execute given command.", 403);
|
||||
}
|
||||
|
||||
/**
|
||||
* delete a admin entry by either id or loginname
|
||||
*
|
||||
* @param int $id
|
||||
* required, the admin-id
|
||||
*
|
||||
* @access admin
|
||||
* @return string json-encoded array
|
||||
* @throws Exception
|
||||
*/
|
||||
public function delete()
|
||||
{
|
||||
throw new Exception("Not allowed to execute given command.", 403);
|
||||
}
|
||||
}
|
||||
33
lib/formfields/admin/backups/formfield.backups_add.php
Normal file
33
lib/formfields/admin/backups/formfield.backups_add.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of the Froxlor project.
|
||||
* Copyright (c) 2010 the Froxlor Team (see authors).
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
return [
|
||||
'backups_add' => [
|
||||
'title' => lng('backups.backups_add'),
|
||||
'image' => 'fa-solid fa-file-archive',
|
||||
'self_overview' => ['section' => 'backups', 'page' => 'backups'],
|
||||
'sections' => []
|
||||
],
|
||||
];
|
||||
33
lib/formfields/admin/backups/formfield.backups_edit.php
Normal file
33
lib/formfields/admin/backups/formfield.backups_edit.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of the Froxlor project.
|
||||
* Copyright (c) 2010 the Froxlor Team (see authors).
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
return [
|
||||
'backups_edit' => [
|
||||
'title' => lng('backups.backups_edit'),
|
||||
'image' => 'fa-solid fa-file-archive',
|
||||
'self_overview' => ['section' => 'backups', 'page' => 'admins'],
|
||||
'sections' => []
|
||||
],
|
||||
];
|
||||
33
lib/formfields/admin/backups/formfield.backups_restore.php
Normal file
33
lib/formfields/admin/backups/formfield.backups_restore.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of the Froxlor project.
|
||||
* Copyright (c) 2010 the Froxlor Team (see authors).
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
return [
|
||||
'backups_restore' => [
|
||||
'title' => lng('backups.backups_restore'),
|
||||
'image' => 'fa-solid fa-file-archive',
|
||||
'self_overview' => ['section' => 'backups', 'page' => 'backups'],
|
||||
'sections' => []
|
||||
],
|
||||
];
|
||||
0
lib/formfields/admin/backups/index.html
Normal file
0
lib/formfields/admin/backups/index.html
Normal file
@@ -223,6 +223,12 @@ return [
|
||||
'required_resources' => 'customers',
|
||||
'add_shortlink' => 'admin_plans.php?page=overview&action=add'
|
||||
],
|
||||
[
|
||||
'url' => 'admin_backups.php?page=overview',
|
||||
'label' => lng('admin.backups.backups'),
|
||||
'required_resources' => 'change_serversettings',
|
||||
'add_shortlink' => 'admin_backups.php?page=overview&action=add'
|
||||
],
|
||||
[
|
||||
'url' => 'admin_settings.php?page=updatecounters',
|
||||
'label' => lng('admin.updatecounters'),
|
||||
|
||||
122
lib/tablelisting/admin/tablelisting.backups.php
Normal file
122
lib/tablelisting/admin/tablelisting.backups.php
Normal file
@@ -0,0 +1,122 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of the Froxlor project.
|
||||
* Copyright (c) 2010 the Froxlor Team (see authors).
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
use Froxlor\UI\Callbacks\Admin;
|
||||
use Froxlor\UI\Callbacks\Customer;
|
||||
use Froxlor\UI\Callbacks\Impersonate;
|
||||
use Froxlor\UI\Callbacks\ProgressBar;
|
||||
use Froxlor\UI\Callbacks\Style;
|
||||
use Froxlor\UI\Callbacks\Text;
|
||||
use Froxlor\UI\Listing;
|
||||
|
||||
return [
|
||||
'backups_list' => [
|
||||
'title' => lng('admin.backups.backups'),
|
||||
'icon' => 'fa-solid fa-file-archive',
|
||||
'self_overview' => ['section' => 'admins', 'page' => 'admins'],
|
||||
'default_sorting' => ['loginname' => 'asc'],
|
||||
'columns' => [
|
||||
'id' => [
|
||||
'label' => 'ID',
|
||||
'field' => 'id',
|
||||
'sortable' => true,
|
||||
],
|
||||
'customerid' => [
|
||||
'label' => lng('customerid'),
|
||||
'field' => 'customerid',
|
||||
'sortable' => true,
|
||||
],
|
||||
'loginname' => [
|
||||
'label' => lng('login.username'),
|
||||
'field' => 'loginname',
|
||||
'callback' => [Impersonate::class, 'customer'],
|
||||
'sortable' => true,
|
||||
],
|
||||
'adminid' => [
|
||||
'label' => lng('adminid'),
|
||||
'field' => 'adminid',
|
||||
'sortable' => true,
|
||||
],
|
||||
'adminname' => [
|
||||
'label' => lng('admin.admin'),
|
||||
'field' => 'adminname',
|
||||
'callback' => [Impersonate::class, 'admin'],
|
||||
'sortable' => true,
|
||||
],
|
||||
'size' => [
|
||||
'label' => lng('backup.size'),
|
||||
'field' => 'size',
|
||||
'sortable' => true,
|
||||
],
|
||||
'created_at' => [
|
||||
'label' => lng('backup.created_at'),
|
||||
'field' => 'created_at',
|
||||
'sortable' => true,
|
||||
],
|
||||
],
|
||||
'visible_columns' => Listing::getVisibleColumnsForListing('admin_list', [
|
||||
'id',
|
||||
'adminname',
|
||||
'loginname',
|
||||
'size',
|
||||
'created_at',
|
||||
]),
|
||||
'actions' => [
|
||||
'show' => [
|
||||
'icon' => 'fa-solid fa-eye',
|
||||
'title' => lng('usersettings.custom_notes.title'),
|
||||
'modal' => [Text::class, 'customerNoteDetailModal'],
|
||||
'visible' => [Customer::class, 'hasNote']
|
||||
],
|
||||
'edit' => [
|
||||
'icon' => 'fa-solid fa-edit',
|
||||
'title' => lng('panel.edit'),
|
||||
'href' => [
|
||||
'section' => 'backups',
|
||||
'page' => 'backups',
|
||||
'action' => 'edit',
|
||||
'id' => ':id'
|
||||
],
|
||||
],
|
||||
'delete' => [
|
||||
'icon' => 'fa-solid fa-trash',
|
||||
'title' => lng('panel.delete'),
|
||||
'class' => 'btn-danger',
|
||||
'href' => [
|
||||
'section' => 'backups',
|
||||
'page' => 'backups',
|
||||
'action' => 'delete',
|
||||
'id' => ':id'
|
||||
],
|
||||
'visible' => [Admin::class, 'isNotMe']
|
||||
],
|
||||
],
|
||||
'format_callback' => [
|
||||
[Style::class, 'deactivated'],
|
||||
[Style::class, 'diskspaceWarning'],
|
||||
[Style::class, 'trafficWarning']
|
||||
]
|
||||
]
|
||||
];
|
||||
@@ -32,6 +32,7 @@ const TABLE_MAIL_USERS = 'mail_users';
|
||||
const TABLE_MAIL_VIRTUAL = 'mail_virtual';
|
||||
const TABLE_PANEL_ACTIVATION = 'panel_activation';
|
||||
const TABLE_PANEL_ADMINS = 'panel_admins';
|
||||
const TABLE_PANEL_BACKUPS = 'panel_backups';
|
||||
const TABLE_PANEL_CUSTOMERS = 'panel_customers';
|
||||
const TABLE_PANEL_DATABASES = 'panel_databases';
|
||||
const TABLE_PANEL_DOMAINS = 'panel_domains';
|
||||
|
||||
Reference in New Issue
Block a user