Random parenting scripts for Linux

This does not replace real parenting.

Hardware trick

Don't use any Wifi at home, put hub for child PC on electric timer.

Too young to browse the web

iptables -A OUTPUT -o eth0 -m owner --uid-owner {USERNAME} -j REJECT

Go-To-Bed

This uses systemd-cron's PERSISTENT feature.
#/etc/cron.d/go_to_bed
PERSISTENT=false
30    20 * * 0-4 root echo "GO TO SLEEP" > /etc/nologin
55-59 20 * * 0-4 root /usr/bin/beep
0     21 * * 0-4 root /sbin/poweroff
PERSISTENT=true
0 8 * * * root rm /etc/nologin -f -v

Google-Chrome monitor

This works as long as your child doesn't know about incognito mode. (could be patched-out in Chromium I guess)
#/etc/cron.d/historique
1,5,10,15,20,25,30,35,40,45,50,55 * * * * root /usr/local/sbin/historique

#!/usr/bin/python3

import os
import subprocess

subprocess.call(['cp', '/home/melanie/.config/google-chrome/Default/History', '/tmp/'])

proc = subprocess.Popen(['sqlite3', '/tmp/History',
                         "select datetime(last_visit_time/1000000-11644473600+7200,'unixepoch'),url,title "
                         "from urls "
                         "order by last_visit_time desc"],
                         universal_newlines=True,
                         stdout=subprocess.PIPE)

count = 0

html = open('/var/www/index.html', 'w')
html.write('''
<html>
<head>
  <title>Melanie</title>
  <meta http-equiv="refresh" content="300">
  <meta charset="UTF-8">
</head>
<body>
<h2>Historique<h2>
<table border=1>
  <tr>
    <td>Date</td>
    <td>Url </td>
    <td>Titre</td>
  </tr>
''')

for line in proc.stdout:
    count += 1
    if count == 40:
        break
    line = line.rstrip()
    #print(line)
    date, url, nom = line.split('|')
    html.write('<tr>')
    html.write('<td>' + date + '</td>')
    html.write('<td><a href="' + url + '">' + url[0:50] + '</a></td>')
    html.write('<td>' + nom + '</td>')
    html.write('</tr>\n')


html.write('</table></body></html>')
html.close()

You can use micro-httpd to deliver the web page:
# /etc/systemd/system/micro-httpd.socket
[Unit]
Description=micro-httpd

[Socket]
ListenStream=0.0.0.0:80
Accept=true

[Install]
WantedBy=sockets.target

#/etc/systemd/system/micro-httpd@.service
[Unit]
Description=micro-httpd

[Service]
User=nobody
Group=www-data
ExecStart=/usr/sbin/micro-httpd /var/www
StandardInput=socket