summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--conf/main.go67
-rw-r--r--db/db.go6
-rw-r--r--phlox/main.go24
3 files changed, 90 insertions, 7 deletions
diff --git a/conf/main.go b/conf/main.go
index 182d97f..d0785f8 100644
--- a/conf/main.go
+++ b/conf/main.go
@@ -71,6 +71,11 @@ func main() {
9: SetPath(),
10: SetAddress(),
11: ListEndpoints(),
+
+ 12: SetHost(),
+ 13: GetHost(),
+ 14: SetLogin(),
+ 15: GetLogin(),
}
for val, cmd := range cmds {
@@ -116,3 +121,65 @@ func SchemaVersion() *Command {
},
}
}
+
+
+func SetHost() *Command {
+ return &Command{
+ Flag: "set-host-address",
+ Usage: "set the address to serve the reverse proxy on",
+ Invoke: func() {
+ OpenDb()
+ defer p.Close()
+ address := ReadLine("Address: ")
+ err := p.SetHostAddress(address)
+ if err != nil { log.Fatal(err) }
+ fmt.Printf("set host address to %v\n", address)
+ },
+ }
+}
+
+
+func GetHost() *Command {
+ return &Command{
+ Flag: "get-host-address",
+ Usage: "get the address to serve the reverse proxy on",
+ Invoke: func() {
+ OpenDb()
+ defer p.Close()
+ address, err := p.GetHostAddress()
+ if err != nil { log.Fatal(err) }
+ fmt.Printf("host address is %v\n", address)
+ },
+ }
+}
+
+
+func SetLogin() *Command {
+ return &Command{
+ Flag: "set-login-page",
+ Usage: "set the file to serve as the login page",
+ Invoke: func() {
+ OpenDb()
+ defer p.Close()
+ path := ReadLine("File Path (blank for internal default): ")
+ err := p.SetLoginPage(path)
+ if err != nil { log.Fatal(err) }
+ fmt.Printf("set login page to %v\n", path)
+ },
+ }
+}
+
+
+func GetLogin() *Command {
+ return &Command{
+ Flag: "get-login-page",
+ Usage: "get the file to serve the reverse proxy on",
+ Invoke: func() {
+ OpenDb()
+ defer p.Close()
+ path, err := p.GetLoginPage()
+ if err != nil { log.Fatal(err) }
+ fmt.Printf("login page is at %v\n", path)
+ },
+ }
+}
diff --git a/db/db.go b/db/db.go
index 3210846..d9b4578 100644
--- a/db/db.go
+++ b/db/db.go
@@ -150,6 +150,12 @@ func (p *Phlox) Open(filename string) error {
}
+func (p *Phlox) Close() error {
+ err := p.db.Close()
+ return err
+}
+
+
func (p *Phlox) GetSchemaVersion() (int, error) {
row := p.db.QueryRow("select max(version) from schema;")
if row.Err() != nil {
diff --git a/phlox/main.go b/phlox/main.go
index 3516374..ee9416c 100644
--- a/phlox/main.go
+++ b/phlox/main.go
@@ -4,14 +4,30 @@ import (
"fmt"
"io"
"strings"
+ "flag"
"net"
"net/http"
"net/url"
log "github.com/sirupsen/logrus"
+ db "sanine.net/git/phlox/db"
)
+var p *db.Plhox
+
+
func main() {
+ var dbfile string
+ flag.StringVar(&dbfile, "db", "/etc/phlox/phlox.conf", "path to the configuration db")
+ flag.Parse()
+
+ p := &db.Phlox{}
+ err := p.Open(dbfile)
+ if err != nil {
+ log.Fatal(err)
+ }
+ defer p.Close()
+
const addr = "localhost:3333"
log.Info("configuring reverse proxy...")
@@ -22,12 +38,6 @@ func main() {
}
-type Endpoint struct {
- Path string
- Origin *url.URL
-}
-
-
func configureEndpoint(path, address string) {
log.Infof("proxying endpoint %v to %v", path, address)
origin, err := url.Parse(address)
@@ -68,7 +78,7 @@ func proxyRequest(w http.ResponseWriter, req *http.Request, end Endpoint) *http
// misc request cleanups
req.URL.Scheme = end.Origin.Scheme
req.RequestURI = ""
-
+
// make request
response, err := http.DefaultClient.Do(req)
if err != nil {