"""#!/usr/bin/env pyton3 # -*- coding: UTF-8 -*- '__autor__' =='serkus' """ #from http.server import HTTPServer, SimpleHTTPRequestHandler, BaseHTTPRequestHandler import logging #from core.handler import Handler as Handler import os, sys, json, ssl #PORT_NUMBER = 8000 from utils.findfsdb import create_db from utils.utils import load_config import json # from BaseHTTPServer import BaseHTTPRequestHandler,HTTPServer #from http.server import BaseHTTPRequestHandler from core.bottle.bottle import Bottle, run #route, post, head, request, error, run from utils.utils import get_list_overlays, load_config, write_config, sort_install_pkg from utils.package import search from utils.findfsdb import on_find from core.route import Router from core.jwt import genaratorSecretsToken import logging from io import BytesIO #repl = '\n' app = Bottle() @app.post('/login') def login(user='demo', password='demo'): if auth(): return(generatoSecretsToken()) else: return ("403") @app.post('/') def main(): try: with open('./pkgs.json', 'tr') as fn: data = fn.read() pkg_list = json.loads(data) #print(pkg_list) return json.dumps(pkg_list) except Exception(e): print(e) return "404" @app.post('/set/settings') def set_settings_app(params): config = load_config() # param = self.path.replace("/?st_app=", "") list_param = param.split(',') print(list_param) for i in list_param: if i.startswith('port'): port = int(i.split('=')[1]) elif i.startswith('Lang'): Lang = i.split('=')[1] write_config(port, Lang) print(config) print(param) @app.post('/find') def search(pkg): # param = self.path.replace("/find?pkg=", "") #request['params']['name'] Pk_list = [] Search_result = {} if len(param.split('/')) == 2: param = param.split('/')[1] P_list = on_find(param) print(p_list) if len(P_list) == 0: print("Never Found") self.r_t = str(json.dumps({"Package_result": p_list})) else: for p in p_list: print(p) if len(param.split("/")) == 2: Pk_list.append(search(param.split("/")[1])) else: Pk_list.append(search(param)) # print(pk) Search_result = {"Package_result": Pk_list} # self.r_t = str(json.dumps(search_result)) return str(json.dumps(Search_result)) # self.r_t = json.dumps(pkg_list) @app.post('/get/settings') def get_settings_app(): return str(json.dumps(load_config())) @app.post('/install') def install(): # os.sys(emerge ) pass @app.post('/delete') def delete(): #os.sys('emerge -C ') pass @app.post('/get/set_world') def get_setWorld(): """with open('/var/lib/portage/set_world') as fSet: setList = fSet.read().split('\n') return json.dumps('set_world':setList}) """ @app.post('/set/set_world') def set_setWorld(): pass @app.post('/docs') def docs(): pass @app.route('/',['GET']) def req_get(): try: with open('./pkgs.json', 'tr') as fn: data = fn.read() pkg_list = json.loads(data) #print(pkg_list) return json.dumps(pkg_list) except Exception(e): print(e) return "404" #return" 403" def runServer(): create_db() config = load_config() if len(config) == 0: print("Файл конфигурации пустой.") return 1 try: print(config['PORT']) except KeyError: print("KeyError") except KeyboardInterrupt: pass #[3] keyfile='key.pem', run(host='0.0.0.0', port= config['Server']['PORT'], certfile='localhost.pem') """ def https_server(): https_server_address = ('', 4443) httpd = HTTPServer(https_server_address, SimpleHTTPRequestHandler) httpd.socket = ssl.wrap_socket(httpd.socket, server_side = True, certfile = 'localhost.pem', ssl_version = ssl.PROTOCOL_TLS) httpd.serve_forever() def run(): create_db() config = load_config() if len(config) == 0: print("Файл конфигурации пустой.") return 1 try: print(config['PORT']) except KeyError: print("KeyError") except KeyboardInterrupt: pass # server = HTTPServer(('', config['PORT']), Router) server = HTTPServer(('', config['Server']['PORT']), Handler) # print('Started HTTP Server on port', config['PORT']) server.socket = ssl.wrap_socket(server.socket, server_side = True, certfile = 'localhost.pem', ssl_version = ssl.PROTOCOL_TLS) print('Started HTTP Server on port', config['Server']['PORT']) print("https://localhost:8000") try: server.serve_forever() except KeyboardInterrupt: logging.info('Stopping httpd...\n') server.server_close() """ if __name__ == '__main__': #https_server() #run() #https_server() runServer()