lhttpd first changes WIP
This commit is contained in:
parent
44e7fe2fe3
commit
3891ac0d5c
2 changed files with 172 additions and 20 deletions
87
createini.pb
87
createini.pb
|
@ -1,19 +1,96 @@
|
|||
CreatePreferences("lhttpd.ini", #PB_Preference_NoSpace | #PB_Preference_GroupSeparator)
|
||||
Structure GROUP
|
||||
gr_name.s ; group name
|
||||
gr_passwd.s ; group password
|
||||
gr_gid.i ; group id
|
||||
gr_mem.i ; group members
|
||||
EndStructure
|
||||
|
||||
Global gID.i = getgid_()
|
||||
Global group.group
|
||||
Global gName.s
|
||||
Global eingabe.s
|
||||
|
||||
*groupmem = AllocateMemory(SizeOf(group))
|
||||
*groupmem = getgrgid_(gID)
|
||||
CopyMemory(*groupmem, @group, SizeOf(group))
|
||||
gName = PeekS(@group\gr_name, -1, #PB_Ascii)
|
||||
|
||||
OpenConsole("lhttpd Init")
|
||||
If gName <> "root"
|
||||
PrintN("You need to run this app as root capable user")
|
||||
End
|
||||
EndIf
|
||||
|
||||
PrintN("Create lhttpd config: /etc/lhttpd/lhttpd.cfg")
|
||||
PrintN("Create service file: /usr/lib/systemd/system/lhttpd.service")
|
||||
PrintN("Logfiles /var/log/lhttpd/* (access.log & error.log)")
|
||||
PrintN("User = lhttpd")
|
||||
PrintN("Grounp = lhttpd")
|
||||
PrintN("Everything Ok (y/n)")
|
||||
eingabe = Input()
|
||||
If eingabe <> "y"
|
||||
PrintN("Bad: "+eingabe+" exit...")
|
||||
End
|
||||
EndIf
|
||||
PrintN("Create dir...")
|
||||
CreateDirectory("/etc/lhttpd")
|
||||
CreateDirectory("/etc/lhttpd/ssl")
|
||||
CreateDirectory("/var/lib/lhttpd")
|
||||
PrintN("Create group lhttpd")
|
||||
RunProgram("groupadd", "-f lhttpd", "", #PB_Program_Wait)
|
||||
Delay(1000)
|
||||
PrintN("Create User lhttpd")
|
||||
RunProgram("useradd", "-s /bin/false -b /var/lib -g lhttpd lhttpd","", #PB_Program_Wait)
|
||||
PrintN("Create config")
|
||||
CreatePreferences("/etc/lhttpd/lhttpd.cfg", #PB_Preference_NoSpace | #PB_Preference_GroupSeparator)
|
||||
PreferenceGroup("lhttpd")
|
||||
WritePreferenceString("HTTP_Port","8081")
|
||||
WritePreferenceString("HTTP_Binding","0.0.0.0")
|
||||
WritePreferenceString("HTTPS_CA","/home/renlin/dev/libressl/sample/test_ca.pem")
|
||||
WritePreferenceString("HTTPS_Cert","/home/renlin/dev/libressl/sample/test_server_cert.pem")
|
||||
WritePreferenceString("HTTPS_Key","/home/renlin/dev/libressl/sample/test_server_key.pem")
|
||||
WritePreferenceString("HTTPS_CA","/etc/lhttpd/ssl/sample/test_ca.pem")
|
||||
WritePreferenceString("HTTPS_Cert","/etc/lhttpd/ssl/sample/test_server_cert.pem")
|
||||
WritePreferenceString("HTTPS_Key","/etc/lhttpd/ssl/sample/test_server_key.pem")
|
||||
WritePreferenceString("HTTPS_Key_Pass","test-server-pass")
|
||||
WritePreferenceString("HTTPS_Port","8444")
|
||||
WritePreferenceString("HTTPS_Binding","127.0.0.1")
|
||||
WritePreferenceString("HTTPS_enable","0")
|
||||
WritePreferenceString("Defaultfile","/index.html")
|
||||
WritePreferenceString("Basedirectory","/home/renlin/testweb/")
|
||||
WritePreferenceString("Basedirectory","/srv/www/htdocs")
|
||||
WritePreferenceString("Error400_Handling","integrated")
|
||||
WritePreferenceString("Max_HTTP_Clients","10")
|
||||
WritePreferenceString("Max_HTTPS_Clients","100")
|
||||
WritePreferenceString("Filememorycache","0")
|
||||
WritePreferenceString("Checkrun","/tmp/lhttpd.run")
|
||||
ClosePreferences()
|
||||
PrintN("chown and chmod for ssl...")
|
||||
RunProgram("chown", "-R lhttpd:lhttpd /etc/lhttpd","", #PB_Program_Wait)
|
||||
RunProgram("chmod", "-r 700 /etc/lhttpd/ssl","",#PB_Program_Wait)
|
||||
PrintN("create service file...")
|
||||
If CreateFile(0, "/usr/lib/systemd/system/lhttpd.service")
|
||||
WriteStringN(0,"[Unit]")
|
||||
WriteStringN(0,"Description=Lweb httpd server")
|
||||
WriteStringN(0,"After=network.target")
|
||||
WriteStringN(0,"StartLimitIntervalSec=0")
|
||||
WriteStringN(0,"")
|
||||
WriteStringN(0,"[Service]")
|
||||
WriteStringN(0,"Type=simple")
|
||||
WriteStringN(0,"Restart=always")
|
||||
WriteStringN(0,"RestartSec=1")
|
||||
WriteStringN(0,"User=lhttpd")
|
||||
WriteStringN(0,"PIDFile=/tmp/lhttpd.run")
|
||||
WriteStringN(0,"ExecStart=/opt/lhttpd/lhttpd")
|
||||
WriteStringN(0,"ExecStop=/bin/rm /tmp/lhttpd.run")
|
||||
WriteStringN(0,"")
|
||||
WriteStringN(0,"[Install]")
|
||||
WriteStringN(0,"WantedBy=multi-user.target")
|
||||
CloseFile(0)
|
||||
PrintN("daemon reload...")
|
||||
RunProgram("systemctl", "daemon-reload", "", #PB_Program_Wait)
|
||||
PrintN("tests...")
|
||||
RunProgram("systemctl", "status lhttpd", "", #PB_Program_Wait)
|
||||
PrintN("finished")
|
||||
Else
|
||||
PrintN("Servicefile failed")
|
||||
EndIf
|
||||
|
||||
|
||||
End
|
||||
|
|
105
lhttpd.pb
105
lhttpd.pb
|
@ -10,6 +10,56 @@
|
|||
|
||||
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.
|
||||
|
||||
OpenConsole("lhttpd")
|
||||
|
||||
Define Parameter.s, Configfile.s, Checkruntime.s, Exit_Web.i
|
||||
Define Accesslog.s, Errorlog.s
|
||||
|
||||
Configfile = "/etc/lhttpd/lhttpd.cfg"
|
||||
Checkruntime = "/tmp/lhttpd.run"
|
||||
|
||||
Repeat
|
||||
Parameter = ProgramParameter()
|
||||
|
||||
If Parameter = "-h" Or Parameter = "--help"
|
||||
PrintN("lhttpd Web Server")
|
||||
PrintN("(c)2021 by Linder Hard- und Software")
|
||||
PrintN("")
|
||||
PrintN("Start parameters:")
|
||||
PrintN("-c=/etc/lhttpd or --config=/etc/lhttpd")
|
||||
PrintN(" Configuration file.")
|
||||
PrintN("--run=/tmp/lhttpd.run")
|
||||
PrintN(" Check periodical for the file")
|
||||
ElseIf Left(Parameter,3) = "-c=" Or Left(Parameter,9) = "--config="
|
||||
Configfile = Right(Parameter, Len(Parameter) - FindString(Parameter, "=") + 1)
|
||||
If ReadFile(0, Configfile)
|
||||
CloseFile(0)
|
||||
Else
|
||||
PrintN("Failed unable to open config file")
|
||||
End
|
||||
EndIf
|
||||
ElseIf Left(Parameter,6) = "--run="
|
||||
Checkruntime = Right(Parameter, Len(Parameter)-6)
|
||||
If CreateFile(0, Checkruntime)
|
||||
CloseFile(0)
|
||||
Else
|
||||
PrintN("Failed unable to create check file:["+Checkruntime+"]")
|
||||
End
|
||||
EndIf
|
||||
|
||||
ElseIf Parameter = ""
|
||||
;No Parameters
|
||||
Else
|
||||
PrintN("unknown parameter")
|
||||
PrintN("-h for parameters")
|
||||
End
|
||||
EndIf
|
||||
Until Parameter = ""
|
||||
|
||||
|
||||
;*
|
||||
;* Variable Declaration.
|
||||
;*
|
||||
|
@ -17,16 +67,14 @@ EnableExplicit
|
|||
XIncludeFile "lweb_header.pbi"
|
||||
XIncludeFile "lweb.pbi"
|
||||
|
||||
OpenConsole("Test")
|
||||
|
||||
If OpenPreferences("lhttpd.ini", #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/test_ca.pem"))
|
||||
lhs_web::set_config(lhs_web::#conf_HTTPS_Cert, ReadPreferenceString("HTTPS_Cert","/home/renlin/dev/libressl/sample/test_server_cert.pem"))
|
||||
lhs_web::set_config(lhs_web::#conf_HTTPS_Key, ReadPreferenceString("HTTPS_Key","/home/renlin/dev/libressl/sample/test_server_key.pem"))
|
||||
lhs_web::set_config(lhs_web::#conf_HTTPS_Key_Pass, ReadPreferenceString("HTTPS_Key_Pass","test-server-pass"))
|
||||
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"))
|
||||
|
@ -45,24 +93,51 @@ Else
|
|||
PrintN("Could not open config file.")
|
||||
EndIf
|
||||
|
||||
lhs_log::App_Name = "http-s_server_example"
|
||||
lhs_log::SetLogFile("http-s_server_example_debug.log")
|
||||
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:
|
||||
;*
|
||||
Accesslog = lhs_log_ext::Create("Accesslog")
|
||||
Errorlog = lhs_log_ext::Create("Errorlog")
|
||||
lhs_log::Out("Errorlog UUID:"+Errorlog)
|
||||
lhs_log::Out("Accesslog UUID:"+Accesslog)
|
||||
lhs_log_ext::SetLogFile(Accesslog, "http-s_access.log")
|
||||
lhs_log_ext::SetLogFile(Errorlog, "http-s_error.log")
|
||||
lhs_log_ext::Init(Accesslog)
|
||||
lhs_log_ext::Init(Errorlog)
|
||||
|
||||
;*
|
||||
;* includes
|
||||
;*
|
||||
|
||||
If lhs_web::start_server()
|
||||
lhs_log::Out("Server started:")
|
||||
lhs_log::Out("HTTP Port:"+ lhs_web::get_config(lhs_web::#conf_HTTP_port)
|
||||
lhs_log::Out("HTTPS Port:"+ lhs_web::get_config(lhs_web::#conf_HTTPS_port)
|
||||
lhs_log::Out("HTTP Port:"+ lhs_web::get_config(lhs_web::#conf_HTTP_port))
|
||||
lhs_log::Out("HTTPS Port:"+ lhs_web::get_config(lhs_web::#conf_HTTPS_port))
|
||||
Else
|
||||
lhs_log::Out("Serverstart failed."
|
||||
lhs_log::Out("Serverstart failed.")
|
||||
End
|
||||
EndIf
|
||||
|
||||
PrintN("Webserver")
|
||||
PrintN("HTTP an Port:"+lhs_web::get_config(lhs_web::#conf_port))
|
||||
PrintN("HTTPS an Port:"+lhs_web::get_config(lhs_web::#conf_HTTPS_Port))
|
||||
PrintN("Press Enter to Exit")
|
||||
Input()
|
||||
|
||||
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))
|
||||
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue