mirror of https://github.com/calzoneman/sync.git
Move contact page to its own route handler
This commit is contained in:
parent
88236e036c
commit
13d4a49976
|
@ -13,6 +13,7 @@
|
||||||
"bluebird": "^2.10.1",
|
"bluebird": "^2.10.1",
|
||||||
"body-parser": "^1.14.0",
|
"body-parser": "^1.14.0",
|
||||||
"cheerio": "^0.19.0",
|
"cheerio": "^0.19.0",
|
||||||
|
"clone": "^1.0.2",
|
||||||
"compression": "^1.5.2",
|
"compression": "^1.5.2",
|
||||||
"cookie-parser": "^1.4.0",
|
"cookie-parser": "^1.4.0",
|
||||||
"create-error": "^0.3.1",
|
"create-error": "^0.3.1",
|
||||||
|
|
|
@ -0,0 +1,27 @@
|
||||||
|
import clone from 'clone';
|
||||||
|
|
||||||
|
export default class WebConfiguration {
|
||||||
|
constructor(config) {
|
||||||
|
this.config = config;
|
||||||
|
}
|
||||||
|
|
||||||
|
getEmailContacts() {
|
||||||
|
return clone(this.config.contacts);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
WebConfiguration.fromOldConfig = function (oldConfig) {
|
||||||
|
const config = {
|
||||||
|
contacts: []
|
||||||
|
};
|
||||||
|
|
||||||
|
oldConfig.get('contacts').forEach(contact => {
|
||||||
|
config.contacts.push({
|
||||||
|
name: contact.name,
|
||||||
|
email: contact.email,
|
||||||
|
title: contact.title
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
return new WebConfiguration(config);
|
||||||
|
};
|
|
@ -44,6 +44,7 @@ var Flags = require("./flags");
|
||||||
var sio = require("socket.io");
|
var sio = require("socket.io");
|
||||||
import LocalChannelIndex from './web/localchannelindex';
|
import LocalChannelIndex from './web/localchannelindex';
|
||||||
import IOConfiguration from './configuration/ioconfig';
|
import IOConfiguration from './configuration/ioconfig';
|
||||||
|
import WebConfiguration from './configuration/webconfig';
|
||||||
import NullClusterClient from './io/cluster/nullclusterclient';
|
import NullClusterClient from './io/cluster/nullclusterclient';
|
||||||
|
|
||||||
var Server = function () {
|
var Server = function () {
|
||||||
|
@ -64,10 +65,12 @@ var Server = function () {
|
||||||
|
|
||||||
// webserver init -----------------------------------------------------
|
// webserver init -----------------------------------------------------
|
||||||
const ioConfig = IOConfiguration.fromOldConfig(Config);
|
const ioConfig = IOConfiguration.fromOldConfig(Config);
|
||||||
|
const webConfig = WebConfiguration.fromOldConfig(Config);
|
||||||
const clusterClient = new NullClusterClient(ioConfig);
|
const clusterClient = new NullClusterClient(ioConfig);
|
||||||
const channelIndex = new LocalChannelIndex();
|
const channelIndex = new LocalChannelIndex();
|
||||||
self.express = express();
|
self.express = express();
|
||||||
require("./web/webserver").init(self.express,
|
require("./web/webserver").init(self.express,
|
||||||
|
webConfig,
|
||||||
ioConfig,
|
ioConfig,
|
||||||
clusterClient,
|
clusterClient,
|
||||||
channelIndex);
|
channelIndex);
|
||||||
|
|
|
@ -0,0 +1,26 @@
|
||||||
|
import CyTubeUtil from '../../utilities';
|
||||||
|
import { sendJade } from '../jade';
|
||||||
|
|
||||||
|
export default function initialize(app, webConfig) {
|
||||||
|
app.get('/contact', (req, res) => {
|
||||||
|
// Basic obfuscation of email addresses to prevent spambots
|
||||||
|
// from picking them up. Not real encryption.
|
||||||
|
// Deobfuscated by clientside JS.
|
||||||
|
const contacts = webConfig.getEmailContacts().map(contact => {
|
||||||
|
const emkey = CyTubeUtil.randomSalt(16);
|
||||||
|
let email = new Array(contact.email.length);
|
||||||
|
for (let i = 0; i < contact.email.length; i++) {
|
||||||
|
email[i] = String.fromCharCode(
|
||||||
|
contact.email.charCodeAt(i) ^ emkey.charCodeAt(i % emkey.length)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
contact.email = escape(email.join(""));
|
||||||
|
contact.emkey = escape(emkey);
|
||||||
|
return contact;
|
||||||
|
});
|
||||||
|
|
||||||
|
return sendJade(res, 'contact', {
|
||||||
|
contacts: contacts
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
|
@ -110,39 +110,11 @@ function handleUserAgreement(req, res) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleContactPage(req, res) {
|
|
||||||
// Make a copy to prevent messing with the original
|
|
||||||
var contacts = Config.get("contacts").map(function (c) {
|
|
||||||
return {
|
|
||||||
name: c.name,
|
|
||||||
email: c.email,
|
|
||||||
title: c.title
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
// Rudimentary hiding of email addresses to prevent spambots
|
|
||||||
contacts.forEach(function (c) {
|
|
||||||
c.emkey = $util.randomSalt(16)
|
|
||||||
var email = new Array(c.email.length);
|
|
||||||
for (var i = 0; i < c.email.length; i++) {
|
|
||||||
email[i] = String.fromCharCode(
|
|
||||||
c.email.charCodeAt(i) ^ c.emkey.charCodeAt(i % c.emkey.length)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
c.email = escape(email.join(""));
|
|
||||||
c.emkey = escape(c.emkey);
|
|
||||||
});
|
|
||||||
|
|
||||||
sendJade(res, "contact", {
|
|
||||||
contacts: contacts
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
/**
|
/**
|
||||||
* Initializes webserver callbacks
|
* Initializes webserver callbacks
|
||||||
*/
|
*/
|
||||||
init: function (app, ioConfig, clusterClient, channelIndex) {
|
init: function (app, webConfig, ioConfig, clusterClient, channelIndex) {
|
||||||
app.use(function (req, res, next) {
|
app.use(function (req, res, next) {
|
||||||
req._ip = ipForRequest(req);
|
req._ip = ipForRequest(req);
|
||||||
next();
|
next();
|
||||||
|
@ -203,7 +175,7 @@ module.exports = {
|
||||||
app.get("/sioconfig(.json)?", handleSocketConfig);
|
app.get("/sioconfig(.json)?", handleSocketConfig);
|
||||||
require("./routes/socketconfig")(app, clusterClient);
|
require("./routes/socketconfig")(app, clusterClient);
|
||||||
app.get("/useragreement", handleUserAgreement);
|
app.get("/useragreement", handleUserAgreement);
|
||||||
app.get("/contact", handleContactPage);
|
require("./routes/contact")(app, webConfig);
|
||||||
require("./auth").init(app);
|
require("./auth").init(app);
|
||||||
require("./account").init(app);
|
require("./account").init(app);
|
||||||
require("./acp").init(app);
|
require("./acp").init(app);
|
||||||
|
@ -232,6 +204,9 @@ module.exports = {
|
||||||
}
|
}
|
||||||
if (!message) {
|
if (!message) {
|
||||||
message = 'An unknown error occurred.';
|
message = 'An unknown error occurred.';
|
||||||
|
} else if (/\.(jade|js)/.test(message)) {
|
||||||
|
// Prevent leakage of stack traces
|
||||||
|
message = 'An internal error occurred.';
|
||||||
}
|
}
|
||||||
|
|
||||||
// Log 5xx (server) errors
|
// Log 5xx (server) errors
|
||||||
|
|
Loading…
Reference in New Issue