diff --git a/lib/web/auth.js b/lib/web/auth.js index 937bbd91..395f17dc 100644 --- a/lib/web/auth.js +++ b/lib/web/auth.js @@ -8,6 +8,7 @@ var jade = require("jade"); var fs = require("fs"); var path = require("path"); var webserver = require("./webserver"); +var cookieall = webserver.cookieall; var sendJade = require("./jade").sendJade; var Logger = require("../logger"); var $util = require("../utilities"); @@ -39,25 +40,16 @@ function handleLogin(req, res) { loginError: err }); } else { - res.cookie("auth", user.name + ":" + user.hash, { + cookieall(res, "auth", user.name + ":" + user.hash, { expires: new Date(Date.now() + 7*24*60*60*1000), httpOnly: true }); - res.cookie("auth", user.name + ":" + user.hash, { - domain: Config.get("http.domain"), + cookieall(res, "rank", user.global_rank, { expires: new Date(Date.now() + 7*24*60*60*1000), httpOnly: true }); - if (Config.get("https.enabled")) { - res.cookie("auth", user.name + ":" + user.hash, { - domain: Config.get("https.domain"), - expires: new Date(Date.now() + 7*24*60*60*1000), - httpOnly: true - }); - } - // Try to find an appropriate redirect var ref = req.header("referrer"); if (!ref) { diff --git a/lib/web/webserver.js b/lib/web/webserver.js index c3b0db28..ad34a8d0 100644 --- a/lib/web/webserver.js +++ b/lib/web/webserver.js @@ -55,12 +55,22 @@ function logRequest(req, status) { httplog.log([ ipForRequest(req), - req.route.method.toUpperCase(), + req.method, req.path, req.header("user-agent") ].join(" ")); } +function cookieall(res, name, val, opts) { + res.cookie(name, val, opts); + opts.domain = Config.get("http.domain"); + res.cookie(name, val, opts); + if (Config.get("https.enabled")) { + opts.domain = Config.get("https.domain"); + res.cookie(name, val, opts); + } +} + /** * Redirects a request to HTTPS if the server supports it */ @@ -87,7 +97,6 @@ function redirectHttp(req, res) { if (port !== 80) { domain += ":" + port; } - console.log(domain); res.redirect(domain + req.path); return true; } @@ -232,9 +241,25 @@ function handleContactPage(req, res) { function static(dir) { dir = path.join(__dirname, dir); return function (req, res) { + if (isSuspicious(req)) { + logRequest(req, 403); + res.status(403); + if (typeof req.header("user-agent") === "string" && + req.header("user-agent").toLowerCase() === "zmeu") { + res.send("This server disallows requests from ZmEu."); + } else { + res.send("The request " + req.route.method.toUpperCase() + " " + + req.path + " looks pretty fishy to me. Double check that " + + "you typed it correctly."); + } + return; + } + res.sendfile(req.path.replace(/^\//, ""), { maxAge: Config.get("http.cache-ttl") * 1000, root: dir + }, function (err) { + logRequest(req); }); }; } @@ -266,24 +291,6 @@ module.exports = { require("./auth").init(app); require("./account").init(app); require("./acp").init(app); - app.all("*", function (req, res, next) { - if (isSuspicious(req)) { - logRequest(req, 403); - res.status(403); - if (typeof req.header("user-agent") === "string" && - req.header("user-agent").toLowerCase() === "zmeu") { - res.send("This server disallows requests from ZmEu."); - } else { - res.send("The request " + req.route.method.toUpperCase() + " " + - req.path + " looks pretty fishy to me. Double check that " + - "you typed it correctly."); - } - return; - } - logRequest(req); - next(); - }); - //app.use(express.static("www")); app.use(static(path.join("..", "..", "www"))); }, @@ -293,5 +300,7 @@ module.exports = { redirectHttps: redirectHttps, - redirectHttp: redirectHttp + redirectHttp: redirectHttp, + + cookieall: cookieall }; diff --git a/templates/head.jade b/templates/head.jade index 94f8ded4..7be37e4f 100644 --- a/templates/head.jade +++ b/templates/head.jade @@ -9,7 +9,7 @@ mixin head() //link(href="/css/bootstrap-theme.min.css", rel="stylesheet") link(href="/css/sticky-footer-navbar.css", rel="stylesheet") link(href="/css/cytube.css", rel="stylesheet") - link(id="usertheme", href="/css/themes/default.css", rel="stylesheet") + link(id="usertheme", href="/css/themes/slate.css", rel="stylesheet") script(src="/js/theme.js") //[if lt IE 9] diff --git a/templates/nav.jade b/templates/nav.jade index b75939d1..c0e977c4 100644 --- a/templates/nav.jade +++ b/templates/nav.jade @@ -36,7 +36,6 @@ mixin navdefaultlinks(page) li: a(href="/login") Login li: a(href="/register") Register - mixin navloginlogout(redirect) if loggedIn mixin navlogoutform(redirect) diff --git a/templates/useroptions.jade b/templates/useroptions.jade index 92259e3c..7ab992ad 100644 --- a/templates/useroptions.jade +++ b/templates/useroptions.jade @@ -29,7 +29,7 @@ mixin us-general label.control-label.col-sm-4(for="#us-theme") Theme .col-sm-8 select#us-theme.form-control - option(value="default") Default + option(value="/css/themes/light.css") Light option(value="/css/themes/bootstrap-theme.min.css") Bootstrap option(value="/css/themes/slate.css") Slate option(value="/css/themes/cyborg.css") Cyborg diff --git a/www/css/themes/default.css b/www/css/themes/light.css similarity index 100% rename from www/css/themes/default.css rename to www/css/themes/light.css diff --git a/www/js/callbacks.js b/www/js/callbacks.js index f834fee6..5c8b609c 100644 --- a/www/js/callbacks.js +++ b/www/js/callbacks.js @@ -908,7 +908,7 @@ Callbacks = { $(li).appendTo($("#library")); }, - itemsPerPage: 10 + itemsPerPage: 100 }; var p = Paginate(data.results, opts); diff --git a/www/js/data.js b/www/js/data.js index d13328b8..10094903 100644 --- a/www/js/data.js +++ b/www/js/data.js @@ -9,7 +9,7 @@ The above copyright notice and this permission notice shall be included in all c THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -var CL_VERSION = "3.0.0"; +var CL_VERSION = 3.0; var CLIENT = { rank: -1, @@ -99,9 +99,8 @@ function getOrDefault(k, def) { } var USEROPTS = { - theme : getOrDefault("theme", "default"), - css : getOrDefault("css", ""), - layout : getOrDefault("layout", "default"), + theme : getOrDefault("theme", "/css/themes/slate.css"), + layout : getOrDefault("layout", "fluid"), synch : getOrDefault("synch", true), hidevid : getOrDefault("hidevid", false), show_timestamps : getOrDefault("show_timestamps", true), @@ -164,5 +163,16 @@ function eraseCookie(name) { createCookie(name,"",-1); } +(function () { + var localVersion = parseFloat(getOpt("version")); + if (isNaN(localVersion)) { + USEROPTS.theme = "/css/themes/slate.css"; + USEROPTS.layout = "fluid"; + setOpt("theme", "/css/themes/slate.css"); + setOpt("layout", "fluid"); + setOpt("version", CL_VERSION); + } +})(); + /* to be implemented in callbacks.js */ function setupCallbacks() { } diff --git a/www/js/theme.js b/www/js/theme.js index 3e1bf4e6..d9310267 100644 --- a/www/js/theme.js +++ b/www/js/theme.js @@ -3,7 +3,7 @@ return s.trim(); }); - var theme = "default"; + var theme = "/css/themes/slate.css"; for (var i = 0; i < c.length; i++) { if (c[i].indexOf("cytube-theme=") === 0) { theme = c[i].split("=")[1]; @@ -11,7 +11,8 @@ } } - if (theme !== "default") { + if (theme !== "/css/themes/slate.css") { + console.log("THEME COOKIE:", theme); var cur = document.getElementById("usertheme"); cur.parentNode.removeChild(cur); var css = document.createElement("link"); diff --git a/www/js/util.js b/www/js/util.js index cf19195d..174c91e7 100644 --- a/www/js/util.js +++ b/www/js/util.js @@ -662,7 +662,7 @@ function applyOpts() { $("#usertheme").remove(); var theme = USEROPTS.theme; if (theme === "default") { - theme = "/css/themes/default.css"; + theme = "/css/themes/slate.css"; } $("").attr("rel", "stylesheet") .attr("type", "text/css")