Parental Controls on KDE Desktop
By Limiting Session Time


PREFACE:

I have been running Linux in my businesses and at home for over 8 years now.
One of the issues I have ran into is trying to limit the time my kids spend on the computer.
I wanted to be able to configure something to limit the sessiontime to 30 mins per day. My version of parental control. Yeah! Take that Kids!!

I have 3 kids (ages 12,11 & 7), each with separate username / passwords on a machinerunning Fedora Core 8 with KDE desktop.
Actually the machine had both Gnome and KDE installed on it, since that is FC default when installing.
This presented some additional issues after I initially got the first version of the script working.

My kids quickly figured out if they logged into the GNOME desktop the script didn't kick them off after 30 mins.
So I had to figure out a way to remove the GNOME session option from the KDM login manager.
Please see information below.

I started looking for a solution but I never found exactly what I was looking for,so I pieced some information together to come up with this solution.

Please let me know if this solution is helpful or if you have suggestions or comments.


SOLUTION:

I found a number of posts but this is where I started:
http://www.kde-forum.org/artikel/15602/Session-Time.html

I took this idea and built a little upon it. I first wrote a bash shell named:timelimit.sh
Click here for source code

1. #!/bin/bash
2. dia=`date +"%d"`<
3. ultimo=`cat ~/.kde/sessao`
4. if [ "${dia}" == "${ultimo}" ] ;
5. then
6. kdialog --title "TIME LIMIT EXCEEDED" --error "You already use your time today!!!" &
7. sleep 10
8. ps -p $! 2>&1 > /dev/null
9. #Grab the status of the ps command<
10. status=$?
11. #A value of 0 means that it was found running
12. if [ "$status" == "0" ]
13. then
14. kill $!
15. fi
16. dcop ksmserver ksmserver logout 0 0 0
17. exit 1
18. fi
19. echo ${dia} > ~/.kde/sessao
20. # Initial time delay (less 2 mins)
21. sleep 28m
22. kdialog --title "WARNING TIME EXPIRED!!!" --error "Time to log off - You have 2 mins to log off" &
23. sleep 1m
24. ps -p $! 2>&1 > /dev/null
25. #Grab the status of the ps command
26. status=$?
27. if [ "$status" == "0" ]
28. then
29. kill $!
30. fi
31. kdialog --title "WARNING TIME EXPIRED!!!" --error "Time to log off - You have 1 min to log off" &
32. sleep 1m
33. ps -p $! 2>&1 > /dev/null
34. #Grab the status of the ps command
35. status=$?
36. #A value of 0 means that it was found running
37. if [ "$status" == "0" ]
38. then
39. kill $!
40. fi
41. # Force log off
42. dcop ksmserver ksmserver logout 0 0 0

Click here for source code

INSTRUCTIONS:

1. Edit timelimit.sh
2. Make executable for all who access
3. Copy/move to a directory accessible by all
4. Add a link to the users Autostart directory
5. Login as user

STEP BY STEP:

0. Login as root
1. emacs timelimit.sh
2. chmod 755 timelimit.sh
3. mv timelimit.sh /usr/bin/
4. cd ~/.kde/Autostart
5. ln -s /usr/bin/timelimit.sh

If you have both Gnome/KDE desktops installed and running, with KDM you caneasily prevent
a user from changing session to GNOME by removing (or moving) thedesktop definition file located in the /usr/share/xsessions directory.
I moved thefile to a different filename

6. cd /usr/share/xsessions/
7. mv gnome.desktop gnome.desktop.old
8. Log out of session - KDM will only display KDE as a desktop option.

TESTING:
1. You may want to lower the inital wait time to 1 min or even comment it out.
2. You may want to change the logout command to: "dcop kdesktop default logout" at lines 16 & 42
This command brought up the logout dialog on my system and was helpful for testing.


USEFUL LINKS:

This is where I started:
http://www.kde-forum.org/artikel/15602/Session-Time.html
Autostart Information:
http://gentoo-wiki.com/HOWTO_Autostart_Programs
kdialog Information:
http://developer.kde.org/documentation/tutorials/kdialog/x27.html


IMPROVEMENTS:

1. Add agument for time in minutes.
2. There needs to be a better way to calculate the amount of time a user has used.
The current implementation will only allow the user to login once per day. It assumes
all the time has been used in the session. I need to find a way to do this. Any suggestions?
3. There may be other cases or situations I haven't thought of that need to be handled.
4. Others????


CONTACT:

For comments or suggestions, please contact:
Tony Keith
Last Update: 02/16/08