Compare commits

..

7 Commits

Author SHA1 Message Date
627cfa8592 order log 2020-02-26 15:26:19 +01:00
653cc41ff2 fix error 2020-02-26 13:57:22 +01:00
ad17778f38 update modules 2020-01-23 08:41:45 +01:00
687735e29e add entry count info 2020-01-23 08:36:53 +01:00
de3ec4572d remove item import 2020-01-22 07:35:34 +01:00
a8223d110b fix 2020-01-21 18:25:35 +01:00
207c7c3ba9 add log clearing, client restriction 2020-01-21 16:14:53 +01:00
6 changed files with 50 additions and 46 deletions

View File

@ -6,5 +6,11 @@
"password": "12345",
"database": "appreports"
},
"port": "8080"
"port": "8080",
"restrictClients": false,
"allowedClients": [
"127.0.0.1",
"::1"
],
"clearLogAfterDays": -1
}

View File

@ -27,11 +27,7 @@ app.use(bodyParser.text({ type: '*/*' }));
app.post('/', (req, res, next) => {
const json = tryParseJSON(req.body);
if (typeof req.query.json != 'undefined') {
switch (json.action) {
case 'delete': {
pg.query('DELETE FROM "Log" WHERE ID = $1', json.data);
}
}
//json mod requests
} else {
pg.query(
`INSERT INTO "Log" ("App", "Type", "Client", "Message", "Misc", "Stack") Values($1, $2, $3, $4, $5, $6)`,
@ -44,8 +40,17 @@ app.post('/', (req, res, next) => {
app.get('/', async (req, res, next) => {
if (typeof req.query.json != 'undefined') {
if (
config.restrictClients &&
!config.allowedClients.includes(req.connection.remoteAddress)
) {
console.log('blocked request from ' + req.connection.remoteAddress);
res.status(403).end();
return;
}
const data = await pg.query(
`SELECT "ID", "Timestamp", "Type", "App", "Client", "Message", "Misc", "Stack" FROM "Log"`
`SELECT "ID", "Timestamp", "Type", "App", "Client", "Message", "Misc", "Stack" FROM "Log" ORDER BY "Timestamp" ASC`
);
const rows = [];
const headings = data.rows.length > 0 ? Object.keys(data.rows[0]) : [];
@ -59,6 +64,11 @@ app.get('/', async (req, res, next) => {
.end(
JSON.stringify({ headings: headings, data: rows, hidden: hiddenData })
);
try {
const clearLogInterval = Number.parseInt(config.clearLogAfterDays);
if (clearLogInterval > 0)
await pg.query(`DELETE FROM "Log" WHERE "Timestamp" < now() - interval '${clearLogInterval} days'`);
} catch (e) {}
} else {
next();
}

26
package-lock.json generated
View File

@ -264,14 +264,15 @@
"integrity": "sha1-32BBeABfUi8V60SQ5yR6G/qmf4w="
},
"pg": {
"version": "7.12.1",
"resolved": "https://registry.npmjs.org/pg/-/pg-7.12.1.tgz",
"integrity": "sha512-l1UuyfEvoswYfcUe6k+JaxiN+5vkOgYcVSbSuw3FvdLqDbaoa2RJo1zfJKfPsSYPFVERd4GHvX3s2PjG1asSDA==",
"version": "7.17.1",
"resolved": "https://registry.npmjs.org/pg/-/pg-7.17.1.tgz",
"integrity": "sha512-SYWEip6eADsgDQIZk0bmB2JDOrC8Xu6z10KlhlXl03NSomwVmHB6ZTVyDCwOfT6bXHI8QndJdk5XxSSRXikaSA==",
"requires": {
"buffer-writer": "2.0.0",
"packet-reader": "1.0.0",
"pg-connection-string": "0.1.3",
"pg-pool": "^2.0.4",
"pg-packet-stream": "^1.1.0",
"pg-pool": "^2.0.9",
"pg-types": "^2.1.0",
"pgpass": "1.x",
"semver": "4.3.2"
@ -287,10 +288,15 @@
"resolved": "https://registry.npmjs.org/pg-int8/-/pg-int8-1.0.1.tgz",
"integrity": "sha512-WCtabS6t3c8SkpDBUlb1kjOs7l66xsGdKpIPZsg4wR+B3+u9UAum2odSsF9tnvxg80h4ZxLWMy4pRjOsFIqQpw=="
},
"pg-packet-stream": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/pg-packet-stream/-/pg-packet-stream-1.1.0.tgz",
"integrity": "sha512-kRBH0tDIW/8lfnnOyTwKD23ygJ/kexQVXZs7gEyBljw4FYqimZFxnMMx50ndZ8In77QgfGuItS5LLclC2TtjYg=="
},
"pg-pool": {
"version": "2.0.7",
"resolved": "https://registry.npmjs.org/pg-pool/-/pg-pool-2.0.7.tgz",
"integrity": "sha512-UiJyO5B9zZpu32GSlP0tXy8J2NsJ9EFGFfz5v6PSbdz/1hBLX1rNiiy5+mAm5iJJYwfCv4A0EBcQLGWwjbpzZw=="
"version": "2.0.9",
"resolved": "https://registry.npmjs.org/pg-pool/-/pg-pool-2.0.9.tgz",
"integrity": "sha512-gNiuIEKNCT3OnudQM2kvgSnXsLkSpd6mS/fRnqs6ANtrke6j8OY5l9mnAryf1kgwJMWLg0C1N1cYTZG1xmEYHQ=="
},
"pg-types": {
"version": "2.2.0",
@ -336,9 +342,9 @@
}
},
"postgresupdater": {
"version": "1.0.14",
"resolved": "https://registry.npmjs.org/postgresupdater/-/postgresupdater-1.0.14.tgz",
"integrity": "sha512-fAH6PWFE+/h7F8Pvwm3KCjkxqqbBO2+f75MrCox2bq2ISd1wzCs3kP0Yz+r8fZDLdORM0pJpV6tLHKd3PEBUcQ==",
"version": "1.0.16",
"resolved": "https://registry.npmjs.org/postgresupdater/-/postgresupdater-1.0.16.tgz",
"integrity": "sha512-6pe6ozTKwSqevDcXC/WIUvb0qBMUlCWtwKb8EOg1c+qf12Hyh+5U/t5Mq79QI8Pa3Z7d86nStGhnVpSevH2HHg==",
"requires": {
"pg": "^7.12.1"
}

View File

@ -15,6 +15,6 @@
"dependencies": {
"body-parser": "^1.19.0",
"express": "^4.17.1",
"postgresupdater": "^1.0.14"
"postgresupdater": "^1.0.16"
}
}

View File

@ -1,14 +1,20 @@
<template>
<div id="app">
<div>
<table v-if="json.headings && json.data">
<div v-if="json.headings && json.data">
<p>successfully loaded {{json.data.length}} entries</p>
<table>
<tr>
<th
v-for="(value, key) in json.headings.filter((val,ind)=>!json.hidden.includes(ind))"
:key="key"
>{{value}}</th>
</tr>
<Item v-for="(row,rowKey) in json.data" :key=rowKey :data=row :hidden=json.hidden></Item>
<tr v-for="(row,rowKey) in json.data" :key=rowKey>
<td
v-for="(value,key) in row.filter((val,ind)=>!json.hidden.includes(ind))"
:key="key"
>{{value}}</td>
</tr>
</table>
</div>
<br />
@ -22,8 +28,6 @@
</template>
<script>
import {Item} from "./Item";
export default {
name: "App",
data() {
@ -36,8 +40,7 @@ export default {
fetch("?json")
.then(res => res.json())
.then(json => (self.json = json));
},
components: [Item]
}
};
</script>

View File

@ -1,21 +0,0 @@
<template>
<tr id="item">
<td
v-for="(value,key) in data.filter((val,ind)=>!hidden.includes(ind))"
:key="key"
>{{value}}</td>
</tr>
</template>
<script>
export default {
name: "Item",
properties: {
data: Object,
hidden: Array
}
};
</script>
<style scoped>
</style>