Archived
1
0

update mod panel, begin migration to gx

This commit is contained in:
Jeff Becker 2016-03-25 09:48:19 -04:00
parent 7a67e38bf1
commit 33c6c33af2
No known key found for this signature in database
GPG Key ID: AB950234D6EA286B
8 changed files with 270 additions and 93 deletions

1
.gitignore vendored
View File

@ -29,3 +29,4 @@ certs
rebuild.sh rebuild.sh
vendor

View File

@ -1,5 +1,5 @@
# #
# .gitignore for nntpchan repo # .gxignore for nntpchan repo
# #
# emacs temp files # emacs temp files
@ -27,5 +27,6 @@ srndv2
# certificates # certificates
certs certs
rebuild.sh rebuild.sh
.git

107
contrib/static/feed.js Normal file
View File

@ -0,0 +1,107 @@
function createConnectionElement(j) {
var e = document.createElement("div");
e.setAttribute("class", "connection");
var auth = document.createElement("div");
auth.appendChild(document.createTextNode("Connection: "+j.name));
// authentication state
if (j.authed) {
auth.setAttribute("class", "authed");
auth.appendChild(document.createTextNode("(authenticated)"));
} else {
auth.appendChild(document.createTextNode("(not authenticated)"));
}
e.appendChild(auth);
// connection mode
var mode = document.createElement("div");
mode.setAttribute("class", "mode");
mode.appendChild(document.createTextNode("mode: "+j.mode));
e.appendChild(mode);
var pending = document.createElement("div");
pending.setAttribute("class", "pending");
// pending articles
var articles = Object.keys(j.pending);
pending.appendChild(document.createTextNode("pending articles: "+articles.length));
for ( var idx = 0 ; idx < articles.length; idx ++ ) {
var msgid = articles[idx];
var state = j.pending[msgid];
var elem = document.createElement("div");
elem.appendChild(document.createTextNode(msgid + ": " + state));
elem.setAttribute("class", "pending_item "+state);
pending.appendChild(elem);
}
e.appendChild(pending);
// e.appendChild(document.createTextNode(JSON.stringify(j)));
return e;
}
function inject_nntp_feed_element(feed, elem) {
elem.appendChild(document.createElement("hr"));
var name = document.createElement("div");
name.setAttribute("class", "feeds_name");
name_elem = document.createTextNode("Name: "+feed.State.Config.Name);
name.appendChild(name_elem);
elem.appendChild(name);
var conns = document.createElement("div");
conns.setAttribute("class", "connections");
for ( var idx = 0 ; idx < feed.Conns.length; idx ++ ) {
conns.appendChild(createConnectionElement(feed.Conns[idx]));
}
elem.appendChild(conns);
}
function update_nntpchan_feed_ticker(elem, result_elem) {
nntpchan_admin("feed.list", null, function(j) {
if (j) {
if (j.error) {
console.log("nntpchan_feed_ticker: error, "+j.error);
} else {
// remove all children
while(elem.children.length) {
elem.children[0].remove();
}
var result = j.result;
for (var idx = 0; idx < result.length; idx++) {
var item = result[idx];
var entry = document.createElement("div");
inject_nntp_feed_element(item, entry);
elem.appendChild(entry);
}
}
}
}, result_elem);
}
function nntp_feed_add() {
var param = {};
var e = document.getElementById("add_feed_name");
param.name = e.value;
e = document.getElementById("add_feed_host");
param.host = e.value;
e = document.getElementById("add_feed_port");
param.port = parseInt(e.value);
e = document.getElementById("nntpchan_feed_result");
nntpchan_admin("feed.add", param, null, e);
}
function nntp_feed_del() {
var e = document.getElementById("del_feed_name");
var name = e.value;
e = document.getElementById("nntpchan_feed_result");
nntpchan_admin("feed.del", {name: name}, null, e);
}
function nntp_feed_update() {
var e = document.getElementById("nntpchan_feeds");
if (e) {
setInterval(function(){
var e1 = document.getElementById("nntpchan_feed_result");
update_nntpchan_feed_ticker(e, e1);
}, 1000);
}
}

View File

@ -87,7 +87,7 @@ function nntpchan_admin_board(method) {
}) })
} }
function nntpchan_admin(method, param, handler_cb) { function nntpchan_admin(method, param, handler_cb, result_elem) {
if (handler_cb) { if (handler_cb) {
// we got a handler already set // we got a handler already set
} else { } else {
@ -108,7 +108,7 @@ function nntpchan_admin(method, param, handler_cb) {
handle: handler_cb, handle: handler_cb,
method: ( param && "POST" ) || "GET", method: ( param && "POST" ) || "GET",
data: param data: param
}) }, result_elem)
} }
@ -142,83 +142,7 @@ function nntpchan_delete() {
}); });
} }
function createConnectionElement(j) { function nntpchan_mod(mod_action, result_elem) {
var e = document.createElement("div");
e.setAttribute("class", "connection");
var auth = document.createElement("div");
auth.appendChild(document.createTextNode("Connection: "+j.name));
// authentication state
if (j.authed) {
auth.setAttribute("class", "authed");
auth.appendChild(document.createTextNode("(authenticated)"));
} else {
auth.appendChild(document.createTextNode("(not authenticated)"));
}
e.appendChild(auth);
// connection mode
var mode = document.createElement("div");
mode.setAttribute("class", "mode");
mode.appendChild(document.createTextNode("mode: "+j.mode));
e.appendChild(mode);
var pending = document.createElement("div");
pending.setAttribute("class", "pending");
// pending articles
var articles = Object.keys(j.pending);
pending.appendChild(document.createTextNode("pending articles: "+articles.length));
for ( var idx = 0 ; idx < articles.length; idx ++ ) {
var msgid = articles[idx];
var state = j.pending[msgid];
var elem = document.createElement("div");
elem.appendChild(document.createTextNode(msgid + ": " + state));
elem.setAttribute("class", "pending_item "+state);
pending.appendChild(elem);
}
e.appendChild(pending);
// e.appendChild(document.createTextNode(JSON.stringify(j)));
return e;
}
function inject_nntp_feed_element(feed, elem) {
elem.appendChild(document.createElement("hr"));
var name = document.createElement("div");
name.setAttribute("class", "feeds_name");
name_elem = document.createTextNode("Name: "+feed.State.Config.Name);
name.appendChild(name_elem);
elem.appendChild(name);
var conns = document.createElement("div");
conns.setAttribute("class", "connections");
for ( var idx = 0 ; idx < feed.Conns.length; idx ++ ) {
conns.appendChild(createConnectionElement(feed.Conns[idx]));
}
elem.appendChild(conns);
}
function update_nntpchan_feed_ticker(elem) {
nntpchan_admin("feed.list", null, function(j) {
if (j) {
if (j.error) {
console.log("nntpchan_feed_ticker: error, "+j.error);
} else {
// remove all children
while(elem.children.length) {
elem.children[0].remove();
}
var result = j.result;
for (var idx = 0; idx < result.length; idx++) {
var item = result[idx];
var entry = document.createElement("div");
inject_nntp_feed_element(item, entry);
elem.appendChild(entry);
}
}
}
});
}
function nntpchan_mod(mod_action) {
// get the element // get the element
var input = document.getElementById("nntpchan_mod_target"); var input = document.getElementById("nntpchan_mod_target");
@ -226,8 +150,13 @@ function nntpchan_mod(mod_action) {
if (mod_action.parser) { if (mod_action.parser) {
target = mod_action.parser(target); target = mod_action.parser(target);
} }
var elem;
var elem = document.getElementById("nntpchan_mod_result"); if (result_elem) {
elem = result_elem;
} else {
elem = document.getElementById("nntpchan_mod_result");
}
// clear old results // clear old results
while( elem.firstChild ) { while( elem.firstChild ) {
elem.removeChild(elem.firstChild); elem.removeChild(elem.firstChild);

View File

@ -0,0 +1,41 @@
{{!
modpage.mustache -- the moderator panel when logged in
template parameters:
- prefix ( the site's prefix )
}}
<html>
<head>
<link rel="stylesheet" href="{{prefix}}static/site.css" />
<link id="current_theme" rel="stylesheet" href="{{prefix}}static/user.css" />
<!-- yes it uses js -->
<script type="text/javascript" src="{{prefix}}static/nntpchan.js"></script>
<script type="text/javascript" src="{{prefix}}static/mod.js"></script>
<script type="text/javascript" src="{{prefix}}static/feed.js"></script>
<title> {{#i18n.Translations}}{{modpage_title}}{{/i18n.Translations}} </title>
</head>
<body onload="main()">
<div id="nntpchan_mod_result"></div>
<div class="nntpchan_feed_pane">
<pre> Add Feed </pre>
<label for="add_feed_host">Host</label>
<input id="add_feed_host" />
<label for="add_feed_host">Port</label>
<input id="add_feed_port" />
<label for="add_feed_name">Name</label>
<input id="add_feed_name" />
<button onclick="nntp_feed_add()">Add</button>
</div>
<div class="nntpchan_feed_pane">
<pre> Remove Feed </pre>
<label for="del_feed_name">Name</label>
<input id="del_feed_name" />
<button onclick="nntp_feed_del()">Remove</button>
</div>
<div id="nntpchan_feed_result"></div>
<div id="nntpchan_feeds" onload="nntp_feed_update()"></div>
<noscript>
<b>{{#i18n.Translations}}{{nojs_info}}{{/i18n.Translations}}</b>
</noscript>
</body>
</html>

View File

@ -98,16 +98,6 @@
</div> </div>
</div> </div>
<div id="nntpchan_mod_result"></div> <div id="nntpchan_mod_result"></div>
<div id="nntpchan_feeds"></div>
<script>
// start nntp feed stats ticker
var e = document.getElementById("nntpchan_feeds");
if (e) {
setInterval(function() {
update_nntpchan_feed_ticker(e);
}, 2000);
}
</script>
<noscript> <noscript>
<b>{{#i18n.Translations}}{{nojs_info}}{{/i18n.Translations}}</b> <b>{{#i18n.Translations}}{{nojs_info}}{{/i18n.Translations}}</b>
</noscript> </noscript>

11
package.json Normal file
View File

@ -0,0 +1,11 @@
{
"name": "nntpchan",
"author": "jeff",
"version": "0.0.0",
"gxDependencies": [
],
"language": "go",
"issues_url": "https://github.com/majestrate/nntpchan",
"gx_version": "0.4.0",
"gx": {}
}

97
srnd.go Normal file
View File

@ -0,0 +1,97 @@
package main
import (
"fmt"
"github.com/majestrate/srndv2/src/srnd"
"log"
"os"
"os/signal"
"syscall"
)
func main() {
daemon := new(srnd.NNTPDaemon)
if len(os.Args) > 1 {
action := os.Args[1]
if action == "setup" {
log.Println("Setting up SRNd base...")
daemon.Setup()
log.Println("Setup Done")
} else if action == "run" {
log.Printf("Starting up %s...", srnd.Version())
daemon.Setup()
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt)
signal.Notify(c, syscall.SIGTERM)
go func() {
<-c
log.Println("Shutting down...")
daemon.End()
os.Exit(0)
}()
daemon.Run()
} else if action == "tool" {
if len(os.Args) > 2 {
tool := os.Args[2]
if tool == "mod" {
if len(os.Args) >= 5 {
action := os.Args[3]
if action == "add" {
pk := os.Args[4]
daemon.Setup()
db := daemon.GetDatabase()
err := db.MarkModPubkeyGlobal(pk)
if err != nil {
log.Fatal(err)
}
} else if action == "del" {
pk := os.Args[4]
daemon.Setup()
db := daemon.GetDatabase()
err := db.UnMarkModPubkeyGlobal(pk)
if err != nil {
log.Fatal(err)
}
}
} else {
fmt.Fprintf(os.Stdout, "usage: %s tool mod [add|del] pubkey\n", os.Args[0])
}
} else if tool == "rethumb" {
srnd.ThumbnailTool()
} else if tool == "keygen" {
srnd.KeygenTool()
} else if tool == "nntp" {
if len(os.Args) >= 5 {
action := os.Args[3]
if action == "del-login" {
daemon.Setup()
daemon.DelNNTPLogin(os.Args[4])
} else if action == "add-login" {
if len(os.Args) == 6 {
username := os.Args[4]
passwd := os.Args[5]
daemon.Setup()
daemon.AddNNTPLogin(username, passwd)
} else {
fmt.Fprintf(os.Stdout, "Usage: %s tool nntp add-login username password\n", os.Args[0])
}
} else {
fmt.Fprintf(os.Stdout, "Usage: %s tool nntp [add-login|del-login]\n", os.Args[0])
}
} else {
fmt.Fprintf(os.Stdout, "Usage: %s tool nntp [add-login|del-login]\n", os.Args[0])
}
} else {
fmt.Fprintf(os.Stdout, "Usage: %s tool [rethumb|keygen|nntp|mod]\n", os.Args[0])
}
} else {
fmt.Fprintf(os.Stdout, "Usage: %s tool [rethumb|keygen|nntp|mod]\n", os.Args[0])
}
} else {
log.Println("Invalid action:", action)
}
} else {
fmt.Fprintf(os.Stdout, "Usage: %s [setup|run|tool]\n", os.Args[0])
}
}