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)
#inGlobalDict
# "JSONConfigurationDict":<JSON>
import ssl
class RobotDaemonServer(Thread):
def __init__(self,name,inGlobalDict):
Thread.__init__(self)
@ -533,8 +534,8 @@ class RobotDaemonServer(Thread):
# Update the global dict
ServerSettings.SettingsUpdate(inGlobalDict)
def run(self):
inServerAddress="";
inPort = gSettingsDict["ServerDict"]["ListenPort"];
inServerAddress=""
inPort = gSettingsDict["ServerDict"]["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)
@ -543,5 +544,7 @@ class RobotDaemonServer(Thread):
gSettingsDict["Logger"].info(f"Server init. Listen URL: {inServerAddress}, Listen port: {inPort}")
#httpd.serve_forever()
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')
httpd.serve_forever()

@ -279,7 +279,8 @@ def pyOpenRPA_Processor(inRequest, inGSettings):
lActivityTypeListStr += f"{lActivityItem['Def']}; "
except Exception as e:
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
inGSettings["ProcessorDict"]["ActivityList"]+=lInput
else:
@ -290,7 +291,8 @@ def pyOpenRPA_Processor(inRequest, inGSettings):
lActivityTypeListStr = lInput['Def']
except Exception as e:
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
inGSettings["ProcessorDict"]["ActivityList"].append(lInput)
# Execute activity list
@ -313,7 +315,8 @@ def pyOpenRPA_ActivityListExecute(inRequest, inGSettings):
lActivityTypeListStr += f"{lActivityItem['Def']}; "
except Exception as e:
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
lResultList = Processor.ActivityListExecute(inGSettings = inGSettings, inActivityList = lInput)
inRequest.OpenRPAResponseDict["Body"] = bytes(json.dumps(lResultList), "utf8")
@ -325,7 +328,10 @@ def pyOpenRPA_ActivityListExecute(inRequest, inGSettings):
lActivityTypeListStr = lInput['Def']
except Exception as e:
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
lResultList = Processor.ActivityListExecute(inGSettings = inGSettings, inActivityList = [lInput])
inRequest.OpenRPAResponseDict["Body"] = bytes(json.dumps(lResultList[0]), "utf8")

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

@ -600,6 +600,40 @@ def WebCPUpdate(inGSettings, inCPKeyStr, inHTMLRenderDef=None, inJSONGeneratorDe
if inJSInitGeneratorDef is not None:
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):
"""
Return User info about request

Loading…
Cancel
Save