From f0bafed3ceb43d90f2636b38f71bb21ec689214c Mon Sep 17 00:00:00 2001 From: ghost Date: Wed, 21 Feb 2024 09:54:15 +0200 Subject: [PATCH] remove key protocol dependency --- .env | 9 ++- config/services.yaml | 1 + public/css/default.css | 22 +++++++ src/Controller/RoomController.php | 79 ++++++++++++++++---------- templates/default/room/index.html.twig | 12 +++- templates/default/room/index.rss.twig | 6 +- 6 files changed, 89 insertions(+), 40 deletions(-) diff --git a/.env b/.env index da241c1..8b394b8 100644 --- a/.env +++ b/.env @@ -19,7 +19,7 @@ APP_ENV=dev APP_SECRET=EDIT_ME ###< symfony/framework-bundle ### -APP_VERSION=1.11.0 +APP_VERSION=1.12.0 APP_NAME=KevaChat @@ -74,7 +74,10 @@ APP_SESSION_ONLINE_TIMEOUT=900 # Moderators IP with extra permissions, separated with | APP_MODERATOR_REMOTE_IP= -# Username regex rule (must be compatible with APP_ADD_POST_KEY_REGEX) +# Username anon +APP_ADD_USER_NAME_ANON=anon + +# Username regex rule APP_ADD_USER_NAME_REGEX=/^[A-z0-9-_]{1,64}$/ # User name reserved (case insensitive) separated with | @@ -107,7 +110,7 @@ APP_ADD_POST_REMOTE_IP_DENIED= # Post ID rules (for kevacoin key) # do not change to keep external KevaChat nodes compatibility -APP_ADD_POST_KEY_REGEX=/^([\d]{1,64})@([A-z0-9-_]{1,64})$/ +APP_ADD_POST_KEY_REGEX=/.{1,255}/ # Post content rules (for kevacoin value, max length is 3072) # do not change to keep external KevaChat nodes compatibility diff --git a/config/services.yaml b/config/services.yaml index d37cadf..ba6acb0 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -26,6 +26,7 @@ parameters: app.kevacoin.mine.solo.url: '%env(APP_KEVACOIN_MINE_SOLO_URL)%' app.session.default.timeout: '%env(APP_SESSION_DEFAULT_TIMEOUT)%' app.session.online.timeout: '%env(APP_SESSION_ONLINE_TIMEOUT)%' + app.add.user.name.anon: '%env(APP_ADD_USER_NAME_ANON)%' app.add.user.name.regex: '%env(APP_ADD_USER_NAME_REGEX)%' app.add.user.name.blacklist: '%env(APP_ADD_USER_NAME_BLACKLIST)%' app.add.user.remote.ip.delay: '%env(APP_ADD_USER_REMOTE_IP_DELAY)%' diff --git a/public/css/default.css b/public/css/default.css index b583858..e34cdf4 100644 --- a/public/css/default.css +++ b/public/css/default.css @@ -15,6 +15,11 @@ --color-warning: #ee784e; --color-error: #ff6363; --color-default: #999; + + transition: all .1s ease-in; + -webkit-transition: all .2s ease-in; + -moz-transition: all .2s ease-in; + -o-transition: all .2s ease-in; } *::placeholder @@ -170,6 +175,23 @@ main ul li span > svg float: right; } +main ul li small +{ + color: var(--color-default); + display: inline-block; + opacity: 0; +} + +main ul li small svg +{ + vertical-align: top; +} + +main ul li > div:hover > small +{ + opacity: 1; +} + main > form { box-sizing: border-box; diff --git a/src/Controller/RoomController.php b/src/Controller/RoomController.php index 4ea42b1..fe683b7 100644 --- a/src/Controller/RoomController.php +++ b/src/Controller/RoomController.php @@ -229,14 +229,15 @@ class RoomController extends AbstractController } // Require valid kevachat meta - if ($data = $this->_post($pending)) + if ($data = $this->_post($client, $pending)) { // Detect parent post preg_match(self::PARENT_REGEX, $data->message, $mention); - $feed[$data->id] = + $feed[$data->txid] = [ - 'id' => $data->id, + 'txid' => $data->txid, + 'key' => $data->key, 'user' => $data->user, 'time' => $data->time, 'parent' => isset($mention[1]) ? $mention[1] : null, @@ -255,21 +256,16 @@ class RoomController extends AbstractController // Get regular posts foreach ((array) $client->kevaFilter($request->get('namespace')) as $post) { - // Skip values with meta keys - if (str_starts_with($post['key'], '_')) - { - continue; - } - // Require valid kevachat meta - if ($data = $this->_post($post)) + if ($data = $this->_post($client, $post)) { // Detect parent post preg_match(self::PARENT_REGEX, $data->message, $mention); - $feed[$data->id] = + $feed[$data->txid] = [ - 'id' => $data->id, + 'txid' => $data->txid, + 'key' => $data->key, 'user' => $data->user, 'time' => $data->time, 'parent' => isset($mention[1]) ? $mention[1] : null, @@ -579,7 +575,7 @@ class RoomController extends AbstractController } // Check user session exist - $username = 'anon'; + $username = $this->getParameter('app.add.user.name.anon'); if ($request->get('sign') === 'username' && !empty($request->cookies->get('KEVACHAT_SESSION')) && preg_match('/[A-z0-9]{32}/', $request->cookies->get('KEVACHAT_SESSION'))) { @@ -606,7 +602,7 @@ class RoomController extends AbstractController { // Send message by account balance on available if ( - $username != 'anon' + $username != $this->getParameter('app.add.user.name.anon') && $client->getBalance( $username, @@ -617,9 +613,9 @@ class RoomController extends AbstractController $client->kevaPut( $request->get('namespace'), sprintf( - '%d@%s', + '%d%s', time(), - $username + $username != $this->getParameter('app.add.user.name.anon') ? sprintf('@%s', $username) : null ), $request->get('message') ) @@ -688,9 +684,9 @@ class RoomController extends AbstractController $pool->setKey( sprintf( - '%d@%s', + '%d%s', $time, - $username + $username != $this->getParameter('app.add.user.name.anon') ? sprintf('@%s', $username) : null ), ); @@ -742,9 +738,9 @@ class RoomController extends AbstractController $client->kevaPut( $request->get('namespace'), sprintf( - '%d@%s', + '%d%s', time(), - $username + $username != $this->getParameter('app.add.user.name.anon') ? sprintf('@%s', $username) : null ), $request->get('message') ) @@ -1106,7 +1102,10 @@ class RoomController extends AbstractController ); } - private function _post(array $data): ?object + private function _post( + \Kevachat\Kevacoin\Client $client, + array $data + ): ?object { // Validate required data if (empty($data['txid'])) @@ -1124,6 +1123,12 @@ class RoomController extends AbstractController return null; } + // Skip meta records + if (str_starts_with($data['key'], '_')) + { + return null; + } + // Validate key format allowed in settings if (!preg_match((string) $this->getParameter('app.add.post.key.regex'), $data['key'], $key)) { @@ -1136,18 +1141,30 @@ class RoomController extends AbstractController return null; } - // Validate timestamp@username - if (empty($key[1]) || empty($key[2])) + // Get transaction time + if (!$transaction = $client->getRawTransaction($data['txid'])) { return null; } + // Detect username (key @postfix) + if (preg_match('/@([^@]+)$/', $data['key'], $match)) + { + $user = $match[1]; + } + + else + { + $user = $this->getParameter('app.add.user.name.anon'); + } + return (object) [ - 'id' => $data['txid'], - 'time' => $key[1], - 'user' => $key[2], - 'message' => $data['value'] + 'txid' => $data['txid'], + 'key' => $data['key'], + 'message' => $data['value'], + 'time' => $transaction['time'], + 'user' => $user ]; } @@ -1164,7 +1181,7 @@ class RoomController extends AbstractController { $children = $this->_tree( $feed, - $post['id'] + $post['txid'] ); if ($children) @@ -1172,10 +1189,10 @@ class RoomController extends AbstractController $post['tree'] = $children; } - $tree[$post['id']] = $post; + $tree[$post['txid']] = $post; unset( - $feed[$post['id']] + $feed[$post['txid']] ); } } @@ -1214,7 +1231,7 @@ class RoomController extends AbstractController foreach ($raw as $data) { // Is valid post - if ($this->_post($data)) + if ($this->_post($client, $data)) { $total++; } diff --git a/templates/default/room/index.html.twig b/templates/default/room/index.html.twig index 39c2946..56f4359 100644 --- a/templates/default/room/index.html.twig +++ b/templates/default/room/index.html.twig @@ -5,7 +5,7 @@ {% for post in tree %}
  • - + {{ post.user }} @@ -22,10 +22,16 @@ {% else %} - {{ post.time | format_ago }} + {{ post.time | format_ago }} • - {{ 'reply' | trans }} + {{ 'reply' | trans }} {% endif %} + + + + + {{ post.key }} + {# apply markdown whitelist filters only to prevent ping from remote includes #} {{ post.message | message_to_markdown diff --git a/templates/default/room/index.rss.twig b/templates/default/room/index.rss.twig index 6f97712..1bebfcf 100644 --- a/templates/default/room/index.rss.twig +++ b/templates/default/room/index.rss.twig @@ -6,11 +6,11 @@ {{ url('room_namespace', { namespace : request.get('namespace'), _fragment : 'latest' }) }} {% for post in feed %} - {{ post.id }} + {{ post.txid }} {{ post.user }} {{ post.time | date('D, d M Y h:i:s O') }} - {{ url('room_namespace', { namespace : request.get('namespace'), _fragment : post.id }) }} - {{ url('room_namespace', { namespace : request.get('namespace'), _fragment : post.id }) }} + {{ url('room_namespace', { namespace : request.get('namespace'), _fragment : post.txid }) }} + {{ url('room_namespace', { namespace : request.get('namespace'), _fragment : post.txid }) }} {{ post.message | striptags | markdown_to_html | striptags | trim }} {% endfor %}