Add WebAuditMessage + prototype for many servers...

dev-linux
Ivan Maslov 4 years ago
parent 97d5e2bc3a
commit fa8f15329d

@ -526,6 +526,7 @@ class ThreadedHTTPServer(ThreadingMixIn, HTTPServer):
HTTPServer.finish_request(self, request, client_address) HTTPServer.finish_request(self, request, client_address)
#inGlobalDict #inGlobalDict
# "JSONConfigurationDict":<JSON> # "JSONConfigurationDict":<JSON>
import ssl
class RobotDaemonServer(Thread): class RobotDaemonServer(Thread):
def __init__(self,name,inGlobalDict): def __init__(self,name,inGlobalDict):
Thread.__init__(self) Thread.__init__(self)
@ -533,8 +534,8 @@ class RobotDaemonServer(Thread):
# Update the global dict # Update the global dict
ServerSettings.SettingsUpdate(inGlobalDict) ServerSettings.SettingsUpdate(inGlobalDict)
def run(self): def run(self):
inServerAddress=""; inServerAddress=""
inPort = gSettingsDict["ServerDict"]["ListenPort"]; inPort = gSettingsDict["ServerDict"]["ListenPort"]
# Server settings # Server settings
# Choose port 8080, for port 80, which is normally used for a http server, you need root access # Choose port 8080, for port 80, which is normally used for a http server, you need root access
server_address = (inServerAddress, inPort) server_address = (inServerAddress, inPort)
@ -543,5 +544,7 @@ class RobotDaemonServer(Thread):
gSettingsDict["Logger"].info(f"Server init. Listen URL: {inServerAddress}, Listen port: {inPort}") gSettingsDict["Logger"].info(f"Server init. Listen URL: {inServerAddress}, Listen port: {inPort}")
#httpd.serve_forever() #httpd.serve_forever()
httpd = ThreadedHTTPServer(server_address, testHTTPServer_RequestHandler) httpd = ThreadedHTTPServer(server_address, testHTTPServer_RequestHandler)
#httpd.socket = ssl.wrap_socket(httpd.socket, server_side=True,
# certfile='yourpemfile.pem')
#print('Starting server, use <Ctrl-C> to stop') #print('Starting server, use <Ctrl-C> to stop')
httpd.serve_forever() httpd.serve_forever()

@ -279,7 +279,8 @@ def pyOpenRPA_Processor(inRequest, inGSettings):
lActivityTypeListStr += f"{lActivityItem['Def']}; " lActivityTypeListStr += f"{lActivityItem['Def']}; "
except Exception as e: except Exception as e:
lActivityTypeListStr = "Has some error with Activity Type read" lActivityTypeListStr = "Has some error with Activity Type read"
if lL: lL.info(f"ServerSettings.pyOpenRPA_Processor. User activity from web. Domain: {inRequest.OpenRPA['Domain']}, Username: {inRequest.OpenRPA['User']}, ActivityType: {lActivityTypeListStr}") lWebAuditMessageStr = __Orchestrator__.WebAuditMessageCreate(inRequest=inRequest,inOperationCodeStr=lActivityTypeListStr, inMessageStr="pyOpenRPA_Processor")
if lL: lL.info(lWebAuditMessageStr)
# Append in list # Append in list
inGSettings["ProcessorDict"]["ActivityList"]+=lInput inGSettings["ProcessorDict"]["ActivityList"]+=lInput
else: else:
@ -290,7 +291,8 @@ def pyOpenRPA_Processor(inRequest, inGSettings):
lActivityTypeListStr = lInput['Def'] lActivityTypeListStr = lInput['Def']
except Exception as e: except Exception as e:
lActivityTypeListStr = "Has some error with Activity Type read" lActivityTypeListStr = "Has some error with Activity Type read"
if lL: lL.info(f"ServerSettings.pyOpenRPA_Processor. User activity from web. Domain: {inRequest.OpenRPA['Domain']}, Username: {inRequest.OpenRPA['User']}, ActivityType: {lActivityTypeListStr}") lWebAuditMessageStr = __Orchestrator__.WebAuditMessageCreate(inRequest=inRequest,inOperationCodeStr=lActivityTypeListStr, inMessageStr="pyOpenRPA_Processor")
if lL: lL.info(lWebAuditMessageStr)
# Append in list # Append in list
inGSettings["ProcessorDict"]["ActivityList"].append(lInput) inGSettings["ProcessorDict"]["ActivityList"].append(lInput)
# Execute activity list # Execute activity list
@ -313,7 +315,8 @@ def pyOpenRPA_ActivityListExecute(inRequest, inGSettings):
lActivityTypeListStr += f"{lActivityItem['Def']}; " lActivityTypeListStr += f"{lActivityItem['Def']}; "
except Exception as e: except Exception as e:
lActivityTypeListStr = "Has some error with Activity Type read" lActivityTypeListStr = "Has some error with Activity Type read"
if lL: lL.info(f"ServerSettings.pyOpenRPA_ActivityListExecute. User activity from web. Domain: {inRequest.OpenRPA['Domain']}, Username: {inRequest.OpenRPA['User']}, ActivityType: {lActivityTypeListStr}") lWebAuditMessageStr = __Orchestrator__.WebAuditMessageCreate(inRequest=inRequest,inOperationCodeStr=lActivityTypeListStr, inMessageStr="pyOpenRPA_ActivityListExecute")
if lL: lL.info(lWebAuditMessageStr)
# Execution # Execution
lResultList = Processor.ActivityListExecute(inGSettings = inGSettings, inActivityList = lInput) lResultList = Processor.ActivityListExecute(inGSettings = inGSettings, inActivityList = lInput)
inRequest.OpenRPAResponseDict["Body"] = bytes(json.dumps(lResultList), "utf8") inRequest.OpenRPAResponseDict["Body"] = bytes(json.dumps(lResultList), "utf8")
@ -325,7 +328,10 @@ def pyOpenRPA_ActivityListExecute(inRequest, inGSettings):
lActivityTypeListStr = lInput['Def'] lActivityTypeListStr = lInput['Def']
except Exception as e: except Exception as e:
lActivityTypeListStr = "Has some error with Activity Type read" lActivityTypeListStr = "Has some error with Activity Type read"
if lL: lL.info(f"ServerSettings.pyOpenRPA_ActivityListExecute. User activity from web. Domain: {inRequest.OpenRPA['Domain']}, Username: {inRequest.OpenRPA['User']}, ActivityType: {lActivityTypeListStr}") lWebAuditMessageStr = __Orchestrator__.WebAuditMessageCreate(inRequest=inRequest,
inOperationCodeStr=lActivityTypeListStr,
inMessageStr="pyOpenRPA_ActivityListExecute")
if lL: lL.info(lWebAuditMessageStr)
# Execution # Execution
lResultList = Processor.ActivityListExecute(inGSettings = inGSettings, inActivityList = [lInput]) lResultList = Processor.ActivityListExecute(inGSettings = inGSettings, inActivityList = [lInput])
inRequest.OpenRPAResponseDict["Body"] = bytes(json.dumps(lResultList[0]), "utf8") inRequest.OpenRPAResponseDict["Body"] = bytes(json.dumps(lResultList[0]), "utf8")

@ -53,6 +53,13 @@ def __Create__():
"URL": "" "URL": ""
} }
], ],
"ListenDict": { # Prototype
"localhost":{
"AddressStr":"",
"PortInt":80,
"CertFilePEMPathStr":""
}
},
"AccessUsers": { # Default - all URL is blocked "AccessUsers": { # Default - all URL is blocked
"FlagCredentialsAsk": True, # Turn on Authentication "FlagCredentialsAsk": True, # Turn on Authentication
"RuleDomainUserDict": { "RuleDomainUserDict": {

@ -600,6 +600,40 @@ def WebCPUpdate(inGSettings, inCPKeyStr, inHTMLRenderDef=None, inJSONGeneratorDe
if inJSInitGeneratorDef is not None: if inJSInitGeneratorDef is not None:
inGSettings["CPDict"][inCPKeyStr]["JSInitGeneratorDef"] = inJSInitGeneratorDef inGSettings["CPDict"][inCPKeyStr]["JSInitGeneratorDef"] = inJSInitGeneratorDef
def WebAuditMessageCreate(inRequest, inOperationCodeStr="-", inMessageStr="-"):
"""
Create message string with request user details (IP, Login etc...). Very actual for IT security in big company.
.. code-block:: python
# USAGE
from pyOpenRPA import Orchestrator
lWebAuditMessageStr = Orchestrator.WebAuditMessageCreate(
inRequest = lRequest,
inOperationCodeStr = "OP_CODE_1",
inMessageStr="Success"):
# Log the WebAudit message
lLogger.info(lWebAuditMessageStr)
:param inRequest: HTTP request handler
:param inOperationCodeStr: operation code in string format (actual for IT audit in control panels)
:param inMessageStr: additional message after
:return: format "WebAudit :: DOMAIN\\USER@101.121.123.12 :: operation code :: message"
"""
try:
lClientIPStr = inRequest.client_address[0]
lUserDict = WebUserInfoGet(inRequest=inRequest)
lDomainUpperStr = lUserDict["DomainUpperStr"]
lUserLoginStr = lUserDict["UserNameUpperStr"]
lResultStr = f"WebAudit :: {lDomainUpperStr}\\\\{lUserLoginStr}@{lClientIPStr} :: {inOperationCodeStr} :: {inMessageStr}"
except Exception as e:
print(str(e)) # Has no logger - must be dead alg branch
lResultStr = inMessageStr
return lResultStr
def WebUserInfoGet(inRequest): def WebUserInfoGet(inRequest):
""" """
Return User info about request Return User info about request

Loading…
Cancel
Save