Execute script on login

awado

Member
Mar 2, 2020
32
7
13
53
For security reasons I implemented an rsyslog config script to send a push notification on every ssh login attempt. Can this be done for the web login too?
 
You could also use a rsyslog config script similar to the SSH one. Each authentication is logged in daemon.log as

Code:
Mar 25 10:45:55 proxmox pvedaemon[3117373]: <root@pam> successful openid auth for user 'lnxbil@keycloak'
 
Thanks LnxBil. Somehow it should be obvious, if I'd have watched the syslog closely enough. Works like a charm. If anyone wants to do the same, here's my solution:

Add the script to "/etc/rsyslog.d".

Code:
nano /etc/rsyslog.d/pushover-web.conf

module(load="omprog")
template(name="webloginmsg" type="string" string="%msg%")
if ($programname == "pvedaemon") and ($msg contains "successful auth") then {
    action(type="omprog"
           binary="/usr/sbin/pushover.sh"
           output="/var/log/pushover.log"
           template="webloginmsg")
}

Everytime someone successfully logs in via web, it triggers this script:

Code:
nano /usr/sbin/pushover.sh

#!/bin/bash

read log
curl -s --form-string "token=your-token" --form-string "user=your-user" --form-string "message=$log"  https://api.pushover.net/1/messages.json

Make the script executable and restart the service.

Code:
chmod +x /usr/sbin/pushover.sh
systemctl restart rsyslog.service
 
The only downside is: the log entry repeats every 5 minutes and triggers the push notification.
 

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!