lweb/lhttpd.pb

142 lines
3.6 KiB
Text
Raw Normal View History

;****************************
;*
;* Lihaso Web Server (lhttpd)
;*
;* (c)2020 by Linder Hard- und Software
;*
;* V0.5
;* - Simple webserver for HTTP & HTTPS
2023-03-30 10:49:06 +02:00
;* V0.8
;* - Webserver for HTTP & HTTPS now with the last Library Version
;*
EnableExplicit
2021-05-25 17:04:24 +02:00
XIncludeFile "lhs_lib/SYS/lhs_log_ext.pbi" ;User for Access Log, Error Access Log, Error Log and maybe more.
2023-03-30 10:49:06 +02:00
XIncludeFile "lhs_lib/SYS/lhs_sys_debug_wrapper.pbi" ;For all Log Outputs
2021-05-25 17:04:24 +02:00
OpenConsole("lhttpd")
Define Parameter.s, Configfile.s, Checkruntime.s, Exit_Web.i
2023-03-30 10:49:06 +02:00
Define Accesslog.s, Errorlog.s, Debuglogfile.s, DebuglogID.s
Define Version.s = "V0.8"
2021-05-25 17:04:24 +02:00
Configfile = "/etc/lhttpd/lhttpd.cfg"
Checkruntime = "/tmp/lhttpd.run"
Repeat
Parameter = ProgramParameter()
If Parameter = "-h" Or Parameter = "--help"
2023-03-30 10:49:06 +02:00
PrintN("lhttpd Web Server "+Version)
PrintN("(c)2023 by Linder Hard- und Software")
2021-05-25 17:04:24 +02:00
PrintN("")
PrintN("Start parameters:")
2023-03-30 10:49:06 +02:00
PrintN("-c=/etc/lhttpd/server.xml or --config=/etc/lhttpd/server.xml")
2021-05-25 17:04:24 +02:00
PrintN(" Configuration file.")
PrintN("--run=/tmp/lhttpd.run")
PrintN(" Check periodical for the file")
2023-03-30 10:49:06 +02:00
PrintN("--debug=/var/log/lhttpd_debug.log")
PrintN(" Activate Debug Log")
2021-05-25 17:04:24 +02:00
ElseIf Left(Parameter,3) = "-c=" Or Left(Parameter,9) = "--config="
2023-03-30 15:46:01 +02:00
Configfile = Right(Parameter, Len(Parameter) - FindString(Parameter, "="))
2021-05-25 17:04:24 +02:00
If ReadFile(0, Configfile)
CloseFile(0)
Else
2023-03-30 15:46:01 +02:00
PrintN("Failed unable to open config file:["+Configfile+"]")
2021-05-25 17:04:24 +02:00
End
EndIf
ElseIf Left(Parameter,6) = "--run="
Checkruntime = Right(Parameter, Len(Parameter)-6)
If ReadFile(0, Checkruntime)
2021-05-25 17:04:24 +02:00
CloseFile(0)
Else
PrintN("Failed to read check file:["+Checkruntime+"]")
2021-05-25 17:04:24 +02:00
End
EndIf
2023-03-30 10:49:06 +02:00
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)
2021-05-25 17:04:24 +02:00
ElseIf Parameter = ""
;No Parameters
Else
PrintN("unknown parameter")
PrintN("-h for parameters")
End
EndIf
Until Parameter = ""
;*
;* Variable Declaration.
;*
XIncludeFile "lweb_header.pbi"
XIncludeFile "lweb.pbi"
2023-03-30 10:49:06 +02:00
PrintN("lhttpd Webserver "+Version)
If Len(Checkruntime) > 0
2023-03-30 15:46:01 +02:00
If ReadFile(0, Checkruntime)
2023-03-30 10:49:06 +02:00
CloseFile(0)
PrintN("PID File created --run="+Checkruntime)
Else
2023-03-30 10:49:06 +02:00
PrintN("Error: PID File:["+Checkruntime+"] could Not be created.")
End
EndIf
Else
2023-03-30 10:49:06 +02:00
PrintN("NO PID File configured --run=file.pid")
PrintN("Exit")
End
EndIf
2023-03-30 10:49:06 +02:00
2021-05-25 17:04:24 +02:00
;*
2023-03-30 10:49:06 +02:00
;* Server Config Start
;*
PrintN("Read Configuration:")
If lhs_web::server_initial("file:"+Configfile)
ldl::Logging("config succesfully loaded.")
Else
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.")
2021-05-25 17:04:24 +02:00
2023-03-30 10:49:06 +02:00
PrintN("Start Server...")
;*
2023-03-30 10:49:06 +02:00
;* Server Start
;*
2023-03-30 10:49:06 +02:00
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
2023-03-30 10:49:06 +02:00
ldl::Logging("Serverstart failed.")
PrintN("Serverstart failed.")
End
EndIf
2023-03-30 10:49:06 +02:00
PrintN("Server Started.")
2021-05-25 17:04:24 +02:00
Exit_Web = 0
Repeat
Delay(100)
If ReadFile(0, Checkruntime)
CloseFile(0)
Else
PrintN("lhttpd stopping...")
Exit_Web = 1
EndIf
Until Exit_Web = 1
PrintN("lhttpd stoped.")
End