patrix/README.md

100 lines
5.3 KiB
Markdown
Raw Permalink Normal View History

2017-09-10 11:54:43 +02:00
patrix is a simple command line client for [Matrix](https://matrix.org) written in perl. It can create and configure rooms, send text messages or files to rooms. I use it to send [Zabbix](https://www.zabbix.com) alerts to a Matrix room, a bit like [sendxmpp](https://github.com/lhost/sendxmpp) can do with XMPP.
2017-09-06 15:43:25 +02:00
It requires the following perl modules
* LWP::UserAgent
* HTTP::Request
* LWP::Protocol::https
2017-09-06 15:43:25 +02:00
* Config::Simple
* File::HomeDir
2017-09-07 12:46:40 +02:00
* File::Basename
* File::MimeInfo
2017-09-13 16:56:21 +02:00
* File::Spec
2017-09-06 15:43:25 +02:00
* Getopt::Long
2017-09-07 15:03:46 +02:00
* URI::Escape
2017-09-06 15:43:25 +02:00
* JSON
2017-09-10 10:33:33 +02:00
* Term::ReadKey
* Hash::Merge::Simple
* Scalar::Util
2017-09-06 15:43:25 +02:00
2017-09-10 11:54:43 +02:00
Here're the vailable options:
2017-09-06 15:43:25 +02:00
* --user: specify the user you want to login as
* --password: the password to auth against the HS
* --server: the HS you want to connect to. Default is https://matrix.org
2018-02-22 12:05:33 +01:00
* --proxy: use an HTTP proxy to access the HS. If not specified, will try to get system wide proxy (see LWP::UserAgent->env_proxy)
* --access-token: can be used instead of --user and --password. Use --get-access-token to get one first for example.
* --room: the room to which the message must be sent. Can be a room ID or a room alias
2017-09-06 15:43:25 +02:00
* --message: the text message you want to send. If you send something on stdin, it's assumed to be the text to send and this option is ignored
* --debug: if present, will be verbose
* --config: path to a conf file. Default conf file is ~/.patrixrc
2017-09-13 17:37:50 +02:00
* --file: if action is send-file, specify the path of the file to send. You can send several files at once by using multiple --file args
2017-09-09 16:42:11 +02:00
* --invite: a matrix ID (@user:server.domain.tld) to invite in a room. Can be specified several times. Valid for create-room and modify-room
* --name: set the name of a room. Valid for create-room and modify-room
* --topic: set the topic of a room. Valid for create-room and modify-room
* --alias: set an alias for a room. Valid for create-room and modify-room
* --join-rules: change joining rules. Can be either public (anyone can join the room) or invite (you must be invited to join the room)
* --perm: set power levels on the room. Can be specified several times. See examples
* --user-perm: set user levels on the room. Can be specified several times. See examples
* --event-perm: set power levels requires to send specific state events. Can be specified several times. See examples
* --reset-perm: the default behavior of the various --perm args is to add or override specific permissions without changing the others already existing permissions. If this flag is set, the previous permissions will be removed, and the one specified with the --perm arg will be applied. The only exception is for user power levels which are at least as high as the operator (including the operator). These user power levels will be kept even is --reset-perm is set
2017-09-06 15:43:25 +02:00
* --action: what to do. Valid actions are
2017-09-24 14:06:30 +02:00
* setup: write a config file
2017-09-06 15:43:25 +02:00
* send-msg (default): send the text message
* send-message: an alias for send-msg
* send-notice: send a notice. Very similar to send-msg but the client may display it differently. Eg Riot will not notify you for notices
2017-11-24 12:30:29 +01:00
* send-code: same as send-msg, but text will be presented like code (<pre><code>text</code></pre>)
2017-09-07 12:46:40 +02:00
* send-file: send a binary file. --file must be set
2017-09-07 17:54:12 +02:00
* create-room: create a new room
2017-09-10 10:33:33 +02:00
* modify-room: change an existing room (add an alias, set name, topic, join_rules, invite)
2017-09-10 16:59:32 +02:00
* del-room-alias: remove an existing room alias
2017-09-06 15:43:25 +02:00
* get-access-token: just login and print the access token
2017-09-06 16:21:16 +02:00
* get-room-list: prints the list of public rooms of this server
* get-room-id: resolve a room alias to its ID
2017-09-06 15:43:25 +02:00
2017-09-24 14:06:30 +02:00
All the actions can be specified either with --action=foo or as --fo (eg --action=send-file is equivalent to --send-file)
2017-09-06 15:43:25 +02:00
All the available options can be set a the configuration file using a simple ini style format, eg
2017-09-06 15:46:45 +02:00
```
2017-09-06 15:43:25 +02:00
user=alert
password=p@ssw0rd
room=!BWdARvAgNQGgSjgtAG:matrix.domain.com
2017-09-06 15:46:45 +02:00
```
Options given on the command line take precedence over the config file
2017-09-07 15:08:31 +02:00
Examples:
* Send the content of /var/log/boot.log to a room (as text)
2017-09-07 15:08:31 +02:00
```
cat /var/log/boot.log | patrix --room='#bootlogs:matrix.domain.com' --send-notice
2017-09-07 15:08:31 +02:00
```
* Send a file (here, the room name must be specified in the config file)
2017-09-07 15:08:31 +02:00
```
patrix --send-file --file=/home/dani/archive.tgz --user=dani --password=secret --server=matrix.domain.com
2017-09-07 15:08:31 +02:00
```
* Send a simple text message, and enable debuging
2017-09-07 15:08:31 +02:00
```
patrix --debug --message="Hello World"
```
* Create a new room, set its name and invite a Matrix user
2017-09-10 11:01:06 +02:00
```
patrix --create-room --name="Human readable room name" --invite="@dani:matrix.example.com"
2017-09-10 11:01:06 +02:00
```
* Configure an existing room
2017-09-10 11:01:06 +02:00
```
patrix --modify-room --join-rules=public --topic='New topic' --room='!uXfknaWNcAnvthnIms:matrix.example.com' --invite='@admin:matrix.example.com'
```
* Change power level needed for the ban action. Set the default power levels of new users to 10. Set power level for @dani:matrix.example.com to 90
```
2017-11-24 12:30:55 +01:00
patrix --modify-room --perm "ban=70" --perm "users_default=10" --user-perm "@dani:matrix.example.com=90"
```
* Set the required power level to send the m.room.name event to 80 (you can change the room name if you have a power level of at least 80)
```
patrix --modify-room --event-perm "m.room.name=80"
```
* Reset permissions. Only keep user power levels which are at least the same as yours (including yours)
```
patrix --modify-room --reset-perm
2017-09-10 11:01:06 +02:00
```