Skip to content

Workplacer switches your Mattermost custom status depending on the IP of your device.

License

Notifications You must be signed in to change notification settings

stmichaelis/workplacer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Workplacer switches your Mattermost custom status depending on the IP of your device.

In times where you may be working from home or at the office on an irregular basis, it could be beneficial to let your co-workers know in Mattermost where you currently are sitting. This small script sets your custom status based on the IP your device received, assuming that those from home and at work are different.

Usage

  -acidr string
        -acidr <Class Inter-Doman Routing>: CIDR address of network A, e.g. 192.168.1.0/24 for all ip addresses in 192.168.1.*. Multiple address spaces may be separated by comma.
  -aemoji string
        -aemoji <emoji>: Emoji to use for custom status when connected to network A (default "house")
  -atext string
        -atext <status text>: Description to use for custom status when connected to network A (default "Working from home")
  -atime string
        -atime <hh:mm>: Time of today when to clear status when connected to network A (default "18:00")
  -bcidr string
        -bcidr <Class Inter-Doman Routing>: CIDR address of network B, e.g. 192.168.1.0/24 for all ip addresses in 192.168.1.*. Multiple address spaces may be separated by comma.
  -bemoji string
        -bemoji <emoji>: Emoji to use for custom status when connected to network B (default "office")
  -btext string
        -btext <status text>: Description to use for custom status when connected to network B (default "At the office")
  -btime string
        -btime <hh:mm>: Time of today when to clear status when connected to network B (default "18:00")
  -mlog
        Sends log messages to the given Mattermost user in addition to stdout if set
  -password string
        -password <Password of your Mattermost account>. Reads from stdin if set to "-" or empty and no authenticaton token set.
  -showtoken
        Wether to output the Mattermost access token to stdout
  -token string
        -token <Mattermost User Authorization Token>
  -url string
        -url <URL of your mattermost server>
  -username string
        -username <Mattermost username without leading @>

Why there are a and b networks and not just one

The script is overriding the status of each networks once it connects to the other one. This may happen if you start your work at home and then travel to the office later on. To not override other, manually set, custom statuses, this only happens if the text message is known to the script.

Example: You manually set your status to "on a vacation" and still open your machine while away. This will not override your vacation status.

Why only two networks

This is my typical scenario. In case you need more networks (working at the coffee shop) you can run the script twice, but have to live with the drawbacks of not overriding the former status (see above), or simply extend this script.

Example

Minimal usage:

workplacer -token ASCRCYX793CYHRTWDS -url https://your.mattermost-server.net -username thatsme -acidr "192.168.3.0/24" -bcidr "10.2.0.0/16"

Logging in

You can provide your password via the -password-option. To avoid putting your password into a script use the option -showtoken to have your token printed to the terminal once after login and from there on use this instead of the password, see below.

If neither token nor password is provided on the commandline you are queried for the password.

Mattermost access token

To avoid having to put your password onto the commandline, this script can use an access token.

In case you don't want to put this token as a commandline option, you can also set it to the environment variable MATTERMOST_TOKEN.

Personal access tokens

Mattermost allows creating permanent, personal tokens, if enabled globally and for you specifically by the server administrator. Go to Account Settings > Security > Personal Access Tokens, then select Create New Token.

Standard session tokens

You can use the password option of the script to login, retrieve a token and have it display on stdout via -showtoken.

Example:

workplacer -password - -showtoken -url https://your.mattermost-server.net -username thatsme -acidr "192.168.3.0/24" -bcidr "10.2.0.0/16"

Or you query the mattermost server directly: https://api.mattermost.com/#tag/authentication

curl -i -d '{"login_id":"someone@nowhere.com","password":"thisisabadpassword"}' http://localhost:8065/api/v4/users/login

Please be aware that these tokens may expire after some time, based on the session lenght limit set by the server administrator. Setting a custom status does not refresh this token. You can use the mlog option to have the script post log messages to yourself, which should refresh the token for a Mattermost server with default settings.

Installation

Precompiled binaries

For your convenience you can find precompiled binaries on the release page of this repository for several operating systems (currently tested only on Windows). This is just a simple binary without any further dependencies, which you can place at a suitable location on your system for calling from the commandline/task scheduler.

Installation from source

You need to have a compiler for the go programming language version >= 1.18 locally installed, then run:

go install github.com/stmichaelis/workplacer@latest

May take a while to download as it is using the official Mattermost API binding.

Automatic execution on Windows based on connection events

On Windows you can use the task scheduler to trigger a run of the script based on network connection events. Select in the trigger section to run on an event, log should be set to Microsoft-Windows-NetworkProfile/Operational, source to NetworkProfile and event id to 10000.

False positives when running the script

False positive, i.e. setting the wrong status, may occur when there is an overlap between home and work networks, you are using a VPN, or using the device at a place (e.g. coffee shops) which is neither work nor home and using the same private IP network from one of your other locations. You can try:

  • For VPNs (which in most cases are for connecting to the work network) you should set your home network to the acidr network. The a-networks takes precedence over the b-network and even when in a VPN your home network should still be there.
  • Think about using IPv6 addresses like 2001:db8::/32 Many providers keep the first parts of your assigned network adress constant, based on physical location.
  • For WiFi-connections: Let the script only run when connected to specific networks. In the Windows task scheduler you can select the specific network on the conditions tab.
  • Change your local home network address space. It's your network after all.

About

Workplacer switches your Mattermost custom status depending on the IP of your device.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages