@ -779,11 +779,11 @@ def WebURLConnectDef(inMethodStr, inURLStr, inMatchTypeStr, inDef, inContentType
" inDef " : None #Function with str result
: param inGSettings : Global settings dict ( singleton )
: param inMethodStr :
: param inURLStr :
: param inMatchTypeStr :
: param inDef :
: param inContentTypeStr :
: param inMethodStr : " GET|POST " ,
: param inURLStr : example " /index " , #URL of the request
: param inMatchTypeStr : #"BeginWith|Contains|Equal|EqualCase",
: param inDef : def arg allowed list : 2 : [ inRequest , inGSettings ] , 1 : [ inRequest ] , 0 : [ ]
: param inContentTypeStr : default : " application/octet-stream "
"""
inGSettings = GSettingsGet ( inGSettings = inGSettings ) # Set the global settings
lURLItemDict = {
@ -897,7 +897,7 @@ def WebCPUpdate(inCPKeyStr, inHTMLRenderDef=None, inJSONGeneratorDef=None, inJSI
if inJSInitGeneratorDef is not None : lCPManager . mBackwardCompatibilityJSDef = inJSInitGeneratorDef
def WebAuditMessageCreate ( inRequest , inOperationCodeStr = " - " , inMessageStr = " - " ) :
def WebAuditMessageCreate ( inRequest = None , inOperationCodeStr = " - " , inMessageStr = " - " ) :
"""
Create message string with request user details ( IP , Login etc . . . ) . Very actual for IT security in big company .
@ -914,12 +914,13 @@ def WebAuditMessageCreate(inRequest, inOperationCodeStr="-", inMessageStr="-"):
# Log the WebAudit message
lLogger . info ( lWebAuditMessageStr )
: param inRequest : HTTP request handler
: param inRequest : HTTP request handler . Optional if call def from request thread
: 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 :
if inRequest is None : inRequest = WebRequestGet ( )
lClientIPStr = inRequest . client_address [ 0 ]
lUserDict = WebUserInfoGet ( inRequest = inRequest )
lDomainUpperStr = lUserDict [ " DomainUpperStr " ]
@ -930,54 +931,58 @@ def WebAuditMessageCreate(inRequest, inOperationCodeStr="-", inMessageStr="-"):
lResultStr = inMessageStr
return lResultStr
def WebRequestParseBodyBytes ( inRequest ) :
def WebRequestParseBodyBytes ( inRequest = None ) :
"""
Extract the body in bytes from the request
: param inRequest : inRequest from the server
: param inRequest : inRequest from the server . Optional if call def from request thread
: return : Bytes or None
"""
if inRequest is None : inRequest = WebRequestGet ( )
lBodyBytes = None
if inRequest . headers . get ( ' Content-Length ' ) is not None :
lInputByteArrayLength = int ( inRequest . headers . get ( ' Content-Length ' ) )
lBodyBytes = inRequest . rfile . read ( lInputByteArrayLength )
return lBodyBytes
def WebRequestParseBodyStr ( inRequest ) :
def WebRequestParseBodyStr ( inRequest = None ) :
"""
Extract the body in str from the request
: param inRequest : inRequest from the server
: param inRequest : inRequest from the server . Optional if call def from request thread
: return : str or None
"""
if inRequest is None : inRequest = WebRequestGet ( )
return WebRequestParseBodyBytes ( inRequest = inRequest ) . decode ( ' utf-8 ' )
def WebRequestParseBodyJSON ( inRequest ) :
def WebRequestParseBodyJSON ( inRequest = None ) :
"""
Extract the body in dict / list from the request
: param inRequest :
: param inRequest : inRequest from the server . Optional if call def from request thread
: return : dict or list
"""
if inRequest is None : inRequest = WebRequestGet ( )
return json . loads ( WebRequestParseBodyStr ( inRequest = inRequest ) )
def WebRequestParsePath ( inRequest ) :
def WebRequestParsePath ( inRequest = None ) :
"""
Parse the request - extract the url . Example : / pyOpenRPA / Debugging / DefHelper / . . .
: param inRequest :
: param inRequest : inRequest from the server . Optional if call def from request thread
: return : Str , Example : / pyOpenRPA / Debugging / DefHelper / . . .
"""
if inRequest is None : inRequest = WebRequestGet ( )
return urllib . parse . unquote ( inRequest . path )
def WebRequestParseFile ( inRequest ) :
def WebRequestParseFile ( inRequest = None ) :
"""
Parse the request - extract the file ( name , body in bytes )
: param inRequest :
: param inRequest : inRequest from the server . Optional if call def from request thread
: return : ( FileNameStr , FileBodyBytes ) or ( None , None )
"""
if inRequest is None : inRequest = WebRequestGet ( )
lResultTurple = ( None , None )
if inRequest . headers . get ( ' Content-Length ' ) is not None :
lInputByteArray = WebRequestParseBodyBytes ( inRequest = inRequest )
@ -997,45 +1002,61 @@ def WebRequestParseFile(inRequest):
return lResultTurple
def WebRequestResponseSend ( inRe quest, inResponeStr ) :
def WebRequestResponseSend ( inRe sponeStr, inRequest = None ) :
"""
Send response for the request
: param inRequest : inRequest from the server . Optional if call def from request thread
: return :
"""
if inRequest is None : inRequest = WebRequestGet ( )
inRequest . OpenRPAResponseDict [ " Body " ] = bytes ( inResponeStr , " utf8 " )
def WebUserInfoGet ( inRequest ) :
def WebRequestGet ( ) :
"""
Return the web request instance if current thread was created by web request from client . else return None
"""
lCurrentThread = threading . current_thread ( )
if hasattr ( lCurrentThread , " request " ) :
return lCurrentThread . request
def WebUserInfoGet ( inRequest = None ) :
"""
Return User info about request
: param inRequest :
: param inRequest : inRequest from the server . Optional if call def from request thread
: return : { " DomainUpperStr " : " " , " UserNameUpperStr " : " " }
"""
if inRequest is None : inRequest = WebRequestGet ( )
lDomainUpperStr = inRequest . OpenRPA [ " Domain " ] . upper ( )
lUserUpperStr = inRequest . OpenRPA [ " User " ] . upper ( )
return { " DomainUpperStr " : lDomainUpperStr , " UserNameUpperStr " : lUserUpperStr }
def WebUserIsSuperToken ( inRequest , inGSettings = None ) :
def WebUserIsSuperToken ( inRequest = None , inGSettings = None ) :
"""
Return bool if request is authentificated with supetoken ( token which is never expires )
: param inRequest :
: param inRequest : inRequest from the server . Optional if call def from request thread
: param inGSettings : Global settings dict ( singleton )
: return : bool True - is supertoken ; False - is not supertoken
"""
if inRequest is None : inRequest = WebRequestGet ( )
inGSettings = GSettingsGet ( inGSettings = inGSettings ) # Set the global settings
lIsSuperTokenBool = False
# Get Flag is supertoken (True|False)
lIsSuperTokenBool = inGSettings . get ( " ServerDict " , { } ) . get ( " AccessUsers " , { } ) . get ( " AuthTokensDict " , { } ) . get ( inRequest . OpenRPA [ " AuthToken " ] , { } ) . get ( " FlagDoNotExpire " , False )
return lIsSuperTokenBool
def WebUserUACHierarchyGet ( inRequest ) :
def WebUserUACHierarchyGet ( inRequest = None ) :
"""
Return User UAC Hierarchy DICT Return { . . . }
: param inRequest :
: param inRequest : inRequest from the server . Optional if call def from request thread
: return : UAC Dict { }
"""
if inRequest is None : inRequest = WebRequestGet ( )
return inRequest . UserRoleHierarchyGet ( )