Compare commits

..

No commits in common. "13e16c9f01a5156b39c503cd99b5922b6cc5c59f" and "7ba9d94ac200f9b842024a236e7bdc529c9b550e" have entirely different histories.

20 changed files with 568 additions and 569 deletions

View File

@ -7,10 +7,10 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Set up Go 1.16 - name: Set up Go 1.13
uses: actions/setup-go@v1 uses: actions/setup-go@v1
with: with:
go-version: 1.16.x go-version: 1.13.x
id: go id: go
- name: Check out code into the Go module directory - name: Check out code into the Go module directory

View File

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

View File

@ -1,18 +1,14 @@
package bot package bot
import ( import (
"embed"
"encoding/json" "encoding/json"
"fmt"
"net/http" "net/http"
"strings" "strings"
) )
//go:embed *.html
var embeddedFS embed.FS
func (b *bot) serveRoot(w http.ResponseWriter, r *http.Request) { func (b *bot) serveRoot(w http.ResponseWriter, r *http.Request) {
index, _ := embeddedFS.ReadFile("index.html") fmt.Fprint(w, rootIndex)
w.Write(index)
} }
func (b *bot) serveNav(w http.ResponseWriter, r *http.Request) { func (b *bot) serveNav(w http.ResponseWriter, r *http.Request) {
@ -40,3 +36,53 @@ func (b *bot) GetWebNavigation() []EndPoint {
} }
return endpoints 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
View File

@ -1,6 +1,6 @@
module github.com/velour/catbase module github.com/velour/catbase
go 1.16 go 1.13
require ( require (
code.chrissexton.org/cws/getaoc v0.0.0-20191201043947-d5417d4b618d code.chrissexton.org/cws/getaoc v0.0.0-20191201043947-d5417d4b618d

View File

@ -1,160 +0,0 @@
<!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">&times;</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>

241
plugins/admin/index.go Normal file
View File

@ -0,0 +1,241 @@
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">&times;</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>
`

View File

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

View File

@ -3,7 +3,6 @@ package admin
import ( import (
"crypto/md5" "crypto/md5"
"crypto/rand" "crypto/rand"
"embed"
"encoding/json" "encoding/json"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
@ -15,9 +14,6 @@ import (
"golang.org/x/crypto/bcrypt" "golang.org/x/crypto/bcrypt"
) )
//go:embed *.html
var embeddedFS embed.FS
func (p *AdminPlugin) registerWeb() { func (p *AdminPlugin) registerWeb() {
r := chi.NewRouter() r := chi.NewRouter()
r.HandleFunc("/api", p.handleVarsAPI) r.HandleFunc("/api", p.handleVarsAPI)
@ -31,8 +27,7 @@ func (p *AdminPlugin) registerWeb() {
} }
func (p *AdminPlugin) handleAppPass(w http.ResponseWriter, r *http.Request) { func (p *AdminPlugin) handleAppPass(w http.ResponseWriter, r *http.Request) {
index, _ := embeddedFS.ReadFile("apppass.html") fmt.Fprint(w, apppassIndex)
w.Write(index)
} }
type PassEntry struct { type PassEntry struct {
@ -167,8 +162,7 @@ func writeErr(w http.ResponseWriter, err error) {
} }
func (p *AdminPlugin) handleVars(w http.ResponseWriter, r *http.Request) { func (p *AdminPlugin) handleVars(w http.ResponseWriter, r *http.Request) {
index, _ := embeddedFS.ReadFile("vars.html") fmt.Fprint(w, varIndex)
w.Write(index)
} }
func (p *AdminPlugin) handleVarsAPI(w http.ResponseWriter, r *http.Request) { func (p *AdminPlugin) handleVarsAPI(w http.ResponseWriter, r *http.Request) {

View File

@ -3,7 +3,6 @@
package cli package cli
import ( import (
"embed"
"encoding/json" "encoding/json"
"fmt" "fmt"
"net/http" "net/http"
@ -18,9 +17,6 @@ import (
"github.com/velour/catbase/bot/user" "github.com/velour/catbase/bot/user"
) )
//go:embed *.html
var embeddedFS embed.FS
type CliPlugin struct { type CliPlugin struct {
bot bot.Bot bot bot.Bot
db *sqlx.DB db *sqlx.DB
@ -101,8 +97,7 @@ func (p *CliPlugin) handleWebAPI(w http.ResponseWriter, r *http.Request) {
} }
func (p *CliPlugin) handleWeb(w http.ResponseWriter, r *http.Request) { func (p *CliPlugin) handleWeb(w http.ResponseWriter, r *http.Request) {
index, _ := embeddedFS.ReadFile("index.html") fmt.Fprint(w, indexHTML)
w.Write(index)
} }
// Completing the Connector interface, but will not actually be a connector // Completing the Connector interface, but will not actually be a connector

136
plugins/cli/index.go Normal file
View File

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

View File

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

View File

@ -1,7 +1,6 @@
package counter package counter
import ( import (
"embed"
"encoding/json" "encoding/json"
"fmt" "fmt"
"net/http" "net/http"
@ -13,9 +12,6 @@ import (
"github.com/velour/catbase/bot/msg" "github.com/velour/catbase/bot/msg"
) )
//go:embed *.html
var embeddedFS embed.FS
func (p *CounterPlugin) registerWeb() { func (p *CounterPlugin) registerWeb() {
r := chi.NewRouter() r := chi.NewRouter()
r.HandleFunc("/api/users/{user}/items/{item}/increment", p.mkIncrementAPI(1)) r.HandleFunc("/api/users/{user}/items/{item}/increment", p.mkIncrementAPI(1))
@ -93,8 +89,7 @@ func (p *CounterPlugin) mkIncrementAPI(delta int) func(w http.ResponseWriter, r
} }
func (p *CounterPlugin) handleCounter(w http.ResponseWriter, r *http.Request) { func (p *CounterPlugin) handleCounter(w http.ResponseWriter, r *http.Request) {
index, _ := embeddedFS.ReadFile("index.html") fmt.Fprint(w, html)
w.Write(index)
} }
func (p *CounterPlugin) handleCounterAPI(w http.ResponseWriter, r *http.Request) { func (p *CounterPlugin) handleCounterAPI(w http.ResponseWriter, r *http.Request) {

108
plugins/counter/html.go Normal file
View File

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

View File

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

View File

@ -4,7 +4,6 @@ package fact
import ( import (
"database/sql" "database/sql"
"embed"
"encoding/json" "encoding/json"
"fmt" "fmt"
"html/template" "html/template"
@ -27,9 +26,6 @@ import (
// The factoid plugin provides a learning system to the bot so that it can // 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 // 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 // factoid stores info about our factoid for lookup and later interaction
type Factoid struct { type Factoid struct {
ID sql.NullInt64 ID sql.NullInt64
@ -855,6 +851,5 @@ func (p *FactoidPlugin) serveAPI(w http.ResponseWriter, r *http.Request) {
} }
func (p *FactoidPlugin) serveQuery(w http.ResponseWriter, r *http.Request) { func (p *FactoidPlugin) serveQuery(w http.ResponseWriter, r *http.Request) {
index, _ := embeddedFS.ReadFile("index.html") fmt.Fprint(w, factoidIndex)
w.Write(index)
} }

View File

@ -1,3 +1,13 @@
// © 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> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
@ -107,3 +117,4 @@
</script> </script>
</body> </body>
</html> </html>
`

View File

@ -1,3 +1,6 @@
package meme
var memeIndex = `
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
@ -211,3 +214,4 @@
</script> </script>
</body> </body>
</html> </html>
`

View File

@ -1,7 +1,6 @@
package meme package meme
import ( import (
"embed"
"encoding/json" "encoding/json"
"fmt" "fmt"
"net/http" "net/http"
@ -14,9 +13,6 @@ import (
"github.com/velour/catbase/bot" "github.com/velour/catbase/bot"
) )
//go:embed *.html
var embeddedFS embed.FS
func (p *MemePlugin) registerWeb(c bot.Connector) { func (p *MemePlugin) registerWeb(c bot.Connector) {
r := chi.NewRouter() r := chi.NewRouter()
r.HandleFunc("/slash", p.slashMeme(c)) r.HandleFunc("/slash", p.slashMeme(c))
@ -135,8 +131,7 @@ func (p *MemePlugin) addMeme(w http.ResponseWriter, r *http.Request) {
} }
func (p *MemePlugin) webRoot(w http.ResponseWriter, r *http.Request) { func (p *MemePlugin) webRoot(w http.ResponseWriter, r *http.Request) {
index, _ := embeddedFS.ReadFile("index.html") fmt.Fprint(w, memeIndex)
w.Write(index)
} }
func (p *MemePlugin) img(w http.ResponseWriter, r *http.Request) { func (p *MemePlugin) img(w http.ResponseWriter, r *http.Request) {

View File

@ -1,7 +1,6 @@
package secrets package secrets
import ( import (
"embed"
"encoding/json" "encoding/json"
"fmt" "fmt"
"net/http" "net/http"
@ -13,9 +12,6 @@ import (
"github.com/velour/catbase/config" "github.com/velour/catbase/config"
) )
//go:embed *.html
var embeddedFS embed.FS
type SecretsPlugin struct { type SecretsPlugin struct {
b bot.Bot b bot.Bot
c *config.Config c *config.Config
@ -65,7 +61,7 @@ func (p *SecretsPlugin) removeSecret(key string) error {
} }
func (p *SecretsPlugin) updateSecret(key, value 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) _, err := p.db.Exec(q, value, key)
if err != nil { if err != nil {
return err return err
@ -156,6 +152,5 @@ func (p *SecretsPlugin) handleRemove(w http.ResponseWriter, r *http.Request) {
} }
func (p *SecretsPlugin) handleIndex(w http.ResponseWriter, r *http.Request) { func (p *SecretsPlugin) handleIndex(w http.ResponseWriter, r *http.Request) {
index, _ := embeddedFS.ReadFile("index.html") w.Write([]byte(indexTpl))
w.Write(index)
} }

View File

@ -1,3 +1,6 @@
package secrets
var indexTpl = `
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
@ -119,3 +122,4 @@
</script> </script>
</body> </body>
</html> </html>
`