close Warning: Can't synchronize with repository "keplertools" (/srv/svn/keplertools does not appear to be a Subversion repository.). Look in the Trac log for more information.

Opened 4 months ago

Last modified 6 weeks ago

#5792 assigned Defekt

OTP-Generator-GUI

Reported by: Rüdiger Kupper Owned by: bau
Priority: schnell erledigen Milestone: Schuljahr 2025/26
Component: Software: Ubuntu Severity: beeinträchtigt den Unterricht einiger Lehrer
Keywords: Cc: bau

Description

Das Kopieren der Notfallcodes funktionierte heute nicht. Das zugehörige Skript liegt in /usr/local/sbin/OTP.py. Das steht unter SNV-Verwaltung.

Das Skript wurde auf dem paedml geändert, aber nicht eingecheckt, so dass die Änderungen nicht auf den Clients angekommen sind.

Hier sind die Änderungen:

12:39/0 paedml ~ # svn diff /usr/local/sbin/OTP.py
Index: /usr/local/sbin/OTP.py
===================================================================
--- /usr/local/sbin/OTP.py	(Revision 1509)
+++ /usr/local/sbin/OTP.py	(Arbeitskopie)
@@ -3,75 +3,87 @@
 
 import os, sys, pyotp
 from pathlib import Path
-from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QLabel
+from PyQt5.QtWidgets import QApplication, QMainWindow, QPushButton, QLabel
 from PyQt5.QtGui import QIcon, QPixmap
 from PyQt5 import QtCore
 from PyQt5.QtCore import QTimer
 
-def ButtonClick():	
-    aotp = w.totp.now()    
-    w.OTPlabel.setText("Code: " + aotp + " erzeugt und in Zwischenablage kopiert (STRG-V).")
-    w.OTPlabel.setStyleSheet("text-align:center;background-color:#a6deb5;")    
-    w.clipboard.setText(aotp)
 
-def ButtonNCClick():
-    with open(str(Path.home()) + "/.google_authenticator") as f:
-      i = 1
-      Notfallcodes = "Ihre Notfallcodes: \n"
-      for zeile in f:
-       if (i>5):
-         Notfallcodes += ("#" + str(i-5)).rjust(3," ") + ": " + zeile
-       i += 1
-    w.OTPlabel.setText("Notfall-Codes wurden in die Zwischenablage kopiert (STRG-V).")
-    w.OTPlabel.setStyleSheet("text-align:center;background-color:#eb9e34;")             
-    w.clipboard.setText(Notfallcodes)  
 
 
-if __name__ == '__main__':
-    
-    app = QApplication(sys.argv)
+class MainWindow(QMainWindow):
 
-    w = QWidget()
-    w.resize(500, 120)    
-    w.setWindowTitle('Kepler-Einmal-Code-Erzeuger (TOTP)')
-    w.setWindowIcon(QIcon('/usr/share/icons/OTP.png')) 
-    
+  def __init__(self):
+    super().__init__()
+
+    self.setWindowTitle('Kepler-Einmal-Code-Erzeuger (TOTP)')
+    self.setWindowIcon(QIcon('/usr/share/icons/OTP.png'))     
+    self.setWindowFlags(QtCore.Qt.WindowCloseButtonHint);
+    self.setFixedSize(QtCore.QSize(500, 120))    
+    self.move(300, 300)    
+
     with open(str(Path.home()) + "/.google_authenticator") as f:
       secret = f.readline().strip()
-    
-    w.totp = pyotp.TOTP(secret)
-    
-    Button = QPushButton("Code erzeugen",w)
-    Button.clicked.connect(ButtonClick)
+
+    self.totp = pyotp.TOTP(secret)
+
+    Button = QPushButton("OTP erzeugen",self)
+    Button.clicked.connect(self.ButtonClick)
     Button.move(150,30)
     Button.resize(300, 50)
     Button.setStyleSheet("font: bold; font-size: 30px; height: 48px;")
 
-    label = QLabel(w)
-    pixmap = QPixmap('/home/share/Kollegium/Logo_und_Briefvorlagen/LOGO_KEPLER_klein 40x26_Kaupp_geglaettet.png')
+    label = QLabel(self)
+    pixmap = QPixmap('/home/share/installations/Kepler_Logo.png')
     label.setPixmap(pixmap)
-    label.move(10,10)
+    label.resize(150,75)
+    label.move(10,5)
     
-    w.OTPlabel = QLabel(w)
-    w.OTPlabel.move(10,90)
-    w.OTPlabel.resize(480,20)
-    w.OTPlabel.setText('')
-    w.OTPlabel.setAlignment(QtCore.Qt.AlignCenter);
-    w.clipboard = QApplication.clipboard()
-    
-    w.timer=QTimer()
-    w.timer.timeout.connect(ButtonClick)
-    w.timer.start(1000)
-    #ButtonClick()    
-    
-    if (os.system("lehrernetz")==0):
-      w.resize(630, 120)
-      ButtonNC = QPushButton("Notfallcodes",w)
-      ButtonNC.clicked.connect(ButtonNCClick)
+
+    self.OTPlabel = QLabel(self)
+    self.OTPlabel.move(10,90)
+    self.OTPlabel.resize(480,20)
+    self.OTPlabel.setText('')
+    self.OTPlabel.setAlignment(QtCore.Qt.AlignCenter);
+    self.clipboard = QApplication.clipboard()
+
+    if (os.system("./lehrernetz")==0):      
+      self.setFixedSize(QtCore.QSize(630, 120))    
+      ButtonNC = QPushButton("Notfallcodes",self)
+      ButtonNC.clicked.connect(self.ButtonNCClick)
       ButtonNC.move(460,42)
       ButtonNC.resize(160, 25)
       ButtonNC.setStyleSheet("font-size: 15px; height: 24px;")
-      w.OTPlabel.resize(610,20)
-    w.show()
-    
+      self.OTPlabel.resize(610,20)
+
+    timer=QTimer()
+    timer.timeout.connect(self.ButtonClick)
+    timer.start(1000)
+
+
+  def ButtonClick(self):
+    aotp = self.totp.now()    
+    self.OTPlabel.setText("Code: " + aotp + " erzeugt und in Zwischenablage kopiert (STRG-V).")
+    self.OTPlabel.setStyleSheet("text-align:center;background-color:#a6deb5;")    
+    self.clipboard.setText(aotp)
+
+  def ButtonNCClick(self):
+    with open(str(Path.home()) + "/.google_authenticator") as f:
+      i = 1
+      Notfallcodes = "Ihre Notfallcodes: \n"
+      for zeile in f:
+       if (i>5):
+         Notfallcodes += ("#" + str(i-5)).rjust(3," ") + ": " + zeile
+       i += 1
+    self.OTPlabel.setText("Notfall-Codes wurden in die Zwischenablage kopiert (STRG-V).")
+    self.OTPlabel.setStyleSheet("text-align:center;background-color:#eb9e34;")             
+    self.clipboard.setText(Notfallcodes)  
+
+
+
+if __name__ == '__main__':
+        
+    app = QApplication(sys.argv)
+    window = MainWindow()
+    window.show()
     sys.exit(app.exec_())

Change History (2)

comment:1 by Rüdiger Kupper, 4 months ago

Owner: changed from Rüdiger Kupper to bau
Status: new → assigned

Ich habe die Änderungen eingecheckt, ohne sie nochmal anzuschauen. Die neue Version zeigt jetzt überhaupt keinen Knopf für die Notfallcodes mehr an. Klappt vielleicht der Test auf's Lehrernetz nicht?

-> Kannst Du da mal drüberschauen?

comment:2 by bau, 6 weeks ago

Im Script wurde ein Timer gestartet, der munter weiter werkelte. Ich habe diesen nun in der Funktion ButtonClick am Ende wieder ausgeschaltet. Somit werden jetzt auch wieder Notfallcodes angezeigt. Beim OS-Call war ein Punkt an der falschen Stelle.

Das Script befindet sich jetzt auf dem paedml unter /usr/local/sbin/OTP.py

Note: See TracTickets for help on using tickets.