pygtk widget to show token

1)Si es un sistema en el que teneis root:
yum install python-pip
pip install pyotp

2) Creamos un token con freeotp tomando nota del secret

3) El script en python:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import pygtk
pygtk.require(‘2.0’)
import gtk
import time
import sys
import datetime
import pyotp
totp = pyotp.TOTP(“$SERIAL”)

class Token:

def __init__(self):
window = gtk.Window(gtk.WINDOW_TOPLEVEL)
window.connect(“destroy”, lambda w: gtk.main_quit())
window.set_title(“My Token”)
self.label = gtk.Label()
window.add(self.label)
window.set_border_width(25)
window.show_all ()

def update(self):
currentotp = str(totp.now()).zfill(6)
seconds=30 – (int(datetime.datetime.now().strftime(‘%S’)) % 30)
self.label.set_text(“Token : ” + currentotp + ” Remaining seconds ” + str(seconds))
return True #needed to keep the update method in the schedule

def main():
gtk.main()

if __name__ == “__main__”:
token = Token()
gtk.timeout_add(200, token.update) #add to the main loop scheduled tasks
main()

4) Gnome launcher:
.local/share/applications/mytoken.desktop
[Desktop Entry]
Encoding=UTF-8
Name=MyRsa
Exec=/home/jramirez/bin/mytoken.py
Icon=/home/jramirez/Desktop/mytoken_icon.png
Type=Application
Categories=Development;

#TODO:
clipboard with a button

Leave a Reply

Your email address will not be published. Required fields are marked *