Im using Linux Mint.
I have written a python script that is designed to not be accessible to the logged in standard user but is still be executed while they are logged in. It is to run and log them out if a certain field is set in a mysql database and show a dialog saying "you're being logged out blah".
If I run the python script as the standard user all is well and they get logged out.
If I run the python script as the admin user I get:
glib.GError: Unable to connect to server
when it tries to show the dialog box
If I re-run the script with the admin user and sudo
, it works.
The idea is for this to run from cron, and unless I can get cron to run the script as the admin user with sudo
it's not going to work.
Any help?
EDIT
this is the two gui parts of the script
this part is called every time the script runs and will show a notification with the amount of time the user has left
u.get_time_left()
n = pynotify.Notification("Time Left", str(u.timeLeft / 60)+" Minutes remaining")
n.set_urgency(pynotify.URGENCY_CRITICAL)
n.set_timeout(10000) # 10 seconds
n.set_category("device")
helper = gtk.Button()
icon = helper.render_icon(gtk.STOCK_DIALOG_WARNING, gtk.ICON_SIZE_DIALOG)
#n.set_icon_from_pixbuf(icon)
try :
n.show()
This part only runs if certain conditions are met ie the time they have left is under 5 mins.
def getText():
#base this on a message dialog
dialog = gtk.MessageDialog(
None,
gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
gtk.MESSAGE_QUESTION,
gtk.BUTTONS_OK,
None)
dialog.set_markup('Your time limit is nearing the <b>end</b>')
entryUser = gtk.Entry()
entryPass =gtk.Entry()
entryUser.connect("activate", responseToDialog, dialog, gtk.RESPONSE_OK)
hbox = gtk.HBox()
hbox.pack_start(gtk.Label("Username:"), False, 5, 5)
hbox.pack_start(entryUser)
hbox.pack_start(gtk.Label("Password:"), False, 5, 5)
hbox.pack_start(entryPass)
dialog.format_secondary_markup("Please enter a new voucher <i>Username</i> and <i>password</i> to carry on your current session")
dialog.vbox.pack_end(hbox, True, True, 0)
dialog.show_all()
dialog.run()
username = entryUser.get_text()
password = entryPass.get_text()
dialog.destroy()
voucher = {'username':username,'password':password}
return voucher