ajout d'une protection par mot de passe + favicon + theme configurable

This commit is contained in:
WEBER Antoine 2015-09-29 23:04:17 +02:00
parent 755a91a5b6
commit 0f9f498607
11 changed files with 42 additions and 20 deletions

35
app.js
View File

@ -4,11 +4,7 @@ var favicon = require('serve-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
/*var routes = require('./routes/index');
var users = require('./routes/users');
var file = require('./routes/file');
var channel = require('./routes/channel');*/
var config = require('./config');
var app = express();
@ -16,14 +12,39 @@ var app = express();
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');
// uncomment after placing your favicon in /public
//app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
//protection par mot de passe
if( typeof config.auth_user !== 'undefined' && typeof config.auth_password !== 'undefined' ){
console.log("SAFE MODE: votre serveur est protégé par mot de passe.");
var basicAuth = require('basic-auth');
app.use(function(req, res, next) {
var user = basicAuth(req);
if (!user || user.name !== config.auth_user || user.pass !== config.auth_password) {
res.set('WWW-Authenticate', 'Basic realm=Authorization Required');
return res.sendStatus(401);
}
else{
next();
}
});
}
else{
console.log("UNSAFE MODE: configurez un auth_user et auth_password dans le fichier config.js");
}
//envoyer config a tout le monde
app.use(function(req, res, next) {
res.locals.config = config;
next();
});
app.use(favicon(path.join(__dirname, 'public', 'iconarchive_plex.ico')));
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
app.use('/', require('./routes/index'));
app.use('/users', require('./routes/users'));
app.use('/file', require('./routes/file'));

View File

@ -17,9 +17,10 @@ Docker
module.exports = {
database: "/home/antoine/plex-config/Plex Media Server/Plug-in Support/Databases/com.plexapp.plugins.library.db",
theme: "//cdnjs.cloudflare.com/ajax/libs/bootswatch/3.3.5/darkly/bootstrap.css",
presentation: "<h1>Bienvenue sur mon serveur</h1><p>Merci de respecter mon upload...</p>",
//auth_user: "monUser",
//auth_password: "monPassword",
init_db: function(){
var sqlite3 = require('sqlite3').verbose();

View File

@ -6,14 +6,15 @@
"start": "node ./bin/www"
},
"dependencies": {
"basic-auth": "^1.0.3",
"body-parser": "~1.13.2",
"cluster": "~0.7.7",
"cookie-parser": "~1.3.5",
"debug": "~2.2.0",
"express": "~4.13.1",
"jade": "~1.11.0",
"morgan": "~1.6.1",
"serve-favicon": "~2.3.0",
"sqlite3": "~3",
"cluster":"~0.7.7"
"sqlite3": "~3"
}
}

View File

@ -3,7 +3,7 @@ var router = express.Router();
/* GET home page. */
router.get('/:id', function(req, res, next) {
var config = require('../config');
var config = res.locals.config;
var db = config.init_db();
var data = [];

View File

@ -3,8 +3,7 @@ var router = express.Router();
/* GET users listing. */
router.get('/:id/:filename', function (req, res, next) {
var config = require('../config');
var config = res.locals.config;
var db = config.init_db();
//db.run("CREATE TABLE if not exists user_info (info TEXT)");

View File

@ -4,7 +4,7 @@ var router = express.Router();
/* GET home page. */
router.get('/', function(req, res, next) {
var config = require('../config');
var config = res.locals.config;//require('../config');
var db = config.init_db();
var data = [];

View File

@ -19,8 +19,7 @@ function humanFileSize(bytes, si) {
/* GET home page. */
router.get('/:id', function(req, res, next) {
var config = require('../config');
var config = res.locals.config;
var db = config.init_db();
var data;

View File

@ -17,7 +17,7 @@ function addZero(v) {
/* GET home page. */
router.get('/:id', function(req, res, next) {
var config = require('../config');
var config = res.locals.config;
var db = config.init_db();
var data = [];

View File

@ -3,7 +3,7 @@ var router = express.Router();
/* GET home page. */
router.get('/:id', function(req, res, next) {
var config = require('../config');
var config = res.locals.config;
var db = config.init_db();
var shows = [];

View File

@ -3,6 +3,7 @@ var router = express.Router();
/* GET users listing. */
router.get('/', function(req, res, next) {
var config = res.locals.config;
res.send('respond with a resource');
});

View File

@ -3,7 +3,7 @@ html
head
title= title
meta(charset='UTF8')
link(rel='stylesheet', href='//cdnjs.cloudflare.com/ajax/libs/bootswatch/3.3.5/darkly/bootstrap.css')
link(rel='stylesheet', href='#{config.theme}')
link(rel='stylesheet', href='//cdn.datatables.net/1.10.9/css/dataTables.bootstrap.min.css')
script(type='text/javascript', src='//code.jquery.com/jquery-1.11.3.min.js')
script(type='text/javascript', src='//cdn.datatables.net/1.10.9/js/jquery.dataTables.min.js')