mirror of
https://gitlab.os-k.eu/neox/CNIRevelator.git
synced 2023-08-25 14:03:10 +02:00
Working on launcher : download functions
This commit is contained in:
parent
3e2990dd82
commit
c9a7ef7742
@ -80,20 +80,10 @@ def main(logger):
|
|||||||
logger.info('launcher : ' + CST_NAME + ' ' + CST_VER)
|
logger.info('launcher : ' + CST_NAME + ' ' + CST_VER)
|
||||||
logger.info('launcher : *****Hello World*****')
|
logger.info('launcher : *****Hello World*****')
|
||||||
logger.info('launcher : *****Launching SoftUpdate()*****')
|
logger.info('launcher : *****Launching SoftUpdate()*****')
|
||||||
try:
|
|
||||||
Answer = SoftUpdate(logger)
|
|
||||||
except Exception as e:
|
|
||||||
logger.info('launcher : *****FATAL ERROR*****' + str(e))
|
|
||||||
os.abort()
|
|
||||||
|
|
||||||
logger.info('launcher : *****Ending SoftUpdate()*****')
|
|
||||||
try:
|
|
||||||
if Answer == True:
|
|
||||||
logger.info('launcher : *****Launching main()*****')
|
logger.info('launcher : *****Launching main()*****')
|
||||||
State = main(logger)
|
State = main(logger)
|
||||||
except Exception as e:
|
|
||||||
logger.info('launcher : *****FATAL ERROR*****' + str(e))
|
|
||||||
os.abort()
|
|
||||||
|
|
||||||
logger.info('launcher : *****Ending main()*****')
|
logger.info('launcher : *****Ending main()*****')
|
||||||
logger.info('launcher : *****Goodbye!*****')
|
logger.info('launcher : *****Goodbye!*****')
|
||||||
|
BIN
src/analyzer/id-card.ico
Normal file
BIN
src/analyzer/id-card.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.9 KiB |
1
src/launcher/conf.ig
Normal file
1
src/launcher/conf.ig
Normal file
@ -0,0 +1 @@
|
|||||||
|
6ycYLNx1sN8Mj+SlRRAzweESYblyfQvwl9J3erpw4EUT/4sOuvhEwM0vI+alw/vD
|
@ -26,8 +26,133 @@
|
|||||||
import hashlib
|
import hashlib
|
||||||
from pypac import PACSession
|
from pypac import PACSession
|
||||||
from requests.auth import HTTPProxyAuth
|
from requests.auth import HTTPProxyAuth
|
||||||
|
import base64, hashlib
|
||||||
|
from Crypto import Random
|
||||||
|
from Crypto.Cipher import AES
|
||||||
|
import os
|
||||||
|
|
||||||
|
import logger # logger.py
|
||||||
|
import globs # globs.py
|
||||||
|
import ihm # ihm.py
|
||||||
|
|
||||||
|
class AESCipher(object):
|
||||||
|
|
||||||
|
def __init__(self, key):
|
||||||
|
self.bs = 32
|
||||||
|
self.key = hashlib.sha256(key.encode()).digest()
|
||||||
|
|
||||||
|
def encrypt(self, raw):
|
||||||
|
raw = self._pad(raw)
|
||||||
|
iv = Random.new().read(AES.block_size)
|
||||||
|
cipher = AES.new(self.key, AES.MODE_CBC, iv)
|
||||||
|
return base64.b64encode(iv + cipher.encrypt(raw))
|
||||||
|
|
||||||
|
def decrypt(self, enc):
|
||||||
|
enc = base64.b64decode(enc)
|
||||||
|
iv = enc[:AES.block_size]
|
||||||
|
cipher = AES.new(self.key, AES.MODE_CBC, iv)
|
||||||
|
return self._unpad(cipher.decrypt(enc[AES.block_size:])).decode('utf-8')
|
||||||
|
|
||||||
|
def _pad(self, s):
|
||||||
|
return s + (self.bs - len(s) % self.bs) * chr(self.bs - len(s) % self.bs)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _unpad(s):
|
||||||
|
return s[:-ord(s[len(s) - 1:])]
|
||||||
|
|
||||||
|
|
||||||
|
class newcredentials:
|
||||||
|
def __init__(self):
|
||||||
|
|
||||||
|
logfile = logger.logCur
|
||||||
|
|
||||||
|
self.login = ''
|
||||||
|
self.password = ''
|
||||||
|
self.valid = False
|
||||||
|
self.readInTheBooks = False
|
||||||
|
self.trying = 0
|
||||||
|
session = PACSession()
|
||||||
|
|
||||||
|
while True:
|
||||||
|
self.trying += 1
|
||||||
|
|
||||||
|
try:
|
||||||
|
sessionAnswer = session.get('https://www.google.com')
|
||||||
|
except Exception as e:
|
||||||
|
logfile.printerr('Network Error : ' + str(e))
|
||||||
|
sessionAnswer = '<Response [407]>'# XXX TO DEBUG XXX
|
||||||
|
|
||||||
|
logfile.printdbg("Session Answer : " + str(sessionAnswer))
|
||||||
|
|
||||||
|
if str(sessionAnswer) == '<Response [200]>':
|
||||||
|
logfile.printdbg('Successfully connected to the Internet !')
|
||||||
|
self.sessionHandler = session
|
||||||
|
self.valid = True
|
||||||
|
return
|
||||||
|
|
||||||
|
if str(sessionAnswer) != '<Response [407]>':
|
||||||
|
logfile.printerr('Network Error!')
|
||||||
|
return
|
||||||
|
|
||||||
|
if self.trying > 3:
|
||||||
|
logfile.printerr('Invalid credentials : access denied, a maximum of 3 trials have been raised !')
|
||||||
|
return
|
||||||
|
|
||||||
|
logfile.printdbg('Invalid credentials : access denied')
|
||||||
|
|
||||||
|
# Deleting the root of Evil if needed
|
||||||
|
if self.readInTheBooks:
|
||||||
|
os.remove(globs.CNIRFolder + '\\conf.ig')
|
||||||
|
logfile.printdbg("Deleting the root of Evil")
|
||||||
|
|
||||||
|
try:
|
||||||
|
with open(globs.CNIRFolder + '\\conf.ig', 'rb') as (configFile):
|
||||||
|
self.readInTheBooks = True
|
||||||
|
# Decrypt the config file
|
||||||
|
AESObj = AESCipher(globs.CNIRCryptoKey)
|
||||||
|
try:
|
||||||
|
# Reading it
|
||||||
|
reading = AESObj.decrypt(configFile.read())
|
||||||
|
# Parsing it
|
||||||
|
if reading != '||':
|
||||||
|
if reading.find('||') != -1:
|
||||||
|
# TADAAA
|
||||||
|
self.login, self.password = reading.split('||')[0:2]
|
||||||
|
else:
|
||||||
|
# UPS
|
||||||
|
logfile.printerr('Cryptokey is bad !')
|
||||||
|
return
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
raise IOError(str(e))
|
||||||
|
|
||||||
|
except FileNotFoundError:
|
||||||
|
logfile.printdbg('We will ask for credentials then')
|
||||||
|
|
||||||
|
launcherWindow = ihm.launcherWindowCur
|
||||||
|
|
||||||
|
# Parameters for the password invite
|
||||||
|
invite = ihm.LoginDialog(launcherWindow)
|
||||||
|
invite.transient(launcherWindow)
|
||||||
|
invite.grab_set()
|
||||||
|
|
||||||
|
launcherWindow.wait_window(invite)
|
||||||
|
|
||||||
|
# Getting the credentials
|
||||||
|
self.login = invite.login
|
||||||
|
self.password = invite.key
|
||||||
|
|
||||||
|
AESObj = AESCipher(globs.CNIRCryptoKey)
|
||||||
|
with open(globs.CNIRFolder + '\\conf.ig', 'wb+') as (configFile):
|
||||||
|
logfile.printdbg('Saving credentials in encrypted config file')
|
||||||
|
configFile.write(AESObj.encrypt(self.login + '||' + self.password))
|
||||||
|
|
||||||
|
|
||||||
|
return
|
||||||
|
|
||||||
class newdownload():
|
class newdownload():
|
||||||
def __init__(url):
|
def __init__(self, credentials, urlFile, destinationFile):
|
||||||
self.url = url
|
self.urlFile = urlFile
|
||||||
|
self.destinationFile = destinationFile
|
||||||
|
|
||||||
|
|
@ -28,3 +28,4 @@ CNIRTesserHash = '5b58db27f7bc08c58a2cb33d01533b034b067cf8'
|
|||||||
CNIRFolder = os.getcwd()
|
CNIRFolder = os.getcwd()
|
||||||
CNIRLColor = "#006699"
|
CNIRLColor = "#006699"
|
||||||
CNIRName = "CNIRevelator Launcher 3"
|
CNIRName = "CNIRevelator Launcher 3"
|
||||||
|
CNIRCryptoKey = '82Xh!efX3#@P~2eG'
|
||||||
|
@ -34,6 +34,8 @@ import globs # globs.py
|
|||||||
class LoginDialog(Toplevel):
|
class LoginDialog(Toplevel):
|
||||||
|
|
||||||
def __init__(self, parent):
|
def __init__(self, parent):
|
||||||
|
self.key = ''
|
||||||
|
self.login = ''
|
||||||
super().__init__(parent)
|
super().__init__(parent)
|
||||||
self.title('Connexion')
|
self.title('Connexion')
|
||||||
Label(self, text='IPN : ').pack()
|
Label(self, text='IPN : ').pack()
|
||||||
@ -55,16 +57,13 @@ class LoginDialog(Toplevel):
|
|||||||
self.iconbitmap(sys._MEIPASS + '\\id-card.ico\\id-card.ico')
|
self.iconbitmap(sys._MEIPASS + '\\id-card.ico\\id-card.ico')
|
||||||
else:
|
else:
|
||||||
self.iconbitmap('id-card.ico')
|
self.iconbitmap('id-card.ico')
|
||||||
upwin.update()
|
|
||||||
x = ws / 2 - w / 2
|
x = ws / 2 - w / 2
|
||||||
y = hs / 2 - h / 2
|
y = hs / 2 - h / 2
|
||||||
self.geometry('%dx%d+%d+%d' % (w, h, x, y))
|
self.geometry('%dx%d+%d+%d' % (w, h, x, y))
|
||||||
|
|
||||||
def logingin(self):
|
def connecti(self):
|
||||||
global key
|
self.login = self.entry_login.get().strip()
|
||||||
global login
|
self.key = self.entry_pass.get().strip()
|
||||||
login = self.entry_login.get().strip()
|
|
||||||
key = self.entry_pass.get().strip()
|
|
||||||
self.destroy()
|
self.destroy()
|
||||||
|
|
||||||
class LauncherWindow(Tk):
|
class LauncherWindow(Tk):
|
||||||
|
@ -34,7 +34,7 @@ class NewLoggingSystem:
|
|||||||
|
|
||||||
# Deleting the error log
|
# Deleting the error log
|
||||||
try:
|
try:
|
||||||
os.remove(globs.CNIRFolder + '\\error.log') # The deletion does not working
|
os.remove(globs.CNIRFolder + '\\error.log')
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
#print(str(e) + " : " + str(globs.CNIRFolder + '\\error.log'))
|
#print(str(e) + " : " + str(globs.CNIRFolder + '\\error.log'))
|
||||||
pass
|
pass
|
||||||
|
@ -31,6 +31,7 @@ import time
|
|||||||
import logger # logger.py
|
import logger # logger.py
|
||||||
import globs # globs.py
|
import globs # globs.py
|
||||||
import ihm # ihm.py
|
import ihm # ihm.py
|
||||||
|
import downloader # downloader.py
|
||||||
|
|
||||||
def createShortcut(path, target='', wDir='', icon=''):
|
def createShortcut(path, target='', wDir='', icon=''):
|
||||||
ext = path[-3:]
|
ext = path[-3:]
|
||||||
@ -59,7 +60,17 @@ def batch():
|
|||||||
|
|
||||||
for i in range(0,10000):
|
for i in range(0,10000):
|
||||||
if i % 1000 : launcherWindow.mainCanvas.itemconfigure(launcherWindow.msg, text=('Starting... ' + str(i)))
|
if i % 1000 : launcherWindow.mainCanvas.itemconfigure(launcherWindow.msg, text=('Starting... ' + str(i)))
|
||||||
return
|
|
||||||
|
credentials = downloader.newcredentials()
|
||||||
|
|
||||||
|
if not credentials.valid:
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
for i in range(10000,20000):
|
||||||
|
if i % 1000 : launcherWindow.mainCanvas.itemconfigure(launcherWindow.msg, text=('Starting... ' + str(i)))
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
## Main Function
|
## Main Function
|
||||||
def umain():
|
def umain():
|
||||||
@ -69,7 +80,8 @@ def umain():
|
|||||||
launcherWindow = ihm.launcherWindowCur
|
launcherWindow = ihm.launcherWindowCur
|
||||||
|
|
||||||
try:
|
try:
|
||||||
batch()
|
# EXECUTING THE UPDATE BATCH
|
||||||
|
success = batch()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logfile.printerr("An error occured on the thread : " + str(traceback.format_exc()))
|
logfile.printerr("An error occured on the thread : " + str(traceback.format_exc()))
|
||||||
launcherWindow.mainCanvas.itemconfigure(launcherWindow.msg, text=('ERROR : ' + str(e)))
|
launcherWindow.mainCanvas.itemconfigure(launcherWindow.msg, text=('ERROR : ' + str(e)))
|
||||||
@ -77,7 +89,12 @@ def umain():
|
|||||||
launcherWindow.destroy()
|
launcherWindow.destroy()
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
|
if success:
|
||||||
|
logfile.printdbg("Software is up-to-date !")
|
||||||
launcherWindow.mainCanvas.itemconfigure(launcherWindow.msg, text='Software is up-to-date !')
|
launcherWindow.mainCanvas.itemconfigure(launcherWindow.msg, text='Software is up-to-date !')
|
||||||
|
else:
|
||||||
|
logfile.printerr("An error occured. No effective update !")
|
||||||
|
launcherWindow.mainCanvas.itemconfigure(launcherWindow.msg, text='An error occured. No effective update !')
|
||||||
time.sleep(2)
|
time.sleep(2)
|
||||||
launcherWindow.destroy()
|
launcherWindow.destroy()
|
||||||
return 0
|
return 0
|
||||||
@ -88,4 +105,5 @@ def umain():
|
|||||||
sys.exit(2)
|
sys.exit(2)
|
||||||
return 2
|
return 2
|
||||||
|
|
||||||
|
return
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user