1
1
Fork 0
mirror of https://git.sr.ht/~emersion/tlstunnel synced 2024-04-19 07:53:48 +02:00

Initial commit

This commit is contained in:
Simon Ser 2020-09-08 12:11:32 +02:00
commit 21eed45822
No known key found for this signature in database
GPG Key ID: 0FDE7BE0E88F5E48
6 changed files with 118 additions and 0 deletions

21
LICENSE Normal file
View File

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2020 Simon Ser
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

7
README.md Normal file
View File

@ -0,0 +1,7 @@
# tlstunnel
A TLS reverse proxy.
## License
MIT

70
config.go Normal file
View File

@ -0,0 +1,70 @@
package main
import (
"os"
"io"
"bufio"
"fmt"
"github.com/google/shlex"
)
type Directive struct {
Params []string
Children []*Directive
}
func Load(path string) ([]*Directive, error) {
f, err := os.Open(path)
if err != nil {
return nil, err
}
defer f.Close()
return Parse(f)
}
func Parse(r io.Reader) ([]*Directive, error) {
scanner := bufio.NewScanner(r)
var directives []*Directive
var cur *Directive
for scanner.Scan() {
l := scanner.Text()
words, err := shlex.Split(l)
if err != nil {
return directives, fmt.Errorf("failed to parse config file: %v", err)
} else if len(words) == 0 {
continue
}
if len(words) == 1 && l[len(l) - 1] == '}' {
if cur == nil {
return nil, fmt.Errorf("unexpected '}'")
}
cur = nil
continue
}
var d *Directive
if words[len(words) - 1] == "{" && l[len(l) - 1] == '{' {
d = &Directive{
Params: words[:len(words) - 1],
}
cur = d
directives = append(directives, d)
} else {
d = &Directive{Params: words}
if cur != nil {
cur.Children = append(cur.Children, d)
} else {
directives = append(directives, d)
}
}
}
if err := scanner.Err(); err != nil {
return nil, fmt.Errorf("failed to read config file: %v", err)
}
return directives, nil
}

5
go.mod Normal file
View File

@ -0,0 +1,5 @@
module git.sr.ht/~emersion/tlstunnel
go 1.15
require github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510

2
go.sum Normal file
View File

@ -0,0 +1,2 @@
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 h1:El6M4kTTCOh6aBiKaUGG7oYTSPP8MxqL4YI3kZKwcP4=
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510/go.mod h1:pupxD2MaaD3pAXIBCelhxNneeOaAeabZDe5s4K6zSpQ=

13
main.go Normal file
View File

@ -0,0 +1,13 @@
package main
import (
"log"
)
func main() {
directives, err := Load("config")
if err != nil {
log.Fatalf("failed to load config file: %v", err)
}
_ = directives
}