Archived
1
0
Fork 0

Add temporary passwords

This commit is contained in:
Varakh 2018-04-06 14:17:03 +02:00
parent 871dfa5675
commit ccc686ae28
9 changed files with 204 additions and 5 deletions

View file

@ -89,6 +89,10 @@ class ACL extends \Zend\Permissions\Acl\Acl
'/complains/{sid}',
'/complains/delete/{sid}/{tcldbid}',
'/passwords/{sid}',
'/passwords/add/{sid}',
'/passwords/delete/{sid}',
];
const ACL_DEFAULT_ALLOWS = [

View file

@ -326,3 +326,19 @@ $container[SnapshotDeleteAction::class] = function ($container) {
return new SnapshotDeleteAction($container);
};
$app->get('/snapshots/delete/{sid}/{name}', SnapshotDeleteAction::class);
// passwords
$container[PasswordsAction::class] = function ($container) {
return new PasswordsAction($container);
};
$app->get('/passwords/{sid}', PasswordsAction::class);
$container[PasswordAddAction::class] = function ($container) {
return new PasswordAddAction($container);
};
$app->post('/passwords/add/{sid}', PasswordAddAction::class);
$container[PasswordDeleteAction::class] = function ($container) {
return new PasswordDeleteAction($container);
};
$app->post('/passwords/delete/{sid}', PasswordDeleteAction::class);

View file

@ -63,6 +63,7 @@ menu.servers.clients: "Clients"
menu.servers.groups: "Groups"
menu.servers.bans: "Bans"
menu.servers.complains: "Complains"
menu.servers.passwords: "Passwords"
menu.servers.tokens: "Tokens"
menu.servers.snapshots: "Snapshots"
menu.servers.logs: "Log"
@ -86,6 +87,7 @@ channelgroup_info.title: "Channelgroup"
profile.title: "Profile"
tokens.title: "Tokens"
snapshots.title: "Snapshots"
passwords.title: "Passwords"
# dynamic render of key value pairs
key: "Attribute"
@ -244,3 +246,12 @@ snapshots.h.details: "Details"
snapshots.deploy: "Deploy"
snapshots.delete: "Delete"
# passwords
passwords.h.actions: "Actions"
passwords.h.details: "Details"
passwords.add: "Add a temporary password"
passwords.add.password: "Password"
passwords.add.duration: "Duration (in seconds)"
passwords.add.description: "Description"
passwords.add.channel: "Channel (user joins)"
passwords.add.channel_password: "Channelpassword"

View file

@ -0,0 +1,34 @@
<?php
use Slim\Http\Request;
use Slim\Http\Response;
final class PasswordAddAction extends AbstractAction
{
public function __invoke(Request $request, Response $response, $args)
{
$sid = $args['sid'];
$body = $request->getParsedBody();
$password = $body['password'];
$duration = $body['duration'];
$description = $body['description'];
$channel = $body['channel'];
$channelPassword = $body['channel_password'];
$this->ts->login($this->auth->getIdentity()['user'], $this->auth->getIdentity()['password']);
$selectResult = $this->ts->getInstance()->selectServer($sid, 'serverId');
$passwordAddResult = $this->ts->getInstance()->serverTempPasswordAdd(
$password,
$duration,
$description,
$channel,
$channelPassword
);
$this->flash->addMessage('success', $this->translator->trans('done'));
return $response->withRedirect('/passwords/' . $sid);
}
}

View file

@ -0,0 +1,23 @@
<?php
use Slim\Http\Request;
use Slim\Http\Response;
final class PasswordDeleteAction extends AbstractAction
{
public function __invoke(Request $request, Response $response, $args)
{
$sid = $args['sid'];
$body = $request->getParsedBody();
$password = $body['pw_clear'];
$this->ts->login($this->auth->getIdentity()['user'], $this->auth->getIdentity()['password']);
$selectResult = $this->ts->getInstance()->selectServer($sid, 'serverId');
$passwordDeleteResult = $this->ts->getInstance()->serverTempPasswordDel($password);
$this->flash->addMessage('success', $this->translator->trans('done'));
return $response->withRedirect('/passwords/' . $sid);
}
}

View file

@ -0,0 +1,33 @@
<?php
use Slim\Http\Request;
use Slim\Http\Response;
final class PasswordsAction extends AbstractAction
{
public function __invoke(Request $request, Response $response, $args)
{
$sid = $args['sid'];
$this->ts->login($this->auth->getIdentity()['user'], $this->auth->getIdentity()['password']);
$selectResult = $this->ts->getInstance()->selectServer($sid, 'serverId');
$dataResult = $this->ts->getInstance()->serverTempPasswordList();
$channelsResult = $this->ts->getInstance()->channelList();
$channelsResult = $this->ts->getInstance()->getElement('data', $channelsResult);
$channels = [];
$channels['---'] = 0;
foreach ($channelsResult as $channel) {
$channels[$channel['channel_name']] = $channel['cid'];
}
// render GET
$this->view->render($response, 'passwords.twig', [
'title' => $this->translator->trans('passwords.title'),
'data' => $this->ts->getInstance()->getElement('data', $dataResult),
'channels' => $channels,
'sid' => $sid
]);
}
}

View file

@ -14,17 +14,42 @@
{% if item %}
<input type="hidden" name="{{ editable.key }}"
id="{{ editable.key }}" value="0"/>
id="{{ editable.key }}" value="0"
{% if editable.readOnly is defined and editable.readOnly == true %}
readonly
{% endif %}
/>
<input type="checkbox" name="{{ editable.key }}"
id="{{ editable.key }}" value="1" checked/>
id="{{ editable.key }}" value="1" checked
{% if editable.readOnly is defined and editable.readOnly == true %}
readonly
{% endif %}
/>
{% else %}
<input type="hidden" name="{{ editable.key }}"
id="{{ editable.key }}" value="0" />
id="{{ editable.key }}" value="0"
{% if editable.readOnly is defined and editable.readOnly == true %}
readonly
{% endif %}
/>
<input type="checkbox" name="{{ editable.key }}"
id="{{ editable.key }}" value="1" />
id="{{ editable.key }}" value="1"
{% if editable.readOnly is defined and editable.readOnly == true %}
readonly
{% endif %}
/>
{% endif %}
{% elseif editable.type == 'select' %}
<select class="form-control" name="{{ editable.key }}" id="{{ editable.key }}">
<select class="form-control" name="{{ editable.key }}" id="{{ editable.key }}"
{% if editable.readOnly is defined and editable.readOnly == true %}
readonly
{% endif %}
>
{% for k,v in editable.options %}
{% if v == item %}
@ -40,6 +65,9 @@
{% else %}
value="{{ item }}"
{% endif %}
{% if editable.readOnly is defined and editable.readOnly == true %}
readonly
{% endif %}
/>
{% endif %}

View file

@ -37,6 +37,9 @@
<a href="/complains/{{ session_get('sid') }}">
<li class="active withripple" data-target="#page">{% trans %}menu.servers.complains{% endtrans %}</li>
</a>
<a href="/passwords/{{ session_get('sid') }}">
<li class="active withripple" data-target="#page">{% trans %}menu.servers.passwords{% endtrans %}</li>
</a>
<a href="/tokens/{{ session_get('sid') }}">
<li class="active withripple" data-target="#page">{% trans %}menu.servers.tokens{% endtrans %}</li>
</a>

View file

@ -0,0 +1,47 @@
{% extends 'layout.twig' %}
{% block content %}
<h1 class="header">{{ title }}</h1>
<h2 class="header">{% trans %}passwords.h.actions{% endtrans %}</h2>
{% include 'form.twig' with {
'fields': [
{
'header_label': 'passwords.add'|trans,
'label': '<i class="material-icons">check_circle</i>',
'uri': '/passwords/add/' ~ sid,
'uri_method': 'post',
'fields': [
{'type': 'text', 'key': 'password', 'label': 'passwords.add.password'|trans},
{'type': 'number', 'key': 'duration', 'label': 'passwords.add.duration'|trans},
{'type': 'text', 'key': 'description', 'label': 'passwords.add.description'|trans},
{'type': 'select', 'key': 'channel', 'options': channels,'label': 'passwords.add.channel'|trans},
{'type': 'text', 'key': 'channel_password', 'label': 'passwords.add.channel_password'|trans},
]
},
]
} %}
{% if data|length > 0 %}
<h2 class="header">{% trans %}passwords.h.details{% endtrans %}</h2>
{% include 'table.twig' with {'data': data,
'hiddenColumns': ['uid', 'tcpw'],
'filters': [{'key': 'start', 'apply': 'timestamp'}, {'key': 'end', 'apply': 'timestamp'}],
'links': [
{'key': 'tcid', 'uri': '/channels/' ~ sid, 'uri_param': 'tcid'},
],
'attributesEditable': [
{
'key': 'pw_clear',
'type': 'text',
'uri': '/passwords/delete/' ~ sid,
'uri_method': 'post',
'submit_label': '<i class="material-icons">delete</i>',
'readOnly': true
}
]
} %}
{% endif %}
{% endblock %}