From 826d49424e6183ef9f52c04a50bff57ce597fd1d Mon Sep 17 00:00:00 2001 From: Jack Date: Sun, 22 Oct 2017 10:06:07 -0400 Subject: [PATCH 01/37] Add title attribute --- public/views/panel/api.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/views/panel/api.html b/public/views/panel/api.html index d8dcfa9..7cb1e60 100644 --- a/public/views/panel/api.html +++ b/public/views/panel/api.html @@ -61,7 +61,7 @@ {{prefix}}: - + From ebfbcbe2cee330f2801a1f3c0e02f046ac8a738e Mon Sep 17 00:00:00 2001 From: Jack Date: Sun, 22 Oct 2017 12:19:51 -0400 Subject: [PATCH 02/37] Allow uploading via API key --- app/models/Upload.js | 1 + app/routes/routes.js | 33 ++++++++++++++--- app/routes/upload.js | 101 +++++++++++++++++++++++++++++++++++++++------------ 3 files changed, 106 insertions(+), 29 deletions(-) diff --git a/app/models/Upload.js b/app/models/Upload.js index 4b77826..3b43c6a 100644 --- a/app/models/Upload.js +++ b/app/models/Upload.js @@ -11,6 +11,7 @@ var UploadSchema = mongoose.Schema({ default: 0 }, uploader: String, + uploadKey: String, date: Date, file: Object }); diff --git a/app/routes/routes.js b/app/routes/routes.js index 5ff6175..fe75047 100644 --- a/app/routes/routes.js +++ b/app/routes/routes.js @@ -8,17 +8,40 @@ var login = require('./login.js'); var panel = require('./panel.js'); var keys = require('./keys.js'); -var fs = require('fs'); -var path = require('path'); +var Key = require('../models/Key.js'); -var requireLogin = function(req, res, next) { +var checkApiKey = function (key, cb) { + Key.find({key: key}, function (err, res) { + if (err) throw err; + cb(res.length === 1); + }); +}; + +var requireLogin = function (req, res, next) { if (!req.session || !req.session.passport) return res.redirect('/login'); else return next(); }; -module.exports = function(app) { +var requireLoginApi = function(req, res, next) { + if (!req.session || !req.session.passport) { + if (!req.body.apikey) { + return res.redirect('/login'); + } else { + checkApiKey(res.body.apikey, function(valid) { + if (!valid) + return res.sendStatus(401); + else + return next(); + }); + } + } else { + return next(); + } +}; + +module.exports = function (app) { app.use('/', index); app.use('/home', requireLogin, home); app.use('/v', view); @@ -30,7 +53,7 @@ module.exports = function(app) { app.use('/panel', requireLogin, panel); app.use('/panel*', requireLogin, panel); - app.use(function(err, req, res, next) { + app.use(function (err, req, res, next) { if (err.name === 'UnauthorizedError') { res.status(401); res.json({"message": err.name + ": " + err.message}); diff --git a/app/routes/upload.js b/app/routes/upload.js index b5138ff..7f6b8c3 100644 --- a/app/routes/upload.js +++ b/app/routes/upload.js @@ -4,6 +4,7 @@ var router = express.Router(); var mongoose = require('mongoose'); var User = require('../models/User.js'); var Upload = require('../models/Upload.js'); +var Key = require('../models/Key.js'); var multer = require('multer'); var dest = multer({dest: 'uploads/'}); @@ -14,12 +15,6 @@ function fileNameExists(name) { }); } -function updateUserStats(user, size) { - User.updateOne({username: user}, {$inc: {uploadCount: 1, uploadSize: size}}, function (err, res) { - if (err) throw err; - }); -} - function genFileName() { var charset = "abcdefghijklmnopqrstuvwxyz"; do { @@ -30,32 +25,90 @@ function genFileName() { return chars.join(''); } -router.post('/', dest.single('file'), function (req, res) { - // Size must be below 128 Megabytes (1024*1024*128 Bytes) - if (req.file.size >= 134217728) { - res.status(413).json({'message': 'File too large.'}); - return; +function updateStats(type, id, size) { + if (type === 'session') { + User.updateOne({username: id}, {$inc: {uploadCount: 1, uploadSize: size}}, function (err) { + if (err) throw err; + }); + } else if (type === 'apikey') { + Key.updateOne({key: id}, {$inc: {uploadCount: 1, uploadSize: size}}, function (err) { + if (err) throw err; + }); } +} - updateUserStats(req.session.passport.user, req.file.size); +var checkApiKey = function (key, cb) { + Key.find({key: key}, function (err, res) { + if (err) throw err; + cb(res.length === 1, res); + }); +}; - var entry = { - name: genFileName(), - uploader: req.session.passport.user, - created: Date.now(), - file: req.file - }; +var checkScope = function (type, id, perm, cb) { + if (type === 'session') { + User.findOne({username: id}, function (err, user) { + if (err) throw err; + cb(user.scope.indexOf(perm) !== -1); + }); + } else { + Key.findOne({key: id}, function (err, key) { + if (err) throw err; + cb(key.scope.indexOf(perm) !== -1); + }); + } +}; - Upload.create(entry, function (err, next) { - if (err) { - next(err); - } else { - res.send({ +function uploadFile(req, res, type, key) { + if (!req.file) + return res.status(400).json({'message': 'No file specified.'}); + + // Size must be below 128 Megabytes (1024*1024*128 Bytes) + if (req.file.size >= 134217728) + return res.status(413).json({'message': 'File too large.'}); + + var uploader = type === 'session' ? req.session.passport.user : key[0].username; + var uploadKey = type === 'apikey' ? key[0].key : null; + var id = type === 'session' ? req.session.passport.user : key[0].key; + + checkScope(type, id, 'file.upload', function (valid) { + if (!valid) + return res.status(403).json({'message': 'No permission.'}); + + var entry = { + name: genFileName(), + uploader: uploader, + uploadKey: uploadKey, + date: Date.now(), + file: req.file + }; + + updateStats(type, id, req.file.size); + + Upload.create(entry, function (err) { + if (err) throw err; + res.status(200).json({ name: entry.name, url: 'https://shimapan.rocks/v/' + entry.name }); - } + }); }); +} + +router.post('/', dest.single('file'), function (req, res) { + if (!req.session || !req.session.passport) { + if (!req.body.apikey) { + return res.sendStatus(401); + } else { + checkApiKey(req.body.apikey, function (valid, key) { + if (!valid) + return res.sendStatus(401); + else + uploadFile(req, res, 'apikey', key); + }); + } + } else { + uploadFile(req, res, 'session'); + } }); module.exports = router; From ba704d19dc560bb6e16efd55c5ba61e67ce335ef Mon Sep 17 00:00:00 2001 From: Jack Date: Mon, 23 Oct 2017 14:14:12 -0400 Subject: [PATCH 03/37] Update example bash script --- public/views/panel/api.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/views/panel/api.html b/public/views/panel/api.html index 7cb1e60..f8e937b 100644 --- a/public/views/panel/api.html +++ b/public/views/panel/api.html @@ -23,7 +23,7 @@

This key can be used with any 3rd party program or service to upload to and manage your account with Shimapan.

For example, it can be used in a bash script to upload from the command line:

-
APIKEY=[Your API Key Here]
URL=$(curl -s -F "apikey=$APIKEY" -F "file=@$1" https://shimapan.rocks/api/upload | grep url | awk '{print $2}')
echo $URL | tr -d '[\\\,"\n]'
+
APIKEY=[Your API Key Here]
URL=$(curl -s -F "apikey=$APIKEY" -F "file=@$1" https://shimapan.rocks/api/upload | grep -Po '"'"url"'"\s*:\s*"\K([^"]*)'
echo $URL

Key Permissions:

From 86b7de2039936def90c96c1731d4be9a868fd2ba Mon Sep 17 00:00:00 2001 From: Jack Foltz Date: Sat, 13 Jan 2018 17:20:14 -0500 Subject: [PATCH 04/37] Update file permissions --- .gitignore | 0 README.md | 0 app/models/Invite.js | 0 app/models/Key.js | 0 app/models/Upload.js | 0 app/models/User.js | 0 app/public/css/form.css | 0 app/public/css/form.min.css | 0 app/public/css/home.css | 0 app/public/css/home.min.css | 0 app/public/css/index.css | 0 app/public/css/index.min.css | 0 app/public/css/panel.css | 0 app/public/css/panel.min.css | 0 app/public/index/typegraph.js | 0 app/public/panel/controllers/ApiCtrl.js | 0 app/public/panel/controllers/NavCtrl.js | 0 app/public/panel/routes.js | 0 app/public/panel/shimapan-panel.js | 0 app/public/services/ApiSvc.js | 0 app/public/services/AuthSvc.js | 0 app/public/shimapan/components/LoginComp.js | 0 app/public/shimapan/components/RegisterComp.js | 0 app/public/shimapan/components/UploadComp.js | 0 app/public/shimapan/shimapan.js | 0 app/routes/auth.js | 0 app/routes/home.js | 0 app/routes/index.js | 0 app/routes/keys.js | 0 app/routes/login.js | 0 app/routes/panel.js | 0 app/routes/register.js | 0 app/routes/routes.js | 0 app/routes/upload.js | 0 app/routes/view.js | 0 config/default.json | 0 config/dev.json | 0 config/passport.js | 0 config/test.json | 0 gulpfile.js | 0 package-lock.json | 0 package.json | 0 public/img/edge.mp4 | Bin public/img/flower.png | Bin public/img/glyphicons-512-copy.png | Bin public/views/home.html | 0 public/views/index.html | 0 public/views/login.html | 0 public/views/panel.html | 0 public/views/panel/api.html | 0 public/views/panel/dash.html | 0 public/views/panel/invites.html | 0 public/views/panel/search.html | 0 public/views/panel/stats.html | 0 public/views/panel/users.html | 0 public/views/register.html | 0 public/views/shimapan/login-form.html | 0 public/views/shimapan/register-form.html | 0 public/views/shimapan/upload-form.html | 0 server.js | 0 test/api.js | 0 test/test.png | Bin test/testUtil.js | 0 63 files changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 .gitignore mode change 100644 => 100755 README.md mode change 100644 => 100755 app/models/Invite.js mode change 100644 => 100755 app/models/Key.js mode change 100644 => 100755 app/models/Upload.js mode change 100644 => 100755 app/models/User.js mode change 100644 => 100755 app/public/css/form.css mode change 100644 => 100755 app/public/css/form.min.css mode change 100644 => 100755 app/public/css/home.css mode change 100644 => 100755 app/public/css/home.min.css mode change 100644 => 100755 app/public/css/index.css mode change 100644 => 100755 app/public/css/index.min.css mode change 100644 => 100755 app/public/css/panel.css mode change 100644 => 100755 app/public/css/panel.min.css mode change 100644 => 100755 app/public/index/typegraph.js mode change 100644 => 100755 app/public/panel/controllers/ApiCtrl.js mode change 100644 => 100755 app/public/panel/controllers/NavCtrl.js mode change 100644 => 100755 app/public/panel/routes.js mode change 100644 => 100755 app/public/panel/shimapan-panel.js mode change 100644 => 100755 app/public/services/ApiSvc.js mode change 100644 => 100755 app/public/services/AuthSvc.js mode change 100644 => 100755 app/public/shimapan/components/LoginComp.js mode change 100644 => 100755 app/public/shimapan/components/RegisterComp.js mode change 100644 => 100755 app/public/shimapan/components/UploadComp.js mode change 100644 => 100755 app/public/shimapan/shimapan.js mode change 100644 => 100755 app/routes/auth.js mode change 100644 => 100755 app/routes/home.js mode change 100644 => 100755 app/routes/index.js mode change 100644 => 100755 app/routes/keys.js mode change 100644 => 100755 app/routes/login.js mode change 100644 => 100755 app/routes/panel.js mode change 100644 => 100755 app/routes/register.js mode change 100644 => 100755 app/routes/routes.js mode change 100644 => 100755 app/routes/upload.js mode change 100644 => 100755 app/routes/view.js mode change 100644 => 100755 config/default.json mode change 100644 => 100755 config/dev.json mode change 100644 => 100755 config/passport.js mode change 100644 => 100755 config/test.json mode change 100644 => 100755 gulpfile.js mode change 100644 => 100755 package-lock.json mode change 100644 => 100755 package.json mode change 100644 => 100755 public/img/edge.mp4 mode change 100644 => 100755 public/img/flower.png mode change 100644 => 100755 public/img/glyphicons-512-copy.png mode change 100644 => 100755 public/views/home.html mode change 100644 => 100755 public/views/index.html mode change 100644 => 100755 public/views/login.html mode change 100644 => 100755 public/views/panel.html mode change 100644 => 100755 public/views/panel/api.html mode change 100644 => 100755 public/views/panel/dash.html mode change 100644 => 100755 public/views/panel/invites.html mode change 100644 => 100755 public/views/panel/search.html mode change 100644 => 100755 public/views/panel/stats.html mode change 100644 => 100755 public/views/panel/users.html mode change 100644 => 100755 public/views/register.html mode change 100644 => 100755 public/views/shimapan/login-form.html mode change 100644 => 100755 public/views/shimapan/register-form.html mode change 100644 => 100755 public/views/shimapan/upload-form.html mode change 100644 => 100755 server.js mode change 100644 => 100755 test/api.js mode change 100644 => 100755 test/test.png mode change 100644 => 100755 test/testUtil.js diff --git a/.gitignore b/.gitignore old mode 100644 new mode 100755 diff --git a/README.md b/README.md old mode 100644 new mode 100755 diff --git a/app/models/Invite.js b/app/models/Invite.js old mode 100644 new mode 100755 diff --git a/app/models/Key.js b/app/models/Key.js old mode 100644 new mode 100755 diff --git a/app/models/Upload.js b/app/models/Upload.js old mode 100644 new mode 100755 diff --git a/app/models/User.js b/app/models/User.js old mode 100644 new mode 100755 diff --git a/app/public/css/form.css b/app/public/css/form.css old mode 100644 new mode 100755 diff --git a/app/public/css/form.min.css b/app/public/css/form.min.css old mode 100644 new mode 100755 diff --git a/app/public/css/home.css b/app/public/css/home.css old mode 100644 new mode 100755 diff --git a/app/public/css/home.min.css b/app/public/css/home.min.css old mode 100644 new mode 100755 diff --git a/app/public/css/index.css b/app/public/css/index.css old mode 100644 new mode 100755 diff --git a/app/public/css/index.min.css b/app/public/css/index.min.css old mode 100644 new mode 100755 diff --git a/app/public/css/panel.css b/app/public/css/panel.css old mode 100644 new mode 100755 diff --git a/app/public/css/panel.min.css b/app/public/css/panel.min.css old mode 100644 new mode 100755 diff --git a/app/public/index/typegraph.js b/app/public/index/typegraph.js old mode 100644 new mode 100755 diff --git a/app/public/panel/controllers/ApiCtrl.js b/app/public/panel/controllers/ApiCtrl.js old mode 100644 new mode 100755 diff --git a/app/public/panel/controllers/NavCtrl.js b/app/public/panel/controllers/NavCtrl.js old mode 100644 new mode 100755 diff --git a/app/public/panel/routes.js b/app/public/panel/routes.js old mode 100644 new mode 100755 diff --git a/app/public/panel/shimapan-panel.js b/app/public/panel/shimapan-panel.js old mode 100644 new mode 100755 diff --git a/app/public/services/ApiSvc.js b/app/public/services/ApiSvc.js old mode 100644 new mode 100755 diff --git a/app/public/services/AuthSvc.js b/app/public/services/AuthSvc.js old mode 100644 new mode 100755 diff --git a/app/public/shimapan/components/LoginComp.js b/app/public/shimapan/components/LoginComp.js old mode 100644 new mode 100755 diff --git a/app/public/shimapan/components/RegisterComp.js b/app/public/shimapan/components/RegisterComp.js old mode 100644 new mode 100755 diff --git a/app/public/shimapan/components/UploadComp.js b/app/public/shimapan/components/UploadComp.js old mode 100644 new mode 100755 diff --git a/app/public/shimapan/shimapan.js b/app/public/shimapan/shimapan.js old mode 100644 new mode 100755 diff --git a/app/routes/auth.js b/app/routes/auth.js old mode 100644 new mode 100755 diff --git a/app/routes/home.js b/app/routes/home.js old mode 100644 new mode 100755 diff --git a/app/routes/index.js b/app/routes/index.js old mode 100644 new mode 100755 diff --git a/app/routes/keys.js b/app/routes/keys.js old mode 100644 new mode 100755 diff --git a/app/routes/login.js b/app/routes/login.js old mode 100644 new mode 100755 diff --git a/app/routes/panel.js b/app/routes/panel.js old mode 100644 new mode 100755 diff --git a/app/routes/register.js b/app/routes/register.js old mode 100644 new mode 100755 diff --git a/app/routes/routes.js b/app/routes/routes.js old mode 100644 new mode 100755 diff --git a/app/routes/upload.js b/app/routes/upload.js old mode 100644 new mode 100755 diff --git a/app/routes/view.js b/app/routes/view.js old mode 100644 new mode 100755 diff --git a/config/default.json b/config/default.json old mode 100644 new mode 100755 diff --git a/config/dev.json b/config/dev.json old mode 100644 new mode 100755 diff --git a/config/passport.js b/config/passport.js old mode 100644 new mode 100755 diff --git a/config/test.json b/config/test.json old mode 100644 new mode 100755 diff --git a/gulpfile.js b/gulpfile.js old mode 100644 new mode 100755 diff --git a/package-lock.json b/package-lock.json old mode 100644 new mode 100755 diff --git a/package.json b/package.json old mode 100644 new mode 100755 diff --git a/public/img/edge.mp4 b/public/img/edge.mp4 old mode 100644 new mode 100755 diff --git a/public/img/flower.png b/public/img/flower.png old mode 100644 new mode 100755 diff --git a/public/img/glyphicons-512-copy.png b/public/img/glyphicons-512-copy.png old mode 100644 new mode 100755 diff --git a/public/views/home.html b/public/views/home.html old mode 100644 new mode 100755 diff --git a/public/views/index.html b/public/views/index.html old mode 100644 new mode 100755 diff --git a/public/views/login.html b/public/views/login.html old mode 100644 new mode 100755 diff --git a/public/views/panel.html b/public/views/panel.html old mode 100644 new mode 100755 diff --git a/public/views/panel/api.html b/public/views/panel/api.html old mode 100644 new mode 100755 diff --git a/public/views/panel/dash.html b/public/views/panel/dash.html old mode 100644 new mode 100755 diff --git a/public/views/panel/invites.html b/public/views/panel/invites.html old mode 100644 new mode 100755 diff --git a/public/views/panel/search.html b/public/views/panel/search.html old mode 100644 new mode 100755 diff --git a/public/views/panel/stats.html b/public/views/panel/stats.html old mode 100644 new mode 100755 diff --git a/public/views/panel/users.html b/public/views/panel/users.html old mode 100644 new mode 100755 diff --git a/public/views/register.html b/public/views/register.html old mode 100644 new mode 100755 diff --git a/public/views/shimapan/login-form.html b/public/views/shimapan/login-form.html old mode 100644 new mode 100755 diff --git a/public/views/shimapan/register-form.html b/public/views/shimapan/register-form.html old mode 100644 new mode 100755 diff --git a/public/views/shimapan/upload-form.html b/public/views/shimapan/upload-form.html old mode 100644 new mode 100755 diff --git a/server.js b/server.js old mode 100644 new mode 100755 diff --git a/test/api.js b/test/api.js old mode 100644 new mode 100755 diff --git a/test/test.png b/test/test.png old mode 100644 new mode 100755 diff --git a/test/testUtil.js b/test/testUtil.js old mode 100644 new mode 100755 From bf2eb3b251784d0dd21be5d3fa7fa5c363e64f66 Mon Sep 17 00:00:00 2001 From: Jack Foltz Date: Sat, 13 Jan 2018 17:36:40 -0500 Subject: [PATCH 05/37] Add hasOwnProperty checks to AuthSvc --- app/public/services/AuthSvc.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/public/services/AuthSvc.js b/app/public/services/AuthSvc.js index e387e93..03c38f7 100755 --- a/app/public/services/AuthSvc.js +++ b/app/public/services/AuthSvc.js @@ -9,7 +9,8 @@ angular.module('AuthSvc', []).service('AuthService', ['$http', '$window', functi transformRequest: function(obj) { var str = []; for (var p in obj) - str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p])); + if (obj.hasOwnProperty(p)) + str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p])); return str.join("&"); }, data: user @@ -36,7 +37,8 @@ angular.module('AuthSvc', []).service('AuthService', ['$http', '$window', functi transformRequest: function(obj) { var str = []; for (var p in obj) - str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p])); + if (obj.hasOwnProperty(p)) + str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p])); return str.join("&"); }, data: user From f3af8ea53e5c506fc407dbf23d45d7a4f1199b92 Mon Sep 17 00:00:00 2001 From: Jack Foltz Date: Sat, 13 Jan 2018 17:58:50 -0500 Subject: [PATCH 06/37] Disable dragging on panel links --- public/views/panel.html | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/public/views/panel.html b/public/views/panel.html index e7a939c..b15c315 100755 --- a/public/views/panel.html +++ b/public/views/panel.html @@ -12,13 +12,13 @@
From 24ba7b6eb3e3bbe489385451c30f24f7bdf986a2 Mon Sep 17 00:00:00 2001 From: Jack Foltz Date: Sat, 13 Jan 2018 17:59:07 -0500 Subject: [PATCH 07/37] Update homepage video and style --- app/public/css/index.css | 4 +--- public/views/index.html | 4 +--- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/app/public/css/index.css b/app/public/css/index.css index 4461762..2bcbff1 100755 --- a/app/public/css/index.css +++ b/app/public/css/index.css @@ -8,7 +8,7 @@ body { a { position: absolute; - top: 5px; + top: 40px; left: 48%; opacity: 0.1; height: 30px; @@ -34,8 +34,6 @@ video { left: 50%; min-width: 100%; min-height: 100%; - width: 1920px; - height: 760px; z-index: -100; transform: translateX(-50%) translateY(-50%); background-size: cover; diff --git a/public/views/index.html b/public/views/index.html index 0a3373f..99d4e8c 100755 --- a/public/views/index.html +++ b/public/views/index.html @@ -15,9 +15,7 @@