141 lines
3.6 KiB
Text
141 lines
3.6 KiB
Text
;****************************
|
|
;*
|
|
;* Lihaso Web Server (lhttpd)
|
|
;*
|
|
;* (c)2020 by Linder Hard- und Software
|
|
;*
|
|
;* 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_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, Debuglogfile.s, DebuglogID.s
|
|
Define Version.s = "V0.8"
|
|
|
|
Configfile = "/etc/lhttpd/lhttpd.cfg"
|
|
Checkruntime = "/tmp/lhttpd.run"
|
|
|
|
Repeat
|
|
Parameter = ProgramParameter()
|
|
|
|
If Parameter = "-h" Or Parameter = "--help"
|
|
PrintN("lhttpd Web Server "+Version)
|
|
PrintN("(c)2023 by Linder Hard- und Software")
|
|
PrintN("")
|
|
PrintN("Start parameters:")
|
|
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, "="))
|
|
If ReadFile(0, Configfile)
|
|
CloseFile(0)
|
|
Else
|
|
PrintN("Failed unable to open config file:["+Configfile+"]")
|
|
End
|
|
EndIf
|
|
ElseIf Left(Parameter,6) = "--run="
|
|
Checkruntime = Right(Parameter, Len(Parameter)-6)
|
|
If ReadFile(0, Checkruntime)
|
|
CloseFile(0)
|
|
Else
|
|
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
|
|
PrintN("unknown parameter")
|
|
PrintN("-h for parameters")
|
|
End
|
|
EndIf
|
|
Until Parameter = ""
|
|
|
|
|
|
;*
|
|
;* Variable Declaration.
|
|
;*
|
|
|
|
XIncludeFile "lweb_header.pbi"
|
|
XIncludeFile "lweb.pbi"
|
|
|
|
PrintN("lhttpd Webserver "+Version)
|
|
|
|
If Len(Checkruntime) > 0
|
|
If ReadFile(0, Checkruntime)
|
|
CloseFile(0)
|
|
PrintN("PID File created --run="+Checkruntime)
|
|
Else
|
|
PrintN("Error: PID File:["+Checkruntime+"] could Not be created.")
|
|
End
|
|
EndIf
|
|
Else
|
|
PrintN("NO PID File configured --run=file.pid")
|
|
PrintN("Exit")
|
|
End
|
|
EndIf
|
|
|
|
|
|
|
|
;*
|
|
;* 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.")
|
|
|
|
PrintN("Start Server...")
|
|
;*
|
|
;* Server Start
|
|
;*
|
|
|
|
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
|
|
ldl::Logging("Serverstart failed.")
|
|
PrintN("Serverstart failed.")
|
|
End
|
|
EndIf
|
|
|
|
PrintN("Server Started.")
|
|
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
|