lhttpd and createini updated
Now a working dedicated http/https server.
This commit is contained in:
parent
05a1b71465
commit
88b0eeb260
4 changed files with 89 additions and 21 deletions
25
createini.pb
25
createini.pb
|
@ -36,6 +36,9 @@ PrintN("Create dir...")
|
||||||
CreateDirectory("/etc/lhttpd")
|
CreateDirectory("/etc/lhttpd")
|
||||||
CreateDirectory("/etc/lhttpd/ssl")
|
CreateDirectory("/etc/lhttpd/ssl")
|
||||||
CreateDirectory("/var/lib/lhttpd")
|
CreateDirectory("/var/lib/lhttpd")
|
||||||
|
CreateDirectory("/var/log/lhttpd")
|
||||||
|
CreateDirectory("/opt/lhttpd")
|
||||||
|
|
||||||
PrintN("Create group lhttpd")
|
PrintN("Create group lhttpd")
|
||||||
RunProgram("groupadd", "-f lhttpd", "", #PB_Program_Wait)
|
RunProgram("groupadd", "-f lhttpd", "", #PB_Program_Wait)
|
||||||
Delay(1000)
|
Delay(1000)
|
||||||
|
@ -44,15 +47,15 @@ RunProgram("useradd", "-s /bin/false -b /var/lib -g lhttpd lhttpd","", #PB_Progr
|
||||||
PrintN("Create config")
|
PrintN("Create config")
|
||||||
CreatePreferences("/etc/lhttpd/lhttpd.cfg", #PB_Preference_NoSpace | #PB_Preference_GroupSeparator)
|
CreatePreferences("/etc/lhttpd/lhttpd.cfg", #PB_Preference_NoSpace | #PB_Preference_GroupSeparator)
|
||||||
PreferenceGroup("lhttpd")
|
PreferenceGroup("lhttpd")
|
||||||
WritePreferenceString("HTTP_Port","8081")
|
WritePreferenceString("HTTP_Port","8080")
|
||||||
WritePreferenceString("HTTP_Binding","0.0.0.0")
|
WritePreferenceString("HTTP_Binding","0.0.0.0")
|
||||||
WritePreferenceString("HTTPS_CA","/etc/lhttpd/ssl/sample/test_ca.pem")
|
WritePreferenceString("HTTPS_CA","/etc/lhttpd/ssl/sample/fullchain.pem")
|
||||||
WritePreferenceString("HTTPS_Cert","/etc/lhttpd/ssl/sample/test_server_cert.pem")
|
WritePreferenceString("HTTPS_Cert","/etc/lhttpd/ssl/sample/cert.pem")
|
||||||
WritePreferenceString("HTTPS_Key","/etc/lhttpd/ssl/sample/test_server_key.pem")
|
WritePreferenceString("HTTPS_Key","/etc/lhttpd/ssl/sample/privkey.pem")
|
||||||
WritePreferenceString("HTTPS_Key_Pass","test-server-pass")
|
WritePreferenceString("HTTPS_Key_Pass","test-server-pass")
|
||||||
WritePreferenceString("HTTPS_Port","8444")
|
WritePreferenceString("HTTPS_Port","8443)
|
||||||
WritePreferenceString("HTTPS_Binding","127.0.0.1")
|
WritePreferenceString("HTTPS_Binding","0.0.0.0")
|
||||||
WritePreferenceString("HTTPS_enable","0")
|
WritePreferenceString("HTTPS_enable","1")
|
||||||
WritePreferenceString("Defaultfile","/index.html")
|
WritePreferenceString("Defaultfile","/index.html")
|
||||||
WritePreferenceString("Basedirectory","/srv/www/htdocs")
|
WritePreferenceString("Basedirectory","/srv/www/htdocs")
|
||||||
WritePreferenceString("Error400_Handling","integrated")
|
WritePreferenceString("Error400_Handling","integrated")
|
||||||
|
@ -60,9 +63,17 @@ WritePreferenceString("Max_HTTP_Clients","10")
|
||||||
WritePreferenceString("Max_HTTPS_Clients","100")
|
WritePreferenceString("Max_HTTPS_Clients","100")
|
||||||
WritePreferenceString("Filememorycache","0")
|
WritePreferenceString("Filememorycache","0")
|
||||||
WritePreferenceString("Checkrun","/tmp/lhttpd.run")
|
WritePreferenceString("Checkrun","/tmp/lhttpd.run")
|
||||||
|
WritePreferenceString("Debug_logfile","/var/log/lhttpd/debug.log")
|
||||||
|
WritePreferenceString("Debug_disable","true")
|
||||||
|
WritePreferenceString("Access_logfile","/var/log/lhttpd/access.log")
|
||||||
|
WritePreferenceString("Error_logfile","/var/log/lhttpd/error.log")
|
||||||
ClosePreferences()
|
ClosePreferences()
|
||||||
PrintN("chown and chmod for ssl...")
|
PrintN("chown and chmod for ssl...")
|
||||||
|
|
||||||
RunProgram("chown", "-R lhttpd:lhttpd /etc/lhttpd","", #PB_Program_Wait)
|
RunProgram("chown", "-R lhttpd:lhttpd /etc/lhttpd","", #PB_Program_Wait)
|
||||||
|
RunProgram("chown", "-R lhttpd:lhttpd /var/lib/lhttpd","", #PB_Program_Wait)
|
||||||
|
RunProgram("chown", "-R lhttpd:lhttpd /var/log/lhttpd","", #PB_Program_Wait)
|
||||||
|
RunProgram("chmod", "-r 755 /etc/lhttpd","",#PB_Program_Wait)
|
||||||
RunProgram("chmod", "-r 700 /etc/lhttpd/ssl","",#PB_Program_Wait)
|
RunProgram("chmod", "-r 700 /etc/lhttpd/ssl","",#PB_Program_Wait)
|
||||||
PrintN("create service file...")
|
PrintN("create service file...")
|
||||||
If CreateFile(0, "/usr/lib/systemd/system/lhttpd.service")
|
If CreateFile(0, "/usr/lib/systemd/system/lhttpd.service")
|
||||||
|
|
29
lhttpd.pb
29
lhttpd.pb
|
@ -43,10 +43,10 @@ Repeat
|
||||||
EndIf
|
EndIf
|
||||||
ElseIf Left(Parameter,6) = "--run="
|
ElseIf Left(Parameter,6) = "--run="
|
||||||
Checkruntime = Right(Parameter, Len(Parameter)-6)
|
Checkruntime = Right(Parameter, Len(Parameter)-6)
|
||||||
If CreateFile(0, Checkruntime)
|
If ReadFile(0, Checkruntime)
|
||||||
CloseFile(0)
|
CloseFile(0)
|
||||||
Else
|
Else
|
||||||
PrintN("Failed unable to create check file:["+Checkruntime+"]")
|
PrintN("Failed to read check file:["+Checkruntime+"]")
|
||||||
End
|
End
|
||||||
EndIf
|
EndIf
|
||||||
|
|
||||||
|
@ -67,7 +67,7 @@ Until Parameter = ""
|
||||||
XIncludeFile "lweb_header.pbi"
|
XIncludeFile "lweb_header.pbi"
|
||||||
XIncludeFile "lweb.pbi"
|
XIncludeFile "lweb.pbi"
|
||||||
|
|
||||||
If OpenPreferences("lhttpd.ini", #PB_Preference_GroupSeparator)
|
If OpenPreferences(Configfile, #PB_Preference_GroupSeparator)
|
||||||
If PreferenceGroup("lhttpd")
|
If PreferenceGroup("lhttpd")
|
||||||
lhs_web::set_config(lhs_web::#conf_HTTP_port, ReadPreferenceString("HTTP_Port","8081"))
|
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_HTTP_binding, ReadPreferenceString("HTTP_Binding","0.0.0.0"))
|
||||||
|
@ -84,6 +84,11 @@ If OpenPreferences("lhttpd.ini", #PB_Preference_GroupSeparator)
|
||||||
lhs_web::set_config(lhs_web::#conf_max_HTTP_clients, ReadPreferenceString("Max_HTTP_Clients","10"))
|
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_max_HTTPS_clients, ReadPreferenceString("Max_HTTPS_Clients","100"))
|
||||||
lhs_web::set_config(lhs_web::#conf_cache_enable, ReadPreferenceString("Filememorycache","0"))
|
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()
|
ClosePreferences()
|
||||||
Else
|
Else
|
||||||
PrintN("No correct config file -> End")
|
PrintN("No correct config file -> End")
|
||||||
|
@ -91,10 +96,18 @@ If OpenPreferences("lhttpd.ini", #PB_Preference_GroupSeparator)
|
||||||
EndIf
|
EndIf
|
||||||
Else
|
Else
|
||||||
PrintN("Could not open config file.")
|
PrintN("Could not open config file.")
|
||||||
|
End
|
||||||
|
EndIf
|
||||||
|
If CreateFile(0, Checkruntime)
|
||||||
|
CloseFile(0)
|
||||||
|
PrintN("PID File created")
|
||||||
|
Else
|
||||||
|
PrintN("Error: PID could not be created.")
|
||||||
|
End
|
||||||
EndIf
|
EndIf
|
||||||
|
|
||||||
lhs_log::App_Name = "http-s_server_example"
|
lhs_log::App_Name = "lhttpd Web Server Debug"
|
||||||
lhs_log::SetLogFile("http-s_server_example_debug.log")
|
lhs_log::SetLogFile(lhs_web::get_config(lhs_web::#conf_debug_logfile))
|
||||||
lhs_log::SetMaxSize(32)
|
lhs_log::SetMaxSize(32)
|
||||||
lhs_log::SetLogDateFormat("%yyyy.%mm.%dd %hh:%ii:%ss")
|
lhs_log::SetLogDateFormat("%yyyy.%mm.%dd %hh:%ii:%ss")
|
||||||
lhs_log::SetLogFileDateFormat("%yyyy_%mm_%dd_%hh_%ii_%ss")
|
lhs_log::SetLogFileDateFormat("%yyyy_%mm_%dd_%hh_%ii_%ss")
|
||||||
|
@ -107,8 +120,10 @@ Accesslog = lhs_log_ext::Create("Accesslog")
|
||||||
Errorlog = lhs_log_ext::Create("Errorlog")
|
Errorlog = lhs_log_ext::Create("Errorlog")
|
||||||
lhs_log::Out("Errorlog UUID:"+Errorlog)
|
lhs_log::Out("Errorlog UUID:"+Errorlog)
|
||||||
lhs_log::Out("Accesslog UUID:"+Accesslog)
|
lhs_log::Out("Accesslog UUID:"+Accesslog)
|
||||||
lhs_log_ext::SetLogFile(Accesslog, "http-s_access.log")
|
lhs_web::set_config(lhs_web::#conf_Access_logUUID, Accesslog)
|
||||||
lhs_log_ext::SetLogFile(Errorlog, "http-s_error.log")
|
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(Accesslog)
|
||||||
lhs_log_ext::Init(Errorlog)
|
lhs_log_ext::Init(Errorlog)
|
||||||
|
|
||||||
|
|
47
lweb.pbi
47
lweb.pbi
|
@ -48,8 +48,12 @@ Module lhs_web
|
||||||
EndStructure
|
EndStructure
|
||||||
|
|
||||||
Structure log_config
|
Structure log_config
|
||||||
|
Debuglog.s
|
||||||
|
Debugdisable.i
|
||||||
Accesslog.s
|
Accesslog.s
|
||||||
|
AccesslogUUID.s
|
||||||
Errorlog.s
|
Errorlog.s
|
||||||
|
ErrorlogUUID.s
|
||||||
EndStructure
|
EndStructure
|
||||||
|
|
||||||
Structure server
|
Structure server
|
||||||
|
@ -242,10 +246,24 @@ Module lhs_web
|
||||||
|
|
||||||
Procedure set_config(parameter.i=#conf_defaultfile, setting.s="index.html")
|
Procedure set_config(parameter.i=#conf_defaultfile, setting.s="index.html")
|
||||||
Select parameter
|
Select parameter
|
||||||
Case #conf_log_Accesslog
|
Case #conf_Access_logfile
|
||||||
configuration\log\Accesslog = setting
|
configuration\log\Accesslog = setting
|
||||||
Case #conf_log_Errorlog
|
Case #conf_Error_logfile
|
||||||
configuration\log\Errorlog = setting
|
configuration\log\Errorlog = setting
|
||||||
|
Case #conf_Access_logUUID
|
||||||
|
configuration\log\AccesslogUUID = setting
|
||||||
|
Case #conf_Error_logUUID
|
||||||
|
configuration\log\ErrorlogUUID = setting
|
||||||
|
Case #conf_debug_logfile
|
||||||
|
configuration\log\Debuglog = setting
|
||||||
|
Case #conf_debug_disable
|
||||||
|
If setting = "true"
|
||||||
|
configuration\log\Debugdisable = #True
|
||||||
|
Else
|
||||||
|
configuration\log\Debugdisable = #False
|
||||||
|
EndIf
|
||||||
|
Case #conf_runfile
|
||||||
|
|
||||||
Case #conf_HTTP_port
|
Case #conf_HTTP_port
|
||||||
configuration\http\port = Val(setting)
|
configuration\http\port = Val(setting)
|
||||||
Case #conf_HTTPS_Port
|
Case #conf_HTTPS_Port
|
||||||
|
@ -306,6 +324,22 @@ Module lhs_web
|
||||||
|
|
||||||
Procedure.s get_config(parameter.i=#conf_defaultfile)
|
Procedure.s get_config(parameter.i=#conf_defaultfile)
|
||||||
Select parameter
|
Select parameter
|
||||||
|
Case #conf_Access_logfile
|
||||||
|
ProcedureReturn configuration\log\Accesslog
|
||||||
|
Case #conf_Error_logfile
|
||||||
|
ProcedureReturn configuration\log\Errorlog
|
||||||
|
Case #conf_Access_logUUID
|
||||||
|
ProcedureReturn configuration\log\AccesslogUUID
|
||||||
|
Case #conf_Error_logUUID
|
||||||
|
ProcedureReturn configuration\log\ErrorlogUUID
|
||||||
|
Case #conf_debug_logfile
|
||||||
|
ProcedureReturn configuration\log\Debuglog
|
||||||
|
Case #conf_debug_disable
|
||||||
|
If configuration\log\Debugdisable = #True
|
||||||
|
ProcedureReturn "true"
|
||||||
|
Else
|
||||||
|
ProcedureReturn "false"
|
||||||
|
EndIf
|
||||||
Case #conf_defaultfile
|
Case #conf_defaultfile
|
||||||
ProcedureReturn configuration\defaultfile
|
ProcedureReturn configuration\defaultfile
|
||||||
Case #conf_basedir
|
Case #conf_basedir
|
||||||
|
@ -328,6 +362,9 @@ Module lhs_web
|
||||||
Procedure start_server()
|
Procedure start_server()
|
||||||
Global NewMap m_clients.s_clients(configuration\http\max_clients+configuration\https\max_clients)
|
Global NewMap m_clients.s_clients(configuration\http\max_clients+configuration\https\max_clients)
|
||||||
Protected tlsresponse.i
|
Protected tlsresponse.i
|
||||||
|
If configuration\log\Debugdisable
|
||||||
|
lhs_log::Disable()
|
||||||
|
EndIf
|
||||||
|
|
||||||
;Init HTTP Socket
|
;Init HTTP Socket
|
||||||
server_HTTP_id = lsocket::CreateSocket(configuration\http\port, configuration\http\max_clients, lsocket::#SOCK_STREAM, lsocket::#AF_INET, configuration\http\binding)
|
server_HTTP_id = lsocket::CreateSocket(configuration\http\port, configuration\http\max_clients, lsocket::#SOCK_STREAM, lsocket::#AF_INET, configuration\http\binding)
|
||||||
|
@ -554,11 +591,11 @@ Module lhs_web
|
||||||
|
|
||||||
;lhs_log::Out("JSONString:"+ JSONStringToMap)
|
;lhs_log::Out("JSONString:"+ JSONStringToMap)
|
||||||
thread_type = ""
|
thread_type = ""
|
||||||
If configuration\log\Accesslog <> ""
|
If configuration\log\AccesslogUUID <> ""
|
||||||
If m_clients(Str(thread_cli_id))\client_type = #client_HTTPS
|
If m_clients(Str(thread_cli_id))\client_type = #client_HTTPS
|
||||||
lhs_log_ext::Out(configuration\log\Accesslog, lsocket::GetSocketIP(ltls::GetSocket(thread_cli_id)) + " " + Header(#http_head_method) + " " + Header(#http_head_request))
|
lhs_log_ext::Out(configuration\log\AccesslogUUID, lsocket::GetSocketIP(ltls::GetSocket(thread_cli_id)) + " " + Header(#http_head_method) + " " + Header(#http_head_request))
|
||||||
Else
|
Else
|
||||||
lhs_log_ext::Out(configuration\log\Accesslog, lsocket::GetSocketIP(thread_cli_id) + " " + Header(#http_head_method) + " " + Header(#http_head_request))
|
lhs_log_ext::Out(configuration\log\AccesslogUUID, lsocket::GetSocketIP(thread_cli_id) + " " + Header(#http_head_method) + " " + Header(#http_head_request))
|
||||||
EndIf
|
EndIf
|
||||||
|
|
||||||
EndIf
|
EndIf
|
||||||
|
|
|
@ -39,8 +39,13 @@ DeclareModule lhs_web
|
||||||
#conf_HTTPS_Port
|
#conf_HTTPS_Port
|
||||||
#conf_HTTPS_Binding
|
#conf_HTTPS_Binding
|
||||||
#conf_HTTPS_Enable
|
#conf_HTTPS_Enable
|
||||||
#conf_log_Errorlog
|
#conf_debug_logfile
|
||||||
#conf_log_Accesslog
|
#conf_debug_disable
|
||||||
|
#conf_Access_logfile
|
||||||
|
#conf_Access_logUUID
|
||||||
|
#conf_Error_logfile
|
||||||
|
#conf_Error_logUUID
|
||||||
|
#conf_runfile
|
||||||
EndEnumeration
|
EndEnumeration
|
||||||
|
|
||||||
Enumeration cli_handler 1
|
Enumeration cli_handler 1
|
||||||
|
|
Loading…
Reference in a new issue