New lhttpd Release of main application

This commit is contained in:
René Linder 2023-03-30 10:49:06 +02:00
parent beef8490f5
commit 5d82ee5704

117
lhttpd.pb
View file

@ -6,17 +6,19 @@
;* ;*
;* V0.5 ;* V0.5
;* - Simple webserver for HTTP & HTTPS ;* - Simple webserver for HTTP & HTTPS
;* V0.8
;* - Webserver for HTTP & HTTPS now with the last Library Version
;* ;*
EnableExplicit EnableExplicit
XIncludeFile "lhs_lib/SYS/lhs_log.pbi" ;Currently for Debugging
XIncludeFile "lhs_lib/SYS/lhs_log_ext.pbi" ;User for Access Log, Error Access Log, Error Log and maybe more. XIncludeFile "lhs_lib/SYS/lhs_log_ext.pbi" ;User for Access Log, Error Access Log, Error Log and maybe more.
XIncludeFile "lhs_lib/SYS/lhs_sys_debug_wrapper.pbi" ;For all Log Outputs
OpenConsole("lhttpd") OpenConsole("lhttpd")
Define Parameter.s, Configfile.s, Checkruntime.s, Exit_Web.i Define Parameter.s, Configfile.s, Checkruntime.s, Exit_Web.i
Define Accesslog.s, Errorlog.s Define Accesslog.s, Errorlog.s, Debuglogfile.s, DebuglogID.s
Define Version.s = "V0.8"
Configfile = "/etc/lhttpd/lhttpd.cfg" Configfile = "/etc/lhttpd/lhttpd.cfg"
Checkruntime = "/tmp/lhttpd.run" Checkruntime = "/tmp/lhttpd.run"
@ -25,14 +27,17 @@ Repeat
Parameter = ProgramParameter() Parameter = ProgramParameter()
If Parameter = "-h" Or Parameter = "--help" If Parameter = "-h" Or Parameter = "--help"
PrintN("lhttpd Web Server") PrintN("lhttpd Web Server "+Version)
PrintN("(c)2021 by Linder Hard- und Software") PrintN("(c)2023 by Linder Hard- und Software")
PrintN("") PrintN("")
PrintN("Start parameters:") PrintN("Start parameters:")
PrintN("-c=/etc/lhttpd or --config=/etc/lhttpd") PrintN("-c=/etc/lhttpd/server.xml or --config=/etc/lhttpd/server.xml")
PrintN(" Configuration file.") PrintN(" Configuration file.")
PrintN("--run=/tmp/lhttpd.run") PrintN("--run=/tmp/lhttpd.run")
PrintN(" Check periodical for the file") PrintN(" Check periodical for the file")
PrintN("--debug=/var/log/lhttpd_debug.log")
PrintN(" Activate Debug Log")
ElseIf Left(Parameter,3) = "-c=" Or Left(Parameter,9) = "--config=" ElseIf Left(Parameter,3) = "-c=" Or Left(Parameter,9) = "--config="
Configfile = Right(Parameter, Len(Parameter) - FindString(Parameter, "=") + 1) Configfile = Right(Parameter, Len(Parameter) - FindString(Parameter, "=") + 1)
If ReadFile(0, Configfile) If ReadFile(0, Configfile)
@ -49,7 +54,14 @@ Repeat
PrintN("Failed to read check file:["+Checkruntime+"]") PrintN("Failed to read check file:["+Checkruntime+"]")
End End
EndIf EndIf
ElseIf Left(Parameter, 8) = "--debug="
Debuglogfile = Right(Parameter, Len(Parameter)-8)
DebuglogID = lhs_log_ext::Create("DebugLog")
lhs_log_ext::SetLogFile(DebuglogID, Debuglogfile)
lhs_log_ext::Init(DebuglogID)
ldl::Register(lhs_log_ext::@Out(), DebuglogID, 1, DebuglogID, ldl::#AdvancedLog)
ldl::SetDefault(DebuglogID)
ldl::Logging("Start Debug Log registered with ldl at UUID:"+DebuglogID)
ElseIf Parameter = "" ElseIf Parameter = ""
;No Parameters ;No Parameters
Else Else
@ -67,83 +79,54 @@ Until Parameter = ""
XIncludeFile "lweb_header.pbi" XIncludeFile "lweb_header.pbi"
XIncludeFile "lweb.pbi" XIncludeFile "lweb.pbi"
If OpenPreferences(Configfile, #PB_Preference_GroupSeparator) PrintN("lhttpd Webserver "+Version)
If PreferenceGroup("lhttpd")
lhs_web::set_config(lhs_web::#conf_HTTP_port, ReadPreferenceString("HTTP_Port","8081")) If Len(Checkruntime) > 0
lhs_web::set_config(lhs_web::#conf_HTTP_binding, ReadPreferenceString("HTTP_Binding","0.0.0.0")) If CreateFile(0, Checkruntime)
lhs_web::set_config(lhs_web::#conf_HTTPS_CA, ReadPreferenceString("HTTPS_CA","/home/renlin/dev/libressl/sample/fullchain.pem")) CloseFile(0)
lhs_web::set_config(lhs_web::#conf_HTTPS_Cert, ReadPreferenceString("HTTPS_Cert","/home/renlin/dev/libressl/sample/cert.pem")) PrintN("PID File created --run="+Checkruntime)
lhs_web::set_config(lhs_web::#conf_HTTPS_Key, ReadPreferenceString("HTTPS_Key","/home/renlin/dev/libressl/sample/privkey.pem"))
lhs_web::set_config(lhs_web::#conf_HTTPS_Key_Pass, ReadPreferenceString("HTTPS_Key_Pass",""))
lhs_web::set_config(lhs_web::#conf_HTTPS_Port, ReadPreferenceString("HTTPS_Port","8444"))
lhs_web::set_config(lhs_web::#conf_HTTPS_Binding, ReadPreferenceString("HTTPS_Binding","127.0.0.1"))
lhs_web::set_config(lhs_web::#conf_HTTPS_Enable, ReadPreferenceString("HTTPS_enable","0"))
lhs_web::set_config(lhs_web::#conf_defaultfile, ReadPreferenceString("Defaultfile","/index.html"))
lhs_web::set_config(lhs_web::#conf_basedir, ReadPreferenceString("Basedirectory","/home/renlin/testweb/"))
lhs_web::set_config(lhs_web::#conf_error400, ReadPreferenceString("Error400_Handling","integrated"))
lhs_web::set_config(lhs_web::#conf_max_HTTP_clients, ReadPreferenceString("Max_HTTP_Clients","10"))
lhs_web::set_config(lhs_web::#conf_max_HTTPS_clients, ReadPreferenceString("Max_HTTPS_Clients","100"))
lhs_web::set_config(lhs_web::#conf_cache_enable, ReadPreferenceString("Filememorycache","0"))
Checkruntime = ReadPreferenceString("Checkrun","/tmp/lhttpd.run")
lhs_web::set_config(lhs_web::#conf_debug_logfile, ReadPreferenceString("Debug_logfile","/var/log/lhttpd-debug.log"))
lhs_web::set_config(lhs_web::#conf_debug_disable, ReadPreferenceString("Debug_disable","true"))
lhs_web::set_config(lhs_web::#conf_access_logfile, ReadPreferenceString("Access_logfile","/var/log/lhttpd-access.log"))
lhs_web::set_config(lhs_web::#conf_error_logfile, ReadPreferenceString("Error_logfile","/var/log/lhttpd-error.log"))
ClosePreferences()
Else Else
PrintN("No correct config file -> End") PrintN("Error: PID File:["+Checkruntime+"] could Not be created.")
End End
EndIf EndIf
Else Else
PrintN("Could not open config file.") PrintN("NO PID File configured --run=file.pid")
PrintN("Exit")
End End
EndIf EndIf
If CreateFile(0, Checkruntime)
CloseFile(0)
PrintN("PID File created")
;*
;* Server Config Start
;*
PrintN("Read Configuration:")
If lhs_web::server_initial("file:"+Configfile)
ldl::Logging("config succesfully loaded.")
Else Else
PrintN("Error: PID could not be created.") ldl::Logging("config load failed.")
End End
EndIf EndIf
PrintN("Configured HTTP at Port(s):"+lhs_web::server_get_config("ports_http"))
PrintN("Configured HTTPS at Port(s):"+lhs_web::server_get_config("ports_https"))
PrintN("Configuration read done.")
lhs_log::App_Name = "lhttpd Web Server Debug" PrintN("Start Server...")
lhs_log::SetLogFile(lhs_web::get_config(lhs_web::#conf_debug_logfile))
lhs_log::SetMaxSize(32)
lhs_log::SetLogDateFormat("%yyyy.%mm.%dd %hh:%ii:%ss")
lhs_log::SetLogFileDateFormat("%yyyy_%mm_%dd_%hh_%ii_%ss")
lhs_log::Init()
;* ;*
;* Enable extended Logging: ;* Server Start
;*
Accesslog = lhs_log_ext::Create("Accesslog")
Errorlog = lhs_log_ext::Create("Errorlog")
lhs_log_ext::OutL(lhs_web::get_config(lhs_web::#conf_Debug_logUUID), lhs_log_ext::#Debugging,"Errorlog UUID:"+Errorlog)
lhs_log_ext::OutL(lhs_web::get_config(lhs_web::#conf_Debug_logUUID), lhs_log_ext::#Debugging,"Accesslog UUID:"+Accesslog)
lhs_web::set_config(lhs_web::#conf_Access_logUUID, Accesslog)
lhs_web::set_config(lhs_web::#conf_Error_logUUID, Errorlog)
lhs_log_ext::SetLogFile(Accesslog, lhs_web::get_config(lhs_web::#conf_access_logfile))
lhs_log_ext::SetLogFile(Errorlog, lhs_web::get_config(lhs_web::#conf_error_logfile))
lhs_log_ext::Init(Accesslog)
lhs_log_ext::Init(Errorlog)
;*
;* includes
;* ;*
If lhs_web::start_server() If lhs_web::server_start()
lhs_log_ext::OutL(lhs_web::get_config(lhs_web::#conf_Debug_logUUID), lhs_log_ext::#Debugging,"Server started:") ldl::Logging("Server started:")
lhs_log_ext::OutL(lhs_web::get_config(lhs_web::#conf_Debug_logUUID), lhs_log_ext::#Debugging,"HTTP Port:"+ lhs_web::get_config(lhs_web::#conf_HTTP_port)) ldl::Logging("Configured HTTP at Port(s):"+lhs_web::server_get_config("ports_http"))
lhs_log_ext::OutL(lhs_web::get_config(lhs_web::#conf_Debug_logUUID), lhs_log_ext::#Debugging,"HTTPS Port:"+ lhs_web::get_config(lhs_web::#conf_HTTPS_port)) ldl::Logging("Configured HTTPS at Port(s):"+lhs_web::server_get_config("ports_https"))
Else Else
lhs_log_ext::OutL(lhs_web::get_config(lhs_web::#conf_Debug_logUUID), lhs_log_ext::#Debugging,"Serverstart failed.") ldl::Logging("Serverstart failed.")
PrintN("Serverstart failed.")
End End
EndIf EndIf
PrintN("lhttpd Webserver") PrintN("Server Started.")
PrintN("HTTP on Port:"+lhs_web::get_config(lhs_web::#conf_HTTP_port))
PrintN("HTTPS on Port:"+lhs_web::get_config(lhs_web::#conf_HTTPS_Port))
Exit_Web = 0 Exit_Web = 0
Repeat Repeat
Delay(100) Delay(100)