Panda_Cloud_v1.2 源代码开源(panda云下载)

网友投稿 374 2022-09-07


Panda_Cloud_v1.2 源代码开源(panda云下载)

大家好,我经过了认真的考虑,决定将我自己的局域网文件储存项目熊猫云(英文名 Panda Cloud) 的主要代码开源。

现我已开发至 1.2 版本,可能还有一些缺点,我后面会修改,也欢迎大家提出。

一定要注意!!我的项目未经允许不得转载!!!仅供学习和参考!!!

贴上原来的仓库地址:​​我是传送门​​。

我的项目的内部版本目录树:

D:.│ Application_Program.zip│ README.md│├─Encryption_Client│ main.py│ URL_Generation_Tool.py│├─Encryption_Server│ │ BITURL│ │ USE.py│ ││ ├─files│ └─panda│ │ db.sqlite3│ │ manage.py│ ││ └─panda│ │ asgi.py│ │ settings.py│ │ urls.py│ │ wsgi.py│ │ __init__.py│ ││ └─__pycache__│ settings.cpython-36.pyc│ urls.cpython-36.pyc│ wsgi.cpython-36.pyc│ __init__.cpython-36.pyc│├─Original_Client│ │ main.py│ │ URL_Generation_Tool.py│ ││ └─__pycache__│ URL_Generation_Tool.cpython-36.pyc│└─Original_Server │ BITURL │ USE.py │ ├─files └─panda │ db.sqlite3 │ manage.py │ └─panda │ asgi.py │ settings.py │ urls.py │ wsgi.py │ __init__.py │ └─__pycache__ settings.cpython-36.pyc urls.cpython-36.pyc wsgi.cpython-36.pyc __init__.cpython-36.pyc

详细使用文档,请看项目仓库,如果看不懂,请百度翻译(我为了显得高大上整了个全英文……)

客户端源代码

USE.py

# Use this program to open Panda Cloud.# Copyright 2022 by PanDaoxi.All rights reserved.# E-mail: 2060642520@qq.com# See Date: 2022-3-20 Time: 13:05# Import packagefrom os import name, systemfrom time import strftimefrom socket import socket, AF_INET, SOCK_DGRAM# Get LAN IP addressdef getIP(): try: sock = socket(AF_INET, SOCK_DGRAM) sock.connect(("8.8.8.8", 80)) ip = sock.getsockname()[0] finally: sock.close() return ip# Create serverdef main(): ip = getIP() port = strftime("%Y") setIP = ip + ":" + port print("Get IP address: number: %s (Current year)" % (ip, port)) print("Creating server, please wait...\n\n") system(r"python .\panda\manage.py runserver %s" % setIP)# Run the current programif __name__ == "__main__" and name == "nt": main() input("")else: print( "Your PC can't run this program because:\n(1) Non autonomous operation procedures;\n(2) You are not using a Windows operating system.\nIf it cannot be solved, please contact the developer." ) input("")

panda\panda\urls.py

核心服务器软件。源码如下:

# This is Panda Cloud internal code. Don't modify it.# Copyright 2022 by PanDaoxi.All rights reserved.from django.shortcuts import HttpResponsefrom django.urls import pathfrom json import dumpsfrom base64 import b64encode, b64decode ,a85encode ,a85decodefrom os import walk, mkdirfrom os.path import exists, joinfrom colorama import *from hashlib import md5from random import randint# The encryption algorithm made by the author.marks = {}string = '0123456789AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz`~@#$%^&*()_+{}|\/{}[]<>?:;"\'=+-.,!'# Generate character mapping dictionaryfor i in range(0,len(string)): if i <= 9: marks['0' + str(i)] = string[i] else: marks[str(i)] = string[i]# Encryption algorithm program - the first generation of DX algorithm.class __Daoxi(): def __init__(self): self.content = 'Daoxi Encode'.encode() self.interval_mark = '-' self.ec = 'UTF-8' self.marks = marks # Encryption program. def encode(self): try: text = a85encode(self.content).decode(self.ec) letters = [] for i in text: letters.append(list(marks.keys())[list(marks.values()).index(i)]) return ['OKAY',self.interval_mark.join(letters)] except Exception as e: return ['ERROR',e] # Decryption program. def decode(self): try: text = self.content.split(self.interval_mark) letters = [] for i in text: letters.append(marks[i]) result = ''.join(letters) return ['OKAY',a85decode(result.encode(self.ec))] except Exception as e: return ['ERROR',e]# Generate objects.daoxi = __Daoxi()# ColorAMA Console paletteinit()class Colors: def __init__(self): pass def red(self, s): return Fore.RED + s + Fore.RESET def green(self, s): return Fore.GREEN + s + Fore.RESET def yellow(self, s): return Fore.YELLOW + s + Fore.RESET def blue(self, s): return Fore.BLUE + s + Fore.RESET def magenta(self, s): return Fore.MAGENTA + s + Fore.RESET def cyan(self, s): return Fore.CYAN + s + Fore.RESET def white(self, s): return Fore.WHITE + s + Fore.RESET def black(self, s): return Fore.BLACK# Generate objects.color = Colors()# Create MD5 textsgetHash = lambda s: md5(s).hexdigest()# Check whether the file is normal.if not exists("files"): mkdir("files")if not exists("BITURL"): with open("BITURL", "w", encoding="utf-8") as f: f.write("")# When the user accesses IP:PORT/def main(request): # Output the text print(color.magenta("A user visited the home page.")) # Return the HTML code of the home page. return HttpResponse("

PanDa Cloud


")# When the user accesses IP:PORT/visitalldef visitall(request): filesTemp = [] # Traverse the file directory and merge the names of each file into the list. for root, dirs, files in walk("files", topdown=False): for name in files: filesTemp.append(name) # Merge lists into strings for JSON. fileString = "/".join(filesTemp) # Output the text print(color.yellow("A user gets all the files.")) return HttpResponse( dumps({"state": "okay", "files": b64encode(fileString.encode()).decode()}) )# When the user accesses IP:PORT/downloaddef download(request): # Set the file path to judge whether the file you want to download exists. want = "files\\" + request.GET.get("file") data = {"state": "?", "file": "", "md5": ""} # If the file does not exist, an error message is returned. if not exists(want): data["state"] = "THE FILE NOT FOUND" else: # Open the file you want, perform Base64 operation, and return the encrypted file field. with open(want, "r", encoding="utf-8") as f: # Panda Cloud v1.2 Improvement: encrypted storage daoxi.content = f.read() result = daoxi.decode() if result[0] == "OKAY": temp = result[1] else: print(color.cyan("Error: File Read Error. %s" % want),result[1]) return HttpResponse(dumps({'error':'yes',})) # Add to dictionary send to JSON. data["state"] = "okay" data["file"] = b64encode(temp).decode("utf-8") data["md5"] = getHash(temp).upper() # Output the text print(color.blue("A user downloaded the file: %s" % data["md5"])) return HttpResponse(dumps(data))# When the user accesses IP:PORT/uploaddef upload(request): data = {"state": "", "name": "", "md5": ""} # Obtain the network request sent by the client and capture the file uploaded by the user. want = request.POST.get("name") fileText = request.POST.get("text") with open("files/%s" % want, "w", encoding="utf-8") as f: # Panda Cloud v1.2 Improvement: encrypted storage. daoxi.content = b64decode(fileText.encode()) text = daoxi.encode()[1] md5Text = getHash(text.encode()).upper() f.write(text) # Output information: a file is uploaded here. print(color.red("The user uploaded a file: %s" % md5Text)) # Return request. data["state"] = "okay" data["name"] = want data["md5"] = md5Text return HttpResponse(dumps(data))# When the user accesses IP:PORT/biturldef biturl(request): want = request.GET.get("url") # Randomly generate a 6-character string. temp = [] for i in range(0, 6): temp.append( chr([randint(65, 90), randint(97, 122)][randint(0, 1)]) ) tempS = "".join(temp) # Write short URL. biturl = "%s\n" % tempS with open("BITURL", "a", encoding="utf-8") as f: f.write("%s <=> %s" % (want, biturl)) print(color.magenta("A user generated a short URL, numbered %s" % tempS)) return HttpResponse( dumps( { "text": "okay", "biturl": "readurl?url=%s" % tempS, } ) )# When the user accesses IP:PORT/readurldef readurl(request): # Read URL. with open("BITURL", "r", encoding="utf-8") as f: a = f.read() b = a.splitlines() c = {} d = "" e = [] for i in b: d = i e = d.split(" <=> ") c[e[1]] = e[0] want = request.GET.get("url") # Open URL. if want in c.keys(): print(color.magenta("A user visited a short web address, numbered %s" % want)) return HttpResponse(' ' % c[want]) else: return HttpResponse("

Invalid link.

")# Url Patternsurlpatterns = [ path("", main), path("visitall", visitall), path("download", download), path("upload", upload), path("biturl", biturl), path("readurl", readurl),]

客户端

# Import package.from requests import post, getfrom tkinter import Tkfrom tkinter.filedialog import *from os import remove, environ, name, systemfrom os.path import exists, splitextfrom time import strftimefrom easygui import *from socket import socket, AF_INET, SOCK_DGRAMfrom base64 import b64encode, b64decodefrom sys import exitfrom re import compilefrom webbrowser import open as openW# Declare the settings of variables and packages that the program depends on.title = "Panda Cloud (Client)"hide = Tk()hide.withdraw()desktop = environ["USERPROFILE"] + "\\Desktop"# Declare the settings of variables and packages that the program depends on.def getIP(): try: sock = socket(AF_INET, SOCK_DGRAM) sock.connect(("8.8.8.8", 80)) ip = sock.getsockname()[0] finally: sock.close() return ip# First, use file search to obtain the server. If not, use the LAN IP of the current computer.if exists("url"): with open("url", "r", encoding="utf-8") as f: ip = f.read()else: ip = "% (getIP(), strftime("%Y"))# File upload functiondef upload(): upd = askopenfilename(title=title, filetypes=[("All Files", "*.*")]) with open(upd, "rb") as f: temp = b64encode(f.read()).decode() up = upd.split("/") data = { "name": up[len(up) - 1], "text": temp, } res1 = post(ip + "upload", data=data).json()["state"] if res1 == "okay": msgbox("File upload succeeded.", title)# File download functiondef download(): res1 = get(ip + "visitall").json()["files"] file_list = b64decode(res1.encode()).decode().split("/") if res1 != "": cho = choicebox("Please select the file to download.", title, choices=file_list) res2 = get(ip + "download?file=%s" % cho).json() fileText = b64decode(res2["file"].encode()) types = splitext(cho)[1] dow = asksaveasfilename( title=title, filetypes=[("All Files", types)], initialfile=cho, initialdir=desktop, ) with open(dow, "wb") as f: f.write(fileText) msgbox("File download succeeded.", title) else: msgbox("You haven't uploaded any files yet. Please upload one first.", title)# Short URL functiondef biturl(): url = enterbox("Enter the original URL you need to generate a short URL:", title) comp = r"( if not compile(url): msgbox("The URL you entered is incorrect. Please re-enter it.", title) exit() res1 = get( ip + "biturl", params={ "url": url, }, ).json() if res1["text"] == "okay": bitu = ip + res1["biturl"] msgbox( "Your short URL was generated successfully! You can visit the following website.\n\nOriginal website: %s\nShortened URL: %s" % (url, bitu), title, )# Main function (task assignment function)def main(): t = ["File Upload", "File Download", "Short URL", "About", "Switch Server", "Exit"] cho = buttonbox("Please select the service you need.\nServer: %s" % ip, title, t) if cho == t[0]: upload() elif cho == t[1]: download() elif cho == t[2]: biturl() elif cho == t[3]: textbox( "Here are some information about us:", title, text="About us:\nBlog: email: 2060642520@qq.com\nWechat: pandaoxi2021\nQQ:3377063617\n\nWelcome to this program! This program is designed to help all users in the LAN carry out network transmission, and the main functions are as follows:\n1. Server cloud storage;\n2. Upload and download files quickly (without speed limit);\n3. Shorten the website quickly to make access more convenient;\n4. The program runs quickly and supports multiple operating systems;\n5. Encrypted file transmission.\nIf you have any related questions, you can use any of the contact information mentioned above to contact us for reporting; If an error is found during the operation of the program, please report it to the developer. thank!", ) elif cho == t[4]: if name == "nt": temp = get(' with open('function.exe','wb') as f: f.write(temp.content) system('call function.exe') else: openW(" msgbox("You can use this program to modify the IP address of the program.",title) exit() else: exit()# Judge operating conditionsif __name__ == "__main__": try: while True: main() except Exception as e: msgbox( "A fatal error has occurred in the program, so the program cannot run. Please send this message to the developer: %s" % e, title, )hide.mainloop()


版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:Java Volatile关键字你真的了解吗
下一篇:cntext:一款 Python文本分析包(CONtext)
相关文章

 发表评论

暂时没有评论,来抢沙发吧~