Commit graph

142 commits

Author SHA1 Message Date
Reto Brunner b0ca8e51fb wire up storage cleaner upon server start 2023-12-24 16:55:45 +01:00
Reto Brunner 21b1152f53 cleaner: expose cli task to do cleaning + vacuum
Make the cleaner available to users by exposing it as a subcommand
to thelounge storage.

This is recommended to be run whenever the storage policy significantly
changes in a way that makes many messages eligible for deletion.
The cleaner would cope, but it'll be inefficient and can take many hours.
Due to how storage works in sqlite, the space would not actually be
given back to the OS, just marked for future writes.
Hence this also runs a vacuum to compact the DB as much as it can.
2023-12-24 16:55:45 +01:00
Reto Brunner 74aff7ee5a introduce storage cleaner
Once this is getting hooked up, it'll periodically delete old
messages.

The StoragePolicy can be chosen by the user, currently there's
two versions, delete everything based on age is the obvious.

The other is for the data hoarders among us. It'll only delete
message types which can be considered low value... Types with
a time aspect like away / back... joins / parts etc.

It tries to do that in a sensible way, so that we don't block
all other db writers that are ongoing.
The "periodically" interval is by design not exposed to the user.
2023-12-24 16:55:45 +01:00
Reto Brunner 14d9ff247d sqlite: implement deleteMessages
This is laying the foundation to build a cleaning task that's
sort of database agnostic.
All calls are done by acting on a "DeletionRequest" so interpretation
of the config will go through a single point
2023-12-23 21:08:07 +01:00
Reto Brunner aec8d0b033 sqlite: accept db connection string
This allows us to inject a memory db during testing
2023-12-23 21:08:07 +01:00
Reto Brunner 60ddf17124 sqlite: use variadic function for serialize_run
This makes the usage of the function a bit nicer
2023-12-23 21:08:07 +01:00
Reto Brunner 97f553eea8 cli: don't fail if stderr is not in json format
A user reported in the IRC chan that installing packages fails with

```
2023-12-13 20:02:34 [INFO] Installing thelounge-theme-solarized v1.1.9...
undefined:1
(node:3329) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
^
SyntaxError: Unexpected token '(', "(node:3329"... is not valid JSON
```

Now, this happens as yarn helpfully prints a deprecation warning
that is shown in the stack trace.

Let's assume that we may get non json messages and log them at debug, as we
don't know their severity.
2023-12-13 22:55:53 +01:00
Reto Brunner d1561f8ebc sqlite: return new version in downgrade()
We want to give the caller the current version, not the last
version we rolled back, fix that
2023-11-06 07:52:59 +01:00
Reto Brunner 884a92c74b sqlite: fix typo fetch_rollbacks 2023-11-06 07:52:59 +01:00
Reto Brunner 77b64c546b dont' crash on rDNS failure 2023-11-06 07:36:52 +01:00
Reto Brunner 1c6bec2323 Merge branch 'cliMigrations' 2023-11-04 11:59:41 +01:00
Reto Brunner 8c54cd50d8 don't crash on rDNS failure
Node apparently throws even on valid ipv6 input in certain environments,
probably due to the DNS server returning SERVFAIL.
Guard against it and fallback with the plain IP

Fixes: https://github.com/thelounge/thelounge/issues/4768
2023-11-04 11:45:11 +01:00
Reto Brunner 3af4ad1076 Respect bind setting for all outgoing requests
So far the bind config only impacted the IRC connections.
However, nothing in our doc comment says that this is intentional.

> ### bind
> Set the local IP to bind to for outgoing connections.

This commit fixes the leak and uses it for all outgoing requests
as described by the docstring.
2023-06-25 19:30:52 +02:00
Reto Brunner 2ef8b37009 sqlite: add migrations support and introduce primary key
Add the ability to migrate our db in the upwards direction.
Use the facility to add primary keys to our messages table.
This should allow work like jumping to messages and the likes.

This also introduces the framework for rollback, without actually
hooking it up.
This should be easy enough to do when the need arises.
2023-06-24 14:50:39 +02:00
Reto Brunner 8aa5e33b1d Fix semver for prerelease versions #4744 2023-06-24 14:35:41 +02:00
Reto Brunner 43a2b397a2 Add comments explaining behavior when echo-message is not available 2023-06-24 14:32:33 +02:00
Reto Brunner 14575c94cf Merge branch 'frameworkInternals' 2023-06-24 14:28:48 +02:00
Kufat 7ac2a6fd77 Fix semver for prerelease versions
Noticed this breakage while trying to install a plugin on 4.4.1-rc2.

```
> semver.default.satisfies("4.4.1-rc2", ">=4.3.0")
false
> semver.default.satisfies("4.4.1-rc2", ">=4.3.0", {includePrerelease: true})
true
```
2023-06-01 08:03:07 -04:00
Val Lorentz 4255c1cdec Add comments explaining behavior when echo-message is not available 2023-05-30 22:09:39 +02:00
Reto Brunner 90ad06a29a Fix load of channels from user config
While the commits that caused the problem have been reverted,
this still adds test cases to it and make the loading more robust.
2023-04-08 13:46:13 +02:00
Val Lorentz 0c7cc85184 Fix load of channels from user config
Network.export() only writes the "type" key if it's a ChanType.QUERY;
so the config on disk has no "type".

This causes it to be undefined when loading, which breaks various other
checks, and then drops it the next time the config is saved.
2023-04-08 12:38:06 +02:00
Reto Brunner 3be805bd38 sqlite: Add rollback support
This enables db migrations to be undone, or "down migrated".
The down migration shouldn't be done automatically
as it could lead to severe data loss if that were done.
Hence, we still hard fail if we encounter a version lower than what
we have in the DB.

A CLI will be added in a later commit that allows users to explicitly
do that.
2023-03-31 11:34:26 +02:00
Reto Brunner 2f162daee1 Revert "models/chan: don't force existence of constructor properties"
This reverts commit e31c95e32d.
2023-03-19 21:58:14 +01:00
Reto Brunner 3ac9c36d95 Revert "user: don't force existence of constructor properties"
This reverts commit c3e3322a79.
2023-03-19 21:58:14 +01:00
Reto Brunner c30da27f95 Revert "network: don't force existence of constructor properties"
This reverts commit 429efb0c3c.
2023-03-19 21:58:14 +01:00
Reto Brunner e8b6434144 Clean up command input code 2023-03-19 12:57:08 +01:00
Reto Brunner 4e954b919c server/client: refactor command input
Keep happy path on the left and try to return as early
as we can to help the reader understand the logic better

The function is too large to be able to quickly scan an if / else
chain and see the function return at the end
2023-03-17 11:28:54 +01:00
Val Lorentz 320075e376 Remove override of UserConfig 2023-03-15 11:49:13 +01:00
Val Lorentz a049a01aeb Client: move socket connection out of the constructor
It will make it easier to write tests for what used to be in
the connect() method
2023-03-15 08:40:53 +01:00
Val Lorentz 76098d7e76 Fix incorrect typing of dehydrated networks and channels
Client and ClientManager deal with both 'dehydrated' channels/networks (ie. directly
from JSON configuration) and the 'rehydrated' ones (classes, with socket objects,
message arrays, etc.).

However, because their attributes are similar, both types were used interchangeably,
which becomes an issue when splitting Client's configuration loading into smaller
methods.
2023-03-15 08:40:53 +01:00
Reto Brunner 7f6059d5b7 input/raw: use the irc-framework api
We are not allowed to mess with the connection object directly
according to the public api surface of the framework
2023-03-04 18:17:17 +01:00
Reto Brunner 8ca9ee873b use the irc connected helper function
We should not mess with irc-framework internals.
Technically we shouldn't even access the connection object,
it's not part of the documented API surface
2023-03-04 18:16:28 +01:00
Reto Brunner 402332340b pluginCommand: type it and guard against bad input 2023-03-04 17:00:53 +01:00
Reto Brunner fade6a8d2e network: add getLobby accessor
This documents what we actually want and allows us to shift the
logic to the network
2023-02-27 18:30:33 +01:00
Reto Brunner dfed1dd757 skip migrations if the user has disabled logging 2023-02-27 14:33:34 +01:00
Reto Brunner d67277d996 clientManager: Expose user config 2023-02-27 14:33:34 +01:00
Reto Brunner 95aaba43fa cli: Implement storage migrate subcommand
This introduces the ability to run the migration offline, while
TL is not running as the migrations can take a long time.

The migrate command is added as a `thelounge storage` subcommand.
Reason being that it is expected that more subcommands will follow,
say `thelounge storage clean` to remove partial data from the db.
2023-02-27 14:33:34 +01:00
Reto Brunner 3e7255ff20 sqlite: Add primary keys to the messages table
We want primary keys to never get re-used to so that we
can implement jump to messages / context fetching etc
in the future.

This isn't hooked up yet at all to the rest of the code, only
the schema is changed
2023-02-27 14:20:31 +01:00
Reto Brunner 86e376fc03 sqlite: run migrations on startup 2023-02-27 14:20:31 +01:00
Reto Brunner 899762cddd sqlite: Add infrastructure for migration tests
This sets up the testing infrastructure to test migrations we are
doing.
It's done on a in memory database directly, we are only interested
in the statements themselves and it's easier than to try and
inject a prepared db into the store.

We do add some dummy data though to make sure we actually execute
the things as we expect.
2023-02-27 14:20:29 +01:00
Reto Brunner 063aca948c sqlite: don't hardcode version test 2023-02-27 14:17:04 +01:00
Max Leiter c2e7390127
Merge pull request #4685 from thelounge/networkProps
network: don't force existence of constructor properties
2023-02-26 17:23:23 -08:00
Max Leiter d10a59395c
Merge pull request #4684 from thelounge/userProps
user: don't force existence of constructor properties
2023-02-26 17:22:31 -08:00
Max Leiter 8fc696620f
Merge pull request #4683 from thelounge/chanProps
models/chan: don't force existence of constructor properties
2023-02-26 17:22:06 -08:00
Max Leiter c6a202d6ab
Merge pull request #4686 from thelounge/decoupleServer
Decouple server
2023-02-26 17:20:20 -08:00
Max Leiter 7c9ed14909
Merge pull request #4695 from maxpoulin64/fix/oidentd-crash-race-condition
Don't crash on oidentd socket race condition
2023-02-25 13:44:37 -08:00
Reto Brunner bdc1f23107 fix formatting 2023-02-18 11:46:31 +01:00
Reto Brunner e9a09f5447 Add id to error log 2023-02-18 11:35:52 +01:00
Pavel Djundik 2f04150461 Fix git commit not being available in dist build 2023-02-15 12:03:08 +02:00
Max Leiter 4cff2ccabe
Link to PR in log.warn 2023-02-13 20:51:27 -08:00
Max Leiter 26b7fbf2c0
Apply suggestions from code review
Co-authored-by: Mina Galić <me+github@igalic.co>
2023-02-13 20:50:16 -08:00
Maxime Poulin 243cb10e2a
Don't crash on oidentd socket race condition 2023-02-08 22:05:22 -05:00
Reto Brunner b7540b5827 Move condensedTypes to shared/
This decouples the rest of the server from the client
2023-01-30 09:14:40 +01:00
Reto Brunner 9d34955836 extract cleanIrcMessage from client to shared 2023-01-30 09:14:40 +01:00
Reto Brunner a8149c0f1a Extract linkify to shared directory
This is the first step to sever any dependency of the server on
the client
2023-01-30 09:14:40 +01:00
Reto Brunner e1ae79cb9c server/tsconfig: remove redundant options 2023-01-30 09:14:40 +01:00
Reto Brunner 429efb0c3c network: don't force existence of constructor properties 2023-01-30 08:52:30 +01:00
Reto Brunner c3e3322a79 user: don't force existence of constructor properties 2023-01-30 01:45:58 +01:00
Reto Brunner e31c95e32d models/chan: don't force existence of constructor properties 2023-01-30 00:29:09 +01:00
Reto Brunner 375164ca88 Merge branch 'storageCleanup' 2023-01-22 15:23:56 +01:00
Reto Brunner 0ebc3a574c search: ignore searchResults if it isn't the active query
Prior to this, the search is still racy but one tends to notice
this only when the DB is large or network is involved.
The user can initiate a search, get bored, navigate to another chan
issue a different search.

Now however, the results of the first search come back in and
hilarity ensues as we are now confused with the state.

To avoid this, keep track of the last search done and any result
that comes in that isn't equal to the active query is garbage and
can be dropped.
2023-01-08 11:41:09 +01:00
Reto Brunner 958a948456 sqlite: Remove client from sqlitestorage
The only reason we accepted a client was that so we have access
to the next message id when we need it.
So let's accept an id provider function instead.
2022-12-30 16:52:04 +01:00
Reto Brunner 52b8a2a78e textStorage: rip out client instance
We don't need the client, so there's no need to accept it.
2022-12-30 16:42:48 +01:00
Reto Brunner 661d5cb5b0 messagestorage: remove implementation details from interface
The interface should not contain things that aren't the API of the
storage interface.
Further, rename ISqliteMessageStorage to SearchableMessageStorage,
as that's also an implementation detail.
We'll never have a second sqlite backend, so the name seems
strange.
2022-12-30 16:42:48 +01:00
Reto Brunner 2d4143b779 sqlite: synchronize enable() internally
TL is stupid and doesn't wait for message{Provider,Storage} to
settle before it starts using the store.

While this should be fixed globally, we can hack around the problem
by pushing everything onto the call stack and hope that we'll eventually
finish the setup before we blow the stack.
2022-11-30 10:28:26 +01:00
Reto Brunner deeea274da Merge branch 'sqlite_cleanup'
Converts sqlite to async, providing a way forward
for migrations to actually happen
2022-11-24 09:45:01 +01:00
Reto Brunner d34b58811a Merge branch 'search' 2022-11-24 09:34:24 +01:00
Reto Brunner fd14b4a172 make getClientConfiguration type safe
TS type assertions need to be avoided.

The following trivial example demonstrates why

```
type Person = {
	name: string;
	isBad: boolean;
};

function makePerson(): Person {
	const p: Person = {name: 'whatever'} as Person
	p.isBad = false
	return p // theoretically we are now good, p is a Person
}
```

Should the type ever change though, TS will happily trot along

```
type Person = {
	name: string;
	isBad: boolean;
	omgHowCouldYou: number;
};

function makePerson(): Person {
	const p: Person = {name: 'whatever'} as Person
	p.isBad = true
	return p // p is *not* a Person, omgHowCouldYou is missing
}
```

But we pinky swore to the compiler that p is in fact a Person.
In other words, the types are now wrong and you will fail during
runtime.
2022-11-22 03:07:29 +01:00
Reto Brunner 1597c2c56e server: the http{,s} server can't be null 2022-11-22 02:21:27 +01:00
Reto Brunner 8095d9e88a SearchQuery: offset is always a number
Fix type confusion that specified offset to be a string, it is
always a number.
2022-11-15 18:50:52 +01:00
Reto Brunner d62dd3e62d messageStorage: convert to async
Message stores are more complicated that a sync "fire and forget"
API allows for.
For starters, non trivial stores (say sqlite) can fail during init
and we want to be able to catch that.
Second, we really need to be able to run migrations and such, which
may block (and fail) the activation of the store.

On the plus side, this pushes error handling to the caller rather
than the stores, which is a good thing as that allows us to eventually
push this to the client in the UI, rather than just logging it in the
server on stdout
2022-11-02 00:01:36 +01:00
Reto Brunner f068fd4290 sqlite: convert migrations to async
This removes quite a bunch of indention and callbacks
2022-11-01 22:23:47 +01:00
Reto Brunner bbe81bb2fa sqlite: add serialize_get 2022-11-01 22:23:47 +01:00
Reto Brunner f04a06682d extract migrations 2022-11-01 22:23:47 +01:00
Reto Brunner 5e1cbe32f9 sqlite: use serialize_fetchall in search 2022-11-01 22:23:47 +01:00
Reto Brunner ee8223c200 sqlite: use serialize_fetchall in getMessages 2022-11-01 22:23:47 +01:00
Reto Brunner cc3302e874 sqlite: create serialize_fetchall helper function
That puts all the serialization logic into one place and
allows us to use async / promises
2022-11-01 22:23:47 +01:00
Reto Brunner 89ee537364 sqlite: add run helper function
Extract the serialization logic into a single place and
consistently log errors to the console rather than a fire
and forget approach.
2022-11-01 22:23:30 +01:00
Reto Brunner e62b169a6a sqlite: fix docstring 2022-11-01 22:19:56 +01:00
Reto Brunner f6b292107e sqlite: move export to bottom of the file
This makes it easier to see what's getting exported, rather than
if it's interspersed randomly in the middle of the file
2022-11-01 22:19:56 +01:00
Reto Brunner bea4545abf don't call search on a disabled msg provider
A provider might be available, but not functional (broken migration
invalid configuration or what have you).
Don't try to call search in this case.
2022-11-01 22:19:56 +01:00
Reto Brunner cebc6d069f sqlite: error if sqlite isn't enabled but search() is called
When we assert that something can't possibly happen, we better
error out rather than jugging on with no error ;)
2022-11-01 22:19:56 +01:00
Reto Brunner 30e9f45fac Use nick as a realname fallback
Currently the realname is set to an advertisement if it isn't explicitly
set by the user.
Some clients started to show the realname as a display name in their
UI, which makes this tedious as you'll end up with gazillion "The Lounge
User" entries.

To avoid this, set the realname to the nick on first connect, so that
it is useful.
Note that this isn't done on nick changes, but only on the initial
connect step.

Fixes: https://github.com/thelounge/thelounge/issues/4527
2022-08-28 11:21:54 +02:00
Antonio Mika 117c5fa3fd
Added client type checking to webpack (#4619)
* Added client type checking

* Fixed client-side typescript issues
2022-08-23 00:26:07 -07:00
Reto Brunner 621fa92036 linkPreviews: Enforce TLS validity
When a URL is prefixed with a TLS scheme, we should make sure
that the remote provides a valid cert, even just for prefetches.
Else MITM of such a site is trivial.

This probably breaks some people with self signed cert, but the
age where that was acceptable is past. We have free CAs now like
Let's Encrypt.
2022-08-06 12:37:51 +02:00
Reto Brunner a95ab55154 Merge branch 'installDocs' 2022-08-01 13:29:48 +02:00
Reto Brunner 31739b8ac9 install: Document file: prefix in cli help 2022-07-23 23:05:34 +02:00
Reto Brunner e221e708c1 install: expand ~ for local paths
Make `thelounge install file:~/path/to/package` work rather than
erroring out that the folder doesn't exists.

Probably funny on Windows, but it doesn't hurt either
2022-07-23 17:05:31 +02:00
Reto c8cd4057bc
Fix ctcp request message (#4603)
The message was ordered the wrong way in the TS rewrite.

Old:
    +bookworm sent a CTCP request: "chadler" to version
New:
    +bookworm sent a CTCP request: "version" to chadler
2022-07-06 22:28:18 -07:00
Max Leiter d72d8694bb
Potentially fix saving new networks (#4599) 2022-06-28 13:32:08 -07:00
Pavel Djundik a15ac88ff2 Fix user commands not working
Fixes #4593
2022-06-21 10:51:24 +03:00
Max Leiter dd05ee3a65
TypeScript and Vue 3 (#4559)
Co-authored-by: Eric Nemchik <eric@nemchik.com>
Co-authored-by: Pavel Djundik <xPaw@users.noreply.github.com>
2022-06-18 17:25:21 -07:00