Created export button for server list
Created page for for import upload Created function to receive datapull/1133/head
parent
e28192278c
commit
5aa3fd6f6a
|
@ -50,6 +50,8 @@ $sm_lang = array(
|
||||||
'no' => 'No',
|
'no' => 'No',
|
||||||
'insert' => 'Insert',
|
'insert' => 'Insert',
|
||||||
'add_new' => 'Add new',
|
'add_new' => 'Add new',
|
||||||
|
'export_config' => 'Export Configuration',
|
||||||
|
'import_config' => 'Import Configuration',
|
||||||
'update_available' => 'A new version ({version}) is available. Click <a href="https://github.com/phpservermon/phpservermon/releases/latest" target="_blank" rel="noopener">here</a> to download the update.',
|
'update_available' => 'A new version ({version}) is available. Click <a href="https://github.com/phpservermon/phpservermon/releases/latest" target="_blank" rel="noopener">here</a> to download the update.',
|
||||||
'back_to_top' => 'Back to top',
|
'back_to_top' => 'Back to top',
|
||||||
'go_back' => 'Go back',
|
'go_back' => 'Go back',
|
||||||
|
|
|
@ -29,6 +29,9 @@
|
||||||
namespace psm\Module\Server\Controller;
|
namespace psm\Module\Server\Controller;
|
||||||
|
|
||||||
use psm\Service\Database;
|
use psm\Service\Database;
|
||||||
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Server module. Add/edit/delete servers, show a list of all servers etc.
|
* Server module. Add/edit/delete servers, show a list of all servers etc.
|
||||||
|
@ -50,16 +53,77 @@ class ServerController extends AbstractServerController
|
||||||
|
|
||||||
$this->setCSRFKey('server');
|
$this->setCSRFKey('server');
|
||||||
$this->setActions(array(
|
$this->setActions(array(
|
||||||
'index', 'edit', 'save', 'delete', 'view',
|
'index', 'edit', 'save', 'delete', 'view', 'export', 'import', 'importpost'
|
||||||
), 'index');
|
), 'index');
|
||||||
|
|
||||||
// make sure only admins are allowed to edit/delete servers:
|
// make sure only admins are allowed to edit/delete servers:
|
||||||
$this->setMinUserLevelRequiredForAction(PSM_USER_ADMIN, array(
|
$this->setMinUserLevelRequiredForAction(PSM_USER_ADMIN, array(
|
||||||
'delete', 'edit', 'save'
|
'delete', 'edit', 'save', 'export'
|
||||||
));
|
));
|
||||||
$this->twig->addGlobal('subtitle', psm_get_lang('menu', 'server'));
|
$this->twig->addGlobal('subtitle', psm_get_lang('menu', 'server'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Exports a JSON file with the server configuration
|
||||||
|
*/
|
||||||
|
protected function executeExport()
|
||||||
|
{
|
||||||
|
$request = new Request();
|
||||||
|
$response = new Response(
|
||||||
|
json_encode($this->getServers()),
|
||||||
|
200,
|
||||||
|
['Content-Type' => 'application/json']
|
||||||
|
);
|
||||||
|
|
||||||
|
$response->prepare($request);
|
||||||
|
$response->send();
|
||||||
|
return exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Import settings page
|
||||||
|
*/
|
||||||
|
protected function executeImport()
|
||||||
|
{
|
||||||
|
$sidebar = new \psm\Util\Module\Sidebar($this->twig);
|
||||||
|
$this->setSidebar($sidebar);
|
||||||
|
if ($this->getUser()->getUserLevel() == PSM_USER_ADMIN) {
|
||||||
|
$modal = new \psm\Util\Module\Modal($this->twig, 'delete', \psm\Util\Module\Modal::MODAL_TYPE_DANGER);
|
||||||
|
$this->addModal($modal);
|
||||||
|
$modal->setTitle(psm_get_lang('servers', 'delete_title'));
|
||||||
|
$modal->setMessage(psm_get_lang('servers', 'delete_message'));
|
||||||
|
$modal->setOKButtonLabel(psm_get_lang('system', 'delete'));
|
||||||
|
|
||||||
|
$tpl_data = [
|
||||||
|
'label_upload' => 'Upload',
|
||||||
|
'url_save' => psm_build_url(array(
|
||||||
|
'mod' => 'server',
|
||||||
|
'action' => 'importpost',
|
||||||
|
'back_to' => ""
|
||||||
|
))
|
||||||
|
];
|
||||||
|
|
||||||
|
return $this->twig->render('module/server/server/import.tpl.html', $tpl_data);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return $this->executeIndex();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Import post page
|
||||||
|
*/
|
||||||
|
protected function executeImportpost()
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* - Load file from $_FILES
|
||||||
|
* - Check if valid JSON
|
||||||
|
* - List all allowed fields
|
||||||
|
* - foreach (check if exists, else import)
|
||||||
|
*
|
||||||
|
* Check if exists based on?
|
||||||
|
*/
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Prepare the template to show a list of all servers
|
* Prepare the template to show a list of all servers
|
||||||
*/
|
*/
|
||||||
|
@ -86,6 +150,24 @@ class ServerController extends AbstractServerController
|
||||||
'success',
|
'success',
|
||||||
psm_get_lang('system', 'add_new')
|
psm_get_lang('system', 'add_new')
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$sidebar->addButton(
|
||||||
|
'export_config',
|
||||||
|
psm_get_lang('system', 'export_config'),
|
||||||
|
psm_build_url(array('mod' => 'server', 'action' => 'export')),
|
||||||
|
'arrow-down',
|
||||||
|
'success',
|
||||||
|
psm_get_lang('system', 'export_config')
|
||||||
|
);
|
||||||
|
|
||||||
|
$sidebar->addButton(
|
||||||
|
'import_config',
|
||||||
|
psm_get_lang('system', 'import_config'),
|
||||||
|
psm_build_url(array('mod' => 'server', 'action' => 'import')),
|
||||||
|
'arrow-up',
|
||||||
|
'success',
|
||||||
|
psm_get_lang('system', 'import_config')
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
$sidebar->addButton(
|
$sidebar->addButton(
|
||||||
|
|
|
@ -33,6 +33,22 @@
|
||||||
</div>
|
</div>
|
||||||
{% endmacro input_select %}
|
{% endmacro input_select %}
|
||||||
|
|
||||||
|
|
||||||
|
{% macro input_upload(id, name, label, help, help_label) %}
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="{{ id }}">{{ label }}</label> <br \>
|
||||||
|
<input type="file" id="{{ id }}" name="{{ name }}"
|
||||||
|
{% if help %}aria-describedby="{{ help }}"{% endif %}>
|
||||||
|
|
||||||
|
{% if help %}
|
||||||
|
<small id="{{ help }}" class="form-text text-muted">{{
|
||||||
|
help_label|striptags('<a>,<b>,<br>')|raw }}</small>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
</div>
|
||||||
|
{% endmacro input_upload %}
|
||||||
|
|
||||||
|
|
||||||
{% macro input_select_multiple(id, name, label, placeholder, options, select_message) %}
|
{% macro input_select_multiple(id, name, label, placeholder, options, select_message) %}
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="{{ id }}">{{ label }}</label>
|
<label for="{{ id }}">{{ label }}</label>
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
{% import 'main/macros.tpl.html' as macro %}
|
||||||
|
<form name="importpost" action="{{ url_save|raw }}" class="col-md-6 pl-0 pr-0" id="importpost" method="post"
|
||||||
|
autocomplete="off" enctype="multipart/form-data">
|
||||||
|
<fieldset>
|
||||||
|
<legend>{{ titlemode }}</legend>
|
||||||
|
<div class="col">
|
||||||
|
<!-- Label -->
|
||||||
|
{{ macro.input_upload("import_upload", "import_upload", "Upload Configuration", null, null) }}
|
||||||
|
|
||||||
|
<!-- Submit -->
|
||||||
|
<legend>{{ label_upload }}</legend>
|
||||||
|
{{ macro.button_save(null, label_upload) }}
|
||||||
|
<a class="btn" href="{{ url_go_back|raw }}">Go Back</a>
|
||||||
|
{{ macro.input_csrf() }}
|
||||||
|
</form>
|
Loading…
Reference in New Issue