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 : *****Hello World*****')
|
||||
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()*****')
|
||||
State = main(logger)
|
||||
except Exception as e:
|
||||
logger.info('launcher : *****FATAL ERROR*****' + str(e))
|
||||
os.abort()
|
||||
logger.info('launcher : *****Launching main()*****')
|
||||
State = main(logger)
|
||||
|
||||
|
||||
logger.info('launcher : *****Ending main()*****')
|
||||
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
|
||||
from pypac import PACSession
|
||||
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():
|
||||
def __init__(url):
|
||||
self.url = url
|
||||
def __init__(self, credentials, urlFile, destinationFile):
|
||||
self.urlFile = urlFile
|
||||
self.destinationFile = destinationFile
|
||||
|
||||
|
@ -28,3 +28,4 @@ CNIRTesserHash = '5b58db27f7bc08c58a2cb33d01533b034b067cf8'
|
||||
CNIRFolder = os.getcwd()
|
||||
CNIRLColor = "#006699"
|
||||
CNIRName = "CNIRevelator Launcher 3"
|
||||
CNIRCryptoKey = '82Xh!efX3#@P~2eG'
|
||||
|
@ -34,6 +34,8 @@ import globs # globs.py
|
||||
class LoginDialog(Toplevel):
|
||||
|
||||
def __init__(self, parent):
|
||||
self.key = ''
|
||||
self.login = ''
|
||||
super().__init__(parent)
|
||||
self.title('Connexion')
|
||||
Label(self, text='IPN : ').pack()
|
||||
@ -55,16 +57,13 @@ class LoginDialog(Toplevel):
|
||||
self.iconbitmap(sys._MEIPASS + '\\id-card.ico\\id-card.ico')
|
||||
else:
|
||||
self.iconbitmap('id-card.ico')
|
||||
upwin.update()
|
||||
x = ws / 2 - w / 2
|
||||
y = hs / 2 - h / 2
|
||||
self.geometry('%dx%d+%d+%d' % (w, h, x, y))
|
||||
|
||||
def logingin(self):
|
||||
global key
|
||||
global login
|
||||
login = self.entry_login.get().strip()
|
||||
key = self.entry_pass.get().strip()
|
||||
def connecti(self):
|
||||
self.login = self.entry_login.get().strip()
|
||||
self.key = self.entry_pass.get().strip()
|
||||
self.destroy()
|
||||
|
||||
class LauncherWindow(Tk):
|
||||
|
@ -34,7 +34,7 @@ class NewLoggingSystem:
|
||||
|
||||
# Deleting the error log
|
||||
try:
|
||||
os.remove(globs.CNIRFolder + '\\error.log') # The deletion does not working
|
||||
os.remove(globs.CNIRFolder + '\\error.log')
|
||||
except Exception as e:
|
||||
#print(str(e) + " : " + str(globs.CNIRFolder + '\\error.log'))
|
||||
pass
|
||||
|
@ -28,9 +28,10 @@ import traceback
|
||||
import sys
|
||||
import time
|
||||
|
||||
import logger # logger.py
|
||||
import globs # globs.py
|
||||
import ihm # ihm.py
|
||||
import logger # logger.py
|
||||
import globs # globs.py
|
||||
import ihm # ihm.py
|
||||
import downloader # downloader.py
|
||||
|
||||
def createShortcut(path, target='', wDir='', icon=''):
|
||||
ext = path[-3:]
|
||||
@ -59,7 +60,17 @@ def batch():
|
||||
|
||||
for i in range(0,10000):
|
||||
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
|
||||
def umain():
|
||||
@ -69,7 +80,8 @@ def umain():
|
||||
launcherWindow = ihm.launcherWindowCur
|
||||
|
||||
try:
|
||||
batch()
|
||||
# EXECUTING THE UPDATE BATCH
|
||||
success = batch()
|
||||
except Exception as e:
|
||||
logfile.printerr("An error occured on the thread : " + str(traceback.format_exc()))
|
||||
launcherWindow.mainCanvas.itemconfigure(launcherWindow.msg, text=('ERROR : ' + str(e)))
|
||||
@ -77,7 +89,12 @@ def umain():
|
||||
launcherWindow.destroy()
|
||||
return 1
|
||||
|
||||
launcherWindow.mainCanvas.itemconfigure(launcherWindow.msg, text='Software is up-to-date !')
|
||||
if success:
|
||||
logfile.printdbg("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)
|
||||
launcherWindow.destroy()
|
||||
return 0
|
||||
@ -88,4 +105,5 @@ def umain():
|
||||
sys.exit(2)
|
||||
return 2
|
||||
|
||||
return
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user