serve now pulls config and config panics if it fails to create
Had to also add var to allow serve to pull certs If it cannot manage the config it needs to exit, so it made more sense to add it there then check every time it is calledexperimental
parent
abb66d2498
commit
2cb3b541b8
|
|
@ -4,7 +4,6 @@ import (
|
|||
"bufio"
|
||||
"log"
|
||||
"os"
|
||||
"errors"
|
||||
)
|
||||
|
||||
const CFG = `
|
||||
|
|
@ -34,6 +33,7 @@ type Config struct {
|
|||
TmpDir string
|
||||
HostsLoc string
|
||||
CfgLoc string
|
||||
Var string
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -41,12 +41,14 @@ type Config struct {
|
|||
var configFuncs []func(*Config)
|
||||
|
||||
// Create initialized a config to be used the entire session
|
||||
func Create() (err error,cfg Config) {
|
||||
func Create() (cfg Config) {
|
||||
for _,fp := range(configFuncs){
|
||||
fp(&cfg)
|
||||
}
|
||||
if (cfg.System.OS == ""){return errors.New("Failed to detect the OS"), cfg}
|
||||
err, cfg = cfg.Update()
|
||||
if (cfg.System.OS == ""){log.Panic("Failed to detect the OS")}
|
||||
err, cfg := cfg.Update()
|
||||
|
||||
if (err != nil){log.Panic("Failed to handle the config file: " + err.Error())}
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,16 +1,16 @@
|
|||
//go:build linux
|
||||
// +build linux
|
||||
|
||||
package cfg
|
||||
|
||||
|
||||
func init(){
|
||||
fp := func(c *Config){
|
||||
c.System.OS = "linux"
|
||||
c.System.TmpDir = "/tmp/"
|
||||
c.System.HostsLoc = "/etc/hosts"
|
||||
c.System.CfgLoc = "/etc/rhosts/"
|
||||
func init() {
|
||||
fp := func(c *Config) {
|
||||
c.System.OS = "linux"
|
||||
c.System.TmpDir = "/tmp/"
|
||||
c.System.HostsLoc = "/etc/hosts"
|
||||
c.System.CfgLoc = "/etc/rhosts/"
|
||||
c.System.Var = "/var/lib/rhosts/"
|
||||
}
|
||||
|
||||
configFuncs = append(configFuncs,fp)
|
||||
configFuncs = append(configFuncs, fp)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,19 +1,20 @@
|
|||
//go:build windows
|
||||
// +build windows
|
||||
|
||||
package sys
|
||||
|
||||
|
||||
func init(){
|
||||
func init() {
|
||||
|
||||
}
|
||||
|
||||
func init(){
|
||||
fp := func(c *Config){
|
||||
c.System.os = "windows"
|
||||
func init() {
|
||||
fp := func(c *Config) {
|
||||
c.System.os = "windows"
|
||||
c.System.tmpdir = "/tmp/"
|
||||
c.System.hostsloc = "/Windows/System32/drivers/etc/hosts"
|
||||
c.System.cfgloc = "/ProgramData/rhosts/"
|
||||
c.System.Var = "/ProgramData/rhosts/"
|
||||
}
|
||||
|
||||
configFuncs = append(configFuncs,fp)
|
||||
configFuncs = append(configFuncs, fp)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,8 +22,7 @@ type siteEntry struct {
|
|||
}
|
||||
|
||||
func Update() (err error) {
|
||||
err, config := cfg.Create()
|
||||
if (err != nil){return}
|
||||
config := cfg.Create()
|
||||
var siteBuff []siteList
|
||||
|
||||
err = error(nil)
|
||||
|
|
|
|||
|
|
@ -83,7 +83,7 @@ func main() {
|
|||
}
|
||||
|
||||
// Starting web server
|
||||
serve.Start("blank")
|
||||
serve.Start()
|
||||
|
||||
// Update the hosts file
|
||||
if daemon == false {
|
||||
|
|
|
|||
|
|
@ -3,11 +3,13 @@ package serve
|
|||
|
||||
import (
|
||||
"net/http"
|
||||
"jbreich/rhosts/cfg"
|
||||
)
|
||||
|
||||
func Start(certLoc string) {
|
||||
func Start() {
|
||||
config := cfg.Create()
|
||||
go httpServer()
|
||||
//go httpsServer(&certLoc)
|
||||
go httpsServer(config.System.Var + "/certs/")
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -15,8 +17,8 @@ func httpServer() (err error) {
|
|||
err = http.ListenAndServe("127.0.0.1:80", http.HandlerFunc(httpHandler))
|
||||
return
|
||||
}
|
||||
func httpsServer(certLoc *string) (err error) {
|
||||
err = http.ListenAndServeTLS("127.0.0.1:80", *certLoc+"ca.crt", *certLoc+"ca.key", http.HandlerFunc(httpHandler))
|
||||
func httpsServer(certLoc string) (err error) {
|
||||
err = http.ListenAndServeTLS("127.0.0.1:80", certLoc+"ca.crt", certLoc+"ca.key", http.HandlerFunc(httpHandler))
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue