Skip to content
This repository has been archived by the owner on Aug 27, 2020. It is now read-only.

Commit

Permalink
basic webui
Browse files Browse the repository at this point in the history
  • Loading branch information
lzjluzijie committed Jul 7, 2018
1 parent 1516534 commit 251e1c9
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 25 deletions.
9 changes: 1 addition & 8 deletions core/client/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,7 @@ import (
)

//GetClient return client from path
func GetClientConfig(data []byte) (client *WebSocksClient, err error) {
//read config
config := &WebSocksClientConfig{}
err = json.Unmarshal(data, config)
if err != nil {
return
}

func GetClient(config *WebSocksClientConfig) (client *WebSocksClient, err error) {
//tackle config
serverURL, err := url.Parse(config.ServerURL)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions templates/base/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>WebSocks</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/css/bulma.min.css" integrity="sha256-zIG416V1ynj3Wgju/scU80KAEWOsO5rRLfVyRDuOv7Q=" crossorigin="anonymous">
{% block head %} {% endblock %}
</head>
<body>
{% block body %} {% endblock %}
Expand Down
77 changes: 62 additions & 15 deletions templates/client.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,29 @@
{% extends "base/base.html" %} {% block body %}
{% extends "base/base.html" %}
{% block head %}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bulma-switch.min.css"
integrity="sha256-jCV/cXwP13w0GNHLgFx6SFgTNAvJPvS5MIhuE30Ng08=" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/axios.min.js"
integrity="sha256-mpnrJ5DpEZZkwkE1ZgkEQQJW/46CSEh/STrZKOB/qoM=" crossorigin="anonymous"></script>
<script>
function Run() {
let params = new URLSearchParams();
params.append("ListenAddr", document.getElementById("ListenAddr").value);
params.append("ServerURL", document.getElementById("ServerURL").value);
params.append("SNI", document.getElementById("SNI").value);
params.append("InsecureCert", document.getElementById("InsecureCert").value);
//todo bool
console.log(document.getElementById("InsecureCert").checked);
axios.post('/api/client', params)
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
});
}
</script>
{% endblock %}
{% block body %}
<section class="section">
<div class="container">
<h1 class="title">
Expand All @@ -8,23 +33,45 @@ <h1 class="title">
A secure proxy based on websocket.
</p>

<form action="/api/client" method="post">
<div class="field">
<label class="label">Server URL</label>
<div class="control">
<input class="input" type="text" placeholder="wss://server.com:2333/password">
</div>
</div>
</section>

<section>
<div class="container">
<div class="field">
<label class="label">ListenAddr</label>
<div class="control">
<input class="input" type="text" id="ListenAddr" name="ListenAddr" placeholder=":10801">
</div>
</div>

<div class="field">
<label class="label">ServerURL</label>
<div class="control">
<input class="input" type="text" id="ServerURL" name="ServerURL"
placeholder="wss://server.com:2333/password">
</div>
</div>

<div class="field">
<label class="label">SNI</label>
<div class="control">
<input class="input" type="text" id="SNI" name="SNI" placeholder="mirror.centos.org">
</div>
</div>

<div class="field">
<p class="control">
<button class="button">
Start
</button>
</p>
</div>
<div class="field">
<div class="control">
<input type="checkbox" id="InsecureCert" name="InsecureCert" class="switch" checked="checked">
<label for="InsecureCert">InsecureCert</label>
</div>
</form>
</div>

<div class="field">
<p class="control">
<button class="button" onclick="Run()">Start</button>
</p>
</div>
</div>
</section>
{% endblock %}
3 changes: 2 additions & 1 deletion templates/home.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{% extends "base/base.html" %} {% block body %}
{% extends "base/base.html" %}
{% block body %}
<section class="section">
<div class="container">
<h1 class="title">
Expand Down
47 changes: 46 additions & 1 deletion websocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ import (

"net/http"

"encoding/json"
"fmt"
"log"

"github.com/go-macaron/pongo2"
"github.com/juju/loggo"
"github.com/lzjluzijie/websocks/config"
Expand Down Expand Up @@ -62,7 +66,13 @@ func main() {
return
}

webSocksClient, err := client.GetClientConfig(data)
clientConfig := &client.WebSocksClientConfig{}
err = json.Unmarshal(data, clientConfig)
if err != nil {
return
}

webSocksClient, err := client.GetClient(clientConfig)
if err != nil {
return
}
Expand Down Expand Up @@ -178,6 +188,41 @@ func main() {
return
})

m.Post("/api/client", func(ctx *macaron.Context) {
listenAddr := ctx.Query("ListenAddr")
serverURL := ctx.Query("ServerURL")
sni := ctx.Query("SNI")
insecureCertS := ctx.Query("InsecureCert")
insecureCert := false
if insecureCertS == "on" {
insecureCert = true
}

webSocksClientConfig := &client.WebSocksClientConfig{
ListenAddr: listenAddr,
ServerURL: serverURL,
SNI: sni,
InsecureCert: insecureCert,
}

websocksClient, err := client.GetClient(webSocksClientConfig)
if err != nil {
ctx.Error(403, err.Error())
}

ctx.WriteHeader(200)
ctx.Write([]byte(fmt.Sprintf("%v", webSocksClientConfig)))

go func() {
websocksClient.LogLevel = loggo.DEBUG
err = websocksClient.Listen()
if err != nil {
log.Println(err.Error())
}
}()
return
})

//todo pac
m.Get("/pac", func(ctx *macaron.Context) {
return
Expand Down

0 comments on commit 251e1c9

Please sign in to comment.