mirror of
https://github.com/KevinMidboe/zoff.git
synced 2025-10-29 01:40:24 +00:00
Prettified som more files and fixed some logging of missing files so they are more similar in fashion
This commit is contained in:
@@ -1,17 +1,16 @@
|
||||
var cluster = require('cluster'),
|
||||
net = require('net'),
|
||||
path = require('path'),
|
||||
var cluster = require("cluster"),
|
||||
net = require("net"),
|
||||
path = require("path"),
|
||||
//publicPath = path.join(__dirname, 'public'),
|
||||
http = require('http'),
|
||||
http = require("http"),
|
||||
port = 8080,
|
||||
//farmhash = require('farmhash'),
|
||||
uniqid = require('uniqid'),
|
||||
num_processes = require('os').cpus().length;
|
||||
uniqid = require("uniqid"),
|
||||
num_processes = require("os").cpus().length;
|
||||
|
||||
publicPath = path.join(__dirname, 'public');
|
||||
publicPath = path.join(__dirname, "public");
|
||||
pathThumbnails = __dirname;
|
||||
|
||||
|
||||
try {
|
||||
var redis = require("redis");
|
||||
var client = redis.createClient({ host: "localhost", port: 6379 });
|
||||
@@ -37,12 +36,12 @@ function startClustered(redis_enabled) {
|
||||
var workers = [];
|
||||
var spawn = function(i) {
|
||||
workers[i] = cluster.fork();
|
||||
workers[i].on('exit', function(code, signal) {
|
||||
workers[i].on("exit", function(code, signal) {
|
||||
if (code == 1) {
|
||||
process.exit(1);
|
||||
return;
|
||||
}
|
||||
console.log('respawning worker', i);
|
||||
console.log("respawning worker", i);
|
||||
spawn(i);
|
||||
});
|
||||
};
|
||||
@@ -53,7 +52,7 @@ function startClustered(redis_enabled) {
|
||||
|
||||
var worker_index = function(ip, len) {
|
||||
//console.log(ip);
|
||||
var s = '';
|
||||
var s = "";
|
||||
if (ip == undefined) ip = uniqid.time();
|
||||
for (var i = 0, _len = ip.length; i < _len; i++) {
|
||||
if (!isNaN(ip[i])) {
|
||||
@@ -64,10 +63,13 @@ function startClustered(redis_enabled) {
|
||||
//eturn farmhash.fingerprint32(ip) % len;
|
||||
};
|
||||
|
||||
var server = net.createServer({ pauseOnConnect: true }, function(connection, a) {
|
||||
var worker = workers[worker_index(connection.remoteAddress, num_processes)];
|
||||
worker.send('sticky-session:connection', connection);
|
||||
}).listen(port);
|
||||
var server = net
|
||||
.createServer({ pauseOnConnect: true }, function(connection, a) {
|
||||
var worker =
|
||||
workers[worker_index(connection.remoteAddress, num_processes)];
|
||||
worker.send("sticky-session:connection", connection);
|
||||
})
|
||||
.listen(port);
|
||||
} else {
|
||||
startSingle(true, redis_enabled);
|
||||
}
|
||||
@@ -75,10 +77,13 @@ function startClustered(redis_enabled) {
|
||||
|
||||
function startSingle(clustered, redis_enabled) {
|
||||
var server;
|
||||
var client = require('./apps/client.js');
|
||||
var client = require("./apps/client.js");
|
||||
try {
|
||||
var cert_config = require(path.join(path.join(__dirname, 'config'), 'cert_config.js'));
|
||||
var fs = require('fs');
|
||||
var cert_config = require(path.join(
|
||||
path.join(__dirname, "config"),
|
||||
"cert_config.js"
|
||||
));
|
||||
var fs = require("fs");
|
||||
var privateKey = fs.readFileSync(cert_config.privateKey).toString();
|
||||
var certificate = fs.readFileSync(cert_config.certificate).toString();
|
||||
var ca = fs.readFileSync(cert_config.ca).toString();
|
||||
@@ -87,7 +92,7 @@ function startSingle(clustered, redis_enabled) {
|
||||
cert: certificate,
|
||||
ca: ca
|
||||
};
|
||||
var https = require('https');
|
||||
var https = require("https");
|
||||
server = https.Server(credentials, routingFunction);
|
||||
} catch (err) {
|
||||
console.log("Starting without https (probably on localhost)");
|
||||
@@ -103,20 +108,20 @@ function startSingle(clustered, redis_enabled) {
|
||||
var socketIO = client.socketIO;
|
||||
|
||||
if (redis_enabled) {
|
||||
var redis = require('socket.io-redis');
|
||||
var redis = require("socket.io-redis");
|
||||
try {
|
||||
socketIO.adapter(redis({ host: 'localhost', port: 6379 }));
|
||||
socketIO.adapter(redis({ host: "localhost", port: 6379 }));
|
||||
} catch (e) {
|
||||
console.log("No redis-server to connect to..");
|
||||
}
|
||||
}
|
||||
socketIO.listen(server);
|
||||
|
||||
process.on('message', function(message, connection) {
|
||||
if (message !== 'sticky-session:connection') {
|
||||
process.on("message", function(message, connection) {
|
||||
if (message !== "sticky-session:connection") {
|
||||
return;
|
||||
}
|
||||
server.emit('connection', connection);
|
||||
server.emit("connection", connection);
|
||||
connection.resume();
|
||||
});
|
||||
}
|
||||
@@ -126,11 +131,15 @@ function onListen() {
|
||||
}
|
||||
|
||||
function routingFunction(req, res, next) {
|
||||
var client = require('./apps/client.js');
|
||||
var admin = require('./apps/admin.js');
|
||||
var client = require("./apps/client.js");
|
||||
var admin = require("./apps/admin.js");
|
||||
try {
|
||||
var url = req.headers['x-forwarded-host'] ? req.headers['x-forwarded-host'] : req.headers.host.split(":")[0];
|
||||
var subdomain = req.headers['x-forwarded-host'] ? req.headers['x-forwarded-host'].split(".") : req.headers.host.split(":")[0].split(".");
|
||||
var url = req.headers["x-forwarded-host"]
|
||||
? req.headers["x-forwarded-host"]
|
||||
: req.headers.host.split(":")[0];
|
||||
var subdomain = req.headers["x-forwarded-host"]
|
||||
? req.headers["x-forwarded-host"].split(".")
|
||||
: req.headers.host.split(":")[0].split(".");
|
||||
|
||||
if (subdomain.length > 1 && subdomain[0] == "admin") {
|
||||
admin(req, res, next);
|
||||
@@ -140,7 +149,7 @@ function routingFunction(req, res, next) {
|
||||
} catch (e) {
|
||||
console.log("Bad request for " + req.headers.host + req.url, e);
|
||||
res.statusCode = 500;
|
||||
res.write('Bad request'); //write a response to the client
|
||||
res.write("Bad request"); //write a response to the client
|
||||
res.end(); //end the response
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,40 +1,39 @@
|
||||
var express = require('express');
|
||||
var express = require("express");
|
||||
var app = express();
|
||||
|
||||
const path = require('path');
|
||||
const publicPath = path.join(__dirname + "", '../public');
|
||||
var exphbs = require('express-handlebars');
|
||||
const path = require("path");
|
||||
const publicPath = path.join(__dirname + "", "../public");
|
||||
var exphbs = require("express-handlebars");
|
||||
var hbs = exphbs.create({
|
||||
defaultLayout: publicPath + '/layouts/admin/main',
|
||||
layoutsDir: publicPath + '/layouts',
|
||||
partialsDir: publicPath + '/partials'
|
||||
defaultLayout: publicPath + "/layouts/admin/main",
|
||||
layoutsDir: publicPath + "/layouts",
|
||||
partialsDir: publicPath + "/partials"
|
||||
});
|
||||
|
||||
var passport = require('passport');
|
||||
var mpromise = require('mpromise');
|
||||
var LocalStrategy = require('passport-local').Strategy;
|
||||
var mongoose = require('mongoose');
|
||||
var mongo_db_cred = require(pathThumbnails + '/config/mongo_config.js');
|
||||
var mongojs = require('mongojs');
|
||||
var passport = require("passport");
|
||||
var mpromise = require("mpromise");
|
||||
var LocalStrategy = require("passport-local").Strategy;
|
||||
var mongoose = require("mongoose");
|
||||
var mongo_db_cred = require(pathThumbnails + "/config/mongo_config.js");
|
||||
var mongojs = require("mongojs");
|
||||
var db = mongojs(mongo_db_cred.config);
|
||||
var token_db = mongojs("tokens");
|
||||
var bodyParser = require('body-parser');
|
||||
var session = require('express-session');
|
||||
var MongoStore = require('connect-mongo')(session);
|
||||
var api = require(pathThumbnails + '/routing/admin/api.js');
|
||||
var bodyParser = require("body-parser");
|
||||
var session = require("express-session");
|
||||
var MongoStore = require("connect-mongo")(session);
|
||||
var api = require(pathThumbnails + "/routing/admin/api.js");
|
||||
|
||||
var compression = require('compression');
|
||||
var User = require(pathThumbnails + '/models/user.js');
|
||||
var url = 'mongodb://' + mongo_db_cred.host + '/' + mongo_db_cred.users;
|
||||
var compression = require("compression");
|
||||
var User = require(pathThumbnails + "/models/user.js");
|
||||
var url = "mongodb://" + mongo_db_cred.host + "/" + mongo_db_cred.users;
|
||||
mongoose.connect(url);
|
||||
|
||||
|
||||
app.engine('handlebars', hbs.engine);
|
||||
app.set('view engine', 'handlebars');
|
||||
app.use(compression({filter: shouldCompress}))
|
||||
app.engine("handlebars", hbs.engine);
|
||||
app.set("view engine", "handlebars");
|
||||
app.use(compression({ filter: shouldCompress }));
|
||||
|
||||
function shouldCompress(req, res) {
|
||||
if (req.headers['x-no-compression']) {
|
||||
if (req.headers["x-no-compression"]) {
|
||||
// don't compress responses with this request header
|
||||
return false;
|
||||
}
|
||||
@@ -42,14 +41,15 @@ function shouldCompress (req, res) {
|
||||
// fallback to standard filter function
|
||||
return compression.filter(req, res);
|
||||
}
|
||||
app.set('trust proxy', '127.0.0.1');
|
||||
app.set("trust proxy", "127.0.0.1");
|
||||
|
||||
var bodyParser = require('body-parser');
|
||||
var bodyParser = require("body-parser");
|
||||
var cookieParser = require("cookie-parser");
|
||||
var referrerPolicy = require('referrer-policy');
|
||||
var helmet = require('helmet');
|
||||
var featurePolicy = require('feature-policy');
|
||||
app.use(featurePolicy({
|
||||
var referrerPolicy = require("referrer-policy");
|
||||
var helmet = require("helmet");
|
||||
var featurePolicy = require("feature-policy");
|
||||
app.use(
|
||||
featurePolicy({
|
||||
features: {
|
||||
fullscreen: ["*"],
|
||||
//vibrate: ["'none'"],
|
||||
@@ -57,31 +57,38 @@ app.use(featurePolicy({
|
||||
microphone: ["'none'"],
|
||||
camera: ["'none'"],
|
||||
speaker: ["*"],
|
||||
syncXhr: ["'self'"],
|
||||
syncXhr: ["'self'"]
|
||||
//notifications: ["'self'"]
|
||||
}
|
||||
}));
|
||||
app.use(helmet({
|
||||
frameguard: false,
|
||||
}));
|
||||
app.use(referrerPolicy({ policy: 'origin-when-cross-origin' }));
|
||||
app.enable('view cache');
|
||||
app.set('views', publicPath);
|
||||
})
|
||||
);
|
||||
app.use(
|
||||
helmet({
|
||||
frameguard: false
|
||||
})
|
||||
);
|
||||
app.use(referrerPolicy({ policy: "origin-when-cross-origin" }));
|
||||
app.enable("view cache");
|
||||
app.set("views", publicPath);
|
||||
app.use(bodyParser.json()); // to support JSON-encoded bodies
|
||||
app.use(bodyParser.urlencoded({
|
||||
app.use(
|
||||
bodyParser.urlencoded({
|
||||
extended: true
|
||||
}));
|
||||
app.use(session({
|
||||
})
|
||||
);
|
||||
app.use(
|
||||
session({
|
||||
secret: mongo_db_cred.secret,
|
||||
resave: true,
|
||||
saveUninitialized: true,
|
||||
store: new MongoStore({
|
||||
url: url,
|
||||
useNewUrlParser: true,
|
||||
collection: 'sessions',
|
||||
collection: "sessions",
|
||||
ttl: mongo_db_cred.expire
|
||||
})
|
||||
})); // session secret
|
||||
})
|
||||
); // session secret
|
||||
app.use(passport.initialize());
|
||||
app.use(passport.session()); // persistent login sessions
|
||||
|
||||
@@ -91,8 +98,6 @@ passport.serializeUser(function(user, done) {
|
||||
done(null, user.id);
|
||||
});
|
||||
|
||||
|
||||
|
||||
// used to deserialize the user
|
||||
passport.deserializeUser(function(id, done) {
|
||||
User.findById(id, function(err, user) {
|
||||
@@ -100,33 +105,37 @@ passport.deserializeUser(function(id, done) {
|
||||
});
|
||||
});
|
||||
|
||||
passport.use('local-signup', new LocalStrategy({
|
||||
passport.use(
|
||||
"local-signup",
|
||||
new LocalStrategy(
|
||||
{
|
||||
// by default, local strategy uses username and password, we will override with username
|
||||
usernameField : 'username',
|
||||
passwordField : 'password',
|
||||
usernameField: "username",
|
||||
passwordField: "password",
|
||||
passReqToCallback: true // allows us to pass back the entire request to the callback
|
||||
},
|
||||
function(req, username, password, done) {
|
||||
// asynchronous
|
||||
// User.findOne wont fire unless data is sent back
|
||||
process.nextTick(function() {
|
||||
|
||||
// find a user whose username is the same as the forms username
|
||||
// we are checking to see if the user trying to login already exists
|
||||
var token = req.body.token;
|
||||
token_db.collection("tokens").find({token: token}, function(err, docs){
|
||||
token_db
|
||||
.collection("tokens")
|
||||
.find({ token: token }, function(err, docs) {
|
||||
if (docs.length == 1) {
|
||||
token_db.collection("tokens").remove({token: token}, function(err, docs){
|
||||
User.findOne({ 'username' : username }, function(err, user) {
|
||||
token_db
|
||||
.collection("tokens")
|
||||
.remove({ token: token }, function(err, docs) {
|
||||
User.findOne({ username: username }, function(err, user) {
|
||||
// if there are any errors, return the error
|
||||
if (err)
|
||||
return done(err);
|
||||
if (err) return done(err);
|
||||
|
||||
// check to see if theres already a user with that username
|
||||
if (user) {
|
||||
return done(null, false);
|
||||
} else {
|
||||
|
||||
// if there is no user with that username
|
||||
// create the user
|
||||
var newUser = new User();
|
||||
@@ -137,12 +146,10 @@ function(req, username, password, done) {
|
||||
|
||||
// save the user
|
||||
newUser.save(function(err) {
|
||||
if (err)
|
||||
throw err;
|
||||
if (err) throw err;
|
||||
return done(null, newUser);
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
});
|
||||
} else {
|
||||
@@ -150,74 +157,84 @@ function(req, username, password, done) {
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
}));
|
||||
|
||||
passport.use('local-login', new LocalStrategy({
|
||||
passport.use(
|
||||
"local-login",
|
||||
new LocalStrategy(
|
||||
{
|
||||
// by default, local strategy uses username and password, we will override with email
|
||||
usernameField : 'username',
|
||||
passwordField : 'password',
|
||||
usernameField: "username",
|
||||
passwordField: "password",
|
||||
passReqToCallback: true // allows us to pass back the entire request to the callback
|
||||
}, function(req, username, password, done) { // callback with email and password from our form
|
||||
},
|
||||
function(req, username, password, done) {
|
||||
// callback with email and password from our form
|
||||
|
||||
// find a user whose email is the same as the forms email
|
||||
// we are checking to see if the user trying to login already exists
|
||||
User.findOne({ 'username' : username }, function(err, user) {
|
||||
User.findOne({ username: username }, function(err, user) {
|
||||
// if there are any errors, return the error before anything else
|
||||
if (err)
|
||||
return done(err);
|
||||
if (err) return done(err);
|
||||
|
||||
// if no user is found, return the message
|
||||
if (!user)
|
||||
return done(null, false); // req.flash is the way to set flashdata using connect-flash
|
||||
if (!user) return done(null, false); // req.flash is the way to set flashdata using connect-flash
|
||||
|
||||
// if the user is found but the password is wrong
|
||||
if (!user.validPassword(password))
|
||||
return done(null, false); // create the loginMessage and save it to session as flashdata
|
||||
if (!user.validPassword(password)) return done(null, false); // create the loginMessage and save it to session as flashdata
|
||||
|
||||
// all is well, return successful user
|
||||
|
||||
return done(null, user);
|
||||
});
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
}));
|
||||
|
||||
app.post('/signup', passport.authenticate('local-signup', {
|
||||
successRedirect : '/', // redirect to the secure profile section
|
||||
failureRedirect : '/signup', // redirect back to the signup page if there is an error
|
||||
app.post(
|
||||
"/signup",
|
||||
passport.authenticate("local-signup", {
|
||||
successRedirect: "/", // redirect to the secure profile section
|
||||
failureRedirect: "/signup", // redirect back to the signup page if there is an error
|
||||
failureFlash: true // allow flash messages
|
||||
}));
|
||||
})
|
||||
);
|
||||
|
||||
app.post('/login', passport.authenticate('local-login', {
|
||||
successRedirect : '/', // redirect to the secure profile section
|
||||
failureRedirect : '/login#failed', // redirect back to the signup page if there is an error
|
||||
app.post(
|
||||
"/login",
|
||||
passport.authenticate("local-login", {
|
||||
successRedirect: "/", // redirect to the secure profile section
|
||||
failureRedirect: "/login#failed", // redirect back to the signup page if there is an error
|
||||
failureFlash: true // allow flash messages
|
||||
}));
|
||||
})
|
||||
);
|
||||
|
||||
app.use('/login', isLoggedInTryingToLogIn, function(req, res) {
|
||||
app.use("/login", isLoggedInTryingToLogIn, function(req, res) {
|
||||
var data = {
|
||||
where_get: "not_authenticated"
|
||||
};
|
||||
|
||||
res.render('layouts/admin/not_authenticated', data);
|
||||
res.render("layouts/admin/not_authenticated", data);
|
||||
});
|
||||
|
||||
app.use('/signup', isLoggedInTryingToLogIn, function(req, res) {
|
||||
app.use("/signup", isLoggedInTryingToLogIn, function(req, res) {
|
||||
var data = {
|
||||
where_get: "not_authenticated"
|
||||
};
|
||||
|
||||
res.render('layouts/admin/not_authenticated', data);
|
||||
res.render("layouts/admin/not_authenticated", data);
|
||||
});
|
||||
|
||||
app.use('/', api);
|
||||
app.use("/", api);
|
||||
|
||||
app.use('/logout', function(req, res) {
|
||||
app.use("/logout", function(req, res) {
|
||||
req.logout();
|
||||
res.redirect('/login');
|
||||
res.redirect("/login");
|
||||
});
|
||||
|
||||
app.use('/assets/admin/authenticated', function(req, res, next) {
|
||||
app.use("/assets/admin/authenticated", function(req, res, next) {
|
||||
if (!req.isAuthenticated()) {
|
||||
res.sendStatus(403);
|
||||
return;
|
||||
@@ -225,15 +242,15 @@ app.use('/assets/admin/authenticated', function(req, res, next) {
|
||||
return next();
|
||||
});
|
||||
|
||||
app.use('/assets', express.static(publicPath + '/assets'));
|
||||
app.use("/assets", express.static(publicPath + "/assets"));
|
||||
|
||||
app.use('/', isLoggedIn, function(req, res) {
|
||||
app.use("/", isLoggedIn, function(req, res) {
|
||||
var data = {
|
||||
where_get: "authenticated",
|
||||
year: new Date().getYear()+1900,
|
||||
year: new Date().getYear() + 1900
|
||||
};
|
||||
|
||||
res.render('layouts/admin/authenticated', data);
|
||||
res.render("layouts/admin/authenticated", data);
|
||||
});
|
||||
|
||||
function isLoggedInTryingToLogIn(req, res, next) {
|
||||
@@ -244,9 +261,8 @@ function isLoggedInTryingToLogIn(req, res, next){
|
||||
}
|
||||
|
||||
function isLoggedIn(req, res, next) {
|
||||
if (req.isAuthenticated())
|
||||
return next();
|
||||
res.redirect('/login');
|
||||
if (req.isAuthenticated()) return next();
|
||||
res.redirect("/login");
|
||||
}
|
||||
|
||||
//app.listen(default_port);
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
VERSION = require(pathThumbnails + '/VERSION.js');
|
||||
VERSION = require(pathThumbnails + "/VERSION.js");
|
||||
var secure = false;
|
||||
var path = require('path');
|
||||
var path = require("path");
|
||||
try {
|
||||
var cert_config = require(path.join(path.join(__dirname, '../config/'), 'cert_config.js'));
|
||||
var fs = require('fs');
|
||||
var cert_config = require(path.join(
|
||||
path.join(__dirname, "../config/"),
|
||||
"cert_config.js"
|
||||
));
|
||||
var fs = require("fs");
|
||||
var privateKey = fs.readFileSync(cert_config.privateKey).toString();
|
||||
var certificate = fs.readFileSync(cert_config.certificate).toString();
|
||||
var ca = fs.readFileSync(cert_config.ca).toString();
|
||||
@@ -16,37 +19,36 @@ try {
|
||||
} catch (err) {}
|
||||
|
||||
var add = "";
|
||||
var express = require('express');
|
||||
var express = require("express");
|
||||
var app = express();
|
||||
var compression = require('compression');
|
||||
var exphbs = require('express-handlebars');
|
||||
var cors = require('cors');
|
||||
var Functions = require(pathThumbnails + '/handlers/functions.js');
|
||||
var compression = require("compression");
|
||||
var exphbs = require("express-handlebars");
|
||||
var cors = require("cors");
|
||||
var Functions = require(pathThumbnails + "/handlers/functions.js");
|
||||
|
||||
var hbs = exphbs.create({
|
||||
defaultLayout: publicPath + '/layouts/client/main',
|
||||
layoutsDir: publicPath + '/layouts/client',
|
||||
partialsDir: publicPath + '/partials',
|
||||
defaultLayout: publicPath + "/layouts/client/main",
|
||||
layoutsDir: publicPath + "/layouts/client",
|
||||
partialsDir: publicPath + "/partials",
|
||||
helpers: {
|
||||
if_equal: function(a, b, opts) {
|
||||
if (a == b) {
|
||||
return opts.fn(this)
|
||||
return opts.fn(this);
|
||||
} else {
|
||||
return opts.inverse(this)
|
||||
return opts.inverse(this);
|
||||
}
|
||||
},
|
||||
decodeString: function(s) {
|
||||
if (s == undefined) return s;
|
||||
return Functions.decodeChannelName(s);
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
var uniqid = require('uniqid');
|
||||
app.use(compression({filter: shouldCompress}))
|
||||
var uniqid = require("uniqid");
|
||||
app.use(compression({ filter: shouldCompress }));
|
||||
|
||||
function shouldCompress(req, res) {
|
||||
if (req.headers['x-no-compression']) {
|
||||
if (req.headers["x-no-compression"]) {
|
||||
// don't compress responses with this request header
|
||||
return false;
|
||||
}
|
||||
@@ -55,18 +57,19 @@ function shouldCompress (req, res) {
|
||||
return compression.filter(req, res);
|
||||
}
|
||||
|
||||
app.engine('handlebars', hbs.engine);
|
||||
app.set('view engine', 'handlebars');
|
||||
app.enable('view cache');
|
||||
app.set('views', publicPath);
|
||||
app.set('trust proxy', '127.0.0.1');
|
||||
app.engine("handlebars", hbs.engine);
|
||||
app.set("view engine", "handlebars");
|
||||
app.enable("view cache");
|
||||
app.set("views", publicPath);
|
||||
app.set("trust proxy", "127.0.0.1");
|
||||
|
||||
var bodyParser = require('body-parser');
|
||||
var bodyParser = require("body-parser");
|
||||
var cookieParser = require("cookie-parser");
|
||||
var referrerPolicy = require('referrer-policy');
|
||||
var helmet = require('helmet');
|
||||
var featurePolicy = require('feature-policy');
|
||||
app.use(featurePolicy({
|
||||
var referrerPolicy = require("referrer-policy");
|
||||
var helmet = require("helmet");
|
||||
var featurePolicy = require("feature-policy");
|
||||
app.use(
|
||||
featurePolicy({
|
||||
features: {
|
||||
fullscreen: ["*"],
|
||||
//vibrate: ["'none'"],
|
||||
@@ -74,112 +77,131 @@ app.use(featurePolicy({
|
||||
microphone: ["'none'"],
|
||||
camera: ["'none'"],
|
||||
speaker: ["*"],
|
||||
syncXhr: ["'self'"],
|
||||
syncXhr: ["'self'"]
|
||||
//notifications: ["'self'"]
|
||||
}
|
||||
}));
|
||||
app.use(helmet({
|
||||
frameguard: false,
|
||||
}));
|
||||
app.use(referrerPolicy({ policy: 'origin-when-cross-origin' }));
|
||||
})
|
||||
);
|
||||
app.use(
|
||||
helmet({
|
||||
frameguard: false
|
||||
})
|
||||
);
|
||||
app.use(referrerPolicy({ policy: "origin-when-cross-origin" }));
|
||||
app.use(bodyParser.json()); // to support JSON-encoded bodies
|
||||
app.use(bodyParser.urlencoded({ // to support URL-encoded bodies
|
||||
app.use(
|
||||
bodyParser.urlencoded({
|
||||
// to support URL-encoded bodies
|
||||
extended: true
|
||||
}));
|
||||
})
|
||||
);
|
||||
app.use(cookieParser());
|
||||
//app.set('json spaces', 2);
|
||||
|
||||
io = require('socket.io')({
|
||||
pingTimeout: 25000,
|
||||
io = require("socket.io")({
|
||||
pingTimeout: 25000
|
||||
//path: '/zoff',
|
||||
//"origins": ("https://zoff.me:443*,https://zoff.me:8080*,zoff.me:8080*,https://remote.zoff.me:443*,https://remote.zoff.me:8080*,https://fb.zoff.me:443*,https://fb.zoff.me:8080*,https://admin.zoff.me:443*,https://admin.zoff.me:8080*, http://localhost:8080*")});
|
||||
});
|
||||
|
||||
var socketIO = require(pathThumbnails +'/handlers/io.js');
|
||||
var socketIO = require(pathThumbnails + "/handlers/io.js");
|
||||
socketIO();
|
||||
|
||||
app.socketIO = io;
|
||||
|
||||
|
||||
/* Globally needed "libraries" and files */
|
||||
var router = require(pathThumbnails + '/routing/client/router.js');
|
||||
var api_file = require(pathThumbnails + '/routing/client/api.js');
|
||||
var router = require(pathThumbnails + "/routing/client/router.js");
|
||||
var api_file = require(pathThumbnails + "/routing/client/api.js");
|
||||
var api = api_file.router;
|
||||
api_file.sIO = app.socketIO;
|
||||
var ico_router = require(pathThumbnails + '/routing/client/icons_routing.js');
|
||||
var ico_router = require(pathThumbnails + "/routing/client/icons_routing.js");
|
||||
|
||||
app.get('/robots.txt', function (req, res) {
|
||||
res.type('text/plain');
|
||||
app.get("/robots.txt", function(req, res) {
|
||||
res.type("text/plain");
|
||||
res.send("User-agent: *\nAllow: /$\nDisallow: /");
|
||||
});
|
||||
|
||||
app.use(function(req, res, next) {
|
||||
var cookie = req.cookies._uI;
|
||||
var skipElements = ["/_embed", "/assets/manifest.json", "/apple-touch-icon.png"];
|
||||
var skipElements = [
|
||||
"/_embed",
|
||||
"/assets/manifest.json",
|
||||
"/apple-touch-icon.png"
|
||||
];
|
||||
if (skipElements.indexOf(req.originalUrl) > -1) {
|
||||
res.header("Access-Control-Allow-Origin", "*");
|
||||
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
|
||||
res.header(
|
||||
"Access-Control-Allow-Headers",
|
||||
"Origin, X-Requested-With, Content-Type, Accept"
|
||||
);
|
||||
next();
|
||||
} else {
|
||||
if (req.originalUrl.split("/").length > 3) {
|
||||
res.header("Access-Control-Allow-Origin", "*");
|
||||
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
|
||||
res.header(
|
||||
"Access-Control-Allow-Headers",
|
||||
"Origin, X-Requested-With, Content-Type, Accept"
|
||||
);
|
||||
next();
|
||||
} else {
|
||||
if (cookie === undefined) {
|
||||
try {
|
||||
//console.error((new Date), "originalUrl", req.originalUrl);
|
||||
//console.error((new Date), "couldn't fetch cookie for some reason, maybe no cookie exists?", req.get('origin'), "couldn't fetch cookie for some reason, maybe no cookie exists?");
|
||||
|
||||
} catch (e) {
|
||||
//console.error((new Date), "couldn't fetch origin");
|
||||
}
|
||||
var user_name = Functions.hash_pass(Functions.rndName(uniqid.time(), 15));
|
||||
res.cookie('_uI', user_name, {
|
||||
var user_name = Functions.hash_pass(
|
||||
Functions.rndName(uniqid.time(), 15)
|
||||
);
|
||||
res.cookie("_uI", user_name, {
|
||||
maxAge: 365 * 10000 * 3600000,
|
||||
httpOnly: true,
|
||||
secure: secure,
|
||||
secure: secure
|
||||
//sameSite: true,
|
||||
});
|
||||
} else {
|
||||
//process.stderr.write((new Date), "couldn't fetch cookie for some reason, maybe no cookie exists?", req, "couldn't fetch cookie for some reason, maybe no cookie exists?");
|
||||
res.cookie('_uI', cookie, {
|
||||
res.cookie("_uI", cookie, {
|
||||
maxAge: 365 * 10000 * 3600000,
|
||||
httpOnly: true,
|
||||
secure: secure,
|
||||
secure: secure
|
||||
//sameSite: true,
|
||||
});
|
||||
}
|
||||
res.header("Access-Control-Allow-Origin", "*");
|
||||
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
|
||||
res.header(
|
||||
"Access-Control-Allow-Headers",
|
||||
"Origin, X-Requested-With, Content-Type, Accept"
|
||||
);
|
||||
next();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
app.use('/service-worker.js', function(req, res) {
|
||||
res.sendFile(publicPath + '/service-worker.js');
|
||||
app.use("/service-worker.js", function(req, res) {
|
||||
res.sendFile(publicPath + "/service-worker.js");
|
||||
});
|
||||
|
||||
app.use('/', ico_router);
|
||||
app.use('/', api);
|
||||
app.use('/', cors(), router);
|
||||
app.use("/", ico_router);
|
||||
app.use("/", api);
|
||||
app.use("/", cors(), router);
|
||||
|
||||
app.use('/assets/js', function(req, res, next) {
|
||||
app.use("/assets/js", function(req, res, next) {
|
||||
res.sendStatus(403);
|
||||
return;
|
||||
});
|
||||
|
||||
app.use('/assets/admin', function(req, res, next) {
|
||||
app.use("/assets/admin", function(req, res, next) {
|
||||
res.sendStatus(403);
|
||||
return;
|
||||
});
|
||||
|
||||
app.use('/assets', express.static(publicPath + '/assets'));
|
||||
app.use("/assets", express.static(publicPath + "/assets"));
|
||||
|
||||
app.use(function(req, res, next) {
|
||||
res.status(404);
|
||||
res.redirect("/404");
|
||||
})
|
||||
});
|
||||
|
||||
module.exports = app;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
var api_key = {
|
||||
"youtube": "xxxx",
|
||||
"soundcloud": "xx",
|
||||
youtube: "xxxx",
|
||||
soundcloud: "xx" // This can be excluded if you don't have a soundcloud key
|
||||
};
|
||||
|
||||
try {
|
||||
|
||||
@@ -1,42 +1,45 @@
|
||||
var toShowConfig = {
|
||||
"addsongs": true,
|
||||
"adminpass": 1,
|
||||
"allvideos": 1,
|
||||
"frontpage": 1,
|
||||
"longsongs": 1,
|
||||
"removeplay": 1,
|
||||
"shuffle": 1,
|
||||
"skip": 1,
|
||||
"startTime": 1,
|
||||
"userpass": 1,
|
||||
"vote": 1,
|
||||
"toggleChat": { $ifNull: [ "$toggleChat", true ] },
|
||||
"strictSkip": { $ifNull: [ "$strictSkip", false ] },
|
||||
"strictSkipNumber": { $ifNull: [ "$strictSkipNumber", 10 ] },
|
||||
"description": { $ifNull: [ "$description", "" ] },
|
||||
"thumbnail": { $ifNull: [ "$thumbnail", "" ] },
|
||||
"rules": { $ifNull: [ "$rules", "" ] },
|
||||
"_id": 0
|
||||
addsongs: true,
|
||||
adminpass: 1,
|
||||
allvideos: 1,
|
||||
frontpage: 1,
|
||||
longsongs: 1,
|
||||
removeplay: 1,
|
||||
shuffle: 1,
|
||||
skip: 1,
|
||||
startTime: 1,
|
||||
userpass: 1,
|
||||
vote: 1,
|
||||
toggleChat: { $ifNull: ["$toggleChat", true] },
|
||||
strictSkip: { $ifNull: ["$strictSkip", false] },
|
||||
strictSkipNumber: { $ifNull: ["$strictSkipNumber", 10] },
|
||||
description: { $ifNull: ["$description", ""] },
|
||||
thumbnail: { $ifNull: ["$thumbnail", ""] },
|
||||
rules: { $ifNull: ["$rules", ""] },
|
||||
_id: 0
|
||||
};
|
||||
|
||||
var project_object = {
|
||||
"_id": 0,
|
||||
"id": 1,
|
||||
"added": 1,
|
||||
"now_playing": 1,
|
||||
"title": 1,
|
||||
"votes": 1,
|
||||
"start": 1,
|
||||
"duration": 1,
|
||||
"end": 1,
|
||||
"type": 1,
|
||||
"source": { $ifNull: [ "$source", "youtube" ] },
|
||||
"thumbnail": {
|
||||
$ifNull: [ "$thumbnail", {
|
||||
_id: 0,
|
||||
id: 1,
|
||||
added: 1,
|
||||
now_playing: 1,
|
||||
title: 1,
|
||||
votes: 1,
|
||||
start: 1,
|
||||
duration: 1,
|
||||
end: 1,
|
||||
type: 1,
|
||||
source: { $ifNull: ["$source", "youtube"] },
|
||||
thumbnail: {
|
||||
$ifNull: [
|
||||
"$thumbnail",
|
||||
{
|
||||
$concat: ["https://img.youtube.com/vi/", "$id", "/mqdefault.jpg"]
|
||||
} ]
|
||||
}
|
||||
]
|
||||
},
|
||||
"tags": { $ifNull: [ "$tags", [] ] },
|
||||
tags: { $ifNull: ["$tags", []] }
|
||||
};
|
||||
|
||||
var toShowChannel = {
|
||||
@@ -53,7 +56,7 @@ var toShowChannel = {
|
||||
now_playing: 1,
|
||||
type: 1,
|
||||
source: 1,
|
||||
thumbnail: 1,
|
||||
thumbnail: 1
|
||||
};
|
||||
|
||||
module.exports.project_object = project_object;
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,39 +1,84 @@
|
||||
var path = require('path');
|
||||
var path = require("path");
|
||||
try {
|
||||
var mongo_config = require(path.join(path.join(__dirname, '../config/'), 'mongo_config.js'));
|
||||
var mongo_config = require(path.join(
|
||||
path.join(__dirname, "../config/"),
|
||||
"mongo_config.js"
|
||||
));
|
||||
} catch (e) {
|
||||
console.log("Error - missing file");
|
||||
console.log("Seems you forgot to create the file mongo_config.js in /server/config/. Have a look at mongo_config.example.js.");
|
||||
console.log(
|
||||
"(!) Missing file - /config/mongo_config.js. Have a look at /config/mongo_config.example.js. The server won't run without this existing."
|
||||
);
|
||||
process.exit(1);
|
||||
}
|
||||
var mongojs = require('mongojs');
|
||||
var db = mongojs('mongodb://' + mongo_config.host + '/' + mongo_config.config);
|
||||
var connected_db = mongojs('mongodb://' + mongo_config.host + '/user_credentials');
|
||||
var mongojs = require("mongojs");
|
||||
var db = mongojs("mongodb://" + mongo_config.host + "/" + mongo_config.config);
|
||||
var connected_db = mongojs(
|
||||
"mongodb://" + mongo_config.host + "/user_credentials"
|
||||
);
|
||||
var ObjectId = mongojs.ObjectId;
|
||||
|
||||
db.collection("chat_logs").createIndex({ "createdAt": 1 }, { expireAfterSeconds: 600 }, function(){});
|
||||
db.collection("timeout_api").createIndex({ "createdAt": 1 }, { expireAfterSeconds: 120 }, function(){});
|
||||
db.collection("api_links").createIndex({ "createdAt": 1 }, { expireAfterSeconds: 86400 }, function(){});
|
||||
db.on('connected', function(err) {
|
||||
db.collection("chat_logs").createIndex(
|
||||
{ createdAt: 1 },
|
||||
{ expireAfterSeconds: 600 },
|
||||
function() {}
|
||||
);
|
||||
db.collection("timeout_api").createIndex(
|
||||
{ createdAt: 1 },
|
||||
{ expireAfterSeconds: 120 },
|
||||
function() {}
|
||||
);
|
||||
db.collection("api_links").createIndex(
|
||||
{ createdAt: 1 },
|
||||
{ expireAfterSeconds: 86400 },
|
||||
function() {}
|
||||
);
|
||||
db.on("connected", function(err) {
|
||||
console.log("connected");
|
||||
});
|
||||
|
||||
db.on('error',function(err) {
|
||||
db.on("error", function(err) {
|
||||
console.log("\n" + new Date().toString() + "\n Database error: ", err);
|
||||
});
|
||||
|
||||
|
||||
db.on('error',function(err) {
|
||||
db.on("error", function(err) {
|
||||
console.log("\n" + new Date().toString() + "\n Database error: ", err);
|
||||
});
|
||||
|
||||
/* Resetting usernames, and connected users */
|
||||
db.collection("unique_ids").update({"_id": "unique_ids"}, {$set: {unique_ids: []}}, {multi: true, upsert: true}, function(err, docs){});
|
||||
db.collection("user_names").remove({"guid": {$exists: true}}, {multi: true, upsert: true}, function(err, docs){});
|
||||
db.collection("user_names").update({"_id": "all_names"}, {$set: {names: []}}, {multi: true, upsert: true}, function(err, docs){});
|
||||
db.collection("connected_users").update({users: {$exists: true}}, {$set: {users: []}}, {multi: true, upsert: true}, function(err, docs){});
|
||||
db.collection("connected_users").update({"_id": "total_users"}, {$set: {total_users: []}}, {multi: true, upsert: true}, function(err, docs) {});
|
||||
db.collection("frontpage_lists").update({viewers: {$ne: 0}}, {$set: {"viewers": 0}}, {multi: true, upsert: true}, function(err, docs) {});
|
||||
|
||||
db.collection("unique_ids").update(
|
||||
{ _id: "unique_ids" },
|
||||
{ $set: { unique_ids: [] } },
|
||||
{ multi: true, upsert: true },
|
||||
function(err, docs) {}
|
||||
);
|
||||
db.collection("user_names").remove(
|
||||
{ guid: { $exists: true } },
|
||||
{ multi: true, upsert: true },
|
||||
function(err, docs) {}
|
||||
);
|
||||
db.collection("user_names").update(
|
||||
{ _id: "all_names" },
|
||||
{ $set: { names: [] } },
|
||||
{ multi: true, upsert: true },
|
||||
function(err, docs) {}
|
||||
);
|
||||
db.collection("connected_users").update(
|
||||
{ users: { $exists: true } },
|
||||
{ $set: { users: [] } },
|
||||
{ multi: true, upsert: true },
|
||||
function(err, docs) {}
|
||||
);
|
||||
db.collection("connected_users").update(
|
||||
{ _id: "total_users" },
|
||||
{ $set: { total_users: [] } },
|
||||
{ multi: true, upsert: true },
|
||||
function(err, docs) {}
|
||||
);
|
||||
db.collection("frontpage_lists").update(
|
||||
{ viewers: { $ne: 0 } },
|
||||
{ $set: { viewers: 0 } },
|
||||
{ multi: true, upsert: true },
|
||||
function(err, docs) {}
|
||||
);
|
||||
|
||||
module.exports = db;
|
||||
|
||||
@@ -1,85 +1,112 @@
|
||||
var Functions = require(pathThumbnails + '/handlers/functions.js');
|
||||
var db = require(pathThumbnails + '/handlers/db.js');
|
||||
var Functions = require(pathThumbnails + "/handlers/functions.js");
|
||||
var db = require(pathThumbnails + "/handlers/db.js");
|
||||
function frontpage_lists(msg, socket) {
|
||||
if(msg == undefined || !msg.hasOwnProperty('version') || msg.version != VERSION || msg.version == undefined) {
|
||||
if (
|
||||
msg == undefined ||
|
||||
!msg.hasOwnProperty("version") ||
|
||||
msg.version != VERSION ||
|
||||
msg.version == undefined
|
||||
) {
|
||||
var result = {
|
||||
version: {
|
||||
expected: VERSION,
|
||||
got: msg.hasOwnProperty("version") ? msg.version : undefined,
|
||||
got: msg.hasOwnProperty("version") ? msg.version : undefined
|
||||
}
|
||||
};
|
||||
socket.emit('update_required', result);
|
||||
socket.emit("update_required", result);
|
||||
return;
|
||||
}
|
||||
|
||||
db.collection("frontpage_lists").find({frontpage:true}, function(err, docs){
|
||||
db.collection("connected_users").find({"_id": "total_users"}, function(err, tot){
|
||||
socket.compress(true).emit("playlists", {channels: docs, viewers: tot[0].total_users.length});
|
||||
db.collection("frontpage_lists").find({ frontpage: true }, function(
|
||||
err,
|
||||
docs
|
||||
) {
|
||||
db.collection("connected_users").find({ _id: "total_users" }, function(
|
||||
err,
|
||||
tot
|
||||
) {
|
||||
socket
|
||||
.compress(true)
|
||||
.emit("playlists", {
|
||||
channels: docs,
|
||||
viewers: tot[0].total_users.length
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function get_frontpage_lists(callback) {
|
||||
var project_object = {
|
||||
"_id": 1,
|
||||
"count": 1,
|
||||
"frontpage": 1,
|
||||
"id": 1,
|
||||
"title": 1,
|
||||
"viewers": 1,
|
||||
"accessed": 1,
|
||||
"pinned": { $ifNull: [ "$pinned", 0 ] },
|
||||
"description": {
|
||||
$ifNull: [ {$cond: {
|
||||
"if": {
|
||||
"$or": [
|
||||
{ "$eq": [ "$description", ""] },
|
||||
{ "$eq": [ "$description", null] },
|
||||
{ "$eq": [ "$description", undefined] }
|
||||
_id: 1,
|
||||
count: 1,
|
||||
frontpage: 1,
|
||||
id: 1,
|
||||
title: 1,
|
||||
viewers: 1,
|
||||
accessed: 1,
|
||||
pinned: { $ifNull: ["$pinned", 0] },
|
||||
description: {
|
||||
$ifNull: [
|
||||
{
|
||||
$cond: {
|
||||
if: {
|
||||
$or: [
|
||||
{ $eq: ["$description", ""] },
|
||||
{ $eq: ["$description", null] },
|
||||
{ $eq: ["$description", undefined] }
|
||||
]
|
||||
},
|
||||
then: "This list has no description",
|
||||
else: "$description"
|
||||
}}, "This list has no description"]
|
||||
|
||||
}
|
||||
},
|
||||
"thumbnail": {
|
||||
$ifNull: [ {$cond: {
|
||||
"if": {
|
||||
"$or": [
|
||||
{ "$eq": [ "$thumbnail", ""] },
|
||||
{ "$eq": [ "$thumbnail", null] },
|
||||
{ "$eq": [ "$thumbnail", undefined] }
|
||||
"This list has no description"
|
||||
]
|
||||
},
|
||||
thumbnail: {
|
||||
$ifNull: [
|
||||
{
|
||||
$cond: {
|
||||
if: {
|
||||
$or: [
|
||||
{ $eq: ["$thumbnail", ""] },
|
||||
{ $eq: ["$thumbnail", null] },
|
||||
{ $eq: ["$thumbnail", undefined] }
|
||||
]
|
||||
},
|
||||
then: {
|
||||
$concat: ["https://img.youtube.com/vi/", "$id", "/mqdefault.jpg"]
|
||||
},
|
||||
else: "$thumbnail"
|
||||
}}, { $concat : [ "https://img.youtube.com/vi/", "$id", "/mqdefault.jpg"]}]
|
||||
|
||||
}
|
||||
},
|
||||
{ $concat: ["https://img.youtube.com/vi/", "$id", "/mqdefault.jpg"] }
|
||||
]
|
||||
}
|
||||
};
|
||||
db.collection("frontpage_lists").aggregate([
|
||||
db.collection("frontpage_lists").aggregate(
|
||||
[
|
||||
{
|
||||
"$match": {
|
||||
$match: {
|
||||
frontpage: true,
|
||||
count: {$gt: 3},
|
||||
count: { $gt: 3 }
|
||||
}
|
||||
},
|
||||
{
|
||||
"$project": project_object
|
||||
$project: project_object
|
||||
},
|
||||
{
|
||||
"$sort" : {
|
||||
"pinned": -1,
|
||||
"viewers": -1,
|
||||
"accessed": -1,
|
||||
"count": -1,
|
||||
"title": 1
|
||||
$sort: {
|
||||
pinned: -1,
|
||||
viewers: -1,
|
||||
accessed: -1,
|
||||
count: -1,
|
||||
title: 1
|
||||
}
|
||||
},
|
||||
], callback);
|
||||
}
|
||||
],
|
||||
callback
|
||||
);
|
||||
}
|
||||
|
||||
function update_frontpage(coll, id, title, thumbnail, source, callback) {
|
||||
@@ -90,14 +117,26 @@ function update_frontpage(coll, id, title, thumbnail, source, callback) {
|
||||
title: title,
|
||||
accessed: Functions.get_time()
|
||||
};
|
||||
if(doc.length > 0 && ((doc[0].thumbnail != "" && doc[0].thumbnail != undefined && (doc[0].thumbnail.indexOf("https://i1.sndcdn.com") > -1 || doc[0].thumbnail.indexOf("https://w1.sndcdn.com") > -1 || doc[0].thumbnail.indexOf("https://img.youtube.com") > -1)) || (doc[0].thumbnail == "" || doc[0].thumbnail == undefined))) {
|
||||
if (
|
||||
doc.length > 0 &&
|
||||
((doc[0].thumbnail != "" &&
|
||||
doc[0].thumbnail != undefined &&
|
||||
(doc[0].thumbnail.indexOf("https://i1.sndcdn.com") > -1 ||
|
||||
doc[0].thumbnail.indexOf("https://w1.sndcdn.com") > -1 ||
|
||||
doc[0].thumbnail.indexOf("https://img.youtube.com") > -1)) ||
|
||||
(doc[0].thumbnail == "" || doc[0].thumbnail == undefined))
|
||||
) {
|
||||
updateObject.thumbnail = thumbnail;
|
||||
if (thumbnail == undefined) updateObject.thumbnail = "";
|
||||
}
|
||||
db.collection("frontpage_lists").update({_id: coll}, {$set: updateObject
|
||||
},{upsert: true}, function(err, returnDocs){
|
||||
if(typeof(callback) == "function") callback();
|
||||
});
|
||||
db.collection("frontpage_lists").update(
|
||||
{ _id: coll },
|
||||
{ $set: updateObject },
|
||||
{ upsert: true },
|
||||
function(err, returnDocs) {
|
||||
if (typeof callback == "function") callback();
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -1,20 +1,26 @@
|
||||
var path = require('path');
|
||||
var path = require("path");
|
||||
try {
|
||||
var mongo_config = require(path.join(path.join(__dirname, '../config/'), 'mongo_config.js'));
|
||||
var mongo_config = require(path.join(
|
||||
path.join(__dirname, "../config/"),
|
||||
"mongo_config.js"
|
||||
));
|
||||
} catch (e) {
|
||||
console.log("Error - missing file");
|
||||
console.log("Seems you forgot to create the file mongo_config.js in /server/config/. Have a look at mongo_config.example.js.");
|
||||
console.log(
|
||||
"(!) Missing file - /config/mongo_config.js. Have a look at /config/mongo_config.example.js. The server won't run without this existing."
|
||||
);
|
||||
process.exit(1);
|
||||
}
|
||||
var mongojs = require('mongojs');
|
||||
var connected_db = mongojs('mongodb://' + mongo_config.host + '/user_credentials');
|
||||
var crypto = require('crypto');
|
||||
var db = require(pathThumbnails + '/handlers/db.js');
|
||||
var uniqid = require('uniqid');
|
||||
var Filter = require('bad-words');
|
||||
var filter = new Filter({ placeHolder: 'x'});
|
||||
var mongojs = require("mongojs");
|
||||
var connected_db = mongojs(
|
||||
"mongodb://" + mongo_config.host + "/user_credentials"
|
||||
);
|
||||
var crypto = require("crypto");
|
||||
var db = require(pathThumbnails + "/handlers/db.js");
|
||||
var uniqid = require("uniqid");
|
||||
var Filter = require("bad-words");
|
||||
var filter = new Filter({ placeHolder: "x" });
|
||||
|
||||
var Chat = require(pathThumbnails + '/handlers/chat.js');
|
||||
var Chat = require(pathThumbnails + "/handlers/chat.js");
|
||||
|
||||
function encodeChannelName(str) {
|
||||
var _fn = encodeURIComponent;
|
||||
@@ -36,34 +42,55 @@ function decodeChannelName(str) {
|
||||
}
|
||||
|
||||
function remove_unique_id(short_id) {
|
||||
db.collection("unique_ids").update({"_id": "unique_ids"}, {$pull: {unique_ids: short_id}}, function(err, docs) {});
|
||||
db.collection("unique_ids").update(
|
||||
{ _id: "unique_ids" },
|
||||
{ $pull: { unique_ids: short_id } },
|
||||
function(err, docs) {}
|
||||
);
|
||||
}
|
||||
|
||||
function remove_name_from_db(guid, channel) {
|
||||
// Use temporary, with caution. Can bottleneck in large quantity of users.
|
||||
//
|
||||
// Find a way of indexing users in lists in a clever way, to avoid the search here
|
||||
db.collection("connected_users").find({"_id": "total_users"}, function(err, all_users) {
|
||||
var hasOne = all_users[0].total_users.some(function(v){ return v.indexOf(guid)>=0 });
|
||||
if(!hasOne) {
|
||||
db.collection("user_names").find({"guid": guid}, function(err, user){
|
||||
if(user.length == 1){
|
||||
db.collection("user_names").update({"_id": "all_names"}, {$pull: {names: user[0].name}}, function(err, updated) {
|
||||
db.collection("user_names").remove({"guid": guid}, function(err, removed) { });
|
||||
db.collection("connected_users").find({ _id: "total_users" }, function(
|
||||
err,
|
||||
all_users
|
||||
) {
|
||||
var hasOne = all_users[0].total_users.some(function(v) {
|
||||
return v.indexOf(guid) >= 0;
|
||||
});
|
||||
if (!hasOne) {
|
||||
db.collection("user_names").find({ guid: guid }, function(err, user) {
|
||||
if (user.length == 1) {
|
||||
db.collection("user_names").update(
|
||||
{ _id: "all_names" },
|
||||
{ $pull: { names: user[0].name } },
|
||||
function(err, updated) {
|
||||
db.collection("user_names").remove({ guid: guid }, function(
|
||||
err,
|
||||
removed
|
||||
) {});
|
||||
}
|
||||
);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
if(channel == undefined || channel == "") return;
|
||||
db.collection("user_names").update({"guid": guid}, {$pull: {channels: channel}}, function(err, docs) {
|
||||
if (channel == undefined || channel == "") return;
|
||||
db.collection("user_names").update(
|
||||
{ guid: guid },
|
||||
{ $pull: { channels: channel } },
|
||||
function(err, docs) {
|
||||
//console.log("Pulled user from current channel");
|
||||
});
|
||||
}
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function isUrl(str) {
|
||||
var pattern = new RegExp("\\b(((ht|f)tp(s?)\\:\\/\\/|~\\/|\\/)|www.)" +
|
||||
var pattern = new RegExp(
|
||||
"\\b(((ht|f)tp(s?)\\:\\/\\/|~\\/|\\/)|www.)" +
|
||||
"(\\w+:\\w+@)?(([-\\w]+\\.)+(com|org|net|gov" +
|
||||
"|mil|biz|info|mobi|name|aero|jobs|museum" +
|
||||
"|travel|[a-z]{2}))(:[\\d]{1,5})?" +
|
||||
@@ -72,7 +99,8 @@ function isUrl(str) {
|
||||
"([-\\w~!$+|.,*:=]|%[a-f\\d]{2})*)" +
|
||||
"(&(?:[-\\w~!$+|.,*:]|%[a-f\\d{2}])+=?" +
|
||||
"([-\\w~!$+|.,*:=]|%[a-f\\d]{2})*)*)*" +
|
||||
"(#([-\\w~!$+|.,*:=]|%[a-f\\d]{2})*)?\\b");
|
||||
"(#([-\\w~!$+|.,*:=]|%[a-f\\d]{2})*)?\\b"
|
||||
);
|
||||
if (!pattern.test(str)) {
|
||||
return false;
|
||||
} else {
|
||||
@@ -90,7 +118,11 @@ function getSession(socket) {
|
||||
return socket.cookie_id;
|
||||
} catch (e) {
|
||||
// Returning "sessiong"-based on place of connection
|
||||
return hash_pass(socket.handshake.headers["user-agent"] + socket.handshake.address + socket.handshake.headers["accept-language"]);
|
||||
return hash_pass(
|
||||
socket.handshake.headers["user-agent"] +
|
||||
socket.handshake.address +
|
||||
socket.handshake.headers["accept-language"]
|
||||
);
|
||||
//return "empty";
|
||||
}
|
||||
}
|
||||
@@ -98,20 +130,23 @@ function getSession(socket) {
|
||||
function remove_from_array(array, element) {
|
||||
if (contains(array, element)) {
|
||||
var index = array.indexOf(element);
|
||||
if(index != -1)
|
||||
array.splice(index, 1);
|
||||
if (index != -1) array.splice(index, 1);
|
||||
}
|
||||
}
|
||||
|
||||
function generate_channel_name(res) {
|
||||
var trying_id = uniqid.time().toLowerCase();
|
||||
db.collection("frontpage_lists").find({frontpage: {$exists: true }, "_id": trying_id }, {"_id": 1}, function(err, docs){
|
||||
db.collection("frontpage_lists").find(
|
||||
{ frontpage: { $exists: true }, _id: trying_id },
|
||||
{ _id: 1 },
|
||||
function(err, docs) {
|
||||
if (docs.length == 0) {
|
||||
res.send(trying_id);
|
||||
return;
|
||||
}
|
||||
generate_channel_name(res);
|
||||
});
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
function get_short_id(socket) {
|
||||
@@ -121,73 +156,151 @@ function get_short_id(socket) {
|
||||
socket.emit("id", new_short_id);
|
||||
}
|
||||
|
||||
function check_inlist(coll, guid, socket, offline, callback, double_check)
|
||||
{
|
||||
function check_inlist(coll, guid, socket, offline, callback, double_check) {
|
||||
if (coll == undefined) {
|
||||
if(typeof(callback) == "function") callback();
|
||||
if (typeof callback == "function") callback();
|
||||
return;
|
||||
}
|
||||
//coll = coll.replace(/ /g,'');
|
||||
if (!offline && coll != undefined) {
|
||||
db.collection("connected_users").update({"_id": coll}, {$addToSet:{users: guid}}, {upsert: true}, function(err, updated) {
|
||||
db.collection("connected_users").update(
|
||||
{ _id: coll },
|
||||
{ $addToSet: { users: guid } },
|
||||
{ upsert: true },
|
||||
function(err, updated) {
|
||||
if (updated.nModified > 0 || updated.upserted != undefined) {
|
||||
db.collection("connected_users").find({"_id": coll}, function(err, new_doc) {
|
||||
db.collection("frontpage_lists").update({"_id": coll}, {$set: {"viewers": new_doc[0].users.length}}, function(){
|
||||
if(new_doc[0].users == undefined || new_doc[0].users.length == undefined) {
|
||||
db.collection("connected_users").find({ _id: coll }, function(
|
||||
err,
|
||||
new_doc
|
||||
) {
|
||||
db.collection("frontpage_lists").update(
|
||||
{ _id: coll },
|
||||
{ $set: { viewers: new_doc[0].users.length } },
|
||||
function() {
|
||||
if (
|
||||
new_doc[0].users == undefined ||
|
||||
new_doc[0].users.length == undefined
|
||||
) {
|
||||
io.to(coll).emit("viewers", 1);
|
||||
} else {
|
||||
io.to(coll).emit("viewers", new_doc[0].users.length);
|
||||
}
|
||||
Chat.namechange({initial: true, first:true, channel: coll}, guid, socket, false, function(enabled) {
|
||||
db.collection("user_names").find({"guid": guid}, function(err, docs) {
|
||||
Chat.namechange(
|
||||
{ initial: true, first: true, channel: coll },
|
||||
guid,
|
||||
socket,
|
||||
false,
|
||||
function(enabled) {
|
||||
db.collection("user_names").find({ guid: guid }, function(
|
||||
err,
|
||||
docs
|
||||
) {
|
||||
if (docs.length == 1) {
|
||||
var icon = "";
|
||||
if (docs[0].icon != undefined) icon = docs[0].icon;
|
||||
db.collection("user_names").update({"guid": guid}, {$addToSet:{channels: coll}}, function(err, doc){});
|
||||
db.collection("user_names").update(
|
||||
{ guid: guid },
|
||||
{ $addToSet: { channels: coll } },
|
||||
function(err, doc) {}
|
||||
);
|
||||
if (enabled) {
|
||||
socket.broadcast.to(coll).emit('chat', {from: docs[0].name, icon: icon, msg: " joined"});
|
||||
socket.broadcast.to(coll).emit("chat", {
|
||||
from: docs[0].name,
|
||||
icon: icon,
|
||||
msg: " joined"
|
||||
});
|
||||
}
|
||||
} else if (docs.length == 0) {
|
||||
//console.log("User doesn't have a name for some reason.");
|
||||
//console.log("guid", guid);
|
||||
//console.log("channel", coll);
|
||||
//console.log("Trying to get a chat-name");
|
||||
Chat.get_name(guid, {announce: false, socket: socket, channel: coll});
|
||||
Chat.get_name(guid, {
|
||||
announce: false,
|
||||
socket: socket,
|
||||
channel: coll
|
||||
});
|
||||
}
|
||||
});
|
||||
db.collection("connected_users").update({"_id": "total_users"}, {$addToSet: {total_users: guid + coll}}, function(err, docs){
|
||||
if(callback != undefined && typeof(callback) == "function") callback();
|
||||
});
|
||||
});
|
||||
});
|
||||
db.collection("connected_users").update(
|
||||
{ _id: "total_users" },
|
||||
{ $addToSet: { total_users: guid + coll } },
|
||||
function(err, docs) {
|
||||
if (
|
||||
callback != undefined &&
|
||||
typeof callback == "function"
|
||||
)
|
||||
callback();
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
});
|
||||
} else {
|
||||
db.collection("connected_users").find({"_id": coll}, function(err, new_doc) {
|
||||
db.collection("connected_users").find({ _id: coll }, function(
|
||||
err,
|
||||
new_doc
|
||||
) {
|
||||
io.to(coll).emit("viewers", new_doc[0].users.length);
|
||||
});
|
||||
if(callback != undefined && typeof(callback) == "function") callback();
|
||||
if (callback != undefined && typeof callback == "function")
|
||||
callback();
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
);
|
||||
} else {
|
||||
if (offline) {
|
||||
db.collection("connected_users").update({"_id": "offline_users"}, {$addToSet: {users: guid}}, function(err, docs){});
|
||||
db.collection("connected_users").update(
|
||||
{ _id: "offline_users" },
|
||||
{ $addToSet: { users: guid } },
|
||||
function(err, docs) {}
|
||||
);
|
||||
} else {
|
||||
db.collection("connected_users").update({"_id": coll}, {$addToSet: {users: guid}}, function(err, docs){});
|
||||
db.collection("connected_users").update(
|
||||
{ _id: coll },
|
||||
{ $addToSet: { users: guid } },
|
||||
function(err, docs) {}
|
||||
);
|
||||
}
|
||||
//
|
||||
if (coll != undefined && coll != "") {
|
||||
db.collection("connected_users").update({"_id": "total_users"}, {$addToSet: {total_users: guid + coll}}, function(err, docs) {});
|
||||
db.collection("connected_users").update(
|
||||
{ _id: "total_users" },
|
||||
{ $addToSet: { total_users: guid + coll } },
|
||||
function(err, docs) {}
|
||||
);
|
||||
}
|
||||
if(callback != undefined && typeof(callback) == "function") callback();
|
||||
if (callback != undefined && typeof callback == "function") callback();
|
||||
}
|
||||
}
|
||||
|
||||
function rndName(seed, len) {
|
||||
var vowels = ['a', 'e', 'i', 'o', 'u'];
|
||||
consts = ['b', 'c', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'm', 'n', 'p', 'r', 's', 't', 'v', 'w', 'x', 'y'];
|
||||
var vowels = ["a", "e", "i", "o", "u"];
|
||||
consts = [
|
||||
"b",
|
||||
"c",
|
||||
"d",
|
||||
"f",
|
||||
"g",
|
||||
"h",
|
||||
"j",
|
||||
"k",
|
||||
"l",
|
||||
"m",
|
||||
"n",
|
||||
"p",
|
||||
"r",
|
||||
"s",
|
||||
"t",
|
||||
"v",
|
||||
"w",
|
||||
"x",
|
||||
"y"
|
||||
];
|
||||
len = Math.floor(len);
|
||||
word = '';
|
||||
word = "";
|
||||
is_vowel = false;
|
||||
var arr;
|
||||
try {
|
||||
@@ -206,19 +319,18 @@ function rndName(seed, len) {
|
||||
function removeEmojis(string) {
|
||||
//https://stackoverflow.com/a/41164278/4266467
|
||||
var regex = /(?:[\u2700-\u27bf]|(?:\ud83c[\udde6-\uddff]){2}|[\ud800-\udbff][\udc00-\udfff]|[\u0023-\u0039]\ufe0f?\u20e3|\u3299|\u3297|\u303d|\u3030|\u24c2|\ud83c[\udd70-\udd71]|\ud83c[\udd7e-\udd7f]|\ud83c\udd8e|\ud83c[\udd91-\udd9a]|\ud83c[\udde6-\uddff]|\ud83c[\ude01-\ude02]|\ud83c\ude1a|\ud83c\ude2f|\ud83c[\ude32-\ude3a]|\ud83c[\ude50-\ude51]|\u203c|\u2049|[\u25aa-\u25ab]|\u25b6|\u25c0|[\u25fb-\u25fe]|\u00a9|\u00ae|\u2122|\u2139|\ud83c\udc04|[\u2600-\u26FF]|\u2b05|\u2b06|\u2b07|\u2b1b|\u2b1c|\u2b50|\u2b55|\u231a|\u231b|\u2328|\u23cf|[\u23e9-\u23f3]|[\u23f8-\u23fa]|\ud83c\udccf|\u2934|\u2935|[\u2190-\u21ff])/g;
|
||||
return string.replace(regex, '');
|
||||
return string.replace(regex, "");
|
||||
}
|
||||
|
||||
function decrypt_string(pw) {
|
||||
try {
|
||||
return Buffer.from(pw, 'base64').toString('ascii')
|
||||
return Buffer.from(pw, "base64").toString("ascii");
|
||||
} catch (e) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
function get_time()
|
||||
{
|
||||
function get_time() {
|
||||
var d = new Date();
|
||||
var time = Math.floor(d.getTime() / 1000);
|
||||
return time;
|
||||
@@ -240,8 +352,15 @@ function contains(a, obj) {
|
||||
|
||||
function hash_pass(adminpass, hex) {
|
||||
if (adminpass == undefined || adminpass == "") return "";
|
||||
if(hex) return crypto.createHash('sha256').update(adminpass).digest('hex');
|
||||
return crypto.createHash('sha256').update(adminpass).digest('base64');
|
||||
if (hex)
|
||||
return crypto
|
||||
.createHash("sha256")
|
||||
.update(adminpass)
|
||||
.digest("hex");
|
||||
return crypto
|
||||
.createHash("sha256")
|
||||
.update(adminpass)
|
||||
.digest("base64");
|
||||
}
|
||||
|
||||
function setSessionAdminPass(id, adminpass, list, callback) {
|
||||
@@ -251,13 +370,18 @@ function setSessionAdminPass(id, adminpass, list, callback) {
|
||||
return;
|
||||
}
|
||||
|
||||
connected_db.collection(id).update({_id: list}, {$set: {adminpass: hash_pass(decrypt_string(adminpass), true)}}, {upsert: true}, function(e, d){
|
||||
connected_db
|
||||
.collection(id)
|
||||
.update(
|
||||
{ _id: list },
|
||||
{ $set: { adminpass: hash_pass(decrypt_string(adminpass), true) } },
|
||||
{ upsert: true },
|
||||
function(e, d) {
|
||||
callback();
|
||||
return;
|
||||
});
|
||||
} catch(e) {
|
||||
|
||||
}
|
||||
);
|
||||
} catch (e) {}
|
||||
}
|
||||
|
||||
function setSessionChatPass(id, name, pass, callback) {
|
||||
@@ -266,10 +390,17 @@ function setSessionChatPass(id, name, pass, callback) {
|
||||
callback();
|
||||
return;
|
||||
}
|
||||
connected_db.collection(id).update({_id: "_chat_"}, {$set: {password: pass, name: name}}, {upsert: true}, function(e) {
|
||||
connected_db
|
||||
.collection(id)
|
||||
.update(
|
||||
{ _id: "_chat_" },
|
||||
{ $set: { password: pass, name: name } },
|
||||
{ upsert: true },
|
||||
function(e) {
|
||||
callback();
|
||||
return;
|
||||
})
|
||||
}
|
||||
);
|
||||
} catch (e) {
|
||||
callback();
|
||||
return;
|
||||
@@ -295,24 +426,35 @@ function getSessionChatPass(id, callback) {
|
||||
callback("", "", false);
|
||||
return;
|
||||
}
|
||||
})
|
||||
});
|
||||
} catch (e) {
|
||||
callback();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function setChromecastHost(id, other_id, list, callback) {
|
||||
try {
|
||||
if(id == "empty" || id == undefined || other_id == "empty" || other_id == undefined) {
|
||||
if (
|
||||
id == "empty" ||
|
||||
id == undefined ||
|
||||
other_id == "empty" ||
|
||||
other_id == undefined
|
||||
) {
|
||||
callback();
|
||||
return;
|
||||
}
|
||||
connected_db.collection(id).update({_id: list}, {"chromecast": true, id: other_id}, {upsert: true}, function(e, docs) {
|
||||
connected_db
|
||||
.collection(id)
|
||||
.update(
|
||||
{ _id: list },
|
||||
{ chromecast: true, id: other_id },
|
||||
{ upsert: true },
|
||||
function(e, docs) {
|
||||
callback(true);
|
||||
return;
|
||||
});
|
||||
}
|
||||
);
|
||||
} catch (e) {
|
||||
callback(false);
|
||||
}
|
||||
@@ -320,15 +462,22 @@ function setChromecastHost(id, other_id, list, callback) {
|
||||
|
||||
function setSessionUserPass(id, userpass, list, callback) {
|
||||
try {
|
||||
if(id == "empty" || id == undefined || userpass == undefined) {
|
||||
if (id == "empty" || id == undefined || userpass == undefined) {
|
||||
callback();
|
||||
return;
|
||||
}
|
||||
|
||||
connected_db.collection(id).update({_id: list}, {$set: {userpass: userpass}}, {upsert: true}, function(e, d){
|
||||
connected_db
|
||||
.collection(id)
|
||||
.update(
|
||||
{ _id: list },
|
||||
{ $set: { userpass: userpass } },
|
||||
{ upsert: true },
|
||||
function(e, d) {
|
||||
callback();
|
||||
return;
|
||||
});
|
||||
}
|
||||
);
|
||||
} catch (e) {
|
||||
callback();
|
||||
}
|
||||
@@ -354,7 +503,7 @@ function getSessionAdminUser(id, list, callback) {
|
||||
} else {
|
||||
callback(userpass, adminpass, true);
|
||||
}
|
||||
})
|
||||
});
|
||||
} catch (e) {
|
||||
callback("", "", false);
|
||||
}
|
||||
@@ -371,21 +520,25 @@ function removeSessionChatPass(id, callback) {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function removeSessionAdminPass(id, channel, callback) {
|
||||
if (id == "empty" || id == undefined) {
|
||||
callback();
|
||||
return;
|
||||
}
|
||||
connected_db.collection(id).update({_id: channel}, {$set: {"adminpass": ""}}, function() {
|
||||
connected_db
|
||||
.collection(id)
|
||||
.update({ _id: channel }, { $set: { adminpass: "" } }, function() {
|
||||
callback();
|
||||
return;
|
||||
});
|
||||
}
|
||||
|
||||
function remove_from_chat_channel(coll, guid) {
|
||||
db.collection("user_names").update({"guid": guid}, {$pull: {channels: coll}}, function(err, docs) {
|
||||
});
|
||||
db.collection("user_names").update(
|
||||
{ guid: guid },
|
||||
{ $pull: { channels: coll } },
|
||||
function(err, docs) {}
|
||||
);
|
||||
}
|
||||
|
||||
function left_channel(coll, guid, short_id, in_list, socket, change, caller) {
|
||||
@@ -398,16 +551,36 @@ function left_channel(coll, guid, short_id, in_list, socket, change, caller) {
|
||||
return;
|
||||
}
|
||||
//coll = coll.replace(/ /g,'');
|
||||
db.collection("connected_users").update({"_id": coll}, {$pull: {users: guid}}, function(err, updated) {
|
||||
db.collection("connected_users").update(
|
||||
{ _id: coll },
|
||||
{ $pull: { users: guid } },
|
||||
function(err, updated) {
|
||||
if (updated.nModified > 0) {
|
||||
db.collection("connected_users").update({"_id": "total_users"}, {$pull: {total_users: guid + coll}}, function(err, updated){});
|
||||
db.collection("connected_users").find({"_id": coll}, function(err, new_doc){
|
||||
db.collection("frontpage_lists").update({"_id": coll, viewers: {$gt: 0}}, {$inc: {viewers: -1}}, function(err, doc) {
|
||||
db.collection("user_names").find({"guid": guid}, function(err, docs) {
|
||||
db.collection("connected_users").update(
|
||||
{ _id: "total_users" },
|
||||
{ $pull: { total_users: guid + coll } },
|
||||
function(err, updated) {}
|
||||
);
|
||||
db.collection("connected_users").find({ _id: coll }, function(
|
||||
err,
|
||||
new_doc
|
||||
) {
|
||||
db.collection("frontpage_lists").update(
|
||||
{ _id: coll, viewers: { $gt: 0 } },
|
||||
{ $inc: { viewers: -1 } },
|
||||
function(err, doc) {
|
||||
db.collection("user_names").find({ guid: guid }, function(
|
||||
err,
|
||||
docs
|
||||
) {
|
||||
if (docs.length == 1) {
|
||||
var icon = "";
|
||||
if (docs[0].icon != undefined) icon = docs[0].icon;
|
||||
io.to(coll).emit('chat', {from: docs[0].name, icon: icon, msg: " left"});
|
||||
io.to(coll).emit("chat", {
|
||||
from: docs[0].name,
|
||||
icon: icon,
|
||||
msg: " left"
|
||||
});
|
||||
}
|
||||
});
|
||||
io.to(coll).emit("viewers", new_doc[0].users.length);
|
||||
@@ -417,36 +590,56 @@ function left_channel(coll, guid, short_id, in_list, socket, change, caller) {
|
||||
} else {
|
||||
remove_from_chat_channel(coll, guid);
|
||||
}
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
} else {
|
||||
db.collection("connected_users").update({"_id": "offline_users"}, {$pull: {users: guid}}, function(err, updated){
|
||||
db.collection("connected_users").update(
|
||||
{ _id: "offline_users" },
|
||||
{ $pull: { users: guid } },
|
||||
function(err, updated) {
|
||||
//if(updated.nModified > 0) {
|
||||
db.collection("connected_users").update({"_id": "total_users"}, {$pull: {total_users: guid + coll}}, function(err, updated){});
|
||||
db.collection("connected_users").update(
|
||||
{ _id: "total_users" },
|
||||
{ $pull: { total_users: guid + coll } },
|
||||
function(err, updated) {}
|
||||
);
|
||||
if (!change) {
|
||||
remove_name_from_db(guid, coll);
|
||||
} else {
|
||||
remove_from_chat_channel(coll, guid);
|
||||
}
|
||||
//}
|
||||
});
|
||||
|
||||
}
|
||||
});
|
||||
);
|
||||
}
|
||||
}
|
||||
);
|
||||
remove_unique_id(short_id);
|
||||
}
|
||||
|
||||
|
||||
function checkTimeout(type, timeout, channel, guid, conf_pass, this_pass, socket, callback, error_message, error_callback){
|
||||
function checkTimeout(
|
||||
type,
|
||||
timeout,
|
||||
channel,
|
||||
guid,
|
||||
conf_pass,
|
||||
this_pass,
|
||||
socket,
|
||||
callback,
|
||||
error_message,
|
||||
error_callback
|
||||
) {
|
||||
if (conf_pass != "" && conf_pass == this_pass) {
|
||||
callback();
|
||||
return;
|
||||
}
|
||||
db.collection("timeout_api").find({
|
||||
db.collection("timeout_api").find(
|
||||
{
|
||||
type: type,
|
||||
guid: guid,
|
||||
}, function(err, docs) {
|
||||
guid: guid
|
||||
},
|
||||
function(err, docs) {
|
||||
if (docs.length > 0) {
|
||||
var date = new Date(docs[0].createdAt);
|
||||
date.setSeconds(date.getSeconds() + timeout);
|
||||
@@ -454,11 +647,15 @@ function checkTimeout(type, timeout, channel, guid, conf_pass, this_pass, socket
|
||||
|
||||
var retry_in = (date.getTime() - now.getTime()) / 1000;
|
||||
if (retry_in > 0) {
|
||||
if(typeof(error_callback) == "function") {
|
||||
if (typeof error_callback == "function") {
|
||||
error_callback();
|
||||
} else if (error_message) {
|
||||
var sOrNot = Math.ceil(retry_in) > 1 || Math.ceil(retry_in) == 0 ? "s" : "";
|
||||
socket.emit("toast", error_message + Math.ceil(retry_in) + " second" + sOrNot + ".");
|
||||
var sOrNot =
|
||||
Math.ceil(retry_in) > 1 || Math.ceil(retry_in) == 0 ? "s" : "";
|
||||
socket.emit(
|
||||
"toast",
|
||||
error_message + Math.ceil(retry_in) + " second" + sOrNot + "."
|
||||
);
|
||||
} else {
|
||||
socket.emit("toast", "wait_longer");
|
||||
}
|
||||
@@ -466,17 +663,23 @@ function checkTimeout(type, timeout, channel, guid, conf_pass, this_pass, socket
|
||||
}
|
||||
}
|
||||
var now_date = new Date();
|
||||
db.collection("timeout_api").update({type: type, guid: guid}, {
|
||||
db.collection("timeout_api").update(
|
||||
{ type: type, guid: guid },
|
||||
{
|
||||
$set: {
|
||||
"createdAt": now_date,
|
||||
createdAt: now_date,
|
||||
type: type,
|
||||
guid: guid,
|
||||
guid: guid
|
||||
}
|
||||
},
|
||||
}, {upsert: true}, function(err, docs) {
|
||||
{ upsert: true },
|
||||
function(err, docs) {
|
||||
callback();
|
||||
return;
|
||||
});
|
||||
});
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
module.exports.checkTimeout = checkTimeout;
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,33 +1,36 @@
|
||||
var Functions = require(pathThumbnails + '/handlers/functions.js');
|
||||
var crypto = require('crypto');
|
||||
var Filter = require('bad-words');
|
||||
var filter = new Filter({ placeHolder: 'x'});
|
||||
var Functions = require(pathThumbnails + "/handlers/functions.js");
|
||||
var crypto = require("crypto");
|
||||
var Filter = require("bad-words");
|
||||
var filter = new Filter({ placeHolder: "x" });
|
||||
/*var filter = {
|
||||
clean: function(str) {
|
||||
return str;
|
||||
}
|
||||
}*/
|
||||
var projects = require(pathThumbnails + "/handlers/aggregates.js");
|
||||
var db = require(pathThumbnails + '/handlers/db.js');
|
||||
var db = require(pathThumbnails + "/handlers/db.js");
|
||||
|
||||
function password(inp, coll, guid, offline, socket) {
|
||||
var sessionId = Functions.getSession(socket);
|
||||
if (sessionId == "") sessionId = "empty";
|
||||
if(inp !== undefined && inp !== null && inp !== "")
|
||||
{
|
||||
if(!inp.hasOwnProperty("password") || !inp.hasOwnProperty("channel") ||
|
||||
typeof(inp.password) != "string" || typeof(inp.channel) != "string") {
|
||||
if (inp !== undefined && inp !== null && inp !== "") {
|
||||
if (
|
||||
!inp.hasOwnProperty("password") ||
|
||||
!inp.hasOwnProperty("channel") ||
|
||||
typeof inp.password != "string" ||
|
||||
typeof inp.channel != "string"
|
||||
) {
|
||||
var result = {
|
||||
channel: {
|
||||
expected: "string",
|
||||
got: inp.hasOwnProperty("channel") ? typeof(inp.channel) : undefined,
|
||||
got: inp.hasOwnProperty("channel") ? typeof inp.channel : undefined
|
||||
},
|
||||
password: {
|
||||
expected: "password",
|
||||
got: inp.hasOwnProperty("password") ? typeof(inp.password) : undefined,
|
||||
},
|
||||
got: inp.hasOwnProperty("password") ? typeof inp.password : undefined
|
||||
}
|
||||
};
|
||||
socket.emit('update_required', result);
|
||||
socket.emit("update_required", result);
|
||||
return;
|
||||
}
|
||||
pw = inp.password;
|
||||
@@ -45,37 +48,67 @@ function password(inp, coll, guid, offline, socket) {
|
||||
uncrypted = pw;
|
||||
pw = Functions.hash_pass(Functions.decrypt_string(pw), true);
|
||||
Functions.check_inlist(coll, guid, socket, offline, undefined, "place 8");
|
||||
Functions.getSessionAdminUser(sessionId, coll, function(userpass, adminpass) {
|
||||
Functions.getSessionAdminUser(sessionId, coll, function(
|
||||
userpass,
|
||||
adminpass
|
||||
) {
|
||||
adminpass = Functions.hash_pass(adminpass);
|
||||
db.collection(coll + "_settings").find(function(err, docs) {
|
||||
if(docs !== null && docs.length !== 0)
|
||||
{
|
||||
if(docs[0].adminpass === "" || docs[0].adminpass == Functions.hash_pass(pw))
|
||||
{
|
||||
Functions.setSessionAdminPass(sessionId, inp.password, coll, function() {
|
||||
db.collection(coll + "_settings").update({ id: "config" }, {$set:{adminpass:Functions.hash_pass(pw)}}, function(err, docs){
|
||||
if (docs !== null && docs.length !== 0) {
|
||||
if (
|
||||
docs[0].adminpass === "" ||
|
||||
docs[0].adminpass == Functions.hash_pass(pw)
|
||||
) {
|
||||
Functions.setSessionAdminPass(
|
||||
sessionId,
|
||||
inp.password,
|
||||
coll,
|
||||
function() {
|
||||
db.collection(coll + "_settings").update(
|
||||
{ id: "config" },
|
||||
{ $set: { adminpass: Functions.hash_pass(pw) } },
|
||||
function(err, docs) {
|
||||
if (adminpass != pw && adminpass != "") {
|
||||
socket.emit("toast", "changedpass");
|
||||
} else {
|
||||
socket.emit("toast", "correctpass");
|
||||
}
|
||||
socket.emit("pw", true);
|
||||
});
|
||||
});
|
||||
} else if(docs[0].adminpass === "" || docs[0].adminpass == adminpass) {
|
||||
Functions.setSessionAdminPass(sessionId, inp.password, coll, function() {
|
||||
db.collection(coll + "_settings").update({ id: "config" }, {$set:{adminpass:Functions.hash_pass(pw)}}, function(err, docs){
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
} else if (
|
||||
docs[0].adminpass === "" ||
|
||||
docs[0].adminpass == adminpass
|
||||
) {
|
||||
Functions.setSessionAdminPass(
|
||||
sessionId,
|
||||
inp.password,
|
||||
coll,
|
||||
function() {
|
||||
db.collection(coll + "_settings").update(
|
||||
{ id: "config" },
|
||||
{ $set: { adminpass: Functions.hash_pass(pw) } },
|
||||
function(err, docs) {
|
||||
if (adminpass != pw) {
|
||||
socket.emit("toast", "changedpass");
|
||||
}
|
||||
socket.emit("pw", true);
|
||||
});
|
||||
});
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
} else {
|
||||
Functions.setSessionAdminPass(Functions.getSession(socket), "", coll, function() {
|
||||
Functions.setSessionAdminPass(
|
||||
Functions.getSession(socket),
|
||||
"",
|
||||
coll,
|
||||
function() {
|
||||
socket.emit("toast", "wrongpass");
|
||||
socket.emit("pw", false);
|
||||
});
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -84,16 +117,15 @@ function password(inp, coll, guid, offline, socket) {
|
||||
var result = {
|
||||
inp: {
|
||||
expected: "string",
|
||||
got: typeof(inpt)
|
||||
},
|
||||
got: typeof inpt
|
||||
}
|
||||
};
|
||||
socket.emit('update_required', result);
|
||||
socket.emit("update_required", result);
|
||||
}
|
||||
}
|
||||
|
||||
function conf_function(params, coll, guid, offline, socket) {
|
||||
if(params !== undefined && params !== null && params !== "")
|
||||
{
|
||||
if (params !== undefined && params !== null && params !== "") {
|
||||
if (coll !== undefined) {
|
||||
try {
|
||||
coll = params.channel; //.replace(/ /g,'');
|
||||
@@ -107,65 +139,97 @@ function conf_function(params, coll, guid, offline, socket) {
|
||||
}
|
||||
}
|
||||
|
||||
if(coll == "" || coll == undefined || coll == null) {
|
||||
if (coll == "" || coll == undefined || coll == null) {
|
||||
socket.emit("update_required");
|
||||
return;
|
||||
}
|
||||
|
||||
Functions.check_inlist(coll, guid, socket, offline, undefined, "place 9");
|
||||
|
||||
Functions.getSessionAdminUser(Functions.getSession(socket), coll, function(userpass, adminpass, gotten) {
|
||||
Functions.getSessionAdminUser(Functions.getSession(socket), coll, function(
|
||||
userpass,
|
||||
adminpass,
|
||||
gotten
|
||||
) {
|
||||
if (gotten) {
|
||||
params.adminpass = adminpass;
|
||||
if (!params.userpass_changed) params.userpass = userpass;
|
||||
}
|
||||
if(!params.hasOwnProperty('voting') || !params.hasOwnProperty('addsongs') ||
|
||||
!params.hasOwnProperty('longsongs') || !params.hasOwnProperty('frontpage') ||
|
||||
!params.hasOwnProperty('allvideos') || !params.hasOwnProperty('removeplay') ||
|
||||
!params.hasOwnProperty('adminpass') || !params.hasOwnProperty('skipping') ||
|
||||
!params.hasOwnProperty('shuffling') || !params.hasOwnProperty('channel') ||
|
||||
typeof(params.userpass) != "string" || typeof(params.adminpass) != "string" ||
|
||||
typeof(params.voting) != "boolean" || typeof(params.addsongs) != "boolean" ||
|
||||
typeof(params.longsongs) != "boolean" || typeof(params.frontpage) != "boolean" ||
|
||||
typeof(params.allvideos) != "boolean" || typeof(params.removeplay) != "boolean" ||
|
||||
typeof(params.skipping) != "boolean" || typeof(params.shuffling) != "boolean" ||
|
||||
typeof(params.userpass_changed) != "boolean") {
|
||||
if (
|
||||
!params.hasOwnProperty("voting") ||
|
||||
!params.hasOwnProperty("addsongs") ||
|
||||
!params.hasOwnProperty("longsongs") ||
|
||||
!params.hasOwnProperty("frontpage") ||
|
||||
!params.hasOwnProperty("allvideos") ||
|
||||
!params.hasOwnProperty("removeplay") ||
|
||||
!params.hasOwnProperty("adminpass") ||
|
||||
!params.hasOwnProperty("skipping") ||
|
||||
!params.hasOwnProperty("shuffling") ||
|
||||
!params.hasOwnProperty("channel") ||
|
||||
typeof params.userpass != "string" ||
|
||||
typeof params.adminpass != "string" ||
|
||||
typeof params.voting != "boolean" ||
|
||||
typeof params.addsongs != "boolean" ||
|
||||
typeof params.longsongs != "boolean" ||
|
||||
typeof params.frontpage != "boolean" ||
|
||||
typeof params.allvideos != "boolean" ||
|
||||
typeof params.removeplay != "boolean" ||
|
||||
typeof params.skipping != "boolean" ||
|
||||
typeof params.shuffling != "boolean" ||
|
||||
typeof params.userpass_changed != "boolean"
|
||||
) {
|
||||
var result = {
|
||||
adminpass: {
|
||||
expected: "string",
|
||||
got: params.hasOwnProperty("adminpass") ? typeof(params.adminpass) : undefined,
|
||||
got: params.hasOwnProperty("adminpass")
|
||||
? typeof params.adminpass
|
||||
: undefined
|
||||
},
|
||||
userpass: {
|
||||
expected: "string",
|
||||
got: params.hasOwnProperty("userpass") ? typeof(params.userpass) : undefined,
|
||||
got: params.hasOwnProperty("userpass")
|
||||
? typeof params.userpass
|
||||
: undefined
|
||||
},
|
||||
vote: {
|
||||
expected: "boolean",
|
||||
got: params.hasOwnProperty("vote") ? typeof(params.vote) : undefined,
|
||||
got: params.hasOwnProperty("vote") ? typeof params.vote : undefined
|
||||
},
|
||||
addsongs: {
|
||||
expected: "boolean",
|
||||
got: params.hasOwnProperty("addsongs") ? typeof(params.addsongs) : undefined,
|
||||
got: params.hasOwnProperty("addsongs")
|
||||
? typeof params.addsongs
|
||||
: undefined
|
||||
},
|
||||
longsongs: {
|
||||
expected: "boolean",
|
||||
got: params.hasOwnProperty("longsongs") ? typeof(params.longsongs) : undefined,
|
||||
got: params.hasOwnProperty("longsongs")
|
||||
? typeof params.longsongs
|
||||
: undefined
|
||||
},
|
||||
frontpage: {
|
||||
expected: "boolean",
|
||||
got: params.hasOwnProperty("frontpage") ? typeof(params.frontpage) : undefined,
|
||||
got: params.hasOwnProperty("frontpage")
|
||||
? typeof params.frontpage
|
||||
: undefined
|
||||
},
|
||||
skipping: {
|
||||
expected: "boolean",
|
||||
got: params.hasOwnProperty("skipping") ? typeof(params.skipping) : undefined,
|
||||
got: params.hasOwnProperty("skipping")
|
||||
? typeof params.skipping
|
||||
: undefined
|
||||
},
|
||||
shuffling: {
|
||||
expected: "boolean",
|
||||
got: params.hasOwnProperty("shuffling") ? typeof(params.shuffling) : undefined,
|
||||
got: params.hasOwnProperty("shuffling")
|
||||
? typeof params.shuffling
|
||||
: undefined
|
||||
},
|
||||
userpass_changed: {
|
||||
expected: "boolean",
|
||||
got: params.hasOwnProperty("userpass_changed") ? typeof(params.userpass_changed) : undefined,
|
||||
got: params.hasOwnProperty("userpass_changed")
|
||||
? typeof params.userpass_changed
|
||||
: undefined
|
||||
}
|
||||
};
|
||||
socket.emit("update_required", result);
|
||||
@@ -183,7 +247,10 @@ function conf_function(params, coll, guid, offline, socket) {
|
||||
|
||||
var userpass = Functions.decrypt_string(params.userpass);
|
||||
|
||||
if((!params.userpass_changed && frontpage) || (params.userpass_changed && userpass == "")) {
|
||||
if (
|
||||
(!params.userpass_changed && frontpage) ||
|
||||
(params.userpass_changed && userpass == "")
|
||||
) {
|
||||
userpass = "";
|
||||
} else if (params.userpass_changed && userpass != "") {
|
||||
frontpage = false;
|
||||
@@ -192,7 +259,9 @@ function conf_function(params, coll, guid, offline, socket) {
|
||||
var hash;
|
||||
if (params.description) description = params.description;
|
||||
if (adminpass !== "" && !gotten) {
|
||||
hash = Functions.hash_pass(Functions.hash_pass(Functions.decrypt_string(adminpass), true));
|
||||
hash = Functions.hash_pass(
|
||||
Functions.hash_pass(Functions.decrypt_string(adminpass), true)
|
||||
);
|
||||
} else if (adminpass !== "" && gotten) {
|
||||
hash = Functions.hash_pass(adminpass);
|
||||
} else {
|
||||
@@ -200,13 +269,22 @@ function conf_function(params, coll, guid, offline, socket) {
|
||||
}
|
||||
if (userpass != "") {
|
||||
if (!params.userpass_changed && gotten) {
|
||||
|
||||
} else {
|
||||
userpass = crypto.createHash('sha256').update(userpass).digest("base64");
|
||||
userpass = crypto
|
||||
.createHash("sha256")
|
||||
.update(userpass)
|
||||
.digest("base64");
|
||||
}
|
||||
}
|
||||
db.collection(coll + "_settings").find({id: "config"}, function(err, docs){
|
||||
if(docs !== null && docs.length !== 0 && (docs[0].adminpass === "" || docs[0].adminpass == hash)) {
|
||||
db.collection(coll + "_settings").find({ id: "config" }, function(
|
||||
err,
|
||||
docs
|
||||
) {
|
||||
if (
|
||||
docs !== null &&
|
||||
docs.length !== 0 &&
|
||||
(docs[0].adminpass === "" || docs[0].adminpass == hash)
|
||||
) {
|
||||
var obj = {
|
||||
addsongs: addsongs,
|
||||
allvideos: allvideos,
|
||||
@@ -217,15 +295,30 @@ function conf_function(params, coll, guid, offline, socket) {
|
||||
shuffle: shuffling,
|
||||
longsongs: longsongs,
|
||||
adminpass: hash,
|
||||
desc: description,
|
||||
desc: description
|
||||
};
|
||||
if(params.hasOwnProperty("toggleChat") && docs[0].adminpass != "" && docs[0].adminpass != undefined && docs[0].adminpass == hash) {
|
||||
if (
|
||||
params.hasOwnProperty("toggleChat") &&
|
||||
docs[0].adminpass != "" &&
|
||||
docs[0].adminpass != undefined &&
|
||||
docs[0].adminpass == hash
|
||||
) {
|
||||
obj.toggleChat = params.toggleChat;
|
||||
}
|
||||
if(params.hasOwnProperty("strictSkip") && docs[0].adminpass != "" && docs[0].adminpass != undefined && docs[0].adminpass == hash) {
|
||||
if (
|
||||
params.hasOwnProperty("strictSkip") &&
|
||||
docs[0].adminpass != "" &&
|
||||
docs[0].adminpass != undefined &&
|
||||
docs[0].adminpass == hash
|
||||
) {
|
||||
obj.strictSkip = params.strictSkip;
|
||||
}
|
||||
if(params.hasOwnProperty("strictSkipNumber") && docs[0].adminpass != "" && docs[0].adminpass != undefined && docs[0].adminpass == hash) {
|
||||
if (
|
||||
params.hasOwnProperty("strictSkipNumber") &&
|
||||
docs[0].adminpass != "" &&
|
||||
docs[0].adminpass != undefined &&
|
||||
docs[0].adminpass == hash
|
||||
) {
|
||||
try {
|
||||
obj.strictSkipNumber = parseInt(params.strictSkipNumber);
|
||||
} catch (e) {}
|
||||
@@ -235,33 +328,56 @@ function conf_function(params, coll, guid, offline, socket) {
|
||||
} else if (frontpage) {
|
||||
obj["userpass"] = "";
|
||||
}
|
||||
db.collection(coll + "_settings").update({ id: "config" }, {
|
||||
$set:obj
|
||||
}, function(err, docs){
|
||||
Functions.setSessionUserPass(Functions.getSession(socket), obj["userpass"], coll, function() {
|
||||
db.collection(coll + "_settings").aggregate([
|
||||
db.collection(coll + "_settings").update(
|
||||
{ id: "config" },
|
||||
{
|
||||
"$match": {
|
||||
$set: obj
|
||||
},
|
||||
function(err, docs) {
|
||||
Functions.setSessionUserPass(
|
||||
Functions.getSession(socket),
|
||||
obj["userpass"],
|
||||
coll,
|
||||
function() {
|
||||
db.collection(coll + "_settings").aggregate(
|
||||
[
|
||||
{
|
||||
$match: {
|
||||
id: "config"
|
||||
}
|
||||
},
|
||||
{
|
||||
"$project": projects.toShowConfig
|
||||
},
|
||||
], function(err, docs){
|
||||
$project: projects.toShowConfig
|
||||
}
|
||||
],
|
||||
function(err, docs) {
|
||||
if (docs[0].adminpass !== "") docs[0].adminpass = true;
|
||||
if(docs[0].hasOwnProperty("userpass") && docs[0].userpass != "") docs[0].userpass = true;
|
||||
if (
|
||||
docs[0].hasOwnProperty("userpass") &&
|
||||
docs[0].userpass != ""
|
||||
)
|
||||
docs[0].userpass = true;
|
||||
else docs[0].userpass = false;
|
||||
io.to(coll).emit("conf", docs);
|
||||
socket.emit("toast", "savedsettings");
|
||||
|
||||
db.collection("frontpage_lists").update({_id: coll}, {$set:{
|
||||
frontpage:frontpage, accessed: Functions.get_time()}
|
||||
db.collection("frontpage_lists").update(
|
||||
{ _id: coll },
|
||||
{
|
||||
$set: {
|
||||
frontpage: frontpage,
|
||||
accessed: Functions.get_time()
|
||||
}
|
||||
},
|
||||
{upsert:true}, function(err, docs){});
|
||||
});
|
||||
});
|
||||
});
|
||||
{ upsert: true },
|
||||
function(err, docs) {}
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
} else {
|
||||
socket.emit("toast", "wrongpass");
|
||||
}
|
||||
@@ -271,12 +387,11 @@ function conf_function(params, coll, guid, offline, socket) {
|
||||
var result = {
|
||||
params: {
|
||||
expected: "object",
|
||||
got: typeof(params),
|
||||
got: typeof params
|
||||
}
|
||||
};
|
||||
socket.emit("update_required", result);
|
||||
}
|
||||
socket.emit('update_required', result);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports.password = password;
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
var path = require('path');
|
||||
var path = require("path");
|
||||
|
||||
function requested_change(type, string, channel) {
|
||||
try {
|
||||
//channel = channel.replace(/ /g,'');
|
||||
var nodemailer = require('nodemailer');
|
||||
var mailconfig = require(path.join(__dirname, '../config/mailconfig.js'));
|
||||
var nodemailer = require("nodemailer");
|
||||
var mailconfig = require(path.join(__dirname, "../config/mailconfig.js"));
|
||||
|
||||
let transporter = nodemailer.createTransport(mailconfig);
|
||||
|
||||
@@ -12,15 +12,22 @@ function requested_change(type, string, channel) {
|
||||
if (error) {
|
||||
return;
|
||||
} else {
|
||||
var message = "A " + type + " change was requested on <b>" + channel + "</b><br><br>New supposed value is: <br><br><b>" + string + "</b><br><br><br> \
|
||||
var message =
|
||||
"A " +
|
||||
type +
|
||||
" change was requested on <b>" +
|
||||
channel +
|
||||
"</b><br><br>New supposed value is: <br><br><b>" +
|
||||
string +
|
||||
"</b><br><br><br> \
|
||||
Go to <a href='https://admin.zoff.me/'>https://admin.zoff.me/</a> to accept or decline the request.";
|
||||
var msg = {
|
||||
from: mailconfig.from,
|
||||
to: mailconfig.notify_mail,
|
||||
subject: 'ZOFF: Requested new ' + type,
|
||||
subject: "ZOFF: Requested new " + type,
|
||||
text: message,
|
||||
html: message,
|
||||
}
|
||||
html: message
|
||||
};
|
||||
transporter.sendMail(msg, (error, info) => {
|
||||
if (error) {
|
||||
transporter.close();
|
||||
@@ -32,7 +39,9 @@ function requested_change(type, string, channel) {
|
||||
});
|
||||
} catch (e) {
|
||||
console.log("Mail is not configured and wont work");
|
||||
console.log("Seems you forgot to create a mailconfig.js in /server/config/. Have a look at the mailconfig.example.js.");
|
||||
console.log(
|
||||
"Seems you forgot to create a mailconfig.js in /server/config/. Have a look at the mailconfig.example.js."
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,16 +1,17 @@
|
||||
var path = require('path');
|
||||
var path = require("path");
|
||||
var time_regex = /P((([0-9]*\.?[0-9]*)Y)?(([0-9]*\.?[0-9]*)M)?(([0-9]*\.?[0-9]*)W)?(([0-9]*\.?[0-9]*)D)?)?(T(([0-9]*\.?[0-9]*)H)?(([0-9]*\.?[0-9]*)M)?(([0-9]*\.?[0-9]*)S)?)?/;
|
||||
try {
|
||||
var keys = require(path.join(__dirname, '../config/api_key.js'));
|
||||
var keys = require(path.join(__dirname, "../config/api_key.js"));
|
||||
var key = keys.youtube;
|
||||
var soundcloudKey = keys.soundcloud;
|
||||
} catch (e) {
|
||||
console.log("Error - missing file");
|
||||
console.log("Seems you forgot to create the file api_key.js in /server/config/. Have a look at api_key.example.js.");
|
||||
console.log(
|
||||
"(!) Missing file - /config/api_key.js Have a look at /config/api_key.example.js. The server won't run without this existing."
|
||||
);
|
||||
process.exit(1);
|
||||
}
|
||||
var request = require('request');
|
||||
var db = require(pathThumbnails + '/handlers/db.js');
|
||||
var request = require("request");
|
||||
var db = require(pathThumbnails + "/handlers/db.js");
|
||||
var countryCodes = ["US", "NO", "SE", "DK", "CA", "EU", "UK"];
|
||||
|
||||
function check_if_error_or_blocked(id, channel, errored, callback) {
|
||||
@@ -18,17 +19,26 @@ function check_if_error_or_blocked(id, channel, errored, callback) {
|
||||
callback(false);
|
||||
return;
|
||||
}
|
||||
db.collection(channel).find({id: id, now_playing: true}, function(err, song) {
|
||||
db.collection(channel).find({ id: id, now_playing: true }, function(
|
||||
err,
|
||||
song
|
||||
) {
|
||||
if (song.length == 0) {
|
||||
callback(false);
|
||||
return;
|
||||
}
|
||||
var song_info = song[0];
|
||||
if (song_info.source != "soundcloud") {
|
||||
request({
|
||||
request(
|
||||
{
|
||||
type: "GET",
|
||||
url: "https://www.googleapis.com/youtube/v3/videos?part=id,status,contentDetails&key="+key+"&id=" + song_info.id,
|
||||
}, function(error, response, body) {
|
||||
url:
|
||||
"https://www.googleapis.com/youtube/v3/videos?part=id,status,contentDetails&key=" +
|
||||
key +
|
||||
"&id=" +
|
||||
song_info.id
|
||||
},
|
||||
function(error, response, body) {
|
||||
try {
|
||||
var resp = JSON.parse(body);
|
||||
if (resp.pageInfo.totalResults == 0) {
|
||||
@@ -37,14 +47,24 @@ function check_if_error_or_blocked(id, channel, errored, callback) {
|
||||
} else if (!resp.items[0].status.embeddable) {
|
||||
callback(true);
|
||||
return;
|
||||
} else if(resp.items[0].contentDetails.hasOwnProperty("licensedContent") &&
|
||||
resp.items[0].contentDetails.licensedContent) {
|
||||
} else if (
|
||||
resp.items[0].contentDetails.hasOwnProperty("licensedContent") &&
|
||||
resp.items[0].contentDetails.licensedContent
|
||||
) {
|
||||
callback(true);
|
||||
return;
|
||||
} else if(resp.items[0].contentDetails.hasOwnProperty("regionRestriction") &&
|
||||
resp.items[0].contentDetails.regionRestriction.hasOwnProperty("blocked") &&
|
||||
resp.items[0].contentDetails.regionRestriction.blocked.length > 0) {
|
||||
var any = resp.items[0].contentDetails.blocked.some(function(element) {
|
||||
} else if (
|
||||
resp.items[0].contentDetails.hasOwnProperty(
|
||||
"regionRestriction"
|
||||
) &&
|
||||
resp.items[0].contentDetails.regionRestriction.hasOwnProperty(
|
||||
"blocked"
|
||||
) &&
|
||||
resp.items[0].contentDetails.regionRestriction.blocked.length > 0
|
||||
) {
|
||||
var any = resp.items[0].contentDetails.blocked.some(function(
|
||||
element
|
||||
) {
|
||||
return countryCodes.indexOf(element) > -1;
|
||||
});
|
||||
if (any) {
|
||||
@@ -58,12 +78,19 @@ function check_if_error_or_blocked(id, channel, errored, callback) {
|
||||
callback(true);
|
||||
return;
|
||||
}
|
||||
});
|
||||
}
|
||||
);
|
||||
} else {
|
||||
request({
|
||||
request(
|
||||
{
|
||||
type: "GET",
|
||||
url: "http://api.soundcloud.com/tracks/" + song_info.id + "?client_id=" + soundcloudKey,
|
||||
}, function(error, response, body) {
|
||||
url:
|
||||
"http://api.soundcloud.com/tracks/" +
|
||||
song_info.id +
|
||||
"?client_id=" +
|
||||
soundcloudKey
|
||||
},
|
||||
function(error, response, body) {
|
||||
try {
|
||||
var resp = JSON.parse(body);
|
||||
if (resp.sharing != "public" || resp.embeddable_by != "all") {
|
||||
@@ -76,42 +103,55 @@ function check_if_error_or_blocked(id, channel, errored, callback) {
|
||||
callback(true);
|
||||
return;
|
||||
}
|
||||
});
|
||||
}
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function filterFunction(el) {
|
||||
return el != null &&
|
||||
el != "" &&
|
||||
el != undefined &&
|
||||
el.trim() != ''
|
||||
return el != null && el != "" && el != undefined && el.trim() != "";
|
||||
}
|
||||
|
||||
function get_genres_soundcloud(song, channel) {
|
||||
request("http://api.soundcloud.com/tracks/" + song.id + "?client_id=" + soundcloudKey, function(err, response, body) {
|
||||
request(
|
||||
"http://api.soundcloud.com/tracks/" +
|
||||
song.id +
|
||||
"?client_id=" +
|
||||
soundcloudKey,
|
||||
function(err, response, body) {
|
||||
if (err) {
|
||||
console.log("error start", err, song, "error end");
|
||||
return;
|
||||
}
|
||||
try {
|
||||
var object = JSON.parse(body);
|
||||
if(!object.hasOwnProperty("genre") || !object.hasOwnProperty("tag_list")) return;
|
||||
if (
|
||||
!object.hasOwnProperty("genre") ||
|
||||
!object.hasOwnProperty("tag_list")
|
||||
)
|
||||
return;
|
||||
var genre = object.genre + ",";
|
||||
genre = genre.toLowerCase().split(",").concat(object.tag_list.toLowerCase().split('"'));
|
||||
genre = genre
|
||||
.toLowerCase()
|
||||
.split(",")
|
||||
.concat(object.tag_list.toLowerCase().split('"'));
|
||||
genre = genre.filter(filterFunction);
|
||||
|
||||
db.collection(channel).update({"id": song.id}, {
|
||||
db.collection(channel).update(
|
||||
{ id: song.id },
|
||||
{
|
||||
$set: {
|
||||
"tags": genre
|
||||
tags: genre
|
||||
}
|
||||
}, function(e,d) {
|
||||
|
||||
});
|
||||
},
|
||||
function(e, d) {}
|
||||
);
|
||||
} catch (e) {
|
||||
console.log("errored 2", e);
|
||||
}
|
||||
});
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
function get_genres_list(list, channel) {
|
||||
@@ -119,12 +159,13 @@ function get_genres_list(list, channel) {
|
||||
var i = 0;
|
||||
try {
|
||||
for (var i = 0; i < list.length; i++) {
|
||||
|
||||
if (!list[i].hasOwnProperty("id")) continue;
|
||||
if (list[i].source == undefined || list[i].source == "youtube") {
|
||||
youtube_array += list[i].id + ",";
|
||||
}
|
||||
else if(list[i].source != undefined && list[i].source == "soundcloud") {
|
||||
} else if (
|
||||
list[i].source != undefined &&
|
||||
list[i].source == "soundcloud"
|
||||
) {
|
||||
get_genres_soundcloud(list[i], channel);
|
||||
}
|
||||
}
|
||||
@@ -150,18 +191,22 @@ function get_genres_list(list, channel) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function start_soundcloud_get(arr, channel, callback) {
|
||||
get_genres_soundcloud_recursive(arr, channel, 0, callback);
|
||||
}
|
||||
|
||||
function get_genres_soundcloud_recursive(arr, channel, i, callback) {
|
||||
if (i >= arr.length) {
|
||||
if(typeof(callback) == "function") callback();
|
||||
if (typeof callback == "function") callback();
|
||||
return;
|
||||
}
|
||||
var song = arr[i];
|
||||
request("http://api.soundcloud.com/tracks/" + song.id + "?client_id=" + soundcloudKey, function(err, response, body) {
|
||||
request(
|
||||
"http://api.soundcloud.com/tracks/" +
|
||||
song.id +
|
||||
"?client_id=" +
|
||||
soundcloudKey,
|
||||
function(err, response, body) {
|
||||
if (err) {
|
||||
console.log("error start", err, song, "error end");
|
||||
get_genres_soundcloud_recursive(arr, channel, i + 1, callback);
|
||||
@@ -169,26 +214,37 @@ function get_genres_soundcloud_recursive(arr, channel, i, callback) {
|
||||
}
|
||||
try {
|
||||
var object = JSON.parse(body);
|
||||
if(!object.hasOwnProperty("genre") || !object.hasOwnProperty("tag_list")) {
|
||||
if (
|
||||
!object.hasOwnProperty("genre") ||
|
||||
!object.hasOwnProperty("tag_list")
|
||||
) {
|
||||
get_genres_soundcloud_recursive(arr, channel, i + 1, callback);
|
||||
return;
|
||||
}
|
||||
var genre = object.genre + ",";
|
||||
genre = genre.toLowerCase().split(",").concat(object.tag_list.toLowerCase().split('"'));
|
||||
genre = genre
|
||||
.toLowerCase()
|
||||
.split(",")
|
||||
.concat(object.tag_list.toLowerCase().split('"'));
|
||||
genre = genre.filter(filterFunction);
|
||||
|
||||
db.collection(channel).update({"id": song.id}, {
|
||||
db.collection(channel).update(
|
||||
{ id: song.id },
|
||||
{
|
||||
$set: {
|
||||
"tags": genre
|
||||
tags: genre
|
||||
}
|
||||
}, function(e,d) {
|
||||
},
|
||||
function(e, d) {
|
||||
get_genres_soundcloud_recursive(arr, channel, i + 1, callback);
|
||||
});
|
||||
}
|
||||
);
|
||||
} catch (e) {
|
||||
console.log("errored 2", e);
|
||||
get_genres_soundcloud_recursive(arr, channel, i + 1, callback);
|
||||
}
|
||||
});
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
function get_genres_list_recursive(list, channel, callback) {
|
||||
@@ -198,25 +254,24 @@ function get_genres_list_recursive(list, channel, callback) {
|
||||
if (!list[i].hasOwnProperty("id")) continue;
|
||||
if (list[i].source == undefined || list[i].source == "youtube") {
|
||||
youtube_array.push(list[i]);
|
||||
}
|
||||
else if(list[i].source != undefined && list[i].source == "soundcloud") {
|
||||
} else if (list[i].source != undefined && list[i].source == "soundcloud") {
|
||||
soundcloud_array.push(list[i]);
|
||||
}
|
||||
}
|
||||
start_youtube_get(youtube_array, channel, function() {
|
||||
start_soundcloud_get(soundcloud_array, channel, function() {
|
||||
if(typeof(callback) == "function") callback();
|
||||
})
|
||||
})
|
||||
if (typeof callback == "function") callback();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function start_youtube_get(arr, channel, callback) {
|
||||
get_genres_youtube_recursive(arr, channel, 0, callback)
|
||||
get_genres_youtube_recursive(arr, channel, 0, callback);
|
||||
}
|
||||
|
||||
function get_genres_youtube_recursive(arr, channel, i, callback) {
|
||||
if (i >= arr.length) {
|
||||
if(typeof(callback) == "function") callback();
|
||||
if (typeof callback == "function") callback();
|
||||
return;
|
||||
}
|
||||
var ids = [];
|
||||
@@ -226,10 +281,16 @@ function get_genres_youtube_recursive(arr, channel, i, callback) {
|
||||
}
|
||||
ids.push(arr[y].id);
|
||||
}
|
||||
request({
|
||||
request(
|
||||
{
|
||||
type: "GET",
|
||||
url: "https://www.googleapis.com/youtube/v3/videos?part=contentDetails,snippet,id,topicDetails&key="+key+"&id=" + ids.join(","),
|
||||
}, function(error, response, body) {
|
||||
url:
|
||||
"https://www.googleapis.com/youtube/v3/videos?part=contentDetails,snippet,id,topicDetails&key=" +
|
||||
key +
|
||||
"&id=" +
|
||||
ids.join(",")
|
||||
},
|
||||
function(error, response, body) {
|
||||
if (error) {
|
||||
get_genres_youtube_recursive(arr, channel, i + ids.length, callback);
|
||||
return;
|
||||
@@ -244,30 +305,45 @@ function get_genres_youtube_recursive(arr, channel, i, callback) {
|
||||
if (!resp.items[z].hasOwnProperty("topicDetails")) continue;
|
||||
var genre = resp.items[z].topicDetails.topicCategories;
|
||||
genre = genre.join(",");
|
||||
genre = genre.replace(new RegExp("https://en.wikipedia.org/wiki/", "g"), "");
|
||||
genre = genre.replace(/_/g, " ").toLowerCase().split(",");
|
||||
genre = genre.replace(
|
||||
new RegExp("https://en.wikipedia.org/wiki/", "g"),
|
||||
""
|
||||
);
|
||||
genre = genre
|
||||
.replace(/_/g, " ")
|
||||
.toLowerCase()
|
||||
.split(",");
|
||||
genre = genre.filter(filterFunction);
|
||||
//console.log(resp.items[i].id + " - ", genre);
|
||||
db.collection(channel).update({"id": resp.items[z].id}, {
|
||||
db.collection(channel).update(
|
||||
{ id: resp.items[z].id },
|
||||
{
|
||||
$set: {
|
||||
"tags": genre
|
||||
tags: genre
|
||||
}
|
||||
}, function(e, d) {
|
||||
});
|
||||
},
|
||||
function(e, d) {}
|
||||
);
|
||||
}
|
||||
get_genres_youtube_recursive(arr, channel, i + ids.length, callback);
|
||||
} else {
|
||||
get_genres_youtube_recursive(arr, channel, i + ids.length, callback);
|
||||
}
|
||||
});
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
function get_genres_youtube(ids, channel) {
|
||||
request({
|
||||
request(
|
||||
{
|
||||
type: "GET",
|
||||
url: "https://www.googleapis.com/youtube/v3/videos?part=contentDetails,snippet,id,topicDetails&key="+key+"&id=" + ids,
|
||||
}, function(error, response, body) {
|
||||
url:
|
||||
"https://www.googleapis.com/youtube/v3/videos?part=contentDetails,snippet,id,topicDetails&key=" +
|
||||
key +
|
||||
"&id=" +
|
||||
ids
|
||||
},
|
||||
function(error, response, body) {
|
||||
if (error) {
|
||||
return;
|
||||
}
|
||||
@@ -280,39 +356,66 @@ function get_genres_youtube(ids, channel) {
|
||||
if (!resp.items[i].hasOwnProperty("topicDetails")) continue;
|
||||
var genre = resp.items[i].topicDetails.topicCategories;
|
||||
genre = genre.join(",");
|
||||
genre = genre.replace(new RegExp("https://en.wikipedia.org/wiki/", "g"), "");
|
||||
genre = genre.replace(/_/g, " ").toLowerCase().split(",");
|
||||
genre = genre.replace(
|
||||
new RegExp("https://en.wikipedia.org/wiki/", "g"),
|
||||
""
|
||||
);
|
||||
genre = genre
|
||||
.replace(/_/g, " ")
|
||||
.toLowerCase()
|
||||
.split(",");
|
||||
genre = genre.filter(filterFunction);
|
||||
//console.log(resp.items[i].id + " - ", genre);
|
||||
db.collection(channel).update({"id": resp.items[i].id}, {
|
||||
db.collection(channel).update(
|
||||
{ id: resp.items[i].id },
|
||||
{
|
||||
$set: {
|
||||
"tags": genre
|
||||
tags: genre
|
||||
}
|
||||
}, function(e, d) {});
|
||||
},
|
||||
function(e, d) {}
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
function get_correct_info(song_generated, channel, broadcast, callback) {
|
||||
//channel = channel.replace(/ /g,'');
|
||||
request({
|
||||
request(
|
||||
{
|
||||
type: "GET",
|
||||
url: "https://www.googleapis.com/youtube/v3/videos?part=contentDetails,snippet,id,topicDetails&key="+key+"&id=" + song_generated.id,
|
||||
|
||||
}, function(error, response, body) {
|
||||
url:
|
||||
"https://www.googleapis.com/youtube/v3/videos?part=contentDetails,snippet,id,topicDetails&key=" +
|
||||
key +
|
||||
"&id=" +
|
||||
song_generated.id
|
||||
},
|
||||
function(error, response, body) {
|
||||
try {
|
||||
var resp = JSON.parse(body);
|
||||
if (resp.items.length == 1) {
|
||||
var duration = parseInt(durationToSeconds(resp.items[0].contentDetails.duration));
|
||||
var duration = parseInt(
|
||||
durationToSeconds(resp.items[0].contentDetails.duration)
|
||||
);
|
||||
var title = resp.items[0].snippet.localized.title;
|
||||
var genre = resp.items[0].topicDetails.topicCategories;
|
||||
genre = genre.join(",");
|
||||
genre = genre.replace(new RegExp("https://en.wikipedia.org/wiki/", "g"), "");
|
||||
genre = genre.replace(/_/g, " ").toLowerCase().split(",");
|
||||
genre = genre.replace(
|
||||
new RegExp("https://en.wikipedia.org/wiki/", "g"),
|
||||
""
|
||||
);
|
||||
genre = genre
|
||||
.replace(/_/g, " ")
|
||||
.toLowerCase()
|
||||
.split(",");
|
||||
genre = genre.filter(filterFunction);
|
||||
//console.log(genre + " - ", song_generated.id);
|
||||
if(title != song_generated.title || duration < parseInt(song_generated.duration)) {
|
||||
if (
|
||||
title != song_generated.title ||
|
||||
duration < parseInt(song_generated.duration)
|
||||
) {
|
||||
if (title != song_generated.title) {
|
||||
song_generated.title = title;
|
||||
}
|
||||
@@ -321,73 +424,94 @@ function get_correct_info(song_generated, channel, broadcast, callback) {
|
||||
song_generated.start = 0;
|
||||
song_generated.end = duration;
|
||||
}
|
||||
db.collection(channel).update({"id": song_generated.id}, {
|
||||
db.collection(channel).update(
|
||||
{ id: song_generated.id },
|
||||
{
|
||||
$set: {
|
||||
"duration": song_generated.duration,
|
||||
"start": song_generated.start,
|
||||
"end": song_generated.end,
|
||||
"title": song_generated.title,
|
||||
"tags": genre
|
||||
duration: song_generated.duration,
|
||||
start: song_generated.start,
|
||||
end: song_generated.end,
|
||||
title: song_generated.title,
|
||||
tags: genre
|
||||
}
|
||||
}, function(err, docs) {
|
||||
},
|
||||
function(err, docs) {
|
||||
if (broadcast && docs.nModified == 1) {
|
||||
song_generated.new_id = song_generated.id;
|
||||
//if(song_generated.type == "video")
|
||||
if(typeof(callback) == "function") {
|
||||
if (typeof callback == "function") {
|
||||
callback(song_generated, true);
|
||||
} else {
|
||||
io.to(channel).emit("channel", {type: "changed_values", value: song_generated});
|
||||
}
|
||||
} else {
|
||||
if(typeof(callback) == "function") {
|
||||
callback(song_generated, true);
|
||||
}
|
||||
}
|
||||
io.to(channel).emit("channel", {
|
||||
type: "changed_values",
|
||||
value: song_generated
|
||||
});
|
||||
}
|
||||
} else {
|
||||
db.collection(channel).update({"id": song_generated.id}, {
|
||||
if (typeof callback == "function") {
|
||||
callback(song_generated, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
} else {
|
||||
db.collection(channel).update(
|
||||
{ id: song_generated.id },
|
||||
{
|
||||
$set: {
|
||||
"tags": genre
|
||||
tags: genre
|
||||
}
|
||||
}, function(e,d) {
|
||||
if(typeof(callback) == "function") {
|
||||
},
|
||||
function(e, d) {
|
||||
if (typeof callback == "function") {
|
||||
callback(song_generated, true);
|
||||
}
|
||||
});
|
||||
}
|
||||
);
|
||||
}
|
||||
} else {
|
||||
findSimilar(song_generated, channel, broadcast, callback)
|
||||
findSimilar(song_generated, channel, broadcast, callback);
|
||||
}
|
||||
} catch (e) {
|
||||
if(typeof(callback) == "function") {
|
||||
if (typeof callback == "function") {
|
||||
callback({}, false);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
function check_error_video(msg, channel) {
|
||||
if(!msg.hasOwnProperty("id") || !msg.hasOwnProperty("title") ||
|
||||
typeof(msg.id) != "string" || typeof(msg.title) != "string") {
|
||||
if (
|
||||
!msg.hasOwnProperty("id") ||
|
||||
!msg.hasOwnProperty("title") ||
|
||||
typeof msg.id != "string" ||
|
||||
typeof msg.title != "string"
|
||||
) {
|
||||
var result = {
|
||||
id: {
|
||||
expected: "string",
|
||||
got: msg.hasOwnProperty("id") ? typeof(msg.id) : undefined,
|
||||
got: msg.hasOwnProperty("id") ? typeof msg.id : undefined
|
||||
},
|
||||
title: {
|
||||
expected: "string",
|
||||
got: msg.hasOwnProperty("title") ? typeof(msg.title) : undefined,
|
||||
},
|
||||
got: msg.hasOwnProperty("title") ? typeof msg.title : undefined
|
||||
}
|
||||
};
|
||||
return;
|
||||
}
|
||||
if (msg.source == "soundcloud") return;
|
||||
//channel = channel.replace(/ /g,'');
|
||||
request({
|
||||
request(
|
||||
{
|
||||
type: "GET",
|
||||
url: "https://www.googleapis.com/youtube/v3/videos?part=id&key="+key+"&id=" + msg.id,
|
||||
|
||||
}, function(error, response, body) {
|
||||
url:
|
||||
"https://www.googleapis.com/youtube/v3/videos?part=id&key=" +
|
||||
key +
|
||||
"&id=" +
|
||||
msg.id
|
||||
},
|
||||
function(error, response, body) {
|
||||
try {
|
||||
var resp = JSON.parse(body);
|
||||
if (resp.pageInfo.totalResults == 0) {
|
||||
@@ -396,54 +520,84 @@ function check_error_video(msg, channel) {
|
||||
} catch (e) {
|
||||
console.log(msg.id, key, e, body);
|
||||
}
|
||||
});
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
function findSimilar(msg, channel, broadcast, callback) {
|
||||
//channel = channel.replace(/ /g,'');
|
||||
var yt_url = "https://www.googleapis.com/youtube/v3/search?key="+key+"&videoEmbeddable=true&part=id&type=video&order=viewCount&safeSearch=none&maxResults=5&q=" + encodeURIComponent(msg.title);
|
||||
request({
|
||||
var yt_url =
|
||||
"https://www.googleapis.com/youtube/v3/search?key=" +
|
||||
key +
|
||||
"&videoEmbeddable=true&part=id&type=video&order=viewCount&safeSearch=none&maxResults=5&q=" +
|
||||
encodeURIComponent(msg.title);
|
||||
request(
|
||||
{
|
||||
method: "GET",
|
||||
url: yt_url,
|
||||
}, function(error, response, body){
|
||||
url: yt_url
|
||||
},
|
||||
function(error, response, body) {
|
||||
var resp = JSON.parse(body);
|
||||
if (resp.items.length > 0) {
|
||||
var vid_url = "https://www.googleapis.com/youtube/v3/videos?part=contentDetails,snippet,id&key="+key+"&id=";
|
||||
var vid_url =
|
||||
"https://www.googleapis.com/youtube/v3/videos?part=contentDetails,snippet,id&key=" +
|
||||
key +
|
||||
"&id=";
|
||||
for (var i = 0; i < resp.items.length; i++) {
|
||||
vid_url += resp.items[i].id.videoId + ",";
|
||||
}
|
||||
request({
|
||||
request(
|
||||
{
|
||||
type: "GET",
|
||||
url: vid_url
|
||||
}, function(error, response, body) {
|
||||
},
|
||||
function(error, response, body) {
|
||||
var resp = JSON.parse(body);
|
||||
var found = false;
|
||||
var element = {};
|
||||
for (var i = 0; i < resp.items.length; i++) {
|
||||
if(similarity(resp.items[i].snippet.localized.title, msg.title) > 0.75) {
|
||||
if (
|
||||
similarity(resp.items[i].snippet.localized.title, msg.title) >
|
||||
0.75
|
||||
) {
|
||||
found = true;
|
||||
element = {
|
||||
title: resp.items[i].snippet.localized.title,
|
||||
duration: parseInt(durationToSeconds(resp.items[i].contentDetails.duration)),
|
||||
duration: parseInt(
|
||||
durationToSeconds(resp.items[i].contentDetails.duration)
|
||||
),
|
||||
id: resp.items[i].id,
|
||||
start: 0,
|
||||
end: parseInt(durationToSeconds(resp.items[i].contentDetails.duration)),
|
||||
}
|
||||
end: parseInt(
|
||||
durationToSeconds(resp.items[i].contentDetails.duration)
|
||||
)
|
||||
};
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (found) {
|
||||
db.collection(channel).update({"id": msg.id}, {
|
||||
db.collection(channel).update(
|
||||
{ id: msg.id },
|
||||
{
|
||||
$set: element
|
||||
}, function(err, docs) {
|
||||
if(docs && docs.hasOwnProperty("nModified") && docs.nModified == 1 && broadcast) {
|
||||
},
|
||||
function(err, docs) {
|
||||
if (
|
||||
docs &&
|
||||
docs.hasOwnProperty("nModified") &&
|
||||
docs.nModified == 1 &&
|
||||
broadcast
|
||||
) {
|
||||
element.new_id = element.id;
|
||||
element.id = msg.id;
|
||||
if (!callback) {
|
||||
io.to(channel).emit("channel", {type: "changed_values", value: element});
|
||||
io.to(channel).emit("channel", {
|
||||
type: "changed_values",
|
||||
value: element
|
||||
});
|
||||
}
|
||||
}
|
||||
if(typeof(callback) == "function") {
|
||||
if (typeof callback == "function") {
|
||||
msg.title = element.title;
|
||||
msg.id = element.id;
|
||||
msg.duration = element.duration;
|
||||
@@ -451,13 +605,16 @@ function findSimilar(msg, channel, broadcast, callback) {
|
||||
msg.end = element.end;
|
||||
callback(msg, true);
|
||||
}
|
||||
});
|
||||
} else if(typeof(callback) == "function") {
|
||||
}
|
||||
);
|
||||
} else if (typeof callback == "function") {
|
||||
callback({}, false);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
function similarity(s1, s2) {
|
||||
@@ -471,7 +628,9 @@ function similarity(s1, s2) {
|
||||
if (longerLength == 0) {
|
||||
return 1.0;
|
||||
}
|
||||
return (longerLength - editDistance(longer, shorter)) / parseFloat(longerLength);
|
||||
return (
|
||||
(longerLength - editDistance(longer, shorter)) / parseFloat(longerLength)
|
||||
);
|
||||
}
|
||||
|
||||
function editDistance(s1, s2) {
|
||||
@@ -482,21 +641,18 @@ function editDistance(s1, s2) {
|
||||
for (var i = 0; i <= s1.length; i++) {
|
||||
var lastValue = i;
|
||||
for (var j = 0; j <= s2.length; j++) {
|
||||
if (i == 0)
|
||||
costs[j] = j;
|
||||
if (i == 0) costs[j] = j;
|
||||
else {
|
||||
if (j > 0) {
|
||||
var newValue = costs[j - 1];
|
||||
if (s1.charAt(i - 1) != s2.charAt(j - 1))
|
||||
newValue = Math.min(Math.min(newValue, lastValue),
|
||||
costs[j]) + 1;
|
||||
newValue = Math.min(Math.min(newValue, lastValue), costs[j]) + 1;
|
||||
costs[j - 1] = lastValue;
|
||||
lastValue = newValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (i > 0)
|
||||
costs[s2.length] = lastValue;
|
||||
if (i > 0) costs[s2.length] = lastValue;
|
||||
}
|
||||
return costs[s2.length];
|
||||
}
|
||||
|
||||
@@ -1,58 +1,97 @@
|
||||
var Functions = require(pathThumbnails + '/handlers/functions.js');
|
||||
var Notifications = require(pathThumbnails + '/handlers/notifications.js');
|
||||
var crypto = require('crypto');
|
||||
var db = require(pathThumbnails + '/handlers/db.js');
|
||||
var Functions = require(pathThumbnails + "/handlers/functions.js");
|
||||
var Notifications = require(pathThumbnails + "/handlers/notifications.js");
|
||||
var crypto = require("crypto");
|
||||
var db = require(pathThumbnails + "/handlers/db.js");
|
||||
|
||||
function thumbnail(msg, coll, guid, offline, socket) {
|
||||
if(msg.thumbnail != undefined && msg.channel && msg.channel != undefined && Functions.isUrl(msg.thumbnail)){
|
||||
if(typeof(msg.channel) != "string" || typeof(msg.thumbnail) != "string")
|
||||
{
|
||||
if (
|
||||
msg.thumbnail != undefined &&
|
||||
msg.channel &&
|
||||
msg.channel != undefined &&
|
||||
Functions.isUrl(msg.thumbnail)
|
||||
) {
|
||||
if (typeof msg.channel != "string" || typeof msg.thumbnail != "string") {
|
||||
var result = {
|
||||
channel: {
|
||||
expected: "string",
|
||||
got: msg.hasOwnProperty("channel") ? typeof(msg.channel) : undefined,
|
||||
got: msg.hasOwnProperty("channel") ? typeof msg.channel : undefined
|
||||
},
|
||||
pass: {
|
||||
expected: "string",
|
||||
got: msg.hasOwnProperty("pass") ? typeof(msg.pass) : undefined,
|
||||
got: msg.hasOwnProperty("pass") ? typeof msg.pass : undefined
|
||||
},
|
||||
thumbnail: {
|
||||
expected: "string",
|
||||
got: msg.hasOwnProperty("thumbnail") ? typeof(msg.thumbnail) : undefined,
|
||||
got: msg.hasOwnProperty("thumbnail")
|
||||
? typeof msg.thumbnail
|
||||
: undefined
|
||||
},
|
||||
adminpass: {
|
||||
expected: "string",
|
||||
got: msg.hasOwnProperty("adminpass") ? typeof(msg.adminpass) : undefined,
|
||||
},
|
||||
got: msg.hasOwnProperty("adminpass")
|
||||
? typeof msg.adminpass
|
||||
: undefined
|
||||
}
|
||||
};
|
||||
socket.emit("update_required", result);
|
||||
return;
|
||||
}
|
||||
//coll = coll.replace(/ /g,'');
|
||||
Functions.getSessionAdminUser(Functions.getSession(socket), coll, function(userpass, adminpass) {
|
||||
Functions.getSessionAdminUser(Functions.getSession(socket), coll, function(
|
||||
userpass,
|
||||
adminpass
|
||||
) {
|
||||
if (userpass != "" || msg.pass == undefined) {
|
||||
msg.pass = userpass;
|
||||
} else if (msg.hasOwnProperty("pass")) {
|
||||
msg.pass = crypto.createHash('sha256').update(Functions.decrypt_string(msg.pass)).digest("base64");
|
||||
msg.pass = crypto
|
||||
.createHash("sha256")
|
||||
.update(Functions.decrypt_string(msg.pass))
|
||||
.digest("base64");
|
||||
}
|
||||
if(adminpass != "" || msg.adminpass == undefined) {
|
||||
if (adminpass != "" || msg.adminpass == undefined) {
|
||||
msg.adminpass = Functions.hash_pass(adminpass);
|
||||
} else {
|
||||
msg.adminpass = Functions.hash_pass(Functions.hash_pass(Functions.decrypt_string(msg.adminpass),true));
|
||||
msg.adminpass = Functions.hash_pass(
|
||||
Functions.hash_pass(Functions.decrypt_string(msg.adminpass), true)
|
||||
);
|
||||
}
|
||||
if (msg.thumbnail != "") {
|
||||
msg.thumbnail = msg.thumbnail.replace(/^https?\:\/\//i, "");
|
||||
if(msg.thumbnail.substring(0,2) != "//") msg.thumbnail = "//" + msg.thumbnail;
|
||||
if (msg.thumbnail.substring(0, 2) != "//")
|
||||
msg.thumbnail = "//" + msg.thumbnail;
|
||||
}
|
||||
var channel = msg.channel.toLowerCase();
|
||||
var hash = msg.adminpass;
|
||||
db.collection(channel + "_settings").find({id: "config"}, function(err, docs){
|
||||
if(docs.length > 0 && (docs[0].userpass == undefined || docs[0].userpass == "" || (msg.hasOwnProperty('pass') && docs[0].userpass == msg.pass))) {
|
||||
if(docs !== null && docs.length !== 0 && docs[0].adminpass !== "" && docs[0].adminpass == hash){
|
||||
db.collection("suggested_thumbnails").update({channel: channel}, {$set:{thumbnail: msg.thumbnail}}, {upsert:true}, function(err, docs){
|
||||
Notifications.requested_change("thumbnail", msg.thumbnail, channel);
|
||||
db.collection(channel + "_settings").find({ id: "config" }, function(
|
||||
err,
|
||||
docs
|
||||
) {
|
||||
if (
|
||||
docs.length > 0 &&
|
||||
(docs[0].userpass == undefined ||
|
||||
docs[0].userpass == "" ||
|
||||
(msg.hasOwnProperty("pass") && docs[0].userpass == msg.pass))
|
||||
) {
|
||||
if (
|
||||
docs !== null &&
|
||||
docs.length !== 0 &&
|
||||
docs[0].adminpass !== "" &&
|
||||
docs[0].adminpass == hash
|
||||
) {
|
||||
db.collection("suggested_thumbnails").update(
|
||||
{ channel: channel },
|
||||
{ $set: { thumbnail: msg.thumbnail } },
|
||||
{ upsert: true },
|
||||
function(err, docs) {
|
||||
Notifications.requested_change(
|
||||
"thumbnail",
|
||||
msg.thumbnail,
|
||||
channel
|
||||
);
|
||||
socket.emit("toast", "suggested_thumbnail");
|
||||
});
|
||||
}
|
||||
);
|
||||
}
|
||||
} else {
|
||||
socket.emit("auth_required");
|
||||
@@ -66,49 +105,84 @@ function thumbnail(msg, coll, guid, offline, socket) {
|
||||
|
||||
function description(msg, coll, guid, offline, socket) {
|
||||
if (msg.description && msg.channel && msg.description.length < 100) {
|
||||
if(typeof(msg.channel) != "string" || typeof(msg.description) != "string") {
|
||||
if (typeof msg.channel != "string" || typeof msg.description != "string") {
|
||||
var result = {
|
||||
channel: {
|
||||
expected: "string",
|
||||
got: msg.hasOwnProperty("channel") ? typeof(msg.channel) : undefined,
|
||||
got: msg.hasOwnProperty("channel") ? typeof msg.channel : undefined
|
||||
},
|
||||
pass: {
|
||||
expected: "string",
|
||||
got: msg.hasOwnProperty("pass") ? typeof(msg.pass) : undefined,
|
||||
got: msg.hasOwnProperty("pass") ? typeof msg.pass : undefined
|
||||
},
|
||||
description: {
|
||||
expected: "string",
|
||||
got: msg.hasOwnProperty("description") ? typeof(msg.description) : undefined,
|
||||
got: msg.hasOwnProperty("description")
|
||||
? typeof msg.description
|
||||
: undefined
|
||||
},
|
||||
adminpass: {
|
||||
expected: "string",
|
||||
got: msg.hasOwnProperty("adminpass") ? typeof(msg.adminpass) : undefined,
|
||||
},
|
||||
got: msg.hasOwnProperty("adminpass")
|
||||
? typeof msg.adminpass
|
||||
: undefined
|
||||
}
|
||||
};
|
||||
socket.emit("update_required", result);
|
||||
return;
|
||||
}
|
||||
//coll = coll.replace(/ /g,'');
|
||||
Functions.getSessionAdminUser(Functions.getSession(socket), coll, function(userpass, adminpass, gotten) {
|
||||
if(userpass != "" || msg.pass == undefined) {
|
||||
Functions.getSessionAdminUser(Functions.getSession(socket), coll, function(
|
||||
userpass,
|
||||
adminpass,
|
||||
gotten
|
||||
) {
|
||||
if (userpass != "" || msg.pass == undefined) {
|
||||
msg.pass = userpass;
|
||||
} else if (msg.hasOwnProperty("pass")) {
|
||||
msg.pass = crypto.createHash('sha256').update(Functions.decrypt_string(msg.pass)).digest("base64");
|
||||
msg.pass = crypto
|
||||
.createHash("sha256")
|
||||
.update(Functions.decrypt_string(msg.pass))
|
||||
.digest("base64");
|
||||
}
|
||||
if (adminpass != "" || msg.adminpass == undefined) {
|
||||
msg.adminpass = Functions.hash_pass(adminpass);
|
||||
} else {
|
||||
msg.adminpass = Functions.hash_pass(Functions.hash_pass(Functions.decrypt_string(msg.adminpass), true));
|
||||
msg.adminpass = Functions.hash_pass(
|
||||
Functions.hash_pass(Functions.decrypt_string(msg.adminpass), true)
|
||||
);
|
||||
}
|
||||
var channel = msg.channel.toLowerCase();
|
||||
var hash = msg.adminpass;
|
||||
db.collection(channel + "_settings").find({id: "config"}, function(err, docs){
|
||||
if(docs.length > 0 && (docs[0].userpass == undefined || docs[0].userpass == "" || (msg.hasOwnProperty('pass') && docs[0].userpass == msg.pass))) {
|
||||
if(docs !== null && docs.length !== 0 && docs[0].adminpass !== "" && docs[0].adminpass == hash){
|
||||
db.collection("suggested_descriptions").update({channel: channel}, {$set:{description: msg.description}}, {upsert:true}, function(err, docs){
|
||||
Notifications.requested_change("description", msg.description, channel);
|
||||
db.collection(channel + "_settings").find({ id: "config" }, function(
|
||||
err,
|
||||
docs
|
||||
) {
|
||||
if (
|
||||
docs.length > 0 &&
|
||||
(docs[0].userpass == undefined ||
|
||||
docs[0].userpass == "" ||
|
||||
(msg.hasOwnProperty("pass") && docs[0].userpass == msg.pass))
|
||||
) {
|
||||
if (
|
||||
docs !== null &&
|
||||
docs.length !== 0 &&
|
||||
docs[0].adminpass !== "" &&
|
||||
docs[0].adminpass == hash
|
||||
) {
|
||||
db.collection("suggested_descriptions").update(
|
||||
{ channel: channel },
|
||||
{ $set: { description: msg.description } },
|
||||
{ upsert: true },
|
||||
function(err, docs) {
|
||||
Notifications.requested_change(
|
||||
"description",
|
||||
msg.description,
|
||||
channel
|
||||
);
|
||||
socket.emit("toast", "suggested_description");
|
||||
});
|
||||
}
|
||||
);
|
||||
}
|
||||
} else {
|
||||
socket.emit("auth_required");
|
||||
@@ -120,52 +194,80 @@ function description(msg, coll, guid, offline, socket) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function rules(msg, coll, guid, offline, socket) {
|
||||
if (msg.rules && msg.channel && msg.rules.length < 250) {
|
||||
if(typeof(msg.channel) != "string" || typeof(msg.rules) != "string") {
|
||||
if (typeof msg.channel != "string" || typeof msg.rules != "string") {
|
||||
var result = {
|
||||
channel: {
|
||||
expected: "string",
|
||||
got: msg.hasOwnProperty("channel") ? typeof(msg.channel) : undefined,
|
||||
got: msg.hasOwnProperty("channel") ? typeof msg.channel : undefined
|
||||
},
|
||||
pass: {
|
||||
expected: "string",
|
||||
got: msg.hasOwnProperty("pass") ? typeof(msg.pass) : undefined,
|
||||
got: msg.hasOwnProperty("pass") ? typeof msg.pass : undefined
|
||||
},
|
||||
rules: {
|
||||
expected: "string",
|
||||
got: msg.hasOwnProperty("rules") ? typeof(msg.rules) : undefined,
|
||||
got: msg.hasOwnProperty("rules") ? typeof msg.rules : undefined
|
||||
},
|
||||
adminpass: {
|
||||
expected: "string",
|
||||
got: msg.hasOwnProperty("adminpass") ? typeof(msg.adminpass) : undefined,
|
||||
},
|
||||
got: msg.hasOwnProperty("adminpass")
|
||||
? typeof msg.adminpass
|
||||
: undefined
|
||||
}
|
||||
};
|
||||
socket.emit("update_required", result);
|
||||
return;
|
||||
}
|
||||
//coll = coll.replace(/ /g,'');
|
||||
Functions.getSessionAdminUser(Functions.getSession(socket), coll, function(userpass, adminpass, gotten) {
|
||||
if(userpass != "" || msg.pass == undefined) {
|
||||
Functions.getSessionAdminUser(Functions.getSession(socket), coll, function(
|
||||
userpass,
|
||||
adminpass,
|
||||
gotten
|
||||
) {
|
||||
if (userpass != "" || msg.pass == undefined) {
|
||||
msg.pass = userpass;
|
||||
} else if (msg.hasOwnProperty("pass")) {
|
||||
msg.pass = crypto.createHash('sha256').update(Functions.decrypt_string(msg.pass)).digest("base64");
|
||||
msg.pass = crypto
|
||||
.createHash("sha256")
|
||||
.update(Functions.decrypt_string(msg.pass))
|
||||
.digest("base64");
|
||||
}
|
||||
if (adminpass != "" || msg.adminpass == undefined) {
|
||||
msg.adminpass = Functions.hash_pass(adminpass);
|
||||
} else {
|
||||
msg.adminpass = Functions.hash_pass(Functions.hash_pass(Functions.decrypt_string(msg.adminpass), true));
|
||||
msg.adminpass = Functions.hash_pass(
|
||||
Functions.hash_pass(Functions.decrypt_string(msg.adminpass), true)
|
||||
);
|
||||
}
|
||||
var channel = msg.channel.toLowerCase();
|
||||
var hash = msg.adminpass;
|
||||
db.collection(channel + "_settings").find({id: "config"}, function(err, docs){
|
||||
if(docs.length > 0 && (docs[0].userpass == undefined || docs[0].userpass == "" || (msg.hasOwnProperty('pass') && docs[0].userpass == msg.pass))) {
|
||||
if(docs !== null && docs.length !== 0 && docs[0].adminpass !== "" && docs[0].adminpass == hash){
|
||||
db.collection("suggested_rules").update({channel: channel}, {$set:{rules: msg.rules}}, {upsert:true}, function(err, docs){
|
||||
db.collection(channel + "_settings").find({ id: "config" }, function(
|
||||
err,
|
||||
docs
|
||||
) {
|
||||
if (
|
||||
docs.length > 0 &&
|
||||
(docs[0].userpass == undefined ||
|
||||
docs[0].userpass == "" ||
|
||||
(msg.hasOwnProperty("pass") && docs[0].userpass == msg.pass))
|
||||
) {
|
||||
if (
|
||||
docs !== null &&
|
||||
docs.length !== 0 &&
|
||||
docs[0].adminpass !== "" &&
|
||||
docs[0].adminpass == hash
|
||||
) {
|
||||
db.collection("suggested_rules").update(
|
||||
{ channel: channel },
|
||||
{ $set: { rules: msg.rules } },
|
||||
{ upsert: true },
|
||||
function(err, docs) {
|
||||
Notifications.requested_change("rules", msg.rules, channel);
|
||||
socket.emit("toast", "suggested_rules");
|
||||
});
|
||||
}
|
||||
);
|
||||
}
|
||||
} else {
|
||||
socket.emit("auth_required");
|
||||
@@ -177,7 +279,6 @@ function rules(msg, coll, guid, offline, socket) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
module.exports.thumbnail = thumbnail;
|
||||
module.exports.description = description;
|
||||
module.exports.rules = rules;
|
||||
|
||||
@@ -1,23 +1,35 @@
|
||||
var express = require('express');
|
||||
var express = require("express");
|
||||
var router = express.Router();
|
||||
var path = require('path');
|
||||
var mongo_db_cred = require(path.join(__dirname, '../../config/mongo_config.js'));
|
||||
var mongojs = require('mongojs');
|
||||
var path = require("path");
|
||||
try {
|
||||
var mongo_db_cred = require(path.join(
|
||||
__dirname,
|
||||
"../../config/mongo_config.js"
|
||||
));
|
||||
} catch (e) {
|
||||
console.log(
|
||||
"(!) Missing file - /config/mongo_config.js. Have a look at /config/mongo_config.example.js. The server won't run without this existing."
|
||||
);
|
||||
process.exit(1);
|
||||
}
|
||||
var mongojs = require("mongojs");
|
||||
var db = mongojs(mongo_db_cred.config);
|
||||
var token_db = mongojs("tokens");
|
||||
var uniqid = require('uniqid');
|
||||
var crypto = require('crypto');
|
||||
var uniqid = require("uniqid");
|
||||
var crypto = require("crypto");
|
||||
var ObjectId = mongojs.ObjectId;
|
||||
var sIO = require(path.join(__dirname, '../../apps/client.js')).socketIO;
|
||||
var sIO = require(path.join(__dirname, "../../apps/client.js")).socketIO;
|
||||
var projects = require(pathThumbnails + "/handlers/aggregates.js");
|
||||
|
||||
router.use(function(req, res, next) {
|
||||
next(); // make sure we go to the next routes and don't stop here
|
||||
});
|
||||
|
||||
router.route('/api/lists').get(function(req, res){
|
||||
router.route("/api/lists").get(function(req, res) {
|
||||
if (req.isAuthenticated()) {
|
||||
db.collection("frontpage_lists").find().sort({count: -1},function(err, docs){
|
||||
db.collection("frontpage_lists")
|
||||
.find()
|
||||
.sort({ count: -1 }, function(err, docs) {
|
||||
res.json(docs);
|
||||
});
|
||||
} else {
|
||||
@@ -25,7 +37,7 @@ router.route('/api/lists').get(function(req, res){
|
||||
}
|
||||
});
|
||||
|
||||
router.route('/api/thumbnails').get(function(req, res){
|
||||
router.route("/api/thumbnails").get(function(req, res) {
|
||||
if (req.isAuthenticated()) {
|
||||
db.collection("suggested_thumbnails").find(function(err, docs) {
|
||||
res.json(docs);
|
||||
@@ -35,7 +47,7 @@ router.route('/api/thumbnails').get(function(req, res){
|
||||
}
|
||||
});
|
||||
|
||||
router.route('/api/descriptions').get(function(req, res){
|
||||
router.route("/api/descriptions").get(function(req, res) {
|
||||
if (req.isAuthenticated()) {
|
||||
db.collection("suggested_descriptions").find(function(err, docs) {
|
||||
res.json(docs);
|
||||
@@ -45,7 +57,7 @@ router.route('/api/descriptions').get(function(req, res){
|
||||
}
|
||||
});
|
||||
|
||||
router.route('/api/rules').get(function(req, res){
|
||||
router.route("/api/rules").get(function(req, res) {
|
||||
if (req.isAuthenticated()) {
|
||||
db.collection("suggested_rules").find(function(err, docs) {
|
||||
res.json(docs);
|
||||
@@ -55,43 +67,69 @@ router.route('/api/rules').get(function(req, res){
|
||||
}
|
||||
});
|
||||
|
||||
router.route('/api/approve_thumbnail').post(function(req, res){
|
||||
router.route("/api/approve_thumbnail").post(function(req, res) {
|
||||
if (req.isAuthenticated()) {
|
||||
var channel = req.body.channel;
|
||||
db.collection("suggested_thumbnails").find({channel: channel}, function(err, docs){
|
||||
db.collection("suggested_thumbnails").find({ channel: channel }, function(
|
||||
err,
|
||||
docs
|
||||
) {
|
||||
var thumbnail = docs[0].thumbnail;
|
||||
db.collection("frontpage_lists").update({_id: channel}, {$set:{thumbnail: thumbnail}}, {upsert: true}, function(err, docs){
|
||||
db.collection(channel + "_settings").update({views:{$exists:true}}, {$set:{thumbnail: thumbnail}}, {upsert: true}, function(err, docs){
|
||||
db.collection("suggested_thumbnails").remove({channel: channel}, function(err, docs){
|
||||
db.collection(channel + "_settings").aggregate([
|
||||
db.collection("frontpage_lists").update(
|
||||
{ _id: channel },
|
||||
{ $set: { thumbnail: thumbnail } },
|
||||
{ upsert: true },
|
||||
function(err, docs) {
|
||||
db.collection(channel + "_settings").update(
|
||||
{ views: { $exists: true } },
|
||||
{ $set: { thumbnail: thumbnail } },
|
||||
{ upsert: true },
|
||||
function(err, docs) {
|
||||
db.collection("suggested_thumbnails").remove(
|
||||
{ channel: channel },
|
||||
function(err, docs) {
|
||||
db.collection(channel + "_settings").aggregate(
|
||||
[
|
||||
{
|
||||
"$match": {
|
||||
$match: {
|
||||
id: "config"
|
||||
}
|
||||
},
|
||||
{
|
||||
"$project": projects.toShowConfig
|
||||
},
|
||||
], function(err, docs) {
|
||||
$project: projects.toShowConfig
|
||||
}
|
||||
],
|
||||
function(err, docs) {
|
||||
if (docs[0].adminpass !== "") docs[0].adminpass = true;
|
||||
if(docs[0].hasOwnProperty("userpass") && docs[0].userpass != "") docs[0].userpass = true;
|
||||
if (
|
||||
docs[0].hasOwnProperty("userpass") &&
|
||||
docs[0].userpass != ""
|
||||
)
|
||||
docs[0].userpass = true;
|
||||
else docs[0].userpass = false;
|
||||
sIO.to(channel).emit("conf", docs);
|
||||
res.send(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
});
|
||||
} else {
|
||||
res.send(false);
|
||||
}
|
||||
});
|
||||
|
||||
router.route('/api/deny_thumbnail').post(function(req, res){
|
||||
router.route("/api/deny_thumbnail").post(function(req, res) {
|
||||
if (req.isAuthenticated()) {
|
||||
var channel = req.body.channel;
|
||||
db.collection("suggested_thumbnails").remove({channel: channel},function(err, docs){
|
||||
db.collection("suggested_thumbnails").remove({ channel: channel }, function(
|
||||
err,
|
||||
docs
|
||||
) {
|
||||
res.send(true);
|
||||
});
|
||||
} else {
|
||||
@@ -99,42 +137,62 @@ router.route('/api/deny_thumbnail').post(function(req, res){
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
router.route('/api/approve_rules').post(function(req, res){
|
||||
router.route("/api/approve_rules").post(function(req, res) {
|
||||
if (req.isAuthenticated()) {
|
||||
var channel = req.body.channel;
|
||||
db.collection("suggested_rules").find({channel: channel}, function(err, docs){
|
||||
db.collection("suggested_rules").find({ channel: channel }, function(
|
||||
err,
|
||||
docs
|
||||
) {
|
||||
var rules = docs[0].rules;
|
||||
db.collection(channel + "_settings").update({views:{$exists:true}}, {$set:{rules: rules}}, {upsert: true}, function(err, docs){
|
||||
db.collection("suggested_rules").remove({channel: channel}, function(err, docs){
|
||||
db.collection(channel + "_settings").aggregate([
|
||||
db.collection(channel + "_settings").update(
|
||||
{ views: { $exists: true } },
|
||||
{ $set: { rules: rules } },
|
||||
{ upsert: true },
|
||||
function(err, docs) {
|
||||
db.collection("suggested_rules").remove(
|
||||
{ channel: channel },
|
||||
function(err, docs) {
|
||||
db.collection(channel + "_settings").aggregate(
|
||||
[
|
||||
{
|
||||
"$match": {
|
||||
$match: {
|
||||
id: "config"
|
||||
}
|
||||
},
|
||||
{
|
||||
"$project": projects.toShowConfig
|
||||
},
|
||||
], function(err, docs) {
|
||||
$project: projects.toShowConfig
|
||||
}
|
||||
],
|
||||
function(err, docs) {
|
||||
if (docs[0].adminpass !== "") docs[0].adminpass = true;
|
||||
if(docs[0].hasOwnProperty("userpass") && docs[0].userpass != "") docs[0].userpass = true;
|
||||
if (
|
||||
docs[0].hasOwnProperty("userpass") &&
|
||||
docs[0].userpass != ""
|
||||
)
|
||||
docs[0].userpass = true;
|
||||
else docs[0].userpass = false;
|
||||
sIO.to(channel).emit("conf", docs);
|
||||
res.send(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
});
|
||||
} else {
|
||||
res.send(false);
|
||||
}
|
||||
});
|
||||
|
||||
router.route('/api/deny_rules').post(function(req, res){
|
||||
router.route("/api/deny_rules").post(function(req, res) {
|
||||
if (req.isAuthenticated()) {
|
||||
var channel = req.body.channel;
|
||||
db.collection("suggested_rules").remove({channel: channel},function(err, docs){
|
||||
db.collection("suggested_rules").remove({ channel: channel }, function(
|
||||
err,
|
||||
docs
|
||||
) {
|
||||
res.send(true);
|
||||
});
|
||||
} else {
|
||||
@@ -142,159 +200,234 @@ router.route('/api/deny_rules').post(function(req, res){
|
||||
}
|
||||
});
|
||||
|
||||
router.route('/api/remove_rules').post(function(req, res){
|
||||
router.route("/api/remove_rules").post(function(req, res) {
|
||||
if (req.isAuthenticated()) {
|
||||
var channel = req.body.channel;
|
||||
db.collection(channel + "_settings").update({views:{$exists:true}}, {$set:{rules: ""}}, function(err, docs){
|
||||
db.collection(channel + "_settings").aggregate([
|
||||
db.collection(channel + "_settings").update(
|
||||
{ views: { $exists: true } },
|
||||
{ $set: { rules: "" } },
|
||||
function(err, docs) {
|
||||
db.collection(channel + "_settings").aggregate(
|
||||
[
|
||||
{
|
||||
"$match": {
|
||||
$match: {
|
||||
id: "config"
|
||||
}
|
||||
},
|
||||
{
|
||||
"$project": projects.toShowConfig
|
||||
},
|
||||
], function(err, docs) {
|
||||
$project: projects.toShowConfig
|
||||
}
|
||||
],
|
||||
function(err, docs) {
|
||||
if (docs[0].adminpass !== "") docs[0].adminpass = true;
|
||||
if(docs[0].hasOwnProperty("userpass") && docs[0].userpass != "") docs[0].userpass = true;
|
||||
if (docs[0].hasOwnProperty("userpass") && docs[0].userpass != "")
|
||||
docs[0].userpass = true;
|
||||
else docs[0].userpass = false;
|
||||
sIO.to(channel).emit("conf", docs);
|
||||
res.send(true);
|
||||
});
|
||||
});
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
} else {
|
||||
res.send(false);
|
||||
}
|
||||
});
|
||||
|
||||
router.route('/api/approve_description').post(function(req, res){
|
||||
router.route("/api/approve_description").post(function(req, res) {
|
||||
if (req.isAuthenticated()) {
|
||||
var channel = req.body.channel;
|
||||
db.collection("suggested_descriptions").find({channel: channel}, function(err, docs){
|
||||
db.collection("suggested_descriptions").find({ channel: channel }, function(
|
||||
err,
|
||||
docs
|
||||
) {
|
||||
var description = docs[0].description;
|
||||
db.collection("frontpage_lists").update({_id: channel}, {$set:{description: description}}, {upsert: true}, function(err, docs){
|
||||
db.collection(channel + "_settings").update({views:{$exists:true}}, {$set:{description: description}}, function(err, docs){
|
||||
db.collection("suggested_descriptions").remove({channel: channel}, function(err, docs){
|
||||
db.collection(channel + "_settings").aggregate([
|
||||
db.collection("frontpage_lists").update(
|
||||
{ _id: channel },
|
||||
{ $set: { description: description } },
|
||||
{ upsert: true },
|
||||
function(err, docs) {
|
||||
db.collection(channel + "_settings").update(
|
||||
{ views: { $exists: true } },
|
||||
{ $set: { description: description } },
|
||||
function(err, docs) {
|
||||
db.collection("suggested_descriptions").remove(
|
||||
{ channel: channel },
|
||||
function(err, docs) {
|
||||
db.collection(channel + "_settings").aggregate(
|
||||
[
|
||||
{
|
||||
"$match": {
|
||||
$match: {
|
||||
id: "config"
|
||||
}
|
||||
},
|
||||
{
|
||||
"$project": projects.toShowConfig
|
||||
},
|
||||
], function(err, docs) {
|
||||
$project: projects.toShowConfig
|
||||
}
|
||||
],
|
||||
function(err, docs) {
|
||||
if (docs[0].adminpass !== "") docs[0].adminpass = true;
|
||||
if(docs[0].hasOwnProperty("userpass") && docs[0].userpass != "") docs[0].userpass = true;
|
||||
if (
|
||||
docs[0].hasOwnProperty("userpass") &&
|
||||
docs[0].userpass != ""
|
||||
)
|
||||
docs[0].userpass = true;
|
||||
else docs[0].userpass = false;
|
||||
sIO.to(channel).emit("conf", docs);
|
||||
res.send(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
});
|
||||
} else {
|
||||
res.send(false);
|
||||
}
|
||||
});
|
||||
|
||||
router.route('/api/deny_description').post(function(req, res){
|
||||
router.route("/api/deny_description").post(function(req, res) {
|
||||
if (req.isAuthenticated()) {
|
||||
var channel = req.body.channel;
|
||||
db.collection("suggested_descriptions").remove({channel: channel}, 1,function(err, docs){
|
||||
db.collection("suggested_descriptions").remove(
|
||||
{ channel: channel },
|
||||
1,
|
||||
function(err, docs) {
|
||||
res.send(true);
|
||||
});
|
||||
}
|
||||
);
|
||||
} else {
|
||||
res.send(false);
|
||||
}
|
||||
});
|
||||
|
||||
router.route('/api/remove_thumbnail').post(function(req, res){
|
||||
router.route("/api/remove_thumbnail").post(function(req, res) {
|
||||
if (req.isAuthenticated()) {
|
||||
var channel = req.body.channel;
|
||||
db.collection("frontpage_lists").update({_id: channel}, {$set:{thumbnail: ""}}, function(err, docs){
|
||||
db.collection(channel + "_settings").update({views:{$exists:true}}, {$set:{thumbnail: ""}}, function(err, docs){
|
||||
db.collection(channel + "_settings").aggregate([
|
||||
db.collection("frontpage_lists").update(
|
||||
{ _id: channel },
|
||||
{ $set: { thumbnail: "" } },
|
||||
function(err, docs) {
|
||||
db.collection(channel + "_settings").update(
|
||||
{ views: { $exists: true } },
|
||||
{ $set: { thumbnail: "" } },
|
||||
function(err, docs) {
|
||||
db.collection(channel + "_settings").aggregate(
|
||||
[
|
||||
{
|
||||
"$match": {
|
||||
$match: {
|
||||
id: "config"
|
||||
}
|
||||
},
|
||||
{
|
||||
"$project": projects.toShowConfig
|
||||
},
|
||||
], function(err, docs) {
|
||||
$project: projects.toShowConfig
|
||||
}
|
||||
],
|
||||
function(err, docs) {
|
||||
if (docs[0].adminpass !== "") docs[0].adminpass = true;
|
||||
if(docs[0].hasOwnProperty("userpass") && docs[0].userpass != "") docs[0].userpass = true;
|
||||
if (
|
||||
docs[0].hasOwnProperty("userpass") &&
|
||||
docs[0].userpass != ""
|
||||
)
|
||||
docs[0].userpass = true;
|
||||
else docs[0].userpass = false;
|
||||
sIO.to(channel).emit("conf", docs);
|
||||
res.send(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
} else {
|
||||
res.send(false);
|
||||
}
|
||||
});
|
||||
|
||||
router.route('/api/remove_description').post(function(req, res){
|
||||
router.route("/api/remove_description").post(function(req, res) {
|
||||
if (req.isAuthenticated()) {
|
||||
var channel = req.body.channel;
|
||||
db.collection("frontpage_lists").update({_id: channel}, {$set:{description: ""}}, function(err, docs){
|
||||
db.collection(channel + "_settings").update({views:{$exists:true}}, {$set:{description: ""}}, function(err, docs){
|
||||
db.collection(channel + "_settings").aggregate([
|
||||
db.collection("frontpage_lists").update(
|
||||
{ _id: channel },
|
||||
{ $set: { description: "" } },
|
||||
function(err, docs) {
|
||||
db.collection(channel + "_settings").update(
|
||||
{ views: { $exists: true } },
|
||||
{ $set: { description: "" } },
|
||||
function(err, docs) {
|
||||
db.collection(channel + "_settings").aggregate(
|
||||
[
|
||||
{
|
||||
"$match": {
|
||||
$match: {
|
||||
id: "config"
|
||||
}
|
||||
},
|
||||
{
|
||||
"$project": projects.toShowConfig
|
||||
},
|
||||
], function(err, docs) {
|
||||
$project: projects.toShowConfig
|
||||
}
|
||||
],
|
||||
function(err, docs) {
|
||||
if (docs[0].adminpass !== "") docs[0].adminpass = true;
|
||||
if(docs[0].hasOwnProperty("userpass") && docs[0].userpass != "") docs[0].userpass = true;
|
||||
if (
|
||||
docs[0].hasOwnProperty("userpass") &&
|
||||
docs[0].userpass != ""
|
||||
)
|
||||
docs[0].userpass = true;
|
||||
else docs[0].userpass = false;
|
||||
sIO.to(channel).emit("conf", docs);
|
||||
res.send(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
} else {
|
||||
res.send(false);
|
||||
}
|
||||
});
|
||||
|
||||
router.route('/api/names').get(function(req, res) {
|
||||
router.route("/api/names").get(function(req, res) {
|
||||
if (req.isAuthenticated()) {
|
||||
db.collection("registered_users").find({_id: {$exists: true}}, {_id: 1, icon: 1}, function(err, docs) {
|
||||
db.collection("registered_users").find(
|
||||
{ _id: { $exists: true } },
|
||||
{ _id: 1, icon: 1 },
|
||||
function(err, docs) {
|
||||
res.json(docs);
|
||||
})
|
||||
}
|
||||
);
|
||||
} else {
|
||||
res.send(false);
|
||||
}
|
||||
});
|
||||
|
||||
router.route('/api/names').post(function(req, res) {
|
||||
router.route("/api/names").post(function(req, res) {
|
||||
if (req.isAuthenticated()) {
|
||||
var icon = req.body.icon;
|
||||
var name = req.body.name;
|
||||
db.collection("registered_users").update({_id: name}, {$set: {icon: icon}}, function(err, docs) {
|
||||
db.collection("registered_users").update(
|
||||
{ _id: name },
|
||||
{ $set: { icon: icon } },
|
||||
function(err, docs) {
|
||||
if (err) res.send(false);
|
||||
else res.send(true);
|
||||
});
|
||||
}
|
||||
);
|
||||
} else {
|
||||
res.send(false);
|
||||
}
|
||||
});
|
||||
|
||||
router.route('/api/names').delete(function(req, res) {
|
||||
router.route("/api/names").delete(function(req, res) {
|
||||
if (req.isAuthenticated()) {
|
||||
var name = req.body.name;
|
||||
db.collection("registered_users").remove({_id: name}, function(err, docs) {
|
||||
db.collection("registered_users").remove({ _id: name }, function(
|
||||
err,
|
||||
docs
|
||||
) {
|
||||
if (err) res.send(false);
|
||||
else res.send(true);
|
||||
});
|
||||
@@ -303,26 +436,30 @@ router.route('/api/names').delete(function(req, res) {
|
||||
}
|
||||
});
|
||||
|
||||
router.route('/api/token').get(function(req, res){
|
||||
router.route("/api/token").get(function(req, res) {
|
||||
if (req.isAuthenticated()) {
|
||||
token_db.collection("tokens").find(function(err, docs) {
|
||||
if (docs.length == 1) {
|
||||
res.json({ token: docs[0].token });
|
||||
} else {
|
||||
var id = new Buffer(makeid()).toString('base64');
|
||||
token_db.collection("tokens").insert({token: id}, function(err, docs){
|
||||
var id = new Buffer(makeid()).toString("base64");
|
||||
token_db
|
||||
.collection("tokens")
|
||||
.insert({ token: id }, function(err, docs) {
|
||||
res.json({ token: id });
|
||||
});
|
||||
}
|
||||
})
|
||||
});
|
||||
} else {
|
||||
res.send(false);
|
||||
}
|
||||
});
|
||||
|
||||
router.route('/api/api_token').get(function(req, res) {
|
||||
router.route("/api/api_token").get(function(req, res) {
|
||||
if (req.isAuthenticated()) {
|
||||
token_db.collection("api_token").find({token: {$exists: true}}, function(err, all) {
|
||||
token_db
|
||||
.collection("api_token")
|
||||
.find({ token: { $exists: true } }, function(err, all) {
|
||||
res.json(all);
|
||||
});
|
||||
} else {
|
||||
@@ -330,20 +467,22 @@ router.route('/api/api_token').get(function(req, res) {
|
||||
}
|
||||
});
|
||||
|
||||
router.route('/api/api_token').delete(function(req, res){
|
||||
router.route("/api/api_token").delete(function(req, res) {
|
||||
if (req.isAuthenticated()) {
|
||||
var id = req.body.id;
|
||||
token_db.collection("api_token").remove({_id: ObjectId(id)}, function(err, success) {
|
||||
token_db
|
||||
.collection("api_token")
|
||||
.remove({ _id: ObjectId(id) }, function(err, success) {
|
||||
if (err) {
|
||||
res.send("failed");
|
||||
return;
|
||||
}
|
||||
res.send("success");
|
||||
})
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
router.route('/api/api_token').put(function(req, res){
|
||||
router.route("/api/api_token").put(function(req, res) {
|
||||
if (req.isAuthenticated()) {
|
||||
var id = req.body.id;
|
||||
var limit = req.body.limit;
|
||||
@@ -351,21 +490,31 @@ router.route('/api/api_token').put(function(req, res){
|
||||
res.sendStatus(500);
|
||||
return;
|
||||
}
|
||||
token_db.collection("api_token").update({_id: ObjectId(id)}, {$set: {limit: limit}}, function(err, success) {
|
||||
token_db
|
||||
.collection("api_token")
|
||||
.update({ _id: ObjectId(id) }, { $set: { limit: limit } }, function(
|
||||
err,
|
||||
success
|
||||
) {
|
||||
if (err) {
|
||||
res.sendStatus(500);
|
||||
return;
|
||||
}
|
||||
res.sendStatus(200);
|
||||
})
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
router.route('/api/api_token').post(function(req, res){
|
||||
router.route("/api/api_token").post(function(req, res) {
|
||||
if (req.isAuthenticated()) {
|
||||
var name = req.body.name;
|
||||
var id = crypto.createHash('sha256').update(uniqid()).digest('base64');
|
||||
token_db.collection("api_token").insert({name: name, token: id, usage: 0}, function(err, docs){
|
||||
var id = crypto
|
||||
.createHash("sha256")
|
||||
.update(uniqid())
|
||||
.digest("base64");
|
||||
token_db
|
||||
.collection("api_token")
|
||||
.insert({ name: name, token: id, usage: 0 }, function(err, docs) {
|
||||
token_db.collection("api_token").find({ token: id }, function(err, d) {
|
||||
res.json({ token: id, _id: d[0]._id });
|
||||
});
|
||||
@@ -375,14 +524,17 @@ router.route('/api/api_token').post(function(req, res){
|
||||
}
|
||||
});
|
||||
|
||||
router.route('/api/delete').post(function(req, res){
|
||||
router.route("/api/delete").post(function(req, res) {
|
||||
if (req.isAuthenticated()) {
|
||||
var list = req.body._id;
|
||||
db.collection(list).drop(function(err, docs) {
|
||||
db.collection(list + "_settings").drop(function(err, docs) {
|
||||
db.collection("frontpage_lists").remove({_id: list}, function(err, docs){
|
||||
db.collection("frontpage_lists").remove({ _id: list }, function(
|
||||
err,
|
||||
docs
|
||||
) {
|
||||
res.send(true);
|
||||
})
|
||||
});
|
||||
});
|
||||
});
|
||||
} else {
|
||||
@@ -390,61 +542,79 @@ router.route('/api/delete').post(function(req, res){
|
||||
}
|
||||
});
|
||||
|
||||
router.route('/api/remove_token').get(function(req, res){
|
||||
router.route("/api/remove_token").get(function(req, res) {
|
||||
if (req.isAuthenticated()) {
|
||||
token_db.collection("tokens").find(function(err, docs) {
|
||||
if (docs.length == 1) {
|
||||
token_db.collection("tokens").remove({token: docs[0].token}, function(err, docs){
|
||||
token_db
|
||||
.collection("tokens")
|
||||
.remove({ token: docs[0].token }, function(err, docs) {
|
||||
res.send(true);
|
||||
})
|
||||
});
|
||||
} else {
|
||||
res.send(false);
|
||||
}
|
||||
})
|
||||
});
|
||||
} else {
|
||||
res.send(false);
|
||||
}
|
||||
});
|
||||
|
||||
router.route('/api/pinned').post(function(req, res){
|
||||
router.route("/api/pinned").post(function(req, res) {
|
||||
if (req.isAuthenticated()) {
|
||||
var to_pin = req.body._id;
|
||||
db.collection("frontpage_lists").update({pinned:1}, {$set:{pinned:0}}, function(err, resp){
|
||||
db.collection("frontpage_lists").update({_id:to_pin}, {$set:{pinned:1}}, function(err, resp){
|
||||
db.collection("frontpage_lists").update(
|
||||
{ pinned: 1 },
|
||||
{ $set: { pinned: 0 } },
|
||||
function(err, resp) {
|
||||
db.collection("frontpage_lists").update(
|
||||
{ _id: to_pin },
|
||||
{ $set: { pinned: 1 } },
|
||||
function(err, resp) {
|
||||
res.send(true);
|
||||
});
|
||||
});
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
} else {
|
||||
res.send(false);
|
||||
}
|
||||
});
|
||||
|
||||
router.route('/api/admin').post(function(req, res){
|
||||
router.route("/api/admin").post(function(req, res) {
|
||||
if (req.isAuthenticated()) {
|
||||
var to_remove = req.body._id;
|
||||
db.collection(to_remove + "_settings").update({views: {$exists: true}}, {$set:{adminpass: ""}}, function(err, docs){
|
||||
db.collection(to_remove + "_settings").update(
|
||||
{ views: { $exists: true } },
|
||||
{ $set: { adminpass: "" } },
|
||||
function(err, docs) {
|
||||
res.send(true);
|
||||
});
|
||||
}
|
||||
);
|
||||
} else {
|
||||
res.send(false);
|
||||
}
|
||||
});
|
||||
|
||||
router.route('/api/userpass').post(function(req, res){
|
||||
router.route("/api/userpass").post(function(req, res) {
|
||||
if (req.isAuthenticated()) {
|
||||
var to_remove = req.body._id;
|
||||
db.collection(to_remove + "_settings").update({views: {$exists: true}}, {$set:{userpass: ""}}, function(err, docs){
|
||||
db.collection(to_remove + "_settings").update(
|
||||
{ views: { $exists: true } },
|
||||
{ $set: { userpass: "" } },
|
||||
function(err, docs) {
|
||||
res.send(true);
|
||||
});
|
||||
}
|
||||
);
|
||||
} else {
|
||||
res.send(false);
|
||||
}
|
||||
});
|
||||
|
||||
function makeid()
|
||||
{
|
||||
function makeid() {
|
||||
var text = "";
|
||||
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
||||
var possible =
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
||||
|
||||
for (var i = 0; i < 20; i++)
|
||||
text += possible.charAt(Math.floor(Math.random() * possible.length));
|
||||
@@ -452,5 +622,4 @@ function makeid()
|
||||
return text;
|
||||
}
|
||||
|
||||
|
||||
module.exports = router;
|
||||
|
||||
@@ -13,7 +13,7 @@ try {
|
||||
} catch (e) {
|
||||
allowed_key = ["***"];
|
||||
console.log(
|
||||
"Allowed API-key for skipping songs from API has not been configured, so all keys are allowed by default (!). Have a look at config/allowed_api.example.js"
|
||||
"(!) Missing file - /config/allowed_api.js Have a look at /config/allowed_api.example.js."
|
||||
);
|
||||
}
|
||||
var crypto = require("crypto");
|
||||
|
||||
@@ -1,24 +1,33 @@
|
||||
var express = require('express');
|
||||
const path = require('path');
|
||||
var express = require("express");
|
||||
const path = require("path");
|
||||
var router = express.Router();
|
||||
router.use(function(req, res, next) {
|
||||
next(); // make sure we go to the next routes and don't stop here
|
||||
});
|
||||
|
||||
router.route('/favicon.ico').get(function(req, res, next) {
|
||||
res.sendFile(path.join(pathThumbnails, '/public/assets/images/favicon.ico'));
|
||||
router.route("/favicon.ico").get(function(req, res, next) {
|
||||
res.sendFile(path.join(pathThumbnails, "/public/assets/images/favicon.ico"));
|
||||
});
|
||||
|
||||
router.route('/browserconfig.xml').get(function(req, res, next) {
|
||||
res.sendFile(path.join(pathThumbnails, '/public/assets/images/browserconfig.xml'));
|
||||
router.route("/browserconfig.xml").get(function(req, res, next) {
|
||||
res.sendFile(
|
||||
path.join(pathThumbnails, "/public/assets/images/browserconfig.xml")
|
||||
);
|
||||
});
|
||||
|
||||
router.route('/apple-touch-icon.png').get(function(req, res, next) {
|
||||
res.sendFile(path.join(pathThumbnails, '/public/assets/images/apple-touch-icon.png'));
|
||||
router.route("/apple-touch-icon.png").get(function(req, res, next) {
|
||||
res.sendFile(
|
||||
path.join(pathThumbnails, "/public/assets/images/apple-touch-icon.png")
|
||||
);
|
||||
});
|
||||
|
||||
router.route('/apple-touch-icon-precomposed.png').get(function(req, res, next) {
|
||||
res.sendFile(path.join(pathThumbnails, '/public/assets/images/apple-touch-icon-precomposed.png'));
|
||||
router.route("/apple-touch-icon-precomposed.png").get(function(req, res, next) {
|
||||
res.sendFile(
|
||||
path.join(
|
||||
pathThumbnails,
|
||||
"/public/assets/images/apple-touch-icon-precomposed.png"
|
||||
)
|
||||
);
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
|
||||
@@ -1,22 +1,25 @@
|
||||
var express = require('express');
|
||||
var express = require("express");
|
||||
var router = express.Router();
|
||||
var path = require('path');
|
||||
var path = require("path");
|
||||
var year = new Date().getYear() + 1900;
|
||||
var path = require('path');
|
||||
var path = require("path");
|
||||
var analytics = "xx";
|
||||
var google = {};
|
||||
var adsense = "xx";
|
||||
var adds = false;
|
||||
var mongojs = require('mongojs');
|
||||
var mongojs = require("mongojs");
|
||||
var token_db = mongojs("tokens");
|
||||
var Functions = require(pathThumbnails + '/handlers/functions.js');
|
||||
var Frontpage = require(pathThumbnails + '/handlers/frontpage.js');
|
||||
var Functions = require(pathThumbnails + "/handlers/functions.js");
|
||||
var Frontpage = require(pathThumbnails + "/handlers/frontpage.js");
|
||||
|
||||
var db = require(pathThumbnails + '/handlers/db.js');
|
||||
var db = require(pathThumbnails + "/handlers/db.js");
|
||||
//var db = require(pathThumbnails + '/handlers/db.js');
|
||||
|
||||
try {
|
||||
google = require(path.join(path.join(__dirname, '../../config/'), 'google.js'));
|
||||
google = require(path.join(
|
||||
path.join(__dirname, "../../config/"),
|
||||
"google.js"
|
||||
));
|
||||
analytics = google.analytics;
|
||||
adsense = google.adsense;
|
||||
} catch (e) {
|
||||
@@ -24,46 +27,50 @@ try {
|
||||
}
|
||||
|
||||
try {
|
||||
var Recaptcha = require('express-recaptcha');
|
||||
var recaptcha_config = require(path.join(path.join(__dirname, '../../config/'), 'recaptcha.js'));
|
||||
var Recaptcha = require("express-recaptcha");
|
||||
var recaptcha_config = require(path.join(
|
||||
path.join(__dirname, "../../config/"),
|
||||
"recaptcha.js"
|
||||
));
|
||||
var RECAPTCHA_SITE_KEY = recaptcha_config.site;
|
||||
var RECAPTCHA_SECRET_KEY = recaptcha_config.key;
|
||||
var recaptcha = new Recaptcha(RECAPTCHA_SITE_KEY, RECAPTCHA_SECRET_KEY);
|
||||
} catch (e) {
|
||||
console.log("Error - missing file");
|
||||
console.log("Seems you forgot to create the file recaptcha.js in /server/config/. Have a look at recaptcha.example.js.");
|
||||
console.log(
|
||||
"(!) Missing file - /config/recaptcha.js Have a look at /config/recaptcha.example.js."
|
||||
);
|
||||
var recaptcha = {
|
||||
middleware: {
|
||||
render: (req, res, next) => {
|
||||
res.recaptcha = ""
|
||||
next()
|
||||
}
|
||||
res.recaptcha = "";
|
||||
next();
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
router.use(recaptcha.middleware.render, function(req, res, next) {
|
||||
next(); // make sure we go to the next routes and don't stop here
|
||||
});
|
||||
|
||||
router.route('/:channel_name').get(function(req, res, next){
|
||||
router.route("/:channel_name").get(function(req, res, next) {
|
||||
channel(req, res, next);
|
||||
});
|
||||
|
||||
router.route('/r/:base64data').get(function(req, res, next){
|
||||
var channelToRedirect = Buffer.from(req.params.base64data, 'base64');
|
||||
res.redirect('/' + channelToRedirect);
|
||||
router.route("/r/:base64data").get(function(req, res, next) {
|
||||
var channelToRedirect = Buffer.from(req.params.base64data, "base64");
|
||||
res.redirect("/" + channelToRedirect);
|
||||
});
|
||||
|
||||
router.route('/').get(function(req, res, next){
|
||||
router.route("/").get(function(req, res, next) {
|
||||
root(req, res, next);
|
||||
});
|
||||
|
||||
router.route('/').post(function(req, res, next){
|
||||
router.route("/").post(function(req, res, next) {
|
||||
root(req, res, next);
|
||||
});
|
||||
|
||||
router.route('/api/embed').get(function(req, res, next) {
|
||||
router.route("/api/embed").get(function(req, res, next) {
|
||||
var data = {
|
||||
year: year,
|
||||
type: "video",
|
||||
@@ -72,16 +79,16 @@ router.route('/api/embed').get(function(req, res, next) {
|
||||
analytics: analytics,
|
||||
stylesheet: "embed.css",
|
||||
embed: true,
|
||||
og_image: "https://zoff.me/assets/images/small-square.jpg",
|
||||
}
|
||||
res.render('layouts/client/embed', data);
|
||||
og_image: "https://zoff.me/assets/images/small-square.jpg"
|
||||
};
|
||||
res.render("layouts/client/embed", data);
|
||||
});
|
||||
|
||||
router.route('/api/oauth').get(function(req, res, next) {
|
||||
res.sendFile(path.join(pathThumbnails, '/public/assets/html/callback.html'));
|
||||
router.route("/api/oauth").get(function(req, res, next) {
|
||||
res.sendFile(path.join(pathThumbnails, "/public/assets/html/callback.html"));
|
||||
});
|
||||
|
||||
router.route('/api/apply').get(function(req, res, next) {
|
||||
router.route("/api/apply").get(function(req, res, next) {
|
||||
var data = {
|
||||
year: year,
|
||||
javascript_file: "token.min.js",
|
||||
@@ -95,17 +102,22 @@ router.route('/api/apply').get(function(req, res, next) {
|
||||
correct: false,
|
||||
stylesheet: "style.css",
|
||||
embed: false,
|
||||
og_image: "https://zoff.me/assets/images/small-square.jpg",
|
||||
}
|
||||
res.render('layouts/client/token', data);
|
||||
og_image: "https://zoff.me/assets/images/small-square.jpg"
|
||||
};
|
||||
res.render("layouts/client/token", data);
|
||||
});
|
||||
|
||||
router.route('/api/apply/:id').get(function(req, res) {
|
||||
router.route("/api/apply/:id").get(function(req, res) {
|
||||
var id = req.params.id;
|
||||
token_db.collection('api_links').find({id: id}, function(err, result) {
|
||||
token_db.collection("api_links").find({ id: id }, function(err, result) {
|
||||
if (result.length == 1) {
|
||||
token_db.collection('api_links').remove({id: id}, function(e,d) {
|
||||
token_db.collection('api_token').update({token: result[0].token}, {$set: {active: true}}, function(e,d) {
|
||||
token_db.collection("api_links").remove({ id: id }, function(e, d) {
|
||||
token_db
|
||||
.collection("api_token")
|
||||
.update(
|
||||
{ token: result[0].token },
|
||||
{ $set: { active: true } },
|
||||
function(e, d) {
|
||||
var data = {
|
||||
year: year,
|
||||
javascript_file: "token.min.js",
|
||||
@@ -119,10 +131,11 @@ router.route('/api/apply/:id').get(function(req, res) {
|
||||
correct: true,
|
||||
stylesheet: "style.css",
|
||||
embed: false,
|
||||
og_image: "https://zoff.me/assets/images/small-square.jpg",
|
||||
og_image: "https://zoff.me/assets/images/small-square.jpg"
|
||||
};
|
||||
res.render("layouts/client/token", data);
|
||||
}
|
||||
res.render('layouts/client/token', data);
|
||||
});
|
||||
);
|
||||
});
|
||||
} else {
|
||||
var data = {
|
||||
@@ -138,18 +151,21 @@ router.route('/api/apply/:id').get(function(req, res) {
|
||||
correct: false,
|
||||
stylesheet: "style.css",
|
||||
embed: false,
|
||||
og_image: "https://zoff.me/assets/images/small-square.jpg",
|
||||
}
|
||||
res.render('layouts/client/token', data);
|
||||
og_image: "https://zoff.me/assets/images/small-square.jpg"
|
||||
};
|
||||
res.render("layouts/client/token", data);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
function root(req, res, next) {
|
||||
try {
|
||||
var url = req.headers['x-forwarded-host'] ? req.headers['x-forwarded-host'] : req.headers.host.split(":")[0];
|
||||
var subdomain = req.headers['x-forwarded-host'] ? req.headers['x-forwarded-host'].split(".") : req.headers.host.split(":")[0].split(".");
|
||||
var url = req.headers["x-forwarded-host"]
|
||||
? req.headers["x-forwarded-host"]
|
||||
: req.headers.host.split(":")[0];
|
||||
var subdomain = req.headers["x-forwarded-host"]
|
||||
? req.headers["x-forwarded-host"].split(".")
|
||||
: req.headers.host.split(":")[0].split(".");
|
||||
/*if(url != "zoff.me" && url != "admin.localhost" && url != "admin.zoff.me" && url != "remote.zoff.me" && url != "fb.zoff.me" && url != "remote.localhost" && url != "localhost") {
|
||||
res.redirect("https://zoff.me");
|
||||
return;
|
||||
@@ -166,9 +182,9 @@ function root(req, res, next) {
|
||||
stylesheet: "style.css",
|
||||
embed: false,
|
||||
client: false,
|
||||
og_image: "https://zoff.me/assets/images/small-square.jpg",
|
||||
}
|
||||
res.render('layouts/client/remote', data);
|
||||
og_image: "https://zoff.me/assets/images/small-square.jpg"
|
||||
};
|
||||
res.render("layouts/client/remote", data);
|
||||
} else if (subdomain[0] == "www") {
|
||||
res.redirect("https://zoff.me");
|
||||
} else {
|
||||
@@ -184,13 +200,16 @@ function root(req, res, next) {
|
||||
embed: false,
|
||||
client: false,
|
||||
og_image: "https://zoff.me/assets/images/small-square.jpg",
|
||||
channels: [],
|
||||
}
|
||||
channels: []
|
||||
};
|
||||
if (subdomain[0] == "client") {
|
||||
data.client = true;
|
||||
}
|
||||
Frontpage.get_frontpage_lists(function(err, docs) {
|
||||
db.collection("connected_users").find({"_id": "total_users"}, function(err, tot) {
|
||||
db.collection("connected_users").find({ _id: "total_users" }, function(
|
||||
err,
|
||||
tot
|
||||
) {
|
||||
if (docs.length > 0) {
|
||||
data.channels_exist = true;
|
||||
data.channels = docs.slice(0, 12);
|
||||
@@ -201,10 +220,9 @@ function root(req, res, next) {
|
||||
data.channel_list = [];
|
||||
}
|
||||
data.viewers = tot[0].total_users.length;
|
||||
res.render('layouts/client/frontpage', data);
|
||||
res.render("layouts/client/frontpage", data);
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
@@ -214,8 +232,12 @@ function root(req, res, next) {
|
||||
|
||||
function channel(req, res, next) {
|
||||
try {
|
||||
var url = req.headers['x-forwarded-host'] ? req.headers['x-forwarded-host'] : req.headers.host.split(":")[0];
|
||||
var subdomain = req.headers['x-forwarded-host'] ? req.headers['x-forwarded-host'].split(".") : req.headers.host.split(":")[0].split(".");
|
||||
var url = req.headers["x-forwarded-host"]
|
||||
? req.headers["x-forwarded-host"]
|
||||
: req.headers.host.split(":")[0];
|
||||
var subdomain = req.headers["x-forwarded-host"]
|
||||
? req.headers["x-forwarded-host"].split(".")
|
||||
: req.headers.host.split(":")[0].split(".");
|
||||
/*if(url != "zoff.me" && url != "admin.localhost" && url != "admin.zoff.me" && url != "remote.zoff.me" && url != "fb.zoff.me" && url != "remote.localhost" && url != "localhost") {
|
||||
res.redirect("https://zoff.me");
|
||||
return;
|
||||
@@ -232,9 +254,9 @@ function channel(req, res, next) {
|
||||
stylesheet: "style.css",
|
||||
embed: false,
|
||||
client: false,
|
||||
og_image: "https://zoff.me/assets/images/small-square.jpg",
|
||||
}
|
||||
res.render('layouts/client/remote', data);
|
||||
og_image: "https://zoff.me/assets/images/small-square.jpg"
|
||||
};
|
||||
res.render("layouts/client/remote", data);
|
||||
} else if (subdomain.length >= 2 && subdomain[0] == "www") {
|
||||
res.redirect("https://zoff.me");
|
||||
} else {
|
||||
@@ -268,14 +290,14 @@ function channel(req, res, next) {
|
||||
embed: false,
|
||||
client: false,
|
||||
og_image: "https://zoff.me/assets/images/small-square.jpg"
|
||||
}
|
||||
};
|
||||
if (subdomain[0] == "client") {
|
||||
data.client = true;
|
||||
}
|
||||
if (req.params.channel_name == "404") {
|
||||
res.status(404);
|
||||
}
|
||||
res.render('layouts/client/channel', data);
|
||||
res.render("layouts/client/channel", data);
|
||||
//});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user