parctl - parental control for parents
parctl [--config file] [--help] [--man]
parctl monitors and limits computer usage ("tube time"). Programs like this are typically used to prevent children from spending too much time over their digital gadgets. The same paradigm has, however, proved to be effective with adult specimen as well, particularly middle-aged computer scientists.
The modus operandi is as follows. The user is given a time quota called slack for every 24 hours. Whenever the user is interacting with the machine, parctl decreases the slack by the corresponding wall clock time. For example, if the user interacts with the machine for 30 minutes, parctl removes 30 minutes from the slack. "Interaction" is defined as "typing on the keyboard or using the mouse".
parctl resets the slack at a certain reset time each day. If the slack gets used up before that, parctl unconditionally suspends the machine. After that, the machine will be practically unusable until the reset time: wake-ups from the suspend will soon cause a re-suspension.
If the user does not interact with the machine for a certain period of time, parctl goes to idle mode and stops consuming the slack. During idle mode, parctl assumes that the user is away from the machine. When the user starts interacting with the machine again, parctl ends idle mode and resumes slack consumption.
parctl displays the remaining slack continuously in a simple window, and warns the user if they are running out of slack. Note that parctl is an X11 application and hence requires a running X session: true terminal junkies are considered hopeless and unsalvageable.
The author acknowledges certain special cases which call for exceptions, such as intense emacs(1) hacking or other "critical system upgrades", when the system simply cannot be suspended. In such dire circumstances, the user can selectively disable the slack consumption by switching to grace mode. Of course, the real need for such a blunt measure should be sagaciously evaluated each and every time.
The author also acknowledges certain use cases where the user mostly sits around the machine, gazing and immersing whatever audiovisual or other electromagnetic energy is being emitted by the device. Such activity is called consuming, and parctl can be told when consuming is in progress. During consuming, parctl decreases the slack unconditionally, regardless of any physical interaction with the machine. In other words, parctl does not go into idle mode at all.
parctl has two different modes for slack:
In fixed mode, the initial amount of slack is fixed. When the slack is used, the system is practically unusable until the reset time.
In deadline mode, the system suspend time ("deadline") is fixed, and the slack varies correspondingly. The system is practically unusable between the deadline and the reset time.
In deadline mode parctl does not go into idle mode at all, and consuming mode is not available. However, grace mode is available: it effectively extends the deadline by the amount of time spent in grace mode.
The slack mode and slack, reset and deadline times are all configurable.
At startup parctl opens a single window that continuously displays the remaining slack with one second precision. Window background color depends on the current mode:
Normal background color means least concern mode: there is ample slack remaining.
Yellow background color means vulnerable mode: only a fraction of slack is remaining.
Red background color means endangered mode: only a couple of minutes of slack is remaining.
Blinking yellow/red background color means critical mode: only tens of seconds of slack is remaining. When parctl enters critical mode, it will display a warning dialog saying that system suspend is imminent.
Green background color means idle mode: slack is not consumed until the user starts interacting with the machine again.
Blue background color means grace mode: slack is not consumed at all.
The aforementioned colors and the corresponding slack limits are configurable.
Grace mode can be toggled by clicking on the window with mouse button 2.
Consuming can be toggled by clicking the window with mouse button 3. If parctl is consuming, the remaining slack is displayed in boldface font.
When the mouse cursor is hovering over the slack label, a tooltip shows the time of system suspension, or an indication of grace mode when it is on.
In addition to slack, parctl can also display the current date and time, time of sunrise and sunset, and the age of the user in days. These features are only visible if configured so.
Most parctl parameters can be configured in a configuration file. In startup, parctl reads two configuration files: its default configuration file $PERLLIB/ParCtl/config.ini and the user configuration file $HOME/.parctl.ini, if it exists. (Here, $PERLLIB
refers to the Perl library directory where ParCtl is installed.)
A different user configuration file can be specified with command line argument --config. Any settings given in the user configuration file override the corresponding default settings.
Configuration files are plain text files in INI-format, as understood by Config::Tiny(3) module:
Settings are divided into separate sections, with each section header on its own line in square brackets.
Each section has a list of key=value
pairs, one pair per line.
Lines starting with #
or ;
are interpreted as comments and ignored.
The default configuration file $PERLLIB/ParCtl/config.ini is a useful template for a new user configuration file.
In general, parctl should not require any user configuration unless you are not satisfied with the defaults. Suspend command (see System Suspend below) may require tweaking if you are not on a Linux-based system.
The following sections are recognized when reading configuration files. Examples below show the default values (note that sections may be commented out by default).
[features]
parctl=true
datetime=false
Settings in features
section control which parctl features are visible:
parctl
enables the "parental control" feature, that is, slack and system suspend. Set to false
if you want to disable slack tracking and suspension.
datetime
enables the date and time feature. If true
, parctl displays the current date and time.
[slack]
mode=fixed
initial=02:00:00
deadline=22:00:00
reset=04:00:00
utc=false
These settings control slack allocation and tracking (see Slack Modes above):
If slack_mode
is fixed
, the amount of slack is fixed to initial
.
If slack_mode
is deadline
, the system is suspended at deadline
.
reset
: This is the wall clock time when slack is reset.
utc
: If set to true, deadline
and reset
times are assumed to be in UTC. Otherwise they are assumed to be in local time, including daylight savings.
All times must be given in HH:MM:SS
format.
[limits]
vulnerable=00:15:00
endangered=00:10:00
critical=00:02:00
idleness=00:01:00
These are time limits for different slack modes. See Slack Modes above for details.
idleness
is the required amount of inactivity after which parctl goes to idle mode.
All times must be given in HH:MM:SS
format.
[suspend]
command=systemctl suspend
command
is the command executed to suspend the system when slack goes to zero. Note that parctl must be run with enough privileges to execute this command.
[formats]
date=%x
time=%X
slack_hm=%H:%M
slack_ms=%M:%S
These are expected to be strftime(3) compatible format strings. parctl uses them to construct various date and time strings:
date
is used for the current date shown when datetime
feature is enabled.
time
is used for various times and durations:
The current time shown when datetime
feature is on.
Duration from/to sunrise and sunset when they are calculated (see Geographical Location).
System suspend time in slack tooltip.
slack_hm
is used for formatting the remaining slack when there is more than 60 minutes of slack remaining. Similarly, slack_ms
is used for formatting the remaining slack when there is less than 60 minutes of slack remaining.
; [fonts]
; font_family=Serif
; font_size=16
; tooltip_font_family=Serif
; tooltip_font_size=10
These settings configure fonts for labels and tooltips. If they are not given, Tk(3pm) defaults will be used.
; [location]
; latitude=60.1666
; longitude=24.9435
This is the geographical location (latitude and longitude) of the user in decimal format. When a location is configured, parctl calculates the time of sunrise and sunset, time of day, and the duration of daylight or darkness. This information is displayed in time tooltip. Hence, datetime
feature must be also enabled.
; [date_of_birth]
; day=1
; month=1
; year=1970
These settings specify the date of birth of the user. If configured, parctl calculates the age of the user in days and displays that in date tooltip. Hence, datetime
feature must be also enabled.
[colors]
idle=green
vulnerable=yellow
endangered=red
grace=deepskyblue
; background=gray
; foreground=black
; tooltip_background=yellow
; tooltip_foreground=black
These define background colors for slack modes (see Slack Modes above). Least concern mode uses the given background color. If unspecified, parctl uses Tk(3pm) defaults.
Read configuration from file instead of $HOME/.parctl.ini.
Display short command line help and exit.
Display parctl manual page and exit.
SIGINT and SIGTERM cause immediate program termination. SIGUSR1 causes parctl to reload configuration files and reset the state as it would do in startup.
The user must be allowed to run suspend command without separate authentication.
Geographical location cannot be acquired from GPS receiver or other geolocation device.
Configuration settings are not validated. For example, it is possible to specify a nonsensical geographical location, or a date of birth that is in the future. Consider yourself being warned.
Yes.
Copyright 2017, 2021-2023 Petteri Hintsanen <petterih@iki.fi>
This program is free software; you may redistribute it and/or modify it under the same terms as Perl itself.
sudo(8), pm-suspend(8), systemctl(1), zzz(8)