diff --git a/config/ACL.php b/config/ACL.php index 9bcbba7..e828dcc 100644 --- a/config/ACL.php +++ b/config/ACL.php @@ -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 = [ diff --git a/config/routes.php b/config/routes.php index 256965e..bc1130a 100644 --- a/config/routes.php +++ b/config/routes.php @@ -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); diff --git a/data/locale/en.yml b/data/locale/en.yml index 8f7c327..3dcf57a 100644 --- a/data/locale/en.yml +++ b/data/locale/en.yml @@ -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" \ No newline at end of file diff --git a/src/Control/Actions/PasswordAddAction.php b/src/Control/Actions/PasswordAddAction.php new file mode 100644 index 0000000..b587755 --- /dev/null +++ b/src/Control/Actions/PasswordAddAction.php @@ -0,0 +1,34 @@ +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); + } +} \ No newline at end of file diff --git a/src/Control/Actions/PasswordDeleteAction.php b/src/Control/Actions/PasswordDeleteAction.php new file mode 100644 index 0000000..5f1d6e9 --- /dev/null +++ b/src/Control/Actions/PasswordDeleteAction.php @@ -0,0 +1,23 @@ +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); + } +} \ No newline at end of file diff --git a/src/Control/Actions/PasswordsAction.php b/src/Control/Actions/PasswordsAction.php new file mode 100644 index 0000000..9fb24c7 --- /dev/null +++ b/src/Control/Actions/PasswordsAction.php @@ -0,0 +1,33 @@ +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 + ]); + } +} \ No newline at end of file diff --git a/src/View/material/form_inline.twig b/src/View/material/form_inline.twig index 1446bd9..2812d2e 100644 --- a/src/View/material/form_inline.twig +++ b/src/View/material/form_inline.twig @@ -14,17 +14,42 @@ {% if item %} + id="{{ editable.key }}" value="0" + + {% if editable.readOnly is defined and editable.readOnly == true %} + readonly + {% endif %} + /> + id="{{ editable.key }}" value="1" checked + + {% if editable.readOnly is defined and editable.readOnly == true %} + readonly + {% endif %} + /> {% else %} + id="{{ editable.key }}" value="0" + + {% if editable.readOnly is defined and editable.readOnly == true %} + readonly + {% endif %} + + /> + id="{{ editable.key }}" value="1" + + {% if editable.readOnly is defined and editable.readOnly == true %} + readonly + {% endif %} + /> {% endif %} {% elseif editable.type == 'select' %} - {% 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 %} diff --git a/src/View/material/layout/menu.twig b/src/View/material/layout/menu.twig index d84f9d9..cff92d6 100644 --- a/src/View/material/layout/menu.twig +++ b/src/View/material/layout/menu.twig @@ -37,6 +37,9 @@
  • {% trans %}menu.servers.complains{% endtrans %}
  • + +
  • {% trans %}menu.servers.passwords{% endtrans %}
  • +
  • {% trans %}menu.servers.tokens{% endtrans %}
  • diff --git a/src/View/material/passwords.twig b/src/View/material/passwords.twig new file mode 100644 index 0000000..d0e19be --- /dev/null +++ b/src/View/material/passwords.twig @@ -0,0 +1,47 @@ +{% extends 'layout.twig' %} + +{% block content %} +

    {{ title }}

    + +

    {% trans %}passwords.h.actions{% endtrans %}

    + + {% include 'form.twig' with { + 'fields': [ + { + 'header_label': 'passwords.add'|trans, + 'label': 'check_circle', + '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 %} +

    {% trans %}passwords.h.details{% endtrans %}

    + {% 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': 'delete', + 'readOnly': true + } + ] + } %} + {% endif %} +{% endblock %} \ No newline at end of file