mirror of
https://github.com/jwinterm/node-tip-bot.git
synced 2026-10-17 05:41:42 +02:00
added work in progress webadmin
This commit is contained in:
@@ -29,6 +29,12 @@ IRC network connection and login info.
|
|||||||
## channels
|
## channels
|
||||||
List of channels to auto-join to.
|
List of channels to auto-join to.
|
||||||
|
|
||||||
|
## webadmin
|
||||||
|
Web interface settings.
|
||||||
|
* **enabled** - enabled web admin
|
||||||
|
* **port** - port to bound to
|
||||||
|
* **users** - list of users with access to web interface in `name: password` format
|
||||||
|
|
||||||
## log
|
## log
|
||||||
Logging settings.
|
Logging settings.
|
||||||
* **file** - file to log to. Set to `false` to disable logging to file.
|
* **file** - file to log to. Set to `false` to disable logging to file.
|
||||||
@@ -85,3 +91,4 @@ To run the bot simply use `npm start` or `node bin/tipbot`.
|
|||||||
Donations are welcome! If you like my bot and want to donate me, here are my wallet addresses:
|
Donations are welcome! If you like my bot and want to donate me, here are my wallet addresses:
|
||||||
|
|
||||||
* **Dogecoin**: DGLT1pTSKAXLSSSz1NGFgZNLioDyHdaDyA
|
* **Dogecoin**: DGLT1pTSKAXLSSSz1NGFgZNLioDyHdaDyA
|
||||||
|
* **Flappycoin**: FPEBPCC1sr9FAJ4DbD3r4YFwMqrr9TppeK
|
||||||
|
|||||||
+18
-1
@@ -2,13 +2,23 @@ var irc = require('irc')
|
|||||||
, winston = require('winston')
|
, winston = require('winston')
|
||||||
, fs = require('fs')
|
, fs = require('fs')
|
||||||
, yaml = require('js-yaml')
|
, yaml = require('js-yaml')
|
||||||
, coin = require('node-dogecoin');
|
, coin = require('node-dogecoin')
|
||||||
|
, webadmin = require('../lib/webadmin/app');
|
||||||
|
|
||||||
|
// check if the config file exists
|
||||||
if(!fs.existsSync('./config/config.yml')) {
|
if(!fs.existsSync('./config/config.yml')) {
|
||||||
winston.error('Configuration file doesn\'t exist! Please read the README.md file first.');
|
winston.error('Configuration file doesn\'t exist! Please read the README.md file first.');
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// handle sigint
|
||||||
|
process.on('exit', function() {
|
||||||
|
winston.info('Exiting...');
|
||||||
|
if(client != null) {
|
||||||
|
client.disconnect('My master ordered me to leave.');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// load settings
|
// load settings
|
||||||
var settings = yaml.load(fs.readFileSync('./config/config.yml', 'utf-8'));
|
var settings = yaml.load(fs.readFileSync('./config/config.yml', 'utf-8'));
|
||||||
|
|
||||||
@@ -43,6 +53,13 @@ coin.getBalance(function(err, balance) {
|
|||||||
winston.info('Connected to JSON RPC API. Current total balance is %d' + settings.coin.short_name, balance);
|
winston.info('Connected to JSON RPC API. Current total balance is %d' + settings.coin.short_name, balance);
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// run webadmin
|
||||||
|
if(settings.webadmin.enabled)
|
||||||
|
{
|
||||||
|
winston.info('Running webadmin on port %d', settings.webadmin.port);
|
||||||
|
webadmin.app(settings.webadmin.port, coin, settings.webadmin, winston);
|
||||||
|
}
|
||||||
|
|
||||||
// connect to the server
|
// connect to the server
|
||||||
winston.info('Connecting to the server...');
|
winston.info('Connecting to the server...');
|
||||||
|
|
||||||
|
|||||||
@@ -25,6 +25,12 @@ coin:
|
|||||||
min_tip: 10
|
min_tip: 10
|
||||||
short_name: Đ
|
short_name: Đ
|
||||||
full_name: dogecoin
|
full_name: dogecoin
|
||||||
|
webadmin:
|
||||||
|
enabled: false
|
||||||
|
port: 8080
|
||||||
|
users:
|
||||||
|
unek: 123
|
||||||
|
nix: 456
|
||||||
commands:
|
commands:
|
||||||
help:
|
help:
|
||||||
pm: true
|
pm: true
|
||||||
|
|||||||
@@ -0,0 +1,43 @@
|
|||||||
|
var express = require('express')
|
||||||
|
, swig = require('swig');
|
||||||
|
|
||||||
|
module.exports.app = function(port, coin, settings, winston) {
|
||||||
|
var app = express();
|
||||||
|
|
||||||
|
app.use(express.basicAuth(function(user, password) {
|
||||||
|
var success = settings.users[user] == password;
|
||||||
|
if(success)
|
||||||
|
winston.info('%s logged into webadmin', user);
|
||||||
|
else
|
||||||
|
winston.warn('Failed webadmin login as %s', user);
|
||||||
|
|
||||||
|
return success;
|
||||||
|
}));
|
||||||
|
|
||||||
|
var tpl = swig.compileFile(__dirname + '/views/index.html');
|
||||||
|
app.get('/', function(req, res) {
|
||||||
|
var accounts = [];
|
||||||
|
coin.listAccounts(5, function(err, reply) {
|
||||||
|
if(err) {
|
||||||
|
winston.error('Tried to get account listing but failed.', err);
|
||||||
|
res.send(500, 'Could not get account list');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for(var user in reply) {
|
||||||
|
if(user !== "")
|
||||||
|
accounts.push({nick: user, balance: reply[user]});
|
||||||
|
};
|
||||||
|
|
||||||
|
accounts.sort(function(a, b) {
|
||||||
|
return b.balance - a.balance
|
||||||
|
});
|
||||||
|
|
||||||
|
var body = tpl({accounts: accounts});
|
||||||
|
res.setHeader('Content-Type', 'text/html');
|
||||||
|
res.setHeader('Content-Length', Buffer.byteLength(body));
|
||||||
|
res.end(body);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
app.listen(port);
|
||||||
|
}
|
||||||
@@ -0,0 +1,67 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
|
<title>Tip bot webadmin</title>
|
||||||
|
|
||||||
|
<link href="http://bootswatch.com/lumen/bootstrap.min.css" rel="stylesheet">
|
||||||
|
|
||||||
|
<!--[if lt IE 9]>
|
||||||
|
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
|
||||||
|
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
|
||||||
|
<![endif]-->
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<nav class="navbar navbar-default" role="navigation">
|
||||||
|
<div class="container">
|
||||||
|
<div class="navbar-header">
|
||||||
|
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-2">
|
||||||
|
<span class="sr-only">Toggle navigation</span>
|
||||||
|
<span class="icon-bar"></span>
|
||||||
|
<span class="icon-bar"></span>
|
||||||
|
<span class="icon-bar"></span>
|
||||||
|
</button>
|
||||||
|
<a class="navbar-brand" href="#">Tip bot webadmin</a>
|
||||||
|
</div>
|
||||||
|
<div class="collapse navbar-collapse">
|
||||||
|
<form class="navbar-form navbar-right" role="search" action="/user" method="get">
|
||||||
|
<div class="input-group">
|
||||||
|
<input type="text" class="form-control" placeholder="Search user...">
|
||||||
|
<div class="input-group-btn">
|
||||||
|
<button type="submit" class="btn btn-default">
|
||||||
|
<span class="glyphicon glyphicon glyphicon-search"></span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</nav>
|
||||||
|
<div class="container">
|
||||||
|
<div class="col-md-8 col-sm-12">
|
||||||
|
<div class="page-header">
|
||||||
|
<h1>Overview <small>Balances</small></h1>
|
||||||
|
</div>
|
||||||
|
<table class="table table-striped">
|
||||||
|
<tr>
|
||||||
|
<th>#</th>
|
||||||
|
<th>Nick</th>
|
||||||
|
<th>Balance</th>
|
||||||
|
</tr>
|
||||||
|
{% for account in accounts %}
|
||||||
|
<tr>
|
||||||
|
<td>{{ loop.index }}</td>
|
||||||
|
<td>{{ account.nick }}</td>
|
||||||
|
<td>{{ account.balance }}</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-4 col-sm-12">
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
+3
-1
@@ -7,7 +7,9 @@
|
|||||||
"irc": "~0.3.6",
|
"irc": "~0.3.6",
|
||||||
"js-yaml": "~3.0.1",
|
"js-yaml": "~3.0.1",
|
||||||
"winston": "~0.7.2",
|
"winston": "~0.7.2",
|
||||||
"node-dogecoin": "~0.3.5"
|
"node-dogecoin": "~0.3.5",
|
||||||
|
"swig": "^1.3.2",
|
||||||
|
"express": "3.4.8"
|
||||||
},
|
},
|
||||||
"devDependencies": {},
|
"devDependencies": {},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
Reference in New Issue
Block a user