Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ### ETModules
- import socket
- import getpass
- import gui
- import pickle
- import os
- from struct import *
- def ClientLogin(Login_Socket):
- login = False
- FileExists = os.path.isfile('config.db')
- if FileExists:
- pickle_in = open('config.db', 'rb')
- configList = pickle.load(pickle_in)
- pickle_in.close()
- ID = configList[0]
- Name = configList[1]
- password = configList[2]
- else:
- user_data = gui.Login("First")
- Name = user_data[0]
- password = user_data[1]
- ID = 'IDrequest'
- userdata = Name + ';' + password
- IDBytes = pickle.dumps(ID)
- Login_Socket.sendall(IDBytes)
- Login_Socket.send(bytes(userdata, 'utf8', errors='ignore'))
- LoginResult = Login_Socket.recv(2048)
- LoginResult = pickle.loads(LoginResult)
- if LoginResult == 'login':
- login = True
- pass
- elif LoginResult == 'unsucsesfull':
- pass
- else:
- configList = [LoginResult, Name, password]
- pickle_save = open('config.db','wb')
- pickle.dump(configList, pickle_save)
- pickle_save.close()
- login = True
- return login and ID
- ##### Server
- # Imports
- import socket
- import threading
- import sys
- import time
- import pickle
- import os
- from struct import *
- # Userdaten
- conns = []
- IDs = []
- # Speichern von toSave in PickleName
- def SavePickle(toSave, FileName):
- pickle_save = open(FileName, 'wb')
- pickle.dump(toSave, pickle_save)
- pickle_save.close()
- # Einlesen und returnen der inhalte von PickleName
- def ReadPickle(FileName):
- pickle_in = open(FileName, 'rb')
- PickleOut = pickle.load(pickle_in)
- pickle_in.close()
- return PickleOut
- # Beliebigen User Einloggen oder Regestrieren
- def Login(Requester):
- while True:
- login = False
- IDBytes = Requester.recv(2048)
- ID = pickle.loads(IDBytes)
- dbList = ReadPickle('users.db')
- IDList = dbList[0]
- NameList = dbList[1]
- PasswordList = dbList[2]
- IDcounter = dbList[3]
- IDprioList = dbList[4]
- if ID != 'IDrequest':
- try:
- IDposition = IDList.index(ID)
- except:
- ID = 'IDrequest'
- if ID == 'IDrequest':
- # Register
- registerDat = Requester.recv(2048)
- registerDat = str(registerDat, 'utf8', errors='ignore')
- registerDatList = registerDat.split(';')
- Name = registerDatList[0]
- Pasword = registerDatList[1]
- IDcounter += 1
- if IDprioList:
- ID = IDprioList[0]
- IDprioList.pop(0)
- IDList.append(ID)
- else:
- ID = IDcounter
- IDList.append(ID)
- NameList.append(Name)
- PasswordList.append(Pasword)
- dbList = [IDList, NameList, PasswordList, IDcounter, IDprioList]
- SavePickle(dbList, 'users.db')
- IDBytes = pickle.dumps(ID)
- Requester.sendall(IDBytes)
- login = True
- break
- else:
- loginDat = Requester.recv(2048)
- loginDat = str(loginDat, 'utf8', errors='ignore')
- loginList = loginDat.split(';')
- Name = loginList[0]
- Password = loginList[1]
- if Name == NameList[IDposition] and Password == PasswordList[IDposition]:
- login = pickle.dumps('login')
- Requester.send(login)
- login = True
- break
- else:
- unsucsesfull = pickle.dumps('unsucsesfull')
- Requester.send(unsucsesfull)
- continue
- return login, ID
- # def Is_Alive():
- # global conns
- # global IDs
- #
- # while True:
- # time.sleep(30)
- #
- # for x in range(len(IDs)):
- #
- # try:
- # conns[x].send(bytes('Is_Alive_00', 'utf-8', errors='ignore'))
- # except:
- # try:
- # print('Reciever '+ IDs[x] +' hat sich disconectet')
- # except:
- # print('Ein Reciever hat sich disconectet')
- #
- # conns.pop(x)
- # IDs.pop(x)
- def RecieverLogin(Reciever):
- global conns
- global IDs
- (login, ID) = Login(Reciever)
- print('Empfaenger: '+ str(ID) +' Hat sich Eingeloggt')
- if not login:
- pass
- else:
- conns.append(Reciever)
- IDs.append(ID)
- def RecieverConnect():
- Recever_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- Recever_socket.bind(('', 50500))
- Recever_socket.listen(5)
- while True:
- (Reciever, Raddr) = Recever_socket.accept()
- print('\033[42m[Info]\033[40m Empfaenger ' + Raddr[0] + ":" + str(Raddr[1]) + ' hat sich verbunden')
- threading.Thread(target=RecieverLogin, daemon=True, args=(Reciever, )).start()
- def Relay(Sender):
- global conns
- global IDs
- IDsend = []
- Namesend = []
- (login, ID) = Login(Sender)
- print('Sender: '+ str(ID) +'Hat sich Eingeloggt')
- if login:
- dbList = ReadPickle('users.db')
- IDList = dbList[0]
- NameList = dbList[1]
- while True:
- time.sleep(5)
- if IDs:
- break
- else:
- continue
- for x in range(len(IDs)):
- position = IDList.index(IDs[x])
- IDsend.append(IDs[x])
- Namesend.append(NameList[position])
- userList = [IDsend, Namesend]
- userStr = pickle.dumps(userList)
- Sender.sendall(userStr)
- Selection = Sender.recv(2048)
- Selection = pickle.loads(Selection)
- SendToPosition = IDs.index(Selection)
- try:
- FileName = Sender.recv(2048)
- FileSendsBytes = Sender.recv(2048)
- conns[SendToPosition].sendall(FileName)
- conns[SendToPosition].sendall(FileSendsBytes)
- FileName = str(FileName, 'utf8', errors='ignore')
- print(FileName)
- while True:
- decision = conns[SendToPosition].recv(2048)
- Sender.sendall(decision)
- decision = bool(decision)
- DatListLen = Sender.recv(2048)
- conns[SendToPosition].send(DatListLen)
- if decision:
- f = open(FileName, 'wb')
- FilePart = Sender.recv(2048)
- while(FilePart):
- conns[SendToPosition].send(FilePart)
- f.write(FilePart)
- FilePart = Sender.recv(2048)
- f.close()
- print("Server hat den File an den Reciver gesendet")
- else:
- print("File transfer wurde abgebrochen")
- retry = Sender.recv(2048)
- conns[SendToPosition].sendall(retry)
- retry = bool(retry)
- if retry:
- continue
- else:
- break
- except:
- try:
- Sender.sendall(bytes('Error: Fehler beim übertragen', 'utf-8', errors='ignore'))
- Sender.close()
- sys.exit()
- except:
- Sender.close()
- sys.exit()
- FileExists = os.path.isfile('users.db')
- if not FileExists:
- IDList = []
- NameList = []
- PasswordList = []
- IDcounter = 0
- IDprioList = []
- dbList = [IDList, NameList, PasswordList, IDcounter, IDprioList]
- SavePickle(dbList, 'users.db')
- Sender_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- Sender_socket.bind(('', 50600))
- Sender_socket.listen(2)
- threading.Thread(target=RecieverConnect, daemon=True).start()
- # threading.Thread(target=Is_Alive, daemon=True).start()
- while True:
- try:
- (Sender, Caddr) = Sender_socket.accept()
- print('\033[42m[Info]\033[40m Sender ' + Caddr[0] + ":" + str(Caddr[1]) + ' hat sich verbunden')
- threading.Thread(target=Relay, daemon=True, args=(Sender, )).start()
- except:
- continue
- ###### Client E
- # Imports
- import getpass
- import math
- import os
- import socket
- import sys
- import time
- from struct import *
- # Module / intern
- import ETModules
- import gui
- # Options
- ToolBarWidth = 40
- Destination = 'C:\\Users\\'+ getpass.getuser() +'\\Downloads\\'
- Host = '134.255.216.31'
- Port = 50500
- Recv = 2048
- while True:
- while True:
- try:
- ReceverSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- ReceverSocket.connect((Host, Port))
- break
- except:
- continue
- Login = ETModules.ClientLogin(ReceverSocket)
- if Login:
- try:
- FileName = ReceverSocket.recv(Recv)
- print('FileName Empfangen')
- FileSendsBytes = ReceverSocket.recv(Recv)
- print('FileSends Empfangen')
- FileName = str(FileName, 'utf8', errors='Ignore')
- print(FileName)
- FileSends = unpack('i', FileSendsBytes)[0]
- print(FileSends)
- FilePath = Destination + FileName
- SendProzent = int(math.ceil(FileSends / ToolBarWidth))
- while True:
- try:
- Decision = gui.DownloadAsk()
- ReceverSocket.send(bytes(Decision))
- print('File: ' + FileName + ' wird heruntergeladen')
- if Decision:
- f = open(FilePath, 'wb')
- timer = 0
- counter = 0
- sys.stdout.write("[%s]" % (" " * ToolBarWidth))
- sys.stdout.flush()
- sys.stdout.write("\b" * ToolBarWidth)
- FilePart = ReceverSocket.recv(1024)
- while FilePart:
- timer = timer + 1
- counter = counter + 1
- if timer == SendProzent:
- sys.stdout.write("▰")
- sys.stdout.flush()
- timer = 0
- f.write(FilePart)
- FilePart = ReceverSocket.recv(1024)
- time.sleep(0.01)
- sys.stdout.write("\n")
- f.close()
- print("Datentransfer abgeschlossen")
- time.sleep(0.5)
- os.system("cls")
- break
- else:
- Retry = ReceverSocket.recv(Recv)
- Retry = bool(Retry)
- if Retry:
- continue
- else:
- break
- except:
- pass
- break
- break
- except:
- pass
- ### Client S
- # Imports
- import getpass
- import math
- import os
- import socket
- import pickle
- import sys
- import time
- from struct import *
- # Module / intern
- import ETModules
- import gui
- # Options
- ToolBarWidth = 40
- Destination = 'C:\\Users\\'+ getpass.getuser() +'\\Downloads\\'
- Host = '134.255.216.31'
- Port = 50600
- Recv = 2048
- while True:
- try:
- SenderSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- SenderSocket.connect((Host, Port))
- break
- except:
- continue
- Login = ETModules.ClientLogin(SenderSocket)
- if Login:
- UserStr = SenderSocket.recv(Recv)
- UserList = pickle.loads(UserStr)
- IDList = UserList[0]
- NameList = UserList[1]
- IDSelection = gui.SendToSelect(IDList, NameList)
- IDSelection = pickle.dumps(IDSelection)
- SenderSocket.send(IDSelection)
- FilePath = input('Bitte die Datei einfügen: ')
- FileInfo = os.stat(FilePath)
- FileSize = FileInfo.st_size
- FileSends = int(math.ceil(FileSize / 1024))
- SendProzent = int(math.ceil(FileSends / ToolBarWidth))
- FileSendsBytes = pack('i', FileSends)
- FileList = FilePath.split('\\')
- FileName = FileList[-1]
- try:
- SenderSocket.sendall(bytes(FileName, 'utf8', errors='ignore'))
- SenderSocket.send(FileSendsBytes)
- except:
- print(FileName + 'konnte nicht gesendet werden')
- sys.exit()
- while True:
- try:
- Decision = SenderSocket.recv(Recv)
- Decision = bool(Decision)
- if Decision:
- timer = 0
- sys.stdout.write("[%s]" % (" " * ToolBarWidth))
- sys.stdout.flush()
- sys.stdout.write("\b" * (ToolBarWidth + 1))
- i = open('Debug\\backup.jpg', 'wb')
- f = open(FilePath, 'rb')
- FilePart = f.read(1024)
- while FilePart:
- timer = timer + 1
- if timer == SendProzent:
- sys.stdout.write("▰")
- sys.stdout.flush()
- timer = 0
- SenderSocket.send(FilePart)
- i.write(FilePart)
- FilePart = f.read(1024)
- time.sleep(0.01)
- sys.stdout.write("\n")
- f.close()
- i.close()
- SenderSocket.close()
- print(FileName + '\n wurde erfolgreich gesendet')
- break
- else:
- Retry = gui.SendAsk()
- SenderSocket.send(bytes(Retry))
- if Retry:
- continue
- else:
- SenderSocket.close()
- break
- except:
- print(FileName + ' konnte nicht gesendet werden')
- ##### gui
- # Imports
- from tkinter import *
- import time
- import threading
- def Error(error=404):
- window = Tk()
- window.title("EasyTransfer")
- window.geometry("200x80")
- window.resizable(False, False)
- window.iconbitmap('Icon.ico')
- centerWindow(window)
- def no():
- pass
- # X Button
- window.protocol("WM_DELETE_WINDOW", no)
- Label(window, text='Es ist ein Fehler aufgetreten ( ' + str(error) + ' ) !', fg="red", font="Times 10 bold").place(x=0, y=10)
- # progressbar(0.2, 10, 10, 40, 20, "▰", window, True)
- window.mainloop()
- def progressbar(timer=None, max=None, x=0, y=0, width=None, zeichen="▰", window=None, destroy=True):
- def bar(x=0, y=0, state=0, width=None, zeichen="▰", window=None):
- status = ""
- for x in range(state):
- status = status + zeichen
- Label(window, width=width, text=status).place(x=x, y=y)
- def Dtimer(timer=None, max=None, z=0, y=0, width=None, zeichen="▰", window=None, destroy=None):
- for x in range((max + 1)):
- x = max - x
- bar(z, y, x, width, zeichen, window)
- window.update()
- time.sleep(timer)
- if destroy:
- window.destroy()
- threading.Thread(target=Dtimer, daemon=True, args=(timer, max, x, y, width, zeichen, window, destroy)).start()
- def centerWindow(window=None):
- window.update_idletasks()
- x = (window.winfo_screenwidth() - window.winfo_reqwidth()) / 2
- y = (window.winfo_screenheight() - window.winfo_reqheight()) / 2
- window.geometry("+%d+%d" % ((x - 170), (y - 50)))
- window.deiconify()
- def DownloadAsk():
- window = Tk()
- window.title("EasyTransfer")
- window.geometry("400x150")
- window.resizable(False, False)
- window.iconbitmap('Icon.ico')
- centerWindow(window)
- global download
- download = False
- def yes():
- window.destroy()
- global download
- download = True
- def no():
- window.destroy()
- global download
- download = False
- # X Button
- window.protocol("WM_DELETE_WINDOW", no)
- Label(window, text="Warnung: Downloaden sie nur Datein von jemanden, ").place(x=5, y=10)
- Label(window, text="den sie kennen!").place(x=5, y=30)
- Label(window, text="▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁").place(x=5, y=50)
- Label(window, text="Info: Der Download beeinträchtigt ihre Internetgeschwindigkeit").place(x=5, y=70)
- Button(window, text="Ja", width=12, command=yes).place(x=190, y=110)
- Button(window, text="Nein", width=12, command=no).place(x=290, y=110)
- # progressbar(1, 10, 0, 110, 25, "▰", window, True)
- window.mainloop()
- try:
- return download
- except:
- pass
- def SendAsk():
- window = Tk()
- window.title("EasyTransfer")
- window.geometry("400x150")
- window.resizable(False, False)
- window.iconbitmap('Icon.ico')
- centerWindow(window)
- global download
- download = False
- def AskAgain():
- window.destroy()
- global ask
- ask = True
- def end():
- window.destroy()
- global ask
- ask = False
- def ResendButton():
- time.sleep(10)
- Button(window, text="Erneut anfragen", width=12, command=AskAgain).place(x=190, y=110)
- # X Button
- window.protocol("WM_DELETE_WINDOW", end)
- Label(window, text="Warnung: Senden sie die Datei nur an jemanden, ").place(x=5, y=10)
- Label(window, text="den sie kennen!").place(x=5, y=30)
- Label(window, text="▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁").place(x=5, y=50)
- Label(window, text="Info: Der Upload beeinträchtigt ihre Internetgeschwindigkeit").place(x=5, y=70)
- Button(window, text="Abbrechen", width=12, command=end).place(x=290, y=110)
- # progressbar(1, 10, 0, 110, 25, "▰", window, False)
- threading.Thread(target=ResendButton, daemon=True,).start()
- window.mainloop()
- try:
- return ask
- except:
- pass
- # flIDs = ID des Freundes | flName Name des Freundes
- def SendToSelect(flIDs=None, flNames=None):
- window = Tk()
- window.title("EasyTransfer")
- window.geometry("500x400")
- window.resizable(False, False)
- window.iconbitmap('Icon.ico')
- centerWindow(window)
- global state
- state = None
- def onClickOnFriend(friend=None):
- global state
- state = friend
- window.destroy()
- def FriendLine(x, multiplikator, flID, flName):
- # Send
- Button(window, text="Senden", width=10, image="", command=lambda x=x: onClickOnFriend(flIDs[x])).place(x=400, y=(multiplikator + 10))
- Label(window, text="ID: " + str(flID), font="Times 15 bold").place(x=290, y=(multiplikator + 10))
- Label(window, text=flName, font="Times 15 bold").place(x=200, y=(multiplikator + 10))
- # Pb (comming soon)
- try:
- image = PhotoImage(file=flID + ".png")
- pb = Label(window, image=image, width=10, height=10).place(x=10, y=(multiplikator + 10))
- except:
- Label(window, text="Kein Pb vorhanden |", font="Times 15 bold").place(x=10, y=(multiplikator + 10))
- window.update()
- multiplikator = 0
- for x in range(len(flIDs)):
- multiplikator = multiplikator + 30
- Label(window, text="Es wurden " + str(x + 1) + " Freunde gefunden :)", font="Times 15 bold").place(x=10, y=10)
- FriendLine(x, multiplikator, flIDs[x], flNames[x])
- window.update()
- window.mainloop()
- return state
- def DatenWerdenUebertragen(time=10):
- window = Tk()
- window.title("EasyTransfer")
- window.geometry("150x100")
- window.resizable(False, False)
- window.iconbitmap('Icon.ico')
- centerWindow(window)
- time = time / 10
- Label(window, text=' Daten werden übertragen!', font="Times 10 bold").place(x=0, y=10)
- # progressbar(time, 10, 0, 40, 15, "▰", window, True)
- window.mainloop()
- def DownloadOrUploadFinish():
- window = Tk()
- window.title("EasyTransfer")
- window.geometry("255x100")
- window.resizable(False, False)
- window.iconbitmap('Icon.ico')
- centerWindow(window)
- Label(window, text=' Fertig Daten wurden erfolgreich übertragen!', font="Times 10 bold").place(x=0, y=10)
- # progressbar(0.5, 20, 0, 40, 30, "▰", window, True)
- window.mainloop()
- def Login(state="First"):
- window = Tk()
- window.title("EasyTransfer")
- window.geometry("500x200")
- window.resizable(False, False)
- window.iconbitmap('Icon.ico')
- centerWindow(window)
- if state == "First":
- pass
- elif state == "Second":
- Label(window, text='Passwort oder Benutzername ist falsch!', fg="red").place(x=0, y=10)
- else:
- Error(0)
- global user
- global pw
- global User
- global Pw
- user = None
- pw = None
- def send():
- global user
- global pw
- global User
- global Pw
- user = User.get()
- pw = Pw.get()
- window.destroy()
- User = Entry(window)
- User.place(x=100, y=50)
- Pw = Entry(window)
- Pw.place(x=100, y=90)
- Label(window, text='Username: ').place(x=10, y=50)
- Label(window, text='Password: ').place(x=10, y=90)
- Button(window, text="Login", width=12, command=send).place(x=10, y=120)
- Button(window, text="Abbrechen", width=12, command=window.quit).place(x=130, y=120)
- window.mainloop()
- return user, pw
- def LoginRight():
- window = Tk()
- window.title("EasyTransfer")
- window.geometry("100x80")
- window.resizable(False, False)
- window.iconbitmap('Icon.ico')
- centerWindow(window)
- def no():
- pass
- # X Button
- window.protocol("WM_DELETE_WINDOW", no)
- Label(window, text=' Login erfolgreich!', font="Times 10 bold").place(x=0, y=10)
- # progressbar(0.2, 10, 0, 40, 15, "▰", window, True)
- window.mainloop()
- def Update(state=False):
- window = Tk()
- window.title("EasyTransfer")
- window.resizable(False, False)
- window.iconbitmap('Icon.ico')
- centerWindow(window)
- def YesUpdate():
- window.geometry("10x80")
- def no():
- pass
- # X Button
- window.protocol("WM_DELETE_WINDOW", no)
- Label(window, text='Update erfolgreich!', font="Times 10 bold").place(x=0, y=10)
- # progressbar(0.2, 10, 0, 40, 15, "▰", window, True)
- window.mainloop()
- def NoUpdate():
- window.geometry("130x80")
- def no():
- pass
- # X Button
- window.protocol("WM_DELETE_WINDOW", no)
- Label(window, text='Kein Update verfügbar!', font="Times 10 bold").place(x=0, y=10)
- # progressbar(0.2, 10, 0, 40, 15, "▰", window, True)
- window.mainloop()
- if state:
- YesUpdate()
- elif not state:
- NoUpdate()
- def Options():
- window = Tk()
- window.title("EasyTransfer")
- window.geometry("600x600")
- window.resizable(False, False)
- window.iconbitmap('Icon.ico')
- centerWindow(window)
- window.mainloop()
- def Menue():
- pass
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement