Browse Source

Rip out REST API and web interface.

It's not really used and I'd rather not have it here unless I'm able to actively maintain it properly and build out the web interface.

I might re-add it later but for now I'd rather not have it unless anyone's actively using it.
tags/v0.9.2-beta
Daniel Oaks 6 years ago
parent
commit
f7f049973f
9 changed files with 2 additions and 401 deletions
  1. 1
    23
      README.md
  2. 0
    15
      docs/INFO.md
  3. 1
    8
      irc/config.go
  4. 0
    200
      irc/rest_api.go
  5. 0
    39
      irc/server.go
  6. 0
    17
      oragono-web.yaml
  7. 0
    8
      oragono.yaml
  8. 0
    70
      web/config.go
  9. 0
    21
      web/server.go

+ 1
- 23
README.md View File

@@ -19,7 +19,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). For the purpo
19 19
 
20 20
 ## Features
21 21
 
22
-* UTF-8 nick and channel names with rfc7613
22
+* UTF-8 nick and channel names with rfc7613 (PRECIS)
23 23
 * [yaml](http://yaml.org/) configuration
24 24
 * native TLS/SSL support
25 25
 * server password (`PASS` command)
@@ -32,7 +32,6 @@ This project adheres to [Semantic Versioning](http://semver.org/). For the purpo
32 32
 * banning ips/nets and masks with `KLINE` and `DLINE`
33 33
 * [IRCv3 support](http://ircv3.net/software/servers.html)
34 34
 * a heavy focus on developing with [specifications](http://oragono.io/specs.html)
35
-* integrated (alpha) REST API and web interface
36 35
 
37 36
 ## Installation
38 37
 
@@ -131,27 +130,6 @@ After this, your channel will remember the fact that you're the owner, the topic
131 130
 Make sure to setup [SASL](https://freenode.net/kb/answer/sasl) in your client to automatically login to your account when you next join the server.
132 131
 
133 132
 
134
-<!--# Web interface
135
-
136
-Oragono also includes a web interface, which works with the REST API to provide a way to manage user accounts and bans.
137
-
138
-This interface is an early alpha, is in no way secure and will not be in a final release for a while. Requires the alpha REST API to be enabled (check your server config to enable that if you really want to).
139
-
140
-## Installation
141
-
142
-```sh
143
-go build oragono-web.go
144
-cp oragono-web.yaml web.yaml
145
-vim web.yaml  # modify the config file to your liking
146
-oragono-web mkcerts
147
-```
148
-
149
-## Running
150
-
151
-```sh
152
-oragono-web run
153
-```-->
154
-
155 133
 # Credits
156 134
 
157 135
 * Jeremy Latt, creator of Ergonomadic, <https://github.com/jlatt>

+ 0
- 15
docs/INFO.md View File

@@ -72,21 +72,6 @@ This will make the server rehash its configuration files and TLS certificates, a
72 72
 useful if you're automatically updating your TLS certs!
73 73
 
74 74
 
75
-## REST API
76
-
77
-Oragono contains a draft, very early REST API implementation. My plans for this is to allow
78
-external web interfaces or other automated programs to monitor what's going on with the
79
-server, apply/remove bans, and to essentially allow administration of the server without
80
-being connected to it and opered-up. This sort of API mimics InspIRCd and Anope, which
81
-contain similar APIs.
82
-
83
-I'm not sure exactly how it's going to continue to be developed, and I'm sure there'll be
84
-lots of changes around appropriately restricting access to the API, which is why it's
85
-disabled for now and not exposed in our Docker builds. As well, while it's very unstable,
86
-the REST API doesn't count for our SemVer versioning. When this feature is more developed
87
-and I'm happy with where it's at, I'll provide proper support and documentation for the API.
88
-
89
-
90 75
 ## Rejected Features
91 76
 
92 77
 'Rejected' sounds harsh, but basically these are features I've decided I'm not gonna

+ 1
- 8
irc/config.go View File

@@ -108,12 +108,6 @@ func (conf *OperConfig) PasswordBytes() []byte {
108 108
 	return bytes
109 109
 }
110 110
 
111
-// RestAPIConfig controls the integrated REST API.
112
-type RestAPIConfig struct {
113
-	Enabled bool
114
-	Listen  string
115
-}
116
-
117 111
 // ConnectionLimitsConfig controls the automated connection limits.
118 112
 type ConnectionLimitsConfig struct {
119 113
 	Enabled     bool
@@ -198,8 +192,7 @@ type Config struct {
198 192
 		Listen             []string
199 193
 		TLSListeners       map[string]*TLSListenConfig `yaml:"tls-listeners"`
200 194
 		STS                STSConfig
201
-		RestAPI            RestAPIConfig `yaml:"rest-api"`
202
-		CheckIdent         bool          `yaml:"check-ident"`
195
+		CheckIdent         bool `yaml:"check-ident"`
203 196
 		MOTD               string
204 197
 		ProxyAllowedFrom   []string `yaml:"proxy-allowed-from"`
205 198
 		MaxSendQString     string   `yaml:"max-sendq"`

+ 0
- 200
irc/rest_api.go View File

@@ -1,200 +0,0 @@
1
-// Copyright (c) 2016-2017 Daniel Oaks <daniel@danieloaks.net>
2
-// released under the MIT license
3
-
4
-// viewing and modifying accounts, registered channels, dlines, rehashing, etc
5
-
6
-package irc
7
-
8
-import (
9
-	"encoding/json"
10
-	"net/http"
11
-	"strconv"
12
-	"time"
13
-
14
-	"fmt"
15
-
16
-	"github.com/gorilla/mux"
17
-	"github.com/tidwall/buntdb"
18
-)
19
-
20
-const restErr = "{\"error\":\"An unknown error occurred\"}"
21
-
22
-// ircServer is used to keep a link to the current running server since this is the best
23
-// way to do it, given how HTTP handlers dispatch and work.
24
-var ircServer *Server
25
-
26
-type restInfoResp struct {
27
-	ServerName  string `json:"server-name"`
28
-	NetworkName string `json:"network-name"`
29
-
30
-	Version string `json:"version"`
31
-}
32
-
33
-type restStatusResp struct {
34
-	Clients  int `json:"clients"`
35
-	Opers    int `json:"opers"`
36
-	Channels int `json:"channels"`
37
-}
38
-
39
-type restXLinesResp struct {
40
-	DLines map[string]IPBanInfo `json:"dlines"`
41
-	KLines map[string]IPBanInfo `json:"klines"`
42
-}
43
-
44
-type restAcct struct {
45
-	Name         string    `json:"name"`
46
-	RegisteredAt time.Time `json:"registered-at"`
47
-	Clients      int       `json:"clients"`
48
-}
49
-
50
-type restAccountsResp struct {
51
-	Verified map[string]restAcct `json:"verified"`
52
-}
53
-
54
-type restRehashResp struct {
55
-	Successful bool      `json:"successful"`
56
-	Error      string    `json:"error"`
57
-	Time       time.Time `json:"time"`
58
-}
59
-
60
-func restInfo(w http.ResponseWriter, r *http.Request) {
61
-	rs := restInfoResp{
62
-		Version:     SemVer,
63
-		ServerName:  ircServer.name,
64
-		NetworkName: ircServer.networkName,
65
-	}
66
-	b, err := json.Marshal(rs)
67
-	if err != nil {
68
-		fmt.Fprintln(w, restErr)
69
-	} else {
70
-		fmt.Fprintln(w, string(b))
71
-	}
72
-}
73
-
74
-func restStatus(w http.ResponseWriter, r *http.Request) {
75
-	rs := restStatusResp{
76
-		Clients:  ircServer.clients.Count(),
77
-		Opers:    len(ircServer.operators),
78
-		Channels: ircServer.channels.Len(),
79
-	}
80
-	b, err := json.Marshal(rs)
81
-	if err != nil {
82
-		fmt.Fprintln(w, restErr)
83
-	} else {
84
-		fmt.Fprintln(w, string(b))
85
-	}
86
-}
87
-
88
-func restGetXLines(w http.ResponseWriter, r *http.Request) {
89
-	rs := restXLinesResp{
90
-		DLines: ircServer.dlines.AllBans(),
91
-		KLines: ircServer.klines.AllBans(),
92
-	}
93
-	b, err := json.Marshal(rs)
94
-	if err != nil {
95
-		fmt.Fprintln(w, restErr)
96
-	} else {
97
-		fmt.Fprintln(w, string(b))
98
-	}
99
-}
100
-
101
-func restGetAccounts(w http.ResponseWriter, r *http.Request) {
102
-	rs := restAccountsResp{
103
-		Verified: make(map[string]restAcct),
104
-	}
105
-
106
-	// get accounts
107
-	err := ircServer.store.View(func(tx *buntdb.Tx) error {
108
-		tx.AscendKeys("account.exists *", func(key, value string) bool {
109
-			key = key[len("account.exists "):]
110
-			_, err := tx.Get(fmt.Sprintf(keyAccountVerified, key))
111
-			verified := err == nil
112
-			fmt.Println(fmt.Sprintf(keyAccountVerified, key))
113
-
114
-			// get other details
115
-			name, _ := tx.Get(fmt.Sprintf(keyAccountName, key))
116
-			regTimeStr, _ := tx.Get(fmt.Sprintf(keyAccountRegTime, key))
117
-			regTimeInt, _ := strconv.ParseInt(regTimeStr, 10, 64)
118
-			regTime := time.Unix(regTimeInt, 0)
119
-
120
-			var clients int
121
-			acct := ircServer.accounts[key]
122
-			if acct != nil {
123
-				clients = len(acct.Clients)
124
-			}
125
-
126
-			if verified {
127
-				rs.Verified[key] = restAcct{
128
-					Name:         name,
129
-					RegisteredAt: regTime,
130
-					Clients:      clients,
131
-				}
132
-			} else {
133
-				//TODO(dan): Add to unverified list
134
-			}
135
-
136
-			return true // true to continue I guess?
137
-		})
138
-
139
-		return nil
140
-	})
141
-
142
-	b, err := json.Marshal(rs)
143
-	if err != nil {
144
-		fmt.Fprintln(w, restErr)
145
-	} else {
146
-		fmt.Fprintln(w, string(b))
147
-	}
148
-}
149
-
150
-func restRehash(w http.ResponseWriter, r *http.Request) {
151
-	err := ircServer.rehash()
152
-
153
-	rs := restRehashResp{
154
-		Successful: err == nil,
155
-		Time:       time.Now(),
156
-	}
157
-	if err != nil {
158
-		rs.Error = err.Error()
159
-	}
160
-
161
-	b, err := json.Marshal(rs)
162
-	if err != nil {
163
-		fmt.Fprintln(w, restErr)
164
-	} else {
165
-		fmt.Fprintln(w, string(b))
166
-	}
167
-}
168
-
169
-func StartRestAPI(s *Server, listenAddr string) (*http.Server, error) {
170
-	// so handlers can ref it later
171
-	ircServer = s
172
-
173
-	// start router
174
-	r := mux.NewRouter()
175
-
176
-	// GET methods
177
-	rg := r.Methods("GET").Subrouter()
178
-	rg.HandleFunc("/info", restInfo)
179
-	rg.HandleFunc("/status", restStatus)
180
-	rg.HandleFunc("/xlines", restGetXLines)
181
-	rg.HandleFunc("/accounts", restGetAccounts)
182
-
183
-	// PUT methods
184
-	rp := r.Methods("POST").Subrouter()
185
-	rp.HandleFunc("/rehash", restRehash)
186
-
187
-	// start api
188
-	httpserver := http.Server{
189
-		Addr:    listenAddr,
190
-		Handler: r,
191
-	}
192
-
193
-	go func() {
194
-		if err := httpserver.ListenAndServe(); err != nil {
195
-			s.logger.Error("listeners", fmt.Sprintf("Rest API listenAndServe error: %s", err))
196
-		}
197
-	}()
198
-
199
-	return &httpserver, nil
200
-}

+ 0
- 39
irc/server.go View File

@@ -7,14 +7,12 @@ package irc
7 7
 
8 8
 import (
9 9
 	"bufio"
10
-	"context"
11 10
 	"crypto/tls"
12 11
 	"encoding/base64"
13 12
 	"fmt"
14 13
 	"log"
15 14
 	"math/rand"
16 15
 	"net"
17
-	"net/http"
18 16
 	"os"
19 17
 	"os/signal"
20 18
 	"strconv"
@@ -39,14 +37,6 @@ var (
39 37
 	couldNotParseIPMsg, _ = (&[]ircmsg.IrcMessage{ircmsg.MakeMessage(nil, "", "ERROR", "Unable to parse your IP address")}[0]).Line()
40 38
 )
41 39
 
42
-const (
43
-	// when shutting down the REST server, wait this long
44
-	// before killing active connections. TODO: this might not be
45
-	// necessary at all? but it seems prudent to avoid potential resource
46
-	// leaks
47
-	httpShutdownTimeout = time.Second
48
-)
49
-
50 40
 // Limits holds the maximum limits for various things such as topic lengths.
51 41
 type Limits struct {
52 42
 	AwayLen        int
@@ -116,8 +106,6 @@ type Server struct {
116 106
 	registeredChannelsMutex      sync.RWMutex
117 107
 	rehashMutex                  sync.Mutex
118 108
 	rehashSignal                 chan os.Signal
119
-	restAPI                      RestAPIConfig
120
-	restAPIServer                *http.Server
121 109
 	proxyAllowedFrom             []string
122 110
 	signals                      chan os.Signal
123 111
 	snomasks                     *SnoManager
@@ -1445,7 +1433,6 @@ func (server *Server) applyConfig(config *Config, initial bool) error {
1445 1433
 
1446 1434
 	// we are now open for business
1447 1435
 	server.setupListeners(config)
1448
-	server.setupRestAPI(config)
1449 1436
 
1450 1437
 	return nil
1451 1438
 }
@@ -1583,32 +1570,6 @@ func (server *Server) setupListeners(config *Config) {
1583 1570
 	}
1584 1571
 }
1585 1572
 
1586
-func (server *Server) setupRestAPI(config *Config) {
1587
-	restAPIEnabled := config.Server.RestAPI.Enabled
1588
-	restAPIStarted := server.restAPIServer != nil
1589
-	restAPIListenAddrChanged := server.restAPI.Listen != config.Server.RestAPI.Listen
1590
-
1591
-	// stop an existing REST server if it's been disabled or the addr changed
1592
-	if restAPIStarted && (!restAPIEnabled || restAPIListenAddrChanged) {
1593
-		ctx, _ := context.WithTimeout(context.Background(), httpShutdownTimeout)
1594
-		server.restAPIServer.Shutdown(ctx)
1595
-		server.restAPIServer.Close()
1596
-		server.logger.Info("rehash", "server", fmt.Sprintf("%s rest API stopped on %s.", server.name, server.restAPI.Listen))
1597
-		server.restAPIServer = nil
1598
-	}
1599
-
1600
-	// start a new one if it's enabled or the addr changed
1601
-	if restAPIEnabled && (!restAPIStarted || restAPIListenAddrChanged) {
1602
-		server.restAPIServer, _ = StartRestAPI(server, config.Server.RestAPI.Listen)
1603
-		server.logger.Info(
1604
-			"rehash", "server",
1605
-			fmt.Sprintf("%s rest API started on %s.", server.name, config.Server.RestAPI.Listen))
1606
-	}
1607
-
1608
-	// save the config information
1609
-	server.restAPI = config.Server.RestAPI
1610
-}
1611
-
1612 1573
 func (server *Server) GetDefaultChannelModes() Modes {
1613 1574
 	server.configurableStateMutex.RLock()
1614 1575
 	defer server.configurableStateMutex.RUnlock()

+ 0
- 17
oragono-web.yaml View File

@@ -1,17 +0,0 @@
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

+ 0
- 8
oragono.yaml View File

@@ -43,14 +43,6 @@ server:
43 43
         # should clients include this STS policy when they ship their inbuilt preload lists?
44 44
         preload: false
45 45
 
46
-    # rest management API, for use with web interface
47
-    rest-api:
48
-        # whether the API is enabled or not
49
-        enabled: false
50
-
51
-        # rest API listening port
52
-        listen: "localhost:8090"
53
-
54 46
     # use ident protocol to get usernames
55 47
     check-ident: true
56 48
 

+ 0
- 70
web/config.go View File

@@ -1,70 +0,0 @@
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
-	"gopkg.in/yaml.v2"
15
-)
16
-
17
-// TLSListenConfig defines configuration options for listening on TLS
18
-type TLSListenConfig struct {
19
-	Cert string
20
-	Key  string
21
-}
22
-
23
-// Certificate returns the TLS certificate assicated with this TLSListenConfig
24
-func (conf *TLSListenConfig) Config() (*tls.Config, error) {
25
-	cert, err := tls.LoadX509KeyPair(conf.Cert, conf.Key)
26
-	if err != nil {
27
-		return nil, errors.New("tls cert+key: invalid pair")
28
-	}
29
-
30
-	return &tls.Config{
31
-		Certificates: []tls.Certificate{cert},
32
-	}, err
33
-}
34
-
35
-type Config struct {
36
-	Host             string
37
-	Listen           string
38
-	TLSListenersConf map[string]*TLSListenConfig `yaml:"tls-listeners"`
39
-	Log              string
40
-}
41
-
42
-func (conf *Config) TLSListeners() map[string]*tls.Config {
43
-	tlsListeners := make(map[string]*tls.Config)
44
-	for s, tlsListenersConf := range conf.TLSListenersConf {
45
-		config, err := tlsListenersConf.Config()
46
-		if err != nil {
47
-			log.Fatal(err)
48
-		}
49
-		tlsListeners[name] = config
50
-	}
51
-	return tlsListeners
52
-}
53
-
54
-func LoadConfig(filename string) (config *Config, err error) {
55
-	data, err := ioutil.ReadFile(filename)
56
-	if err != nil {
57
-		return nil, err
58
-	}
59
-
60
-	err = yaml.Unmarshal(data, &config)
61
-	if err != nil {
62
-		return nil, err
63
-	}
64
-
65
-	if config.Listen == "" {
66
-		return nil, errors.New("Listening address missing")
67
-	}
68
-
69
-	return config, nil
70
-}

+ 0
- 21
web/server.go View File

@@ -1,21 +0,0 @@
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