lweb/lweb_auth.pb

167 lines
4.4 KiB
Text
Raw Normal View History

2023-05-17 18:02:54 +02:00
;************************
;* lweb_auth.pb
;*
2024-03-13 09:23:28 +01:00
;* Simple Authentication Library.
2023-05-17 18:02:54 +02:00
;*
;* Created and develobed by Linder Hard- und Software
;*
2024-03-13 09:23:28 +01:00
;* First Release Only "demo" Database
2023-05-17 18:02:54 +02:00
XIncludeFile "lhs_lib/NET/lhs_web_helper.pbi"
Structure DB_Config
Type.i ;0=csv, 1=txt ,2=SQLite, 3=mar, 4=psq
File_Name.s
DB_Connection.s
DB_User.s
DB_Password.s
EndStructure
Structure Config
DB_User.DB_Config
DB_Session.DB_Config
EndStructure
Global.s ZumSenden
Global.s State
Global.s DB_Cfg
Global.s DB_Session
ProcedureCDLL init(Config_XML.s)
EndProcedure
ProcedureCDLL Database_User(DB_Cfg.s)
Select Left(DB_Cfg, 3)
Case "csv"
;csv:/path/to/file.csv
Case "txt"
;txt:/path/to/file.txt
Case "sli"
;sli:/path/to/sqliteDB.sqlite
Case "mar"
;mar:host=localhost port=3306 dbname=test user=|USERNAME| password=|PASSWORD|
Case "psq"
;psq:host=localhost port=5432 dbname=test user=|USERNAME| password=|PASSWORD|
2024-03-13 09:23:28 +01:00
Case "demo"
;Demo Accounts
; Grp. Usr. Pw. ID Mod
;|demo|admin|admin1234|0 |777|
;|demo|user |user1234 |1 |744|
;|demo|guest|guest1234|2 |004|
2023-05-17 18:02:54 +02:00
Default
State = "Failed"
ProcedureReturn @State
EndSelect
EndProcedure
ProcedureCDLL Database_Session(DB_Cfg.s)
Select Left(DB_Cfg, 3)
Case "csv"
;csv:/path/to/file.csv
Case "txt"
;txt:/path/to/file.txt
Case "sli"
;sli:/path/to/sqliteDB.sqlite
Case "mar"
;mar:host=localhost port=3306 dbname=test user=|USERNAME| password=|PASSWORD|
Case "psq"
;psq:host=localhost port=5432 dbname=test user=|USERNAME| password=|PASSWORD|
Default
State = "Failed"
ProcedureReturn @Failed
EndSelect
EndProcedure
Procedure.s GetUserFromDBCFG(DB_Cfg.s)
Protected Pos_Start, Pos_End, User_Name.s
Pos_Start = FindString(DB_Cfg, "user=|", 0) + Len("user=|")
Pos_End = FindString(DB_Cfg, "|", Pos_Start)
User_Name.s = Mid(DB_Cfg, Pos_Start, Pos_End-Pos_Start)
ProcedureReturn User_Name
EndProcedure
Procedure.s GetPassworfFromDBCFG(DB_Cfg.s)
Protected Pos_Start, Pos_End, User_Password.s
Pos_Start = FindString(DB_Cfg, "password=|", 0) + Len("password=|")
Pos_End = FindString(DB_Cfg, "|", Pos_Start)
User_Password.s = Mid(DB_Cfg, Pos_Start, Pos_End-Pos_Start)
ProcedureReturn User_Password
EndProcedure
2024-03-13 09:23:28 +01:00
Procedure.s CreateSession(ID.s)
EndProcedure
Procedure.s IsSession(SessionID.s)
EndProcedure
Procedure.s User_Verify(User.s)
EndProcedure
Procedure.s User_Login(User.s, Password.s)
EndProcedure
Procedure.s Get_MOD(SessionID.s)
EndProcedure
Procedure.s Get_Group(SessionID.s)
EndProcedure
Procedure.s Get_UseID(SessionID.s)
EndProcedure
2023-05-17 18:02:54 +02:00
ProcedureCDLL post_test(handler_Map_JSON.s, ContentData.s)
Define *Text
Define.s Encoded, TBD, Text, JSONStringToMap
Define MyThreadJSON, File
NewMap Header.s()
File = CreateFile(#PB_Any, "test.log")
WriteStringN(File, "handler_Map_JSON:")
WriteStringN(File, handler_Map_JSON)
WriteStringN(File, "Content Data:")
WriteStringN(File, ContentData)
JSONStringToMap = handler_Map_JSON
If JSONStringToMap <> lhs_web_helper::#error_string
MyThreadJSON = ParseJSON(#PB_Any, JSONStringToMap)
If MyThreadJSON
ClearMap(Header())
ExtractJSONMap(JSONValue(MyThreadJSON), Header())
FreeJSON(MyThreadJSON)
EndIf
EndIf
NewMap Response.s()
TBD="<div><div><h1>FormularPost</h1></div><br/>"+#CRLF$
ResetMap(Header())
While NextMapElement(Header())
TBD = TBD+"<div>"+MapKey(Header())+" : "+Header()+" </div><br/>"+#CRLF$
Wend
ContentData = URLDecoder(ContentData, #PB_UTF8)
Text = ~"<html lang=\"de\">" +
"<head>" +
~"<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>" +
"<title>Alle Client Headers</title></header><body>"+TBD+"<hr/><br/><h1>ConentJSON</h1><br/>"+ContentData+"</body></html>"
*Text = AllocateMemory(StringByteLength(Text, #PB_UTF8))
PokeS(*Text, Text, -1, #PB_UTF8)
Encoded = Base64Encoder(*Text, MemorySize(*Text))
Response(lhs_web_helper::#cha_R_ResponseContentType) = lhs_web_helper::#response_string
Response(lhs_web_helper::#cha_R_StringBase64) = Encoded
Response(lhs_web_helper::#cha_R_ResponseType) = lhs_web_helper::mimetype("html")
Response(lhs_web_helper::#cha_R_http_head_status) = "200 Ok"
ZumSenden = lhs_web_helper::MapToJSONString(Response())
WriteStringN(File, "ZumSenden:")
WriteStringN(File, ZumSenden)
CloseFile(File)
ProcedureReturn @ZumSenden
EndProcedure