Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I have two kids that love Ubuntu so much so that they are not doing their Math homework. So in the spirit of Monty Python, I would like to present them with something like:

"Stop. Who would cross the Bridge of Death must answer me these questions three, ere the other side he see."

at the login in.

They would have to solve a few math problems before they can login.

My question is: can this type of thing be done?

share|improve this question
    
Could I do this by writing my own xscreensaver module? Or maybe add it to the /etc/profile? –  user187493 Aug 26 '13 at 18:03
1  
You might also want to look into writing your own Pluggable Authentication Module (PAM) and how to integrate that with the lightdm greeter. –  ImaginaryRobots Aug 26 '13 at 19:10
    
Thanks this is exactly the kind of advise I was looking for :) I'm not too afraid of breaking my system. I figure if I'm not breaking something I'm not doing it right. –  user187493 Aug 26 '13 at 22:01
add comment

2 Answers 2

up vote 30 down vote accepted

The following is tested with Ubuntu 13.04 and system's Python, using Gtk bindings (PyGobject).

Here is one way a bit dirty though and it needs more investigation:

Summary

  • Add a .desktop file at /usr/share/xsessions we will name it custom

  • Add an .xsession file at the user in question (your kids) we will name their user as kid

  • Create the Python GUI application for the math puzzle and run it from .xsession, we will name it as puzzle.py

Details

  • sudo vi /usr/share/xsessions/custom.desktop

Add the following in the file:

[Desktop Entry]
Name=Custom
Comment=This session logs you into your managed desktop environment
Exec=/etc/X11/Xsession
X-Ubuntu-Gettext-Domain=gnome-session-3.0
  • vi /home/kid/.xsession

Add the following in the file:

#!/bin/bash
lightdm &
exec /home/kid/puzzle.py
  • vi /home/kid/puzzle.py

Add the following in the file:

#!/usr/bin/python
# -*- coding: utf-8 -*-
import subprocess
import random
from gi.repository import Gtk


#----------------------------------------------------------------------
class PuzzleWindow(Gtk.Window):

    def __init__(self):
        Gtk.Window.__init__(self, title="Math Puzzle", resizable=False)

        super(PuzzleWindow, self).set_position(Gtk.WindowPosition.CENTER)
        super(PuzzleWindow, self).maximize()

        self.a_number = random.randint(1, 5)
        self.b_number = random.randint(1, 5)
        self.result = self.a_number + self.b_number

        self.vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=5)

        self.label = Gtk.Label("What is the sum of the numbers bellow?")
        self.number_label = Gtk.Label("{num_a} + {num_b}".format(
            num_a=self.a_number, num_b=self.b_number))

        self.entry = Gtk.Entry()
        self.button = Gtk.Button(label="Check answer!")
        self.button.connect("clicked", self.on_button_clicked)

        self.vbox.pack_start(self.label, True, True, 0)
        self.vbox.pack_start(self.number_label, True, True, 0)
        self.vbox.pack_start(self.entry, True, True, 0)
        self.vbox.pack_start(self.button, True, True, 0)
        self.add(self.vbox)

    def on_button_clicked(self, widget):

        if int(self.entry.get_text()) == self.result:
            subprocess.call("unity &", shell=True)
        else:
            self.label.set_text("Wrong answer, try again.")
#----------------------------------------------------------------------
def main():
    """Application's entry point"""
    win = PuzzleWindow()
    win.connect("delete-event", Gtk.main_quit)
    win.show_all()
    Gtk.main()

if __name__ == "__main__":
    main()

Results:

  • If you logout, at the login screen you will see a new session named Custom.
  • By choosing the custom session and after successful login you will presented by a small PyGtk (using pygobject) window asking for a math puzzle. There will be no top bar, launcher and the rest of the default desktop widgets:

Custom access to Unity

  • If you answer correctly, Unity will load...

It needs further research though but i hope that it helps as a starting point.

share|improve this answer
    
Thanks you did most of the work for me. :) –  user187493 Aug 27 '13 at 16:55
    
@user187493 If you consider that your problem is solved, consider accepting the answer. –  Stef K Aug 27 '13 at 17:01
    
I'm new to this forum so how does one go about accepting the answer. –  user187493 Aug 27 '13 at 20:12
    
If you don't mind a text-based solution, couldn't you just write a simple shell script that asks a few questions and checks the answers. If the answers are correct, then do a startx, otherwise, do a logout. Then, edit /etc/passwd and make this script their login shell. It's way less elegant than the above solution, but way simpler to code and maintain. It should also be relatively distro/desktop independent. You would also need to test it to make sure it handles things like sigint (Ctrl_C) gracefully. –  Joe Aug 28 '13 at 23:09
    
Very nice! this is the kind of things that I really like. –  Jacob Vlijm Apr 24 at 14:17
add comment

It can be done, but would take a lot of technical knowhow. The simplest way to do this by writing a script that is run as root that:

  • changes their password(s) automatically to the answer of a given question,
  • changes their desktop wallpaper to show the question they are trying to answer

You would likely need to keep the list of math problems in a text file (or database), and use the imagemagick command line tools to add the problem text to the desktop wallpaper. Use cron to schedule that script to run every so often (daily?).

Getting the login screen to ask for 3 different questions would require a lot of custom hacking and would probably involve replacing large parts of your system, so it not recommended. Even the "simple" script above requires a lot of skill and knowledge, and could potentially break your system if done wrong.

share|improve this answer
    
Thanks for your answer. I was going to use a mini database of questions and answers and I really like the idea of using imagemagik. –  user187493 Aug 26 '13 at 18:07
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.