mirror of https://github.com/velour/catbase.git
Compare commits
2 Commits
7ba9d94ac2
...
13e16c9f01
Author | SHA1 | Date |
---|---|---|
Chris Sexton | 13e16c9f01 | |
Chris Sexton | 59a7815bc0 |
|
@ -7,10 +7,10 @@ jobs:
|
|||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
|
||||
- name: Set up Go 1.13
|
||||
- name: Set up Go 1.16
|
||||
uses: actions/setup-go@v1
|
||||
with:
|
||||
go-version: 1.13.x
|
||||
go-version: 1.16.x
|
||||
id: go
|
||||
|
||||
- name: Check out code into the Go module directory
|
||||
|
|
|
@ -0,0 +1,47 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<!-- Load required Bootstrap and BootstrapVue CSS -->
|
||||
<link type="text/css" rel="stylesheet" href="//unpkg.com/bootstrap/dist/css/bootstrap.min.css" />
|
||||
<link type="text/css" rel="stylesheet" href="//unpkg.com/bootstrap-vue@latest/dist/bootstrap-vue.min.css" />
|
||||
|
||||
<!-- Load polyfills to support older browsers -->
|
||||
<script src="//polyfill.io/v3/polyfill.min.js?features=es2015%2CMutationObserver"></script>
|
||||
|
||||
<!-- Load Vue followed by BootstrapVue -->
|
||||
<script src="//unpkg.com/vue@latest/dist/vue.min.js"></script>
|
||||
<script src="//unpkg.com/bootstrap-vue@latest/dist/bootstrap-vue.min.js"></script>
|
||||
<script src="https://unpkg.com/vue-router"></script>
|
||||
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
|
||||
<meta charset="UTF-8">
|
||||
<title>catbase</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div id="app">
|
||||
<b-navbar>
|
||||
<b-navbar-brand>catbase</b-navbar-brand>
|
||||
<b-navbar-nav>
|
||||
<b-nav-item v-for="item in nav" :href="item.url">{{ item.name }}</b-nav-item>
|
||||
</b-navbar-nav>
|
||||
</b-navbar>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
var app = new Vue({
|
||||
el: '#app',
|
||||
data: {
|
||||
err: '',
|
||||
nav: [],
|
||||
},
|
||||
mounted: function() {
|
||||
axios.get('/nav')
|
||||
.then(resp => {
|
||||
this.nav = resp.data;
|
||||
})
|
||||
.catch(err => console.log(err))
|
||||
}
|
||||
})
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
58
bot/web.go
58
bot/web.go
|
@ -1,14 +1,18 @@
|
|||
package bot
|
||||
|
||||
import (
|
||||
"embed"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
//go:embed *.html
|
||||
var embeddedFS embed.FS
|
||||
|
||||
func (b *bot) serveRoot(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Fprint(w, rootIndex)
|
||||
index, _ := embeddedFS.ReadFile("index.html")
|
||||
w.Write(index)
|
||||
}
|
||||
|
||||
func (b *bot) serveNav(w http.ResponseWriter, r *http.Request) {
|
||||
|
@ -36,53 +40,3 @@ func (b *bot) GetWebNavigation() []EndPoint {
|
|||
}
|
||||
return endpoints
|
||||
}
|
||||
|
||||
var rootIndex = `
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<!-- Load required Bootstrap and BootstrapVue CSS -->
|
||||
<link type="text/css" rel="stylesheet" href="//unpkg.com/bootstrap/dist/css/bootstrap.min.css" />
|
||||
<link type="text/css" rel="stylesheet" href="//unpkg.com/bootstrap-vue@latest/dist/bootstrap-vue.min.css" />
|
||||
|
||||
<!-- Load polyfills to support older browsers -->
|
||||
<script src="//polyfill.io/v3/polyfill.min.js?features=es2015%2CMutationObserver"></script>
|
||||
|
||||
<!-- Load Vue followed by BootstrapVue -->
|
||||
<script src="//unpkg.com/vue@latest/dist/vue.min.js"></script>
|
||||
<script src="//unpkg.com/bootstrap-vue@latest/dist/bootstrap-vue.min.js"></script>
|
||||
<script src="https://unpkg.com/vue-router"></script>
|
||||
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
|
||||
<meta charset="UTF-8">
|
||||
<title>catbase</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div id="app">
|
||||
<b-navbar>
|
||||
<b-navbar-brand>catbase</b-navbar-brand>
|
||||
<b-navbar-nav>
|
||||
<b-nav-item v-for="item in nav" :href="item.url">{{ item.name }}</b-nav-item>
|
||||
</b-navbar-nav>
|
||||
</b-navbar>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
var app = new Vue({
|
||||
el: '#app',
|
||||
data: {
|
||||
err: '',
|
||||
nav: [],
|
||||
},
|
||||
mounted: function() {
|
||||
axios.get('/nav')
|
||||
.then(resp => {
|
||||
this.nav = resp.data;
|
||||
})
|
||||
.catch(err => console.log(err))
|
||||
}
|
||||
})
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
`
|
||||
|
|
2
go.mod
2
go.mod
|
@ -1,6 +1,6 @@
|
|||
module github.com/velour/catbase
|
||||
|
||||
go 1.13
|
||||
go 1.16
|
||||
|
||||
require (
|
||||
code.chrissexton.org/cws/getaoc v0.0.0-20191201043947-d5417d4b618d
|
||||
|
|
|
@ -0,0 +1,160 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<!-- Load required Bootstrap and BootstrapVue CSS -->
|
||||
<link type="text/css" rel="stylesheet" href="//unpkg.com/bootstrap/dist/css/bootstrap.min.css"/>
|
||||
<link type="text/css" rel="stylesheet" href="//unpkg.com/bootstrap-vue@latest/dist/bootstrap-vue.min.css"/>
|
||||
|
||||
<!-- Load polyfills to support older browsers -->
|
||||
<script src="//polyfill.io/v3/polyfill.min.js?features=es2015%2CMutationObserver"></script>
|
||||
|
||||
<!-- Load Vue followed by BootstrapVue -->
|
||||
<script src="//unpkg.com/vue@latest/dist/vue.min.js"></script>
|
||||
<script src="//unpkg.com/bootstrap-vue@latest/dist/bootstrap-vue.min.js"></script>
|
||||
<script src="//unpkg.com/axios/dist/axios.min.js"></script>
|
||||
<meta charset="UTF-8">
|
||||
<title>Vars</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div id="app">
|
||||
<b-navbar>
|
||||
<b-navbar-brand>App Pass</b-navbar-brand>
|
||||
<b-navbar-nav>
|
||||
<b-nav-item v-for="item in nav" :href="item.url" :active="item.name === 'App Pass'">{{ item.name }}
|
||||
</b-nav-item>
|
||||
</b-navbar-nav>
|
||||
</b-navbar>
|
||||
<div class="alert alert-warning alert-dismissible fade show" role="alert" v-if="err != ''">
|
||||
<b-button type="link" class="close" data-dismiss="alert" aria-label="Close" @click="err = ''">
|
||||
<span aria-hidden="true">×</span>
|
||||
</b-button>
|
||||
{{ err }}
|
||||
</div>
|
||||
<b-form>
|
||||
<b-container>
|
||||
<b-row>
|
||||
<b-col cols="5">Password:</b-col>
|
||||
<b-col>
|
||||
<b-input v-model="password"/>
|
||||
</b-col>
|
||||
</b-row>
|
||||
<b-row>
|
||||
<b-col cols="5">Secret:</b-col>
|
||||
<b-col>
|
||||
<b-input v-model="entry.secret"/>
|
||||
</b-col>
|
||||
</b-row>
|
||||
<b-row>
|
||||
<b-col>
|
||||
<b-button @click="list">List</b-button>
|
||||
</b-col>
|
||||
<b-col>
|
||||
<b-button @click="newPass">New</b-button>
|
||||
</b-col>
|
||||
</b-row>
|
||||
</b-container>
|
||||
</b-form>
|
||||
<b-container v-show="showPassword" style="padding: 2em">
|
||||
<b-row align-h="center">
|
||||
<b-col align-self="center" cols="1">ID:</b-col>
|
||||
<b-col align-self="center" cols="3">{{ entry.id }}</b-col>
|
||||
</b-row>
|
||||
<b-row align-h="center">
|
||||
<b-col align-self="center" cols="1">Password:</b-col>
|
||||
<b-col align-self="center" cols="3">{{ entry.secret }}:{{ showPassword }}</b-col>
|
||||
</b-row>
|
||||
<b-row align-h="center">
|
||||
<b-col align-self="center" class="text-center" cols="6">Note: this password will only be displayed once. For
|
||||
single-field entry passwords, use the secret:password format.
|
||||
</b-col>
|
||||
</b-row>
|
||||
</b-container>
|
||||
<b-container>
|
||||
<b-row style="padding-top: 2em;">
|
||||
<b-col>
|
||||
<ul>
|
||||
<li v-for="entry in entries" key="id">
|
||||
<a @click="rm(entry)" href="#">X</a> {{entry.id}}
|
||||
</li>
|
||||
</ul>
|
||||
</b-col>
|
||||
</b-row>
|
||||
</b-container>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
var app = new Vue({
|
||||
el: '#app',
|
||||
data: {
|
||||
err: '',
|
||||
entry: {
|
||||
secret: '',
|
||||
},
|
||||
password: '',
|
||||
showPassword: '',
|
||||
nav: [],
|
||||
entries: [],
|
||||
},
|
||||
mounted() {
|
||||
axios.get('/nav')
|
||||
.then(resp => {
|
||||
this.nav = resp.data;
|
||||
})
|
||||
.catch(err => console.log(err))
|
||||
},
|
||||
methods: {
|
||||
rm: function (data) {
|
||||
this.showPassword = '';
|
||||
this.entry.id = data.id
|
||||
axios.delete('/apppass/api', {
|
||||
data: {
|
||||
password: this.password,
|
||||
passEntry: this.entry
|
||||
}
|
||||
})
|
||||
.then(() => {
|
||||
this.getData()
|
||||
})
|
||||
.catch(({response}) => {
|
||||
console.log('error: ' + response.data.err)
|
||||
this.err = response.data.err
|
||||
})
|
||||
},
|
||||
list: function () {
|
||||
this.showPassword = '';
|
||||
this.getData();
|
||||
},
|
||||
newPass: function () {
|
||||
axios.put('/apppass/api', {
|
||||
password: this.password,
|
||||
passEntry: this.entry
|
||||
})
|
||||
.then(resp => {
|
||||
this.getData()
|
||||
this.showPassword = resp.data.pass
|
||||
this.entry.id = resp.data.id
|
||||
})
|
||||
.catch(({response}) => {
|
||||
console.log('error: ' + response.data.err)
|
||||
this.err = response.data.err
|
||||
})
|
||||
},
|
||||
getData: function () {
|
||||
axios.post('/apppass/api', {
|
||||
password: this.password,
|
||||
passEntry: this.entry
|
||||
})
|
||||
.then(resp => {
|
||||
this.entries = resp.data;
|
||||
})
|
||||
.catch(({response}) => {
|
||||
console.log('error: ' + response.data.err)
|
||||
this.err = response.data.err
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -1,241 +0,0 @@
|
|||
package admin
|
||||
|
||||
var varIndex = `
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<!-- Load required Bootstrap and BootstrapVue CSS -->
|
||||
<link type="text/css" rel="stylesheet" href="//unpkg.com/bootstrap/dist/css/bootstrap.min.css" />
|
||||
<link type="text/css" rel="stylesheet" href="//unpkg.com/bootstrap-vue@latest/dist/bootstrap-vue.min.css" />
|
||||
|
||||
<!-- Load polyfills to support older browsers -->
|
||||
<script src="//polyfill.io/v3/polyfill.min.js?features=es2015%2CMutationObserver"></script>
|
||||
|
||||
<!-- Load Vue followed by BootstrapVue -->
|
||||
<script src="//unpkg.com/vue@latest/dist/vue.min.js"></script>
|
||||
<script src="//unpkg.com/bootstrap-vue@latest/dist/bootstrap-vue.min.js"></script>
|
||||
<script src="//unpkg.com/axios/dist/axios.min.js"></script>
|
||||
<meta charset="UTF-8">
|
||||
<title>Vars</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div id="app">
|
||||
<b-navbar>
|
||||
<b-navbar-brand>Variables</b-navbar-brand>
|
||||
<b-navbar-nav>
|
||||
<b-nav-item v-for="item in nav" :href="item.url" :active="item.name === 'Variables'">{{ item.name }}</b-nav-item>
|
||||
</b-navbar-nav>
|
||||
</b-navbar>
|
||||
<b-alert
|
||||
dismissable
|
||||
variant="error"
|
||||
v-if="err"
|
||||
@dismissed="err = ''">
|
||||
{{ err }}
|
||||
</b-alert>
|
||||
<b-container>
|
||||
<b-table
|
||||
fixed
|
||||
:items="vars"
|
||||
:sort-by.sync="sortBy"
|
||||
:fields="fields"></b-table>
|
||||
</b-container>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
var app = new Vue({
|
||||
el: '#app',
|
||||
data: {
|
||||
err: '',
|
||||
nav: [],
|
||||
vars: [],
|
||||
sortBy: 'key',
|
||||
fields: [
|
||||
{ key: { sortable: true } },
|
||||
'value'
|
||||
]
|
||||
},
|
||||
mounted() {
|
||||
this.getData();
|
||||
axios.get('/nav')
|
||||
.then(resp => {
|
||||
this.nav = resp.data;
|
||||
})
|
||||
.catch(err => console.log(err))
|
||||
},
|
||||
methods: {
|
||||
getData: function() {
|
||||
axios.get('/vars/api')
|
||||
.then(resp => {
|
||||
this.vars = resp.data;
|
||||
})
|
||||
.catch(err => this.err = err);
|
||||
}
|
||||
}
|
||||
})
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
`
|
||||
|
||||
var apppassIndex = `
|
||||
<!DOCTYPE html>
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<!-- Load required Bootstrap and BootstrapVue CSS -->
|
||||
<link type="text/css" rel="stylesheet" href="//unpkg.com/bootstrap/dist/css/bootstrap.min.css"/>
|
||||
<link type="text/css" rel="stylesheet" href="//unpkg.com/bootstrap-vue@latest/dist/bootstrap-vue.min.css"/>
|
||||
|
||||
<!-- Load polyfills to support older browsers -->
|
||||
<script src="//polyfill.io/v3/polyfill.min.js?features=es2015%2CMutationObserver"></script>
|
||||
|
||||
<!-- Load Vue followed by BootstrapVue -->
|
||||
<script src="//unpkg.com/vue@latest/dist/vue.min.js"></script>
|
||||
<script src="//unpkg.com/bootstrap-vue@latest/dist/bootstrap-vue.min.js"></script>
|
||||
<script src="//unpkg.com/axios/dist/axios.min.js"></script>
|
||||
<meta charset="UTF-8">
|
||||
<title>Vars</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div id="app">
|
||||
<b-navbar>
|
||||
<b-navbar-brand>App Pass</b-navbar-brand>
|
||||
<b-navbar-nav>
|
||||
<b-nav-item v-for="item in nav" :href="item.url" :active="item.name === 'App Pass'">{{ item.name }}
|
||||
</b-nav-item>
|
||||
</b-navbar-nav>
|
||||
</b-navbar>
|
||||
<div class="alert alert-warning alert-dismissible fade show" role="alert" v-if="err != ''">
|
||||
<b-button type="link" class="close" data-dismiss="alert" aria-label="Close" @click="err = ''">
|
||||
<span aria-hidden="true">×</span>
|
||||
</b-button>
|
||||
{{ err }}
|
||||
</div>
|
||||
<b-form>
|
||||
<b-container>
|
||||
<b-row>
|
||||
<b-col cols="5">Password:</b-col>
|
||||
<b-col>
|
||||
<b-input v-model="password"/>
|
||||
</b-col>
|
||||
</b-row>
|
||||
<b-row>
|
||||
<b-col cols="5">Secret:</b-col>
|
||||
<b-col>
|
||||
<b-input v-model="entry.secret"/>
|
||||
</b-col>
|
||||
</b-row>
|
||||
<b-row>
|
||||
<b-col>
|
||||
<b-button @click="list">List</b-button>
|
||||
</b-col>
|
||||
<b-col>
|
||||
<b-button @click="newPass">New</b-button>
|
||||
</b-col>
|
||||
</b-row>
|
||||
</b-container>
|
||||
</b-form>
|
||||
<b-container v-show="showPassword" style="padding: 2em">
|
||||
<b-row align-h="center">
|
||||
<b-col align-self="center" cols="1">ID:</b-col>
|
||||
<b-col align-self="center" cols="3">{{ entry.id }}</b-col>
|
||||
</b-row>
|
||||
<b-row align-h="center">
|
||||
<b-col align-self="center" cols="1">Password:</b-col>
|
||||
<b-col align-self="center" cols="3">{{ entry.secret }}:{{ showPassword }}</b-col>
|
||||
</b-row>
|
||||
<b-row align-h="center">
|
||||
<b-col align-self="center" class="text-center" cols="6">Note: this password will only be displayed once. For single-field entry passwords, use the secret:password format.</b-col>
|
||||
</b-row>
|
||||
</b-container>
|
||||
<b-container>
|
||||
<b-row style="padding-top: 2em;">
|
||||
<b-col>
|
||||
<ul>
|
||||
<li v-for="entry in entries" key="id">
|
||||
<a @click="rm(entry)" href="#">X</a> {{entry.id}}</li>
|
||||
</ul>
|
||||
</b-col>
|
||||
</b-row>
|
||||
</b-container>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
var app = new Vue({
|
||||
el: '#app',
|
||||
data: {
|
||||
err: '',
|
||||
entry: {
|
||||
secret: '',
|
||||
},
|
||||
password: '',
|
||||
showPassword: '',
|
||||
nav: [],
|
||||
entries: [],
|
||||
},
|
||||
mounted() {
|
||||
axios.get('/nav')
|
||||
.then(resp => {
|
||||
this.nav = resp.data;
|
||||
})
|
||||
.catch(err => console.log(err))
|
||||
},
|
||||
methods: {
|
||||
rm: function (data) {
|
||||
this.showPassword = '';
|
||||
this.entry.id = data.id
|
||||
axios.delete('/apppass/api', {
|
||||
data: {
|
||||
password: this.password,
|
||||
passEntry: this.entry
|
||||
}
|
||||
})
|
||||
.then(() => {
|
||||
this.getData()
|
||||
})
|
||||
.catch(({response}) => {
|
||||
console.log('error: ' + response.data.err)
|
||||
this.err = response.data.err
|
||||
})
|
||||
},
|
||||
list: function () {
|
||||
this.showPassword = '';
|
||||
this.getData();
|
||||
},
|
||||
newPass: function () {
|
||||
axios.put('/apppass/api', {
|
||||
password: this.password,
|
||||
passEntry: this.entry
|
||||
})
|
||||
.then(resp => {
|
||||
this.getData()
|
||||
this.showPassword = resp.data.pass
|
||||
this.entry.id = resp.data.id
|
||||
})
|
||||
.catch(({response}) => {
|
||||
console.log('error: ' + response.data.err)
|
||||
this.err = response.data.err
|
||||
})
|
||||
},
|
||||
getData: function () {
|
||||
axios.post('/apppass/api', {
|
||||
password: this.password,
|
||||
passEntry: this.entry
|
||||
})
|
||||
.then(resp => {
|
||||
this.entries = resp.data;
|
||||
})
|
||||
.catch(({response}) => {
|
||||
console.log('error: ' + response.data.err)
|
||||
this.err = response.data.err
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
`
|
|
@ -0,0 +1,77 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<!-- Load required Bootstrap and BootstrapVue CSS -->
|
||||
<link type="text/css" rel="stylesheet" href="//unpkg.com/bootstrap/dist/css/bootstrap.min.css"/>
|
||||
<link type="text/css" rel="stylesheet" href="//unpkg.com/bootstrap-vue@latest/dist/bootstrap-vue.min.css"/>
|
||||
|
||||
<!-- Load polyfills to support older browsers -->
|
||||
<script src="//polyfill.io/v3/polyfill.min.js?features=es2015%2CMutationObserver"></script>
|
||||
|
||||
<!-- Load Vue followed by BootstrapVue -->
|
||||
<script src="//unpkg.com/vue@latest/dist/vue.min.js"></script>
|
||||
<script src="//unpkg.com/bootstrap-vue@latest/dist/bootstrap-vue.min.js"></script>
|
||||
<script src="//unpkg.com/axios/dist/axios.min.js"></script>
|
||||
<meta charset="UTF-8">
|
||||
<title>Vars</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div id="app">
|
||||
<b-navbar>
|
||||
<b-navbar-brand>Variables</b-navbar-brand>
|
||||
<b-navbar-nav>
|
||||
<b-nav-item v-for="item in nav" :href="item.url" :active="item.name === 'Variables'">{{ item.name }}
|
||||
</b-nav-item>
|
||||
</b-navbar-nav>
|
||||
</b-navbar>
|
||||
<b-alert
|
||||
dismissable
|
||||
variant="error"
|
||||
v-if="err"
|
||||
@dismissed="err = ''">
|
||||
{{ err }}
|
||||
</b-alert>
|
||||
<b-container>
|
||||
<b-table
|
||||
fixed
|
||||
:items="vars"
|
||||
:sort-by.sync="sortBy"
|
||||
:fields="fields"></b-table>
|
||||
</b-container>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
var app = new Vue({
|
||||
el: '#app',
|
||||
data: {
|
||||
err: '',
|
||||
nav: [],
|
||||
vars: [],
|
||||
sortBy: 'key',
|
||||
fields: [
|
||||
{key: {sortable: true}},
|
||||
'value'
|
||||
]
|
||||
},
|
||||
mounted() {
|
||||
this.getData();
|
||||
axios.get('/nav')
|
||||
.then(resp => {
|
||||
this.nav = resp.data;
|
||||
})
|
||||
.catch(err => console.log(err))
|
||||
},
|
||||
methods: {
|
||||
getData: function () {
|
||||
axios.get('/vars/api')
|
||||
.then(resp => {
|
||||
this.vars = resp.data;
|
||||
})
|
||||
.catch(err => this.err = err);
|
||||
}
|
||||
}
|
||||
})
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -3,6 +3,7 @@ package admin
|
|||
import (
|
||||
"crypto/md5"
|
||||
"crypto/rand"
|
||||
"embed"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
|
@ -14,6 +15,9 @@ import (
|
|||
"golang.org/x/crypto/bcrypt"
|
||||
)
|
||||
|
||||
//go:embed *.html
|
||||
var embeddedFS embed.FS
|
||||
|
||||
func (p *AdminPlugin) registerWeb() {
|
||||
r := chi.NewRouter()
|
||||
r.HandleFunc("/api", p.handleVarsAPI)
|
||||
|
@ -27,7 +31,8 @@ func (p *AdminPlugin) registerWeb() {
|
|||
}
|
||||
|
||||
func (p *AdminPlugin) handleAppPass(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Fprint(w, apppassIndex)
|
||||
index, _ := embeddedFS.ReadFile("apppass.html")
|
||||
w.Write(index)
|
||||
}
|
||||
|
||||
type PassEntry struct {
|
||||
|
@ -162,7 +167,8 @@ func writeErr(w http.ResponseWriter, err error) {
|
|||
}
|
||||
|
||||
func (p *AdminPlugin) handleVars(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Fprint(w, varIndex)
|
||||
index, _ := embeddedFS.ReadFile("vars.html")
|
||||
w.Write(index)
|
||||
}
|
||||
|
||||
func (p *AdminPlugin) handleVarsAPI(w http.ResponseWriter, r *http.Request) {
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
package cli
|
||||
|
||||
import (
|
||||
"embed"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
@ -17,6 +18,9 @@ import (
|
|||
"github.com/velour/catbase/bot/user"
|
||||
)
|
||||
|
||||
//go:embed *.html
|
||||
var embeddedFS embed.FS
|
||||
|
||||
type CliPlugin struct {
|
||||
bot bot.Bot
|
||||
db *sqlx.DB
|
||||
|
@ -97,7 +101,8 @@ func (p *CliPlugin) handleWebAPI(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
func (p *CliPlugin) handleWeb(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Fprint(w, indexHTML)
|
||||
index, _ := embeddedFS.ReadFile("index.html")
|
||||
w.Write(index)
|
||||
}
|
||||
|
||||
// Completing the Connector interface, but will not actually be a connector
|
||||
|
|
|
@ -1,136 +0,0 @@
|
|||
package cli
|
||||
|
||||
var indexHTML = `
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<!-- Load required Bootstrap and BootstrapVue CSS -->
|
||||
<link type="text/css" rel="stylesheet" href="//unpkg.com/bootstrap/dist/css/bootstrap.min.css" />
|
||||
<link type="text/css" rel="stylesheet" href="//unpkg.com/bootstrap-vue@latest/dist/bootstrap-vue.min.css" />
|
||||
|
||||
<!-- Load polyfills to support older browsers -->
|
||||
<script src="//polyfill.io/v3/polyfill.min.js?features=es2015%2CMutationObserver"></script>
|
||||
|
||||
<!-- Load Vue followed by BootstrapVue -->
|
||||
<script src="//unpkg.com/vue@latest/dist/vue.min.js"></script>
|
||||
<script src="//unpkg.com/bootstrap-vue@latest/dist/bootstrap-vue.min.js"></script>
|
||||
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
|
||||
<meta charset="UTF-8">
|
||||
<title>CLI</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div id="app">
|
||||
<b-navbar>
|
||||
<b-navbar-brand>CLI</b-navbar-brand>
|
||||
<b-navbar-nav>
|
||||
<b-nav-item v-for="item in nav" :href="item.url" :active="item.name === 'CLI'">{{ item.name }}</b-nav-item>
|
||||
</b-navbar-nav>
|
||||
</b-navbar>
|
||||
<b-alert
|
||||
dismissable
|
||||
variant="error"
|
||||
:show="err">
|
||||
{{ err }}
|
||||
</b-alert>
|
||||
<b-container>
|
||||
<b-row>
|
||||
<b-col cols="5">Password:</b-col>
|
||||
<b-col><b-input v-model="answer"></b-col>
|
||||
</b-row>
|
||||
<b-row>
|
||||
<b-form-textarea
|
||||
v-sticky-scroll
|
||||
disabled
|
||||
id="textarea"
|
||||
v-model="text"
|
||||
placeholder="The bot will respond here..."
|
||||
rows="10"
|
||||
max-rows="10"
|
||||
no-resize
|
||||
></b-form-textarea>
|
||||
</b-row>
|
||||
<b-form
|
||||
@submit="send">
|
||||
<b-row>
|
||||
<b-col>
|
||||
<b-form-input
|
||||
type="text"
|
||||
placeholder="Username"
|
||||
v-model="user"></b-form-input>
|
||||
</b-col>
|
||||
<b-col>
|
||||
<b-form-input
|
||||
type="text"
|
||||
placeholder="Enter something to send to the bot"
|
||||
v-model="input"
|
||||
autocomplete="off"
|
||||
></b-form-input>
|
||||
</b-col>
|
||||
<b-col>
|
||||
<b-button type="submit" :disabled="!authenticated">Send</b-button>
|
||||
</b-col>
|
||||
</b-row>
|
||||
</b-form>
|
||||
</b-container>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
var app = new Vue({
|
||||
el: '#app',
|
||||
data: {
|
||||
err: '',
|
||||
nav: [],
|
||||
answer: '',
|
||||
correct: 0,
|
||||
textarea: [],
|
||||
user: '',
|
||||
input: '',
|
||||
},
|
||||
mounted: function() {
|
||||
axios.get('/nav')
|
||||
.then(resp => {
|
||||
this.nav = resp.data;
|
||||
})
|
||||
.catch(err => console.log(err))
|
||||
},
|
||||
computed: {
|
||||
authenticated: function() {
|
||||
if (this.user !== '')
|
||||
return true;
|
||||
return false;
|
||||
},
|
||||
text: function() {
|
||||
return this.textarea.join('\n');
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
addText(user, text) {
|
||||
this.textarea.push(user + ": " + text);
|
||||
const len = this.textarea.length;
|
||||
if (this.textarea.length > 10)
|
||||
this.textarea = this.textarea.slice(len-10, len);
|
||||
},
|
||||
send(evt) {
|
||||
evt.preventDefault();
|
||||
evt.stopPropagation()
|
||||
if (!this.authenticated) {
|
||||
return;
|
||||
}
|
||||
const payload = {user: this.user, payload: this.input, password: this.answer};
|
||||
this.addText(this.user, this.input);
|
||||
this.input = "";
|
||||
axios.post('/cli/api', payload)
|
||||
.then(resp => {
|
||||
const data = resp.data;
|
||||
this.addText(data.user, data.payload.trim());
|
||||
this.err = '';
|
||||
})
|
||||
.catch(err => (this.err = err));
|
||||
}
|
||||
}
|
||||
})
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
`
|
|
@ -0,0 +1,132 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<!-- Load required Bootstrap and BootstrapVue CSS -->
|
||||
<link type="text/css" rel="stylesheet" href="//unpkg.com/bootstrap/dist/css/bootstrap.min.css" />
|
||||
<link type="text/css" rel="stylesheet" href="//unpkg.com/bootstrap-vue@latest/dist/bootstrap-vue.min.css" />
|
||||
|
||||
<!-- Load polyfills to support older browsers -->
|
||||
<script src="//polyfill.io/v3/polyfill.min.js?features=es2015%2CMutationObserver"></script>
|
||||
|
||||
<!-- Load Vue followed by BootstrapVue -->
|
||||
<script src="//unpkg.com/vue@latest/dist/vue.min.js"></script>
|
||||
<script src="//unpkg.com/bootstrap-vue@latest/dist/bootstrap-vue.min.js"></script>
|
||||
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
|
||||
<meta charset="UTF-8">
|
||||
<title>CLI</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div id="app">
|
||||
<b-navbar>
|
||||
<b-navbar-brand>CLI</b-navbar-brand>
|
||||
<b-navbar-nav>
|
||||
<b-nav-item v-for="item in nav" :href="item.url" :active="item.name === 'CLI'">{{ item.name }}</b-nav-item>
|
||||
</b-navbar-nav>
|
||||
</b-navbar>
|
||||
<b-alert
|
||||
dismissable
|
||||
variant="error"
|
||||
:show="err">
|
||||
{{ err }}
|
||||
</b-alert>
|
||||
<b-container>
|
||||
<b-row>
|
||||
<b-col cols="5">Password:</b-col>
|
||||
<b-col><b-input v-model="answer"></b-col>
|
||||
</b-row>
|
||||
<b-row>
|
||||
<b-form-textarea
|
||||
v-sticky-scroll
|
||||
disabled
|
||||
id="textarea"
|
||||
v-model="text"
|
||||
placeholder="The bot will respond here..."
|
||||
rows="10"
|
||||
max-rows="10"
|
||||
no-resize
|
||||
></b-form-textarea>
|
||||
</b-row>
|
||||
<b-form
|
||||
@submit="send">
|
||||
<b-row>
|
||||
<b-col>
|
||||
<b-form-input
|
||||
type="text"
|
||||
placeholder="Username"
|
||||
v-model="user"></b-form-input>
|
||||
</b-col>
|
||||
<b-col>
|
||||
<b-form-input
|
||||
type="text"
|
||||
placeholder="Enter something to send to the bot"
|
||||
v-model="input"
|
||||
autocomplete="off"
|
||||
></b-form-input>
|
||||
</b-col>
|
||||
<b-col>
|
||||
<b-button type="submit" :disabled="!authenticated">Send</b-button>
|
||||
</b-col>
|
||||
</b-row>
|
||||
</b-form>
|
||||
</b-container>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
var app = new Vue({
|
||||
el: '#app',
|
||||
data: {
|
||||
err: '',
|
||||
nav: [],
|
||||
answer: '',
|
||||
correct: 0,
|
||||
textarea: [],
|
||||
user: '',
|
||||
input: '',
|
||||
},
|
||||
mounted: function() {
|
||||
axios.get('/nav')
|
||||
.then(resp => {
|
||||
this.nav = resp.data;
|
||||
})
|
||||
.catch(err => console.log(err))
|
||||
},
|
||||
computed: {
|
||||
authenticated: function() {
|
||||
if (this.user !== '')
|
||||
return true;
|
||||
return false;
|
||||
},
|
||||
text: function() {
|
||||
return this.textarea.join('\n');
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
addText(user, text) {
|
||||
this.textarea.push(user + ": " + text);
|
||||
const len = this.textarea.length;
|
||||
if (this.textarea.length > 10)
|
||||
this.textarea = this.textarea.slice(len-10, len);
|
||||
},
|
||||
send(evt) {
|
||||
evt.preventDefault();
|
||||
evt.stopPropagation()
|
||||
if (!this.authenticated) {
|
||||
return;
|
||||
}
|
||||
const payload = {user: this.user, payload: this.input, password: this.answer};
|
||||
this.addText(this.user, this.input);
|
||||
this.input = "";
|
||||
axios.post('/cli/api', payload)
|
||||
.then(resp => {
|
||||
const data = resp.data;
|
||||
this.addText(data.user, data.payload.trim());
|
||||
this.err = '';
|
||||
})
|
||||
.catch(err => (this.err = err));
|
||||
}
|
||||
}
|
||||
})
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -1,6 +1,7 @@
|
|||
package counter
|
||||
|
||||
import (
|
||||
"embed"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
@ -12,6 +13,9 @@ import (
|
|||
"github.com/velour/catbase/bot/msg"
|
||||
)
|
||||
|
||||
//go:embed *.html
|
||||
var embeddedFS embed.FS
|
||||
|
||||
func (p *CounterPlugin) registerWeb() {
|
||||
r := chi.NewRouter()
|
||||
r.HandleFunc("/api/users/{user}/items/{item}/increment", p.mkIncrementAPI(1))
|
||||
|
@ -89,7 +93,8 @@ func (p *CounterPlugin) mkIncrementAPI(delta int) func(w http.ResponseWriter, r
|
|||
}
|
||||
|
||||
func (p *CounterPlugin) handleCounter(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Fprint(w, html)
|
||||
index, _ := embeddedFS.ReadFile("index.html")
|
||||
w.Write(index)
|
||||
}
|
||||
|
||||
func (p *CounterPlugin) handleCounterAPI(w http.ResponseWriter, r *http.Request) {
|
||||
|
|
|
@ -1,108 +0,0 @@
|
|||
package counter
|
||||
|
||||
var html = `
|
||||
<html>
|
||||
<head>
|
||||
<!-- Load required Bootstrap and BootstrapVue CSS -->
|
||||
<link type="text/css" rel="stylesheet" href="//unpkg.com/bootstrap/dist/css/bootstrap.min.css" />
|
||||
<link type="text/css" rel="stylesheet" href="//unpkg.com/bootstrap-vue@latest/dist/bootstrap-vue.min.css" />
|
||||
|
||||
<!-- Load polyfills to support older browsers -->
|
||||
<script src="//polyfill.io/v3/polyfill.min.js?features=es2015%2CMutationObserver"></script>
|
||||
|
||||
<!-- Load Vue followed by BootstrapVue -->
|
||||
<script src="//unpkg.com/vue@latest/dist/vue.min.js"></script>
|
||||
<script src="//unpkg.com/bootstrap-vue@latest/dist/bootstrap-vue.min.js"></script>
|
||||
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
|
||||
<title>Counters</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div id="app">
|
||||
<b-navbar>
|
||||
<b-navbar-brand>Counters</b-navbar-brand>
|
||||
<b-navbar-nav>
|
||||
<b-nav-item v-for="item in nav" :href="item.url" :active="item.name === 'Counter'">{{ item.name }}</b-nav-item>
|
||||
</b-navbar-nav>
|
||||
</b-navbar>
|
||||
<b-alert
|
||||
dismissable
|
||||
:show="err"
|
||||
variant="error">
|
||||
{{ err }}
|
||||
</b-alert>
|
||||
<b-container>
|
||||
<b-row>
|
||||
<b-col cols="5">Password:</b-col>
|
||||
<b-col><b-input v-model="answer"></b-col>
|
||||
</b-row>
|
||||
<b-row v-for="(counter, user) in counters">
|
||||
{{ user }}:
|
||||
<b-container>
|
||||
<b-row v-for="(count, thing) in counter">
|
||||
<b-col offset="1">
|
||||
{{ thing }}:
|
||||
</b-col>
|
||||
<b-col>
|
||||
{{ count }}
|
||||
</b-col>
|
||||
<b-col cols="2">
|
||||
<button @click="subtract(user,thing,count)">-</button>
|
||||
<button @click="add(user,thing,count)">+</button>
|
||||
</b-col>
|
||||
</b-row>
|
||||
</b-container>
|
||||
</b-row>
|
||||
</b-container>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
function convertData(data) {
|
||||
var newData = {};
|
||||
for (let i = 0; i < data.length; i++) {
|
||||
let entry = data[i]
|
||||
if (newData[entry.Nick] === undefined) {
|
||||
newData[entry.Nick] = {}
|
||||
}
|
||||
newData[entry.Nick][entry.Item] = entry.Count;
|
||||
}
|
||||
return newData;
|
||||
}
|
||||
var app = new Vue({
|
||||
el: '#app',
|
||||
data: {
|
||||
err: '',
|
||||
nav: [],
|
||||
answer: '',
|
||||
correct: 0,
|
||||
counters: {}
|
||||
},
|
||||
mounted() {
|
||||
axios.get('/nav')
|
||||
.then(resp => {
|
||||
this.nav = resp.data;
|
||||
})
|
||||
.catch(err => console.log(err))
|
||||
axios.get('/counter/api')
|
||||
.then(resp => (this.counters = convertData(resp.data)))
|
||||
.catch(err => (this.err = err));
|
||||
},
|
||||
methods: {
|
||||
add(user, thing, count) {
|
||||
axios.post('/counter/api',
|
||||
{user: user, thing: thing, action: '++', password: this.answer})
|
||||
.then(resp => {this.counters = convertData(resp.data); this.err = '';})
|
||||
.catch(err => this.err = err);
|
||||
},
|
||||
subtract(user, thing, count) {
|
||||
axios.post('/counter/api',
|
||||
{user: user, thing: thing, action: '--', password: this.answer})
|
||||
.then(resp => {this.counters = convertData(resp.data); this.err = '';})
|
||||
.catch(err => this.err = err);
|
||||
}
|
||||
}
|
||||
})
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
`
|
|
@ -0,0 +1,104 @@
|
|||
<html>
|
||||
<head>
|
||||
<!-- Load required Bootstrap and BootstrapVue CSS -->
|
||||
<link type="text/css" rel="stylesheet" href="//unpkg.com/bootstrap/dist/css/bootstrap.min.css" />
|
||||
<link type="text/css" rel="stylesheet" href="//unpkg.com/bootstrap-vue@latest/dist/bootstrap-vue.min.css" />
|
||||
|
||||
<!-- Load polyfills to support older browsers -->
|
||||
<script src="//polyfill.io/v3/polyfill.min.js?features=es2015%2CMutationObserver"></script>
|
||||
|
||||
<!-- Load Vue followed by BootstrapVue -->
|
||||
<script src="//unpkg.com/vue@latest/dist/vue.min.js"></script>
|
||||
<script src="//unpkg.com/bootstrap-vue@latest/dist/bootstrap-vue.min.js"></script>
|
||||
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
|
||||
<title>Counters</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div id="app">
|
||||
<b-navbar>
|
||||
<b-navbar-brand>Counters</b-navbar-brand>
|
||||
<b-navbar-nav>
|
||||
<b-nav-item v-for="item in nav" :href="item.url" :active="item.name === 'Counter'">{{ item.name }}</b-nav-item>
|
||||
</b-navbar-nav>
|
||||
</b-navbar>
|
||||
<b-alert
|
||||
dismissable
|
||||
:show="err"
|
||||
variant="error">
|
||||
{{ err }}
|
||||
</b-alert>
|
||||
<b-container>
|
||||
<b-row>
|
||||
<b-col cols="5">Password:</b-col>
|
||||
<b-col><b-input v-model="answer"></b-col>
|
||||
</b-row>
|
||||
<b-row v-for="(counter, user) in counters">
|
||||
{{ user }}:
|
||||
<b-container>
|
||||
<b-row v-for="(count, thing) in counter">
|
||||
<b-col offset="1">
|
||||
{{ thing }}:
|
||||
</b-col>
|
||||
<b-col>
|
||||
{{ count }}
|
||||
</b-col>
|
||||
<b-col cols="2">
|
||||
<button @click="subtract(user,thing,count)">-</button>
|
||||
<button @click="add(user,thing,count)">+</button>
|
||||
</b-col>
|
||||
</b-row>
|
||||
</b-container>
|
||||
</b-row>
|
||||
</b-container>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
function convertData(data) {
|
||||
var newData = {};
|
||||
for (let i = 0; i < data.length; i++) {
|
||||
let entry = data[i]
|
||||
if (newData[entry.Nick] === undefined) {
|
||||
newData[entry.Nick] = {}
|
||||
}
|
||||
newData[entry.Nick][entry.Item] = entry.Count;
|
||||
}
|
||||
return newData;
|
||||
}
|
||||
var app = new Vue({
|
||||
el: '#app',
|
||||
data: {
|
||||
err: '',
|
||||
nav: [],
|
||||
answer: '',
|
||||
correct: 0,
|
||||
counters: {}
|
||||
},
|
||||
mounted() {
|
||||
axios.get('/nav')
|
||||
.then(resp => {
|
||||
this.nav = resp.data;
|
||||
})
|
||||
.catch(err => console.log(err))
|
||||
axios.get('/counter/api')
|
||||
.then(resp => (this.counters = convertData(resp.data)))
|
||||
.catch(err => (this.err = err));
|
||||
},
|
||||
methods: {
|
||||
add(user, thing, count) {
|
||||
axios.post('/counter/api',
|
||||
{user: user, thing: thing, action: '++', password: this.answer})
|
||||
.then(resp => {this.counters = convertData(resp.data); this.err = '';})
|
||||
.catch(err => this.err = err);
|
||||
},
|
||||
subtract(user, thing, count) {
|
||||
axios.post('/counter/api',
|
||||
{user: user, thing: thing, action: '--', password: this.answer})
|
||||
.then(resp => {this.counters = convertData(resp.data); this.err = '';})
|
||||
.catch(err => this.err = err);
|
||||
}
|
||||
}
|
||||
})
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -4,6 +4,7 @@ package fact
|
|||
|
||||
import (
|
||||
"database/sql"
|
||||
"embed"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"html/template"
|
||||
|
@ -26,6 +27,9 @@ import (
|
|||
// The factoid plugin provides a learning system to the bot so that it can
|
||||
// respond to queries in a way that is unpredictable and fun
|
||||
|
||||
//go:embed *.html
|
||||
var embeddedFS embed.FS
|
||||
|
||||
// factoid stores info about our factoid for lookup and later interaction
|
||||
type Factoid struct {
|
||||
ID sql.NullInt64
|
||||
|
@ -851,5 +855,6 @@ func (p *FactoidPlugin) serveAPI(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
func (p *FactoidPlugin) serveQuery(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Fprint(w, factoidIndex)
|
||||
index, _ := embeddedFS.ReadFile("index.html")
|
||||
w.Write(index)
|
||||
}
|
||||
|
|
|
@ -1,13 +1,3 @@
|
|||
// © 2013 the CatBase Authors under the WTFPL. See AUTHORS for the list of authors.
|
||||
|
||||
package fact
|
||||
|
||||
// I hate this, but I'm creating strings of the templates to avoid having to
|
||||
// track where templates reside.
|
||||
|
||||
// 2016-01-15 Later note, why are these in plugins and the server is in bot?
|
||||
|
||||
var factoidIndex = `
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
|
@ -116,5 +106,4 @@ var factoidIndex = `
|
|||
})
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
`
|
||||
</html>
|
|
@ -1,6 +1,3 @@
|
|||
package meme
|
||||
|
||||
var memeIndex = `
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
|
@ -214,4 +211,3 @@ var memeIndex = `
|
|||
</script>
|
||||
</body>
|
||||
</html>
|
||||
`
|
|
@ -1,6 +1,7 @@
|
|||
package meme
|
||||
|
||||
import (
|
||||
"embed"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
@ -13,6 +14,9 @@ import (
|
|||
"github.com/velour/catbase/bot"
|
||||
)
|
||||
|
||||
//go:embed *.html
|
||||
var embeddedFS embed.FS
|
||||
|
||||
func (p *MemePlugin) registerWeb(c bot.Connector) {
|
||||
r := chi.NewRouter()
|
||||
r.HandleFunc("/slash", p.slashMeme(c))
|
||||
|
@ -131,7 +135,8 @@ func (p *MemePlugin) addMeme(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
func (p *MemePlugin) webRoot(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Fprint(w, memeIndex)
|
||||
index, _ := embeddedFS.ReadFile("index.html")
|
||||
w.Write(index)
|
||||
}
|
||||
|
||||
func (p *MemePlugin) img(w http.ResponseWriter, r *http.Request) {
|
||||
|
|
|
@ -1,6 +1,3 @@
|
|||
package secrets
|
||||
|
||||
var indexTpl = `
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
|
@ -122,4 +119,3 @@ var indexTpl = `
|
|||
</script>
|
||||
</body>
|
||||
</html>
|
||||
`
|
|
@ -1,6 +1,7 @@
|
|||
package secrets
|
||||
|
||||
import (
|
||||
"embed"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
@ -12,6 +13,9 @@ import (
|
|||
"github.com/velour/catbase/config"
|
||||
)
|
||||
|
||||
//go:embed *.html
|
||||
var embeddedFS embed.FS
|
||||
|
||||
type SecretsPlugin struct {
|
||||
b bot.Bot
|
||||
c *config.Config
|
||||
|
@ -61,7 +65,7 @@ func (p *SecretsPlugin) removeSecret(key string) error {
|
|||
}
|
||||
|
||||
func (p *SecretsPlugin) updateSecret(key, value string) error {
|
||||
q := `update secrets set value=? where key=?)`
|
||||
q := `update secrets set value=? where key=?`
|
||||
_, err := p.db.Exec(q, value, key)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -152,5 +156,6 @@ func (p *SecretsPlugin) handleRemove(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
func (p *SecretsPlugin) handleIndex(w http.ResponseWriter, r *http.Request) {
|
||||
w.Write([]byte(indexTpl))
|
||||
index, _ := embeddedFS.ReadFile("index.html")
|
||||
w.Write(index)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue