|
|
|
@ -1,4 +1,6 @@
|
|
|
|
|
from http.server import BaseHTTPRequestHandler, HTTPServer
|
|
|
|
|
from socketserver import ThreadingMixIn
|
|
|
|
|
import threading
|
|
|
|
|
import json
|
|
|
|
|
from threading import Thread
|
|
|
|
|
from . import Processor
|
|
|
|
@ -11,27 +13,6 @@ import os #for path operations
|
|
|
|
|
from http import cookies
|
|
|
|
|
global mGlobalDict
|
|
|
|
|
from . import ServerSettings
|
|
|
|
|
#inGlobalDict
|
|
|
|
|
# "JSONConfigurationDict":<JSON>
|
|
|
|
|
class RobotDaemonServer(Thread):
|
|
|
|
|
def __init__(self,name,inGlobalDict):
|
|
|
|
|
Thread.__init__(self)
|
|
|
|
|
self.name = name
|
|
|
|
|
# Update the global dict
|
|
|
|
|
ServerSettings.SettingsUpdate(mGlobalDict)
|
|
|
|
|
def run(self):
|
|
|
|
|
inServerAddress="";
|
|
|
|
|
inPort = mGlobalDict["Server"]["ListenPort"];
|
|
|
|
|
# Server settings
|
|
|
|
|
# Choose port 8080, for port 80, which is normally used for a http server, you need root access
|
|
|
|
|
server_address = (inServerAddress, inPort)
|
|
|
|
|
httpd = HTTPServer(server_address, testHTTPServer_RequestHandler)
|
|
|
|
|
# Logging
|
|
|
|
|
mGlobalDict["Logger"].info(f"Server init. Listen URL: {inServerAddress}, Listen port: {inPort}")
|
|
|
|
|
# Запуск адреса в браузере
|
|
|
|
|
os.system("explorer http://127.0.0.1:8081")
|
|
|
|
|
httpd.serve_forever()
|
|
|
|
|
|
|
|
|
|
#Authenticate function ()
|
|
|
|
|
# return dict
|
|
|
|
|
# {
|
|
|
|
@ -380,6 +361,17 @@ class testHTTPServer_RequestHandler(BaseHTTPRequestHandler):
|
|
|
|
|
lFlagUserAccess = UserAccessCheckBefore("POST", self)
|
|
|
|
|
######################################
|
|
|
|
|
if lFlagUserAccess:
|
|
|
|
|
lOrchestratorFolder = "\\".join(__file__.split("\\")[:-1])
|
|
|
|
|
############################
|
|
|
|
|
#New server engine (url from global dict (URLList))
|
|
|
|
|
############################
|
|
|
|
|
for lURLItem in mGlobalDict["Server"]["URLList"]:
|
|
|
|
|
#Check if all condition are applied
|
|
|
|
|
lFlagURLIsApplied=False
|
|
|
|
|
lFlagURLIsApplied=self.URLItemCheckDo(lURLItem, "POST")
|
|
|
|
|
if lFlagURLIsApplied:
|
|
|
|
|
self.ResponseDictSend()
|
|
|
|
|
return
|
|
|
|
|
#Централизованная функция получения запросов/отправки
|
|
|
|
|
if self.path == '/Utils/Processor':
|
|
|
|
|
#ReadRequest
|
|
|
|
@ -405,4 +397,37 @@ class testHTTPServer_RequestHandler(BaseHTTPRequestHandler):
|
|
|
|
|
self.send_response(403)
|
|
|
|
|
# Send headers
|
|
|
|
|
self.end_headers()
|
|
|
|
|
return
|
|
|
|
|
return
|
|
|
|
|
#Logging
|
|
|
|
|
#!Turn it on to stop print in console
|
|
|
|
|
#def log_message(self, format, *args):
|
|
|
|
|
# return
|
|
|
|
|
class ThreadedHTTPServer(ThreadingMixIn, HTTPServer):
|
|
|
|
|
"""Handle requests in a separate thread."""
|
|
|
|
|
def finish_request(self, request, client_address):
|
|
|
|
|
request.settimeout(30)
|
|
|
|
|
# "super" can not be used because BaseServer is not created from object
|
|
|
|
|
HTTPServer.finish_request(self, request, client_address)
|
|
|
|
|
#inGlobalDict
|
|
|
|
|
# "JSONConfigurationDict":<JSON>
|
|
|
|
|
class RobotDaemonServer(Thread):
|
|
|
|
|
def __init__(self,name,inGlobalDict):
|
|
|
|
|
Thread.__init__(self)
|
|
|
|
|
self.name = name
|
|
|
|
|
# Update the global dict
|
|
|
|
|
ServerSettings.SettingsUpdate(mGlobalDict)
|
|
|
|
|
def run(self):
|
|
|
|
|
inServerAddress="";
|
|
|
|
|
inPort = mGlobalDict["Server"]["ListenPort"];
|
|
|
|
|
# Server settings
|
|
|
|
|
# Choose port 8080, for port 80, which is normally used for a http server, you need root access
|
|
|
|
|
server_address = (inServerAddress, inPort)
|
|
|
|
|
#httpd = HTTPServer(server_address, testHTTPServer_RequestHandler)
|
|
|
|
|
# Logging
|
|
|
|
|
mGlobalDict["Logger"].info(f"Server init. Listen URL: {inServerAddress}, Listen port: {inPort}")
|
|
|
|
|
# Запуск адреса в браузере
|
|
|
|
|
os.system("explorer http://127.0.0.1:8081")
|
|
|
|
|
#httpd.serve_forever()
|
|
|
|
|
httpd = ThreadedHTTPServer(server_address, testHTTPServer_RequestHandler)
|
|
|
|
|
#print('Starting server, use <Ctrl-C> to stop')
|
|
|
|
|
httpd.serve_forever()
|
|
|
|
|