Browse Source

Start web interface framework

tags/v0.5.0
Daniel Oaks 7 years ago
parent
commit
8dfa888552
6 changed files with 210 additions and 4 deletions
  1. 2
    0
      .gitignore
  2. 25
    4
      README.md
  3. 68
    0
      oragono-web.go
  4. 17
    0
      oragono-web.yaml
  5. 77
    0
      web/config.go
  6. 21
    0
      web/server.go

+ 2
- 0
.gitignore View File

@@ -97,6 +97,8 @@ _testmain.go
97 97
 /_site/
98 98
 /.vscode/*
99 99
 /ircd*
100
+/web-*
101
+/web.*
100 102
 /ssl.*
101 103
 /tls.*
102 104
 /oragono

+ 25
- 4
README.md View File

@@ -16,6 +16,8 @@ Also see the [mammon](https://github.com/mammon-ircd/mammon) IRC daemon for a si
16 16
 
17 17
 This project adheres to [Semantic Versioning](http://semver.org/). For the purposes of versioning, we consider the "public API" to refer to the configuration files, CLI interface and database format.
18 18
 
19
+# Oragono
20
+
19 21
 ## Features
20 22
 
21 23
 * UTF-8 nick and channel names with rfc7700
@@ -30,12 +32,12 @@ This project adheres to [Semantic Versioning](http://semver.org/). For the purpo
30 32
 * passwords stored with [bcrypt](https://godoc.org/golang.org/x/crypto) (client account passwords also salted)
31 33
 * [IRCv3 support](http://ircv3.net/software/servers.html)
32 34
 * a heavy focus on developing with [specifications](http://oragono.io/specs.html)
35
+* integrated REST API and web interface
33 36
 
34 37
 ## Installation
35 38
 
36 39
 ```sh
37
-go get
38
-go install
40
+go build oragono.go
39 41
 cp oragono.yaml ircd.yaml
40 42
 vim ircd.yaml  # modify the config file to your liking
41 43
 oragono initdb
@@ -53,13 +55,32 @@ See the example [`oragono.yaml`](oragono.yaml). Passwords are stored using bcryp
53 55
 oragono genpasswd
54 56
 ```
55 57
 
56
-## Running the server
58
+## Running
57 59
 
58 60
 ```sh
59 61
 oragono run
60 62
 ```
61 63
 
62
-## Credits
64
+# Web interface
65
+
66
+Oragono also includes a web interface, which works with the REST API to provide a way to manage user accounts and bans.
67
+
68
+## Installation
69
+
70
+```sh
71
+go build oragono-web.go
72
+cp oragono-web.yaml web.yaml
73
+vim web.yaml  # modify the config file to your liking
74
+oragono-web mkcerts
75
+```
76
+
77
+## Running
78
+
79
+```sh
80
+oragono-web run
81
+```
82
+
83
+# Credits
63 84
 
64 85
 * Jeremy Latt, creator of Ergonomadic, <https://github.com/jlatt>
65 86
 * Edmund Huber, maintainer of Ergonomadic, <https://github.com/edmund-huber>

+ 68
- 0
oragono-web.go View File

@@ -0,0 +1,68 @@
1
+// Copyright (c) 2016- Daniel Oaks <daniel@danieloaks.net>
2
+// released under the MIT license
3
+
4
+package main
5
+
6
+import (
7
+	"fmt"
8
+	"log"
9
+
10
+	"github.com/DanielOaks/oragono/irc"
11
+	"github.com/DanielOaks/oragono/mkcerts"
12
+	"github.com/DanielOaks/oragono/web"
13
+	"github.com/docopt/docopt-go"
14
+)
15
+
16
+func main() {
17
+	version := irc.SemVer
18
+	usage := `oragono-web.
19
+Usage:
20
+	oragono-web mkcerts [--conf <filename>] [--quiet]
21
+	oragono-web run [--conf <filename>] [--quiet]
22
+	oragono-web -h | --help
23
+	oragono-web --version
24
+Options:
25
+	--conf <filename>  Configuration file to use [default: web.yaml].
26
+	--quiet            Don't show startup/shutdown lines.
27
+	-h --help          Show this screen.
28
+	--version          Show version.`
29
+
30
+	arguments, _ := docopt.Parse(usage, nil, true, version, false)
31
+
32
+	configfile := arguments["--conf"].(string)
33
+	config, err := web.LoadConfig(configfile)
34
+	if err != nil {
35
+		log.Fatal("Config file did not load successfully:", err.Error())
36
+	}
37
+
38
+	if arguments["mkcerts"].(bool) {
39
+		if !arguments["--quiet"].(bool) {
40
+			log.Println("making self-signed certificates")
41
+		}
42
+
43
+		for name, conf := range config.TLSListenersConf {
44
+			log.Printf(" making cert for %s listener\n", name)
45
+			host := config.Host
46
+			err := mkcerts.CreateCert("Oragono web interface", host, conf.Cert, conf.Key)
47
+			if err == nil {
48
+				if !arguments["--quiet"].(bool) {
49
+					log.Printf("  Certificate created at %s : %s\n", conf.Cert, conf.Key)
50
+				}
51
+			} else {
52
+				log.Fatal("  Could not create certificate:", err.Error())
53
+			}
54
+		}
55
+	} else if arguments["run"].(bool) {
56
+		irc.Log.SetLevel(config.Log)
57
+		server := web.NewServer(config)
58
+		if server == nil {
59
+			log.Println("Could not load server")
60
+			return
61
+		}
62
+		if !arguments["--quiet"].(bool) {
63
+			log.Println(fmt.Sprintf("Oragono web interface v%s running", irc.SemVer))
64
+			defer log.Println(irc.SemVer, "exiting")
65
+		}
66
+		server.Run()
67
+	}
68
+}

+ 17
- 0
oragono-web.yaml View File

@@ -0,0 +1,17 @@
1
+# oragono web interface config
2
+
3
+# hostname of the web interface
4
+hostname: localhost
5
+
6
+# address to listen on
7
+listen: "localhost:8090"
8
+
9
+# tls listeners
10
+tls-listeners:
11
+    # listener on ":6697"
12
+    ":8090":
13
+        key: web-tls.key
14
+        cert: web-tls.crt
15
+
16
+# log level, one of error, warn, info, debug
17
+log: debug

+ 77
- 0
web/config.go View File

@@ -0,0 +1,77 @@
1
+// Copyright (c) 2012-2014 Jeremy Latt
2
+// Copyright (c) 2014-2015 Edmund Huber
3
+// Copyright (c) 2016- Daniel Oaks <daniel@danieloaks.net>
4
+// released under the MIT license
5
+
6
+package web
7
+
8
+import (
9
+	"crypto/tls"
10
+	"errors"
11
+	"io/ioutil"
12
+	"log"
13
+
14
+	"github.com/DanielOaks/oragono/irc"
15
+
16
+	"gopkg.in/yaml.v2"
17
+)
18
+
19
+// TLSListenConfig defines configuration options for listening on TLS
20
+type TLSListenConfig struct {
21
+	Cert string
22
+	Key  string
23
+}
24
+
25
+// Certificate returns the TLS certificate assicated with this TLSListenConfig
26
+func (conf *TLSListenConfig) Config() (*tls.Config, error) {
27
+	cert, err := tls.LoadX509KeyPair(conf.Cert, conf.Key)
28
+	if err != nil {
29
+		return nil, errors.New("tls cert+key: invalid pair")
30
+	}
31
+
32
+	return &tls.Config{
33
+		Certificates: []tls.Certificate{cert},
34
+	}, err
35
+}
36
+
37
+type Config struct {
38
+	Host             string
39
+	Listen           string
40
+	TLSListenersConf map[string]*TLSListenConfig `yaml:"tls-listeners"`
41
+	Log              string
42
+}
43
+
44
+func (conf *Config) TLSListeners() map[string]*tls.Config {
45
+	tlsListeners := make(map[string]*tls.Config)
46
+	for s, tlsListenersConf := range conf.TLSListenersConf {
47
+		config, err := tlsListenersConf.Config()
48
+		if err != nil {
49
+			log.Fatal(err)
50
+		}
51
+		name, err := irc.CasefoldName(s)
52
+		if err == nil {
53
+			tlsListeners[name] = config
54
+		} else {
55
+			log.Println("Could not casefold TLS listener:", err.Error())
56
+		}
57
+	}
58
+	return tlsListeners
59
+}
60
+
61
+func LoadConfig(filename string) (config *Config, err error) {
62
+	data, err := ioutil.ReadFile(filename)
63
+	if err != nil {
64
+		return nil, err
65
+	}
66
+
67
+	err = yaml.Unmarshal(data, &config)
68
+	if err != nil {
69
+		return nil, err
70
+	}
71
+
72
+	if config.Listen == "" {
73
+		return nil, errors.New("Listening address missing")
74
+	}
75
+
76
+	return config, nil
77
+}

+ 21
- 0
web/server.go View File

@@ -0,0 +1,21 @@
1
+// Copyright (c) 2012-2014 Jeremy Latt
2
+// Copyright (c) 2014-2015 Edmund Huber
3
+// Copyright (c) 2016- Daniel Oaks <daniel@danieloaks.net>
4
+// released under the MIT license
5
+
6
+package web
7
+
8
+// Server is the webserver
9
+type Server struct {
10
+}
11
+
12
+// NewServer returns a new Oragono server.
13
+func NewServer(config *Config) *Server {
14
+	server := &Server{}
15
+
16
+	return server
17
+}
18
+
19
+func (*Server) Run() {
20
+
21
+}

Loading…
Cancel
Save