Update haproxy-sdk to new version with small failsafe for illegal commands

Reenable custom backend mapping to show backend server names
Minor formatting fixes
develop
Your Name 2 years ago
parent cf3176f811
commit f4cbb8ccb0
  1. 1
      Dockerfile
  2. 2
      api.js
  3. 1
      controllers/maps.js
  4. 14
      package-lock.json
  5. 2
      package.json
  6. 6
      pages/account.js
  7. 12
      pages/map/[name].js
  8. 19
      router.js
  9. 4
      util.js

@ -9,7 +9,6 @@ RUN npm install --production
COPY .env /opt/.env
COPY . /opt
COPY ./node_modules/@fatchan/haproxy-sdk/lib/_utils.js /opt/node_modules/@fatchan/haproxy-sdk/lib/_utils.js
RUN npm run build

@ -20,7 +20,7 @@ function buildOptions(route, method, body) {
export default async function ApiCall(route, method='get', body, stateCallback, errorCallback, finishProgress, router) {
// Start progress bar
NProgress.start();
NProgress.start();
// Build request options for fetch
const requestOptions = buildOptions(route, method, body);

@ -23,6 +23,7 @@ exports.mapData = async (req, res, next) => {
switch (req.params.name) {
case process.env.DDOS_MAP_NAME:
showValues = true;
case process.env.BACKENDS_MAP_NAME:
case process.env.HOSTS_MAP_NAME:
if (process.env.CUSTOM_BACKENDS_ENABLED) {
showValues = true;

14
package-lock.json generated

@ -9,7 +9,7 @@
"version": "1.0.0",
"license": "AGPL-3.0-only",
"dependencies": {
"@fatchan/haproxy-sdk": "^1.0.5",
"@fatchan/haproxy-sdk": "^1.0.6",
"bcrypt": "^5.0.1",
"body-parser": "^1.20.0",
"bootstrap": "^5.1.3",
@ -102,9 +102,9 @@
"dev": true
},
"node_modules/@fatchan/haproxy-sdk": {
"version": "1.0.5",
"resolved": "https://registry.npmjs.org/@fatchan/haproxy-sdk/-/haproxy-sdk-1.0.5.tgz",
"integrity": "sha512-O0NzzpAwOcJDKUgvkaGIxvXn+uozpAWbT1lncFEX5MGoJ/HmKGQCtARStQNk/d//Q1gm4ILiOmLa9XcJRq+cbQ==",
"version": "1.0.6",
"resolved": "https://registry.npmjs.org/@fatchan/haproxy-sdk/-/haproxy-sdk-1.0.6.tgz",
"integrity": "sha512-VJbQGtGuxNhpcmYQI9kXAKHpmWXqQ9hs0K+GzIDG7pJ2dwBwaDf71hcezvehFhgmQMqD7dDMZG+1QkMCJDbiMA==",
"engines": {
"node": ">=8.15.1",
"npm": ">=6.4.1"
@ -8010,9 +8010,9 @@
}
},
"@fatchan/haproxy-sdk": {
"version": "1.0.5",
"resolved": "https://registry.npmjs.org/@fatchan/haproxy-sdk/-/haproxy-sdk-1.0.5.tgz",
"integrity": "sha512-O0NzzpAwOcJDKUgvkaGIxvXn+uozpAWbT1lncFEX5MGoJ/HmKGQCtARStQNk/d//Q1gm4ILiOmLa9XcJRq+cbQ=="
"version": "1.0.6",
"resolved": "https://registry.npmjs.org/@fatchan/haproxy-sdk/-/haproxy-sdk-1.0.6.tgz",
"integrity": "sha512-VJbQGtGuxNhpcmYQI9kXAKHpmWXqQ9hs0K+GzIDG7pJ2dwBwaDf71hcezvehFhgmQMqD7dDMZG+1QkMCJDbiMA=="
},
"@humanwhocodes/config-array": {
"version": "0.9.5",

@ -13,7 +13,7 @@
"author": "Thomas Lynch (fatchan) <tom@69420.me>",
"license": "AGPL-3.0-only",
"dependencies": {
"@fatchan/haproxy-sdk": "^1.0.5",
"@fatchan/haproxy-sdk": "^1.0.6",
"bcrypt": "^5.0.1",
"body-parser": "^1.20.0",
"bootstrap": "^5.1.3",

@ -92,10 +92,10 @@ const Account = (props) => {
<div className="d-flex w-100 justify-content-between mt-2">
<div className="ms-2">
<div className="fw-bold">
Servers ({user.clusters[user.activeCluster].split(',').length})
<span className="fw-normal">
Servers ({user.clusters.length === 0 ? 0 : user.clusters[user.activeCluster].split(',').length})
{user.clusters.length > 0 && (<span className="fw-normal">
: {user.clusters[user.activeCluster].split(',').map(x => x.substring(0, x.length/2)+'...').join(', ')}
</span>
</span>)}
</div>
</div>
<span className="ml-auto d-flex flex-row">

@ -10,7 +10,7 @@ import ApiCall from '../../api.js';
const MapPage = (props) => {
const router = useRouter();
const { name: mapName } = router.query;
const [mapData, setMapData] = useState(props);
@ -94,6 +94,16 @@ const MapPage = (props) => {
<option selected />
{domainSelectOptions}
</select>
{
(process.env.NEXT_PUBLIC_CUSTOM_BACKENDS_ENABLED && mapId.name === "hosts") &&
<input
className="form-control ml-2"
type="text"
name="value"
placeholder="backend ip:port"
required
/>
}
</>
);
break;

@ -17,16 +17,16 @@ const testRouter = (server, app) => {
rolling: true,
cookie: {
httpOnly: true,
secure: false, //!dev, //TODO: check https
secure: true, //!dev, //TODO: check https
sameSite: 'strict',
maxAge: 1000 * 60 * 60 * 24 * 7, //week
maxAge: 1000 * 60 * 60 * 24 * 30, //month
}
});
const useSession = (req, res, next) => {
sessionStore(req, res, next);
};
const fetchSession = async (req, res, next) => {
if (req.session.user) {
const account = await db.db.collection('accounts').findOne({_id:req.session.user});
@ -43,14 +43,14 @@ const testRouter = (server, app) => {
}
next();
};
const checkSession = (req, res, next) => {
if (!res.locals.user) {
return dynamicResponse(req, res, 302, { redirect: '/login' });
}
next();
};
const csrfMiddleware = csrf();
//HAProxy-sdk middleware
@ -70,7 +70,8 @@ const testRouter = (server, app) => {
};
const hasCluster = (req, res, next) => {
if (res.locals.user.clusters.length > 0) {
console.log(req.path)
if (res.locals.user.clusters.length > 0 || (req.baseUrl+req.path) === '/forms/cluster/add') {
return next();
}
return dynamicResponse(req, res, 302, { redirect: '/clusters' });
@ -93,7 +94,7 @@ const testRouter = (server, app) => {
server.post('/forms/register', useSession, accountController.register);
const mapNames = [process.env.BLOCKED_MAP_NAME, process.env.MAINTENANCE_MAP_NAME, process.env.WHITELIST_MAP_NAME,
process.env.BLOCKED_MAP_NAME, process.env.DDOS_MAP_NAME, process.env.HOSTS_MAP_NAME]
process.env.BACKENDS_MAP_NAME, process.env.DDOS_MAP_NAME, process.env.HOSTS_MAP_NAME]
, mapNamesOrString = mapNames.join('|');
//authed pages that dont require a cluster
@ -102,7 +103,7 @@ const testRouter = (server, app) => {
server.get(`/map/:name(${mapNamesOrString})`, useSession, fetchSession, checkSession, useHaproxy, hasCluster, csrfMiddleware, mapsController.mapPage.bind(null, app));
server.get(`/map/:name(${mapNamesOrString}).json`, useSession, fetchSession, checkSession, useHaproxy, hasCluster, csrfMiddleware, mapsController.mapJson);
server.get('/clusters', useSession, fetchSession, checkSession, useHaproxy, csrfMiddleware, clustersController.clustersPage.bind(null, app));
server.get('/clusters.json', useSession, fetchSession, checkSession, useHaproxy, csrfMiddleware, clustersController.clustersJson);

@ -32,11 +32,11 @@ const fMap = {
columnNames: ['Domain', ''],
},
/*[process.env.BACKENDS_MAP_NAME]: {
[process.env.BACKENDS_MAP_NAME]: {
fname: 'Domain Backend Mappings',
description: 'Which internal server haproxy uses for domains',
columnNames: ['Domain', 'Server Name'],
},*/
},
};

Loading…
Cancel
Save