1 //
2 // Copyright (C) 2014 Sebastian 'tokkee' Harl <sh@tokkee.org>
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions
7 // are met:
8 // 1. Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // 2. Redistributions in binary form must reproduce the above copyright
11 // notice, this list of conditions and the following disclaimer in the
12 // documentation and/or other materials provided with the distribution.
13 //
14 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
15 // ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
16 // TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
18 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
21 // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
22 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23 // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
24 // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 // webui is a web-based user-interface for SysDB.
27 package main
29 import (
30 "flag"
31 "fmt"
32 "log"
33 "net/http"
34 "os"
35 "os/user"
37 "github.com/sysdb/webui/server"
38 )
40 var (
41 addr = flag.String("address", "/var/run/sysdbd.sock", "SysDB server address")
42 username *string
44 listen = flag.String("listen", ":8080", "address to listen for incoming connections")
45 tmpl = flag.String("template-path", "templates", "location of template files")
46 static = flag.String("static-path", "static", "location of static files")
47 )
49 func init() {
50 u, err := user.Current()
51 var def string
52 if err != nil {
53 log.Printf("WARNING: Unable to determine current user: %v", err)
54 } else {
55 def = u.Username
56 }
58 username = flag.String("user", def, "SysDB user name")
59 }
61 func main() {
62 flag.Parse()
64 log.Printf("Connecting to SysDB at %s.", *addr)
65 srv, err := server.New(*addr, *username, server.Config{
66 TemplatePath: *tmpl,
67 StaticPath: *static,
68 })
69 if err != nil {
70 fatalf("Failed to construct web-server: %v", err)
71 }
73 log.Printf("Listening on %s.", *listen)
74 http.Handle("/", srv)
75 err = http.ListenAndServe(*listen, nil)
76 if err != nil {
77 fatalf("Failed to set up HTTP server on address %q: %v", *listen, err)
78 }
79 }
81 func fatalf(format string, a ...interface{}) {
82 fmt.Fprintf(os.Stderr, format, a...)
83 fmt.Fprintln(os.Stderr)
84 os.Exit(1)
85 }
87 // vim: set tw=78 sw=4 sw=4 noexpandtab :