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