Commit Graph

913 Commits

Author SHA1 Message Date
Simon Ser
2a3ae55f52
Add a sasl set-plain command
This allows to manually set the SASL credentials for a network.
2020-07-22 12:16:13 +02:00
Simon Ser
cd3eacdbfc
go fmt 2020-07-22 12:16:01 +02:00
Simon Ser
360ce5b72d
doc: document the network update command 2020-07-22 12:04:26 +02:00
Simon Ser
dcfe206bda
Implement CHATHISTORY AFTER
References: https://todo.sr.ht/~emersion/soju/12
2020-07-15 17:47:57 +02:00
Simon Ser
25d4312e0f
Prevent error handler from falling through in user.run 2020-07-09 14:20:23 +02:00
Simon Ser
907da56311
Add unix as supported upstream URL scheme to service 2020-07-09 12:19:51 +02:00
Simon Ser
1ac895430a
contrib/znc-import: new utility
Allows populating the soju database from a ZNC config file.
2020-07-09 11:25:25 +02:00
Simon Ser
7ebe47ad4a
Fix deadlock in DB.Close
This method was calling itself, instead of the underlying SQLite
database's Close method.
2020-07-09 11:23:51 +02:00
Simon Ser
51dc9f0bf9
Broadcast unhandled messages to downstream connections
In case labelled-response isn't supported, broadcast unhandled messages
to all downstream connections. That's better than silently dropping the
messages.
2020-07-08 18:21:52 +02:00
Simon Ser
1685ba23b3
Strip network name from nickname when auto-saving network 2020-07-06 18:13:40 +02:00
Simon Ser
85fad93a71
Add support for upstream Unix socket connections
References: https://todo.sr.ht/~emersion/soju/51
2020-07-06 17:31:11 +02:00
Simon Ser
7af21d9d81
Parse upstream URLs with net/url
This allows us to ignore the path part of the URL. This is preliminary
work for unix URLs.
2020-07-06 17:18:13 +02:00
Simon Ser
b46a2554e1
Check upstream address with net.SplitHostPort
Looking for a colon is incorrect, IPv6 addresses can contain colons too.
2020-07-06 16:04:56 +02:00
Simon Ser
c490705fee
Sort and split JOIN messages
Sort channels so that channels with a key appear first. Split JOIN
messages so that we don't reach the message size limit.
2020-07-06 11:06:20 +02:00
Simon Ser
4c8b01fb51
Make length check clearer in sendNames 2020-07-06 10:59:34 +02:00
Simon Ser
82990fb774
Accept "irc" WebSocket subprotocol 2020-07-02 11:05:49 +02:00
Simon Ser
3397965dea
Add RemoteAddr to ircConn interface 2020-07-01 17:02:37 +02:00
Hubert Hirtz
dc59263681
Send compact channel name lists
This commit resolves `sendNames`' TODO.
2020-06-30 10:28:05 +02:00
Simon Ser
a9887114d5
Only read X-Forwarded-* if remote address is loopback 2020-06-29 18:33:23 +02:00
Simon Ser
2c172fa8ca
Extract X-Forwarded-* headers for WebSocket connections 2020-06-29 18:27:43 +02:00
Simon Ser
90250f5be5
Reply to WHO BouncerServ
Closes: https://todo.sr.ht/~emersion/soju/75
2020-06-29 18:09:48 +02:00
Simon Ser
d26194f62d
Handle registration failures
References: https://todo.sr.ht/~emersion/soju/30
2020-06-29 17:52:49 +02:00
Simon Ser
0fa07f5f9a
Return io.EOF on websocket connection closure 2020-06-29 10:24:41 +02:00
Hubert Hirtz
cfb1de044e
Don't save corrupted NickServ credentials
soju saved most NickServ messages[0] as credentials because of a missing
`default` clause in the check of the NickServ command.

[0] messages that had at least a command and two other parameters
2020-06-24 23:02:46 +02:00
Simon Ser
6c453aa5ca
service: list commands in lexicographic order 2020-06-24 12:08:35 +02:00
delthas
2232b3128b Fix sending messages from detached channels
Currently, a downstream receives MODE, RPL_CHANNELMODEIS and
RPL_CREATIONTIME messages from soju for detached channels. It should not
be sent any of these messages.

This adds a detach check to the handling of these messages to avoid
receiving these messages.
2020-06-12 14:43:45 +02:00
Simon Ser
ccf9cff351
readme: extend copyright notice to all contributors
soju now has multiple contributors. Even if they weren't explicitly
listed as copyright holders, they still retain copyright ownership for
their contributions. Make this clear. See [1].

[1]: https://www.linuxfoundation.org/blog/2020/01/copyright-notices-in-open-source-software-projects/
2020-06-12 14:37:43 +02:00
Simon Ser
33a69edbfe
readme: add link to website 2020-06-10 23:00:50 +02:00
Simon Ser
67f8773320
Fix missing appendServiceCommandSetHelp argument 2020-06-10 16:34:45 +02:00
fox.cpp
ce37fcc7c2
Do not panic if BouncerServ command without handler is sent 2020-06-10 16:33:13 +02:00
Kenny Levinsen
1cbdb26dd1
service: Handle zero-value in stringPtrFlag.String
FlagSet.PrintDefaults uses reflection to construct a zero value, calls
.String on it, and compares the result with the current flag value to
detect zero-value flags. For stringPtrFlag, this would result in a
panic, as String() always dereferenced the first level of its **string.

Add another check so that both pointer levels are nil-checked.
2020-06-10 16:18:15 +02:00
Simon Ser
18250311b9
ci: check scdoc is happy 2020-06-10 16:15:20 +02:00
Kenny Levinsen
7e7393bd23
docs: Fix manpage syntax 2020-06-10 16:10:17 +02:00
delthas
21af06302a sojuctl: Add support for creating admin users
This adds a new flag, `-admin` for creating admin users, which can
access admin service commands, among which create-user to create other
users on-the-fly.

Since the person running the commands in the README will be the local
soju administrator, the user they create should be admin as well, hence
the README update.
2020-06-08 22:30:09 +02:00
delthas
5be25711c7 Add support for the user create admin service command
This adds support for user create, a new service command only accessible
to admin users. This lets users create other users on the fly and makes
soju start the user routine immediately; unlike sojuctl which currently
requires closing soju, creating the user, and starting soju again.
2020-06-08 22:30:09 +02:00
delthas
f5611ae3f9 Add support for admin-restricted service commands
This is preparatory work for creating new users from a service command.

This adds support for specifying specific service commands as
admin-restricted. Only admin users can run these commands. These
commands won't show up in the help when run from a non-admin
user, unless the user is requesting help for that specific command.
2020-06-08 22:30:09 +02:00
delthas
d1b4faa529 Add an admin flag to users
This is preparatory work for letting some users access admin-exclusive
service commands, such as creating new users.

This adds a boolean admin flag to the User schema. Old users will stay
non-admin after the DB migration.
2020-06-08 22:30:09 +02:00
delthas
ed943f5451 Fix: Check the stdin scanner for errors when reading the password
Reading from stdin with Scanner.Scan() can either fail because of a read
error, or return no bytes because the EOF was reached.

This adds support for checking these cases before actually reading the
password.
2020-06-08 22:30:09 +02:00
delthas
17fe033adc Rename handleServiceCreateNetwork to handleServiceNetworkCreate
This renames handleServiceCreateNetwork for consistency with other
service commands.
2020-06-08 22:30:09 +02:00
Simon Ser
998546cdc3
Introduce User.Created
For Network and Channel, the database only needed to define one Store
operation to create/update a record. However since User is missing an ID
we couldn't have a single StoreUser function like other types. We had
CreateUser and UpdatePassword. As new User fields get added (e.g. the
upcoming Admin flag) this isn't sustainable.

We could have CreateUser and UpdateUser, but this wouldn't be consistent
with other types. Instead, introduce User.Created which indicates
whether the record is already stored in the DB. This can be used in a
new StoreUser function to decide whether we need to UPDATE or INSERT
without relying on SQL constraints and INSERT OR UPDATE.

The ListUsers and GetUser functions set User.Created to true.
2020-06-08 11:59:03 +02:00
Simon Ser
d0cf1d2882
Add support for WebSocket connections
WebSocket connections allow web-based clients to connect to IRC. This
commit implements the WebSocket sub-protocol as specified by the pending
IRCv3 proposal [1].

WebSocket listeners can now be set up via a "wss" protocol in the
`listen` directive. The new `http-origin` directive allows the CORS
allowed origins to be configured.

[1]: https://github.com/ircv3/ircv3-specifications/pull/342
2020-06-07 14:13:46 +02:00
Simon Ser
4b3469335e
Fail auth on empty password in DB 2020-06-06 12:52:22 +02:00
Simon Ser
e54293cd0e
doc: update URL to sr.ht hub in man page 2020-06-06 00:23:25 +02:00
Simon Ser
409b05e2d6
doc: add missing change-password service command 2020-06-06 00:21:37 +02:00
delthas
f7894e612b Add support for downstream CHATHISTORY
This adds support for the WIP (at the time of this commit)
draft/chathistory extension, based on the draft at [1] and the
additional comments at [2].

This gets the history by parsing the chat logs, and is therefore only
enabled when the logs are enabled and the log path is configured.

Getting the history only from the logs adds some restrictions:
- we cannot get history by msgid (those are not logged)
- we cannot get the users masks (maybe they could be inferred from the
  JOIN etc, but it is not worth the effort and would not work every
  time)

The regular soju network history is not sent to clients that support
draft/chathistory, so that they can fetch what they need by manually
calling CHATHISTORY.

The only supported command is BEFORE for now, because that is the only
required command for an app that offers an "infinite history scrollback"
feature.

Regarding implementation, rather than reading the file from the end in
reverse, we simply start from the beginning of each log file, store each
PRIVMSG into a ring, then add the last lines of that ring into the
history we'll return later. The message parsing implementation must be
kept somewhat fast because an app could potentially request thousands of
messages in several files. Here we are using simple sscanf and indexOf
rather than regexps.

In case some log files do not contain any message (for example because
the user had not joined a channel at that time), we try up to a 100 days
of empty log files before giving up.

[1]: https://github.com/prawnsalad/ircv3-specifications/pull/3/files
[2]: https://github.com/ircv3/ircv3-specifications/pull/393/files#r350210018
2020-06-05 23:50:31 +02:00
fox.cpp
1fa5195b2f
Fix handling of empty response to SASL challenge 2020-06-05 11:35:43 +02:00
Simon Ser
6c1634799a
Allow multiple listeners, default to ircs
Users can now specify multiple "listen" directives in their
configuration file. If -listen is specified on the CLI, it's added to
the list of listeners.

Listeners are now parsed as URLs. If the scheme is missing "ircs" is
assumed. URLs allow to enable/disable TLS on a per-listener basis and
will be used for Unix sockets too.

The default listening address is changed from irc+insecure://:6667 to
ircs://:6697. This avoids setting up an insecure listener opened to
everybody.
2020-06-04 20:16:23 +02:00
Simon Ser
754adc36fb
Remove keepAlivePeriod
This is a remnant of setKeepAlive.

Fixes: 77faf72fa3 ("Remove setKeepAlive")
2020-06-04 18:38:04 +02:00
Simon Ser
283d4bf14c
Introduce ircConn
This interface will allow a conn to be backed by a websocket.
2020-06-04 17:27:57 +02:00
Simon Ser
77faf72fa3
Remove setKeepAlive
Go sets a default keep-alive interval of 15 seconds on all TCP
connections, if the platform supports it. See
net.ListenConfig.KeepAlive and net.Dialer.KeepAlive.
2020-06-04 16:58:31 +02:00