114 lines
3.4 KiB
Text
114 lines
3.4 KiB
Text
;****************************
|
|
;*
|
|
;* Lihaso Web Server
|
|
;*
|
|
;* (c)2015 by Linder Hard- und Software
|
|
;*
|
|
;* V0.1
|
|
;* - Initial Web Server
|
|
;* - Modul interface ?
|
|
;*
|
|
|
|
EnableExplicit
|
|
|
|
;*
|
|
;* Deklaration Variabeln
|
|
;*
|
|
|
|
XIncludeFile "lweb_header.pbi"
|
|
XIncludeFile "lweb.pbi"
|
|
|
|
Define counter, v_lweb_srv_stop
|
|
|
|
lhs_web::set_config(lhs_web::#conf_port, "8099")
|
|
;lhs_web::set_config(lhs_web::#conf_binding, "127.0.0.1")
|
|
lhs_web::set_config(lhs_web::#conf_binding, "0.0.0.0")
|
|
|
|
lhs_web::set_config(lhs_web::#conf_defaultfile, "/index.html")
|
|
lhs_web::set_config(lhs_web::#conf_basedir, "/home/renlin/testweb/")
|
|
lhs_web::set_config(lhs_web::#conf_error400, "integrated")
|
|
lhs_web::set_config(lhs_web::#conf_max_clients, "100")
|
|
lhs_web::set_config(lhs_web::#conf_cache_enable, "0")
|
|
;*
|
|
;* includes
|
|
;*
|
|
|
|
Procedure.s Sample_Header(Map Header.s())
|
|
Define *Text
|
|
Define.s Encoded, ZumSenden, TBD
|
|
NewMap Response.s()
|
|
TBD="<div><div><h1>Header</h1></div><br/>"+#CRLF$
|
|
ResetMap(Header())
|
|
While NextMapElement(Header())
|
|
TBD = TBD+"<div>"+MapKey(Header())+" : "+Header()+" </div><br/>"+#CRLF$
|
|
Wend
|
|
|
|
*Text = UTF8("<!DOCTYPE html><html><header><title>Alle Client Headers</title></header><body>"+TBD+"</body></html>")
|
|
Encoded = Base64Encoder(*Text, MemorySize(*Text))
|
|
Debug "Encoded: " + Encoded
|
|
Response(lhs_web::#cha_R_ResponseContentType) = lhs_web::#response_string
|
|
Response(lhs_web::#cha_R_StringBase64) = Encoded
|
|
Response(lhs_web::#cha_R_ResponseType) = lhs_web::mimetype("html")
|
|
Response(lhs_web::#cha_R_http_head_status) = "200 OK"
|
|
ZumSenden = lhs_web::MapStringToJSONString(Response())
|
|
Debug "ZumSenden: " + ZumSenden
|
|
ProcedureReturn ZumSenden
|
|
EndProcedure
|
|
|
|
Procedure.s Formular_Test(Map Header.s(), ContentData.s)
|
|
Define *Text
|
|
Define.s Encoded, ZumSenden, TBD
|
|
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
|
|
Debug "TBD:"+TBD
|
|
Debug "contentData:"+ContentData
|
|
*Text = UTF8("<!DOCTYPE html><html><header><title>Alle Client Headers</title></header><body>"+TBD+"<hr/><br/><h1>ConentJSON</h1><br/>"+ContentData+"</body></html>")
|
|
Debug "Unencoded:"+PeekS(*Text, -1 , #PB_UTF8)
|
|
Encoded = Base64Encoder(*Text, MemorySize(*Text))
|
|
Debug "Encoded: " + Encoded
|
|
Response(lhs_web::#cha_R_ResponseContentType) = lhs_web::#response_string
|
|
Response(lhs_web::#cha_R_StringBase64) = Encoded
|
|
Response(lhs_web::#cha_R_ResponseType) = lhs_web::mimetype("html")
|
|
Response(lhs_web::#cha_R_http_head_status) = "200 OK"
|
|
ZumSenden = lhs_web::MapStringToJSONString(Response())
|
|
Debug "ZumSenden: " + ZumSenden
|
|
ProcedureReturn ZumSenden
|
|
|
|
EndProcedure
|
|
|
|
lhs_web::register_client_handler("/server/show_client_headers", @Sample_Header(),lhs_web::#handler_proto_get, lhs_web::#handler_sub)
|
|
|
|
lhs_web::register_client_handler("/post_test", @Formular_Test(),lhs_web::#handler_proto_post, lhs_web::#handler_sub)
|
|
|
|
;*
|
|
;* Initialisierung Netzwerk
|
|
;*
|
|
|
|
If InitNetwork()
|
|
;Alles IO
|
|
;PrintN("Network initalised")
|
|
Debug "Network initalised"
|
|
Else
|
|
Debug "Network initalisation failen... stop"
|
|
End
|
|
EndIf
|
|
|
|
If lhs_web::start_server()
|
|
Debug "Server gestartet" + lhs_web::get_config(lhs_web::#conf_port)
|
|
Else
|
|
Debug "Fehlgeschlagen"
|
|
End
|
|
EndIf
|
|
|
|
counter = 0
|
|
OpenConsole("Test")
|
|
PrintN("Webserver an Port:"+lhs_web::get_config(lhs_web::#conf_port))
|
|
PrintN("Press Enter to Exit")
|
|
Input()
|
|
|
|
|
|
End
|