(Đồ án hcmute) nghiên cứu xây dựng nền tảng phần mềm fullstack mqtt cho kỹ sư

109 3 0
(Đồ án hcmute) nghiên cứu xây dựng nền tảng phần mềm fullstack mqtt cho kỹ sư

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

BỘ GIÁO DỤC VÀ ĐÀO TẠO TRƯỜNG ĐẠI HỌC SƯ PHẠM KỸ THUẬT THÀNH PHỐ HỒ CHÍ MINH ĐỒ ÁN TỐT NGHIỆP NGÀNH CNKT CƠ ĐIỆN TỬ NGHIÊN CỨU XÂY DỰNG NỀN TẢNG PHẦN MỀM FULLSTACK-MQTT CHO KỸ SƯ GVHD: ThS LÊ PHAN HƯNG SVTH: NGUYỄN TRẦN PHÚC BẢO NGUYỄN NAM BÌNH S K L0 Tp Hồ Chí Minh, 2023 TRƯỜNG ĐẠI HỌC SƯ PHẠM KỸ THUẬT TP.HỒ CHÍ MINH KHOA CƠ KHÍ CHẾ TẠO MÁY ĐỒ ÁN TỐT NGHIỆP NGHIÊN CỨU XÂY DỰNG NỀN TẢNG PHẦN MỀM FULLSTACK-MQTT CHO KỸ SƯ GVHD: ThS LÊ PHAN HƯNG SVTH: NGUYỄN TRẦN PHÚC BẢO 17146232 NGUYỄN NAM BÌNH Khố: 2017 Tp Hồ Chí Minh, ngày 17 tháng nằm 2023 17146233 TRƯỜNG ĐẠI HỌC SƯ PHẠM KỸ THUẬT TP.HỒ CHÍ MINH KHOA CƠ KHÍ CHẾ TẠO MÁY ĐỒ ÁN TỐT NGHIỆP NGHIÊN CỨU XÂY DỰNG NỀN TẢNG PHẦN MỀM FULLSTACK-MQTT CHO KỸ SƯ GVHD: ThS LÊ PHAN HƯNG SVTH: NGUYỄN TRẦN PHÚC BẢO 17146232 NGUYỄN NAM BÌNH Khố: 2017 Tp Hồ Chí Minh, ngày 17 tháng nằm 2023 17146233 i TRƯỜNG ĐẠI HỌC SƯ PHẠM KỸ THUẬT TP HCM CỘNG HOÀ XÃ HỘI CHỦ NGHĨA VIỆT NAM KHOA CƠ KHÍ CHẾ TẠO MÁY Độc lập - Tự – Hạnh phúc NHIỆM VỤ ĐỒ ÁN TỐT NGHIỆP Giảng viên hướng dẫn: Th.S Lê Phan Hưng Sinh viên thực hiện: Nguyễn Trần Phúc Bảo Ngành: Công nghệ kỹ thuật Cơ điện tử Sinh viên thực hiện: Nguyễn Nam Bình Ngành: Cơng nghệ kỹ thuật Cơ điện tử MSSV: 17146232 Lớp: 171462A MSSV: 17146233 Lớp: 171462A Tên đề tài: - Nguyên cứu xây dựng tảng phần mềm Fullstack-MQTT cho kỹ sư Các số liệu, tài liệu ban đầu: + Linh hoạt hiệu dự án + Dễ dàng sử dụng + Dễ dàng nâng cấp cá nhân hố mơ hình + Miễn phí sử dụng Nội dung đồ án: - Nội dung nghiên cứu tổng quan - Cơ sở lý thuyết - Thử nghiệm Kết luận Các sản phẩm dự kiến: + Tập vẽ + Thiết minh + Phần mềm tảng Ngày giao đồ án: Ngày nộp đồ án: Ngơn ngữ trình bày: Bản báo cáo: Tiếng Anh  Tiếng Việt  Trình bày bảo vệ: Tiếng Anh  Tiếng Việt  TRƯỞNG KHOA TRƯỞNG BỘ MÔN GIẢNG VIÊN HƯỚNG DẪN (Ký, ghi rõ họ tên) (Ký, ghi rõ họ tên) (Ký, ghi rõ họ tên) ii NGHIÊN CỨU XÂY DỰNG NỀN TẢNG PHẦN MỀM FULLSTACKMQTT DÀNH CHO KỸ SƯ iii TCP DANH MỤC VIẾT TẮT Transmission Control Protocol UDP User Datagram Protocol ATP AppleTalk Transaction Protocol CUDP Cyclic UDP RUDP Reliable User Datagram Protocol BGP Border Gateway Protocol DHCP Dynamic Host Configuration Protocol FTP File Transfer Protocol HTTP Hypertext Transfer Protocol HTTPS Hypertext Transfer Protocol Secure IMAP Internet Message Access Protocol IRC Internet Relay Chat MQTT Originally an initialism of MQ Telemetry Transport XMPP Messaging and Presence Protocol SYN Synchronize ACK Acknowledges FIN Finish URL Uniform Resource Locator iv MỤC LỤC DANH MỤC VIẾT TẮT iv MỤC LỤC v MỤC LỤC HÌNH ẢNH ix MỤC LỤC BẢNG x LỜI CAM ĐOAN xi LỜI CẢM ƠN: xii CHƯƠNG TỔNG QUAN 1.1 Lý chọn đề tài: 1.2 Tính cấp thiết đề tài: 1.3 Mục tiêu: 1.4 Phương pháp nghiên cứu đối tượng nghiên cứu: 1.5 Các sản phẩm tương tự sản phẩm tiền nhiệm 1.5.1 Sản phẩm Django: 1.5.2 Sản phẩm Flask: 1.6 Phạm vi đề tài: CHƯƠNG 2: CƠ SỞ LÝ THUYẾT 2.1 Mô hình mạng OSI: 2.2 Giao thức mạng TCP: 2.2.1 Lịch sử giao thức TCP: 2.2.2 Bản thân TCP: 2.2.3 Cách hoạt động giao tiếp phương thức TCP 2.3 Nền tảng WWW (world wide web): 2.4 Giao thức HTTP: 2.4.1 HTTP gì? 2.4.2 Cách hoạt động phương thức HTTP hạ tầng mạng: 2.4.3 Các phương thức giao thức mạng HTTP: 2.5 Mã hoá liệu: 2.6 Mã hoá bất đối xứng: 2.7 Mã hoá đối xứng: 2.8 Phương thức HTTPS: 2.9 Các khái niệm Python 2.9.1 Cách thực thi lệnh Python: v 2.9.2 Khái niệm Indentation (Thụt lề) Python 2.9.3 Biến Python: 2.9.4 Ghi Python: 10 2.9.5 Các nguyên tắc đặt tên biến 10 2.9.6 Các kiểu liệu Python: 10 2.9.7 Kiểu văn Python (str): 11 2.9.8 Cắt văn (str) Python: 11 2.9.9 Cắt văn từ vị trí Python: 11 2.9.10 Cắt văn đến vị trí cuối Python: 12 2.9.11 Chỉ mục âm: 12 2.9.12 Chuyển đổi liệu sang dạng viết hoa Python: 12 2.9.13 Chuyển đổi liệu sang dạng viết hoa Python (với casefold): 12 2.9.14 Chuyển đổi liệu sang dạng viết thường Python: 12 2.9.15 Xoá khoảng trắng thừa Python: 12 2.9.16 Thay văn Python: 12 2.9.17 Tách văn tạo thành mảng Python: 12 2.9.18 Nối văn Python: 12 2.9.19 Cấu trúc xếp sẵn cho văn Python (Phần 1): 12 2.9.20 Cấu trúc xếp sẵn cho văn Python (Phần 2): 13 2.9.22 Cấu trúc xếp sẵn cho văn Python (Phần 4): 13 2.9.23 Cấu trúc xếp sẵn cho văn Python (Phần – với %): 13 2.9.24 Chuyển đổi chữ thành chữ viết hoa Python: 13 2.9.25 Canh lề Python: 13 2.9.26 Đếm số lần xuất văn văn gốc – Python: 13 2.9.27 Chuyển đổi văn sang chuẩn UTF-8 Python: 13 2.9.28 Tìm vị trí văn Python: 13 2.9.29 Kiểm tra tất ký tự có thuộc bảng Alphabet: 14 2.9.30 Kiểm tra tất ký tự có phải số: 14 2.9.31 Kiểm tra tất ký tự có phải số (Phần 2): 14 2.9.32 Boolean Python: 14 2.9.33 Số nguyên Python (int): 14 vi 2.9.34 Số thực Python (float): 14 2.9.35 Số phức Python: 14 2.9.36 Toán tử Python – Giới thiệu: 14 2.9.37 Toán tử số học: 15 2.9.39 Toán tử so sánh: 15 2.9.40 Toán tử lý luận (Logical): 15 2.9.41 Toán tử xác thực (Identify): 16 2.9.42 Toán tử Membership: 16 2.9.43 Toán tử Bitwise: 16 2.9.44 Danh sách Python 16 2.9.45 Truy xuất liệu qua số mục: 16 2.9.46 Chỉ số mảng: 17 2.9.47 Thay đổi giá trị phần tử: 17 2.9.48 Thêm phần tử từ đối tượng: 17 2.9.49 Thêm phần tử từ mảng khác: 17 2.9.50 Chèn phần tử vào mảng: 17 2.9.51 Xoá phần tử mảng: 17 2.9.52 Xoá phần tử qua mục: 17 2.9.53 Xoá tồn danh sách: 18 2.9.54 Xoá tất phần tử danh sách: 18 2.9.55 Vòng lặp với danh sách: 18 2.9.56 Lấy chiều dài danh sách: 18 2.9.57 Sắp xếp mảng chữ số: 18 2.9.58 Sao chép mảng: 18 2.9.59 Tuple Python: 18 2.9.60 Khởi tạo biến Tuple: 19 2.9.61 Truy xuất phần tử Tuple: 19 2.9.62 Vòng lặp for Python: 19 2.9.63 Vòng lặp while Python: 20 2.9.64 Các từ khóa tác động đến vòng lặp: 21 2.9.65 Câu lệnh điều kiện Python: 22 2.9.66 Cấu trúc lệnh if Python: 22 2.9.67 Lệnh if … else 24 vii elif not n % 2: return False r, s = 0, n - while s % == 0: r += s //= for _ in range(k): a = random.randrange(2, n - 1) a2 = pow(a, s, n) if a2 == or a2 == n - 1: continue for _ in range(r - 1): a = pow(a, 2, n) if a == n - 1: break else: return False return True def get_super_big_odd_number(bits): k=0 for i in range(bits - 2): k |= tuple: patternhead = '' patternbody = '' if js: jscode = f"{js}" else: jscode = "" if css: csscode = f"{css}" else: csscode = "" loc = html.find(patternhead) html = html[:loc] + jscode + html[loc:] loc = html.find(patternbody) html = html[:loc] + csscode + html[loc:] html = html.strip().encode() return html, len(html) def _render_with_base_html(basehtml, html, js, css) -> tuple: dpattern = { 'block' : '%begin {name}%[\W\s\w]*%end {name}%', 'blockbase': '%[a-zA-Z]*%', } _list_match = {} 81 for match in re.finditer(dpattern['blockbase'], basehtml): tmp_ = match.group().replace('%', '') try: tmp = re.search(f"{dpattern['block'].format(name=tmp_)}", html).group() tmp = tmp.splitlines() tmp = tmp[1:-1] tmp = '\n'.join([i.strip() for i in tmp]) except: tmp = "" finally: basehtml = basehtml.replace(f'%{tmp_}%', tmp) patternEmptyNoUse = r'[ ]+\n' for i in re.finditer(patternEmptyNoUse, basehtml): basehtml = basehtml.replace(i.group(), '') return GetRender._render_common(basehtml, js, css) def Render(**options) -> tuple: ''' \roptions: \r - filehtml strOrBytesPath \r - filecss strOrBytesPath \r - filejs strOrBytesPath \r - listfilecss strOrBytesPath \r - listfilejs strOrBytesPath \r - basehtml strOrBytesPath \r - basetohtml strOrBytesPath \r - basetocss strOrBytesPath \r - basetojs strOrBytesPath ''' filehtml = options.pop('filehtml', None) if not filehtml: raise ValueError('') filecss = options.pop('filecss', None) filejs = options.pop('filejs', None) listfilecss = options.pop('listfilecss', []) listfilejs = options.pop('listfilejs', []) basehtml = options.pop('basehtml', None) basetohtml = options.pop('basetohtml', '') basetocss = options.pop('basetocss', '') basetojs = options.pop('basetojs', '') datahtml = None datacss = None datajs = None basehtml = None try: with open(os.path.join(basetohtml, filehtml), 'rb') as f: datahtml = f.read().decode() except FileNotFoundError: print ("Not found file: '%s' with abspath is '%s'"%(filehtml, os.path.join(basetohtml, filehtml))) 82 listfilejs.append(filejs) listfilecss.append(filecss) datacss = '' for file_css in listfilecss: try: with open(os.path.join(basetocss, file_css), 'rb') as f: datacss += "\n%s"%f.read().decode() except: pass datacss =datacss.strip() datajs = '' for file_js in listfilejs: try: with open(os.path.join(basetojs, file_js), 'rb') as f: datajs += "\n%s"%f.read().decode() except: pass datajs =datajs.strip() if basehtml: try: with open(os.path.join(basetohtml, basehtml), 'rb') as f: basehtml = f.read().decode() except: pass if basehtml: return GetRender._render_with_base_html(basehtml, datahtml, datajs, datacss) else: return GetRender._render_common(datahtml, datajs, datacss) CODE XÁC ĐỊNH SQLINJECTION: class SQL: def injectionFromQuery(data, fmtdata = None): tmp = type(data) data = data.decode() if istype(data, bytes) else str(data) k = re.finditer("[']*([a-zA-Z0-9_]*)[']*\s*=\s*'([a-zA-Z0-9_]*)'", data) m = re.finditer("[']*([a-zA-Z0-9_]*)[']*\s*=\s*'([a-zA-Z0-9_%]*)'", fmtdata) lenm = lenk = for i in k: lenk+=1 for i in m: lenm+=1 if lenk != lenm: raise DangerousRequestException('\x1b[38;2;%d;%d;%dmSQL Injection\x1b[0m'%(255, 0, 0)) return tmp(data) CODE HTTP SERVER: from _sock import ( 83 _sock_object, socket ) from _dict_common_ import ( commonport ) from typings import ( strOrBytes, strOrBytesPath ) from supported._thread import ThreadHandling from supported._queue import Queue from TCPServer.tcpserver import TCPServer from func import request, response from typing import * import ssl class httpserver(_sock_object): def init ( self, host, port, listen: int = 20): self. tcp_server = TCPServer(host, port, listen) self. ca_file = None self. key_file = None self. context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER) self. ssl_sock = None self. is_https = False self. is_do_handshake = True def config( self, ca_file: strOrBytesPath = None, key_file: strOrBytesPath = None, **kwargs): self. ca_file = ca_file self. key_file = key_file self. is_do_handshake = kwargs.pop('is_do_hand_shake', self. is_do_handshake) if ca_file and key_file: 84 try: self. context .load_cert_chain(ca_file, key_file) self. is_https = True except: raise FileNotFoundError else: self. is_https = False def connect(self): self. tcp_server .connect() if self. is_https : self. ssl_sock = self. context .wrap_socket(self. tcp_server .connection, server_side=True, do_handshake_on_connect=self. is_do_handshake) else: self. ssl_sock = self. tcp_server .connection def disconnect(self): self. tcp_server .disconnect() def reconnect( self, ca_file: strOrBytesPath = None, key_file: strOrBytesPath = None): self. tcp_server .disconnect() self.config(ca_file, key_file) self.connect() def accept(self): return self. ssl_sock .accept() def _default_handling(sock, address, *args, **kargs): print(f'[+]Connect from {address[0]}:{address[1]}') k = request(sock, 1024) response(sock, b"""HTTP/1.1 200 OK Date: Mon, 27 Jul 2009 12:28:53 GMT Server: FullstackMQTT/0.0.1a (Win32) Last-Modified: Wed, 22 Jul 2009 19:15:56 GMT Content-Type: text/html Hello, World! """) def _default_end_handling(sock, address, *args, **kargs): try: sock.close() except: pass def loop_forever_http_server( host: str, 85 port : int, listen: int = 20, *args, **kwargs ) -> None: tmp = httpserver(host, port, listen) func_handling = kwargs.pop('handling_func', _default_handling) end_handling = kwargs.pop('end_handling', _default_end_handling) ca_file = kwargs.pop('ca_file', None) key_file = kwargs.pop('key_file', None) do_handshake = kwargs.pop('is_dohandshake', True) tmp.config(ca_file, key_file, is_do_hand_shake = do_handshake) tmp.connect() while True: try: ThreadHandling(None, func_handling, end_handling, *(*tmp.accept(), *args)).start() except: break CODE MQTT SERVER: from TCPServer.tcpserver import TCPServer from _sock import ( _sock_object, socket ) from typings import ( strOrBytes, strOrBytesPath ) from func import request, response from supported._thread import ThreadHandling from supported._queue import Queue from TCPServer.tcpserver import TCPServer from typing import * import json,random class mqttserver(_sock_object): def init (self, host, port, listen: int = 20): try: self. tcp_server = TCPServer(host, port, listen) except: print(f"We can't open MQTT server at {host}:{port}") self. address_server = (host, port) 86 self. listen = listen self. f = "C:\\Users\\Admin\\AppData\\Local\\Temp\\tempdata.json" self. fs = "C:\\Users\\Admin\\AppData\\Local\\Temp\\subcribe.json" def connack(**options): data = options['data'] messengerlen = data[1] & 0xff protocollen = (data[2] & 0xffff)

Ngày đăng: 06/10/2023, 18:04

Tài liệu cùng người dùng

Tài liệu liên quan