diff --git a/lhttpd.pb b/lhttpd.pb index 728c995..62d1827 100644 --- a/lhttpd.pb +++ b/lhttpd.pb @@ -6,17 +6,19 @@ ;* ;* V0.5 ;* - Simple webserver for HTTP & HTTPS +;* V0.8 +;* - Webserver for HTTP & HTTPS now with the last Library Version ;* 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_sys_debug_wrapper.pbi" ;For all Log Outputs OpenConsole("lhttpd") 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" Checkruntime = "/tmp/lhttpd.run" @@ -25,14 +27,17 @@ Repeat Parameter = ProgramParameter() If Parameter = "-h" Or Parameter = "--help" - PrintN("lhttpd Web Server") - PrintN("(c)2021 by Linder Hard- und Software") + PrintN("lhttpd Web Server "+Version) + PrintN("(c)2023 by Linder Hard- und Software") PrintN("") 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("--run=/tmp/lhttpd.run") 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=" Configfile = Right(Parameter, Len(Parameter) - FindString(Parameter, "=") + 1) If ReadFile(0, Configfile) @@ -49,7 +54,14 @@ Repeat PrintN("Failed to read check file:["+Checkruntime+"]") End 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 = "" ;No Parameters Else @@ -67,83 +79,54 @@ Until Parameter = "" XIncludeFile "lweb_header.pbi" XIncludeFile "lweb.pbi" -If OpenPreferences(Configfile, #PB_Preference_GroupSeparator) - If PreferenceGroup("lhttpd") - lhs_web::set_config(lhs_web::#conf_HTTP_port, ReadPreferenceString("HTTP_Port","8081")) - lhs_web::set_config(lhs_web::#conf_HTTP_binding, ReadPreferenceString("HTTP_Binding","0.0.0.0")) - lhs_web::set_config(lhs_web::#conf_HTTPS_CA, ReadPreferenceString("HTTPS_CA","/home/renlin/dev/libressl/sample/fullchain.pem")) - lhs_web::set_config(lhs_web::#conf_HTTPS_Cert, ReadPreferenceString("HTTPS_Cert","/home/renlin/dev/libressl/sample/cert.pem")) - 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() +PrintN("lhttpd Webserver "+Version) + +If Len(Checkruntime) > 0 + If CreateFile(0, Checkruntime) + CloseFile(0) + PrintN("PID File created --run="+Checkruntime) Else - PrintN("No correct config file -> End") + PrintN("Error: PID File:["+Checkruntime+"] could Not be created.") End EndIf Else - PrintN("Could not open config file.") + PrintN("NO PID File configured --run=file.pid") + PrintN("Exit") End 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 - PrintN("Error: PID could not be created.") + ldl::Logging("config load failed.") End 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" -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() - +PrintN("Start Server...") ;* -;* Enable extended Logging: -;* -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 +;* Server Start ;* -If lhs_web::start_server() - lhs_log_ext::OutL(lhs_web::get_config(lhs_web::#conf_Debug_logUUID), lhs_log_ext::#Debugging,"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)) - 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)) +If lhs_web::server_start() + ldl::Logging("Server started:") + ldl::Logging("Configured HTTP at Port(s):"+lhs_web::server_get_config("ports_http")) + ldl::Logging("Configured HTTPS at Port(s):"+lhs_web::server_get_config("ports_https")) 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 EndIf -PrintN("lhttpd Webserver") -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)) - +PrintN("Server Started.") Exit_Web = 0 Repeat Delay(100)